@openchamber/web 1.20.0 → 1.21.1

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 (174) hide show
  1. package/bin/cli.test.js +35 -0
  2. package/bin/lib/DOCUMENTATION.md +12 -0
  3. package/bin/lib/cli-settings-accessors.js +111 -0
  4. package/bin/lib/cli-settings-accessors.test.js +189 -0
  5. package/bin/lib/cli-startup.js +29 -9
  6. package/bin/lib/commands-connect-url.js +12 -14
  7. package/dist/assets/{CodeMirrorCommentWidgets-C36E738Y.js → CodeMirrorCommentWidgets-BGj8TJxW.js} +1 -1
  8. package/dist/assets/CommitSection-DwGiXyjf.js +1 -0
  9. package/dist/assets/DiffView-Db6bjVv1.js +4 -0
  10. package/dist/assets/FilesView-DQOa7Lgz.js +17 -0
  11. package/dist/assets/GitView-CHzJxTi0.js +6 -0
  12. package/dist/assets/{JsonTreeView-KnXFN2A-.js → JsonTreeView-CggOsLot.js} +1 -1
  13. package/dist/assets/MarkdownImageGallery-DoZpaHev.js +1 -0
  14. package/dist/assets/MarkdownRendererImpl-B5Y5xCOz.js +12 -0
  15. package/dist/assets/OnboardingScreen-C98d69Fp.js +1 -0
  16. package/dist/assets/{PatchDiff-BzVOVog8.js → PatchDiff-DJYMUiXA.js} +1 -1
  17. package/dist/assets/PierreDiffViewer-CY2bx_SB.js +157 -0
  18. package/dist/assets/PlanView-PkiOY_9H.js +5 -0
  19. package/dist/assets/SettingsView-D-K3ELCM.js +28 -0
  20. package/dist/assets/SettingsWindow-oyOm2fHR.js +1 -0
  21. package/dist/assets/{ToolOutputDialog-BB1c--Zr.js → ToolOutputDialog-lKyeQTPL.js} +6 -6
  22. package/dist/assets/{ToolPartDiffPreview-DaOIDISD.js → ToolPartDiffPreview-C7kBQNAA.js} +2 -2
  23. package/dist/assets/{VirtualizedFileDiff-lESMT-2b.js → VirtualizedFileDiff-BP7ebDFF.js} +4 -4
  24. package/dist/assets/{Virtualizer-X_7XPoTH.js → Virtualizer-CZlLSacm.js} +1 -1
  25. package/dist/assets/Virtualizer-D_a8gKmg.js +1 -0
  26. package/dist/assets/{WalkthroughView-CaSYE0lw.js → WalkthroughView-MuJodAHD.js} +2 -2
  27. package/dist/assets/{computeVirtualFileMetrics-DkRR5b75.js → computeVirtualFileMetrics-CZ0xPeaT.js} +2 -2
  28. package/dist/assets/contextPanelEmbeddedChat-C9abMBTb.js +1 -0
  29. package/dist/assets/de-CEoCz3j6.js +9 -0
  30. package/dist/assets/es-DwyXCqaL.js +15 -0
  31. package/dist/assets/fr-CS7Csln9.js +13 -0
  32. package/dist/assets/index-CUKcHnUA.css +1 -0
  33. package/dist/assets/index-CaPAjwXQ.js +1 -0
  34. package/dist/assets/index-DIvDEKE-.js +7 -0
  35. package/dist/assets/{isDiffPlainText-BG53Ixxy.js → isDiffPlainText-ZBvDxhVB.js} +1 -1
  36. package/dist/assets/{isFilePlainText-BbV-39jl.js → isFilePlainText-DiLRrkJr.js} +1 -1
  37. package/dist/assets/ja-vnwqLcx6.js +15 -0
  38. package/dist/assets/ko-CXuSfZv5.js +15 -0
  39. package/dist/assets/main-D5RWr6sJ.js +2 -0
  40. package/dist/assets/main-DLlfDjQ_.js +926 -0
  41. package/dist/assets/{markdown-shiki.worker-CKGJ1J33.js → markdown-shiki.worker-D5fBU-lw.js} +5 -5
  42. package/dist/assets/markdownCore-CcTcLsQF.js +3 -0
  43. package/dist/assets/{miniChat-ldEghBLB.js → miniChat-CqR3icsk.js} +2 -2
  44. package/dist/assets/mobile-RN_UTTlB.js +2 -0
  45. package/dist/assets/{patchFileDiff-BcFaMtMu.js → patchFileDiff-CjRR5ESs.js} +1 -1
  46. package/dist/assets/pl-BJxry0Mi.js +15 -0
  47. package/dist/assets/pt-BR-DxLmkhdv.js +15 -0
  48. package/dist/assets/renderElectronMiniChatApp-1wC94fQK.js +2 -0
  49. package/dist/assets/renderMobileApp-ltva2Plg.js +25 -0
  50. package/dist/assets/runtimeEndpointReset-D6SmNZaP.js +15 -0
  51. package/dist/assets/scheduledTasksApi-mjMDet_H.js +1 -0
  52. package/dist/assets/{shikiHighlight-DCT2Sq_z.js → shikiHighlight-fGmFkxAM.js} +1 -1
  53. package/dist/assets/tr-5Mk_hQ2Q.js +6 -0
  54. package/dist/assets/uk-ClgQjmlw.js +15 -0
  55. package/dist/assets/{useAppFontEffects-B53Rb6m7.js → useAppFontEffects-KP8_yiGW.js} +176 -184
  56. package/dist/assets/useInlineCommentController-HIjtuhxD.js +2 -0
  57. package/dist/assets/useRootScrollLock-BSiQ5F75.js +1 -0
  58. package/dist/assets/{vendor-base-ui-DsHmyMwp.js → vendor-base-ui-BeMD8X_w.js} +1 -1
  59. package/dist/assets/{vendor-codemirror-language-data-vch3tJ4c.js → vendor-codemirror-language-data-DrTPkHl4.js} +2 -2
  60. package/dist/assets/{vendor-floating-ui-core-CXmKXOXc.js → vendor-floating-ui-core-PuGzNPnN.js} +1 -1
  61. package/dist/assets/{vendor-floating-ui-dom-WyXykhNi.js → vendor-floating-ui-dom-BTvzWks8.js} +1 -1
  62. package/dist/assets/{vendor-floating-ui-react-dom-DKpLs02S.js → vendor-floating-ui-react-dom-DxYCWdHj.js} +1 -1
  63. package/dist/assets/{vendor-floating-ui-utils-BzXdqYpP.js → vendor-floating-ui-utils-D6FqdtJt.js} +1 -1
  64. package/dist/assets/{vendor-framer-motion-CRSgBxjL.js → vendor-framer-motion-livSKyyV.js} +1 -1
  65. package/dist/assets/vendor-legendapp-list-gg7YLRW7.js +1 -0
  66. package/dist/assets/vendor-linkify-it-DZCzzDkK.js +1 -0
  67. package/dist/assets/vendor-marked-linkify-it-CXI_LHIE.js +1 -0
  68. package/dist/assets/{vendor-motion-dom-DJLgZh4Q.js → vendor-motion-dom-D_o3BTI3.js} +1 -1
  69. package/dist/assets/vendor-uc.micro-BAd0H0z4.js +1 -0
  70. package/dist/assets/vendor-zod-BLfBSgBh.js +39 -0
  71. package/dist/assets/{web-components-pcwCTWjC.js → web-components-DOXvU-tB.js} +4 -4
  72. package/dist/assets/zh-CN-Ba6y8H-i.js +15 -0
  73. package/dist/assets/zh-TW-Dv8yyhN1.js +15 -0
  74. package/dist/index.html +7 -7
  75. package/dist/mini-chat.html +5 -5
  76. package/dist/mobile.html +5 -5
  77. package/dist/site.webmanifest +1 -1
  78. package/dist/sw.js +1 -1
  79. package/package.json +4 -4
  80. package/public/site.webmanifest +1 -1
  81. package/server/index.js +10 -2
  82. package/server/lib/client-auth/pairing.js +8 -7
  83. package/server/lib/client-auth/pairing.test.js +5 -1
  84. package/server/lib/client-auth/remote-clients.js +9 -1
  85. package/server/lib/client-auth/remote-clients.test.js +17 -0
  86. package/server/lib/cloudflare-tunnel.js +1 -1
  87. package/server/lib/fs/DOCUMENTATION.md +1 -0
  88. package/server/lib/fs/routes.js +21 -0
  89. package/server/lib/fs/routes.test.js +89 -3
  90. package/server/lib/git/DOCUMENTATION.md +4 -3
  91. package/server/lib/git/service.js +128 -6
  92. package/server/lib/git/service.test.js +191 -1
  93. package/server/lib/github/pr-status.js +10 -1
  94. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  95. package/server/lib/markdown-image-grants/routes.js +3 -1
  96. package/server/lib/markdown-image-grants/routes.test.js +14 -0
  97. package/server/lib/openchamber-sessions/routes.js +4 -1
  98. package/server/lib/openchamber-sessions/routes.test.js +23 -0
  99. package/server/lib/opencode/env-runtime.js +17 -1
  100. package/server/lib/opencode/env-runtime.test.js +56 -0
  101. package/server/lib/opencode/lifecycle.js +48 -9
  102. package/server/lib/opencode/lifecycle.test.js +125 -1
  103. package/server/lib/opencode/managed-process-registry.d.ts +13 -0
  104. package/server/lib/opencode/managed-process-registry.js +213 -163
  105. package/server/lib/opencode/managed-process-registry.test.mjs +285 -0
  106. package/server/lib/opencode/project-directory-runtime.js +16 -11
  107. package/server/lib/opencode/project-directory-runtime.test.js +32 -12
  108. package/server/lib/opencode/pwa-manifest-routes.js +1 -1
  109. package/server/lib/opencode/routes-upgrade.test.js +96 -12
  110. package/server/lib/opencode/routes.js +53 -5
  111. package/server/lib/opencode/settings-helpers.js +3 -0
  112. package/server/lib/opencode/settings-helpers.test.js +10 -0
  113. package/server/lib/opencode/theme-runtime.js +1 -1
  114. package/server/lib/opencode/theme-runtime.test.js +129 -0
  115. package/server/lib/quota/DOCUMENTATION.md +19 -0
  116. package/server/lib/quota/providers/copilot.js +26 -10
  117. package/server/lib/quota/providers/copilot.test.js +78 -0
  118. package/server/lib/quota/providers/index.js +4 -18
  119. package/server/lib/relay/DOCUMENTATION.md +1 -1
  120. package/server/lib/relay/service.js +34 -2
  121. package/server/lib/relay/service.test.js +69 -0
  122. package/server/lib/session-goal/runtime.js +2 -1
  123. package/server/lib/session-goal/runtime.test.js +4 -2
  124. package/server/lib/small-model/DOCUMENTATION.md +11 -5
  125. package/server/lib/small-model/call.js +64 -20
  126. package/server/lib/small-model/call.test.js +184 -2
  127. package/server/lib/terminal/DOCUMENTATION.md +2 -0
  128. package/server/lib/terminal/runtime.js +29 -1
  129. package/server/lib/terminal/runtime.test.js +26 -0
  130. package/server/lib/tunnels/install-help.js +2 -2
  131. package/server/lib/tunnels/install-help.test.js +9 -0
  132. package/server/lib/ui-auth/ui-auth.js +2 -2
  133. package/server/lib/ui-auth/ui-auth.test.js +2 -2
  134. package/server/lib/walkthrough/languages.js +1 -0
  135. package/dist/assets/CommitSection-C-F3AX6D.js +0 -1
  136. package/dist/assets/DiagramEditor-BPECg1jS.js +0 -1
  137. package/dist/assets/DiagramView-D0YNMix8.js +0 -1
  138. package/dist/assets/DiffView-BHWaMYCC.js +0 -4
  139. package/dist/assets/FilesView-NMBCW2Tm.js +0 -14
  140. package/dist/assets/GitView-Rp8P1KEI.js +0 -6
  141. package/dist/assets/MarkdownImageGallery-BMn3mtor.js +0 -1
  142. package/dist/assets/MarkdownRendererImpl-kD6N03pH.js +0 -12
  143. package/dist/assets/OnboardingScreen-CenIeD4v.js +0 -1
  144. package/dist/assets/PierreDiffViewer-Dlby4XqT.js +0 -136
  145. package/dist/assets/PlanView-Czu1KMJa.js +0 -4
  146. package/dist/assets/SessionSwitcherDropdown-IETz58DB.js +0 -1
  147. package/dist/assets/SettingsView-B6vmuf-c.js +0 -28
  148. package/dist/assets/SettingsWindow-CauZpdD3.js +0 -1
  149. package/dist/assets/contextPanelEmbeddedChat-BEARQjgn.js +0 -1
  150. package/dist/assets/de-DFdX3ABv.js +0 -9
  151. package/dist/assets/es-iC-FKvV9.js +0 -15
  152. package/dist/assets/fr-BBbi_1AL.js +0 -13
  153. package/dist/assets/index-BiEgzzkg.js +0 -1
  154. package/dist/assets/index-Cwmuwk3V.js +0 -7
  155. package/dist/assets/index-GNm1wgUH.css +0 -1
  156. package/dist/assets/ja-DQLQJL2J.js +0 -15
  157. package/dist/assets/ko-BeElEB4Y.js +0 -15
  158. package/dist/assets/main-Dpzo18z7.js +0 -2
  159. package/dist/assets/main-WMjtYzJs.js +0 -921
  160. package/dist/assets/markdownCore--tDmyI_v.js +0 -2
  161. package/dist/assets/mobile-Dk-VGreF.js +0 -2
  162. package/dist/assets/pl-CLHt2_vV.js +0 -15
  163. package/dist/assets/pt-BR-C_MPUq7e.js +0 -15
  164. package/dist/assets/renderElectronMiniChatApp-DIgCOmXY.js +0 -2
  165. package/dist/assets/renderMobileApp-CDfHS5rr.js +0 -25
  166. package/dist/assets/runtimeEndpointReset-ovNbaZ-x.js +0 -15
  167. package/dist/assets/scheduledTasksApi-BFSlqgnG.js +0 -1
  168. package/dist/assets/uk-PhsC-c4-.js +0 -15
  169. package/dist/assets/useInlineCommentController-DSfrIBKT.js +0 -2
  170. package/dist/assets/vendor-zod-C9ioTTSo.js +0 -39
  171. package/dist/assets/zh-CN-wF-NOFHM.js +0 -15
  172. package/dist/assets/zh-TW-4m4-A7rT.js +0 -15
  173. package/server/lib/quota/providers/command-code.js +0 -90
  174. package/server/lib/quota/providers/command-code.test.js +0 -85
@@ -35,13 +35,14 @@ const startIdleTick = async (fetchImpl) => {
35
35
  buildOpenCodeUrl: (pathname) => `http://opencode.test${pathname}`,
36
36
  getOpenCodeAuthHeaders: () => ({}),
37
37
  getSmallModelService,
38
+ isEnabled: () => true,
38
39
  idleQuietMs: 10,
39
40
  });
40
41
  runtime.processPayload({
41
42
  type: 'session.status',
42
43
  properties: { sessionID: SESSION_ID, status: { type: 'idle' }, directory: DIRECTORY },
43
44
  });
44
- await vi.advanceTimersByTimeAsync(10);
45
+ await vi.runOnlyPendingTimersAsync();
45
46
  return { runtime, getSmallModelService };
46
47
  };
47
48
 
@@ -156,6 +157,7 @@ describe('session goal live activity gate', () => {
156
157
  buildOpenCodeUrl: (pathname) => `http://opencode.test${pathname}`,
157
158
  getOpenCodeAuthHeaders: () => ({}),
158
159
  getSmallModelService: async () => service,
160
+ isEnabled: () => true,
159
161
  idleQuietMs: 10,
160
162
  });
161
163
 
@@ -163,7 +165,7 @@ describe('session goal live activity gate', () => {
163
165
  type: 'session.status',
164
166
  properties: { sessionID: SESSION_ID, status: { type: 'idle' }, directory: DIRECTORY },
165
167
  });
166
- await vi.advanceTimersByTimeAsync(10);
168
+ await vi.runOnlyPendingTimersAsync();
167
169
 
168
170
  expect(service.generateSmallModelText).toHaveBeenCalledOnce();
169
171
  const patch = requests.find((request) => request.pathname === `/session/${SESSION_ID}` && request.method === 'PATCH');
@@ -103,18 +103,24 @@ other runtime API.
103
103
  `https://chatgpt.com/backend-api/codex/responses` with
104
104
  `ChatGPT-Account-Id`; expired tokens are refreshed against
105
105
  `auth.openai.com` (single-flight) and written back to `auth.json`.
106
- - **Anthropic** (`type: api`): `/v1/messages` with `x-api-key`.
106
+ - **Anthropic** (`type: api`): `/messages` with `x-api-key`, against
107
+ `provider.anthropic.options.baseURL` when configured (used as-is, matching
108
+ `@ai-sdk/anthropic` — no `/v1` is inserted) or `https://api.anthropic.com/v1`
109
+ otherwise.
107
110
  - **Google** (`type: api`): `generateContent` with `x-goog-api-key`; Gemini 3
108
- uses `thinkingLevel` while older Flash models use `thinkingBudget: 0`.
111
+ uses `thinkingLevel`, Gemini 2.x uses `thinkingBudget: 0`, and all other
112
+ models omit `thinkingConfig` entirely.
109
113
  - Everything else: OpenAI-compatible `/chat/completions` against the
110
114
  provider's base URL, resolved from (1) `provider.<id>.options.baseURL`
111
115
  in the OpenCode config, (2) the hardcoded `https://api.openai.com/v1`
112
116
  endpoint, (3) the endpoint OpenCode resolved at runtime, or (4) the
113
117
  provider's `api` field from the models.dev catalog. The credential follows
114
118
  the same shape: config `options.apiKey`, then the runtime credential, then
115
- the auth.json entry. Configured API keys honor OpenCode's `{env:NAME}` and
116
- `{file:path}` substitutions; file contents and resolved credentials remain
117
- server-side.
119
+ the auth.json entry. `provider.<id>.options.headers` is sent with the
120
+ request and overrides the bearer default, so gateways that authenticate on
121
+ their own header work here exactly as they do in a chat turn. Configured API
122
+ keys and header values honor OpenCode's `{env:NAME}` and `{file:path}`
123
+ substitutions; file contents and resolved credentials remain server-side.
118
124
  - The runtime credential is refused for providers listed in
119
125
  `OWN_CREDENTIAL_HANDLING`. Their branches need the stored entry rather than
120
126
  a bearer token: the clearest case is the ChatGPT-plan `openai` login, whose
@@ -2,7 +2,7 @@ import fs from 'fs';
2
2
  import os from 'os';
3
3
  import path from 'path';
4
4
  import { readAuthFile, writeAuthFile } from '../opencode/auth.js';
5
- import { readConfig, readConfigLayers } from '../opencode/shared.js';
5
+ import { readConfig, readConfigLayers, isPlainObject } from '../opencode/shared.js';
6
6
  import { getCatalogProvider } from './catalog.js';
7
7
  import { getAuthEntryForProvider } from './resolve.js';
8
8
  import { getRuntimeProvider } from './runtime-providers.js';
@@ -19,6 +19,18 @@ const DEFAULT_MAX_OUTPUT_TOKENS = 4_000;
19
19
 
20
20
  const USER_AGENT = 'opencode/1.0 openchamber';
21
21
 
22
+ const mergeHeadersCaseInsensitive = (base, overrides) => {
23
+ const merged = { ...base };
24
+ for (const [name, value] of Object.entries(overrides || {})) {
25
+ const existingName = Object.keys(merged).find((key) => key.toLowerCase() === name.toLowerCase());
26
+ if (existingName) {
27
+ delete merged[existingName];
28
+ }
29
+ merged[name] = value;
30
+ }
31
+ return merged;
32
+ };
33
+
22
34
  const CODEX_TOKEN_URL = 'https://auth.openai.com/oauth/token';
23
35
  const CODEX_CLIENT_ID = 'app_EMoamEEZ73f0CkXaXp7hrann';
24
36
  const CODEX_RESPONSES_URL = 'https://chatgpt.com/backend-api/codex/responses';
@@ -157,11 +169,10 @@ const callOpenaiCompatible = async ({ baseURL, headers, modelID, prompt, system,
157
169
  });
158
170
  const response = await fetch(`${trimmedBase}/chat/completions`, {
159
171
  method: 'POST',
160
- headers: {
172
+ headers: mergeHeadersCaseInsensitive({
161
173
  'Content-Type': 'application/json',
162
174
  Accept: 'application/json',
163
- ...headers,
164
- },
175
+ }, headers),
165
176
  body: JSON.stringify({
166
177
  model: modelID,
167
178
  messages: [
@@ -340,8 +351,11 @@ const callMessages = async ({ url, headers, modelID, prompt, system, maxOutputTo
340
351
  return text;
341
352
  };
342
353
 
343
- const callAnthropic = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({
344
- url: 'https://api.anthropic.com/v1/messages',
354
+ const callAnthropic = async ({ apiKey, baseURL, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => callMessages({
355
+ // Matches @ai-sdk/anthropic: baseURL is the full API prefix (commonly
356
+ // already ending in /v1), so it gets /messages appended as-is rather than
357
+ // having /v1/messages appended, which would double up a configured /v1.
358
+ url: `${(baseURL || 'https://api.anthropic.com/v1').replace(/\/+$/, '')}/messages`,
345
359
  headers: {
346
360
  'x-api-key': apiKey,
347
361
  'anthropic-version': '2023-06-01',
@@ -403,9 +417,10 @@ const getCopilotEndpoint = async ({ baseURL, headers, modelID }) => {
403
417
 
404
418
  const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, responseSchema, timeoutMs, signal }) => {
405
419
  const url = `https://generativelanguage.googleapis.com/v1beta/models/${encodeURIComponent(modelID)}:generateContent`;
406
- const thinkingConfig = modelID.toLowerCase().startsWith('gemini-3')
407
- ? { thinkingLevel: modelID.toLowerCase().includes('flash') ? 'minimal' : 'low' }
408
- : { thinkingBudget: 0 };
420
+ const lowerModelID = modelID.toLowerCase();
421
+ const thinkingConfig = lowerModelID.startsWith('gemini-3')
422
+ ? { thinkingLevel: lowerModelID.includes('flash') ? 'minimal' : 'low' }
423
+ : lowerModelID.startsWith('gemini-2') ? { thinkingBudget: 0 } : null;
409
424
  const response = await fetch(url, {
410
425
  method: 'POST',
411
426
  headers: {
@@ -415,13 +430,11 @@ const callGoogle = async ({ apiKey, modelID, prompt, system, maxOutputTokens, re
415
430
  },
416
431
  body: JSON.stringify({
417
432
  contents: [{ role: 'user', parts: [{ text: prompt }] }],
418
- ...(system ? { systemInstruction: { parts: [{ text: system }] } } : {}),
433
+ ...(system && { systemInstruction: { parts: [{ text: system }] } }),
419
434
  generationConfig: {
420
435
  maxOutputTokens,
421
- thinkingConfig,
422
- ...(responseSchema
423
- ? { responseMimeType: 'application/json', responseSchema: toGoogleSchema(responseSchema) }
424
- : {}),
436
+ ...(thinkingConfig && { thinkingConfig }),
437
+ ...(responseSchema && { responseMimeType: 'application/json', responseSchema: toGoogleSchema(responseSchema) }),
425
438
  },
426
439
  }),
427
440
  signal: requestSignal(timeoutMs, signal),
@@ -508,7 +521,7 @@ const callCodexResponses = async ({ accessToken, accountId, modelID, prompt, sys
508
521
  // Custom provider configuration support
509
522
  // ---------------------------------------------------------------------------
510
523
 
511
- const resolveConfigApiKey = (value, workingDirectory, providerID) => {
524
+ const resolveConfigValue = (value, workingDirectory, providerID, headerName = null) => {
512
525
  const envMatch = value.match(/^\{env:([^}]+)\}$/i);
513
526
  if (envMatch) {
514
527
  return process.env[envMatch[1].trim()]?.trim() || null;
@@ -529,7 +542,12 @@ const resolveConfigApiKey = (value, workingDirectory, providerID) => {
529
542
  { config: layers.customConfig, filePath: layers.paths.customPath },
530
543
  { config: layers.projectConfig, filePath: layers.paths.projectPath },
531
544
  { config: layers.userConfig, filePath: layers.paths.userPath },
532
- ].find(({ config }) => config?.provider?.[providerID]?.options?.apiKey === value);
545
+ ].find(({ config }) => {
546
+ const options = config?.provider?.[providerID]?.options;
547
+ return headerName
548
+ ? options?.headers?.[headerName] === value
549
+ : options?.apiKey === value;
550
+ });
533
551
  resolvedPath = path.resolve(source?.filePath ? path.dirname(source.filePath) : workingDirectory || process.cwd(), configuredPath);
534
552
  }
535
553
 
@@ -538,10 +556,33 @@ const resolveConfigApiKey = (value, workingDirectory, providerID) => {
538
556
  if (!key) throw new Error('empty file');
539
557
  return key;
540
558
  } catch {
541
- throw new Error(`Failed to resolve configured apiKey file for provider "${providerID}"`);
559
+ throw new Error(`Failed to resolve configured ${headerName ? `header "${headerName}"` : 'apiKey'} file for provider "${providerID}"`);
542
560
  }
543
561
  };
544
562
 
563
+ /**
564
+ * `options.headers` from the provider config, with the same `{env:…}`/`{file:…}`
565
+ * substitutions the API key gets.
566
+ *
567
+ * OpenCode sends these on every request, so dropping them here would have the
568
+ * small model authenticating differently from the request path against the same
569
+ * URL. Gateways fronted by an API-management layer reject a bearer-only request
570
+ * outright, because the header is the credential rather than a supplement to it.
571
+ */
572
+ const readConfiguredHeaders = (providerCfg, workingDirectory, providerID) => {
573
+ const configured = providerCfg?.options?.headers;
574
+ if (!isPlainObject(configured)) return null;
575
+ const headers = {};
576
+ for (const [name, value] of Object.entries(configured)) {
577
+ // Config headers are strings; a malformed entry is skipped rather than
578
+ // stringified into a header the gateway would reject.
579
+ if (String(value) !== value) continue;
580
+ const resolved = resolveConfigValue(value.trim(), workingDirectory, providerID, name);
581
+ if (resolved) headers[name] = resolved;
582
+ }
583
+ return Object.keys(headers).length ? headers : null;
584
+ };
585
+
545
586
  const readProviderConfig = (workingDirectory, providerID) => {
546
587
  try {
547
588
  const config = readConfig(workingDirectory);
@@ -549,9 +590,10 @@ const readProviderConfig = (workingDirectory, providerID) => {
549
590
  if (!providerCfg || typeof providerCfg !== 'object') return null;
550
591
  const baseURL = typeof providerCfg?.options?.baseURL === 'string' ? providerCfg.options.baseURL.trim() : null;
551
592
  const rawApiKey = typeof providerCfg?.options?.apiKey === 'string' ? providerCfg.options.apiKey.trim() : null;
552
- const apiKey = rawApiKey ? resolveConfigApiKey(rawApiKey, workingDirectory, providerID) : null;
593
+ const apiKey = rawApiKey ? resolveConfigValue(rawApiKey, workingDirectory, providerID) : null;
553
594
  return {
554
595
  baseURL,
596
+ headers: readConfiguredHeaders(providerCfg, workingDirectory, providerID),
555
597
  // Shape the config-supplied key as a regular api-key auth entry so it
556
598
  // can win the precedence check below and flow through the dispatch's
557
599
  // `entry.type === 'api' ? entry.key : ...` branch unchanged.
@@ -706,7 +748,7 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
706
748
  }
707
749
 
708
750
  if (providerID === 'anthropic') {
709
- return callAnthropic({ apiKey, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
751
+ return callAnthropic({ apiKey, baseURL: providerConfig?.baseURL, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
710
752
  }
711
753
  if (providerID === 'google') {
712
754
  return callGoogle({ apiKey, modelID, prompt, system, maxOutputTokens: tokens, responseSchema, timeoutMs, signal });
@@ -751,7 +793,9 @@ export async function callSmallModel({ auth, catalog, workingDirectory, provider
751
793
 
752
794
  return callOpenaiCompatible({
753
795
  baseURL,
754
- headers: { Authorization: `Bearer ${apiKey}` },
796
+ // Configured headers last: a gateway that authenticates on its own header
797
+ // must be able to override the bearer default rather than sit beside it.
798
+ headers: mergeHeadersCaseInsensitive({ Authorization: `Bearer ${apiKey}` }, providerConfig?.headers),
755
799
  modelID,
756
800
  prompt,
757
801
  system,
@@ -5,11 +5,14 @@ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
5
5
 
6
6
  // readConfig reads merged opencode config layers from disk; mock it so each
7
7
  // test controls the provider config without touching the filesystem. call.js
8
- // imports only readConfig from shared.js, so the rest of that module is left
9
- // untouched for this file.
8
+ // imports the config readers and a plain-object predicate from shared.js, so
9
+ // the rest of that module is left untouched for this file.
10
10
  vi.mock('../opencode/shared.js', () => ({
11
11
  readConfig: vi.fn(),
12
12
  readConfigLayers: vi.fn(),
13
+ // Pure predicate with no disk access — the real implementation, so header
14
+ // parsing is exercised rather than stubbed.
15
+ isPlainObject: (value) => value instanceof Object && !Array.isArray(value),
13
16
  }));
14
17
 
15
18
  vi.mock('./runtime-providers.js', () => ({ getRuntimeProvider: vi.fn(async () => null) }));
@@ -67,6 +70,7 @@ describe('callSmallModel — custom provider config', () => {
67
70
  globalThis.fetch = originalFetch;
68
71
  vi.restoreAllMocks();
69
72
  delete process.env.OPENCHAMBER_TEST_PROVIDER_KEY;
73
+ delete process.env.OPENCHAMBER_TEST_GATEWAY_KEY;
70
74
  });
71
75
 
72
76
  describe('config-supplied credentials (no auth.json entry)', () => {
@@ -122,6 +126,105 @@ describe('callSmallModel — custom provider config', () => {
122
126
  expect(lastCall(fetchMock).init.headers.Authorization).toBe('Bearer sk-env-key');
123
127
  });
124
128
 
129
+ it('sends configured provider headers alongside the bearer token', async () => {
130
+ process.env.OPENCHAMBER_TEST_GATEWAY_KEY = 'sub-key';
131
+ readConfig.mockReturnValue({
132
+ provider: {
133
+ custom: {
134
+ options: {
135
+ apiKey: 'sk-config',
136
+ baseURL: 'https://proxy.example.test/v1',
137
+ headers: {
138
+ 'Ocp-Apim-Subscription-Key': '{env:OPENCHAMBER_TEST_GATEWAY_KEY}',
139
+ 'x-tenant': 'team',
140
+ },
141
+ },
142
+ },
143
+ },
144
+ });
145
+ fetchMock.mockResolvedValue(ok('hello'));
146
+
147
+ await callSmallModel({
148
+ auth: {},
149
+ catalog: {},
150
+ workingDirectory: '/proj',
151
+ providerID: 'custom',
152
+ modelID: 'model',
153
+ prompt: 'hi',
154
+ });
155
+
156
+ const { init } = lastCall(fetchMock);
157
+ expect(init.headers['Ocp-Apim-Subscription-Key']).toBe('sub-key');
158
+ expect(init.headers['x-tenant']).toBe('team');
159
+ expect(init.headers.Authorization).toBe('Bearer sk-config');
160
+ });
161
+
162
+ it('resolves a relative header file from the config layer that defines it', async () => {
163
+ const configPath = '/config/opencode.json';
164
+ const secretPath = '/config/gateway-key';
165
+ vi.spyOn(fs, 'readFileSync').mockImplementation((filePath) => {
166
+ if (filePath === secretPath) return 'sub-key\n';
167
+ throw new Error(`Unexpected file read: ${filePath}`);
168
+ });
169
+ const provider = {
170
+ custom: {
171
+ options: {
172
+ apiKey: 'sk-config',
173
+ baseURL: 'https://proxy.example.test/v1',
174
+ headers: { 'x-gateway-key': '{file:./gateway-key}' },
175
+ },
176
+ },
177
+ };
178
+ readConfig.mockReturnValue({ provider });
179
+ readConfigLayers.mockReturnValue({
180
+ customConfig: {},
181
+ projectConfig: {},
182
+ userConfig: { provider },
183
+ paths: { customPath: null, projectPath: '/project/opencode.json', userPath: configPath },
184
+ });
185
+ fetchMock.mockResolvedValue(ok('hello'));
186
+
187
+ await callSmallModel({
188
+ auth: {},
189
+ catalog: {},
190
+ workingDirectory: '/project',
191
+ providerID: 'custom',
192
+ modelID: 'model',
193
+ prompt: 'hi',
194
+ });
195
+
196
+ expect(lastCall(fetchMock).init.headers['x-gateway-key']).toBe('sub-key');
197
+ expect(fs.readFileSync).toHaveBeenCalledWith(secretPath, 'utf8');
198
+ });
199
+
200
+ it('overrides Authorization without depending on header-name casing', async () => {
201
+ readConfig.mockReturnValue({
202
+ provider: {
203
+ custom: {
204
+ options: {
205
+ apiKey: 'sk-config',
206
+ baseURL: 'https://proxy.example.test/v1',
207
+ headers: { authorization: 'Basic gateway-token' },
208
+ },
209
+ },
210
+ },
211
+ });
212
+ fetchMock.mockResolvedValue(ok('hello'));
213
+
214
+ await callSmallModel({
215
+ auth: {},
216
+ catalog: {},
217
+ workingDirectory: '/project',
218
+ providerID: 'custom',
219
+ modelID: 'model',
220
+ prompt: 'hi',
221
+ });
222
+
223
+ const headers = lastCall(fetchMock).init.headers;
224
+ expect(headers.authorization).toBe('Basic gateway-token');
225
+ expect(headers.Authorization).toBeUndefined();
226
+ });
227
+
125
228
  it('uses apiKey and baseURL from provider config when no auth.json entry exists', async () => {
126
229
  readConfig.mockReturnValue({
127
230
  provider: {
@@ -316,6 +419,69 @@ describe('callSmallModel — custom provider config', () => {
316
419
  });
317
420
  });
318
421
 
422
+ describe('anthropic provider custom baseURL override', () => {
423
+ const anthropicOk = (text) => ({
424
+ ok: true,
425
+ status: 200,
426
+ json: async () => ({ content: [{ type: 'text', text }] }),
427
+ });
428
+
429
+ it('respects provider.anthropic.options.baseURL over the hardcoded Anthropic endpoint', async () => {
430
+ readConfig.mockReturnValue({
431
+ provider: { anthropic: { options: { baseURL: 'http://127.0.0.1:3456/v1' } } },
432
+ });
433
+ fetchMock.mockResolvedValue(anthropicOk('ok'));
434
+
435
+ await callSmallModel({
436
+ auth: { anthropic: { type: 'api', key: 'dummy' } },
437
+ catalog: {},
438
+ workingDirectory: '/proj',
439
+ providerID: 'anthropic',
440
+ modelID: 'claude-haiku-4-5',
441
+ prompt: 'hi',
442
+ });
443
+
444
+ const { url, init } = lastCall(fetchMock);
445
+ expect(url).toBe('http://127.0.0.1:3456/v1/messages');
446
+ expect(url).not.toContain('api.anthropic.com');
447
+ expect(init.headers['x-api-key']).toBe('dummy');
448
+ });
449
+
450
+ it('uses a bare-host baseURL as-is without inserting /v1, matching @ai-sdk/anthropic', async () => {
451
+ readConfig.mockReturnValue({
452
+ provider: { anthropic: { options: { baseURL: 'http://127.0.0.1:3456' } } },
453
+ });
454
+ fetchMock.mockResolvedValue(anthropicOk('ok'));
455
+
456
+ await callSmallModel({
457
+ auth: { anthropic: { type: 'api', key: 'dummy' } },
458
+ catalog: {},
459
+ workingDirectory: '/proj',
460
+ providerID: 'anthropic',
461
+ modelID: 'claude-haiku-4-5',
462
+ prompt: 'hi',
463
+ });
464
+
465
+ expect(lastCall(fetchMock).url).toBe('http://127.0.0.1:3456/messages');
466
+ });
467
+
468
+ it('falls back to https://api.anthropic.com when no anthropic baseURL override is configured', async () => {
469
+ readConfig.mockReturnValue({});
470
+ fetchMock.mockResolvedValue(anthropicOk('ok'));
471
+
472
+ await callSmallModel({
473
+ auth: { anthropic: { type: 'api', key: 'sk-ant' } },
474
+ catalog: {},
475
+ workingDirectory: '/proj',
476
+ providerID: 'anthropic',
477
+ modelID: 'claude-haiku-4-5',
478
+ prompt: 'hi',
479
+ });
480
+
481
+ expect(lastCall(fetchMock).url).toBe('https://api.anthropic.com/v1/messages');
482
+ });
483
+ });
484
+
319
485
  describe('catalog-based base URL (no config override)', () => {
320
486
  it('uses the catalog api field when no config baseURL is set', async () => {
321
487
  readConfig.mockReturnValue({});
@@ -536,6 +702,22 @@ describe('callSmallModel — Google thinking configuration', () => {
536
702
  const body = JSON.parse(lastCall(fetchMock).init.body);
537
703
  expect(body.generationConfig.thinkingConfig).toEqual({ thinkingBudget: 0 });
538
704
  });
705
+
706
+ it('omits thinkingConfig for other Google/Gemini models', async () => {
707
+ fetchMock.mockResolvedValue(googleResponse('generated commit'));
708
+
709
+ await callSmallModel({
710
+ auth: { google: { type: 'api', key: 'google-key' } },
711
+ catalog: {},
712
+ workingDirectory: '/proj',
713
+ providerID: 'google',
714
+ modelID: 'gemini-1.5-flash',
715
+ prompt: 'generate',
716
+ });
717
+
718
+ const body = JSON.parse(lastCall(fetchMock).init.body);
719
+ expect(body.generationConfig.thinkingConfig).toBeUndefined();
720
+ });
539
721
  });
540
722
 
541
723
  describe('callSmallModel — GitHub Copilot endpoint routing', () => {
@@ -19,6 +19,8 @@
19
19
 
20
20
  HTTP remains the authenticated command plane for create, resize, appearance updates, restart, close, and force-kill. There is no SSE output or HTTP input compatibility path.
21
21
 
22
+ `GET /api/terminal/sessions` enumerates live sessions (optionally filtered by resolved `cwd`) so clients can adopt terminals their local tab projection does not know about — another device, a new browser tab, or cleared storage. `POST /api/terminal/touch` refreshes `lastActivity` for the listed session ids; open clients call it periodically so background tabs, which hold no WebSocket attachment, are not idle-reaped while a client still shows them.
23
+
22
24
  ## PTY Lifecycle
23
25
 
24
26
  - IDs are client-provided or generated with `randomUUID()`.
@@ -228,7 +228,7 @@ export function createTerminalRuntime({
228
228
  }
229
229
  if (!existing && sessions.size + pendingSessionCreates.size >= MAX_SESSIONS) throw new Error('Maximum terminal sessions reached');
230
230
  const creation = (async () => {
231
- const session = existing ?? { id, sequence: 0, history: '', pendingHistoryControlSequence: '', pendingThemeControlSequence: '', eventQueue: [], draining: false };
231
+ const session = existing ?? { id, sequence: 0, history: '', pendingHistoryControlSequence: '', pendingThemeControlSequence: '', eventQueue: [], draining: false, createdAt: Date.now() };
232
232
  await startSession(session, { cwd, cols, rows, themeMode, terminalBackground, terminalForeground, shell: normalizedShell, loginShell });
233
233
  sessions.set(id, session);
234
234
  return session;
@@ -297,6 +297,34 @@ export function createTerminalRuntime({
297
297
  res.status(500).json({ error: error?.message || 'Failed to list terminal shells' });
298
298
  }
299
299
  });
300
+ app.get('/api/terminal/sessions', (req, res) => {
301
+ const rawCwd = typeof req.query?.cwd === 'string' ? req.query.cwd.trim() : '';
302
+ const cwdFilter = rawCwd ? path.resolve(rawCwd) : null;
303
+ const list = [];
304
+ for (const session of sessions.values()) {
305
+ if (cwdFilter && path.resolve(session.cwd) !== cwdFilter) continue;
306
+ list.push({
307
+ sessionId: session.id,
308
+ cwd: session.cwd,
309
+ status: session.status,
310
+ createdAt: Number.isInteger(session.createdAt) ? session.createdAt : null,
311
+ });
312
+ }
313
+ res.json({ sessions: list });
314
+ });
315
+ app.post('/api/terminal/touch', (req, res) => {
316
+ const rawIds = Array.isArray(req.body?.sessionIds) ? req.body.sessionIds : [];
317
+ const now = Date.now();
318
+ let touched = 0;
319
+ for (const id of rawIds) {
320
+ if (typeof id !== 'string') continue;
321
+ const session = sessions.get(id);
322
+ if (!session) continue;
323
+ session.lastActivity = now;
324
+ touched += 1;
325
+ }
326
+ res.json({ touched });
327
+ });
300
328
  app.post('/api/terminal/create', async (req, res) => {
301
329
  try { const session = await createSession(req.body ?? {}); res.json({ sessionId: session.id, cols: session.cols, rows: session.rows, status: session.status }); }
302
330
  catch (error) { res.status(error?.message === 'Maximum terminal sessions reached' ? 429 : 400).json({ error: error?.message || 'Failed to create terminal session' }); }
@@ -179,6 +179,32 @@ describe('terminal runtime', () => {
179
179
  } finally { await harness.runtime.shutdown(); }
180
180
  });
181
181
 
182
+ it('lists sessions scoped to a working directory and refreshes activity via touch', async () => {
183
+ const harness = createHarness();
184
+ try {
185
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'term-a', cwd: '/repo' } }, createResponse());
186
+ await harness.routes.post.get('/api/terminal/create')({ body: { sessionId: 'term-b', cwd: '/other' } }, createResponse());
187
+
188
+ const all = createResponse();
189
+ harness.routes.get.get('/api/terminal/sessions')({ query: {} }, all);
190
+ expect(all.body.sessions.map((s) => s.sessionId).sort()).toEqual(['term-a', 'term-b']);
191
+
192
+ const scoped = createResponse();
193
+ harness.routes.get.get('/api/terminal/sessions')({ query: { cwd: '/repo' } }, scoped);
194
+ expect(scoped.body.sessions).toEqual([
195
+ { sessionId: 'term-a', cwd: '/repo', status: 'running', createdAt: expect.any(Number) },
196
+ ]);
197
+
198
+ const touch = createResponse();
199
+ harness.routes.post.get('/api/terminal/touch')({ body: { sessionIds: ['term-a', 'missing', 42] } }, touch);
200
+ expect(touch.body).toEqual({ touched: 1 });
201
+
202
+ const malformed = createResponse();
203
+ harness.routes.post.get('/api/terminal/touch')({ body: {} }, malformed);
204
+ expect(malformed.body).toEqual({ touched: 0 });
205
+ } finally { await harness.runtime.shutdown(); }
206
+ });
207
+
182
208
  it('strips AppImage ARGV0 from PTY child environments', async () => {
183
209
  const previousArgv0 = process.env.ARGV0;
184
210
  process.env.ARGV0 = '/path/to/OpenChamber/OpenChamber-1.17.2-linux-x86_64.AppImage';
@@ -6,11 +6,11 @@ import {
6
6
  const PROVIDER_INSTALL_INFO = {
7
7
  [TUNNEL_PROVIDER_CLOUDFLARE]: {
8
8
  dependency: 'cloudflared',
9
- installUrl: 'https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/',
9
+ installUrl: 'https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/',
10
10
  commands: {
11
11
  darwin: 'brew install cloudflared',
12
12
  win32: 'winget install --id Cloudflare.cloudflared',
13
- linux: 'Download cloudflared from https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflared/downloads/',
13
+ linux: 'Download cloudflared from https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/',
14
14
  },
15
15
  },
16
16
  [TUNNEL_PROVIDER_NGROK]: {
@@ -28,4 +28,13 @@ describe('getTunnelDependencyInstallInfo', () => {
28
28
 
29
29
  expect(info.installCommand).toBe('brew install cloudflared');
30
30
  });
31
+
32
+ it('returns the current Linux cloudflared download guidance', () => {
33
+ const info = getTunnelDependencyInstallInfo(TUNNEL_PROVIDER_CLOUDFLARE, 'linux');
34
+ const downloadUrl = 'https://developers.cloudflare.com/cloudflare-one/networks/connectors/cloudflare-tunnel/downloads/';
35
+
36
+ expect(info.installUrl).toBe(downloadUrl);
37
+ expect(info.installCommand).toBe(`Download cloudflared from ${downloadUrl}`);
38
+ expect(info.message).toContain(downloadUrl);
39
+ });
31
40
  });
@@ -839,7 +839,7 @@ export const createUiAuth = ({
839
839
  let clientTokenResult = null;
840
840
  if (req.body?.issueClientToken === true && typeof clientAuthController?.createClient === 'function') {
841
841
  clientTokenResult = await clientAuthController.createClient({
842
- label: req.body?.clientLabel,
842
+ fallbackLabel: req.body?.clientLabel,
843
843
  expiresAt: new Date(Date.now() + ttlMs).toISOString(),
844
844
  clientKind: req.body?.clientKind,
845
845
  dedupeKey: req.body?.dedupeKey,
@@ -907,7 +907,7 @@ export const createUiAuth = ({
907
907
  let clientTokenResult = null;
908
908
  if (req.body?.issueClientToken === true && typeof clientAuthController?.createClient === 'function') {
909
909
  clientTokenResult = await clientAuthController.createClient({
910
- label: req.body?.clientLabel,
910
+ fallbackLabel: req.body?.clientLabel,
911
911
  expiresAt: new Date(Date.now() + ttlMs).toISOString(),
912
912
  clientKind: req.body?.clientKind,
913
913
  dedupeKey: req.body?.dedupeKey,
@@ -269,7 +269,7 @@ describe('ui auth client credential seam', () => {
269
269
  token: 'client-token',
270
270
  client: {
271
271
  id: 'device-1',
272
- label: input.label,
272
+ label: input.label ?? input.fallbackLabel,
273
273
  createdAt: new Date().toISOString(),
274
274
  lastUsedAt: null,
275
275
  revokedAt: null,
@@ -295,7 +295,7 @@ describe('ui auth client credential seam', () => {
295
295
  await auth.handleSessionCreate(req, res);
296
296
 
297
297
  expect(res.body.clientToken).toBe('client-token');
298
- expect(createClientInput.label).toBe('OpenChamber Desktop');
298
+ expect(createClientInput.fallbackLabel).toBe('OpenChamber Desktop');
299
299
  const expiresAt = Date.parse(createClientInput.expiresAt);
300
300
  expect(expiresAt).toBeGreaterThanOrEqual(before + 122_000);
301
301
  expect(expiresAt).toBeLessThanOrEqual(Date.now() + 124_000);
@@ -27,6 +27,7 @@ const LANGUAGE_NAMES = {
27
27
  ko: 'Korean',
28
28
  pl: 'Polish',
29
29
  ja: 'Japanese',
30
+ tr: 'Turkish',
30
31
  };
31
32
 
32
33
  /**