@the-open-engine/zeroshot 6.29.0 → 6.30.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (347) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/cli/index.js +2 -4
  3. package/lib/agent-cli-provider/adapters/codex.d.ts.map +1 -1
  4. package/lib/agent-cli-provider/adapters/codex.js +0 -1
  5. package/lib/agent-cli-provider/adapters/codex.js.map +1 -1
  6. package/lib/agent-cli-provider/contract-actions.d.ts +1 -1
  7. package/lib/agent-cli-provider/contract-actions.d.ts.map +1 -1
  8. package/lib/agent-cli-provider/contract-actions.js +5 -5
  9. package/lib/agent-cli-provider/contract-actions.js.map +1 -1
  10. package/lib/agent-cli-provider/contract-invoke.d.ts +1 -1
  11. package/lib/agent-cli-provider/contract-invoke.d.ts.map +1 -1
  12. package/lib/agent-cli-provider/contract-invoke.js +2 -2
  13. package/lib/agent-cli-provider/contract-invoke.js.map +1 -1
  14. package/lib/agent-cli-provider/contract-support.d.ts +1 -1
  15. package/lib/agent-cli-provider/contract-support.d.ts.map +1 -1
  16. package/lib/agent-cli-provider/contract-support.js +2 -2
  17. package/lib/agent-cli-provider/contract-support.js.map +1 -1
  18. package/lib/agent-cli-provider/contract.d.ts +1 -0
  19. package/lib/agent-cli-provider/contract.d.ts.map +1 -1
  20. package/lib/agent-cli-provider/contract.js +1 -1
  21. package/lib/agent-cli-provider/contract.js.map +1 -1
  22. package/lib/agent-cli-provider/index.d.ts +1 -1
  23. package/lib/agent-cli-provider/index.d.ts.map +1 -1
  24. package/lib/agent-cli-provider/index.js +2 -1
  25. package/lib/agent-cli-provider/index.js.map +1 -1
  26. package/lib/agent-cli-provider/provider-registry.d.ts +1 -0
  27. package/lib/agent-cli-provider/provider-registry.d.ts.map +1 -1
  28. package/lib/agent-cli-provider/provider-registry.js +4 -0
  29. package/lib/agent-cli-provider/provider-registry.js.map +1 -1
  30. package/lib/agent-cli-provider/single-agent-runtime.d.ts +3 -3
  31. package/lib/agent-cli-provider/single-agent-runtime.d.ts.map +1 -1
  32. package/lib/agent-cli-provider/single-agent-runtime.js +22 -48
  33. package/lib/agent-cli-provider/single-agent-runtime.js.map +1 -1
  34. package/lib/cluster/client.cjs +30 -7
  35. package/lib/cluster/client.d.cts +52 -0
  36. package/lib/cluster/client.d.mts +52 -0
  37. package/lib/cluster/client.d.ts +4 -6
  38. package/lib/cluster/client.mjs +32 -9
  39. package/lib/cluster/connection-state.cjs +25 -0
  40. package/lib/cluster/connection-state.d.cts +13 -0
  41. package/lib/cluster/connection-state.d.mts +13 -0
  42. package/lib/cluster/connection-state.d.ts +13 -0
  43. package/lib/cluster/connection-state.mjs +21 -0
  44. package/lib/{target/hosted-run/contracts.js → cluster/connection-types.cjs} +0 -1
  45. package/lib/cluster/connection-types.d.cts +33 -0
  46. package/lib/cluster/connection-types.d.mts +33 -0
  47. package/lib/cluster/connection-types.d.ts +33 -0
  48. package/lib/cluster/connection-types.mjs +1 -0
  49. package/lib/cluster/connection.cjs +18 -46
  50. package/lib/cluster/connection.d.cts +26 -0
  51. package/lib/cluster/connection.d.mts +26 -0
  52. package/lib/cluster/connection.d.ts +7 -25
  53. package/lib/cluster/connection.mjs +12 -42
  54. package/lib/cluster/errors.cjs +9 -1
  55. package/lib/cluster/errors.d.cts +29 -0
  56. package/lib/cluster/errors.d.mts +29 -0
  57. package/lib/cluster/errors.d.ts +4 -0
  58. package/lib/cluster/errors.mjs +7 -0
  59. package/lib/cluster/frames.d.cts +12 -0
  60. package/lib/cluster/frames.d.mts +12 -0
  61. package/lib/cluster/generated/protocol-schema.d.cts +1 -0
  62. package/lib/cluster/generated/protocol-schema.d.mts +1 -0
  63. package/lib/cluster/generated/protocol.d.cts +781 -0
  64. package/lib/cluster/generated/protocol.d.mts +781 -0
  65. package/lib/cluster/index.cjs +2 -2
  66. package/lib/cluster/index.d.cts +13 -0
  67. package/lib/cluster/index.d.mts +13 -0
  68. package/lib/cluster/index.d.ts +3 -3
  69. package/lib/cluster/index.mjs +2 -2
  70. package/lib/cluster/json-source.cjs +1 -0
  71. package/lib/cluster/json-source.d.cts +5 -0
  72. package/lib/cluster/json-source.d.mts +5 -0
  73. package/lib/cluster/json-source.d.ts +1 -0
  74. package/lib/cluster/json-source.mjs +1 -0
  75. package/lib/cluster/payload-value.cjs +1 -0
  76. package/lib/cluster/payload-value.d.cts +8 -0
  77. package/lib/cluster/payload-value.d.mts +8 -0
  78. package/lib/cluster/payload-value.d.ts +1 -0
  79. package/lib/cluster/payload-value.mjs +1 -0
  80. package/lib/cluster/queue.d.cts +15 -0
  81. package/lib/cluster/queue.d.mts +15 -0
  82. package/lib/cluster/socket.cjs +8 -0
  83. package/lib/cluster/socket.d.cts +13 -0
  84. package/lib/cluster/socket.d.mts +13 -0
  85. package/lib/cluster/socket.d.ts +2 -0
  86. package/lib/cluster/socket.mjs +7 -0
  87. package/lib/cluster/subscriptions.d.cts +73 -0
  88. package/lib/cluster/subscriptions.d.mts +73 -0
  89. package/lib/cluster/subscriptions.d.ts +5 -1
  90. package/lib/cluster/validators.cjs +1 -0
  91. package/lib/cluster/validators.d.cts +7 -0
  92. package/lib/cluster/validators.d.mts +7 -0
  93. package/lib/cluster/validators.d.ts +1 -0
  94. package/lib/cluster/validators.mjs +1 -0
  95. package/lib/cluster-worker/engine-adapter-common.js +37 -0
  96. package/lib/cluster-worker/engine-adapter.js +24 -30
  97. package/lib/cluster-worker/engine-start.js +59 -0
  98. package/lib/cluster-worker/index.js +49 -67
  99. package/lib/cluster-worker/profiles.js +1 -42
  100. package/lib/cluster-worker/runtime-dependencies.js +49 -0
  101. package/lib/cluster-worker/runtime-support.js +2 -34
  102. package/lib/cluster-worker/terminal-normalizer.js +9 -10
  103. package/lib/hosted-session/authority.cjs +61 -0
  104. package/lib/hosted-session/authority.d.cts +3 -0
  105. package/lib/hosted-session/authority.d.mts +3 -0
  106. package/lib/hosted-session/authority.d.ts +3 -0
  107. package/lib/hosted-session/authority.mjs +57 -0
  108. package/lib/hosted-session/coordinator.cjs +78 -51
  109. package/lib/hosted-session/coordinator.d.cts +11 -0
  110. package/lib/hosted-session/coordinator.d.mts +11 -0
  111. package/lib/hosted-session/coordinator.d.ts +4 -2
  112. package/lib/hosted-session/coordinator.mjs +75 -51
  113. package/lib/hosted-session/errors.cjs +25 -0
  114. package/lib/hosted-session/errors.d.cts +10 -0
  115. package/lib/hosted-session/errors.d.mts +10 -0
  116. package/lib/hosted-session/errors.d.ts +10 -0
  117. package/lib/hosted-session/errors.mjs +19 -0
  118. package/lib/hosted-session/index.cjs +4 -1
  119. package/lib/hosted-session/index.d.cts +2 -0
  120. package/lib/hosted-session/index.d.mts +2 -0
  121. package/lib/hosted-session/index.d.ts +2 -2
  122. package/lib/hosted-session/index.mjs +1 -1
  123. package/lib/hosted-session/reconnecting-watch.cjs +131 -0
  124. package/lib/hosted-session/reconnecting-watch.d.cts +13 -0
  125. package/lib/hosted-session/reconnecting-watch.d.mts +13 -0
  126. package/lib/hosted-session/reconnecting-watch.d.ts +13 -0
  127. package/lib/hosted-session/reconnecting-watch.mjs +127 -0
  128. package/lib/hosted-session/types.d.cts +32 -0
  129. package/lib/hosted-session/types.d.mts +32 -0
  130. package/lib/hosted-session/types.d.ts +19 -7
  131. package/lib/hosted-target/access-url.cjs +44 -0
  132. package/lib/hosted-target/access-url.d.cts +2 -0
  133. package/lib/hosted-target/access-url.d.mts +2 -0
  134. package/lib/hosted-target/access-url.d.ts +2 -0
  135. package/lib/hosted-target/access-url.mjs +41 -0
  136. package/lib/hosted-target/adapter-request.cjs +12 -0
  137. package/lib/hosted-target/adapter-request.d.cts +17 -0
  138. package/lib/hosted-target/adapter-request.d.mts +17 -0
  139. package/lib/hosted-target/adapter-request.d.ts +17 -0
  140. package/lib/hosted-target/adapter-request.mjs +9 -0
  141. package/lib/hosted-target/adapter-types.cjs +2 -0
  142. package/lib/hosted-target/adapter-types.d.cts +27 -0
  143. package/lib/hosted-target/adapter-types.d.mts +27 -0
  144. package/lib/hosted-target/adapter-types.d.ts +27 -0
  145. package/lib/hosted-target/adapter-types.mjs +1 -0
  146. package/lib/hosted-target/bounds.cjs +10 -0
  147. package/lib/hosted-target/bounds.d.cts +7 -0
  148. package/lib/hosted-target/bounds.d.mts +7 -0
  149. package/lib/hosted-target/bounds.d.ts +7 -0
  150. package/lib/hosted-target/bounds.mjs +7 -0
  151. package/lib/hosted-target/capsule-error-response.cjs +76 -0
  152. package/lib/hosted-target/capsule-error-response.d.cts +2 -0
  153. package/lib/hosted-target/capsule-error-response.d.mts +2 -0
  154. package/lib/hosted-target/capsule-error-response.d.ts +2 -0
  155. package/lib/hosted-target/capsule-error-response.mjs +73 -0
  156. package/lib/hosted-target/errors.cjs +88 -0
  157. package/lib/hosted-target/errors.d.cts +36 -0
  158. package/lib/hosted-target/errors.d.mts +36 -0
  159. package/lib/hosted-target/errors.d.ts +36 -0
  160. package/lib/hosted-target/errors.mjs +75 -0
  161. package/lib/hosted-target/index.cjs +16 -0
  162. package/lib/hosted-target/index.d.cts +3 -0
  163. package/lib/hosted-target/index.d.mts +3 -0
  164. package/lib/hosted-target/index.d.ts +3 -0
  165. package/lib/hosted-target/index.mjs +2 -0
  166. package/lib/hosted-target/response-validation.cjs +169 -0
  167. package/lib/hosted-target/response-validation.d.cts +5 -0
  168. package/lib/hosted-target/response-validation.d.mts +5 -0
  169. package/lib/hosted-target/response-validation.d.ts +5 -0
  170. package/lib/hosted-target/response-validation.mjs +163 -0
  171. package/lib/hosted-target/retry-executor.cjs +51 -0
  172. package/lib/hosted-target/retry-executor.d.cts +8 -0
  173. package/lib/hosted-target/retry-executor.d.mts +8 -0
  174. package/lib/hosted-target/retry-executor.d.ts +8 -0
  175. package/lib/hosted-target/retry-executor.mjs +48 -0
  176. package/lib/hosted-target/retry.cjs +78 -0
  177. package/lib/hosted-target/retry.d.cts +9 -0
  178. package/lib/hosted-target/retry.d.mts +9 -0
  179. package/lib/hosted-target/retry.d.ts +9 -0
  180. package/lib/hosted-target/retry.mjs +73 -0
  181. package/lib/hosted-target/target-adapter.cjs +10 -0
  182. package/lib/hosted-target/target-adapter.d.cts +3 -0
  183. package/lib/hosted-target/target-adapter.d.mts +3 -0
  184. package/lib/hosted-target/target-adapter.d.ts +3 -0
  185. package/lib/hosted-target/target-adapter.mjs +7 -0
  186. package/lib/hosted-target/types.cjs +4 -0
  187. package/lib/hosted-target/types.d.cts +50 -0
  188. package/lib/hosted-target/types.d.mts +50 -0
  189. package/lib/hosted-target/types.d.ts +50 -0
  190. package/lib/hosted-target/types.mjs +1 -0
  191. package/lib/hosted-target/zero-cloud-v1-adapter.cjs +185 -0
  192. package/lib/hosted-target/zero-cloud-v1-adapter.d.cts +13 -0
  193. package/lib/hosted-target/zero-cloud-v1-adapter.d.mts +13 -0
  194. package/lib/hosted-target/zero-cloud-v1-adapter.d.ts +13 -0
  195. package/lib/hosted-target/zero-cloud-v1-adapter.mjs +181 -0
  196. package/lib/start-cluster.js +3 -3
  197. package/lib/target/bounded-response.cjs +51 -0
  198. package/lib/target/bounded-response.d.cts +1 -0
  199. package/lib/target/bounded-response.d.mts +1 -0
  200. package/lib/target/bounded-response.d.ts +1 -0
  201. package/lib/target/bounded-response.js +51 -0
  202. package/lib/target/bounded-response.mjs +48 -0
  203. package/lib/target/credential-lock.js +1 -3
  204. package/lib/target/credential-store.js +9 -4
  205. package/lib/target/device-flow.cjs +213 -0
  206. package/lib/target/device-flow.d.cts +54 -0
  207. package/lib/target/device-flow.d.mts +54 -0
  208. package/lib/target/device-flow.d.ts +26 -14
  209. package/lib/target/device-flow.js +162 -58
  210. package/lib/target/device-flow.mjs +203 -0
  211. package/lib/target/discovery-errors.cjs +10 -0
  212. package/lib/target/discovery-errors.d.cts +3 -0
  213. package/lib/target/discovery-errors.d.mts +3 -0
  214. package/lib/target/discovery-errors.d.ts +3 -0
  215. package/lib/target/discovery-errors.js +10 -0
  216. package/lib/target/discovery-errors.mjs +6 -0
  217. package/lib/target/discovery-sections.cjs +191 -0
  218. package/lib/target/discovery-sections.d.cts +52 -0
  219. package/lib/target/discovery-sections.d.mts +52 -0
  220. package/lib/target/discovery-sections.d.ts +52 -0
  221. package/lib/target/discovery-sections.js +191 -0
  222. package/lib/target/discovery-sections.mjs +179 -0
  223. package/lib/target/discovery-validation.cjs +109 -0
  224. package/lib/target/discovery-validation.d.cts +28 -0
  225. package/lib/target/discovery-validation.d.mts +28 -0
  226. package/lib/target/discovery-validation.d.ts +28 -0
  227. package/lib/target/discovery-validation.js +109 -0
  228. package/lib/target/discovery-validation.mjs +99 -0
  229. package/lib/target/discovery.cjs +112 -0
  230. package/lib/target/discovery.d.cts +74 -0
  231. package/lib/target/discovery.d.mts +74 -0
  232. package/lib/target/discovery.d.ts +67 -5
  233. package/lib/target/discovery.js +94 -79
  234. package/lib/target/discovery.mjs +105 -0
  235. package/lib/target/index.d.ts +6 -6
  236. package/lib/target/index.js +36 -36
  237. package/lib/target/oauth-http.d.ts +2 -0
  238. package/lib/target/oauth-http.js +25 -0
  239. package/lib/target/refresh-exchange.d.ts +11 -0
  240. package/lib/target/refresh-exchange.js +24 -0
  241. package/lib/target/refresh-revocation.d.ts +8 -0
  242. package/lib/target/refresh-revocation.js +19 -0
  243. package/lib/target/route-template.cjs +85 -0
  244. package/lib/target/route-template.d.cts +7 -0
  245. package/lib/target/route-template.d.mts +7 -0
  246. package/lib/target/route-template.d.ts +7 -0
  247. package/lib/target/route-template.js +85 -0
  248. package/lib/target/route-template.mjs +81 -0
  249. package/lib/target/session-errors.d.ts +4 -0
  250. package/lib/target/session-errors.js +12 -0
  251. package/lib/target/session-verification.d.ts +10 -0
  252. package/lib/target/session-verification.js +42 -0
  253. package/lib/target/target-registry.d.ts +7 -3
  254. package/lib/target/target-registry.js +41 -10
  255. package/lib/target/target-session-manager.d.ts +48 -0
  256. package/lib/target/target-session-manager.js +226 -0
  257. package/lib/target/target-session.d.ts +39 -32
  258. package/lib/target/target-session.js +63 -151
  259. package/lib/target/token-response.cjs +51 -0
  260. package/lib/target/token-response.d.cts +7 -0
  261. package/lib/target/token-response.d.mts +7 -0
  262. package/lib/target/token-response.d.ts +7 -0
  263. package/lib/target/token-response.js +51 -0
  264. package/lib/target/token-response.mjs +48 -0
  265. package/package.json +14 -7
  266. package/protocol/openengine-cluster/v1/worker.schema.json +171 -9
  267. package/scripts/build-cluster.js +23 -3
  268. package/scripts/opcore-introduced-check.js +0 -2
  269. package/src/agent-cli-provider/adapters/codex.ts +0 -1
  270. package/src/agent-cli-provider/contract-actions.ts +9 -5
  271. package/src/agent-cli-provider/contract-invoke.ts +3 -2
  272. package/src/agent-cli-provider/contract-support.ts +12 -6
  273. package/src/agent-cli-provider/contract.ts +6 -1
  274. package/src/agent-cli-provider/index.ts +1 -0
  275. package/src/agent-cli-provider/provider-registry.ts +4 -0
  276. package/src/agent-cli-provider/single-agent-runtime.ts +32 -45
  277. package/src/cluster/client.ts +42 -15
  278. package/src/cluster/connection-state.ts +33 -0
  279. package/src/cluster/connection-types.ts +28 -0
  280. package/src/cluster/connection.ts +37 -68
  281. package/src/cluster/errors.ts +5 -0
  282. package/src/cluster/index.ts +3 -1
  283. package/src/cluster/json-source.ts +1 -0
  284. package/src/cluster/payload-value.ts +1 -0
  285. package/src/cluster/socket.ts +13 -0
  286. package/src/cluster/subscriptions.ts +7 -2
  287. package/src/cluster/validators.ts +1 -0
  288. package/src/cluster/ws.d.ts +1 -1
  289. package/src/hosted-session/authority.ts +77 -0
  290. package/src/hosted-session/coordinator.ts +113 -56
  291. package/src/hosted-session/errors.ts +21 -0
  292. package/src/hosted-session/index.ts +14 -2
  293. package/src/hosted-session/reconnecting-watch.ts +148 -0
  294. package/src/hosted-session/types.ts +22 -8
  295. package/src/hosted-target/access-url.ts +46 -0
  296. package/src/hosted-target/adapter-request.ts +28 -0
  297. package/src/hosted-target/adapter-types.ts +39 -0
  298. package/src/hosted-target/bounds.ts +1 -0
  299. package/src/hosted-target/capsule-error-response.ts +107 -0
  300. package/src/hosted-target/errors.ts +36 -35
  301. package/src/hosted-target/index.ts +10 -23
  302. package/src/hosted-target/response-validation.ts +170 -62
  303. package/src/hosted-target/retry-executor.ts +62 -0
  304. package/src/hosted-target/retry.ts +47 -11
  305. package/src/hosted-target/target-adapter.ts +12 -8
  306. package/src/hosted-target/types.ts +19 -18
  307. package/src/hosted-target/zero-cloud-v1-adapter.ts +229 -316
  308. package/src/isolation-manager.js +1 -16
  309. package/src/target/bounded-response.ts +68 -0
  310. package/src/target/credential-lock.ts +1 -3
  311. package/src/target/credential-store.ts +14 -10
  312. package/src/target/device-flow.ts +209 -85
  313. package/src/target/discovery-errors.ts +6 -0
  314. package/src/target/discovery-sections.ts +251 -0
  315. package/src/target/discovery-validation.ts +144 -0
  316. package/src/target/discovery.ts +163 -97
  317. package/src/target/index.ts +15 -11
  318. package/src/target/oauth-http.ts +27 -0
  319. package/src/target/refresh-exchange.ts +36 -0
  320. package/src/target/refresh-revocation.ts +29 -0
  321. package/src/target/route-template.ts +105 -0
  322. package/src/target/session-errors.ts +9 -0
  323. package/src/target/session-verification.ts +51 -0
  324. package/src/target/target-registry.ts +60 -27
  325. package/src/target/target-session-manager.ts +285 -0
  326. package/src/target/target-session.ts +105 -226
  327. package/src/target/token-response.ts +62 -0
  328. package/docker/zeroshot-oecp/Cargo.toml +0 -12
  329. package/docker/zeroshot-oecp/Dockerfile +0 -65
  330. package/docker/zeroshot-oecp/src/main.rs +0 -32
  331. package/lib/target/bounded-json.d.ts +0 -6
  332. package/lib/target/bounded-json.js +0 -43
  333. package/lib/target/hosted-run/client.d.ts +0 -26
  334. package/lib/target/hosted-run/client.js +0 -158
  335. package/lib/target/hosted-run/commands.d.ts +0 -4
  336. package/lib/target/hosted-run/commands.js +0 -113
  337. package/lib/target/hosted-run/contracts.d.ts +0 -49
  338. package/lib/target/hosted-run/input.d.ts +0 -5
  339. package/lib/target/hosted-run/input.js +0 -200
  340. package/lib/target/hosted-run.d.ts +0 -4
  341. package/lib/target/hosted-run.js +0 -12
  342. package/src/target/bounded-json.ts +0 -48
  343. package/src/target/hosted-run/client.ts +0 -198
  344. package/src/target/hosted-run/commands.ts +0 -140
  345. package/src/target/hosted-run/contracts.ts +0 -53
  346. package/src/target/hosted-run/input.ts +0 -199
  347. package/src/target/hosted-run.ts +0 -8
@@ -1,198 +0,0 @@
1
- import { acquireTargetLock } from '../credential-lock.ts';
2
- import { KeyringCredentialStore } from '../credential-store.ts';
3
- import { discoverTargetSessionEndpoints } from '../discovery.ts';
4
- import { getTarget } from '../target-registry.ts';
5
- import { getAccessTokenProvider, type TargetAccessTokenProvider } from '../target-session.ts';
6
- import { readBoundedJson } from '../bounded-json.ts';
7
-
8
- import type { HostedRunDependencies, HostedRunIntent } from './contracts.ts';
9
-
10
- const MAX_RESPONSE_BYTES = 1024 * 1024;
11
- export const UUID = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
12
- export const TERMINAL_STATES = new Set(['succeeded', 'failed', 'cancelled', 'expired']);
13
- const RUN_INTENT_STATES = new Set([
14
- 'queued',
15
- 'provisioning',
16
- 'running',
17
- 'cancelling',
18
- ...TERMINAL_STATES,
19
- ]);
20
-
21
- export interface HostedContext {
22
- readonly targetName: string;
23
- readonly organization: string;
24
- readonly client: RunIntentClient;
25
- }
26
-
27
- function wait(milliseconds: number): Promise<void> {
28
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
29
- }
30
-
31
- export class HostedRunHttpError extends Error {
32
- readonly status: number;
33
- readonly code: string | null;
34
-
35
- constructor(status: number, message: string, code: string | null = null) {
36
- super(message);
37
- this.name = 'HostedRunHttpError';
38
- this.status = status;
39
- this.code = code;
40
- }
41
- }
42
-
43
- function validateIntent(value: unknown): HostedRunIntent {
44
- if (value === null || typeof value !== 'object' || Array.isArray(value)) {
45
- throw new Error('Zero Cloud returned an invalid run intent');
46
- }
47
- const record = value as Record<string, unknown>;
48
- if (
49
- typeof record['intent_id'] !== 'string' ||
50
- !UUID.test(record['intent_id']) ||
51
- typeof record['state'] !== 'string' ||
52
- !RUN_INTENT_STATES.has(record['state'])
53
- ) {
54
- throw new Error('Zero Cloud returned an invalid run intent');
55
- }
56
- const result = record['result'];
57
- if (result !== null && (typeof result !== 'object' || Array.isArray(result))) {
58
- throw new Error('Zero Cloud returned an invalid run intent result');
59
- }
60
- return record as unknown as HostedRunIntent;
61
- }
62
-
63
- export class RunIntentClient {
64
- private readonly baseUrl: string;
65
- private readonly organization: string;
66
- private readonly tokenProvider: TargetAccessTokenProvider;
67
- private readonly fetch: typeof globalThis.fetch;
68
-
69
- constructor(
70
- baseUrl: string,
71
- organization: string,
72
- tokenProvider: TargetAccessTokenProvider,
73
- fetchImplementation: typeof globalThis.fetch
74
- ) {
75
- this.baseUrl = baseUrl.replace(/\/$/, '');
76
- this.organization = organization;
77
- this.tokenProvider = tokenProvider;
78
- this.fetch = fetchImplementation;
79
- }
80
-
81
- async submit(body: Record<string, unknown>, submissionKey: string): Promise<HostedRunIntent> {
82
- let failure: unknown;
83
- for (let attempt = 0; attempt < 2; attempt += 1) {
84
- try {
85
- return await this.request('', {
86
- method: 'POST',
87
- body: JSON.stringify(body),
88
- headers: { 'Idempotency-Key': submissionKey },
89
- });
90
- } catch (error) {
91
- failure = error;
92
- if (error instanceof HostedRunHttpError && error.status < 500) throw error;
93
- if (attempt === 0) await wait(250);
94
- }
95
- }
96
- throw failure;
97
- }
98
-
99
- get(intentId: string): Promise<HostedRunIntent> {
100
- return this.request(`/${encodeURIComponent(intentId)}`, { method: 'GET' });
101
- }
102
-
103
- cancel(intentId: string): Promise<HostedRunIntent> {
104
- return this.request(`/${encodeURIComponent(intentId)}`, { method: 'DELETE' });
105
- }
106
-
107
- private async request(
108
- suffix: string,
109
- options: { method: string; body?: string; headers?: Record<string, string> }
110
- ): Promise<HostedRunIntent> {
111
- const token = await this.tokenProvider.getAccessToken();
112
- const url = `${this.baseUrl}/orgs/${encodeURIComponent(this.organization)}/run-intents${suffix}`;
113
- const init: RequestInit & { redirect: 'error' } = {
114
- method: options.method,
115
- redirect: 'error',
116
- headers: {
117
- Accept: 'application/json',
118
- Authorization: `Bearer ${token}`,
119
- 'Content-Type': 'application/json',
120
- ...options.headers,
121
- },
122
- };
123
- if (options.body !== undefined) init.body = options.body;
124
- let response: Response;
125
- try {
126
- response = await this.fetch(url, init);
127
- } catch (error) {
128
- throw new Error(
129
- `Zero Cloud request failed: ${error instanceof Error ? error.message : String(error)}`
130
- );
131
- }
132
- const body = await readBoundedJson(response, MAX_RESPONSE_BYTES, {
133
- tooLarge: () => new Error('Zero Cloud response exceeded 1 MiB'),
134
- invalid: () => new Error('Zero Cloud returned invalid JSON'),
135
- });
136
- if (!response.ok) {
137
- const problem = body as Record<string, unknown>;
138
- const code = typeof problem['code'] === 'string' ? problem['code'] : null;
139
- const message =
140
- typeof problem['message'] === 'string' ? problem['message'] : 'request failed';
141
- throw new HostedRunHttpError(
142
- response.status,
143
- `Zero Cloud ${response.status}: ${message}`,
144
- code
145
- );
146
- }
147
- return validateIntent(body);
148
- }
149
- }
150
-
151
- export async function context(targetName: string, deps: HostedRunDependencies): Promise<HostedContext> {
152
- const environment = deps.environment ?? process.env;
153
- const target = getTarget(targetName, deps.settings);
154
- if (!target) throw new Error(`Target "${targetName}" not found.`);
155
- const http = {
156
- fetch: (url: string, init: RequestInit & { redirect: 'error' }) =>
157
- (deps.fetch ?? globalThis.fetch)(url, init),
158
- };
159
- const discovery = await discoverTargetSessionEndpoints(target.url, http);
160
- const ephemeralToken = environment['ZEROSHOT_TARGET_ACCESS_TOKEN']?.trim();
161
- const ephemeralOrganization = environment['ZEROSHOT_TARGET_ORGANIZATION']?.trim();
162
- if ((ephemeralToken && !ephemeralOrganization) || (!ephemeralToken && ephemeralOrganization)) {
163
- throw new Error(
164
- 'ZEROSHOT_TARGET_ACCESS_TOKEN and ZEROSHOT_TARGET_ORGANIZATION must be provided together'
165
- );
166
- }
167
-
168
- let organization: string;
169
- let tokenProvider: TargetAccessTokenProvider;
170
- if (ephemeralToken && ephemeralOrganization) {
171
- organization = ephemeralOrganization;
172
- tokenProvider = { getAccessToken: async () => ephemeralToken };
173
- } else {
174
- if (!target.organization) {
175
- throw new Error(`Login required. Run: zeroshot target login ${targetName}`);
176
- }
177
- organization = target.organization.id;
178
- const credentials = await KeyringCredentialStore.create();
179
- tokenProvider = getAccessTokenProvider(
180
- targetName,
181
- target,
182
- credentials,
183
- () => acquireTargetLock(target.id),
184
- { http, discoveryEndpoints: discovery }
185
- );
186
- }
187
-
188
- return {
189
- targetName,
190
- organization,
191
- client: new RunIntentClient(
192
- discovery.capsuleApiBaseUrl,
193
- organization,
194
- tokenProvider,
195
- deps.fetch ?? globalThis.fetch
196
- ),
197
- };
198
- }
@@ -1,140 +0,0 @@
1
- import crypto from 'node:crypto';
2
-
3
- import type { HostedOptions, HostedRunDependencies, HostedRunIntent } from './contracts.ts';
4
- import {
5
- context,
6
- HostedRunHttpError,
7
- TERMINAL_STATES,
8
- UUID,
9
- type HostedContext,
10
- } from './client.ts';
11
- import {
12
- githubToken,
13
- providerKey,
14
- resolveHostedInput,
15
- validateHostedOptions,
16
- } from './input.ts';
17
-
18
- const DEFAULT_MODEL = 'openai/gpt-5.4';
19
- const RUN_INTENT_VERSION = 'zeroshot.run-intent/v1';
20
- const MAX_RUN_INTENT_BYTES = 1024 * 1024 + 64 * 1024;
21
- const RUN_INTENT_POLL_MS = 500;
22
-
23
- function output(deps: HostedRunDependencies, value: string): void {
24
- (deps.stdout ?? process.stdout).write(`${value}\n`);
25
- }
26
-
27
- function wait(milliseconds: number): Promise<void> {
28
- return new Promise((resolve) => setTimeout(resolve, milliseconds));
29
- }
30
-
31
- function displayState(intent: HostedRunIntent): string {
32
- return intent.waiting_reason ? `${intent.state} (${intent.waiting_reason})` : intent.state;
33
- }
34
-
35
- function resumeCommand(value: HostedContext, intentId: string): string {
36
- return `zeroshot target status ${value.targetName} ${intentId} --follow`;
37
- }
38
-
39
- async function follow(
40
- value: HostedContext,
41
- initial: HostedRunIntent,
42
- deps: HostedRunDependencies
43
- ): Promise<Record<string, unknown> | null> {
44
- let intent = initial;
45
- let displayed: string | null = null;
46
- for (;;) {
47
- const state = displayState(intent);
48
- if (state !== displayed) {
49
- output(deps, `Run ${intent.intent_id}: ${state}`);
50
- displayed = state;
51
- }
52
- if (TERMINAL_STATES.has(intent.state)) break;
53
- await (deps.delay ?? wait)(RUN_INTENT_POLL_MS);
54
- intent = await value.client.get(intent.intent_id);
55
- }
56
- if (intent.state === 'succeeded') {
57
- const summary = intent.result?.['summary'];
58
- if (typeof summary === 'string' && summary) output(deps, summary);
59
- return intent.result;
60
- }
61
- const detail = intent.error_code ? ` (${intent.error_code})` : '';
62
- throw new Error(`hosted run ${intent.state}${detail}`);
63
- }
64
-
65
- export async function runHosted(
66
- input: string,
67
- options: HostedOptions,
68
- deps: HostedRunDependencies
69
- ): Promise<HostedRunIntent | Record<string, unknown> | null> {
70
- validateHostedOptions(options);
71
- const environment = deps.environment ?? process.env;
72
- const resolved = await resolveHostedInput(input, options, environment);
73
- const value = await context(options.target!, deps);
74
- const body = {
75
- label: 'zeroshot-cli',
76
- size: options.size ?? 'standard',
77
- intent: {
78
- version: RUN_INTENT_VERSION,
79
- credentials: {
80
- githubToken: githubToken(environment),
81
- openrouterApiKey: providerKey(environment),
82
- repository: resolved.repository,
83
- model: options.model ?? DEFAULT_MODEL,
84
- },
85
- request: resolved.request,
86
- },
87
- };
88
- if (Buffer.byteLength(JSON.stringify(body)) > MAX_RUN_INTENT_BYTES) {
89
- throw new Error('hosted run intent exceeds the 1088 KiB upload limit');
90
- }
91
- const submissionKey = options.submissionKey ?? crypto.randomUUID();
92
- let created: HostedRunIntent;
93
- try {
94
- created = await value.client.submit(body, submissionKey);
95
- } catch (error) {
96
- if (error instanceof HostedRunHttpError) throw error;
97
- throw new Error(
98
- `${error instanceof Error ? error.message : String(error)}. Recover this submission by rerunning ` +
99
- `the same command with --submission-key ${submissionKey}`,
100
- { cause: error }
101
- );
102
- }
103
- output(deps, `Run ${created.intent_id} queued`);
104
- output(deps, `Resume: ${resumeCommand(value, created.intent_id)}`);
105
- if (options.detach) return created;
106
- output(deps, 'Ctrl+C disconnects without cancelling.');
107
- return follow(value, created, deps);
108
- }
109
-
110
- export async function statusHostedRun(
111
- targetName: string,
112
- intentId: string,
113
- shouldFollow: boolean,
114
- deps: HostedRunDependencies
115
- ): Promise<HostedRunIntent | Record<string, unknown> | null> {
116
- if (!UUID.test(intentId)) throw new Error('run intent id must be a UUID');
117
- const value = await context(targetName, deps);
118
- const intent = await value.client.get(intentId);
119
- if (!shouldFollow) {
120
- output(deps, JSON.stringify(intent, null, 2));
121
- return intent;
122
- }
123
- if (!TERMINAL_STATES.has(intent.state)) {
124
- output(deps, `Following ${intentId}; Ctrl+C disconnects without cancelling.`);
125
- output(deps, `Resume: ${resumeCommand(value, intentId)}`);
126
- }
127
- return follow(value, intent, deps);
128
- }
129
-
130
- export async function cancelHostedRun(
131
- targetName: string,
132
- intentId: string,
133
- deps: HostedRunDependencies
134
- ): Promise<HostedRunIntent> {
135
- if (!UUID.test(intentId)) throw new Error('run intent id must be a UUID');
136
- const value = await context(targetName, deps);
137
- const intent = await value.client.cancel(intentId);
138
- output(deps, `Run ${intent.intent_id}: ${displayState(intent)}`);
139
- return intent;
140
- }
@@ -1,53 +0,0 @@
1
- // Shared hosted-run command contracts.
2
-
3
- import type { SettingsPort } from '../target-registry.ts';
4
-
5
- export interface HostedOptions {
6
- readonly target?: string;
7
- readonly repository?: string;
8
- readonly model?: string;
9
- readonly size?: string;
10
- readonly submissionKey?: string;
11
- readonly detach?: boolean;
12
- readonly pr?: boolean;
13
- readonly provider?: string;
14
- readonly config?: string;
15
- readonly docker?: boolean;
16
- readonly worktree?: boolean;
17
- readonly dockerImage?: string;
18
- readonly strictSchema?: boolean;
19
- readonly ship?: boolean;
20
- readonly prBase?: string;
21
- readonly mergeQueue?: boolean;
22
- readonly closeIssue?: string;
23
- readonly workers?: number;
24
- readonly gitlab?: boolean;
25
- readonly jira?: boolean;
26
- readonly devops?: boolean;
27
- readonly linear?: boolean;
28
- readonly mount?: readonly string[];
29
- readonly noMounts?: boolean;
30
- readonly containerHome?: string;
31
- }
32
-
33
- export interface HostedRunIntent {
34
- readonly intent_id: string;
35
- readonly state: string;
36
- readonly waiting_reason: string | null;
37
- readonly result: Record<string, unknown> | null;
38
- readonly error_code: string | null;
39
- readonly [key: string]: unknown;
40
- }
41
-
42
- export interface HostedRunDependencies {
43
- readonly settings: SettingsPort;
44
- readonly environment?: NodeJS.ProcessEnv;
45
- readonly fetch?: typeof globalThis.fetch;
46
- readonly delay?: (milliseconds: number) => Promise<void>;
47
- readonly stdout?: { write(value: string): void };
48
- }
49
-
50
- export interface ResolvedInput {
51
- readonly repository: string;
52
- readonly request: Record<string, unknown>;
53
- }
@@ -1,199 +0,0 @@
1
- import fs from 'node:fs';
2
- import path from 'node:path';
3
- import { execFileSync } from 'node:child_process';
4
-
5
- import type { HostedOptions, ResolvedInput } from './contracts.ts';
6
-
7
- const SUBMISSION_KEY = /^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{12}$/i;
8
- const CAPSULE_SIZES = new Set(['tiny', 'small', 'standard', 'large']);
9
-
10
- function validRepository(value: string): boolean {
11
- if (!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(value)) return false;
12
- return value.split('/').every((segment) => segment !== '.' && segment !== '..');
13
- }
14
-
15
- function validModel(value: string): boolean {
16
- return (
17
- value.length <= 256 && /^[A-Za-z0-9][A-Za-z0-9._-]*\/[A-Za-z0-9][A-Za-z0-9._:-]*$/.test(value)
18
- );
19
- }
20
-
21
- function repositoryFromRemote(cwd = process.cwd()): string | null {
22
- let remote: string;
23
- try {
24
- remote = execFileSync('git', ['remote', 'get-url', 'origin'], {
25
- cwd,
26
- encoding: 'utf8',
27
- stdio: ['ignore', 'pipe', 'ignore'],
28
- }).trim();
29
- } catch {
30
- return null;
31
- }
32
- const match = remote.match(
33
- /^(?:git@github\.com:|ssh:\/\/git@github\.com\/|https?:\/\/github\.com\/)([^/]+\/[^/]+?)(?:\.git)?$/
34
- );
35
- const repository = match?.[1];
36
- return repository && validRepository(repository) ? repository : null;
37
- }
38
-
39
- function isolationProfile(options: HostedOptions): string {
40
- return options.pr ? 'isolation.pr@1' : 'isolation.worktree@1';
41
- }
42
-
43
- function providerProfile(options: HostedOptions): string {
44
- return options.pr ? 'provider.codex-openrouter-pr@1' : 'provider.codex-openrouter@1';
45
- }
46
-
47
- function promptRequest(prompt: string, options: HostedOptions): Record<string, unknown> {
48
- return {
49
- source: 'prompt',
50
- prompt,
51
- artifacts: [],
52
- isolationProfile: isolationProfile(options),
53
- providerProfile: providerProfile(options),
54
- };
55
- }
56
-
57
- function issueRequest(issue: string, options: HostedOptions): Record<string, unknown> {
58
- return {
59
- source: 'issue',
60
- issue,
61
- artifacts: [],
62
- isolationProfile: isolationProfile(options),
63
- providerProfile: providerProfile(options),
64
- };
65
- }
66
-
67
- function issueInput(value: string, options: HostedOptions): ResolvedInput | null {
68
- const shorthand = value.match(/^([A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+)#([1-9][0-9]*)$/);
69
- if (shorthand?.[1] && shorthand[2] && validRepository(shorthand[1])) {
70
- const issue = `https://github.com/${shorthand[1]}/issues/${shorthand[2]}`;
71
- return { repository: shorthand[1], request: issueRequest(issue, options) };
72
- }
73
- let url: URL;
74
- try {
75
- url = new URL(value);
76
- } catch {
77
- return null;
78
- }
79
- const match = url.pathname.match(/^\/([^/]+)\/([^/]+)\/issues\/([1-9][0-9]*)\/?$/);
80
- const repository = match?.[1] && match[2] ? `${match[1]}/${match[2]}` : '';
81
- if (url.hostname !== 'github.com' || !match || !validRepository(repository)) return null;
82
- return { repository, request: issueRequest(url.href, options) };
83
- }
84
-
85
- async function readStdin(): Promise<string> {
86
- if (process.stdin.isTTY) throw new Error('zeroshot run - requires piped input');
87
- const chunks: Buffer[] = [];
88
- let bytes = 0;
89
- for await (const chunk of process.stdin) {
90
- const value = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
91
- bytes += value.length;
92
- if (bytes > 1024 * 1024) throw new Error('hosted task input exceeds 1 MiB');
93
- chunks.push(value);
94
- }
95
- const value = Buffer.concat(chunks).toString('utf8').trim();
96
- if (!value) throw new Error('hosted task input is empty');
97
- return value;
98
- }
99
-
100
- function readTaskFile(filename: string): string | null {
101
- const flags =
102
- fs.constants.O_RDONLY | (fs.constants.O_NOFOLLOW ?? 0) | (fs.constants.O_NONBLOCK ?? 0);
103
- let descriptor: number;
104
- try {
105
- descriptor = fs.openSync(filename, flags);
106
- } catch (error) {
107
- const code = (error as NodeJS.ErrnoException).code;
108
- if (code === 'ENOENT' || code === 'ENOTDIR' || code === 'EISDIR') return null;
109
- if (code === 'ELOOP') throw new Error(`hosted task file must not be a symlink: ${filename}`);
110
- throw error;
111
- }
112
- try {
113
- if (!fs.fstatSync(descriptor).isFile()) return null;
114
- return fs.readFileSync(descriptor, 'utf8');
115
- } finally {
116
- fs.closeSync(descriptor);
117
- }
118
- }
119
-
120
- export async function resolveHostedInput(
121
- input: string,
122
- options: HostedOptions,
123
- environment: NodeJS.ProcessEnv = process.env
124
- ): Promise<ResolvedInput> {
125
- const explicitIssue = issueInput(input, options);
126
- if (explicitIssue) return explicitIssue;
127
- const repository =
128
- options.repository ?? environment['ZEROSHOT_REPOSITORY'] ?? repositoryFromRemote();
129
- if (!validRepository(repository ?? '')) {
130
- throw new Error(
131
- 'hosted runs need a GitHub repository; use org/repo#123, --repository owner/name, ' +
132
- 'ZEROSHOT_REPOSITORY, or run inside a GitHub checkout'
133
- );
134
- }
135
- if (/^[1-9][0-9]*$/.test(input)) {
136
- return { repository: repository!, request: issueRequest(input, options) };
137
- }
138
- const prompt = input === '-' ? await readStdin() : (readTaskFile(path.resolve(input)) ?? input);
139
- if (!prompt.trim()) throw new Error('hosted task input is empty');
140
- return { repository: repository!, request: promptRequest(prompt.trim(), options) };
141
- }
142
-
143
- export function githubToken(environment: NodeJS.ProcessEnv): string {
144
- const configured = environment['GH_TOKEN'] ?? environment['GITHUB_TOKEN'];
145
- if (configured?.trim()) return configured.trim();
146
- try {
147
- const token = execFileSync('gh', ['auth', 'token'], {
148
- encoding: 'utf8',
149
- stdio: ['ignore', 'pipe', 'ignore'],
150
- }).trim();
151
- if (token) return token;
152
- } catch {
153
- // The actionable error below covers missing and unauthenticated gh alike.
154
- }
155
- throw new Error('hosted runs require GH_TOKEN/GITHUB_TOKEN or an authenticated gh CLI');
156
- }
157
-
158
- export function providerKey(environment: NodeJS.ProcessEnv): string {
159
- const key = environment['OPENROUTER_API_KEY'];
160
- if (!key?.trim()) throw new Error('hosted Codex runs require OPENROUTER_API_KEY');
161
- return key.trim();
162
- }
163
-
164
- export function validateHostedOptions(options: HostedOptions): void {
165
- const unsupported: ReadonlyArray<readonly [keyof HostedOptions, string]> = [
166
- ['config', '--config'],
167
- ['docker', '--docker'],
168
- ['worktree', '--worktree'],
169
- ['dockerImage', '--docker-image'],
170
- ['strictSchema', '--strict-schema'],
171
- ['ship', '--ship'],
172
- ['prBase', '--pr-base'],
173
- ['mergeQueue', '--merge-queue'],
174
- ['closeIssue', '--close-issue'],
175
- ['workers', '--workers'],
176
- ['gitlab', '--gitlab'],
177
- ['jira', '--jira'],
178
- ['devops', '--devops'],
179
- ['linear', '--linear'],
180
- ['mount', '--mount'],
181
- ['noMounts', '--no-mounts'],
182
- ['containerHome', '--container-home'],
183
- ];
184
- const selected = unsupported
185
- .filter(([name]) => options[name] !== undefined && options[name] !== false)
186
- .map(([, flag]) => flag);
187
- if (options.provider && options.provider !== 'codex') selected.push('--provider');
188
- if (selected.length) throw new Error(`hosted runs do not support ${selected.join(', ')}`);
189
- if (!options.target) throw new Error('hosted runs require --target');
190
- if (options.model !== undefined && !validModel(options.model)) {
191
- throw new Error('hosted runs require an exact provider/model slug');
192
- }
193
- if (!CAPSULE_SIZES.has(options.size ?? 'standard')) {
194
- throw new Error('hosted runs require --size tiny, small, standard, or large');
195
- }
196
- if (options.submissionKey !== undefined && !SUBMISSION_KEY.test(options.submissionKey)) {
197
- throw new Error('hosted runs require --submission-key to be a random UUID');
198
- }
199
- }
@@ -1,8 +0,0 @@
1
- export { HostedRunHttpError } from './hosted-run/client.ts';
2
- export { cancelHostedRun, runHosted, statusHostedRun } from './hosted-run/commands.ts';
3
- export { resolveHostedInput, validateHostedOptions } from './hosted-run/input.ts';
4
- export type {
5
- HostedOptions,
6
- HostedRunDependencies,
7
- HostedRunIntent,
8
- } from './hosted-run/contracts.ts';