From f7099be06095f443c895bb66c56a6b94ce5313e8 Mon Sep 17 00:00:00 2001 From: "tao.chen" <93983997+taochen-ct@users.noreply.github.com> Date: Thu, 23 Jul 2026 17:58:29 +0800 Subject: [PATCH] fix: guard flattenProviders against non-array p.models Some OpenCode Serve /config/providers responses include providers without a 'models' field (or with a non-array value). The un-guarded for-of on p.models then throws 'p.models is not iterable' and crashes the inline prompt construction. Skip such providers instead. Also re-assert the button label as 'AI' (matches the df2f3df label simplification, which the 02cedac revert had bundled away). Co-Authored-By: Claude Fable 5 --- src/__tests__/opencode_cell_actions.spec.ts | 2 +- src/components/opencode_inline_prompt.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/__tests__/opencode_cell_actions.spec.ts b/src/__tests__/opencode_cell_actions.spec.ts index 0ea462d..1eca44e 100644 --- a/src/__tests__/opencode_cell_actions.spec.ts +++ b/src/__tests__/opencode_cell_actions.spec.ts @@ -127,7 +127,7 @@ describe('OpenCodeCellActions', () => { const actions = new OpenCodeCellActions(cell); const btns = actions.node.querySelectorAll('button'); expect(btns.length).toBe(1); - expect(btns[0].textContent).toContain('🪄'); + expect(btns[0].textContent).toContain('AI'); }); it('disables the button when notebook panel cannot be resolved', () => { diff --git a/src/components/opencode_inline_prompt.ts b/src/components/opencode_inline_prompt.ts index 88f8c08..4e4aed7 100644 --- a/src/components/opencode_inline_prompt.ts +++ b/src/components/opencode_inline_prompt.ts @@ -114,6 +114,12 @@ function flattenProviders( } const out: { providerId: string; modelId: string }[] = []; for (const p of providers.providers) { + // Some OpenCode Serve responses include providers without a `models` + // field (or with a non-array value). Guard to avoid the "p.models is + // not iterable" crash and simply skip such providers in the picker. + if (!Array.isArray(p.models)) { + continue; + } for (const m of p.models) { out.push({ providerId: p.id, modelId: m.id }); }