@openchamber/web 1.19.0 → 1.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/dist/assets/{CodeMirrorCommentWidgets-DAvopJvy.js → CodeMirrorCommentWidgets-C2BopIs3.js} +1 -1
  2. package/dist/assets/CommitSection-HJeMUAWb.js +1 -0
  3. package/dist/assets/DiffView-D5cvbEPb.js +4 -0
  4. package/dist/assets/FilesView-DPU8aNPL.js +17 -0
  5. package/dist/assets/GitView-Ct6xWrVH.js +6 -0
  6. package/dist/assets/{JsonTreeView-h4dHASlq.js → JsonTreeView-osju7J70.js} +1 -1
  7. package/dist/assets/MarkdownImageGallery-EujHSZ2M.js +1 -0
  8. package/dist/assets/MarkdownRendererImpl-CPzu4kIr.js +12 -0
  9. package/dist/assets/OnboardingScreen-w2VG4fWY.js +1 -0
  10. package/dist/assets/{PatchDiff-jPKTJje5.js → PatchDiff-Dan3mADn.js} +1 -1
  11. package/dist/assets/PierreDiffViewer-CGoI2v0q.js +157 -0
  12. package/dist/assets/PlanView-Dgg-WTEc.js +4 -0
  13. package/dist/assets/SessionSwitcherDropdown-CJTrc8K7.js +1 -0
  14. package/dist/assets/SettingsView-D9yRuFZw.js +28 -0
  15. package/dist/assets/SettingsWindow-DXF-MTHG.js +1 -0
  16. package/dist/assets/ToolOutputDialog-DrCa1JRk.js +15 -0
  17. package/dist/assets/ToolPartDiffPreview-B_tfvlNF.js +8 -0
  18. package/dist/assets/{VirtualizedFileDiff-B37yB9jZ.js → VirtualizedFileDiff-CN_BctrR.js} +4 -4
  19. package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
  20. package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
  21. package/dist/assets/{WalkthroughView-Bxun3k66.js → WalkthroughView-D9Q4lr5x.js} +2 -2
  22. package/dist/assets/{computeVirtualFileMetrics-DYFv_yZS.js → computeVirtualFileMetrics-Gi1d5eU1.js} +1 -1
  23. package/dist/assets/contextPanelEmbeddedChat-CpzVNWAv.js +1 -0
  24. package/dist/assets/de-B_LdJwEM.js +9 -0
  25. package/dist/assets/es-CubfsAYV.js +15 -0
  26. package/dist/assets/fr-5qJM0nFS.js +13 -0
  27. package/dist/assets/index-BW82eK5v.css +1 -0
  28. package/dist/assets/index-Brm3X9rs.js +1 -0
  29. package/dist/assets/index-rlLjZUM5.js +7 -0
  30. package/dist/assets/{isDiffPlainText-DwHKxDYc.js → isDiffPlainText-pH9kAJQH.js} +1 -1
  31. package/dist/assets/{isFilePlainText-Dwq6ILxo.js → isFilePlainText-CVKy_dgB.js} +1 -1
  32. package/dist/assets/ja-DJYIBUlH.js +15 -0
  33. package/dist/assets/ko-DcUBkB7y.js +15 -0
  34. package/dist/assets/main-DLBxKIoX.js +926 -0
  35. package/dist/assets/main-vUCh0VB0.js +2 -0
  36. package/dist/assets/markdownCore-DG6GHLF4.js +3 -0
  37. package/dist/assets/miniChat-BlzGEYgE.js +2 -0
  38. package/dist/assets/mobile-CkX6H-IT.js +2 -0
  39. package/dist/assets/{patchFileDiff-BEDPDypx.js → patchFileDiff-BCTsE43U.js} +3 -3
  40. package/dist/assets/pl-rB6BLcio.js +15 -0
  41. package/dist/assets/pt-BR-DcwtlO-o.js +15 -0
  42. package/dist/assets/renderElectronMiniChatApp-CJYe_KOL.js +2 -0
  43. package/dist/assets/renderMobileApp-hQJTnr8B.js +25 -0
  44. package/dist/assets/runtimeEndpointReset-BDh7r8BL.js +15 -0
  45. package/dist/assets/scheduledTasksApi-CAGPh_gZ.js +1 -0
  46. package/dist/assets/{shikiHighlight-DXYW46vW.js → shikiHighlight-BgTPSITe.js} +1 -1
  47. package/dist/assets/uk-INZlFD9A.js +15 -0
  48. package/dist/assets/useAppFontEffects-Cll4gnsh.js +7268 -0
  49. package/dist/assets/useInlineCommentController-DFFv0hae.js +2 -0
  50. package/dist/assets/{vendor-base-ui-BYlZTzrw.js → vendor-base-ui-_6j2xOWl.js} +1 -1
  51. package/dist/assets/{vendor-codemirror-language-data-CiAYDJXN.js → vendor-codemirror-language-data-DkQX2EBa.js} +2 -2
  52. package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
  53. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
  54. package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
  55. package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
  56. package/dist/assets/{web-components-DCLjCO9n.js → web-components-DLnGY4fs.js} +4 -4
  57. package/dist/assets/zh-CN-Dzda8xa1.js +15 -0
  58. package/dist/assets/zh-TW-Cwn3rNYZ.js +15 -0
  59. package/dist/index.html +6 -5
  60. package/dist/mini-chat.html +5 -4
  61. package/dist/mobile.html +5 -4
  62. package/package.json +5 -7
  63. package/server/index.js +44 -0
  64. package/server/lib/agent-memory/project-resolution.js +10 -1
  65. package/server/lib/agent-memory/project-resolution.test.js +9 -0
  66. package/server/lib/agent-memory/runtime.js +7 -2
  67. package/server/lib/client-auth/pairing.js +8 -7
  68. package/server/lib/client-auth/pairing.test.js +5 -1
  69. package/server/lib/client-auth/remote-clients.js +9 -1
  70. package/server/lib/client-auth/remote-clients.test.js +17 -0
  71. package/server/lib/dictation/DOCUMENTATION.md +32 -8
  72. package/server/lib/dictation/local/sherpa-recognizer.js +35 -78
  73. package/server/lib/dictation/local/worker-process.js +2 -2
  74. package/server/lib/dictation/openai-compatible-session.js +3 -2
  75. package/server/lib/dictation/stream-manager.js +77 -34
  76. package/server/lib/dictation/stream-manager.test.js +60 -2
  77. package/server/lib/fs/routes.test.js +76 -0
  78. package/server/lib/git/routes.js +43 -0
  79. package/server/lib/git/service.js +85 -5
  80. package/server/lib/git/service.test.js +93 -0
  81. package/server/lib/github/pr-status.js +10 -1
  82. package/server/lib/opencode/DOCUMENTATION.md +6 -2
  83. package/server/lib/opencode/feature-routes-runtime.js +5 -9
  84. package/server/lib/opencode/lifecycle.js +202 -26
  85. package/server/lib/opencode/lifecycle.test.js +179 -1
  86. package/server/lib/opencode/providers.js +9 -4
  87. package/server/lib/opencode/providers.test.js +27 -0
  88. package/server/lib/opencode/restart-session-recovery.test.js +59 -0
  89. package/server/lib/opencode/session-runtime.js +39 -2
  90. package/server/lib/opencode/session-runtime.test.js +74 -0
  91. package/server/lib/opencode/settings-helpers.js +15 -0
  92. package/server/lib/opencode/settings-helpers.test.js +22 -0
  93. package/server/lib/opencode/settings-normalization-runtime.js +3 -0
  94. package/server/lib/opencode/settings-normalization-runtime.test.js +16 -0
  95. package/server/lib/opencode/settings-runtime.js +32 -10
  96. package/server/lib/opencode/settings-runtime.test.js +85 -0
  97. package/server/lib/opencode/skill-routes.js +29 -73
  98. package/server/lib/opencode/skill-routes.test.js +2 -5
  99. package/server/lib/project-context/DOCUMENTATION.md +2 -0
  100. package/server/lib/project-context/runtime.js +7 -2
  101. package/server/lib/projects/project-config.js +7 -2
  102. package/server/lib/quota/DOCUMENTATION.md +1 -1
  103. package/server/lib/quota/providers/claude/index.js +2 -2
  104. package/server/lib/quota/providers/index.js +1 -7
  105. package/server/lib/quota/providers/zai.js +26 -6
  106. package/server/lib/quota/providers/zai.test.js +33 -0
  107. package/server/lib/relay/DOCUMENTATION.md +1 -1
  108. package/server/lib/relay/service.js +34 -2
  109. package/server/lib/relay/service.test.js +69 -0
  110. package/server/lib/session-goal/runtime.js +2 -1
  111. package/server/lib/session-goal/runtime.test.js +4 -2
  112. package/server/lib/session-knowledge/DOCUMENTATION.md +2 -0
  113. package/server/lib/skills-catalog/DOCUMENTATION.md +18 -45
  114. package/server/lib/skills-catalog/cache.js +120 -1
  115. package/server/lib/skills-catalog/cache.test.js +77 -0
  116. package/server/lib/skills-catalog/curated-sources.js +21 -5
  117. package/server/lib/skills-catalog/curated-sources.test.js +4 -4
  118. package/server/lib/skills-catalog/disk-cache.js +52 -0
  119. package/server/lib/skills-catalog/github-meta.js +139 -0
  120. package/server/lib/skills-catalog/github-meta.test.js +71 -0
  121. package/server/lib/skills-catalog/source.js +0 -5
  122. package/server/lib/small-model/DOCUMENTATION.md +74 -6
  123. package/server/lib/small-model/call.js +46 -12
  124. package/server/lib/small-model/call.test.js +79 -0
  125. package/server/lib/small-model/index.js +51 -8
  126. package/server/lib/small-model/index.test.js +73 -3
  127. package/server/lib/small-model/routes.js +1 -1
  128. package/server/lib/small-model/runtime-providers.js +156 -0
  129. package/server/lib/small-model/runtime-providers.test.js +112 -0
  130. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  131. package/server/lib/terminal/runtime.js +29 -1
  132. package/server/lib/terminal/runtime.test.js +26 -0
  133. package/server/lib/ui-auth/ui-auth.js +2 -2
  134. package/server/lib/ui-auth/ui-auth.test.js +2 -2
  135. package/dist/assets/CommitSection-D9cV-qR9.js +0 -1
  136. package/dist/assets/DiagramEditor-B9NCadU7.js +0 -1
  137. package/dist/assets/DiagramView-LKGBwf4G.js +0 -1
  138. package/dist/assets/DiffView-BWNq-0ov.js +0 -4
  139. package/dist/assets/FilesView-DB-Q0Gkz.js +0 -14
  140. package/dist/assets/GitView-DsWXqWx3.js +0 -6
  141. package/dist/assets/MarkdownImageGallery-n0ikH-xm.js +0 -1
  142. package/dist/assets/MarkdownRendererImpl-CT2mjx-s.js +0 -12
  143. package/dist/assets/OnboardingScreen-CDjgzxEe.js +0 -1
  144. package/dist/assets/PierreDiffViewer-D_Gt4A_6.js +0 -136
  145. package/dist/assets/PlanView-UvuxIl9-.js +0 -4
  146. package/dist/assets/SessionSwitcherDropdown-xKU4LRuQ.js +0 -1
  147. package/dist/assets/SettingsView-3B9VN6Ys.js +0 -28
  148. package/dist/assets/SettingsWindow-CqQNDKNd.js +0 -1
  149. package/dist/assets/ToolOutputDialog-PmjlAxVE.js +0 -15
  150. package/dist/assets/ToolPartDiffPreview-B34Xw9wq.js +0 -8
  151. package/dist/assets/contextPanelEmbeddedChat-BO1wRpaN.js +0 -1
  152. package/dist/assets/de-DbV6CLxv.js +0 -9
  153. package/dist/assets/es-CVDlyzZ4.js +0 -15
  154. package/dist/assets/fr-Czc-p0g-.js +0 -13
  155. package/dist/assets/index-1OhiMDBz.css +0 -1
  156. package/dist/assets/index-BSvmTvZl.js +0 -1
  157. package/dist/assets/index-DzriVon2.js +0 -7
  158. package/dist/assets/ja-dwc9NM_S.js +0 -15
  159. package/dist/assets/ko-Ds1DZ8FX.js +0 -15
  160. package/dist/assets/main-BF51IOVF.js +0 -921
  161. package/dist/assets/main-D7UPARut.js +0 -2
  162. package/dist/assets/markdownCore-BgeBDwD3.js +0 -2
  163. package/dist/assets/miniChat-BISXSGOo.js +0 -2
  164. package/dist/assets/mobile-BnYxVuvw.js +0 -2
  165. package/dist/assets/pl-CLiTO7i-.js +0 -15
  166. package/dist/assets/pt-BR-GIimJgpK.js +0 -15
  167. package/dist/assets/renderElectronMiniChatApp-BaOy72Gi.js +0 -2
  168. package/dist/assets/renderMobileApp-BiMbzPq9.js +0 -25
  169. package/dist/assets/runtimeEndpointReset-BMBRhIbf.js +0 -15
  170. package/dist/assets/scheduledTasksApi-01zzfzqH.js +0 -1
  171. package/dist/assets/uk-DLfgD1ki.js +0 -15
  172. package/dist/assets/useAppFontEffects-CbzHzFop.js +0 -7271
  173. package/dist/assets/useInlineCommentController-CegKdDXi.js +0 -2
  174. package/dist/assets/vendor-zod-adaMkgkm.js +0 -39
  175. package/dist/assets/zh-CN-DkeP5awK.js +0 -15
  176. package/dist/assets/zh-TW-BocaFm3d.js +0 -15
  177. package/server/lib/quota/providers/command-code.js +0 -90
  178. package/server/lib/quota/providers/command-code.test.js +0 -72
  179. package/server/lib/skills-catalog/clawdhub/api.js +0 -126
  180. package/server/lib/skills-catalog/clawdhub/install.js +0 -238
  181. package/server/lib/skills-catalog/clawdhub/install.test.js +0 -100
  182. package/server/lib/skills-catalog/clawdhub/scan.js +0 -61
@@ -5,6 +5,7 @@ import { readAuthFile, writeAuthFile } from '../opencode/auth.js';
5
5
  import { readConfig, readConfigLayers } from '../opencode/shared.js';
6
6
  import { getCatalogProvider } from './catalog.js';
7
7
  import { getAuthEntryForProvider } from './resolve.js';
8
+ import { getRuntimeProvider } from './runtime-providers.js';
8
9
 
9
10
  // Direct, non-streaming text generation against the provider APIs, replicating
10
11
  // how OpenCode authenticates each of them (see the plugin auth loaders in the
@@ -566,23 +567,52 @@ const readProviderConfig = (workingDirectory, providerID) => {
566
567
  // Dispatch
567
568
  // ---------------------------------------------------------------------------
568
569
 
570
+ /**
571
+ * Providers reached through a dedicated wire format below: a token exchange,
572
+ * an OAuth refresh, or a non-bearer header. OpenCode's runtime
573
+ * `options.apiKey` is not the value those branches need — the ChatGPT-plan
574
+ * `openai` login is the clearest case, where the runtime key is an OAuth
575
+ * access token that api.openai.com answers with 401 — so the runtime
576
+ * credential never stands in for them, and the runtime listing skips them
577
+ * because the auth.json scan already covers them.
578
+ */
579
+ export const DEDICATED_WIRE_FORMAT_PROVIDERS = new Set(['github-copilot', 'copilot', 'openai', 'anthropic', 'google']);
580
+
581
+ /**
582
+ * The runtime credential shaped as an auth entry, or `null` when the provider
583
+ * owns its credential handling or OpenCode reports nothing usable.
584
+ */
585
+ const runtimeCredential = (providerID, runtime) => (
586
+ !DEDICATED_WIRE_FORMAT_PROVIDERS.has(providerID) && runtime?.apiKey
587
+ ? { type: 'api', key: runtime.apiKey }
588
+ : null
589
+ );
590
+
569
591
  /**
570
592
  * Same credential resolution the request path uses: config
571
- * `provider.<id>.options.apiKey` wins, then the auth.json entry.
593
+ * `provider.<id>.options.apiKey` wins, then the runtime credential OpenCode
594
+ * resolved for a plugin provider, then the auth.json entry.
572
595
  * Callers that need to refuse before spending a request (walkthrough readiness)
573
596
  * must use this rather than inventing a second rule.
574
597
  */
575
- export function resolveProviderLogin({ auth, workingDirectory, providerID }) {
598
+ export async function resolveProviderLogin({ auth, workingDirectory, providerID }) {
576
599
  const providerConfig = readProviderConfig(workingDirectory, providerID);
577
- return providerConfig?.auth || getAuthEntryForProvider(auth, providerID) || null;
600
+ return providerConfig?.auth
601
+ || runtimeCredential(providerID, await getRuntimeProvider(providerID))
602
+ || getAuthEntryForProvider(auth, providerID)
603
+ || null;
578
604
  }
579
605
 
580
606
  export async function callSmallModel({ auth, catalog, workingDirectory, providerID, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) {
581
607
  const tokens = Number(maxOutputTokens) > 0 ? Number(maxOutputTokens) : DEFAULT_MAX_OUTPUT_TOKENS;
582
608
  const providerConfig = readProviderConfig(workingDirectory, providerID);
583
- // Match OpenCode's resolveSDK precedence:
584
- // config provider.<id>.options.apiKey wins; the auth.json entry is only a fallback.
585
- const entry = providerConfig?.auth || getAuthEntryForProvider(auth, providerID);
609
+ const runtimeProvider = await getRuntimeProvider(providerID);
610
+ // Match OpenCode's resolveSDK precedence: config `provider.<id>.options`
611
+ // wins, then what OpenCode itself resolved at runtime (the only place a
612
+ // plugin's credential exists), and the auth.json entry last.
613
+ const entry = providerConfig?.auth
614
+ || runtimeCredential(providerID, runtimeProvider)
615
+ || getAuthEntryForProvider(auth, providerID);
586
616
  if (!entry) {
587
617
  // Structured so the walkthrough (and any other caller) can show a blocker
588
618
  // instead of a raw 500 banner with this developer-oriented sentence.
@@ -685,9 +715,12 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
685
715
  // Everything else: OpenAI-compatible chat completions against the catalog's
686
716
  // base URL for that provider (openai itself included). When a custom provider
687
717
  // is not in the catalog (e.g. a user-configured OpenAI-compatible proxy),
688
- // fall back to its baseURL from the OpenCode provider config. The openai
689
- // provider also respects provider.openai.options.baseURL — OpenCode itself
690
- // uses the same config for all providers including openai.
718
+ // fall back to its baseURL from the OpenCode provider config, then to the
719
+ // endpoint OpenCode resolved at runtime — which for a plugin provider is the
720
+ // only place it exists, and for several of them is a local proxy the plugin
721
+ // itself runs. The openai provider also respects
722
+ // provider.openai.options.baseURL — OpenCode itself uses the same config for
723
+ // all providers including openai.
691
724
  const provider = getCatalogProvider(catalog, providerID);
692
725
  const providerConfigUrl = providerConfig?.baseURL;
693
726
  const defaultOpenaiUrl = 'https://api.openai.com/v1';
@@ -695,9 +728,10 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
695
728
  ? providerConfigUrl
696
729
  : providerID === 'openai'
697
730
  ? defaultOpenaiUrl
698
- : typeof provider?.api === 'string' && provider.api
699
- ? provider.api
700
- : null;
731
+ : runtimeProvider?.baseURL
732
+ ?? (typeof provider?.api === 'string' && provider.api
733
+ ? provider.api
734
+ : null);
701
735
  if (!baseURL) {
702
736
  throw new Error(`Provider "${providerID}" has no known API base URL`);
703
737
  }
@@ -12,8 +12,11 @@ vi.mock('../opencode/shared.js', () => ({
12
12
  readConfigLayers: vi.fn(),
13
13
  }));
14
14
 
15
+ vi.mock('./runtime-providers.js', () => ({ getRuntimeProvider: vi.fn(async () => null) }));
16
+
15
17
  const { callSmallModel } = await import('./call.js');
16
18
  const { readConfig, readConfigLayers } = await import('../opencode/shared.js');
19
+ const { getRuntimeProvider } = await import('./runtime-providers.js');
17
20
 
18
21
  // Minimal catalog fragment used by the catalog-based base URL resolution case.
19
22
  const CATALOG = {
@@ -55,6 +58,9 @@ describe('callSmallModel — custom provider config', () => {
55
58
  globalThis.fetch = fetchMock;
56
59
  readConfig.mockReset();
57
60
  readConfigLayers.mockReset();
61
+ // Default: OpenCode knows nothing, so resolution stays file-based.
62
+ getRuntimeProvider.mockReset();
63
+ getRuntimeProvider.mockResolvedValue(null);
58
64
  });
59
65
 
60
66
  afterEach(() => {
@@ -341,6 +347,79 @@ describe('callSmallModel — custom provider config', () => {
341
347
  prompt: 'hi',
342
348
  })).rejects.toThrow('Provider "custom" has no known API base URL');
343
349
  });
350
+
351
+ // A plugin registers its provider inside the running OpenCode process, so
352
+ // neither the config nor auth.json knows anything about it. This is the
353
+ // case that used to fail with "has no known API base URL" (#2666).
354
+ it('uses the endpoint and credential OpenCode resolved for a plugin provider', async () => {
355
+ readConfig.mockReturnValue({});
356
+ getRuntimeProvider.mockResolvedValue({
357
+ id: 'llmapi',
358
+ apiKey: 'plugin-key',
359
+ baseURL: 'https://api.llmapi.ai/v1',
360
+ anonymousZen: false,
361
+ });
362
+ const fetchMock = vi.fn(async () => ok('done'));
363
+ vi.stubGlobal('fetch', fetchMock);
364
+
365
+ await callSmallModel({
366
+ auth: {},
367
+ catalog: {},
368
+ workingDirectory: '/proj',
369
+ providerID: 'llmapi',
370
+ modelID: 'claude-opus-4-8',
371
+ prompt: 'hi',
372
+ });
373
+
374
+ const { url, init } = lastCall(fetchMock);
375
+ expect(url).toBe('https://api.llmapi.ai/v1/chat/completions');
376
+ expect(init.headers.Authorization).toBe('Bearer plugin-key');
377
+ });
378
+
379
+ it('keeps the ChatGPT-plan login on its own transport instead of the runtime key', async () => {
380
+ readConfig.mockReturnValue({});
381
+ // OpenCode reports an OAuth access token as `options.apiKey` for openai;
382
+ // api.openai.com answers it with 401, so it must not stand in for the
383
+ // codex path.
384
+ getRuntimeProvider.mockResolvedValue({
385
+ id: 'openai',
386
+ apiKey: 'oauth-access-token',
387
+ baseURL: null,
388
+ anonymousZen: false,
389
+ });
390
+
391
+ await expect(callSmallModel({
392
+ auth: {},
393
+ catalog: {},
394
+ workingDirectory: '/proj',
395
+ providerID: 'openai',
396
+ modelID: 'gpt-5.4-mini',
397
+ prompt: 'hi',
398
+ })).rejects.toMatchObject({ code: 'no-provider-login' });
399
+ });
400
+
401
+ it('prefers an explicit config baseURL over the runtime endpoint', async () => {
402
+ readConfig.mockReturnValue({ provider: { custom: { options: { baseURL: 'https://configured.example/v1' } } } });
403
+ getRuntimeProvider.mockResolvedValue({
404
+ id: 'custom',
405
+ apiKey: 'runtime-key',
406
+ baseURL: 'https://runtime.example/v1',
407
+ anonymousZen: false,
408
+ });
409
+ const fetchMock = vi.fn(async () => ok('done'));
410
+ vi.stubGlobal('fetch', fetchMock);
411
+
412
+ await callSmallModel({
413
+ auth: { custom: { type: 'api', key: 'auth-key' } },
414
+ catalog: {},
415
+ workingDirectory: '/proj',
416
+ providerID: 'custom',
417
+ modelID: 'm',
418
+ prompt: 'hi',
419
+ });
420
+
421
+ expect(lastCall(fetchMock).url).toBe('https://configured.example/v1/chat/completions');
422
+ });
344
423
  });
345
424
 
346
425
  describe('config-supplied key does not leak', () => {
@@ -5,7 +5,16 @@ import { readAuthFile } from '../opencode/auth.js';
5
5
  import { readConfigLayers } from '../opencode/shared.js';
6
6
  import { getModelCatalog } from './catalog.js';
7
7
  import { resolveSmallModel, parseModelRef, isUsableAuthEntry, getAuthEntryForProvider } from './resolve.js';
8
- import { callSmallModel, resolveProviderLogin } from './call.js';
8
+ import { DEDICATED_WIRE_FORMAT_PROVIDERS, callSmallModel, resolveProviderLogin } from './call.js';
9
+ import { getRuntimeProviderSnapshot } from './runtime-providers.js';
10
+
11
+ // Never a small model, whatever the transport looks like. A plugin can publish
12
+ // an OpenAI-compatible endpoint for Claude Code, but it is a façade over the
13
+ // Claude Agent SDK, which spawns the Claude Code CLI per request and spends
14
+ // the user's Claude subscription rate limit. Paying that for a session title
15
+ // or a summary is the wrong trade, so the refusal is unconditional rather than
16
+ // conditional on an endpoint existing.
17
+ const CLAUDE_CODE_PROVIDER = 'claude-code';
9
18
 
10
19
  const OPENCHAMBER_SETTINGS_FILE = path.join(
11
20
  process.env.OPENCHAMBER_DATA_DIR
@@ -120,7 +129,7 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
120
129
  );
121
130
  }
122
131
 
123
- if (resolved.providerID === 'claude-code') {
132
+ if (resolved.providerID === CLAUDE_CODE_PROVIDER) {
124
133
  throw Object.assign(
125
134
  new Error('Claude Code cannot be used for background small-model actions. Choose another Small Model in Settings → Sessions.'),
126
135
  { statusCode: 422, code: 'small-model-provider-unsupported' },
@@ -180,28 +189,62 @@ export async function generateSmallModelText({ prompt, system, maxOutputTokens,
180
189
  }
181
190
 
182
191
  /**
183
- * Provider ids with a usable OpenCode login — the set the small model can
184
- * actually call. Used by the settings override picker to hide providers that
185
- * would only ever fail (e.g. opencode free models without a token).
192
+ * Provider ids the small model can actually call — an auth.json login, or a
193
+ * credential and endpoint the running OpenCode resolved for a plugin. Used by
194
+ * the Small Model and Changes Walkthrough pickers to hide providers that would
195
+ * only ever fail (e.g. opencode free models without a token).
186
196
  */
187
- export function listAuthenticatedProviders() {
197
+ export async function listAuthenticatedProviders() {
188
198
  try {
189
199
  const auth = readAuthFile();
190
200
  const ids = new Set(
191
201
  Object.keys(auth || {}).filter((providerID) => isUsableAuthEntry(auth[providerID])),
192
202
  );
193
- ids.delete('claude-code');
194
203
  // The catalog id is github-copilot while legacy auth entries may sit
195
204
  // under the copilot alias.
196
205
  if (isUsableAuthEntry(getAuthEntryForProvider(auth, 'github-copilot'))) {
197
206
  ids.add('github-copilot');
198
207
  }
208
+ // Kept separate so a runtime lookup that goes wrong costs the providers it
209
+ // would have added, never the logins already established from disk.
210
+ try {
211
+ for (const providerID of await listRuntimeCallableProviders()) ids.add(providerID);
212
+ } catch {
213
+ // The auth.json set below stands on its own.
214
+ }
215
+ ids.delete(CLAUDE_CODE_PROVIDER);
199
216
  return Array.from(ids);
200
217
  } catch {
201
218
  return [];
202
219
  }
203
220
  }
204
221
 
222
+ /**
223
+ * Providers that only the running OpenCode knows about — plugin-registered
224
+ * ones, and any whose endpoint is resolved at startup.
225
+ *
226
+ * The test is the same one applied to an auth.json login: a credential we may
227
+ * use and somewhere to send it. Whether the endpoint answers the protocol we
228
+ * speak is not knowable from any field OpenCode reports, and guessing it wrong
229
+ * removes a working model from the picker with nothing to explain it.
230
+ */
231
+ async function listRuntimeCallableProviders() {
232
+ const snapshot = await getRuntimeProviderSnapshot();
233
+ if (!snapshot) return [];
234
+ const ids = [];
235
+ for (const id of snapshot.connected) {
236
+ const provider = snapshot.providers.get(id);
237
+ // No credential we may use — including the zen sentinel, whose free models
238
+ // belong to OpenCode's own server.
239
+ if (!provider?.apiKey || !provider.baseURL) continue;
240
+ // Reached through a dedicated wire format and already covered by the
241
+ // auth.json scan above.
242
+ if (DEDICATED_WIRE_FORMAT_PROVIDERS.has(id)) continue;
243
+ ids.push(id);
244
+ }
245
+ return ids;
246
+ }
247
+
205
248
  /**
206
249
  * Reports which model would be used, without calling it.
207
250
  *
@@ -262,7 +305,7 @@ export async function describeSmallModel({ directory, preferredProviderID, prefe
262
305
 
263
306
  // Settings/config/request overrides can name a provider with no usable login.
264
307
  // Report that here so readiness can refuse before the user pays for a 401.
265
- const hasLogin = Boolean(resolveProviderLogin({
308
+ const hasLogin = Boolean(await resolveProviderLogin({
266
309
  auth,
267
310
  workingDirectory: directory,
268
311
  providerID: resolved.providerID,
@@ -19,15 +19,20 @@ vi.mock('./catalog.js', () => ({
19
19
  getCatalogProvider: vi.fn(),
20
20
  }));
21
21
  vi.mock('./call.js', () => ({
22
+ DEDICATED_WIRE_FORMAT_PROVIDERS: new Set(['github-copilot', 'copilot', 'openai', 'anthropic', 'google']),
22
23
  callSmallModel: vi.fn(),
23
- resolveProviderLogin: vi.fn(({ auth, providerID }) => {
24
+ resolveProviderLogin: vi.fn(async ({ auth, providerID }) => {
24
25
  const entry = auth?.[providerID];
25
26
  return entry && typeof entry === 'object' ? entry : null;
26
27
  }),
27
28
  }));
29
+ vi.mock('./runtime-providers.js', () => ({
30
+ getRuntimeProviderSnapshot: vi.fn(async () => null),
31
+ }));
28
32
 
29
33
  const { generateSmallModelText, describeSmallModel, listAuthenticatedProviders } = await import('./index.js');
30
34
  const { readAuthFile } = await import('../opencode/auth.js');
35
+ const { getRuntimeProviderSnapshot } = await import('./runtime-providers.js');
31
36
  const { readConfigLayers } = await import('../opencode/shared.js');
32
37
  const { getModelCatalog } = await import('./catalog.js');
33
38
  const { callSmallModel } = await import('./call.js');
@@ -44,6 +49,7 @@ describe('unsupported small-model providers', () => {
44
49
  readConfigLayers.mockReturnValue({ mergedConfig: {} });
45
50
  getModelCatalog.mockResolvedValue({});
46
51
  callSmallModel.mockReset();
52
+ getRuntimeProviderSnapshot.mockResolvedValue(null);
47
53
  });
48
54
 
49
55
  it('rejects Claude Code with an actionable error before transport dispatch', async () => {
@@ -57,8 +63,72 @@ describe('unsupported small-model providers', () => {
57
63
  expect(callSmallModel).not.toHaveBeenCalled();
58
64
  });
59
65
 
60
- it('does not offer Claude Code in the Small Model picker', () => {
61
- expect(listAuthenticatedProviders()).not.toContain('claude-code');
66
+ it('does not offer Claude Code in the Small Model picker', async () => {
67
+ expect(await listAuthenticatedProviders()).not.toContain('claude-code');
68
+ });
69
+
70
+ // A plugin can publish an OpenAI-compatible endpoint for Claude Code, but it
71
+ // is a façade over the Claude Agent SDK: every call spawns the CLI and
72
+ // spends the user's Claude subscription. The refusal is about that cost, so
73
+ // an available endpoint must not lift it.
74
+ it('still refuses Claude Code when a plugin publishes an HTTP endpoint for it', async () => {
75
+ getRuntimeProviderSnapshot.mockResolvedValue({
76
+ providers: new Map([['claude-code', { id: 'claude-code', apiKey: 'plugin-key', baseURL: 'http://127.0.0.1:60668/v1', anonymousZen: false }]]),
77
+ connected: new Set(['claude-code']),
78
+ });
79
+
80
+ await expect(generateSmallModelText({
81
+ prompt: 'summarize this',
82
+ model: 'claude-code/haiku',
83
+ })).rejects.toMatchObject({ code: 'small-model-provider-unsupported' });
84
+ expect(await listAuthenticatedProviders()).not.toContain('claude-code');
85
+
86
+ getRuntimeProviderSnapshot.mockResolvedValue(null);
87
+ });
88
+ });
89
+
90
+ describe('provider availability for the model pickers', () => {
91
+ beforeEach(() => {
92
+ readAuthFile.mockReturnValue({ openai: { type: 'api', key: 'sk-test' } });
93
+ readConfigLayers.mockReturnValue({ mergedConfig: {} });
94
+ getModelCatalog.mockResolvedValue({});
95
+ getRuntimeProviderSnapshot.mockResolvedValue(null);
96
+ });
97
+
98
+ const snapshot = (providers, connected) => ({
99
+ providers: new Map(providers.map((provider) => [provider.id, provider])),
100
+ connected: new Set(connected ?? providers.map((provider) => provider.id)),
101
+ });
102
+
103
+ it('offers a plugin provider that OpenCode resolved at runtime', async () => {
104
+ getRuntimeProviderSnapshot.mockResolvedValue(snapshot([
105
+ { id: 'llmapi', apiKey: 'plugin-key', baseURL: 'https://api.llmapi.ai/v1', anonymousZen: false },
106
+ ]));
107
+
108
+ expect(await listAuthenticatedProviders()).toEqual(expect.arrayContaining(['openai', 'llmapi']));
109
+ });
110
+
111
+ it('hides a provider with no endpoint to send a request to', async () => {
112
+ getRuntimeProviderSnapshot.mockResolvedValue(snapshot([
113
+ { id: 'endpointless', apiKey: 'plugin-key', baseURL: null, anonymousZen: false },
114
+ ]));
115
+
116
+ expect(await listAuthenticatedProviders()).not.toContain('endpointless');
117
+ });
118
+
119
+ it('never offers opencode zen without a real login', async () => {
120
+ // The zen sentinel is not a credential, so the snapshot carries no apiKey.
121
+ getRuntimeProviderSnapshot.mockResolvedValue(snapshot([
122
+ { id: 'opencode', apiKey: null, baseURL: 'https://opencode.ai/zen/v1', anonymousZen: true },
123
+ ]));
124
+
125
+ expect(await listAuthenticatedProviders()).not.toContain('opencode');
126
+ });
127
+
128
+ it('keeps the auth.json providers when OpenCode cannot be reached', async () => {
129
+ getRuntimeProviderSnapshot.mockResolvedValue(null);
130
+
131
+ expect(await listAuthenticatedProviders()).toContain('openai');
62
132
  });
63
133
  });
64
134
 
@@ -10,7 +10,7 @@ export function registerSmallModelRoutes(app, { getSmallModelService }) {
10
10
  res.json({
11
11
  available: Boolean(resolved),
12
12
  model: resolved,
13
- authenticatedProviders: listAuthenticatedProviders(),
13
+ authenticatedProviders: await listAuthenticatedProviders(),
14
14
  });
15
15
  } catch (error) {
16
16
  console.error('Failed to resolve small model:', error);
@@ -0,0 +1,156 @@
1
+ // Provider state that exists only inside the running OpenCode process.
2
+ //
3
+ // A plugin registers its provider from the `config` hook and supplies the
4
+ // credential from its `auth` loader, both at startup. Neither ends up in
5
+ // `opencode.json` or `auth.json`, so a server that only reads files sees
6
+ // nothing — which is why plugin-backed models used to fail here with
7
+ // "has no known API base URL" while working fine in chat (#2666).
8
+ //
9
+ // `GET /provider` is where that state becomes visible. It reports, per
10
+ // provider, the resolved `options.baseURL` and `options.apiKey`, and per model
11
+ // the wire adapter (`api.npm`) and endpoint (`api.url`).
12
+ //
13
+ // What it does NOT report is `options.fetch`. OpenCode strips functions from
14
+ // the response, and a plugin is free to put its whole protocol in there:
15
+ // rewriting the path, signing the request, translating the payload. Such a
16
+ // provider advertises a perfectly ordinary base URL that answers nothing we
17
+ // know how to ask, and no field distinguishes the two.
18
+ //
19
+ // Asking the endpoint (`GET /models`) looked like the way to tell them apart,
20
+ // and it does answer correctly for that case — but measured against the 166
21
+ // providers in the models.dev catalog it also denies six that work fine and
22
+ // simply have no `/models` route. A provider that vanishes from the picker
23
+ // explains nothing; one that fails on use says why. So this module reports
24
+ // what it knows and leaves the verdict to the call itself.
25
+
26
+ const SNAPSHOT_TTL_MS = 30_000;
27
+ const SNAPSHOT_TIMEOUT_MS = 5_000;
28
+
29
+ // opencode zen hands out this sentinel instead of a key when the user has no
30
+ // zen login, and trims its catalog to the free models. Those run on OpenCode's
31
+ // own subsidised infrastructure and are meant to be reached through OpenCode,
32
+ // not by us. Treating the sentinel as a credential would do exactly that, so
33
+ // it is never accepted as one.
34
+ export const ZEN_ANONYMOUS_API_KEY = 'public';
35
+
36
+ let connection = null;
37
+ let snapshot = null;
38
+ let snapshotAt = 0;
39
+ let inflight = null;
40
+
41
+ /**
42
+ * Wires this module to the running OpenCode instance. Called once at server
43
+ * startup; pass `null` to detach. Until it is wired every lookup answers
44
+ * "nothing known", which leaves the file-based resolution unchanged.
45
+ */
46
+ export function configureOpenCodeRuntimeProviders(next) {
47
+ connection = next ?? null;
48
+ resetOpenCodeRuntimeProviders();
49
+ }
50
+
51
+ /**
52
+ * Drops every cached answer. OpenCode restarts reload plugins, which can
53
+ * change ports, keys and the provider list itself.
54
+ */
55
+ export function resetOpenCodeRuntimeProviders() {
56
+ snapshot = null;
57
+ snapshotAt = 0;
58
+ inflight = null;
59
+ }
60
+
61
+ /**
62
+ * The boundary. Everything the `/provider` payload claims is checked here, so
63
+ * the rest of this module and its callers work with settled values:
64
+ * a credential we may use, an endpoint, and whether the provider is the
65
+ * anonymous zen case.
66
+ *
67
+ * The credential deliberately prefers `options.apiKey` over the `key` field:
68
+ * for a plugin provider the former is what its auth loader produced and what
69
+ * OpenCode itself sends, while `key` only carries env/auth.json values this
70
+ * server can already read from disk.
71
+ */
72
+ function parseProviderListing(payload) {
73
+ const providers = new Map();
74
+ const connected = new Set();
75
+ if (!payload || typeof payload !== 'object') return { providers, connected };
76
+
77
+ const text = (value) => (typeof value === 'string' && value.trim() ? value.trim() : null);
78
+ const record = (value) => (value && typeof value === 'object' ? value : {});
79
+ const endpoint = (value) => text(value)?.replace(/\/+$/, '') ?? null;
80
+
81
+ for (const raw of Array.isArray(payload.all) ? payload.all : []) {
82
+ const id = text(record(raw).id);
83
+ if (!id) continue;
84
+ const options = record(record(raw).options);
85
+ const firstModel = record(Object.values(record(record(raw).models))[0]);
86
+ const declaredKey = text(options.apiKey);
87
+ providers.set(id, {
88
+ id,
89
+ source: text(record(raw).source),
90
+ apiKey: declaredKey === ZEN_ANONYMOUS_API_KEY ? null : (declaredKey ?? text(record(raw).key)),
91
+ baseURL: endpoint(options.baseURL) ?? endpoint(record(firstModel.api).url),
92
+ // True only for the zen-without-login case: a provider that is present
93
+ // and usable through OpenCode, but that we must not call ourselves.
94
+ anonymousZen: declaredKey === ZEN_ANONYMOUS_API_KEY,
95
+ });
96
+ }
97
+
98
+ // Providers OpenCode considers usable right now. A provider can be present
99
+ // in `all` (it is in the catalog) without any credential behind it.
100
+ for (const raw of Array.isArray(payload.connected) ? payload.connected : []) {
101
+ const id = text(raw);
102
+ if (id) connected.add(id);
103
+ }
104
+
105
+ return { providers, connected };
106
+ }
107
+
108
+ const fetchSnapshot = async () => {
109
+ const response = await fetch(connection.buildOpenCodeUrl('/provider', ''), {
110
+ headers: { Accept: 'application/json', ...connection.getOpenCodeAuthHeaders() },
111
+ signal: AbortSignal.timeout(SNAPSHOT_TIMEOUT_MS),
112
+ });
113
+ if (!response.ok) {
114
+ throw new Error(`OpenCode provider listing failed with ${response.status}`);
115
+ }
116
+ return parseProviderListing(await response.json());
117
+ };
118
+
119
+ /**
120
+ * The current runtime provider snapshot, or `null` when OpenCode cannot be
121
+ * reached.
122
+ *
123
+ * `null` means "unknown", never "no providers": callers must fall back to
124
+ * their file-based resolution rather than treat an unreachable OpenCode as an
125
+ * empty provider list.
126
+ */
127
+ export async function getRuntimeProviderSnapshot() {
128
+ if (!connection) return null;
129
+ if (snapshot && Date.now() - snapshotAt < SNAPSHOT_TTL_MS) return snapshot;
130
+ if (!inflight) {
131
+ inflight = fetchSnapshot().finally(() => {
132
+ inflight = null;
133
+ });
134
+ }
135
+ try {
136
+ snapshot = await inflight;
137
+ snapshotAt = Date.now();
138
+ return snapshot;
139
+ } catch {
140
+ // Keep serving the previous snapshot when there is one: a momentarily
141
+ // unreachable OpenCode should not retract providers that were resolving a
142
+ // second ago.
143
+ return snapshot;
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Runtime credential and endpoint for one provider, or `null` when OpenCode
149
+ * knows nothing about it.
150
+ */
151
+ export async function getRuntimeProvider(providerID) {
152
+ const current = await getRuntimeProviderSnapshot();
153
+ return current?.providers.get(providerID) ?? null;
154
+ }
155
+
156
+