@openllmsh/sdk 2.10.12-alpha.1 → 2.10.12

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 (634) hide show
  1. package/README.md +27 -7
  2. package/dist/client/chat.d.ts +38 -0
  3. package/dist/client/chat.js +77 -0
  4. package/dist/client/devices.d.ts +70 -0
  5. package/dist/client/devices.js +172 -0
  6. package/dist/client/http.d.ts +24 -0
  7. package/dist/client/http.js +34 -0
  8. package/dist/client/index.d.ts +43 -0
  9. package/dist/client/index.js +57 -0
  10. package/dist/client/relay-mux.d.ts +71 -0
  11. package/dist/client/relay-mux.js +394 -0
  12. package/dist/client/types.d.ts +47 -0
  13. package/dist/client/types.js +5 -0
  14. package/dist/client/vault.d.ts +68 -0
  15. package/dist/client/vault.js +113 -0
  16. package/dist/connect/chat.d.ts +24 -0
  17. package/dist/connect/chat.js +25 -0
  18. package/dist/connect/client.d.ts +50 -0
  19. package/dist/connect/client.js +141 -0
  20. package/dist/connect/config.d.ts +22 -0
  21. package/dist/connect/config.js +22 -0
  22. package/dist/connect/errors.d.ts +32 -0
  23. package/dist/connect/errors.js +85 -0
  24. package/{connect/index.ts → dist/connect/index.d.ts} +7 -7
  25. package/dist/connect/index.js +23 -0
  26. package/dist/connect/oauth.d.ts +51 -0
  27. package/dist/connect/oauth.js +150 -0
  28. package/dist/connect/routes.d.ts +38 -0
  29. package/dist/connect/routes.js +175 -0
  30. package/dist/connect/store.d.ts +26 -0
  31. package/dist/connect/store.js +65 -0
  32. package/dist/mcp/handle.d.ts +6 -0
  33. package/dist/mcp/handle.js +6 -0
  34. package/dist/mcp/index.d.ts +15 -0
  35. package/dist/mcp/index.js +10 -0
  36. package/dist/mcp/server.d.ts +84 -0
  37. package/dist/mcp/server.js +168 -0
  38. package/dist/mcp/tools/marketplace.d.ts +94 -0
  39. package/dist/mcp/tools/marketplace.js +303 -0
  40. package/dist/mcp/tools/memory-client.d.ts +109 -0
  41. package/dist/mcp/tools/memory-client.js +200 -0
  42. package/dist/mcp/tools/memory-config.d.ts +29 -0
  43. package/dist/mcp/tools/memory-config.js +12 -0
  44. package/dist/mcp/tools/memory.d.ts +92 -0
  45. package/dist/mcp/tools/memory.js +312 -0
  46. package/dist/mcp/tools/model-priority.d.ts +16 -0
  47. package/dist/mcp/tools/model-priority.js +87 -0
  48. package/dist/mcp/tools/openllm.d.ts +75 -0
  49. package/dist/mcp/tools/openllm.js +715 -0
  50. package/dist/mcp/types.d.ts +25 -0
  51. package/dist/mcp/types.js +7 -0
  52. package/dist/openapi/call.d.ts +26 -0
  53. package/dist/openapi/call.js +56 -0
  54. package/dist/openapi/index.d.ts +2 -0
  55. package/dist/openapi/index.js +2 -0
  56. package/dist/openapi/openapi.json +80213 -0
  57. package/dist/openapi/operations.d.ts +14 -0
  58. package/dist/openapi/operations.js +2060 -0
  59. package/dist/protocol/access.d.ts +81 -0
  60. package/dist/protocol/access.js +125 -0
  61. package/dist/protocol/agent-prompt-text.d.ts +15 -0
  62. package/{protocol/agent-prompt-text.ts → dist/protocol/agent-prompt-text.js} +9 -14
  63. package/dist/protocol/agent.d.ts +1487 -0
  64. package/dist/protocol/agent.js +787 -0
  65. package/dist/protocol/api-key-syntax.d.ts +58 -0
  66. package/dist/protocol/api-key-syntax.js +73 -0
  67. package/dist/protocol/audio.d.ts +18 -0
  68. package/dist/protocol/audio.js +21 -0
  69. package/dist/protocol/auth.d.ts +126 -0
  70. package/dist/protocol/auth.js +119 -0
  71. package/dist/protocol/changelog.d.ts +69 -0
  72. package/dist/protocol/changelog.js +107 -0
  73. package/dist/protocol/chat.d.ts +789 -0
  74. package/dist/protocol/chat.js +394 -0
  75. package/dist/protocol/client-registry.d.ts +151 -0
  76. package/dist/protocol/client-registry.js +238 -0
  77. package/dist/protocol/config.d.ts +508 -0
  78. package/dist/protocol/config.js +289 -0
  79. package/dist/protocol/control-channel.d.ts +102 -0
  80. package/{protocol/control-channel.ts → dist/protocol/control-channel.js} +33 -61
  81. package/dist/protocol/cooldown-reason.d.ts +30 -0
  82. package/dist/protocol/cooldown-reason.js +44 -0
  83. package/dist/protocol/cost.d.ts +9 -0
  84. package/dist/protocol/cost.js +8 -0
  85. package/dist/protocol/daemon-port.d.ts +2 -0
  86. package/dist/protocol/daemon-port.js +28 -0
  87. package/dist/protocol/daemon.d.ts +2034 -0
  88. package/dist/protocol/daemon.js +1286 -0
  89. package/dist/protocol/default-chains.d.ts +15 -0
  90. package/dist/protocol/default-chains.js +21 -0
  91. package/dist/protocol/device-state.d.ts +223 -0
  92. package/dist/protocol/device-state.js +52 -0
  93. package/dist/protocol/doctor-report-local.d.ts +105 -0
  94. package/{protocol/doctor-report-local.ts → dist/protocol/doctor-report-local.js} +92 -196
  95. package/dist/protocol/doctor-report-policy.d.ts +62 -0
  96. package/{protocol/doctor-report-policy.ts → dist/protocol/doctor-report-policy.js} +23 -76
  97. package/dist/protocol/doctor-report.d.ts +406 -0
  98. package/dist/protocol/doctor-report.js +645 -0
  99. package/dist/protocol/errors.d.ts +17 -0
  100. package/dist/protocol/errors.js +10 -0
  101. package/dist/protocol/execution-selection.d.ts +92 -0
  102. package/{protocol/execution-selection.ts → dist/protocol/execution-selection.js} +38 -63
  103. package/dist/protocol/hop-grant.d.ts +28 -0
  104. package/{protocol/hop-grant.ts → dist/protocol/hop-grant.js} +7 -13
  105. package/dist/protocol/image-edit-parse.d.ts +25 -0
  106. package/dist/protocol/image-edit-parse.js +196 -0
  107. package/dist/protocol/images.d.ts +288 -0
  108. package/dist/protocol/images.js +229 -0
  109. package/dist/protocol/index.d.ts +69 -0
  110. package/dist/protocol/index.js +74 -0
  111. package/dist/protocol/inference-headers.d.ts +3 -0
  112. package/dist/protocol/keepalive.d.ts +36 -0
  113. package/dist/protocol/keepalive.js +51 -0
  114. package/dist/protocol/local-auth.d.ts +125 -0
  115. package/dist/protocol/local-auth.js +227 -0
  116. package/dist/protocol/local-device-control.d.ts +108 -0
  117. package/{protocol/local-device-control.ts → dist/protocol/local-device-control.js} +40 -70
  118. package/dist/protocol/local-provider.d.ts +105 -0
  119. package/dist/protocol/local-provider.js +213 -0
  120. package/dist/protocol/local-session.d.ts +70 -0
  121. package/dist/protocol/local-session.js +87 -0
  122. package/dist/protocol/marketplace.d.ts +190 -0
  123. package/dist/protocol/marketplace.js +140 -0
  124. package/{protocol/media-attempt.ts → dist/protocol/media-attempt.d.ts} +11 -50
  125. package/dist/protocol/media-attempt.js +50 -0
  126. package/dist/protocol/media-bytes.d.ts +8 -0
  127. package/dist/protocol/media-bytes.js +21 -0
  128. package/dist/protocol/media-default.d.ts +56 -0
  129. package/dist/protocol/media-default.js +302 -0
  130. package/{protocol/media-dimensions.ts → dist/protocol/media-dimensions.d.ts} +11 -78
  131. package/dist/protocol/media-dimensions.js +90 -0
  132. package/dist/protocol/media-input.d.ts +20 -0
  133. package/dist/protocol/media-input.js +29 -0
  134. package/dist/protocol/media-model.d.ts +77 -0
  135. package/dist/protocol/media-model.js +89 -0
  136. package/{protocol/media-option-issue.ts → dist/protocol/media-option-issue.d.ts} +25 -53
  137. package/dist/protocol/media-option-issue.js +50 -0
  138. package/dist/protocol/media-types.d.ts +14 -0
  139. package/dist/protocol/media-types.js +61 -0
  140. package/dist/protocol/model-match.d.ts +254 -0
  141. package/dist/protocol/model-match.js +760 -0
  142. package/dist/protocol/model-settings.d.ts +153 -0
  143. package/dist/protocol/model-settings.js +246 -0
  144. package/dist/protocol/models.d.ts +1065 -0
  145. package/dist/protocol/models.js +638 -0
  146. package/dist/protocol/mux.d.ts +350 -0
  147. package/dist/protocol/mux.js +595 -0
  148. package/{protocol/plan-surface.ts → dist/protocol/plan-surface.d.ts} +12 -26
  149. package/dist/protocol/plan-surface.js +39 -0
  150. package/dist/protocol/provider-models.d.ts +8 -0
  151. package/{protocol/provider-models.ts → dist/protocol/provider-models.js} +7 -9
  152. package/dist/protocol/provider-status.d.ts +59 -0
  153. package/dist/protocol/provider-status.js +142 -0
  154. package/dist/protocol/provider-tier.d.ts +34 -0
  155. package/{protocol/provider-tier.ts → dist/protocol/provider-tier.js} +9 -34
  156. package/dist/protocol/provider-usage.d.ts +230 -0
  157. package/dist/protocol/provider-usage.js +214 -0
  158. package/dist/protocol/providers.d.ts +2496 -0
  159. package/dist/protocol/providers.js +723 -0
  160. package/dist/protocol/public-usage-index.d.ts +449 -0
  161. package/dist/protocol/public-usage-index.js +279 -0
  162. package/dist/protocol/realtime-generated.d.ts +29 -0
  163. package/{protocol/realtime-generated.ts → dist/protocol/realtime-generated.js} +3 -5
  164. package/dist/protocol/realtime.d.ts +241 -0
  165. package/{protocol/realtime.ts → dist/protocol/realtime.js} +88 -155
  166. package/dist/protocol/registry-pointer.d.ts +24 -0
  167. package/dist/protocol/registry-pointer.js +78 -0
  168. package/dist/protocol/relay.d.ts +1152 -0
  169. package/{protocol/relay.ts → dist/protocol/relay.js} +237 -370
  170. package/dist/protocol/replay-session.d.ts +4 -0
  171. package/{protocol/replay-session.ts → dist/protocol/replay-session.js} +1 -8
  172. package/dist/protocol/responses.d.ts +303 -0
  173. package/dist/protocol/responses.js +240 -0
  174. package/dist/protocol/semver.d.ts +59 -0
  175. package/dist/protocol/semver.js +171 -0
  176. package/{protocol/setup-mode.ts → dist/protocol/setup-mode.d.ts} +4 -12
  177. package/dist/protocol/setup-mode.js +18 -0
  178. package/dist/protocol/sha256-hex.d.ts +2 -0
  179. package/dist/protocol/sha256-hex.js +93 -0
  180. package/dist/protocol/stats.d.ts +711 -0
  181. package/dist/protocol/stats.js +353 -0
  182. package/dist/protocol/streaming.d.ts +16 -0
  183. package/dist/protocol/streaming.js +15 -0
  184. package/{protocol/subscription-daemon-floors.ts → dist/protocol/subscription-daemon-floors.d.ts} +8 -14
  185. package/dist/protocol/subscription-daemon-floors.js +4 -0
  186. package/dist/protocol/subscription-provider-compat.d.ts +44 -0
  187. package/dist/protocol/subscription-provider-compat.js +67 -0
  188. package/dist/protocol/subscription-provider.d.ts +15 -0
  189. package/dist/protocol/subscription-provider.js +17 -0
  190. package/dist/protocol/team-grant.d.ts +14 -0
  191. package/{protocol/team-grant.ts → dist/protocol/team-grant.js} +0 -3
  192. package/dist/protocol/team-shareable.d.ts +6 -0
  193. package/{protocol/team-shareable.ts → dist/protocol/team-shareable.js} +29 -33
  194. package/dist/protocol/transcription-encoding.d.ts +25 -0
  195. package/dist/protocol/transcription-encoding.js +47 -0
  196. package/{protocol/url-locality-dns.ts → dist/protocol/url-locality-dns.d.ts} +1 -23
  197. package/dist/protocol/url-locality-dns.js +33 -0
  198. package/dist/protocol/url-locality.d.ts +45 -0
  199. package/dist/protocol/url-locality.js +288 -0
  200. package/dist/protocol/usage-snapshots.d.ts +8 -0
  201. package/{protocol/usage-snapshots.ts → dist/protocol/usage-snapshots.js} +1 -2
  202. package/dist/protocol/vendor-cli-install.d.ts +20 -0
  203. package/{protocol/vendor-cli-install.ts → dist/protocol/vendor-cli-install.js} +10 -15
  204. package/dist/protocol/video-job-plan.d.ts +18 -0
  205. package/dist/protocol/video-job-plan.js +44 -0
  206. package/dist/protocol/videos.d.ts +107 -0
  207. package/dist/protocol/videos.js +154 -0
  208. package/dist/tunnel/channel-envelope.d.ts +53 -0
  209. package/dist/tunnel/channel-envelope.js +100 -0
  210. package/dist/tunnel/codec.d.ts +71 -0
  211. package/dist/tunnel/codec.js +151 -0
  212. package/dist/tunnel/device-anchor.d.ts +62 -0
  213. package/dist/tunnel/device-anchor.js +168 -0
  214. package/dist/tunnel/device-control.d.ts +50 -0
  215. package/dist/tunnel/device-control.js +88 -0
  216. package/dist/tunnel/device-grant.d.ts +91 -0
  217. package/dist/tunnel/device-grant.js +105 -0
  218. package/dist/tunnel/fleet.d.ts +28 -0
  219. package/dist/tunnel/fleet.js +41 -0
  220. package/dist/tunnel/index.d.ts +22 -0
  221. package/dist/tunnel/index.js +22 -0
  222. package/dist/tunnel/mux.d.ts +64 -0
  223. package/dist/tunnel/mux.js +449 -0
  224. package/dist/tunnel/peer-link.d.ts +88 -0
  225. package/dist/tunnel/peer-link.js +271 -0
  226. package/dist/tunnel/rtc-auth.d.ts +159 -0
  227. package/dist/tunnel/rtc-auth.js +340 -0
  228. package/dist/tunnel/rtc-duplex.d.ts +52 -0
  229. package/dist/tunnel/rtc-duplex.js +148 -0
  230. package/dist/tunnel/rtc-ice.d.ts +55 -0
  231. package/dist/tunnel/rtc-ice.js +100 -0
  232. package/dist/tunnel/secure.d.ts +179 -0
  233. package/dist/tunnel/secure.js +936 -0
  234. package/dist/tunnel/stream-reset-error.d.ts +6 -0
  235. package/dist/tunnel/stream-reset-error.js +9 -0
  236. package/dist/tunnel/streams.d.ts +244 -0
  237. package/dist/tunnel/streams.js +1071 -0
  238. package/dist/tunnel/team-grant.d.ts +90 -0
  239. package/dist/tunnel/team-grant.js +226 -0
  240. package/dist/tunnel/wire-bytes.d.ts +32 -0
  241. package/dist/tunnel/wire-bytes.js +90 -0
  242. package/dist/vault/api-key.d.ts +71 -0
  243. package/dist/vault/api-key.js +130 -0
  244. package/{vault/argon2.ts → dist/vault/argon2.d.ts} +18 -53
  245. package/dist/vault/argon2.js +82 -0
  246. package/dist/vault/cli-auth-seal.d.ts +35 -0
  247. package/dist/vault/cli-auth-seal.js +78 -0
  248. package/dist/vault/cred-seal.d.ts +18 -0
  249. package/dist/vault/cred-seal.js +86 -0
  250. package/dist/vault/credential.d.ts +21 -0
  251. package/dist/vault/credential.js +26 -0
  252. package/dist/vault/crypto.d.ts +51 -0
  253. package/dist/vault/crypto.js +156 -0
  254. package/dist/vault/daemon-attest.d.ts +68 -0
  255. package/dist/vault/daemon-attest.js +147 -0
  256. package/dist/vault/derive.d.ts +34 -0
  257. package/dist/vault/derive.js +84 -0
  258. package/dist/vault/device-access.d.ts +17 -0
  259. package/dist/vault/device-access.js +77 -0
  260. package/dist/vault/device-anchor.d.ts +42 -0
  261. package/dist/vault/device-anchor.js +90 -0
  262. package/dist/vault/device-control.d.ts +80 -0
  263. package/{vault/device-control.ts → dist/vault/device-control.js} +46 -104
  264. package/dist/vault/handoff.d.ts +102 -0
  265. package/dist/vault/handoff.js +236 -0
  266. package/dist/vault/index.d.ts +21 -0
  267. package/dist/vault/index.js +21 -0
  268. package/dist/vault/passkey.d.ts +82 -0
  269. package/{vault/passkey.ts → dist/vault/passkey.js} +63 -153
  270. package/dist/vault/phrase.d.ts +40 -0
  271. package/{vault/phrase.ts → dist/vault/phrase.js} +17 -23
  272. package/dist/vault/pin.d.ts +46 -0
  273. package/dist/vault/pin.js +92 -0
  274. package/dist/vault/public-key-seal.d.ts +17 -0
  275. package/dist/vault/public-key-seal.js +59 -0
  276. package/dist/vault/seed.d.ts +96 -0
  277. package/dist/vault/seed.js +179 -0
  278. package/dist/vault/team.d.ts +134 -0
  279. package/dist/vault/team.js +217 -0
  280. package/dist/vault/vault-item.d.ts +45 -0
  281. package/dist/vault/vault-item.js +62 -0
  282. package/dist/vault/vault-migrate-digest.d.ts +10 -0
  283. package/dist/vault/vault-migrate-digest.js +22 -0
  284. package/dist/vault/wrapped.d.ts +19 -0
  285. package/dist/vault/wrapped.js +52 -0
  286. package/dist/wire/adapters/messages/anthropic-map.d.ts +8 -0
  287. package/dist/wire/adapters/messages/anthropic-map.js +32 -0
  288. package/dist/wire/adapters/messages/index.d.ts +7 -0
  289. package/dist/wire/adapters/messages/index.js +7 -0
  290. package/dist/wire/adapters/messages/reasoning-from-items.d.ts +14 -0
  291. package/dist/wire/adapters/messages/reasoning-from-items.js +39 -0
  292. package/dist/wire/adapters/messages/reasoning-signature.d.ts +81 -0
  293. package/dist/wire/adapters/messages/reasoning-signature.js +180 -0
  294. package/dist/wire/adapters/messages/request.d.ts +28 -0
  295. package/dist/wire/adapters/messages/request.js +490 -0
  296. package/dist/wire/adapters/messages/response.d.ts +10 -0
  297. package/dist/wire/adapters/messages/response.js +177 -0
  298. package/dist/wire/adapters/messages/streaming.d.ts +134 -0
  299. package/dist/wire/adapters/messages/streaming.js +791 -0
  300. package/dist/wire/adapters/messages/usage.d.ts +20 -0
  301. package/dist/wire/adapters/messages/usage.js +10 -0
  302. package/dist/wire/adapters/responses/index.d.ts +3 -0
  303. package/dist/wire/adapters/responses/index.js +3 -0
  304. package/dist/wire/adapters/responses/request.d.ts +2 -0
  305. package/dist/wire/adapters/responses/request.js +287 -0
  306. package/dist/wire/adapters/responses/response.d.ts +11 -0
  307. package/dist/wire/adapters/responses/response.js +69 -0
  308. package/dist/wire/adapters/responses/streaming.d.ts +2 -0
  309. package/dist/wire/adapters/responses/streaming.js +267 -0
  310. package/dist/wire/features/account-rank.d.ts +61 -0
  311. package/dist/wire/features/account-rank.js +109 -0
  312. package/dist/wire/features/compaction/compact-request.d.ts +69 -0
  313. package/dist/wire/features/compaction/compact-request.js +667 -0
  314. package/dist/wire/features/compaction/compaction-text.d.ts +17 -0
  315. package/dist/wire/features/compaction/compaction-text.js +29 -0
  316. package/dist/wire/features/context-demote.d.ts +15 -0
  317. package/dist/wire/features/context-demote.js +45 -0
  318. package/dist/wire/features/context-overflow-strategy.d.ts +12 -0
  319. package/dist/wire/features/context-overflow-strategy.js +8 -0
  320. package/dist/wire/features/context-skip.d.ts +120 -0
  321. package/{wire/features/context-skip.ts → dist/wire/features/context-skip.js} +23 -57
  322. package/dist/wire/features/conversation-affinity.d.ts +49 -0
  323. package/dist/wire/features/conversation-affinity.js +121 -0
  324. package/dist/wire/features/max-tokens-backfill.d.ts +50 -0
  325. package/dist/wire/features/max-tokens-backfill.js +118 -0
  326. package/dist/wire/features/model-caps.d.ts +7 -0
  327. package/dist/wire/features/model-caps.js +40 -0
  328. package/dist/wire/features/model-settings.d.ts +3 -0
  329. package/dist/wire/features/model-settings.js +13 -0
  330. package/dist/wire/features/output-limit-clamp.d.ts +14 -0
  331. package/dist/wire/features/output-limit-clamp.js +36 -0
  332. package/dist/wire/features/quota-gate.d.ts +16 -0
  333. package/dist/wire/features/quota-gate.js +48 -0
  334. package/dist/wire/index.d.ts +44 -0
  335. package/dist/wire/index.js +44 -0
  336. package/dist/wire/lib/attempt-outcome.d.ts +19 -0
  337. package/dist/wire/lib/attempt-outcome.js +18 -0
  338. package/{wire/lib/canonical/content-part.ts → dist/wire/lib/canonical/content-part.d.ts} +12 -18
  339. package/dist/wire/lib/canonical/content-part.js +11 -0
  340. package/dist/wire/lib/canonical/count-tokens-capability.d.ts +52 -0
  341. package/dist/wire/lib/canonical/count-tokens-capability.js +109 -0
  342. package/{wire/lib/canonical/encoding-select.ts → dist/wire/lib/canonical/encoding-select.d.ts} +7 -24
  343. package/dist/wire/lib/canonical/encoding-select.js +26 -0
  344. package/dist/wire/lib/canonical/image-signature.d.ts +20 -0
  345. package/dist/wire/lib/canonical/image-signature.js +184 -0
  346. package/dist/wire/lib/canonical/image-sse.d.ts +88 -0
  347. package/dist/wire/lib/canonical/image-sse.js +173 -0
  348. package/{wire/lib/canonical/message.ts → dist/wire/lib/canonical/message.d.ts} +2 -20
  349. package/dist/wire/lib/canonical/message.js +31 -0
  350. package/dist/wire/lib/canonical/token-estimate.d.ts +98 -0
  351. package/dist/wire/lib/canonical/token-estimate.js +230 -0
  352. package/dist/wire/lib/encrypted-content.d.ts +22 -0
  353. package/dist/wire/lib/encrypted-content.js +55 -0
  354. package/dist/wire/lib/error-class.d.ts +57 -0
  355. package/dist/wire/lib/error-class.js +97 -0
  356. package/dist/wire/lib/error-envelope.d.ts +20 -0
  357. package/dist/wire/lib/error-envelope.js +53 -0
  358. package/dist/wire/lib/forwarded-headers.d.ts +16 -0
  359. package/{wire/lib/forwarded-headers.ts → dist/wire/lib/forwarded-headers.js} +62 -72
  360. package/dist/wire/lib/provider-error-rules.d.ts +21 -0
  361. package/dist/wire/lib/provider-error-rules.js +20 -0
  362. package/{wire/lib/refusal.ts → dist/wire/lib/refusal.d.ts} +3 -13
  363. package/dist/wire/lib/refusal.js +27 -0
  364. package/dist/wire/lib/responses-apply-patch.d.ts +57 -0
  365. package/dist/wire/lib/responses-apply-patch.js +81 -0
  366. package/dist/wire/lib/responses-namespace.d.ts +27 -0
  367. package/{wire/lib/responses-namespace.ts → dist/wire/lib/responses-namespace.js} +16 -32
  368. package/dist/wire/lib/secret-scrub.d.ts +23 -0
  369. package/dist/wire/lib/secret-scrub.js +72 -0
  370. package/dist/wire/lib/streaming/accumulate.d.ts +12 -0
  371. package/dist/wire/lib/streaming/accumulate.js +187 -0
  372. package/dist/wire/lib/streaming/finish-reason.d.ts +20 -0
  373. package/dist/wire/lib/streaming/finish-reason.js +15 -0
  374. package/{wire/lib/streaming/peek.ts → dist/wire/lib/streaming/peek.d.ts} +13 -82
  375. package/dist/wire/lib/streaming/peek.js +100 -0
  376. package/dist/wire/lib/streaming/provider-decode.d.ts +57 -0
  377. package/dist/wire/lib/streaming/provider-decode.js +210 -0
  378. package/dist/wire/lib/streaming/response-stream.d.ts +16 -0
  379. package/dist/wire/lib/streaming/response-stream.js +64 -0
  380. package/dist/wire/lib/streaming/sse.d.ts +130 -0
  381. package/dist/wire/lib/streaming/sse.js +600 -0
  382. package/dist/wire/lib/streaming/strip-tool-calls.d.ts +14 -0
  383. package/dist/wire/lib/streaming/strip-tool-calls.js +75 -0
  384. package/dist/wire/lib/streaming/upstream-error.d.ts +32 -0
  385. package/dist/wire/lib/streaming/upstream-error.js +45 -0
  386. package/dist/wire/lib/strip-subagent-isolation.d.ts +16 -0
  387. package/dist/wire/lib/strip-subagent-isolation.js +240 -0
  388. package/dist/wire/lib/thinking-signature.d.ts +56 -0
  389. package/{wire/lib/thinking-signature.ts → dist/wire/lib/thinking-signature.js} +77 -84
  390. package/dist/wire/lib/token-ruler/bpe-core.d.ts +105 -0
  391. package/dist/wire/lib/token-ruler/bpe-core.js +398 -0
  392. package/dist/wire/lib/token-ruler/index.d.ts +2 -0
  393. package/dist/wire/lib/token-ruler/index.js +2 -0
  394. package/dist/wire/lib/token-ruler/ruler.d.ts +36 -0
  395. package/dist/wire/lib/token-ruler/ruler.js +50 -0
  396. package/dist/wire/lib/token-ruler/vocab/claude-ranks.d.ts +14 -0
  397. package/dist/wire/lib/token-ruler/vocab/claude-ranks.js +16 -0
  398. package/{wire/lib/token-ruler/vocab/claude.ts → dist/wire/lib/token-ruler/vocab/claude.d.ts} +2 -12
  399. package/dist/wire/lib/token-ruler/vocab/claude.js +8 -0
  400. package/dist/wire/lib/token-ruler/vocab/o200k-ranks.d.ts +3 -0
  401. package/dist/wire/lib/token-ruler/vocab/o200k-ranks.js +18 -0
  402. package/dist/wire/lib/token-ruler/vocab/o200k.d.ts +11 -0
  403. package/dist/wire/lib/token-ruler/vocab/o200k.js +6 -0
  404. package/dist/wire/lib/tool-name-map.d.ts +44 -0
  405. package/dist/wire/lib/tool-name-map.js +186 -0
  406. package/dist/wire/lib/tool-schema.d.ts +15 -0
  407. package/dist/wire/lib/tool-schema.js +307 -0
  408. package/dist/wire/lib/usage-observer.d.ts +9 -0
  409. package/dist/wire/lib/usage-observer.js +108 -0
  410. package/dist/wire/providers/anthropic/adaptive-thinking.d.ts +125 -0
  411. package/dist/wire/providers/anthropic/adaptive-thinking.js +221 -0
  412. package/dist/wire/providers/anthropic/beta-headers.d.ts +44 -0
  413. package/{wire/providers/anthropic/beta-headers.ts → dist/wire/providers/anthropic/beta-headers.js} +57 -79
  414. package/dist/wire/providers/anthropic/index.d.ts +6 -0
  415. package/{wire/providers/anthropic/index.ts → dist/wire/providers/anthropic/index.js} +6 -6
  416. package/dist/wire/providers/anthropic/request.d.ts +12 -0
  417. package/dist/wire/providers/anthropic/request.js +456 -0
  418. package/dist/wire/providers/anthropic/response.d.ts +3 -0
  419. package/dist/wire/providers/anthropic/response.js +126 -0
  420. package/dist/wire/providers/anthropic/streaming.d.ts +28 -0
  421. package/dist/wire/providers/anthropic/streaming.js +268 -0
  422. package/dist/wire/providers/anthropic/web-search-domains.d.ts +7 -0
  423. package/dist/wire/providers/anthropic/web-search-domains.js +36 -0
  424. package/dist/wire/providers/chatgpt/common.d.ts +27 -0
  425. package/{wire/providers/chatgpt/common.ts → dist/wire/providers/chatgpt/common.js} +69 -89
  426. package/dist/wire/providers/chatgpt/index.d.ts +4 -0
  427. package/{wire/providers/chatgpt/index.ts → dist/wire/providers/chatgpt/index.js} +4 -4
  428. package/dist/wire/providers/chatgpt/request.d.ts +132 -0
  429. package/dist/wire/providers/chatgpt/request.js +696 -0
  430. package/dist/wire/providers/chatgpt/streaming.d.ts +69 -0
  431. package/dist/wire/providers/chatgpt/streaming.js +761 -0
  432. package/dist/wire/providers/chatgpt/web-search.d.ts +19 -0
  433. package/dist/wire/providers/chatgpt/web-search.js +55 -0
  434. package/dist/wire/providers/grok/web-search.d.ts +23 -0
  435. package/dist/wire/providers/grok/web-search.js +74 -0
  436. package/dist/wire/providers/kimi/web-search.d.ts +48 -0
  437. package/dist/wire/providers/kimi/web-search.js +106 -0
  438. package/dist/wire/providers/upstream-deny.d.ts +61 -0
  439. package/dist/wire/providers/upstream-deny.js +293 -0
  440. package/dist/wire/providers/upstream-request.d.ts +104 -0
  441. package/dist/wire/providers/upstream-request.js +411 -0
  442. package/package.json +105 -23
  443. package/ARCHITECTURE.md +0 -43
  444. package/client/chat.ts +0 -140
  445. package/client/devices.ts +0 -269
  446. package/client/http.ts +0 -72
  447. package/client/index.ts +0 -129
  448. package/client/relay-mux.ts +0 -547
  449. package/client/types.ts +0 -51
  450. package/client/vault.ts +0 -239
  451. package/connect/chat.ts +0 -58
  452. package/connect/client.ts +0 -240
  453. package/connect/config.ts +0 -47
  454. package/connect/errors.ts +0 -121
  455. package/connect/oauth.ts +0 -265
  456. package/connect/routes.ts +0 -234
  457. package/connect/store.ts +0 -107
  458. package/mcp/handle.ts +0 -24
  459. package/mcp/index.ts +0 -76
  460. package/mcp/server.ts +0 -319
  461. package/mcp/tools/marketplace.ts +0 -439
  462. package/mcp/tools/memory-client.ts +0 -297
  463. package/mcp/tools/memory-config.ts +0 -32
  464. package/mcp/tools/memory.ts +0 -369
  465. package/mcp/tools/model-priority.ts +0 -88
  466. package/mcp/tools/openllm.ts +0 -883
  467. package/mcp/types.ts +0 -28
  468. package/openapi/call.ts +0 -90
  469. package/openapi/index.ts +0 -8
  470. package/openapi/openapi.json +0 -80213
  471. package/openapi/operations.ts +0 -2075
  472. package/protocol/CONTRIBUTING.md +0 -21
  473. package/protocol/README.md +0 -134
  474. package/protocol/access.ts +0 -186
  475. package/protocol/agent.ts +0 -991
  476. package/protocol/api-key-syntax.ts +0 -105
  477. package/protocol/assets/openllm-light.svg +0 -18
  478. package/protocol/assets/openllm.svg +0 -18
  479. package/protocol/audio.ts +0 -29
  480. package/protocol/auth.ts +0 -142
  481. package/protocol/changelog.ts +0 -155
  482. package/protocol/chat.ts +0 -458
  483. package/protocol/client-registry.ts +0 -356
  484. package/protocol/config.ts +0 -345
  485. package/protocol/cooldown-reason.ts +0 -78
  486. package/protocol/cost.ts +0 -10
  487. package/protocol/daemon-port.ts +0 -31
  488. package/protocol/daemon.ts +0 -1524
  489. package/protocol/default-chains.ts +0 -66
  490. package/protocol/device-state.ts +0 -85
  491. package/protocol/doctor-report.ts +0 -947
  492. package/protocol/errors.ts +0 -14
  493. package/protocol/image-edit-parse.ts +0 -263
  494. package/protocol/images.ts +0 -298
  495. package/protocol/index.ts +0 -74
  496. package/protocol/keepalive.ts +0 -69
  497. package/protocol/local-auth.ts +0 -300
  498. package/protocol/local-provider.ts +0 -288
  499. package/protocol/local-session.ts +0 -118
  500. package/protocol/marketplace.ts +0 -187
  501. package/protocol/media-bytes.ts +0 -28
  502. package/protocol/media-default.ts +0 -357
  503. package/protocol/media-input.ts +0 -61
  504. package/protocol/media-model.ts +0 -142
  505. package/protocol/media-types.ts +0 -70
  506. package/protocol/model-match.ts +0 -1051
  507. package/protocol/model-settings.ts +0 -327
  508. package/protocol/models.ts +0 -767
  509. package/protocol/mux.ts +0 -722
  510. package/protocol/provider-status.ts +0 -206
  511. package/protocol/provider-usage.ts +0 -263
  512. package/protocol/providers.ts +0 -901
  513. package/protocol/public-usage-index.ts +0 -354
  514. package/protocol/registry-pointer.ts +0 -118
  515. package/protocol/responses.ts +0 -280
  516. package/protocol/semver.ts +0 -182
  517. package/protocol/sha256-hex.ts +0 -98
  518. package/protocol/stats.ts +0 -406
  519. package/protocol/streaming.ts +0 -19
  520. package/protocol/subscription-provider-compat.ts +0 -104
  521. package/protocol/subscription-provider.ts +0 -32
  522. package/protocol/transcription-encoding.ts +0 -76
  523. package/protocol/url-locality.ts +0 -288
  524. package/protocol/video-job-plan.ts +0 -50
  525. package/protocol/videos.ts +0 -227
  526. package/tsconfig.json +0 -14
  527. package/tunnel/ARCHITECTURE.md +0 -111
  528. package/tunnel/assets/openllm-light.svg +0 -18
  529. package/tunnel/assets/openllm.svg +0 -18
  530. package/tunnel/channel-envelope.ts +0 -139
  531. package/tunnel/codec.ts +0 -191
  532. package/tunnel/device-anchor.ts +0 -229
  533. package/tunnel/device-control.ts +0 -118
  534. package/tunnel/device-grant.ts +0 -173
  535. package/tunnel/fleet.ts +0 -77
  536. package/tunnel/index.ts +0 -22
  537. package/tunnel/mux.ts +0 -580
  538. package/tunnel/peer-link.ts +0 -390
  539. package/tunnel/rtc-auth.ts +0 -415
  540. package/tunnel/rtc-duplex.ts +0 -187
  541. package/tunnel/rtc-ice.ts +0 -136
  542. package/tunnel/secure.ts +0 -1298
  543. package/tunnel/stream-reset-error.ts +0 -14
  544. package/tunnel/streams.ts +0 -1430
  545. package/tunnel/team-grant.ts +0 -302
  546. package/tunnel/wire-bytes.ts +0 -102
  547. package/vault/ARCHITECTURE.md +0 -470
  548. package/vault/api-key.ts +0 -190
  549. package/vault/cli-auth-seal.ts +0 -157
  550. package/vault/cred-seal.ts +0 -146
  551. package/vault/credential.ts +0 -55
  552. package/vault/crypto.ts +0 -210
  553. package/vault/daemon-attest.ts +0 -229
  554. package/vault/derive.ts +0 -113
  555. package/vault/device-access.ts +0 -87
  556. package/vault/device-anchor.ts +0 -185
  557. package/vault/handoff.ts +0 -396
  558. package/vault/index.ts +0 -21
  559. package/vault/pin.ts +0 -153
  560. package/vault/public-key-seal.ts +0 -131
  561. package/vault/seed.ts +0 -272
  562. package/vault/team.ts +0 -355
  563. package/vault/vault-item.ts +0 -131
  564. package/vault/vault-migrate-digest.ts +0 -29
  565. package/vault/wrapped.ts +0 -77
  566. package/wire/ARCHITECTURE.md +0 -90
  567. package/wire/CONTRIBUTING.md +0 -19
  568. package/wire/adapters/messages/anthropic-map.ts +0 -37
  569. package/wire/adapters/messages/index.ts +0 -7
  570. package/wire/adapters/messages/reasoning-from-items.ts +0 -38
  571. package/wire/adapters/messages/reasoning-signature.ts +0 -243
  572. package/wire/adapters/messages/request.ts +0 -574
  573. package/wire/adapters/messages/response.ts +0 -215
  574. package/wire/adapters/messages/streaming.ts +0 -1027
  575. package/wire/adapters/messages/usage.ts +0 -43
  576. package/wire/adapters/responses/index.ts +0 -3
  577. package/wire/adapters/responses/request.ts +0 -395
  578. package/wire/adapters/responses/response.ts +0 -88
  579. package/wire/adapters/responses/streaming.ts +0 -344
  580. package/wire/assets/openllm-light.svg +0 -18
  581. package/wire/assets/openllm.svg +0 -18
  582. package/wire/features/account-rank.ts +0 -166
  583. package/wire/features/compaction/compact-request.ts +0 -862
  584. package/wire/features/compaction/compaction-text.ts +0 -43
  585. package/wire/features/context-demote.ts +0 -47
  586. package/wire/features/context-overflow-strategy.ts +0 -26
  587. package/wire/features/conversation-affinity.ts +0 -144
  588. package/wire/features/max-tokens-backfill.ts +0 -141
  589. package/wire/features/model-caps.ts +0 -53
  590. package/wire/features/model-settings.ts +0 -24
  591. package/wire/features/output-limit-clamp.ts +0 -64
  592. package/wire/features/quota-gate.ts +0 -85
  593. package/wire/index.ts +0 -44
  594. package/wire/lib/attempt-outcome.ts +0 -43
  595. package/wire/lib/canonical/count-tokens-capability.ts +0 -138
  596. package/wire/lib/canonical/image-signature.ts +0 -202
  597. package/wire/lib/canonical/image-sse.ts +0 -216
  598. package/wire/lib/canonical/token-estimate.ts +0 -266
  599. package/wire/lib/encrypted-content.ts +0 -66
  600. package/wire/lib/error-class.ts +0 -154
  601. package/wire/lib/error-envelope.ts +0 -56
  602. package/wire/lib/provider-error-rules.ts +0 -48
  603. package/wire/lib/responses-apply-patch.ts +0 -104
  604. package/wire/lib/secret-scrub.ts +0 -101
  605. package/wire/lib/streaming/accumulate.ts +0 -221
  606. package/wire/lib/streaming/finish-reason.ts +0 -33
  607. package/wire/lib/streaming/provider-decode.ts +0 -259
  608. package/wire/lib/streaming/response-stream.ts +0 -71
  609. package/wire/lib/streaming/sse.ts +0 -699
  610. package/wire/lib/streaming/strip-tool-calls.ts +0 -95
  611. package/wire/lib/streaming/upstream-error.ts +0 -58
  612. package/wire/lib/strip-subagent-isolation.ts +0 -284
  613. package/wire/lib/token-ruler/bpe-core.ts +0 -426
  614. package/wire/lib/token-ruler/index.ts +0 -2
  615. package/wire/lib/token-ruler/ruler.ts +0 -79
  616. package/wire/lib/token-ruler/vocab/claude-ranks.ts +0 -16
  617. package/wire/lib/token-ruler/vocab/o200k-ranks.ts +0 -18
  618. package/wire/lib/token-ruler/vocab/o200k.ts +0 -19
  619. package/wire/lib/tool-name-map.ts +0 -271
  620. package/wire/lib/tool-schema.ts +0 -353
  621. package/wire/lib/usage-observer.ts +0 -125
  622. package/wire/providers/anthropic/adaptive-thinking.ts +0 -291
  623. package/wire/providers/anthropic/request.ts +0 -607
  624. package/wire/providers/anthropic/response.ts +0 -155
  625. package/wire/providers/anthropic/streaming.ts +0 -315
  626. package/wire/providers/anthropic/web-search-domains.ts +0 -49
  627. package/wire/providers/chatgpt/request.ts +0 -959
  628. package/wire/providers/chatgpt/streaming.ts +0 -1007
  629. package/wire/providers/chatgpt/web-search.ts +0 -63
  630. package/wire/providers/grok/web-search.ts +0 -87
  631. package/wire/providers/kimi/web-search.ts +0 -145
  632. package/wire/providers/upstream-deny.ts +0 -355
  633. package/wire/providers/upstream-request.ts +0 -619
  634. /package/{protocol/inference-headers.ts → dist/protocol/inference-headers.js} +0 -0
@@ -0,0 +1,1286 @@
1
+ import { Schema as S } from "effect";
2
+ import { AuthSessionLostDiagnosticCode } from "./auth.js";
3
+ import { ContextOverflowStrategy, FallbackGroup, ModelFallbackBinding, } from "./config.js";
4
+ import { CooldownReason } from "./cooldown-reason.js";
5
+ import { DaemonReportingPolicy } from "./doctor-report-policy.js";
6
+ import { ExecutionSelection } from "./execution-selection.js";
7
+ import { AUTH_OPERATIONS, AUTH_RELAY_WAIT_MAX_MS } from "./local-auth.js";
8
+ import { DeviceAccessPinReport, DeviceSessionsReport, } from "./local-device-control.js";
9
+ import { LocalKeyProviderSlug } from "./local-provider.js";
10
+ import { ModelSettingDefinitions, ModelSettingsOverrides, } from "./model-settings.js";
11
+ import { ModelAudioSupport, ModelCaps, ModelCapsDefaultRule, ProviderModelList, SubscriptionMeter, } from "./models.js";
12
+ import { DaemonProviderObservation, DaemonProviderReasonCode, DaemonProviderUpstreamAuthCooldown, } from "./provider-status.js";
13
+ import { ProviderUsageSnapshot } from "./provider-usage.js";
14
+ import { ReplaySessionId } from "./replay-session.js";
15
+ import { RequestStatus } from "./stats.js";
16
+ import { SubscriptionProviderSlug } from "./subscription-provider.js";
17
+ import { TEAM_GRANT_B64_MAX } from "./team-grant.js";
18
+ import { VendorCliInstall } from "./vendor-cli-install.js";
19
+ // ─── GET /api/daemon/bootstrap (daemon → cloud) ──────────────────────
20
+ //
21
+ // One snapshot with everything the local pipeline needs to resolve a
22
+ // chain + price-free dispatch: the model catalog, the provider prefixes,
23
+ // and the authenticated user's fallback config. Pulled at boot and
24
+ // refreshed on a TTL so the daemon stays in lockstep with cloud config
25
+ // without recompiling.
26
+ export const DaemonCatalogEntry = S.Struct({
27
+ settings: S.optional(ModelSettingDefinitions),
28
+ model_id: S.String,
29
+ provider: S.String,
30
+ provider_model_id: S.String,
31
+ input_token_limit: S.NullOr(S.Number),
32
+ output_token_limit: S.NullOr(S.Number),
33
+ subscription_meter: S.optional(SubscriptionMeter),
34
+ /**
35
+ * Catalog capabilities for this model. Optional so older clouds keep
36
+ * bootstrapping newer daemons. Absent / empty = unknown (never treated
37
+ * as known-non-vision). The walker vision gate reads this on each hop.
38
+ *
39
+ * Open string array: unknown future literals (e.g. `image_editing`,
40
+ * `realtime`) must not fail the whole bootstrap. Older compiled daemons
41
+ * still decode a closed `ModelCapability` set — cloud encoders should
42
+ * send {@link toBootstrapSafeCapabilities} until those binaries are
43
+ * replaced.
44
+ */
45
+ capabilities: S.optional(S.Array(S.String)),
46
+ /** Catalog-declared final outbound-body constraints for this model. */
47
+ caps: S.optional(ModelCaps),
48
+ /**
49
+ * Catalog-declared audio support (input/output formats, voices,
50
+ * realtime ops). The daemon's audio walker currently re-derives these
51
+ * from the provider slug while the catalog already declares them per
52
+ * model, so the card is the correction channel.
53
+ *
54
+ * Optional, like `caps`: an older cloud omits it and a newer daemon
55
+ * reads absent as UNKNOWN, keeping today's provider-derived defaults.
56
+ * Delivered over the AUTHENTICATED bootstrap, never the signed plan —
57
+ * that payload covers only plan/pmids/origin, so anything appended
58
+ * there would be caller-controllable and unsigned.
59
+ */
60
+ audio_support: S.optional(ModelAudioSupport),
61
+ /** Optional so older clouds keep bootstrapping newer daemons. */
62
+ strip_subagent_isolation: S.optional(S.Boolean),
63
+ });
64
+ export const DaemonBootstrap = S.Struct({
65
+ catalog: S.Array(DaemonCatalogEntry),
66
+ provider_prefixes: S.Array(S.String),
67
+ /**
68
+ * Catalog-owned caps DEFAULTS for models with no catalog row. The
69
+ * daemon runs the SAME `resolveDefaultModelCaps` matcher the cloud
70
+ * does, so an un-catalogued id resolves identically on both paths and
71
+ * the two cannot drift.
72
+ *
73
+ * Optional: an older cloud omits it and the daemon simply resolves no
74
+ * defaults (absent = unknown = permissive, today's behaviour). Rules
75
+ * are DATA on the authenticated bootstrap — never the signed plan.
76
+ */
77
+ caps_defaults: S.optional(S.Array(ModelCapsDefaultRule)),
78
+ user_fallback_groups: S.Array(FallbackGroup),
79
+ user_model_fallback_bindings: S.Array(ModelFallbackBinding),
80
+ model_settings: S.optional(ModelSettingsOverrides),
81
+ /** Per-user context-window overflow routing preference. Absent means the
82
+ * historical hop-to-larger-context behaviour. */
83
+ context_overflow_strategy: S.optional(ContextOverflowStrategy),
84
+ /**
85
+ * Per-user HMAC key the daemon uses to VERIFY the plan `/api/daemon/plan`
86
+ * returns (the cloud signs with the same key). Lets the daemon reject
87
+ * a plan forged by another local process. Null when the cloud has no
88
+ * signing secret configured (dev) — the daemon then accepts unsigned
89
+ * plans. See `docs/proposals/coreless-daemon-passthrough.md` §9.
90
+ */
91
+ plan_signing_key: S.optional(S.NullOr(S.String)),
92
+ /**
93
+ * Authenticated account id for this bootstrap. Optional/additive so older
94
+ * clouds keep bootstrapping; newer daemons use it to compare relay-stamped
95
+ * `peer_user_id` on `channel_open` (cross-user → require a team grant).
96
+ */
97
+ user_id: S.optional(S.String),
98
+ /**
99
+ * Per-contributor HMAC key for verifying team device grants (same key
100
+ * origin uses to sign for this user). Null/absent when
101
+ * `NEON_AUTH_COOKIE_SECRET` is unset — team device routing is then off
102
+ * (`team_device_unavailable`); the daemon refuses team traffic.
103
+ * See `docs/plan/2026-10-26-teams.md` §16.2.
104
+ */
105
+ team_grant_key: S.optional(S.NullOr(S.String)),
106
+ /**
107
+ * The daemon binary version the cloud currently publishes (bare semver, no
108
+ * leading `v` — matches the daemon's compiled `DAEMON_VERSION`). The daemon
109
+ * compares it against its own and SELF-UPDATES when they differ (converge to
110
+ * published — the cloud is the source of truth, so republishing an older tag
111
+ * rolls daemons back). Null/absent when no release is published yet (or the
112
+ * cloud is too old to advertise it) — the daemon then never self-updates.
113
+ * See `packages/cli/daemon/src/self-update.ts`.
114
+ */
115
+ latest_version: S.optional(S.NullOr(S.String)),
116
+ /**
117
+ * The `openllmc` CLI version the cloud currently publishes (bare semver, no
118
+ * leading `v`). The daemon converges the INSTALLED CLI binary at
119
+ * `~/.openllm/bin/openllmc` to it on the same auto-update tick (and under
120
+ * the same opt-out toggle) as its own self-update — one flow, one toggle.
121
+ * The daemon never installs the CLI: an absent binary is skipped. Null/
122
+ * absent when no CLI release is published yet (or the cloud is too old to
123
+ * advertise it) — the daemon then never touches the CLI.
124
+ * One binary is both CLI and daemon now, so this is the release the daemon
125
+ * converges `~/.openllm/bin/openllm` to. See
126
+ * `packages/cli/daemon/src/updater.ts`.
127
+ */
128
+ latest_cli_version: S.optional(S.NullOr(S.String)),
129
+ /**
130
+ * The cloud's resolved `ACTIVE_SUB_METHOD` global preference — a named
131
+ * execution variant (`stream-json` / `sdk-facade` / `acp` / `app-server` /
132
+ * `msp` / `agent-sdk`, optionally `-capture`) or `handrolled`; see
133
+ * `./execution-selection`. Null = no preference: each hop uses its
134
+ * provider's registry default. Sampled once per request from the cached
135
+ * bootstrap snapshot.
136
+ */
137
+ execution_selection: S.optional(S.NullOr(ExecutionSelection)),
138
+ /**
139
+ * Per-provider overrides layered on top of `execution_selection`
140
+ * (`provider:method` entries of the same env). String-keyed so a newer
141
+ * cloud advertising a slug this daemon predates never fails bootstrap
142
+ * decode.
143
+ */
144
+ execution_selections: S.optional(S.NullOr(S.Record(S.String, ExecutionSelection))),
145
+ /**
146
+ * Cloud-controlled toggle for the daemon's SIGNED-PLAN CACHE
147
+ * (`DAEMON_PLAN_CACHE` on the cloud, default ON — an explicit `0`/`false`
148
+ * disables): when true, a `/v1/*` request that reaches the daemon
149
+ * directly may be served against the most recent
150
+ * cloud-signed plan tuple for the same model alias within a short TTL,
151
+ * skipping the per-request cloud round trip. The signature is still
152
+ * verified per request (the cached tuple is exactly what the cloud
153
+ * signed); staleness is bounded by the TTL. False → the daemon requires
154
+ * a plan on every request; ABSENT (a cloud predating the field) → the
155
+ * daemon also keeps the cache off (the cloud is the one authority). See
156
+ * docs/proposals/sub-method-simplified-execution.md §4.
157
+ */
158
+ plan_cache: S.optional(S.Boolean),
159
+ /**
160
+ * The user's FLEET subscription servers: for each subscription provider
161
+ * connected on some ONLINE daemon of this user, the serving daemon's
162
+ * key id. Computed cloud-side from `api_key_activity` presence + status
163
+ * (serve-by-default policy — every online device qualifies). A consuming
164
+ * daemon with no local credential for a subscription hop tunnels the
165
+ * request to `key_id` over the relay
166
+ * (`docs/features/sub-tunnel-and-chat-sessions.md` §1). String-keyed
167
+ * provider so newer slugs never fail an older daemon's decode; optional
168
+ * so older clouds keep bootstrapping newer daemons.
169
+ */
170
+ fleet_subscriptions: S.optional(S.Array(S.Struct({
171
+ provider: S.String,
172
+ key_id: S.String,
173
+ /** Serving daemon X25519 SPKI, absent for pre-pubkey peers. */
174
+ pubkey: S.optional(S.String),
175
+ }))),
176
+ /**
177
+ * SPKI DER (base64) of the account DEVICE-CONTROL public key (Ed25519,
178
+ * derived in the browser from the recovery phrase — never from the DEK, so
179
+ * the cloud cannot sign with it). The daemon first-use pins it UNANCHORED
180
+ * (tunnel only), follows signed rotations, and anchors only from a local
181
+ * root (install anchor / loopback); it verifies
182
+ * browser-signed device grants against it. The
183
+ * field name is historical: before `device_access_kind: "control"` it carried
184
+ * a per-key DEK-derived key ("legacy"). Null when the key is un-provisioned or
185
+ * the caller is session-only / watcher (no owning key). Optional so older
186
+ * clouds keep bootstrapping newer daemons.
187
+ */
188
+ device_access_pubkey: S.optional(S.NullOr(S.String.check(S.isMaxLength(64)))),
189
+ /**
190
+ * `"control"` when {@link device_access_pubkey} is the account control key.
191
+ * Absent = legacy per-key value (the daemon then never upgrades a pin to it
192
+ * and refuses agent sessions with `device_not_anchored`).
193
+ */
194
+ device_access_kind: S.optional(S.Literal("control")),
195
+ /**
196
+ * The control key's generation (`users.device_control_version`, the vault
197
+ * generation it was derived under). A signed rotation must carry a greater
198
+ * `cv` than the daemon's pinned version. Null/absent when unknown.
199
+ */
200
+ device_access_version: S.optional(S.NullOr(S.Number.check(S.isInt()))),
201
+ /**
202
+ * Control-key rotation statements, oldest first (base64 JSON, signed by the
203
+ * PREVIOUS control key — see `@openllmsh/sdk/tunnel` `device-control.ts`). The
204
+ * daemon walks the chain from its own pin to {@link device_access_pubkey}.
205
+ * The cloud cannot forge a step: each is signed by a key only a browser
206
+ * holding the recovery phrase ever derived.
207
+ */
208
+ device_access_rotations: S.optional(S.Array(S.String.check(S.isMaxLength(1024))).check(S.isMaxLength(8))),
209
+ /**
210
+ * Optional reporting policy. Absent on old clouds = off. Expired or
211
+ * `enabled: false` means no upload. See `doctor-report-policy.ts`.
212
+ */
213
+ reporting_policy: S.optional(DaemonReportingPolicy),
214
+ /**
215
+ * Revision of the authenticating key's access policy (models, routes,
216
+ * caps). The daemon drops every cached plan when it changes, so a plan
217
+ * cached under an older policy is never replayed. Null for a session
218
+ * caller with no key. When absent, retain the daemon's known revision.
219
+ */
220
+ key_policy_rev: S.optional(S.NullOr(S.String)),
221
+ });
222
+ /**
223
+ * Wire contracts for the local daemon ⇄ cloud control plane and for the
224
+ * daemon's own localhost control surface.
225
+ *
226
+ * Compliance note: the only daemon→cloud payloads are config pulls and
227
+ * the metadata-only request row below. No subscription token and no
228
+ * prompt/completion content ever crosses this boundary.
229
+ */
230
+ // ─── POST /api/daemon/requests (daemon → cloud) ──────────────────────
231
+ //
232
+ // One `public.requests` row for a subscription hop the daemon ran
233
+ // locally. `user_id` / `key_id` are deliberately ABSENT: the cloud
234
+ // derives both from the authenticating `sk-llm-...` key, so a daemon can
235
+ // only ever record rows for its own owner.
236
+ //
237
+ // No `cost_usd` either — the daemon reports only TOKEN COUNTS; the cloud
238
+ // is the single pricing source of truth and computes cost from these
239
+ // tokens in `daemonRecordHandler` (`costFor`). Keeping cost off the wire
240
+ // is why no pricing table is duplicated onto the daemon.
241
+ const HOLD_NONCE_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}(?![\s\S])/i;
242
+ const HoldNonce = S.String.check(S.isPattern(HOLD_NONCE_PATTERN));
243
+ export const DaemonRecordRequest = S.Struct({
244
+ model: S.String,
245
+ provider: S.String,
246
+ status: RequestStatus,
247
+ /** Canonical prompt tokens — INCLUDES the two cache fields below. */
248
+ tokens_in: S.Number,
249
+ tokens_out: S.Number,
250
+ // The cache split of `tokens_in`. Optional so a daemon built before this
251
+ // field existed still records (its rows just price as all-fresh input, the
252
+ // prior behaviour). Still no `cost_usd`: the cloud prices these tokens.
253
+ cached_tokens: S.optional(S.Number),
254
+ cache_creation_tokens: S.optional(S.Number),
255
+ latency_ms: S.Number,
256
+ idempotency_key: S.optional(S.NullOr(S.String)),
257
+ error: S.optional(S.NullOr(S.String)),
258
+ endpoint: S.optional(S.NullOr(S.String)),
259
+ /** Obscured vendor-account identity of the credential that SERVED this
260
+ * hop — the same `sha256("openllm-account-v1:<provider>:<id>")` digest
261
+ * the status frame reports, computed from the token that ran the
262
+ * request. Lets the usage-calibration estimator attribute this row's
263
+ * cost to the right meter series when a provider has several accounts.
264
+ * Optional so daemons predating the field still record (the cloud
265
+ * stores null → the estimator's conservative null pool). */
266
+ account_hash: S.optional(S.String),
267
+ /**
268
+ * Origin-signed team grant echoed on team hops so the cloud attributes
269
+ * the row to the consumer and settles `team_usage_counters`. Same-user
270
+ * records omit it. Bounded like the mux forward header.
271
+ */
272
+ team_grant: S.optional(S.String.check(S.isMaxLength(TEAM_GRANT_B64_MAX))),
273
+ /**
274
+ * Cap hold this request ran under. Only the hold's TERMINAL record carries
275
+ * it; that record settles the hold at `tokens_in + tokens_out` (may be 0).
276
+ * Accepted only from the device key the hold is bound to.
277
+ */
278
+ hold_nonce: S.optional(HoldNonce),
279
+ /**
280
+ * With `hold_nonce`: tokens reported by this request's earlier attempts
281
+ * (retries, sibling accounts, fallbacks), added to this record's tokens.
282
+ */
283
+ hold_prior_tokens: S.optional(S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0))),
284
+ /**
285
+ * With `hold_nonce`: sends of this request with no usage evidence. The
286
+ * cloud charges each one the hold's full reservation.
287
+ */
288
+ hold_unknown_attempts: S.optional(S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0))),
289
+ cooldown_reason: S.optional(CooldownReason),
290
+ /** Reset instant for reset-aware TTL cap; optional so old daemons omit. */
291
+ reset_at_ms: S.optional(S.Number),
292
+ }).check(
293
+ // A successful hop never cools — a `cooldown_reason` on a `success` record
294
+ // is malformed, so reject it at the schema boundary rather than let the
295
+ // handler mark a cooldown for a model that just served cleanly.
296
+ S.makeFilter((record) => record.status !== "success" || record.cooldown_reason === undefined, { message: "cooldown_reason is only valid on a non-success record" }));
297
+ // ─── POST /api/daemon/models (daemon → cloud) ────────────────────────
298
+ //
299
+ // The daemon writer for `public.model_cache` (live-provider-model-catalog
300
+ // proposal §4): the live model lists the daemon's CONNECTED delegates
301
+ // report from their vendors' own list endpoints. Metadata only — model
302
+ // ids + optional display/context data, never a credential. `user_id` is
303
+ // deliberately ABSENT (derived from the authenticating `sk-llm-...` key,
304
+ // same posture as `DaemonRecordRequest`), and the handler restricts
305
+ // `provider` to the subscription set so a daemon can never overwrite the
306
+ // cloud-owned API-key rows.
307
+ export const DaemonModelReportEntry = S.Struct({
308
+ provider: S.String.check(S.isMaxLength(64)),
309
+ // Same per-list bound as `ProviderModelList` (defense-in-depth on
310
+ // this authenticated write path).
311
+ models: ProviderModelList,
312
+ /** Vendor CLI version (bare semver) that OBSERVED this list. Some
313
+ * vendors gate model visibility by client version (Codex does), so
314
+ * the cloud uses this to refuse a write that would replace a fresh
315
+ * row produced by a NEWER CLI on another device. Optional so daemons
316
+ * built before the field still report (their writes stay permissive). */
317
+ cli_version: S.optional(S.String.check(S.isMaxLength(64))),
318
+ });
319
+ export const DaemonModelReport = S.Struct({
320
+ // One entry per subscription (oauth) provider — the closed set is small;
321
+ // 32 leaves headroom without allowing a bloated report.
322
+ entries: S.Array(DaemonModelReportEntry).check(S.isMaxLength(32)),
323
+ /**
324
+ * Device-discovered local model-server lists, keyed by `local_*` /
325
+ * `local_port_*` provider. Separate from `entries` so an oauth-only
326
+ * maxItems(32) bound cannot crowd out local rows (and vice versa).
327
+ * Absent on older daemons.
328
+ */
329
+ local_entries: S.optional(S.Array(DaemonModelReportEntry).check(S.isMaxLength(64))),
330
+ });
331
+ /** Probe outcome for one local model server on the daemon's machine. */
332
+ export const LocalServerStatus = S.Literals(["ok", "needs_key", "unreachable"]);
333
+ /**
334
+ * Live local-server discovery state pushed on `DaemonStatus` (no keys —
335
+ * only `has_key`). Also the result shape of a `local_rescan` command.
336
+ */
337
+ export const LocalServerState = S.Struct({
338
+ /** Preset slug (`local_ollama`, …) or `local_port_<port>` fallback. */
339
+ slug: S.String.check(S.isMinLength(1), S.isMaxLength(64)),
340
+ port: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(1), S.isLessThanOrEqualTo(65535)),
341
+ base_url: S.String.check(S.isMinLength(1), S.isMaxLength(512)),
342
+ status: LocalServerStatus,
343
+ has_key: S.Boolean,
344
+ models: ProviderModelList,
345
+ });
346
+ export { SubscriptionProviderSlug } from "./subscription-provider.js";
347
+ // ─── POST /api/daemon/session-lost (daemon → cloud) ──────────────────
348
+ //
349
+ // An authenticated daemon reports a confirmed subscription session loss. The
350
+ // cloud derives the user and source key from the bearer token; neither belongs
351
+ // in this body.
352
+ export const DaemonSessionLost = S.Struct({
353
+ slug: SubscriptionProviderSlug,
354
+ account_hash: S.optional(S.String),
355
+ /** Bounded, non-secret classifier of `conn.detail` — never the raw string. */
356
+ diagnostic_code: S.optional(AuthSessionLostDiagnosticCode),
357
+ });
358
+ export const DaemonQuotaStatusReached = S.Struct({
359
+ slug: SubscriptionProviderSlug,
360
+ status: S.Literals(["allowed_warning", "rejected"]),
361
+ account_hash: S.optional(S.String),
362
+ plan: S.optional(S.String),
363
+ /**
364
+ * Sustaining quota-window reset epoch (unix ms). Optional so older daemons
365
+ * omit it; cloud then falls back to account:status + 24h cooldown.
366
+ */
367
+ reset_at_ms: S.optional(S.Number),
368
+ /**
369
+ * The quota snapshot that produced this transition — display-only, it lets
370
+ * the email list every limit with its usage and reset. Optional so older
371
+ * daemons omit it. The cloud decodes it apart from the fields above and
372
+ * falls back to the plain notice when it is missing, undecodable, not a
373
+ * quota snapshot, or disagrees with `status`.
374
+ */
375
+ usage: S.optional(ProviderUsageSnapshot),
376
+ });
377
+ /** Optional user-visible device-session label (open frames + presence). */
378
+ export const SessionTitleField = S.String.check(S.isMaxLength(80));
379
+ /**
380
+ * CLIs the device PTY surface can host: OpenLLM session clients with local
381
+ * history + resume wiring (Claude / Codex / Grok / OpenCode / Hermes), plus a
382
+ * direct login shell. Keep `SubscriptionProviderSlug` for credentials/usage;
383
+ * session frames use this set, while the local-session list uses its narrower
384
+ * canonical set. Kimi and Cursor stay subscription-only for now.
385
+ */
386
+ export const DeviceSessionCli = S.Literals([
387
+ "claude_code",
388
+ "chatgpt",
389
+ "grok",
390
+ "opencode",
391
+ "hermes",
392
+ "shell",
393
+ ]);
394
+ /**
395
+ * CLIs for which `openllm -d <client>` (skip approvals) is meaningful.
396
+ * Canonical set — the picker, session-host, and any consumer import THIS
397
+ * rather than re-declaring their own membership list.
398
+ */
399
+ export const DANGEROUS_SESSION_CLIS = new Set([
400
+ "claude_code",
401
+ "chatgpt",
402
+ "grok",
403
+ "hermes",
404
+ ]);
405
+ /** CLIs with a local history reader on the daemon (v1). Canonical set. */
406
+ export const LISTABLE_SESSION_CLIS = new Set([
407
+ "claude_code",
408
+ "chatgpt",
409
+ "grok",
410
+ "opencode",
411
+ "hermes",
412
+ ]);
413
+ export const supportsDangerousSession = (cli) => DANGEROUS_SESSION_CLIS.has(cli);
414
+ export const isListableSessionCli = (cli) => LISTABLE_SESSION_CLIS.has(cli);
415
+ /**
416
+ * One row from the daemon's local session index (vendor history +
417
+ * `~/.openllm/run/<client>/<pid>/live.json` + in-memory device PTYs).
418
+ * Used by `list_local_sessions` so the picker can attach / cold-resume
419
+ * without scanning disk in the browser.
420
+ */
421
+ export const LocalCliSession = S.Struct({
422
+ /** Vendor session id when known; otherwise a synthetic live-run key. */
423
+ id: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
424
+ title: SessionTitleField,
425
+ cwd: S.NullOr(S.String.check(S.isMaxLength(1024))),
426
+ updated_at_ms: S.Number,
427
+ cli: DeviceSessionCli,
428
+ live: S.Boolean,
429
+ /** Where the live process is hosted, when `live`. */
430
+ host: S.optional(S.NullOr(S.Literals(["local", "device"]))),
431
+ /** OpenLLM device session id when the PTY is already hosted by the daemon. */
432
+ openllm_session_id: S.optional(S.NullOr(S.String.check(S.isMaxLength(64)))),
433
+ /** True when the browser can `mode:"attach"` without spawning a second CLI. */
434
+ attachable: S.Boolean,
435
+ });
436
+ /** Payload for `list_local_sessions`. */
437
+ export const ListLocalSessionsPayload = S.Struct({
438
+ cli: DeviceSessionCli,
439
+ /** Max rows (default 30 server-side; hard cap 100). */
440
+ limit: S.optional(S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(1), S.isLessThanOrEqualTo(100))),
441
+ });
442
+ /** Result blob for `list_local_sessions` (command ack / lifecycle.result). */
443
+ export const ListLocalSessionsResult = S.Struct({
444
+ sessions: S.Array(LocalCliSession),
445
+ });
446
+ /**
447
+ * Result blob for `refresh_models_due` (command ack / lifecycle.result).
448
+ * Always rides a `done` lifecycle — automatic discovery never surfaces as
449
+ * a user-facing command error. `attempted: false` + `reported: 0` is a
450
+ * quiet TTL/credential skip; `reported: 0` + `failed: true` is a total
451
+ * failure. The dashboard refetches `/v1/models` on `reported > 0`
452
+ * (including partial writes) and also on quiet skips (`failed === false`)
453
+ * so a cached query can pick up a catalog another trigger already POSTed.
454
+ */
455
+ export const RefreshModelsDueResult = S.Struct({
456
+ attempted: S.Boolean,
457
+ reported: S.Number,
458
+ failed: S.Boolean,
459
+ error: S.optional(S.String),
460
+ });
461
+ /** Terminal exit reason retained for a dead but resumable device session. */
462
+ export const SessionExitReason = S.Literals([
463
+ "evicted",
464
+ "reaped",
465
+ "done",
466
+ "killed",
467
+ ]);
468
+ // Opaque base64 blob (an X25519 sealed box / SPKI public key) — decrypted or
469
+ // parsed by the recipient, never executed. Padding restricted to at most two
470
+ // '=' characters only at the end (valid base64 format).
471
+ const Base64Blob = S.String.check(S.isPattern(/^[A-Za-z0-9+/]+={0,2}$/));
472
+ /** The closed set of install-time gateway modes: which base URL a client
473
+ * setup bakes — the local daemon (`local`, the default) or the cloud
474
+ * origin. ONE schema for every wire field and TS union that carries it. */
475
+ export const GatewayMode = S.Literals(["local", "cloud"]);
476
+ /** Device-local account slot of a subscription provider (multi-account,
477
+ * `docs/plan/multi-account-subscriptions.md`). Absent ⇒ 0, today's single
478
+ * account. Old daemons strip the field on decode and act on account 0, so
479
+ * senders must only set it when the daemon advertises
480
+ * `features.multi_account`. */
481
+ export const AccountIndex = S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(0), S.isLessThanOrEqualTo(1023));
482
+ const ProviderPayload = S.Struct({
483
+ slug: SubscriptionProviderSlug,
484
+ account_index: S.optional(AccountIndex),
485
+ });
486
+ /** Add an account slot; the daemon allocates the index and returns it. */
487
+ const AddAccountPayload = S.Struct({
488
+ slug: SubscriptionProviderSlug,
489
+ label: S.optional(S.String.check(S.isMaxLength(64))),
490
+ });
491
+ /** Remove an account slot (n >= 1; account 0 is only logged out). */
492
+ const RemoveAccountPayload = S.Struct({
493
+ slug: SubscriptionProviderSlug,
494
+ account_index: AccountIndex.check(S.isGreaterThanOrEqualTo(1)),
495
+ });
496
+ /** Pin an account first in routing, or clear the pin with `null`. */
497
+ const PinAccountPayload = S.Struct({
498
+ slug: SubscriptionProviderSlug,
499
+ account_index: S.NullOr(AccountIndex),
500
+ });
501
+ /** Cancel an in-flight connect. `flow_id` is optional so old senders keep
502
+ * working; when present the daemon binds the signal to that owner and
503
+ * rejects mismatches. Extra field is additive — old decoders ignore it. */
504
+ const CancelConnectPayload = S.Struct({
505
+ slug: SubscriptionProviderSlug,
506
+ account_index: S.optional(AccountIndex),
507
+ flow_id: S.optional(S.String),
508
+ });
509
+ /** A remote-Claude headless-login code submission: the X25519-sealed OAuth
510
+ * authorization code the user pasted from the hosted callback page. Opened on
511
+ * the target daemon and written to the waiting `claude auth login` stdin. The
512
+ * code is single-use + PKCE-bound (useless without the daemon's in-process
513
+ * verifier); sealed so the cloud relays it blind. See
514
+ * `docs/proposals/headless-claude-login-paste-back.md`. */
515
+ const SubmitLoginCodePayload = S.Struct({
516
+ slug: SubscriptionProviderSlug,
517
+ account_index: S.optional(AccountIndex),
518
+ sealed: Base64Blob,
519
+ });
520
+ /** Set or clear a per-port API key for a local model server. `sealed` is an
521
+ * X25519 sealed box to the daemon's pubkey (same posture as
522
+ * `submit_login_code`); an empty sealed blob clears the stored key. */
523
+ const SetLocalKeyPayload = S.Struct({
524
+ port: S.Number.check(S.isInt(), S.isGreaterThanOrEqualTo(1), S.isLessThanOrEqualTo(65535)),
525
+ sealed: S.Union([Base64Blob, S.Literal("")]),
526
+ });
527
+ /** Add, replace or remove one `local_key` provider key slot. `sealed` is an
528
+ * X25519 sealed box of the API key to the daemon's pubkey; the relay and
529
+ * cloud never see plaintext. `account_index` absent ⇒ allocate a new slot
530
+ * (lowest free index). Present + empty `sealed` ⇒ remove that slot. Present
531
+ * + non-empty ⇒ replace that slot's key. */
532
+ const SetProviderKeyPayload = S.Struct({
533
+ slug: LocalKeyProviderSlug,
534
+ account_index: S.optional(AccountIndex),
535
+ sealed: S.Union([Base64Blob, S.Literal("")]),
536
+ label: S.optional(S.String.check(S.isMaxLength(64))),
537
+ });
538
+ /** Team ids name the daemon's `team-keys/<id>.json`, so the wire admits only
539
+ * a path-safe id (the cloud mints UUIDs). */
540
+ export const TEAM_KEY_ID_PATTERN = /^[A-Za-z0-9_-]{1,64}$/;
541
+ const TeamKeyId = S.String.check(S.isPattern(TEAM_KEY_ID_PATTERN));
542
+ const SetTeamKeyPayload = S.Struct({
543
+ team_id: TeamKeyId,
544
+ epoch: S.Int.check(S.isGreaterThanOrEqualTo(0)),
545
+ sealed: Base64Blob,
546
+ });
547
+ const DeleteTeamKeyPayload = S.Struct({ team_id: TeamKeyId });
548
+ const SetAutoUpdatePayload = S.Struct({ enabled: S.Boolean });
549
+ /** Disable device sessions remotely: `statement` is the base64 envelope of
550
+ * `{ v: 1, key_id, ts, nonce, sig }` signed by the account control key
551
+ * (`@openllmsh/sdk/vault` `signDeviceSessionsDisable`). Disable-only — there is no
552
+ * remote enable. The daemon verifies against its ANCHORED pin and blanks
553
+ * `OPENLLM_DEVICE_ANCHOR`; the cloud only relays and cannot forge one. */
554
+ const SetDeviceSessionsPayload = S.Struct({
555
+ statement: S.String.check(S.isMinLength(1), S.isMaxLength(1024), S.isPattern(/^[A-Za-z0-9+/]+={0,2}$/)),
556
+ });
557
+ /** `refresh` re-reads usage for connected providers. Optional `slug` scopes
558
+ * that read to one provider; omitted `slug` means every connected provider
559
+ * (bare `{}` is that whole-daemon read — it does not clear the usage cache).
560
+ * `manual` is the explicit Refresh-usage button only: it may native-refresh
561
+ * an expired stored token. Cache TTL bypass is daemon-internal
562
+ * (`cachedUsage` `force`), never this wire flag. Absent/false is the
563
+ * auto/mount path (stored credential, TTL-respecting). */
564
+ const RefreshPayload = S.Struct({
565
+ slug: S.optional(SubscriptionProviderSlug),
566
+ account_index: S.optional(AccountIndex),
567
+ manual: S.optional(S.Boolean),
568
+ });
569
+ /** One `openllm auth …` request run on the device by the same handler the CLI
570
+ * and MCP reach over loopback (`/local/auth`), so every surface shares one
571
+ * contract and one reply. The paste-back code never travels in clear:
572
+ * `sealed_code` is an X25519 sealed box to the daemon's pubkey. The daemon
573
+ * re-validates the opened request with `parseLocalAuthRequest`. */
574
+ const AuthPayload = S.Struct({
575
+ operation: S.Literals(AUTH_OPERATIONS),
576
+ provider: S.optional(S.String.check(S.isPattern(/^[a-z][a-z0-9_]{0,63}$/))),
577
+ method: S.optional(S.Literals(["browser", "device"])),
578
+ flow_id: S.optional(S.String.check(S.isPattern(/^[a-zA-Z0-9_-]{1,128}$/))),
579
+ account: S.optional(AccountIndex),
580
+ label: S.optional(S.String.check(S.isMinLength(1), S.isMaxLength(64))),
581
+ since: S.optional(S.String.check(S.isPattern(/^[a-f0-9]{1,64}$/))),
582
+ wait_ms: S.optional(S.Int.check(S.isGreaterThanOrEqualTo(0), S.isLessThanOrEqualTo(AUTH_RELAY_WAIT_MAX_MS))),
583
+ sealed_code: S.optional(Base64Blob),
584
+ });
585
+ /** Decoding strips unknown keys, so enqueue boundaries also refuse any raw
586
+ * key outside this set — a plaintext `code` never transits the relay. */
587
+ export const AUTH_PAYLOAD_KEYS = new Set(Object.keys(AuthPayload.fields));
588
+ export const authPayloadKeysAllowed = (payload) => payload !== null &&
589
+ typeof payload === "object" &&
590
+ !Array.isArray(payload) &&
591
+ Object.keys(payload).every((key) => AUTH_PAYLOAD_KEYS.has(key));
592
+ /** Payload-less commands (`status` / `update`): accept an absent payload or a
593
+ * bare `{}` so every union member carries the field (uniform access). */
594
+ const EmptyPayload = S.Struct({});
595
+ /**
596
+ * The CLOSED control-command vocabulary — one struct per kind, literal-
597
+ * discriminated, every payload field a constrained scalar (a provider-slug
598
+ * enum, a charset-pinned artifact slug, a boolean, an opaque base64 blob).
599
+ * NO field may carry a command string, script body, args array, URL, or
600
+ * free filesystem path — adding one is a deliberate, reviewable schema
601
+ * change, not something `S.Unknown` admits. A command outside this set
602
+ * fails decode at the parse boundary on BOTH ends (cloud/relay enqueue +
603
+ * the daemon's relay socket) before any handler runs. See
604
+ * `docs/proposals/daemon-os-sandbox-and-typed-control.md` §2.
605
+ *
606
+ * Built once and addressed three ways so the vocabularies can never drift:
607
+ * bare (enqueue validation), `id` (relay delivery wire), `key_id`
608
+ * (dashboard enqueue wire).
609
+ */
610
+ const commandVariants = (addressing) => [
611
+ S.Struct({
612
+ ...addressing,
613
+ kind: S.Literals(["auth"]),
614
+ payload: AuthPayload,
615
+ }),
616
+ S.Struct({
617
+ ...addressing,
618
+ kind: S.Literals(["connect"]),
619
+ payload: ProviderPayload,
620
+ }),
621
+ S.Struct({
622
+ ...addressing,
623
+ kind: S.Literals(["connect_device_code"]),
624
+ payload: ProviderPayload,
625
+ }),
626
+ S.Struct({
627
+ ...addressing,
628
+ kind: S.Literals(["cancel_connect"]),
629
+ payload: CancelConnectPayload,
630
+ }),
631
+ S.Struct({
632
+ ...addressing,
633
+ kind: S.Literals(["logout"]),
634
+ payload: ProviderPayload,
635
+ }),
636
+ S.Struct({
637
+ ...addressing,
638
+ kind: S.Literals(["submit_login_code"]),
639
+ payload: SubmitLoginCodePayload,
640
+ }),
641
+ S.Struct({
642
+ ...addressing,
643
+ kind: S.Literals(["add_account"]),
644
+ payload: AddAccountPayload,
645
+ }),
646
+ S.Struct({
647
+ ...addressing,
648
+ kind: S.Literals(["remove_account"]),
649
+ payload: RemoveAccountPayload,
650
+ }),
651
+ S.Struct({
652
+ ...addressing,
653
+ kind: S.Literals(["pin_account"]),
654
+ payload: PinAccountPayload,
655
+ }),
656
+ S.Struct({
657
+ ...addressing,
658
+ kind: S.Literals(["set_auto_update"]),
659
+ payload: SetAutoUpdatePayload,
660
+ }),
661
+ S.Struct({
662
+ ...addressing,
663
+ kind: S.Literals(["refresh"]),
664
+ payload: S.optional(RefreshPayload),
665
+ }),
666
+ S.Struct({
667
+ ...addressing,
668
+ kind: S.Literals(["status"]),
669
+ payload: S.optional(EmptyPayload),
670
+ }),
671
+ S.Struct({
672
+ ...addressing,
673
+ kind: S.Literals(["update"]),
674
+ payload: S.optional(EmptyPayload),
675
+ }),
676
+ // Drop every cached signed plan tuple NOW. The dashboard enqueues this
677
+ // after a successful chain/config save so the very next request bounces
678
+ // through the cloud and picks up the new chain instead of replaying the
679
+ // old one for up to the cache TTL (the "app feels unresponsive to chain
680
+ // reorders" friction). Payload-less and idempotent.
681
+ S.Struct({
682
+ ...addressing,
683
+ kind: S.Literals(["bust_plan_cache"]),
684
+ payload: S.optional(EmptyPayload),
685
+ }),
686
+ // Force a live model-list re-report NOW. The daemon's model-report
687
+ // throttle mirrors the cloud's 30m `MODEL_CACHE_TTL_MS` — without this
688
+ // command the only way to re-discover models mid-TTL is `openllmd
689
+ // restart`. The dashboard's "Available models" refresh button enqueues
690
+ // this; the executor clears the throttle, re-fetches every connected
691
+ // delegate's list, and POSTs to `/api/daemon/models` BEFORE acking so
692
+ // the subsequent `/v1/models` refetch the dashboard does after the
693
+ // lifecycle frame lands sees the fresh rows. Payload-less and
694
+ // idempotent.
695
+ S.Struct({
696
+ ...addressing,
697
+ kind: S.Literals(["refresh_models"]),
698
+ payload: S.optional(EmptyPayload),
699
+ }),
700
+ // Automatic, non-force model discovery. Distinct kind — never an
701
+ // optional flag on `refresh_models`, because an older daemon would
702
+ // strip unknown fields and run a throttle-resetting, auth-capable
703
+ // list. Empty payload. Quiet `done` even when every provider skips
704
+ // or fails; the dashboard only sends this when `control_caps`
705
+ // advertises the kind.
706
+ S.Struct({
707
+ ...addressing,
708
+ kind: S.Literals(["refresh_models_due"]),
709
+ payload: S.optional(EmptyPayload),
710
+ }),
711
+ // List vendor-local sessions on this machine for one device CLI
712
+ // (history stores + ~/.openllm/run live.json + in-memory PTYs). Result
713
+ // rides on the command ack / lifecycle.result for the picker.
714
+ S.Struct({
715
+ ...addressing,
716
+ kind: S.Literals(["list_local_sessions"]),
717
+ payload: ListLocalSessionsPayload,
718
+ }),
719
+ // Re-probe well-known (and user-added) local model-server ports NOW.
720
+ // Result is the current `TLocalServerState[]` on the command ack.
721
+ // Payload-less and idempotent; older daemons ignore the unknown kind.
722
+ S.Struct({
723
+ ...addressing,
724
+ kind: S.Literals(["local_rescan"]),
725
+ payload: S.optional(EmptyPayload),
726
+ }),
727
+ // Set or clear the API key for one local model-server port. The key is
728
+ // sealed to the daemon's X25519 pubkey in the browser; the relay never
729
+ // sees plaintext. Empty `sealed` clears. Older daemons ignore the kind.
730
+ S.Struct({
731
+ ...addressing,
732
+ kind: S.Literals(["set_local_key"]),
733
+ payload: SetLocalKeyPayload,
734
+ }),
735
+ // Add / replace / remove a `local_key` provider key slot (OpenCode Go,
736
+ // Z.AI, MiniMax). Sent only when `control_caps` advertises
737
+ // LOCAL_KEY_PROVIDERS_CONTROL_CAP; older daemons ignore the kind.
738
+ S.Struct({
739
+ ...addressing,
740
+ kind: S.Literals(["set_provider_key"]),
741
+ payload: SetProviderKeyPayload,
742
+ }),
743
+ S.Struct({
744
+ ...addressing,
745
+ kind: S.Literals(["set_team_key"]),
746
+ payload: SetTeamKeyPayload,
747
+ }),
748
+ S.Struct({
749
+ ...addressing,
750
+ kind: S.Literals(["delete_team_key"]),
751
+ payload: DeleteTeamKeyPayload,
752
+ }),
753
+ // Control-key-signed device-sessions DISABLE. Older daemons ignore the
754
+ // kind; the dashboard sends it only when `control_caps` advertises it.
755
+ // There is no remote enable — re-enable is install/update/login/desktop
756
+ // with the sessions toggle on (writes the anchor again).
757
+ S.Struct({
758
+ ...addressing,
759
+ kind: S.Literals(["set_device_sessions"]),
760
+ payload: SetDeviceSessionsPayload,
761
+ }),
762
+ ];
763
+ /** The bare `{ kind, payload }` vocabulary — what an enqueue boundary (the
764
+ * relay's watcher `enqueue` frame, `enqueueCommand` in `packages/api`)
765
+ * validates before writing a `daemon_commands` row. */
766
+ export const DaemonCommandBody = S.Union([...commandVariants({})]);
767
+ /** Runtime literal of the closed command vocabulary — the discriminant only,
768
+ * no payload. Used by `control-channel.ts`'s `CommandLifecycle` to echo which
769
+ * command a lifecycle frame is reporting on. The `_kindDriftGuard` below makes
770
+ * this fail to compile if it ever drifts from the `commandVariants` union, so
771
+ * the two stay in lockstep without duplicating the payload mapping. */
772
+ export const DaemonCommandKind = S.Literals([
773
+ "auth",
774
+ "connect",
775
+ "connect_device_code",
776
+ "cancel_connect",
777
+ "logout",
778
+ "submit_login_code",
779
+ "add_account",
780
+ "remove_account",
781
+ "pin_account",
782
+ "set_auto_update",
783
+ "refresh",
784
+ "status",
785
+ "update",
786
+ "bust_plan_cache",
787
+ "refresh_models",
788
+ "refresh_models_due",
789
+ "list_local_sessions",
790
+ "local_rescan",
791
+ "set_local_key",
792
+ "set_provider_key",
793
+ "set_team_key",
794
+ "delete_team_key",
795
+ "set_device_sessions",
796
+ ]);
797
+ const _kindDriftGuard = true;
798
+ void _kindDriftGuard;
799
+ /** One control command delivered to the daemon over its relay socket.
800
+ * `id` is `daemon_commands.id` (bigserial), stringified for the wire. */
801
+ export const DaemonCommand = S.Union([
802
+ ...commandVariants({
803
+ id: S.String,
804
+ replay_session_id: S.optional(ReplaySessionId),
805
+ }),
806
+ ]);
807
+ /** POST /api/daemon/cmd (dashboard → cloud) — enqueue for a target key
808
+ * (`key_id` must belong to the session user). */
809
+ export const DaemonCmdRequest = S.Union([
810
+ ...commandVariants({ key_id: S.String }),
811
+ ]);
812
+ /** A command result the daemon reports back over its relay socket (the
813
+ * `ack`/`status` frames in `relay.ts` carry these). */
814
+ export const DaemonCommandAck = S.Struct({
815
+ id: S.String,
816
+ /** `ack` confirms that the daemon dequeued the command. Terminal outcomes
817
+ * retain the previous ack shape for older relay binaries. */
818
+ status: S.Literals(["ack", "done", "not_done", "error"]),
819
+ result: S.optional(S.Unknown),
820
+ });
821
+ // ─── Daemon control surface (browser → daemon, on localhost) ─────────
822
+ /** Per-provider auth-status on the daemon wire.
823
+ * `connected` = signed in; `disconnected` = unexpected loss; `signed_out` =
824
+ * user-initiated logout (sticky until the next successful login). */
825
+ export const DaemonProviderAuthStatus = S.Literals([
826
+ "connected",
827
+ "disconnected",
828
+ "signed_out",
829
+ ]);
830
+ /** Latest model-list outcome for a connected oauth provider (UI live signal). */
831
+ export const DaemonModelsStatus = S.Literals(["ok", "unavailable"]);
832
+ /**
833
+ * Closed reasons for `models_status: "unavailable"`. Matches the daemon's
834
+ * listModels null tokens; unknown `http_*` collapses to `http_error` on the
835
+ * wire. Never paths, bodies, or headers.
836
+ */
837
+ export const DaemonModelsReason = S.Literals([
838
+ "token_unavailable",
839
+ "version_unresolved",
840
+ "empty_after_filter",
841
+ "error",
842
+ "http_401",
843
+ "http_403",
844
+ "http_404",
845
+ "http_429",
846
+ "http_500",
847
+ "http_502",
848
+ "http_503",
849
+ "http_error",
850
+ ]);
851
+ export const DaemonProviderConnection = S.Struct({
852
+ provider: S.String,
853
+ /**
854
+ * Auth-status literal — the single source of truth.
855
+ * `connected` = signed in; `disconnected` = unexpected loss;
856
+ * `signed_out` = user-initiated logout (sticky until the next login).
857
+ */
858
+ status: DaemonProviderAuthStatus,
859
+ /**
860
+ * Typed observation. Optional so old daemons and persisted blobs remain
861
+ * valid. When present it wins over legacy `status` / `detail` classifiers.
862
+ * `unknown` is never logout and never proven serviceability.
863
+ */
864
+ observation: S.optional(DaemonProviderObservation),
865
+ /** Machine-readable cause for a non-connected observation. Display copy stays on `detail`. */
866
+ reason_code: S.optional(DaemonProviderReasonCode),
867
+ /** The vendor CLI the daemon runs is installed on the machine. The daemon
868
+ * never installs it — installs are user-run (the daemon install script or by
869
+ * hand); the daemon lazily auto-links its isolated run-view
870
+ * (~/.openllm/cli/<provider>/) to the host binary. When false the dashboard
871
+ * prompts the user to (re-)run the daemon installer. Absent means a status
872
+ * probe failed before it could determine installation state; consumers must
873
+ * not treat absence as not installed. */
874
+ cli_installed: S.optional(S.Boolean),
875
+ /** Progress of an OpenLLM-started background vendor installer. Independent
876
+ * of authentication and CLI presence; absent on older daemons or externally
877
+ * managed installations. Contains no logs, process identity or host paths. */
878
+ cli_install: S.optional(VendorCliInstall),
879
+ /** Version of the isolated CLI, when installed + readable. */
880
+ cli_version: S.optional(S.String),
881
+ /** The user appears signed in to this vendor's CLI in their OWN home on the
882
+ * daemon's machine (e.g. `~/.codex/auth.json` holds a ChatGPT login). A
883
+ * read-only, secret-free presence hint so onboarding can put that provider
884
+ * first with a one-tap Connect. It is never a connection: the daemon does
885
+ * not copy, import or use that credential, and Connect still runs the
886
+ * vendor login inside the daemon's isolated home. Absent = unknown (an
887
+ * older daemon, a provider whose host store sits in an OS keychain the
888
+ * daemon will not touch, or an unreadable store); consumers must not read
889
+ * absence as signed out. */
890
+ host_signed_in: S.optional(S.Boolean),
891
+ detail: S.optional(S.String),
892
+ last_login_at_ms: S.optional(S.NullOr(S.Number)),
893
+ /** A LIVE device-code flow awaiting the user (codex/kimi on a remote box):
894
+ * the verification URL + one-time code to surface so the dashboard can
895
+ * render a synced "open this link, enter this code" panel. Present only
896
+ * while a flow is pending; cleared the moment the credential lands. The
897
+ * card flips to Connected automatically on the next status push.
898
+ *
899
+ * The actionable `url`/`code` are OPTIONAL because the relay REDACTS them
900
+ * from the broadcast + persisted status for every dashboard EXCEPT the one
901
+ * that started the login (issue #3 — otherwise the OAuth secret fans out to
902
+ * every same-user browser). A redacted / marker snapshot is the non-secret
903
+ * owner shape `{ pending: true, flow_id?, started_at_ms?, cancel_requested?,
904
+ * mode? }` with no url/code — not a new `mode` value. The initiating
905
+ * dashboard receives `{ url, code, mode? }` on `auth.login.prompt` only.
906
+ * UIs must treat a missing/empty `url` as non-actionable (never auto-open).
907
+ * A cached HTTP/DB marker is unconfirmed until a current-session ordered
908
+ * live `status_push` is applied; TTL does not evict that live owner. */
909
+ pending_auth: S.optional(S.NullOr(S.Struct({
910
+ url: S.optional(S.String),
911
+ code: S.optional(S.String),
912
+ /** True on a REDACTED snapshot (non-origin watcher / persisted row):
913
+ * a login is in progress but the actionable url/code were stripped. */
914
+ pending: S.optional(S.Boolean),
915
+ /** `device_code` (codex/kimi: surface URL + one-time code to enter in
916
+ * the browser, then poll) or `paste_code` (claude headless login:
917
+ * surface URL, then a paste-back input for the code the hosted
918
+ * callback page displays). Absent ⇒ `device_code`. */
919
+ mode: S.optional(S.Literals(["device_code", "paste_code"])),
920
+ /** Relay command id of the login that produced this snapshot (same
921
+ * value as `auth.login.*` `flow_id`). The browser `req_id` lives on
922
+ * `command_lifecycle`, not here. Absent on daemons predating auth
923
+ * events. */
924
+ flow_id: S.optional(S.String),
925
+ /** Epoch ms when this pending flow was created. Carried on both the
926
+ * actionable and the REDACTED snapshot so every consumer can expire a
927
+ * STALE entry (older than {@link PENDING_AUTH_TTL_MS}) without needing
928
+ * the daemon to re-push. The daemon persists its whole status snapshot
929
+ * to `api_key_activity.daemon_status_json`; an abandoned/never-completed
930
+ * login (or a daemon restart that drops the live child) would otherwise
931
+ * leave a dead `pending_auth` in that row forever, and the dashboard
932
+ * would re-surface + auto-open a sign-in flow that no longer exists on
933
+ * every cold load. Absent on daemons predating this field. */
934
+ started_at_ms: S.optional(S.Number),
935
+ /** Slot-derived: cancel was accepted but the owner is still
936
+ * contained. Additive; older decoders ignore it. Not a new mode. */
937
+ cancel_requested: S.optional(S.Boolean),
938
+ }))),
939
+ /** Metadata-only usage snapshot for a CONNECTED provider, read locally by
940
+ * the daemon and pushed with its status. Absent when not connected or the
941
+ * read failed. */
942
+ usage: S.optional(S.NullOr(ProviderUsageSnapshot)),
943
+ /**
944
+ * Live local hop cooldown with reason `auth` (any model of this provider).
945
+ * Visibility only — does not change `status` / `observation` / `reason_code`.
946
+ * Transient; not remembered as last-known.
947
+ */
948
+ upstream_auth_cooldown: S.optional(DaemonProviderUpstreamAuthCooldown),
949
+ /** Obscured vendor-account identity for a CONNECTED provider:
950
+ * sha256("openllm-account-v1:<provider>:<stable-account-id>") over the
951
+ * stable account id the vendor CLI stores locally (Anthropic's
952
+ * accountUuid, ChatGPT's account_id, Kimi's user_id, Grok's user_id).
953
+ * Lets the cloud key usage-meter series per ACCOUNT — two devices on the
954
+ * same account share the hash; a second account on the same provider gets
955
+ * its own — without ever shipping the raw vendor id off-box. Absent when
956
+ * not connected or unreadable, and on daemons predating it. See
957
+ * docs/proposals/inferred-subscription-usage-calibration.md §10. */
958
+ account_hash: S.optional(S.String),
959
+ /** Device-local account slot this row describes (multi-account). Several
960
+ * rows may share one `provider` with distinct indexes. Absent ⇒ 0. */
961
+ account_index: S.optional(AccountIndex),
962
+ /** User label for the account slot, when set. */
963
+ account_label: S.optional(S.String.check(S.isMaxLength(64))),
964
+ /** True on the slot the user pinned first in routing for this provider. */
965
+ account_pinned: S.optional(S.Boolean),
966
+ /** `local_key` slots only: the last four characters of the stored key, so
967
+ * the user can tell keys apart. Never more of the secret. */
968
+ key_hint: S.optional(S.String.check(S.isMaxLength(4))),
969
+ /**
970
+ * Latest live model-list / discover outcome for this provider (UI signal for
971
+ * "Connected, but this device hasn't reported models yet"). Optional +
972
+ * omitted when never attempted so older daemons and older clients stay
973
+ * compatible. Mirror of how {@link LocalServerState} carries models.
974
+ */
975
+ models_status: S.optional(DaemonModelsStatus),
976
+ /** Closed null-reason when `models_status` is `unavailable`. Omitted on `ok`. */
977
+ models_reason: S.optional(DaemonModelsReason),
978
+ });
979
+ /** `control_caps` entry: the daemon understands `account_index` on auth
980
+ * commands and the `add_account` / `remove_account` / `pin_account` kinds.
981
+ * Senders must not address account n >= 1 without it (old daemons strip the
982
+ * field and would act on account 0). */
983
+ export const MULTI_ACCOUNT_CONTROL_CAP = "multi_account";
984
+ /** Control cap: the daemon runs the unified `auth` command (kind `"auth"`).
985
+ * Older daemons drop an unknown kind silently; the browser must refuse with
986
+ * `daemon_outdated` when this cap is absent rather than waiting out a timeout. */
987
+ export const AUTH_CONTROL_CAP = "auth";
988
+ /** Control cap: the daemon stores `local_key` provider keys
989
+ * (`set_provider_key`) and reports each slot as a `connections` row. */
990
+ export const LOCAL_KEY_PROVIDERS_CONTROL_CAP = "local_key_providers_v1";
991
+ /** Control cap: the daemon executes the signed `set_device_sessions` disable. */
992
+ export const DEVICE_SESSIONS_CONTROL_CAP = "device_sessions_v1";
993
+ /** Control cap: the daemon holds team keys (`set_team_key` /
994
+ * `delete_team_key`) and reports them in `team_psk`. */
995
+ export const TEAM_KEY_CUSTODY_CONTROL_CAP = "team_key_custody_v1";
996
+ /** One team key this device holds — the epoch only, never the key. */
997
+ export const DaemonTeamKeyEpoch = S.Struct({
998
+ team_id: S.String,
999
+ epoch: S.Int.check(S.isGreaterThanOrEqualTo(0)),
1000
+ });
1001
+ /**
1002
+ * A `pending_auth` self-expires after this **on cached / unconfirmed
1003
+ * snapshots**. The login ceiling (`DEFAULT_LOGIN_TIMEOUT_MS`, 5 min) reaps
1004
+ * the live child and matching-flow finalization clears the marker; this TTL
1005
+ * is the BACKSTOP for abandoned HTTP/DB rows. A current-session live marker
1006
+ * beats its age — replacement Connect stays forbidden while ownership is
1007
+ * confirmed. Shared by the daemon (in-memory expiry) and the browser. */
1008
+ export const PENDING_AUTH_TTL_MS = 10 * 60_000;
1009
+ // Outcome of the daemon's last cloud bootstrap — drives the dashboard's
1010
+ // Providers UI: needs a key (`no_key`/`invalid_key`) → show the API-key
1011
+ // picker; `unreachable` → retry hint; `connecting` → first bootstrap still
1012
+ // in flight (key is configured, outcome unknown); `ok` → provider cards.
1013
+ export const DaemonCloudState = S.Literals([
1014
+ "ok",
1015
+ "no_key",
1016
+ "invalid_key",
1017
+ "unreachable",
1018
+ "connecting",
1019
+ ]);
1020
+ /**
1021
+ * The openllm CLI's presence on this box, as the daemon already knows it from
1022
+ * its device-state probe (`device-state.ts`) — no probe scripts, no per-client
1023
+ * walk. This is the ONLY install state the dashboard needs now: clients are
1024
+ * configured at RUN time by `openllm <client>`, so there is nothing per-client
1025
+ * to install, stamp, or diverge.
1026
+ */
1027
+ export const DaemonCliState = S.Struct({
1028
+ installed: S.Boolean,
1029
+ /** Version the installed binary reports; absent when it can't be read. */
1030
+ version: S.optional(S.NullOr(S.String)),
1031
+ });
1032
+ /**
1033
+ * An update replacing the `openllm` binary right now — the body of the
1034
+ * cross-process update lease (`packages/cli/src/update-lease.ts`, which a
1035
+ * parity test pins to this shape). `source` is who is updating (`app` = the
1036
+ * desktop app), `received`/`total` the download bytes when known.
1037
+ */
1038
+ export const DaemonUpdateState = S.Struct({
1039
+ pid: S.Number,
1040
+ source: S.Literals(["daemon", "cli", "installer", "app"]),
1041
+ version: S.NullOr(S.String),
1042
+ phase: S.Literals(["download", "verify", "install", "restart"]),
1043
+ received: S.NullOr(S.Number),
1044
+ total: S.NullOr(S.Number),
1045
+ started_at: S.Number,
1046
+ updated_at: S.Number,
1047
+ });
1048
+ // GET /status
1049
+ export const DaemonStatus = S.Struct({
1050
+ /** The RUNNING daemon's version. The dashboard shows this. */
1051
+ daemon_version: S.String,
1052
+ /** The installed binary's version on disk. One binary is both CLI and
1053
+ * daemon, and a swap whose daemon code is unchanged does not restart the
1054
+ * daemon, so this can be ahead of `daemon_version` until the next restart.
1055
+ * Absent on daemons too old to report it. */
1056
+ installed_version: S.optional(S.NullOr(S.String)),
1057
+ /** Whether an sk-llm key is set (the daemon installs keyless). */
1058
+ key_configured: S.Boolean,
1059
+ /** Whether automatic self-update is enabled (OPT-OUT, default on). Drives the
1060
+ * dashboard's auto-update switch; toggled via the `set_auto_update` command.
1061
+ * Absent on daemons too old to report it — those always self-updated, so the
1062
+ * switch then reads as on. See `packages/cli/daemon/src/auto-update-pref.ts`. */
1063
+ auto_update: S.optional(S.Boolean),
1064
+ /** Result of the last bootstrap — see `DaemonCloudState`. */
1065
+ cloud_state: DaemonCloudState,
1066
+ /** This daemon's X25519 public key (SPKI DER, base64). Lets ANOTHER of the
1067
+ * user's daemons SEAL a Claude setup-token to it for cross-machine copy
1068
+ * (`/api/daemon/relay-credential`) — the cloud only ever relays ciphertext.
1069
+ * Absent on daemons too old to publish one. */
1070
+ pubkey: S.optional(S.String),
1071
+ /** True when the cloud's immutable daemon X25519 pin differs from this
1072
+ * daemon's local key. A browser session must reset the pin before RTC can
1073
+ * connect; absent on daemons that have not observed this conflict. */
1074
+ identity_conflict: S.optional(S.Boolean),
1075
+ /** The device-control pin this daemon verifies grants against: `fp` is the
1076
+ * key's fingerprint (`keyFingerprint` in `@openllmsh/sdk/tunnel`), `via` the
1077
+ * path that set it. Whether it is agent-eligible is reported once, in
1078
+ * `device_sessions.anchored`. Absent when unpinned or on older daemons. */
1079
+ device_access_pin: S.optional(DeviceAccessPinReport),
1080
+ /** Device sessions readiness + the dpk proof (`DeviceSessionsReport`).
1081
+ * `anchored` == sessions on (env-file trust anchor present). Absent on
1082
+ * daemons too old to anchor — treat as not anchored. */
1083
+ device_sessions: S.optional(DeviceSessionsReport),
1084
+ /** The loopback port this daemon's `/v1/*` + `/whoami` surface listens on
1085
+ * (`OPENLLM_DAEMON_PORT`, default 8787). Reported in `daemon_status_json`
1086
+ * for display; routing never uses it (origin reaches devices over the
1087
+ * relay, not loopback). Absent on daemons too old to publish it. */
1088
+ port: S.optional(S.Number),
1089
+ /** The OS-sandbox posture this daemon booted with (`sandbox/landlock.ts`):
1090
+ * `enforced` (Landlock active), `off` (kill switch / dev opt-out),
1091
+ * `unsupported` (non-Linux, or a kernel without Landlock — the systemd
1092
+ * unit hardening may still confine the service), `error` (setup failed —
1093
+ * fail-open, surfaced so an unconfined daemon is visible, not silent).
1094
+ * Absent on daemons too old to report it. */
1095
+ sandbox: S.optional(S.Literals(["enforced", "off", "unsupported", "error"])),
1096
+ connections: S.Array(DaemonProviderConnection),
1097
+ /** Team keys this device holds for team tunnels' PSK handshake, so the
1098
+ * browser can tell which teams still need T sealed here. Absent on daemons
1099
+ * without `TEAM_KEY_CUSTODY_CONTROL_CAP`. */
1100
+ team_psk: S.optional(S.Array(DaemonTeamKeyEpoch)),
1101
+ /** The openllm CLI on this box. Absent on daemons too old to report it. */
1102
+ cli: S.optional(DaemonCliState),
1103
+ /** The update replacing the binary right now, or null when none is.
1104
+ * Absent on daemons too old to report it. */
1105
+ update: S.optional(S.NullOr(DaemonUpdateState)),
1106
+ /** Advertised transport capabilities, retained in fleet status telemetry. */
1107
+ caps: S.optional(S.Array(S.String)),
1108
+ /** Current and maximum concurrently-served tunneled requests. Optional for
1109
+ * older daemons; origin uses it only as an additive target-ranking signal. */
1110
+ served_tunnels: S.optional(S.Struct({
1111
+ active: S.Number,
1112
+ capacity: S.Number,
1113
+ })),
1114
+ /**
1115
+ * Control-plane capabilities this daemon implements (distinct from
1116
+ * mux/RTC `caps`). Open strings so a future daemon can advertise an
1117
+ * extra cap without the cloud rejecting the whole status. Optional so
1118
+ * older daemons omit it; the dashboard sends `refresh_models_due` only
1119
+ * when this array includes that exact literal. Command vocabulary stays
1120
+ * closed independently of this list.
1121
+ */
1122
+ control_caps: S.optional(S.Array(S.String)),
1123
+ /** Whether this daemon can host device chat sessions (PTY — POSIX only;
1124
+ * false on win32). Absent on daemons too old to report it — the
1125
+ * dashboard then hides the device variant for this box. */
1126
+ pty_supported: S.optional(S.Boolean),
1127
+ /** Live/dormant device sessions hosted on this box (feature §2.2) —
1128
+ * lets the dashboard mark which sessions can `attach` vs `continue`. */
1129
+ sessions: S.optional(S.Array(S.Struct({
1130
+ /** Local daemon session id; independent of the mux SessionId validator. */
1131
+ id: S.String.check(S.isMinLength(1), S.isMaxLength(128)),
1132
+ // Same closed vocabulary as the local `LocalSessionOpenPayload.cli`.
1133
+ cli: DeviceSessionCli,
1134
+ started_at_ms: S.Number,
1135
+ /** A consumer channel is currently bound. */
1136
+ attached: S.Boolean,
1137
+ /** The PTY is still running (attach re-binds; false → continue). */
1138
+ live: S.Boolean,
1139
+ /** Best-effort process-tree activity signal for dormant sessions. */
1140
+ busy: S.optional(S.Boolean),
1141
+ /** User-visible session label, bounded for presence snapshots. */
1142
+ title: S.optional(SessionTitleField),
1143
+ /** Terminal reason retained for a dead resumable session. */
1144
+ last_exit_reason: S.optional(SessionExitReason),
1145
+ /** Vendor resume id when known (local history / resume spawn). */
1146
+ vendor_session_id: S.optional(S.NullOr(S.String.check(S.isMaxLength(128)))),
1147
+ })).check(S.isMaxLength(32))),
1148
+ /**
1149
+ * Local model servers discovered on this device (no key material —
1150
+ * `has_key` only). Absent on daemons too old to probe. Bounded so a
1151
+ * noisy scan cannot bloat fleet status.
1152
+ */
1153
+ local_servers: S.optional(S.Array(LocalServerState).check(S.isMaxLength(64))),
1154
+ });
1155
+ /**
1156
+ * Canonical payload the cloud HMAC-signs for a daemon plan
1157
+ * (`/api/daemon/plan`), and the daemon re-derives to verify it. Order +
1158
+ * separators are load-bearing — both sides MUST assemble it identically, so
1159
+ * it lives here, shared. Covers: the ordered `plan` (provider/model ids), the
1160
+ * parallel `pmids` (concrete upstream `provider_model_id`s, so the daemon
1161
+ * serves catalog-free), and the `origin` (the deployment that issued the
1162
+ * plan, so the daemon forwards +
1163
+ * records back to it). Signing the lot makes the upstream ids and the
1164
+ * forward/record target tamper-evident.
1165
+ */
1166
+ export const daemonPlanSigningPayload = (plan, providerModelIds, origin, contextOverflowStrategy, holdNonce, maxOutputTokens) => {
1167
+ if (holdNonce != null && !HOLD_NONCE_PATTERN.test(holdNonce)) {
1168
+ throw new Error("Invalid hold nonce");
1169
+ }
1170
+ if (maxOutputTokens != null &&
1171
+ (!Number.isInteger(maxOutputTokens) || maxOutputTokens <= 0)) {
1172
+ throw new Error("Invalid max output tokens");
1173
+ }
1174
+ const base = contextOverflowStrategy === undefined || contextOverflowStrategy === null
1175
+ ? `${plan}\n${providerModelIds}\n${origin}`
1176
+ : `${plan}\n${providerModelIds}\n${origin}\n${contextOverflowStrategy}`;
1177
+ // A capped key's one-hop plan binds its cap hold. The `hold:` prefix can't
1178
+ // collide with a strategy line, which is always a fixed literal.
1179
+ const held = holdNonce === undefined || holdNonce === null
1180
+ ? base
1181
+ : `${base}\nhold:${holdNonce}`;
1182
+ // The output budget only rides a held plan; `out:` can't collide either.
1183
+ return maxOutputTokens === undefined || maxOutputTokens === null
1184
+ ? held
1185
+ : `${held}\nout:${maxOutputTokens}`;
1186
+ };
1187
+ // ─── GET /api/daemon/plan (daemon → cloud) ───────────────────────────
1188
+ //
1189
+ // The local-first gateway's plan fetch: the signed plan tuple, returned as
1190
+ // JSON so a daemon serving a DIRECT client request can obtain a plan without
1191
+ // the request body transiting the cloud. The daemon verifies `sig` with the
1192
+ // bootstrap-delivered per-user key (`planSignatureOk`) before caching or
1193
+ // executing. See
1194
+ // `docs/proposals/local-first-gateway.md` §4.1. For capped keys, repeated
1195
+ // `exclude=<model>` query parameters skip already-failed hops; uncapped keys
1196
+ // ignore them.
1197
+ export const DaemonPlanResponse = S.Struct({
1198
+ /** Comma-joined ordered `provider/model` chain. */
1199
+ plan: S.String,
1200
+ /** Parallel concrete `provider_model_id`s. */
1201
+ pmids: S.String,
1202
+ /** The issuing deployment's origin. */
1203
+ origin: S.String,
1204
+ /** Context-overflow strategy for this plan. Absent means hop-to-larger-context. */
1205
+ context_overflow_strategy: S.optional(ContextOverflowStrategy),
1206
+ /** Reservation for a capped one-hop plan, included in the signed payload. */
1207
+ hold_nonce: S.optional(HoldNonce),
1208
+ /** Largest output the hold allows (held plans only; signed). The daemon
1209
+ * lowers the request's output limit to it before dispatch. */
1210
+ max_output_tokens: S.optional(S.Number.check(S.isInt(), S.isGreaterThan(0))),
1211
+ /** Revision of the key's access policy this plan was built under; a
1212
+ * change drops the daemon's plan cache (see bootstrap `key_policy_rev`).
1213
+ * Optional so a plan from a cloud that predates it still decodes; absent
1214
+ * keeps the revision the daemon already knows. */
1215
+ policy_rev: S.optional(S.String),
1216
+ /** HMAC over the canonical payload; null when the cloud has no signing
1217
+ * secret configured (dev) — the daemon then treats it as unsigned. */
1218
+ sig: S.NullOr(S.String),
1219
+ });
1220
+ /** Header that carries the opaque held-tool continuation between client turns. */
1221
+ export const TOOL_SESSION_HEADER = "x-openllm-tool-session";
1222
+ /** Headers the daemon stamps on EVERY cloud control call (poll/status/bootstrap
1223
+ * /requests/relay/search) so the cloud can record which device a key's daemon
1224
+ * runs on — `api_key_activity.device_id`/`device_label`. The id is the daemon's
1225
+ * stable opaque per-machine UUID (`OPENLLM_DEVICE_ID` in `~/.openllm/.env`); the label is the
1226
+ * host's `os.hostname()` for the dashboard to show. Both metadata-only (no
1227
+ * token, no content). Lets the dashboard tell two daemons behind one NAT apart
1228
+ * — device code + IP, not IP alone. See
1229
+ * `docs/proposals/daemon-device-aware-this-machine.md`. */
1230
+ export const DAEMON_DEVICE_ID_HEADER = "x-openllm-device-id";
1231
+ export const DAEMON_DEVICE_LABEL_HEADER = "x-openllm-device-label";
1232
+ /**
1233
+ * Optional OS platform the daemon reports on control-plane calls
1234
+ * (`process.platform`: `darwin` / `linux` / `win32` / `freebsd` /
1235
+ * `openbsd` / `android` / `aix` / `sunos`). Metadata only —
1236
+ * used for `daemon_connected` analytics. Absent on older binaries.
1237
+ */
1238
+ export const DAEMON_PLATFORM_HEADER = "x-openllm-platform";
1239
+ /**
1240
+ * Header a daemon sends on control-plane calls (chiefly
1241
+ * `GET /api/daemon/bootstrap`) listing the open-vocabulary decode
1242
+ * capabilities it supports — e.g. `MODEL_CAPABILITIES_OPEN_CAP` from
1243
+ * `./models`. Comma-joined; absent/empty on an old compiled daemon, which
1244
+ * the bootstrap encoder MUST treat as "closed literal decoder only" —
1245
+ * never inferred from a version string, which an unbumped daemon build
1246
+ * would leave stale.
1247
+ */
1248
+ export const DAEMON_BOOTSTRAP_CAPS_HEADER = "x-openllm-daemon-caps";
1249
+ /**
1250
+ * Parse the comma-joined {@link DAEMON_BOOTSTRAP_CAPS_HEADER} value into a
1251
+ * capability list. A null/empty header (old daemon, or the header simply
1252
+ * absent) decodes to an empty list — no negotiated capability.
1253
+ */
1254
+ export const parseDaemonBootstrapCapsHeader = (value) => value === null || value.trim() === ""
1255
+ ? []
1256
+ : value
1257
+ .split(",")
1258
+ .map((c) => c.trim())
1259
+ .filter((c) => c.length > 0);
1260
+ // POST /config/api-key — set/update the daemon's sk-llm key after install.
1261
+ export const DaemonSetApiKeyRequest = S.Struct({
1262
+ api_key: S.String,
1263
+ });
1264
+ export const DaemonSetApiKeyResponse = S.Struct({
1265
+ key_configured: S.Boolean,
1266
+ cloud_state: DaemonCloudState,
1267
+ });
1268
+ // POST /connect/:slug
1269
+ export const DaemonConnectResponse = S.Struct({
1270
+ provider: S.String,
1271
+ connected: S.Boolean,
1272
+ detail: S.optional(S.String),
1273
+ /**
1274
+ * True when `connect` kicked off an async flow that hasn't finished yet
1275
+ * (Kimi's device-code login: browser opened, daemon polling in the
1276
+ * background). `detail` is then INFORMATIONAL guidance, not an error —
1277
+ * the UI renders it neutrally and the status stream flips to connected
1278
+ * when the flow completes. Absent/false on terminal results.
1279
+ */
1280
+ pending: S.optional(S.Boolean),
1281
+ });
1282
+ // GET /usage/:slug — reuses the existing snapshot shape verbatim.
1283
+ export const DaemonUsageResponse = S.Struct({
1284
+ provider: S.String,
1285
+ snapshot: ProviderUsageSnapshot,
1286
+ });