@openchamber/web 2.3.2 → 2.3.3

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 (213) hide show
  1. package/dist/assets/{AboutDialog-MZbHWRua.js → AboutDialog-Ctk2zvrv.js} +1 -1
  2. package/dist/assets/{ArchiveView-CkeSWPcI.js → ArchiveView-sbNreasJ.js} +1 -1
  3. package/dist/assets/{CommandPalette-CtKzNzwW.js → CommandPalette-BICwnwAZ.js} +2 -2
  4. package/dist/assets/{DiffView-DaXjHTAq.js → DiffView-B5yeuxv8.js} +1 -1
  5. package/dist/assets/{FilesView-DMNYEydF.js → FilesView-ni2zfAwL.js} +7 -7
  6. package/dist/assets/{GitView-HXttTpUw.js → GitView-C0QgeC9O.js} +3 -3
  7. package/dist/assets/{GuestSurfacePane-KzguENQG.js → GuestSurfacePane-D1gLktSj.js} +1 -1
  8. package/dist/assets/{HelpDialog-9YZGhBgT.js → HelpDialog-CxC6qTaS.js} +1 -1
  9. package/dist/assets/{InProgressOperationBanner-DzGIwGH2.js → InProgressOperationBanner-JFV70YFh.js} +1 -1
  10. package/dist/assets/{JsonTreeView-D9rP8jM8.js → JsonTreeView-RsbV4Usa.js} +1 -1
  11. package/dist/assets/MarkdownRendererImpl-CZK5DoOX.js +1 -0
  12. package/dist/assets/{MemoryDebugPanel-Ct0h3RWh.js → MemoryDebugPanel-caUWOKiz.js} +1 -1
  13. package/dist/assets/{OnboardingScreen-B5Zzb1Mp.js → OnboardingScreen-BDT-J2JP.js} +1 -1
  14. package/dist/assets/{OpenCodeStatusDialog-CXBWWRh8.js → OpenCodeStatusDialog-Cxa2yqOB.js} +1 -1
  15. package/dist/assets/{PatchDiff-DhDAQ5em.js → PatchDiff-C1pnbAsJ.js} +1 -1
  16. package/dist/assets/{PierreDiffViewer-DPa08AmN.js → PierreDiffViewer-D0zX2Msu.js} +1 -1
  17. package/dist/assets/PlanView-BxRCMuGe.js +5 -0
  18. package/dist/assets/{ProjectActionsDialog-DATu0aBc.js → ProjectActionsDialog-D660By4K.js} +1 -1
  19. package/dist/assets/{RunOverview-D6xy_vME.js → RunOverview-C1uTMnQS.js} +2 -2
  20. package/dist/assets/{ScheduledTasksDialog-BWXVnfrf.js → ScheduledTasksDialog-S-gAgo7Z.js} +5 -5
  21. package/dist/assets/SettingsView-CVpfbdob.js +30 -0
  22. package/dist/assets/{SettingsWindow-Cx6TrtY0.js → SettingsWindow-Dd1hHvgh.js} +1 -1
  23. package/dist/assets/SourceBoardView-DbGWAxtS.js +1 -0
  24. package/dist/assets/SpaceAccessDialog-muTSsEJ9.js +1 -0
  25. package/dist/assets/{SpaceApplyDialog-BtuwtlaG.js → SpaceApplyDialog-Dsf6MNGm.js} +1 -1
  26. package/dist/assets/{SpaceRow-MXqvd-dr.js → SpaceRow-7Z6ebRtm.js} +1 -1
  27. package/dist/assets/{SpaceSetupOutput-Uo5LS7Jy.js → SpaceSetupOutput-BytPfCOC.js} +1 -1
  28. package/dist/assets/{SpacesView-DvoOh4sM.js → SpacesView-CYCrlp0D.js} +1 -1
  29. package/dist/assets/{SubmoduleDiffSummary-CyMwDeoP.js → SubmoduleDiffSummary-VrNUbIqF.js} +1 -1
  30. package/dist/assets/{ToolOutputDialog-BaUZIVzc.js → ToolOutputDialog-DHORjBND.js} +7 -7
  31. package/dist/assets/{ToolPartDiffPreview-DmMwdcF4.js → ToolPartDiffPreview-BLAXe7C5.js} +1 -1
  32. package/dist/assets/{UsageStatsView-D7WrDBTC.js → UsageStatsView-BxtYEAa0.js} +1 -1
  33. package/dist/assets/{Virtualizer-CnU8pYMb.js → Virtualizer-Bl4Cf-H-.js} +1 -1
  34. package/dist/assets/{WalkthroughView-r0Ho9F4Z.js → WalkthroughView-B2BJJ4u5.js} +2 -2
  35. package/dist/assets/{WorktreesView-C-t7uxq1.js → WorktreesView-Dv0AO9dF.js} +1 -1
  36. package/dist/assets/{appThemeRegistry-BUY7Ge9i.js → appThemeRegistry-xm_W0svA.js} +1 -1
  37. package/dist/assets/{ar-HauNhDvN.js → ar-Cj8UF12m.js} +4 -4
  38. package/dist/assets/{computeVirtualFileMetrics-CUof18z3.js → computeVirtualFileMetrics-Cx05cmWI.js} +2 -2
  39. package/dist/assets/{de-fEoJ_Yyp.js → de-fSQ1ho01.js} +4 -4
  40. package/dist/assets/{decorate-BkTSGAlD.js → decorate-jpF7GA6t.js} +2 -2
  41. package/dist/assets/{es-CKNTBsZW.js → es-DrdzhSlK.js} +5 -5
  42. package/dist/assets/{fileContentPoller-BJWgy1fX.js → fileContentPoller-C0f20jNG.js} +3 -3
  43. package/dist/assets/{flexokiTheme-BArobfXV.js → flexokiTheme-DKNCYSqL.js} +1 -1
  44. package/dist/assets/{fr-C23655Pi.js → fr-Cmz6Da4q.js} +4 -4
  45. package/dist/assets/{he-CphXS_Fv.js → he-COJRUNy4.js} +4 -4
  46. package/dist/assets/{index-B27cSA9V.js → index-C8Mw8uvl.js} +1 -1
  47. package/dist/assets/{initializeSharedPreferences-CucsmDMw.js → initializeSharedPreferences-U9-v9mfq.js} +1 -1
  48. package/dist/assets/{isDiffPlainText-DSCjvV0m.js → isDiffPlainText-DW43IghW.js} +1 -1
  49. package/dist/assets/{isFilePlainText-C7g4UPox.js → isFilePlainText-Duq5CiuG.js} +1 -1
  50. package/dist/assets/{ja-BmsU2iQe.js → ja-Ce0NvDHZ.js} +4 -4
  51. package/dist/assets/katex-BZNCT55U.css +1 -0
  52. package/dist/assets/katex.min-EZjpSwGK.js +65 -0
  53. package/dist/assets/{ko-CxISpkje.js → ko-BGFcCLLq.js} +4 -4
  54. package/dist/assets/main-BUetg9hg.js +1048 -0
  55. package/dist/assets/{main-CGPiw9fS.js → main-Be_jmIlF.js} +2 -2
  56. package/dist/assets/markdownCore-BkTeS4gA.js +10 -0
  57. package/dist/assets/{miniChat-DVEKVYKe.js → miniChat-g1RgiLLS.js} +2 -2
  58. package/dist/assets/{mobile-Q_FVBe4I.js → mobile-DBli3U-T.js} +2 -2
  59. package/dist/assets/{moveWorkspacePath-CyZJ-2aD.js → moveWorkspacePath-CnYc96Xo.js} +1 -1
  60. package/dist/assets/{nl-jnTBQ_gU.js → nl-Cu1nxo5t.js} +4 -4
  61. package/dist/assets/{parseDiffFromFile-OHXXXyzL.js → parseDiffFromFile-DEjkjYod.js} +3 -3
  62. package/dist/assets/{patchFileDiff-BZrb6h2u.js → patchFileDiff-D__42sau.js} +5 -5
  63. package/dist/assets/{pierreDiffTint-DHf2xvyt.js → pierreDiffTint-3oatL635.js} +4 -4
  64. package/dist/assets/pl-4LdEMgWI.js +20 -0
  65. package/dist/assets/{pt-BR-BfpsFrHv.js → pt-BR-2UbEBNgC.js} +5 -5
  66. package/dist/assets/{relocateRestoredSession-DInneXVI.js → relocateRestoredSession-pkxyd_lV.js} +1 -1
  67. package/dist/assets/renderElectronMiniChatApp-D0tKJFBB.js +2 -0
  68. package/dist/assets/renderMobileApp-D6bOYHuP.js +25 -0
  69. package/dist/assets/{restartOpenCode-DwBaMPJK.js → restartOpenCode-FYqjpaWc.js} +1 -1
  70. package/dist/assets/runtimeEndpointReset-6CNNzem4.js +74 -0
  71. package/dist/assets/{scheduledTasksApi-ClJplEhR.js → scheduledTasksApi-BbnQ4W-W.js} +1 -1
  72. package/dist/assets/{selectionMarkdown-BuveYuup.js → selectionMarkdown-D8QAxC44.js} +1 -1
  73. package/dist/assets/sessionOwnership-BBuf0UCB.js +1 -0
  74. package/dist/assets/{shikiHighlight-DJAESrna.js → shikiHighlight-CweIj1cL.js} +1 -1
  75. package/dist/assets/{space-apply-DWFLwXbI.js → space-apply-CEi013sa.js} +1 -1
  76. package/dist/assets/{space-close-BYDbwdWc.js → space-close-BuStkLrZ.js} +1 -1
  77. package/dist/assets/{spaceNetwork-DHrhfbKM.js → spaceNetwork-tH2d5Mgs.js} +1 -1
  78. package/dist/assets/{textMateThemeFromAppTheme-DcAZmUlv.js → textMateThemeFromAppTheme-DLJBL6al.js} +1 -1
  79. package/dist/assets/tr-Bg0Qt-mG.js +11 -0
  80. package/dist/assets/{uk-C82aEtvs.js → uk-vcnOugr0.js} +5 -5
  81. package/dist/assets/useAppFontEffects-Cs6k0JKv.js +773 -0
  82. package/dist/assets/{useCallableModelProviders-BU_455MN.js → useCallableModelProviders-BsGEzsl2.js} +1 -1
  83. package/dist/assets/{useInlineCommentController-AuUrVz9U.js → useInlineCommentController-CVYaPzfO.js} +2 -2
  84. package/dist/assets/{useRootScrollLock-Cpk7NmBa.js → useRootScrollLock-Dov-44ov.js} +2 -2
  85. package/dist/assets/{vendor-codemirror-language-data-BYGweLoh.js → vendor-codemirror-language-data-DBekkZIx.js} +2 -2
  86. package/dist/assets/vendor-tanstack-react-virtual-Dozz-7fb.js +1 -0
  87. package/dist/assets/vendor-tanstack-virtual-core-DKBj55Em.js +1 -0
  88. package/dist/assets/{vendor-yaml-3778uTud.js → vendor-yaml-CE-D_49-.js} +1 -1
  89. package/dist/assets/{zh-CN-DEq7j9I5.js → zh-CN-C3UhwFsk.js} +5 -5
  90. package/dist/assets/{zh-TW-DgCN99T-.js → zh-TW-D0CmmMvp.js} +5 -5
  91. package/dist/index.html +3 -3
  92. package/dist/mini-chat.html +3 -3
  93. package/dist/mobile.html +3 -3
  94. package/package.json +5 -5
  95. package/server/index.js +13 -1
  96. package/server/lib/agent-memory/actions.js +22 -9
  97. package/server/lib/agent-memory/actions.test.js +57 -0
  98. package/server/lib/agent-memory/runtime.js +8 -5
  99. package/server/lib/agent-tool/DOCUMENTATION.md +17 -1
  100. package/server/lib/agent-tool/runtime.js +41 -7
  101. package/server/lib/agent-tool/runtime.test.js +11 -0
  102. package/server/lib/git/DOCUMENTATION.md +17 -5
  103. package/server/lib/git/lfs-discovery.js +7 -4
  104. package/server/lib/git/lfs-discovery.test.js +60 -0
  105. package/server/lib/git/network-operations.js +9 -3
  106. package/server/lib/git/network-operations.test.js +31 -2
  107. package/server/lib/git/service.js +72 -12
  108. package/server/lib/git/service.test.js +65 -0
  109. package/server/lib/github/DOCUMENTATION.md +1 -0
  110. package/server/lib/github/reference-search.js +49 -18
  111. package/server/lib/github/reference-search.test.js +28 -6
  112. package/server/lib/github/routes.js +87 -1
  113. package/server/lib/github/routes.mutations.test.js +38 -0
  114. package/server/lib/github/routes.test.js +1 -0
  115. package/server/lib/gitlab/DOCUMENTATION.md +4 -0
  116. package/server/lib/gitlab/client.js +23 -0
  117. package/server/lib/gitlab/client.test.js +28 -1
  118. package/server/lib/gitlab/mappers.js +9 -0
  119. package/server/lib/gitlab/resources.js +153 -4
  120. package/server/lib/gitlab/resources.test.js +107 -0
  121. package/server/lib/gitlab/routes.js +120 -1
  122. package/server/lib/gitlab/routes.test.js +59 -0
  123. package/server/lib/markdown-image-grants/DOCUMENTATION.md +4 -0
  124. package/server/lib/markdown-image-grants/routes.js +14 -2
  125. package/server/lib/markdown-image-grants/routes.test.js +23 -0
  126. package/server/lib/notifications/APNS.md +24 -23
  127. package/server/lib/notifications/DOCUMENTATION.md +2 -2
  128. package/server/lib/notifications/apns-runtime.js +8 -5
  129. package/server/lib/notifications/apns-runtime.test.js +26 -0
  130. package/server/lib/notifications/message.js +5 -3
  131. package/server/lib/notifications/message.test.js +9 -0
  132. package/server/lib/notifications/runtime.js +44 -9
  133. package/server/lib/notifications/trigger-runtime.test.js +84 -0
  134. package/server/lib/openchamber-control/DOCUMENTATION.md +6 -1
  135. package/server/lib/openchamber-control/actions.js +18 -2
  136. package/server/lib/openchamber-control/project-knowledge.js +17 -3
  137. package/server/lib/openchamber-control/project-knowledge.test.js +14 -0
  138. package/server/lib/openchamber-control/render-page.js +58 -0
  139. package/server/lib/openchamber-control/service.js +9 -0
  140. package/server/lib/openchamber-control/service.test.js +43 -0
  141. package/server/lib/openchamber-sessions/routes.js +1 -0
  142. package/server/lib/openchamber-sessions/worktree-move.js +26 -10
  143. package/server/lib/openchamber-sessions/worktree-move.test.js +36 -0
  144. package/server/lib/opencode/DOCUMENTATION.md +1 -1
  145. package/server/lib/opencode/managed-config-file.js +3 -2
  146. package/server/lib/opencode/managed-config-file.test.js +20 -6
  147. package/server/lib/opencode/settings-helpers.js +3 -0
  148. package/server/lib/opencode/settings-helpers.test.js +1 -1
  149. package/server/lib/opencode/settings-registry.json +3 -0
  150. package/server/lib/opencode/settings-runtime.js +1 -0
  151. package/server/lib/project-context/DOCUMENTATION.md +25 -1
  152. package/server/lib/project-context/plan-progress.js +69 -0
  153. package/server/lib/project-context/plan-progress.test.js +58 -0
  154. package/server/lib/project-context/routes.http.test.js +22 -0
  155. package/server/lib/project-context/routes.js +20 -0
  156. package/server/lib/project-context/runtime.js +132 -18
  157. package/server/lib/project-context/runtime.test.js +58 -0
  158. package/server/lib/provider-read-cache/index.js +7 -1
  159. package/server/lib/provider-read-cache/index.test.js +12 -0
  160. package/server/lib/relay/DOCUMENTATION.md +17 -1
  161. package/server/lib/session-knowledge/DOCUMENTATION.md +17 -0
  162. package/server/lib/session-knowledge/runtime.js +29 -6
  163. package/server/lib/session-knowledge/runtime.test.js +26 -1
  164. package/server/lib/source-control/audit-storage.js +1 -0
  165. package/server/lib/source-control/mutation-storage.js +3 -0
  166. package/server/lib/spaces/DOCUMENTATION.md +14 -9
  167. package/server/lib/spaces/code-out.js +13 -4
  168. package/server/lib/spaces/code-out.test.js +5 -3
  169. package/server/lib/spaces/dispatcher.js +12 -5
  170. package/server/lib/spaces/dispatcher.test.js +19 -1
  171. package/server/lib/spaces/gatekeeper-channel.js +8 -7
  172. package/server/lib/spaces/gatekeeper-channel.test.js +10 -0
  173. package/server/lib/spaces/gatekeeper-program.cjs +38 -3
  174. package/server/lib/spaces/gatekeeper-program.test.js +20 -0
  175. package/server/lib/spaces/hardening.js +14 -1
  176. package/server/lib/spaces/hardening.test.js +5 -0
  177. package/server/lib/spaces/host-providers.js +165 -0
  178. package/server/lib/spaces/host-providers.test.js +100 -0
  179. package/server/lib/spaces/host.js +16 -4
  180. package/server/lib/spaces/journey.js +87 -17
  181. package/server/lib/spaces/journey.test.js +90 -2
  182. package/server/lib/spaces/layout.js +15 -5
  183. package/server/lib/spaces/places/docker-live-support.js +2 -0
  184. package/server/lib/spaces/places/docker.test.js +2 -0
  185. package/server/lib/spaces/places/fake-docker.js +3 -0
  186. package/server/lib/spaces/places/grants.docker.live.test.js +71 -7
  187. package/server/lib/spaces/routes.js +9 -0
  188. package/server/lib/spaces/routes.test.js +4 -2
  189. package/server/lib/spaces/space-opencode.js +31 -14
  190. package/server/lib/spaces/space-opencode.test.js +15 -2
  191. package/server/lib/spaces/space-records.js +8 -0
  192. package/server/lib/spaces/space-records.test.js +7 -3
  193. package/server/lib/spaces/websocket.test.js +13 -1
  194. package/server/lib/ui-auth/ui-auth.js +28 -3
  195. package/server/lib/ui-auth/ui-auth.test.js +31 -0
  196. package/dist/assets/MarkdownRendererImpl-B2LsA09C.js +0 -1
  197. package/dist/assets/PlanView-Dt5EN_JK.js +0 -5
  198. package/dist/assets/SettingsView-BolP_tuu.js +0 -30
  199. package/dist/assets/SourceBoardView-yca1qvgB.js +0 -1
  200. package/dist/assets/SpaceAccessDialog-CZ-u75py.js +0 -1
  201. package/dist/assets/katex-rNcbfUj4.css +0 -1
  202. package/dist/assets/katex.min-DQ8qF6NR.js +0 -65
  203. package/dist/assets/main-CVHM3_8W.js +0 -1048
  204. package/dist/assets/markdownCore-D5ZOJXeO.js +0 -9
  205. package/dist/assets/pl-Bj-Hy0X5.js +0 -20
  206. package/dist/assets/renderElectronMiniChatApp-B_5BeSF6.js +0 -2
  207. package/dist/assets/renderMobileApp-DGEXUTk-.js +0 -25
  208. package/dist/assets/runtimeEndpointReset-CIpvn8QG.js +0 -59
  209. package/dist/assets/sessionOwnership-BZoGed9N.js +0 -1
  210. package/dist/assets/tr-qMRMBQ8r.js +0 -11
  211. package/dist/assets/useAppFontEffects-Bih1DxXi.js +0 -745
  212. package/dist/assets/vendor-tanstack-react-virtual-CvuLsk7D.js +0 -1
  213. package/dist/assets/vendor-tanstack-virtual-core-DPaNcJcT.js +0 -1
@@ -0,0 +1,165 @@
1
+ // The providers the user defined in the host's OpenCode configuration, "custom" in Settings, as a
2
+ // space can be given them (see "Grants" in DOCUMENTATION.md): a self-hosted gateway or a model
3
+ // server on the user's own machine or network, which OpenCode's catalog does not know, with the
4
+ // models the user listed for it. The host reads the definition again at every grant and every
5
+ // start, so a provider edited in Settings reaches the space at its next start, and nothing of it
6
+ // is kept in the record.
7
+ //
8
+ // The key is resolved the way OpenCode resolves it for the host, measured on 2.0.26: the credential
9
+ // stored for the provider wins, then the first set variable the entry's `env` names, then a literal
10
+ // `apiKey` in its settings. A provider that has none is given with no key: the window then forwards
11
+ // the request as the space made it, less its credential headers.
12
+
13
+ import { z } from 'zod';
14
+
15
+ import { isRecord, readSectionEntry, toProviderEntity } from '../opencode/config-v2.js';
16
+ import { readConfigLayers } from '../opencode/shared.js';
17
+ import { HOST_NAME } from './hardening.js';
18
+
19
+ // The header the window sets for a provider, by the SDK its entry names: what that SDK's API
20
+ // reads a key from. OpenCode's `aisdk:` prefix is the canonical spelling in a v2 entry.
21
+ const HEADER_BY_PACKAGE = new Map([
22
+ ['aisdk:@ai-sdk/openai-compatible', 'authorization'],
23
+ ['aisdk:@ai-sdk/openai', 'authorization'],
24
+ ['aisdk:@ai-sdk/anthropic', 'x-api-key'],
25
+ ]);
26
+
27
+ /** The header a custom provider's key travels in, or null for an SDK the window does not know. */
28
+ export const headerOfPackage = (packageName) => HEADER_BY_PACKAGE.get(packageName) ?? null;
29
+
30
+ // "This machine" as a base URL names it: the Docker host, which the gatekeeper reaches under
31
+ // `host.docker.internal`, while inside the gatekeeper these names would be the gatekeeper itself.
32
+ const LOOPBACK_HOSTS = new Set(['localhost', '[::1]', '0.0.0.0']);
33
+
34
+ /**
35
+ * The address the window forwards a custom provider's requests to: the base URL as the user wrote
36
+ * it, with a loopback host replaced by the Docker host's name. Null for anything that is not an
37
+ * http(s) URL.
38
+ */
39
+ export const windowUpstreamOf = (baseURL) => {
40
+ const url = httpUrlOf(baseURL);
41
+ if (!url) return null;
42
+ if (isLoopback(url)) url.hostname = HOST_NAME;
43
+ return url.toString();
44
+ };
45
+
46
+ /** Whether a base URL names "this machine", which inside the gatekeeper would be the gatekeeper. */
47
+ export const isLoopbackUrl = (baseURL) => {
48
+ const url = httpUrlOf(baseURL);
49
+ return url !== null && isLoopback(url);
50
+ };
51
+
52
+ // Any 127/8 address is this machine, as `localhost` is.
53
+ const isLoopback = (url) => LOOPBACK_HOSTS.has(url.hostname.toLowerCase()) || /^127\./.test(url.hostname);
54
+
55
+ const httpUrlOf = (value) => {
56
+ let url;
57
+ try {
58
+ url = new URL(value);
59
+ } catch {
60
+ return null;
61
+ }
62
+ return /^https?:$/.test(url.protocol) ? url : null;
63
+ };
64
+
65
+ /** The layers of a directory, highest precedence first: custom, project, the user's override file, the user's file. */
66
+ const layersOf = (readLayers, directory) => {
67
+ const { userConfig, userOverrideConfig, projectConfig, customConfig } = readLayers(directory);
68
+ return [customConfig, projectConfig, userOverrideConfig, userConfig];
69
+ };
70
+
71
+ // A provider id a grant can name, the record's own rule; an id outside it, hand-written in the
72
+ // configuration, is left out of the list rather than offered and refused.
73
+ const GRANT_ID_PATTERN = /^[A-Za-z0-9._-]{1,64}$/;
74
+
75
+ /** Every provider id the layers define under either spelling, once, that a grant can name. */
76
+ const definedIds = (layers) => {
77
+ const ids = new Set();
78
+ for (const layer of layers) {
79
+ for (const key of ['providers', 'provider']) {
80
+ const section = layer?.[key];
81
+ if (isRecord(section)) for (const id of Object.keys(section)) if (GRANT_ID_PATTERN.test(id)) ids.add(id);
82
+ }
83
+ }
84
+ return ids;
85
+ };
86
+
87
+ /** A key as a value is one: text with something in it. */
88
+ const keySchema = z.string().min(1);
89
+ const keyOf = (value) => keySchema.safeParse(value).data ?? null;
90
+
91
+ /**
92
+ * `readLayers(directory)` is `readConfigLayers` of the host's OpenCode configuration, injectable
93
+ * for the tests; `readStoredKey(providerId)` answers the key OpenCode stores for a provider, or
94
+ * null, and `hostEnvironment` is where a variable the entry's `env` names is read.
95
+ */
96
+ export function createHostProviders({ readLayers = readConfigLayers, readStoredKey = async () => null, hostEnvironment = process.env } = {}) {
97
+ /** The winning entry for a provider in v2 shape, or null when no layer defines it with an SDK. */
98
+ const entryOf = (layers, providerId) => {
99
+ for (const layer of layers) {
100
+ const { value } = readSectionEntry(layer, 'providers', providerId);
101
+ if (value === undefined) continue;
102
+ const entity = toProviderEntity(value);
103
+ return entity.package ? entity : null;
104
+ }
105
+ return null;
106
+ };
107
+
108
+ const definition = (providerId, entity) => ({
109
+ id: providerId,
110
+ name: entity.name ?? providerId,
111
+ package: entity.package,
112
+ baseURL: entity.settings?.baseURL ?? null,
113
+ headers: entity.headers ?? {},
114
+ models: entity.models ?? {},
115
+ });
116
+
117
+ const resolveKey = async (providerId, entity, { storedKey = readStoredKey } = {}) => {
118
+ const stored = keyOf(await storedKey(providerId));
119
+ if (stored !== null) return stored;
120
+ for (const name of entity.env ?? []) {
121
+ const value = keyOf(hostEnvironment[name]);
122
+ if (value !== null) return value;
123
+ }
124
+ return keyOf(entity.settings?.apiKey);
125
+ };
126
+
127
+ /**
128
+ * One custom provider of the directory's configuration with its key, or null when none defines
129
+ * it. The key is the only secret here and goes to the gatekeeper and nowhere else.
130
+ */
131
+ const read = async (providerId, directory) => {
132
+ const entity = entryOf(layersOf(readLayers, directory), providerId);
133
+ if (!entity) return null;
134
+ return { ...definition(providerId, entity), key: await resolveKey(providerId, entity) };
135
+ };
136
+
137
+ /**
138
+ * Every custom provider of the directory's configuration as a grant dialog shows it, without a
139
+ * key: whether the host has one for it, and what keeps the grant from being given, if anything.
140
+ */
141
+ const list = async (directory) => {
142
+ const layers = layersOf(readLayers, directory);
143
+ const providers = [];
144
+ // The stored keys live in the host's OpenCode, which may not be up when a dialog opens: the
145
+ // list then says what the configuration alone says, and a grant, which needs the key, asks again.
146
+ const storedKey = async (providerId) => readStoredKey(providerId).catch(() => null);
147
+ for (const providerId of definedIds(layers)) {
148
+ const entity = entryOf(layers, providerId);
149
+ if (!entity) continue;
150
+ const { headers: _headers, models, ...rest } = definition(providerId, entity);
151
+ providers.push({
152
+ ...rest,
153
+ // Whether the address names the machine the space runs on: the dialogs say so under a machine over SSH.
154
+ loopback: rest.baseURL !== null && isLoopbackUrl(rest.baseURL),
155
+ models: Object.keys(models),
156
+ hasKey: (await resolveKey(providerId, entity, { storedKey })) !== null,
157
+ // What a grant checks too: an SDK the window can carry a key for, and an http(s) address.
158
+ supported: headerOfPackage(entity.package) !== null && rest.baseURL !== null && httpUrlOf(rest.baseURL) !== null,
159
+ });
160
+ }
161
+ return providers;
162
+ };
163
+
164
+ return { read, list };
165
+ }
@@ -0,0 +1,100 @@
1
+ import { describe, expect, it } from 'vitest';
2
+
3
+ import { createHostProviders, headerOfPackage, isLoopbackUrl, windowUpstreamOf } from './host-providers.js';
4
+
5
+ const OLLAMA = {
6
+ name: 'Ollama (local)',
7
+ package: 'aisdk:@ai-sdk/openai-compatible',
8
+ settings: { baseURL: 'http://localhost:11434/v1' },
9
+ models: { 'qwen3:8b': { modelID: 'qwen3:8b', name: 'Qwen3 8B' } },
10
+ };
11
+ const GATEWAY = {
12
+ name: 'Lighthouse',
13
+ package: 'aisdk:@ai-sdk/openai',
14
+ env: ['LIGHTHOUSE_KEY'],
15
+ settings: { baseURL: 'https://lighthouse-gw.example.dev/v1' },
16
+ headers: { 'x-team': 'platform' },
17
+ models: { 'gpt-5.5': { modelID: 'gpt-5.5' } },
18
+ };
19
+ const layers = ({ user = {}, userOverride = {}, project = {}, custom = {} } = {}) => () => ({ userConfig: user, userOverrideConfig: userOverride, projectConfig: project, customConfig: custom });
20
+
21
+ describe('the host\'s custom providers', () => {
22
+ it('lists the providers the configuration defines with an SDK, without a key, and says what keeps each from a grant', async () => {
23
+ const providers = createHostProviders({
24
+ readLayers: layers({ user: { providers: { 'ollama-local': OLLAMA, lighthouse: GATEWAY, anthropic: { settings: { timeout: 1 } } } } }),
25
+ readStoredKey: async (id) => (id === 'lighthouse' ? 'sk-stored' : null),
26
+ hostEnvironment: {},
27
+ });
28
+ expect(await providers.list('/home/me/project')).toEqual([
29
+ { id: 'ollama-local', name: 'Ollama (local)', package: 'aisdk:@ai-sdk/openai-compatible', baseURL: 'http://localhost:11434/v1', loopback: true, models: ['qwen3:8b'], hasKey: false, supported: true },
30
+ { id: 'lighthouse', name: 'Lighthouse', package: 'aisdk:@ai-sdk/openai', baseURL: 'https://lighthouse-gw.example.dev/v1', loopback: false, models: ['gpt-5.5'], hasKey: true, supported: true },
31
+ ]);
32
+ expect(JSON.stringify(await providers.list('/home/me/project'))).not.toContain('sk-stored');
33
+ });
34
+
35
+ it('lists from the configuration alone while the host\'s OpenCode cannot be asked for its keys, and a read then fails', async () => {
36
+ const providers = createHostProviders({ readLayers: layers({ user: { providers: { lighthouse: GATEWAY } } }), readStoredKey: async () => { throw new Error('OpenCode port is not available'); }, hostEnvironment: { LIGHTHOUSE_KEY: 'sk-env' } });
37
+ expect((await providers.list('/p')).map((provider) => [provider.id, provider.hasKey])).toEqual([['lighthouse', true]]);
38
+ await expect(providers.read('lighthouse', '/p')).rejects.toThrow('OpenCode port is not available');
39
+ });
40
+
41
+ it('says a provider without an http(s) address is unsupported, and leaves out an id a grant cannot name', async () => {
42
+ const providers = createHostProviders({
43
+ readLayers: layers({ user: { providers: { 'no-address': { ...GATEWAY, settings: {} }, 'ftp-address': { ...GATEWAY, settings: { baseURL: 'ftp://files.example/' } }, 'bad id!': GATEWAY, lighthouse: GATEWAY } } }),
44
+ hostEnvironment: {},
45
+ });
46
+ expect((await providers.list('/p')).map((provider) => [provider.id, provider.supported])).toEqual([['no-address', false], ['ftp-address', false], ['lighthouse', true]]);
47
+ });
48
+
49
+ it('reads one provider with its key: the stored credential first, then a named variable, then a literal in the settings', async () => {
50
+ const stored = createHostProviders({ readLayers: layers({ user: { providers: { lighthouse: GATEWAY } } }), readStoredKey: async () => 'sk-stored', hostEnvironment: { LIGHTHOUSE_KEY: 'sk-env' } });
51
+ expect(await stored.read('lighthouse', '/p')).toMatchObject({ id: 'lighthouse', key: 'sk-stored', headers: { 'x-team': 'platform' }, models: { 'gpt-5.5': { modelID: 'gpt-5.5' } } });
52
+
53
+ const fromEnv = createHostProviders({ readLayers: layers({ user: { providers: { lighthouse: GATEWAY } } }), hostEnvironment: { LIGHTHOUSE_KEY: 'sk-env' } });
54
+ expect((await fromEnv.read('lighthouse', '/p')).key).toBe('sk-env');
55
+
56
+ const literal = createHostProviders({ readLayers: layers({ user: { providers: { lighthouse: { ...GATEWAY, settings: { ...GATEWAY.settings, apiKey: 'sk-literal' } } } } }), hostEnvironment: {} });
57
+ expect((await literal.read('lighthouse', '/p')).key).toBe('sk-literal');
58
+
59
+ const none = createHostProviders({ readLayers: layers({ user: { providers: { 'ollama-local': OLLAMA } } }), hostEnvironment: {} });
60
+ expect(await none.read('ollama-local', '/p')).toEqual({ id: 'ollama-local', name: 'Ollama (local)', package: 'aisdk:@ai-sdk/openai-compatible', baseURL: 'http://localhost:11434/v1', headers: {}, models: OLLAMA.models, key: null });
61
+ expect(await none.read('anthropic', '/p')).toBeNull();
62
+ });
63
+
64
+ it('takes the highest layer that defines the provider, project over user, and reads the v1 spelling', async () => {
65
+ const providers = createHostProviders({
66
+ readLayers: layers({
67
+ user: { provider: { lighthouse: { npm: '@ai-sdk/openai-compatible', name: 'Old', options: { baseURL: 'http://10.0.0.5/v1' } } } },
68
+ project: { providers: { lighthouse: GATEWAY } },
69
+ }),
70
+ hostEnvironment: {},
71
+ });
72
+ expect((await providers.read('lighthouse', '/p')).name).toBe('Lighthouse');
73
+ const onlyUser = createHostProviders({ readLayers: layers({ user: { provider: { lighthouse: { npm: '@ai-sdk/openai-compatible', name: 'Old', options: { baseURL: 'http://10.0.0.5/v1' } } } } }), hostEnvironment: {} });
74
+ expect(await onlyUser.read('lighthouse', '/p')).toMatchObject({ name: 'Old', package: 'aisdk:@ai-sdk/openai-compatible', baseURL: 'http://10.0.0.5/v1' });
75
+ });
76
+
77
+ it('knows the header of each SDK the window can serve, and no other', () => {
78
+ expect(headerOfPackage('aisdk:@ai-sdk/openai-compatible')).toBe('authorization');
79
+ expect(headerOfPackage('aisdk:@ai-sdk/openai')).toBe('authorization');
80
+ expect(headerOfPackage('aisdk:@ai-sdk/anthropic')).toBe('x-api-key');
81
+ expect(headerOfPackage('aisdk:@ai-sdk/amazon-bedrock')).toBeNull();
82
+ expect(headerOfPackage(undefined)).toBeNull();
83
+ });
84
+
85
+ it('sends "this machine" to the Docker host and leaves every other address as written', () => {
86
+ expect(windowUpstreamOf('http://localhost:11434/v1')).toBe('http://host.docker.internal:11434/v1');
87
+ expect(windowUpstreamOf('http://127.0.0.1:11434/v1/')).toBe('http://host.docker.internal:11434/v1/');
88
+ expect(windowUpstreamOf('http://127.1.2.3:11434/v1')).toBe('http://host.docker.internal:11434/v1');
89
+ expect(windowUpstreamOf('http://[::1]:8080/v1')).toBe('http://host.docker.internal:8080/v1');
90
+ expect(windowUpstreamOf('http://0.0.0.0:1234/')).toBe('http://host.docker.internal:1234/');
91
+ expect(windowUpstreamOf('http://192.168.1.23:11434/v1')).toBe('http://192.168.1.23:11434/v1');
92
+ expect(windowUpstreamOf('https://lighthouse-gw.example.dev/v1')).toBe('https://lighthouse-gw.example.dev/v1');
93
+ expect(windowUpstreamOf('http://localhost.example.com/v1')).toBe('http://localhost.example.com/v1');
94
+ expect(windowUpstreamOf('ftp://localhost/')).toBeNull();
95
+ expect(windowUpstreamOf('not a url')).toBeNull();
96
+ expect(isLoopbackUrl('http://localhost:11434/v1')).toBe(true);
97
+ expect(isLoopbackUrl('http://192.168.1.23:11434/v1')).toBe(false);
98
+ expect(isLoopbackUrl('ftp://localhost/')).toBe(false);
99
+ });
100
+ });
@@ -12,13 +12,14 @@ import path from 'node:path';
12
12
 
13
13
  import { z } from 'zod';
14
14
 
15
- import { getStoredLogin, renewStoredLogin } from '../opencode/auth.js';
15
+ import { getProviderAuth, getStoredLogin, renewStoredLogin } from '../opencode/auth.js';
16
16
  import { createCodeIn } from './code-in.js';
17
17
  import { createCodeOut } from './code-out.js';
18
18
  import { createSpaceDispatcher } from './dispatcher.js';
19
19
  import { SpaceError } from './errors.js';
20
20
  import { createGatekeeperChannel } from './gatekeeper-channel.js';
21
21
  import { createHostGit } from './host-git.js';
22
+ import { createHostProviders } from './host-providers.js';
22
23
  import { createSpaceJourney } from './journey.js';
23
24
  import { KEEP_INTERVAL_MS, createLoginExchange, createLoginKeeper } from './login-keeper.js';
24
25
  import { hashProjectDirectory } from './labels.js';
@@ -126,8 +127,10 @@ export function readOrCreateOwner(dataDir) {
126
127
  * `readHostLogin(provider)` reads the host's own browser login for a provider from the host's
127
128
  * OpenCode, for a login grant, and `renewHostLogin(provider, exchange)` replaces it with the one
128
129
  * the issuer gives for its refresh token; the tests give a login of their own, and `loginWindowOf`
129
- * lets the live test point that grant's upstream at its stand-in. `userAgent` names this
130
- * OpenChamber to the issuer.
130
+ * lets the live test point that grant's upstream at its stand-in. `hostProviders` reads the
131
+ * providers the user defined in the host's OpenCode configuration, `host-providers.js` over the
132
+ * host's configuration and OpenCode's stored keys unless a test gives its own. `userAgent` names
133
+ * this OpenChamber to the issuer.
131
134
  */
132
135
  export function createSpacesHost({
133
136
  dataDir,
@@ -143,6 +146,7 @@ export function createSpacesHost({
143
146
  readHostLogin = getStoredLogin,
144
147
  renewHostLogin = renewStoredLogin,
145
148
  loginWindowOf = undefined,
149
+ hostProviders = null,
146
150
  userAgent = 'OpenChamber',
147
151
  runCommand = runCommandProcess,
148
152
  openCommandStream = openCommandStreamProcess,
@@ -191,7 +195,13 @@ export function createSpacesHost({
191
195
  const dispatcher = createSpaceDispatcher({
192
196
  logger,
193
197
  transport: {
194
- listSpaceIds: async () => (await listSpaces()).map((space) => space.id),
198
+ // A miss is an answer only when every configured place answered. A place the settings no
199
+ // longer name is not one of them: nothing here reaches a space on it either way.
200
+ listSpaceIds: async () => {
201
+ const { spaces, unavailable } = await manager.listAllSpaces();
202
+ const failure = unavailable.find(({ placeId }) => registry.get(placeId))?.failure ?? null;
203
+ return { ids: spaces.map((space) => space.id), failure };
204
+ },
195
205
  connect: connectReachable,
196
206
  readToken: async (spaceId) => {
197
207
  await requireReachable(spaceId);
@@ -320,6 +330,8 @@ export function createSpacesHost({
320
330
  readHostSecret: (name) => hostEnvironment[name],
321
331
  readHostLogin: keeper.fresh,
322
332
  loginWindowOf,
333
+ // A custom provider's key is OpenCode's stored one, else the variable its entry names, read now and kept nowhere.
334
+ hostProviders: hostProviders ?? createHostProviders({ readStoredKey: async (providerId) => (await getProviderAuth(providerId))?.key ?? null, hostEnvironment }),
323
335
  readIdleStop,
324
336
  saveIdleStop,
325
337
  announce: (spaceId, payload) => { hub?.injectEvent({ payload, directory: 'global', spaceId }); },
@@ -42,6 +42,7 @@ import { z } from 'zod';
42
42
 
43
43
  import { SpaceError } from './errors.js';
44
44
  import { DEFAULT_IDLE_STOP, idleStopSchema } from './idle-stop.js';
45
+ import { headerOfPackage, windowUpstreamOf } from './host-providers.js';
45
46
  import { ROLE_GATEKEEPER, createSpaceId, hashProjectDirectory, spaceResourceName } from './labels.js';
46
47
  import { spaceProjectPath, spaceWindowUrl } from './layout.js';
47
48
  import { LOGIN_PROVIDERS, loginEndOf, loginEnded, loginGrantOf } from './space-opencode.js';
@@ -89,6 +90,8 @@ const grantRequestSchema = z.discriminatedUnion('kind', [
89
90
  z.object({ kind: z.literal('domain'), upstream: grantSchema.options[1].shape.upstream }).strict(),
90
91
  // The host's browser login for a provider; the token is read from the host's OpenCode here.
91
92
  z.object({ kind: z.literal('login'), provider: providerIdSchema }).strict(),
93
+ // A provider the user defined on the host; its address, key and models are read from the host's configuration here.
94
+ z.object({ kind: z.literal('custom'), provider: providerIdSchema }).strict(),
92
95
  ]);
93
96
  // The header the window sets for a provider: what its API reads a key from. Only providers
94
97
  // named here are taken: one that reads its key another way or signs its requests, Azure,
@@ -133,7 +136,9 @@ const failureOf = (error) => ({
133
136
  * `readHostLogin(provider)` reads the host's own browser login for a provider from its OpenCode,
134
137
  * `{ methodID, access, expires, metadata }` or null, for a login grant; it is never stored either.
135
138
  * `loginWindowOf(provider, login)` is the window grant that login makes, `space-opencode.js`'s
136
- * unless a live test points the upstream at a stand-in.
139
+ * unless a live test points the upstream at a stand-in. `hostProviders` reads the providers the
140
+ * user defined in the host's OpenCode configuration, `host-providers.js`, for a custom grant:
141
+ * `read(providerId, directory)` one with its key, `list(directory)` all of them without.
137
142
  * `serverInside.writeToken(spaceId, token)` replaces the token the server inside reads when it
138
143
  * starts, and `restartOpenCodeInside(spaceId)` asks the server inside to restart its OpenCode.
139
144
  * `readIdleStop()` and `saveIdleStop(setting)` read and keep the user's idle stop setting, and
@@ -159,6 +164,7 @@ export function createSpaceJourney({
159
164
  readHostSecret = () => undefined,
160
165
  readHostLogin = async () => null,
161
166
  loginWindowOf = loginGrantOf,
167
+ hostProviders = { read: async () => null, list: async () => [] },
162
168
  readIdleStop = async () => ({ ...DEFAULT_IDLE_STOP }),
163
169
  saveIdleStop = async () => {},
164
170
  folderExists = async (directory) => (await fsPromises.stat(directory).catch(() => null))?.isDirectory() === true,
@@ -397,16 +403,55 @@ export function createSpaceJourney({
397
403
  /** A grant as the list and the grant route show it: everything the record holds, which holds no value. */
398
404
  const describeGrant = (grant) => ({ ...grant, url: spaceWindowUrl(grant.id) });
399
405
 
406
+ /** Whether a grant has an entry in OpenCode's configuration inside: a key, a login or a custom provider. */
407
+ const configuresProvider = (grant) => grant.kind === 'model' || grant.kind === 'login' || grant.kind === 'custom';
408
+
409
+ /**
410
+ * The window grant a custom provider's definition makes, or null for one the window cannot
411
+ * serve: its base URL with "this machine" sent to the Docker host, its key under the header its
412
+ * SDK reads, no header and no key for a provider that has none, and the provider's own headers
413
+ * beside either, which the gatekeeper keeps with the key and the space never sees.
414
+ */
415
+ const customWindowOf = (definition) => {
416
+ if (!definition) return null;
417
+ const upstream = definition.baseURL === null ? null : windowUpstreamOf(definition.baseURL);
418
+ const header = headerOfPackage(definition.package);
419
+ if (upstream === null || header === null) return null;
420
+ const window = definition.key === null ? { upstream, header: null, secret: null } : { upstream, header, secret: definition.key };
421
+ if (Object.keys(definition.headers).length > 0) window.headers = definition.headers;
422
+ return window;
423
+ };
424
+
425
+ /**
426
+ * The host's definition of every custom provider among the grants, by id, without a key, for
427
+ * the configuration inside. One the host cannot read now is left out and logged; the next start reads again.
428
+ */
429
+ const customDefinitionsOf = async (grants, repository) => {
430
+ const definitions = new Map();
431
+ for (const grant of grants) {
432
+ if (grant.kind !== 'custom') continue;
433
+ const definition = await hostProviders.read(grant.provider, repository).catch(() => null);
434
+ if (!definition) {
435
+ logger.warn?.(`[spaces] the custom provider ${grant.provider} is not in the host's configuration now; the space is not told about it`);
436
+ continue;
437
+ }
438
+ const { key: _key, ...rest } = definition;
439
+ definitions.set(grant.provider, rest);
440
+ }
441
+ return definitions;
442
+ };
443
+
400
444
  /**
401
445
  * Says one grant of the record to the gatekeeper. Resolves whether it could: a typed key is
402
446
  * not remembered and needs the user again, and so does an environment variable that is not set
403
447
  * now; a gatekeeper that refuses or does not answer counts the same way and is logged, because
404
448
  * the space runs either way and the list must say that its access is missing.
405
449
  */
406
- const deliverGrant = async (spaceId, grant, login = null) => {
450
+ const deliverGrant = async (spaceId, grant, login = null, repository = null) => {
407
451
  let secret = null;
408
- let upstream = grant.kind === 'login' ? null : grant.upstream;
452
+ let upstream = grant.kind === 'login' || grant.kind === 'custom' ? null : grant.upstream;
409
453
  let header = grant.kind === 'model' ? grant.header : null;
454
+ let headers;
410
455
  if (grant.kind === 'model') {
411
456
  if (grant.source.kind === 'typed') return false;
412
457
  secret = readHostSecret(grant.source.name);
@@ -417,8 +462,15 @@ export function createSpaceJourney({
417
462
  if (!window) return false;
418
463
  ({ upstream, header, secret } = window);
419
464
  }
465
+ if (grant.kind === 'custom') {
466
+ const window = customWindowOf(await hostProviders.read(grant.provider, repository).catch(() => null));
467
+ if (!window) return false;
468
+ ({ upstream, header, secret, headers } = window);
469
+ }
420
470
  try {
421
- await gatekeeper.addGrant(spaceId, { id: grant.id, upstream, header, secret });
471
+ const said = { id: grant.id, upstream, header, secret };
472
+ if (headers) said.headers = headers;
473
+ await gatekeeper.addGrant(spaceId, said);
422
474
  return true;
423
475
  } catch (error) {
424
476
  logger.warn?.(`[spaces] the grant ${grant.id} of space ${spaceId} could not be said again: ${error?.code ?? error?.message ?? error}`);
@@ -431,10 +483,10 @@ export function createSpaceJourney({
431
483
  * stop in the home volume, but a write that failed at the grant is repaired only here. It
432
484
  * cooperates and enforces nothing, so a failure is logged and the start goes on.
433
485
  */
434
- const rewriteProviderConfig = async (spaceId, grants) => {
435
- if (!grants.some((grant) => grant.kind === 'model' || grant.kind === 'login')) return;
486
+ const rewriteProviderConfig = async (spaceId, grants, repository) => {
487
+ if (!grants.some((grant) => configuresProvider(grant))) return;
436
488
  try {
437
- await spaceOpenCode.writeProviderConfig(spaceId, grants);
489
+ await spaceOpenCode.writeProviderConfig(spaceId, grants, await customDefinitionsOf(grants, repository));
438
490
  } catch (error) {
439
491
  logger.warn?.(`[spaces] the provider configuration of space ${spaceId} was not written again: ${error?.code ?? error?.message ?? error}`);
440
492
  }
@@ -453,12 +505,12 @@ export function createSpaceJourney({
453
505
  };
454
506
 
455
507
  /** Every grant of the record said again after a start. Resolves the ids that went and the ids that need the user. */
456
- const restoreGrants = async (spaceId, grants) => {
508
+ const restoreGrants = async (spaceId, grants, repository) => {
457
509
  const restored = [];
458
510
  const needsAccess = [];
459
511
  for (const grant of grants) {
460
512
  const login = grant.kind === 'login' ? await usableHostLogin(grant) : null;
461
- (await deliverGrant(spaceId, grant, login) ? restored : needsAccess).push(grant.id);
513
+ (await deliverGrant(spaceId, grant, login, repository) ? restored : needsAccess).push(grant.id);
462
514
  }
463
515
  return { restored, needsAccess };
464
516
  };
@@ -528,6 +580,16 @@ export function createSpaceJourney({
528
580
  return { logins };
529
581
  };
530
582
 
583
+ /**
584
+ * The providers the user defined in the host's OpenCode configuration for a project, as the
585
+ * grant dialogs offer them, never a key: a catalog provider overridden there is not among them,
586
+ * since the dialogs offer those under their own names.
587
+ */
588
+ const readHostCustomProviders = async (directory) => {
589
+ const providers = (await hostProviders.list(directory)).filter((provider) => !HEADER_BY_PROVIDER.has(provider.id) && !LOGIN_PROVIDERS.includes(provider.id));
590
+ return { providers };
591
+ };
592
+
531
593
  /** Waits for a login row repair that is writing now; its failure is its own and logged there. */
532
594
  const afterRowRepair = (spaceId) => (rowRepairs.get(spaceId) ?? Promise.resolve()).catch(() => {});
533
595
 
@@ -561,7 +623,8 @@ export function createSpaceJourney({
561
623
  }
562
624
  for (const space of spaces) {
563
625
  if (space.state !== 'running' || busy.has(space.id)) continue;
564
- const grants = (records.read(space.id).record?.grants ?? []).filter((grant) => grant.kind !== 'model' || grant.source.kind === 'env');
626
+ const record = records.read(space.id).record;
627
+ const grants = (record?.grants ?? []).filter((grant) => grant.kind !== 'model' || grant.source.kind === 'env');
565
628
  if (grants.length === 0) continue;
566
629
  let held;
567
630
  try {
@@ -573,7 +636,7 @@ export function createSpaceJourney({
573
636
  const lost = grants.filter((grant) => !held.has(grant.id));
574
637
  if (lost.length === 0) continue;
575
638
  try {
576
- const { restored } = await exclusive(space.id, () => restoreGrants(space.id, lost));
639
+ const { restored } = await exclusive(space.id, () => restoreGrants(space.id, lost, record.repository));
577
640
  if (restored.length > 0) logger.info?.(`[spaces] said the grants ${restored.join(', ')} of space ${space.id} again`);
578
641
  } catch (error) {
579
642
  logger.warn?.(`[spaces] the grants of space ${space.id} were not said again: ${error?.code ?? error?.message ?? error}`);
@@ -753,8 +816,8 @@ export function createSpaceJourney({
753
816
  if (record) {
754
817
  await gatekeeper.setNetwork(spaceId, record.network);
755
818
  networkRestored = true;
756
- grants = await restoreGrants(spaceId, record.grants);
757
- await rewriteProviderConfig(spaceId, record.grants);
819
+ grants = await restoreGrants(spaceId, record.grants, record.repository);
820
+ await rewriteProviderConfig(spaceId, record.grants, record.repository);
758
821
  if (record.grants.some((grant) => grant.kind === 'model' || grant.kind === 'login')) repairLoginRowInBackground(spaceId);
759
822
  // A history that never arrived, or that failed, is sent again: a stop right after the
760
823
  // creation is the usual way it fails, and the space would otherwise stay shallow for good.
@@ -835,7 +898,14 @@ export function createSpaceJourney({
835
898
  let grant;
836
899
  let window;
837
900
  let login = null;
838
- if (asked.kind === 'model') {
901
+ if (asked.kind === 'custom') {
902
+ const definition = await hostProviders.read(asked.provider, current.record.repository);
903
+ if (!definition) throw new SpaceError('provider_not_found', `${asked.provider} is not a provider of your own in Settings. Add it there, then grant.`);
904
+ if (headerOfPackage(definition.package) === null) throw new SpaceError('provider_not_supported', `${definition.name} cannot be given through the network filter yet: its SDK reads a key in a way the network filter does not know.`);
905
+ window = customWindowOf(definition);
906
+ if (!window) throw new SpaceError('provider_not_supported', `${definition.name} has no http(s) address in Settings.`);
907
+ grant = { kind: 'custom', id: asked.provider, provider: asked.provider };
908
+ } else if (asked.kind === 'model') {
839
909
  const source = asked.secret.kind === 'typed' ? { kind: 'typed' } : { kind: 'env', name: asked.secret.name };
840
910
  const secret = asked.secret.kind === 'typed' ? asked.secret.value : readHostSecret(asked.secret.name);
841
911
  if (typeof secret !== 'string' || secret === '') {
@@ -858,7 +928,7 @@ export function createSpaceJourney({
858
928
  // keep the login's headers and model list for requests the window now sends with the key; a
859
929
  // removal that fails answers the grant before anything changed.
860
930
  const replaced = current.record.grants.find((entry) => entry.id === grant.id);
861
- if (grant.kind === 'model' && replaced?.kind === 'login') await spaceOpenCode.removeLogin(spaceId, grant.provider);
931
+ if (grant.kind !== 'login' && replaced?.kind === 'login') await spaceOpenCode.removeLogin(spaceId, grant.provider);
862
932
  await gatekeeper.addGrant(spaceId, { id: grant.id, ...window });
863
933
  const grants = [...current.record.grants.filter((entry) => entry.id !== grant.id), grant];
864
934
  if (records.update(spaceId, { grants }).status !== 'ok') {
@@ -866,7 +936,7 @@ export function createSpaceJourney({
866
936
  }
867
937
  // A failure here answers the grant with it; the key is in the gatekeeper and the record, and
868
938
  // the next start writes the configuration and the row again.
869
- if (grant.kind === 'model' || grant.kind === 'login') await spaceOpenCode.writeProviderConfig(spaceId, grants);
939
+ if (configuresProvider(grant)) await spaceOpenCode.writeProviderConfig(spaceId, grants, await customDefinitionsOf(grants, current.record.repository));
870
940
  if (grant.kind === 'login') await spaceOpenCode.writeLogin(spaceId, grant.provider, login);
871
941
  return { grant: describeGrant(grant) };
872
942
  });
@@ -1158,5 +1228,5 @@ export function createSpaceJourney({
1158
1228
  return { brought, applied, removal, kept };
1159
1229
  });
1160
1230
 
1161
- return { createSpace, listSpaces, startSpace, stopSpace, restartSpace, restartOpenCode, removeSpace, stopAllSpaces, reopen, isIdle, grantAccess, sayLogin, readHostLogins, openDomain, restoreLostGrants, readJournal, previewApply, applySpace, readIdleStopSetting, changeIdleStop, runSetup, readSetup, readDisk, cleanUpDisk, pullImage };
1231
+ return { createSpace, listSpaces, startSpace, stopSpace, restartSpace, restartOpenCode, removeSpace, stopAllSpaces, reopen, isIdle, grantAccess, sayLogin, readHostLogins, readHostCustomProviders, openDomain, restoreLostGrants, readJournal, previewApply, applySpace, readIdleStopSetting, changeIdleStop, runSetup, readSetup, readDisk, cleanUpDisk, pullImage };
1162
1232
  }