@orgsdk/cli 0.1.0 → 0.2.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 (271) hide show
  1. package/README.md +21 -7
  2. package/bin/orgsdk.mjs +1 -1
  3. package/dist/THIRD_PARTY_NOTICES.txt +278 -0
  4. package/dist/runtime/README.md +9 -7
  5. package/dist/runtime/cli.js +12 -13
  6. package/dist/runtime/client.js +79 -17
  7. package/dist/runtime/contract.js +39 -6
  8. package/dist/runtime/executor-configuration.js +1 -1
  9. package/dist/runtime/isolated-actions.js +4 -5
  10. package/dist/runtime/isolated-worker.js +5 -0
  11. package/dist/runtime/mcp/aliases.js +29 -0
  12. package/dist/runtime/mcp/client.js +239 -0
  13. package/dist/runtime/mcp/contract.js +57 -0
  14. package/dist/runtime/mcp/functions.js +40 -0
  15. package/dist/runtime/mcp/network.js +61 -0
  16. package/dist/runtime/mcp/schema-types.js +35 -0
  17. package/dist/runtime/mcp/transport.js +18 -0
  18. package/dist/runtime/project-data.js +1 -1
  19. package/dist/runtime/register-executor.js +23 -0
  20. package/dist/runtime/runner.js +30 -24
  21. package/dist/runtime/sdk-declarations.js +8 -1
  22. package/dist/runtime/session-job-contract.js +29 -0
  23. package/dist/runtime/session-job.js +256 -0
  24. package/dist/runtime/session-plugin-call.js +33 -0
  25. package/dist/runtime/sessions/manager.js +5 -3
  26. package/dist/runtime/sessions/process.js +3 -3
  27. package/dist/runtime/sessions/session-runtime.js +7 -3
  28. package/dist/runtime/sessions/worker-guard.js +20 -0
  29. package/dist/runtime/spawn-job.js +69 -0
  30. package/dist/runtime/supervisor.js +102 -146
  31. package/dist/runtime/worker.js +48 -45
  32. package/dist/server/{bun-driver-JKOGHIVX.js → bun-driver-DTZUUCI3.js} +1 -1
  33. package/dist/server/{chunk-WCVBLUNL.js → chunk-S5SFX3JM.js} +24 -0
  34. package/dist/server/index.js +2628 -1230
  35. package/dist/server/migrations/0003_remote-mcp.sql +17 -0
  36. package/dist/server/migrations/meta/0003_snapshot.json +3395 -0
  37. package/dist/server/migrations/meta/_journal.json +7 -0
  38. package/dist/server/{node-driver-FRDSYDBU.js → node-driver-HDJKKWXQ.js} +1 -1
  39. package/dist/server/out/404/index.html +1 -1
  40. package/dist/server/out/404.html +1 -1
  41. package/dist/server/out/__next.!KHdvcmtzcGFjZSk.__PAGE__.txt +10 -10
  42. package/dist/server/out/__next._full.txt +10 -10
  43. package/dist/server/out/__next._tree.txt +2 -2
  44. package/dist/server/out/_next/static/chunks/0ay0b1lpy734z.js +1 -0
  45. package/dist/server/out/_next/static/chunks/0c-3k17txbh0-.js +1 -0
  46. package/dist/server/out/_next/static/chunks/0cwfl2xanfapu.js +1 -0
  47. package/dist/server/out/_next/static/chunks/0e7s8ie0wlk66.js +1 -0
  48. package/dist/server/out/_next/static/chunks/0ey-6hb0za4r_.js +1 -0
  49. package/dist/server/out/_next/static/chunks/0huhp5j8dlai8.js +1 -0
  50. package/dist/server/out/_next/static/chunks/0khjy8qh1ll42.js +1 -0
  51. package/dist/server/out/_next/static/chunks/0r0572w1rwpcv.js +1 -0
  52. package/dist/server/out/_next/static/chunks/0rlc9tihf4po6.css +1 -0
  53. package/dist/server/out/_next/static/chunks/0u_9k8f7709np.js +1 -0
  54. package/dist/server/out/_next/static/chunks/0w34iczo7r1v5.js +1 -0
  55. package/dist/server/out/_next/static/chunks/{280w168xxgtwt.js → 0y5lgqdwpeabb.js} +4 -4
  56. package/dist/server/out/_next/static/chunks/0zfiikazg0_ga.js +1 -0
  57. package/dist/server/out/_next/static/chunks/1-75euysc3lin.js +22 -0
  58. package/dist/server/out/_next/static/chunks/10aam78qxauw0.js +1 -0
  59. package/dist/server/out/_next/static/chunks/12ro_nqb83zku.js +1 -0
  60. package/dist/server/out/_next/static/chunks/19ue6x5c3f_38.js +3 -0
  61. package/dist/server/out/_next/static/chunks/1c1ayx3fqtub5.js +31 -0
  62. package/dist/server/out/_next/static/chunks/1c2xcwifk3vhh.js +1 -0
  63. package/dist/server/out/_next/static/chunks/1dwr62uuyceq-.js +1 -0
  64. package/dist/server/out/_next/static/chunks/1fweh1ttncdlv.js +1 -0
  65. package/dist/server/out/_next/static/chunks/1iklteprcoims.js +1 -0
  66. package/dist/server/out/_next/static/chunks/1qaow7bdy3oid.js +1 -0
  67. package/dist/server/out/_next/static/chunks/1tnzhqkfwk7l8.js +1 -0
  68. package/dist/server/out/_next/static/chunks/1wn9ohqcnx8y8.js +3 -0
  69. package/dist/server/out/_next/static/chunks/1zieh-zxgxmcp.js +1 -0
  70. package/dist/server/out/_next/static/chunks/25qsan0t-_of0.js +1 -0
  71. package/dist/server/out/_next/static/chunks/26yareaaj1kyr.js +1 -0
  72. package/dist/server/out/_next/static/chunks/2bkkmnhngpacd.js +1 -0
  73. package/dist/server/out/_next/static/chunks/2e39uy7huhczu.js +1 -0
  74. package/dist/server/out/_next/static/chunks/2lxgam-nk-e9a.js +3 -0
  75. package/dist/server/out/_next/static/chunks/{3dx108d0g6032.js → 2navy2mx7--vk.js} +1 -1
  76. package/dist/server/out/_next/static/chunks/2ngzwwqeitkk7.js +1 -0
  77. package/dist/server/out/_next/static/chunks/2rp65hq6bmpxv.js +1 -0
  78. package/dist/server/out/_next/static/chunks/2z60o39-yshg2.js +1 -0
  79. package/dist/server/out/_next/static/chunks/3_d6w25_b15kx.js +1 -0
  80. package/dist/server/out/_next/static/chunks/3d8gkwu9nszjk.js +1 -0
  81. package/dist/server/out/_next/static/chunks/3l-16g1y6k5rs.js +1 -0
  82. package/dist/server/out/_next/static/chunks/3obu_9-ka7u_h.js +1 -0
  83. package/dist/server/out/_next/static/chunks/3xs2ji0dgkbmc.js +1 -0
  84. package/dist/server/out/_next/static/chunks/{turbopack-3-ry682tkyiqk.js → turbopack-2u1d16houkiyo.js} +1 -1
  85. package/dist/server/out/_not-found/__next._full.txt +3 -3
  86. package/dist/server/out/_not-found/__next._not-found.__PAGE__.txt +3 -3
  87. package/dist/server/out/_not-found/__next._tree.txt +2 -2
  88. package/dist/server/out/_not-found/index.html +1 -1
  89. package/dist/server/out/_not-found/index.txt +3 -3
  90. package/dist/server/out/accounts/2fa/__next._full.txt +8 -8
  91. package/dist/server/out/accounts/2fa/__next._tree.txt +2 -2
  92. package/dist/server/out/accounts/2fa/__next.accounts.2fa.__PAGE__.txt +8 -8
  93. package/dist/server/out/accounts/2fa/index.html +1 -1
  94. package/dist/server/out/accounts/2fa/index.txt +8 -8
  95. package/dist/server/out/accounts/email/__next._full.txt +7 -7
  96. package/dist/server/out/accounts/email/__next._tree.txt +2 -2
  97. package/dist/server/out/accounts/email/__next.accounts.email.__PAGE__.txt +7 -7
  98. package/dist/server/out/accounts/email/index.html +1 -1
  99. package/dist/server/out/accounts/email/index.txt +7 -7
  100. package/dist/server/out/accounts/login/__next._full.txt +7 -7
  101. package/dist/server/out/accounts/login/__next._tree.txt +2 -2
  102. package/dist/server/out/accounts/login/__next.accounts.login.__PAGE__.txt +7 -7
  103. package/dist/server/out/accounts/login/index.html +1 -1
  104. package/dist/server/out/accounts/login/index.txt +7 -7
  105. package/dist/server/out/accounts/logout/__next._full.txt +7 -7
  106. package/dist/server/out/accounts/logout/__next._tree.txt +2 -2
  107. package/dist/server/out/accounts/logout/__next.accounts.logout.__PAGE__.txt +7 -7
  108. package/dist/server/out/accounts/logout/index.html +1 -1
  109. package/dist/server/out/accounts/logout/index.txt +7 -7
  110. package/dist/server/out/accounts/password/change/__next._full.txt +7 -7
  111. package/dist/server/out/accounts/password/change/__next._tree.txt +2 -2
  112. package/dist/server/out/accounts/password/change/__next.accounts.password.change.__PAGE__.txt +7 -7
  113. package/dist/server/out/accounts/password/change/index.html +1 -1
  114. package/dist/server/out/accounts/password/change/index.txt +7 -7
  115. package/dist/server/out/accounts/password/reset/__next._full.txt +5 -5
  116. package/dist/server/out/accounts/password/reset/__next._tree.txt +2 -2
  117. package/dist/server/out/accounts/password/reset/__next.accounts.password.reset.__PAGE__.txt +5 -5
  118. package/dist/server/out/accounts/password/reset/index.html +1 -1
  119. package/dist/server/out/accounts/password/reset/index.txt +5 -5
  120. package/dist/server/out/accounts/signup/__next._full.txt +7 -7
  121. package/dist/server/out/accounts/signup/__next._tree.txt +2 -2
  122. package/dist/server/out/accounts/signup/__next.accounts.signup.__PAGE__.txt +7 -7
  123. package/dist/server/out/accounts/signup/index.html +1 -1
  124. package/dist/server/out/accounts/signup/index.txt +7 -7
  125. package/dist/server/out/actions/__next.!KHdvcmtzcGFjZSk.actions.__PAGE__.txt +15 -15
  126. package/dist/server/out/actions/__next._full.txt +15 -15
  127. package/dist/server/out/actions/__next._tree.txt +2 -2
  128. package/dist/server/out/actions/index.html +1 -1
  129. package/dist/server/out/actions/index.txt +15 -15
  130. package/dist/server/out/agents/__next.!KHdvcmtzcGFjZSk.agents.__PAGE__.txt +8 -8
  131. package/dist/server/out/agents/__next._full.txt +8 -8
  132. package/dist/server/out/agents/__next._tree.txt +2 -2
  133. package/dist/server/out/agents/index.html +1 -1
  134. package/dist/server/out/agents/index.txt +8 -8
  135. package/dist/server/out/approvals/__next.!KHdvcmtzcGFjZSk.approvals.__PAGE__.txt +10 -10
  136. package/dist/server/out/approvals/__next._full.txt +10 -10
  137. package/dist/server/out/approvals/__next._tree.txt +2 -2
  138. package/dist/server/out/approvals/index.html +1 -1
  139. package/dist/server/out/approvals/index.txt +10 -10
  140. package/dist/server/out/artifacts/__next.!KHdvcmtzcGFjZSk.artifacts.__PAGE__.txt +12 -12
  141. package/dist/server/out/artifacts/__next._full.txt +12 -12
  142. package/dist/server/out/artifacts/__next._tree.txt +2 -2
  143. package/dist/server/out/artifacts/index.html +1 -1
  144. package/dist/server/out/artifacts/index.txt +12 -12
  145. package/dist/server/out/audit/__next.!KHdvcmtzcGFjZSk.audit.__PAGE__.txt +10 -10
  146. package/dist/server/out/audit/__next._full.txt +10 -10
  147. package/dist/server/out/audit/__next._tree.txt +2 -2
  148. package/dist/server/out/audit/index.html +1 -1
  149. package/dist/server/out/audit/index.txt +10 -10
  150. package/dist/server/out/chat/__next.!KHdvcmtzcGFjZSk.chat.__PAGE__.txt +8 -8
  151. package/dist/server/out/chat/__next._full.txt +8 -8
  152. package/dist/server/out/chat/__next._tree.txt +2 -2
  153. package/dist/server/out/chat/index.html +1 -1
  154. package/dist/server/out/chat/index.txt +8 -8
  155. package/dist/server/out/connections/__next.!KHdvcmtzcGFjZSk.connections.__PAGE__.txt +10 -10
  156. package/dist/server/out/connections/__next._full.txt +10 -10
  157. package/dist/server/out/connections/__next._tree.txt +2 -2
  158. package/dist/server/out/connections/index.html +1 -1
  159. package/dist/server/out/connections/index.txt +10 -10
  160. package/dist/server/out/credentials/__next.!KHdvcmtzcGFjZSk.credentials.__PAGE__.txt +11 -11
  161. package/dist/server/out/credentials/__next._full.txt +11 -11
  162. package/dist/server/out/credentials/__next._tree.txt +2 -2
  163. package/dist/server/out/credentials/index.html +1 -1
  164. package/dist/server/out/credentials/index.txt +11 -11
  165. package/dist/server/out/documents/__next.!KHdvcmtzcGFjZSk.documents.__PAGE__.txt +10 -10
  166. package/dist/server/out/documents/__next._full.txt +10 -10
  167. package/dist/server/out/documents/__next._tree.txt +2 -2
  168. package/dist/server/out/documents/index.html +1 -1
  169. package/dist/server/out/documents/index.txt +10 -10
  170. package/dist/server/out/index.html +1 -1
  171. package/dist/server/out/index.txt +10 -10
  172. package/dist/server/out/people/__next.!KHdvcmtzcGFjZSk.people.__PAGE__.txt +10 -10
  173. package/dist/server/out/people/__next._full.txt +10 -10
  174. package/dist/server/out/people/__next._tree.txt +2 -2
  175. package/dist/server/out/people/index.html +1 -1
  176. package/dist/server/out/people/index.txt +10 -10
  177. package/dist/server/out/plugins/__next.!KHdvcmtzcGFjZSk.plugins.__PAGE__.txt +13 -13
  178. package/dist/server/out/plugins/__next._full.txt +13 -13
  179. package/dist/server/out/plugins/__next._tree.txt +2 -2
  180. package/dist/server/out/plugins/index.html +1 -1
  181. package/dist/server/out/plugins/index.txt +13 -13
  182. package/dist/server/out/projects/__next.!KHdvcmtzcGFjZSk.projects.__PAGE__.txt +10 -10
  183. package/dist/server/out/projects/__next._full.txt +10 -10
  184. package/dist/server/out/projects/__next._tree.txt +2 -2
  185. package/dist/server/out/projects/index.html +1 -1
  186. package/dist/server/out/projects/index.txt +10 -10
  187. package/dist/server/out/runs/__next.!KHdvcmtzcGFjZSk.runs.__PAGE__.txt +12 -12
  188. package/dist/server/out/runs/__next._full.txt +12 -12
  189. package/dist/server/out/runs/__next._tree.txt +2 -2
  190. package/dist/server/out/runs/index.html +1 -1
  191. package/dist/server/out/runs/index.txt +12 -12
  192. package/dist/server/out/schedules/__next.!KHdvcmtzcGFjZSk.schedules.__PAGE__.txt +12 -12
  193. package/dist/server/out/schedules/__next._full.txt +12 -12
  194. package/dist/server/out/schedules/__next._tree.txt +2 -2
  195. package/dist/server/out/schedules/index.html +1 -1
  196. package/dist/server/out/schedules/index.txt +12 -12
  197. package/dist/server/out/settings/__next.!KHdvcmtzcGFjZSk.settings.__PAGE__.txt +10 -10
  198. package/dist/server/out/settings/__next._full.txt +10 -10
  199. package/dist/server/out/settings/__next._tree.txt +2 -2
  200. package/dist/server/out/settings/index.html +1 -1
  201. package/dist/server/out/settings/index.txt +10 -10
  202. package/dist/server/out/setup/__next._full.txt +7 -7
  203. package/dist/server/out/setup/__next._tree.txt +2 -2
  204. package/dist/server/out/setup/__next.setup.__PAGE__.txt +7 -7
  205. package/dist/server/out/setup/index.html +1 -1
  206. package/dist/server/out/setup/index.txt +7 -7
  207. package/dist/server/out/tables/__next.!KHdvcmtzcGFjZSk.tables.__PAGE__.txt +10 -10
  208. package/dist/server/out/tables/__next._full.txt +10 -10
  209. package/dist/server/out/tables/__next._tree.txt +2 -2
  210. package/dist/server/out/tables/index.html +1 -1
  211. package/dist/server/out/tables/index.txt +10 -10
  212. package/dist/server/out/webhooks/__next.!KHdvcmtzcGFjZSk.webhooks.__PAGE__.txt +10 -10
  213. package/dist/server/out/webhooks/__next._full.txt +10 -10
  214. package/dist/server/out/webhooks/__next._tree.txt +2 -2
  215. package/dist/server/out/webhooks/index.html +1 -1
  216. package/dist/server/out/webhooks/index.txt +10 -10
  217. package/dist/server/out/workspaces/invite/__next._full.txt +6 -6
  218. package/dist/server/out/workspaces/invite/__next._tree.txt +2 -2
  219. package/dist/server/out/workspaces/invite/__next.workspaces.invite.__PAGE__.txt +6 -6
  220. package/dist/server/out/workspaces/invite/index.html +1 -1
  221. package/dist/server/out/workspaces/invite/index.txt +6 -6
  222. package/docs/browser-sessions.md +85 -0
  223. package/docs/npm-distribution.md +13 -11
  224. package/docs/remote-mcp.md +51 -0
  225. package/package.json +53 -20
  226. package/runtime/README.md +9 -7
  227. package/dist/runtime/generated/schema.d.ts +0 -6443
  228. package/dist/server/out/THIRD_PARTY_NOTICES.md +0 -13
  229. package/dist/server/out/_next/static/chunks/016glzdsa3q5_.js +0 -1
  230. package/dist/server/out/_next/static/chunks/05i1qq0mw887k.js +0 -1
  231. package/dist/server/out/_next/static/chunks/06tt8wiyre1ez.js +0 -1
  232. package/dist/server/out/_next/static/chunks/0cm9i2msjsy--.js +0 -1
  233. package/dist/server/out/_next/static/chunks/0hq5dvj7fy64b.js +0 -1
  234. package/dist/server/out/_next/static/chunks/0ma4vl-fj0tmu.js +0 -1
  235. package/dist/server/out/_next/static/chunks/0noal-jqjivtf.js +0 -1
  236. package/dist/server/out/_next/static/chunks/0spckmsiek0gd.js +0 -1
  237. package/dist/server/out/_next/static/chunks/103sekujf0rxr.js +0 -1
  238. package/dist/server/out/_next/static/chunks/10h8kpcnjfe_v.js +0 -1
  239. package/dist/server/out/_next/static/chunks/16_aurf9162_6.js +0 -1
  240. package/dist/server/out/_next/static/chunks/1c48yx15nlt6w.js +0 -1
  241. package/dist/server/out/_next/static/chunks/1jp827_2p_wkf.js +0 -1
  242. package/dist/server/out/_next/static/chunks/1kdk-viqnjs3j.js +0 -1
  243. package/dist/server/out/_next/static/chunks/1mlfee105fhl7.js +0 -1
  244. package/dist/server/out/_next/static/chunks/1q9jpzm9b6zy9.js +0 -1
  245. package/dist/server/out/_next/static/chunks/1v0-a7pehktp9.js +0 -22
  246. package/dist/server/out/_next/static/chunks/24qxhh2dqvhaa.js +0 -1
  247. package/dist/server/out/_next/static/chunks/253gnn8ai3i89.js +0 -1
  248. package/dist/server/out/_next/static/chunks/27umf0z4povug.js +0 -1
  249. package/dist/server/out/_next/static/chunks/2a_c2xcjy62fq.css +0 -1
  250. package/dist/server/out/_next/static/chunks/2mvlvogrl6o0u.js +0 -1
  251. package/dist/server/out/_next/static/chunks/2xzrcwr9q6195.js +0 -1
  252. package/dist/server/out/_next/static/chunks/2yi6lq56xoijl.js +0 -31
  253. package/dist/server/out/_next/static/chunks/30g0jo299pr8e.js +0 -1
  254. package/dist/server/out/_next/static/chunks/36tf56rgybjz0.js +0 -3
  255. package/dist/server/out/_next/static/chunks/39dofrhzg_uju.js +0 -1
  256. package/dist/server/out/_next/static/chunks/3a8aanmz3kfof.js +0 -1
  257. package/dist/server/out/_next/static/chunks/3bd3k15tx3lj1.js +0 -1
  258. package/dist/server/out/_next/static/chunks/3d34pxerfr389.js +0 -1
  259. package/dist/server/out/_next/static/chunks/3elab9vgx7_ok.js +0 -1
  260. package/dist/server/out/_next/static/chunks/3gvae9c-5pi5z.js +0 -1
  261. package/dist/server/out/_next/static/chunks/3hzia782sc9pf.js +0 -1
  262. package/dist/server/out/_next/static/chunks/3jl4k-15i8847.js +0 -1
  263. package/dist/server/out/_next/static/chunks/3lb23el6qno6s.js +0 -1
  264. package/dist/server/out/_next/static/chunks/3prum3lr5470i.js +0 -3
  265. package/dist/server/out/_next/static/chunks/3prwkrciuqwjg.js +0 -1
  266. package/dist/server/out/_next/static/chunks/3txmqtuo5xgfd.js +0 -3
  267. package/dist/server/out/third-party-licenses/monaco-editor.txt +0 -21
  268. package/dist/server/out/third-party-licenses/zod.txt +0 -21
  269. /package/dist/server/out/_next/static/{F49bfPs3jKhcIuc95hqZh → -qfuCDzkIvBZY_UFsMHnB}/_buildManifest.js +0 -0
  270. /package/dist/server/out/_next/static/{F49bfPs3jKhcIuc95hqZh → -qfuCDzkIvBZY_UFsMHnB}/_clientMiddlewareManifest.js +0 -0
  271. /package/dist/server/out/_next/static/{F49bfPs3jKhcIuc95hqZh → -qfuCDzkIvBZY_UFsMHnB}/_ssgManifest.js +0 -0
@@ -7,6 +7,7 @@ import { projectFileFunctions } from "./project-files.js";
7
7
  import { z } from "zod";
8
8
  import { SandboxExecutor } from "./engine/sandbox/executor.js";
9
9
  import { loadPlugins } from "./plugins.js";
10
+ import { mcpPlugin } from "./mcp/functions.js";
10
11
  import {
11
12
  TRACE_LIMIT,
12
13
  TRACE_QUEUE_BYTES,
@@ -30,18 +31,18 @@ var Runner = class {
30
31
  events = Promise.resolve();
31
32
  async event(kind, data) {
32
33
  const pending = this.events.then(
33
- () => this.client.request(
34
- `/internal/execution/v1/runs/${this.job.run_id}/events/`,
35
- "POST",
36
- { sequence: ++this.sequence, kind, data }
37
- )
34
+ () => this.client.publishEvent(this.job.run_id, {
35
+ sequence: ++this.sequence,
36
+ kind,
37
+ data
38
+ })
38
39
  ).then(() => void 0);
39
40
  this.events = pending.catch(() => void 0);
40
41
  return pending;
41
42
  }
42
43
  async approval(prompt) {
43
44
  let approval = approvalSchema.parse(
44
- await this.client.product("approvals/", "POST", {
45
+ await this.client.createApproval({
45
46
  run: this.job.run_id,
46
47
  prompt
47
48
  })
@@ -53,15 +54,13 @@ var Runner = class {
53
54
  while (approval.status === "pending") {
54
55
  this.signal.throwIfAborted();
55
56
  await sleep(1e3);
56
- approval = approvalSchema.parse(
57
- await this.client.product(`approvals/${approval.id}/`)
58
- );
57
+ approval = approvalSchema.parse(await this.client.approval(approval.id));
59
58
  }
60
59
  if (approval.status !== "approved")
61
60
  throw new Error("Approval denied or interrupted");
62
61
  return true;
63
62
  }
64
- builtins(agent) {
63
+ builtins() {
65
64
  let fileFunctions;
66
65
  const files = ["readFile", "writeFile", "listFiles", "removeFile"].map(
67
66
  (name) => ({
@@ -91,23 +90,12 @@ var Runner = class {
91
90
  {
92
91
  name: "saveArtifact",
93
92
  calling: "positional",
94
- handler: (name, content) => this.client.product("artifacts/", "POST", {
93
+ handler: (name, content) => this.client.saveArtifact({
95
94
  run: this.job.run_id,
96
95
  name: z.string().parse(name),
97
96
  content: z.string().parse(content)
98
97
  })
99
98
  },
100
- ...agent.resources === void 0 && this.job.operation !== "code" ? [
101
- {
102
- name: "saveMemory",
103
- calling: "positional",
104
- handler: (title, content) => this.client.product("documents/", "POST", {
105
- kind: "memory",
106
- title: z.string().parse(title),
107
- content: z.string().parse(content)
108
- })
109
- }
110
- ] : [],
111
99
  {
112
100
  name: "delegate",
113
101
  calling: "positional",
@@ -134,10 +122,16 @@ var Runner = class {
134
122
  );
135
123
  }
136
124
  const executor = new SandboxExecutor();
137
- executor.registerBuiltins(this.builtins(agent));
125
+ executor.registerBuiltins(this.builtins());
126
+ const remote = agent.plugins.filter((plugin) => plugin.distribution === "mcp").map((plugin) => mcpPlugin(plugin, this.client, this.signal));
138
127
  executor.registerMultiple(
139
- await loadPlugins(agent.plugins, this.client, agent.id)
128
+ await loadPlugins(
129
+ agent.plugins.filter((plugin) => plugin.distribution !== "mcp"),
130
+ this.client,
131
+ agent.id
132
+ )
140
133
  );
134
+ executor.registerMultiple(remote.flatMap((entry) => entry.functions));
141
135
  let pending = Promise.resolve();
142
136
  let eventCount = 0;
143
137
  let eventBytes = 0;
@@ -192,6 +186,7 @@ var Runner = class {
192
186
  const output = result.result ?? null;
193
187
  return output;
194
188
  } finally {
189
+ await Promise.all(remote.map((entry) => entry.runtime.close()));
195
190
  let timer;
196
191
  let onAbort;
197
192
  try {
@@ -221,6 +216,17 @@ var Runner = class {
221
216
  "Unsupported operation: built-in chat has been retired; use external-client code or actions"
222
217
  );
223
218
  const agent = this.agent(this.job.snapshot.root_agent_id);
219
+ if (this.job.operation === "mcp_discover") {
220
+ const plugin = agent.plugins[0];
221
+ if (this.job.protocol_version !== 4 || !plugin || agent.plugins.length !== 1 || plugin.distribution !== "mcp" || !this.job.snapshot.mcp_discovery)
222
+ throw new Error("Invalid MCP discovery job");
223
+ const remote = mcpPlugin(plugin, this.client, this.signal);
224
+ try {
225
+ return await remote.runtime.discover();
226
+ } finally {
227
+ await remote.runtime.close();
228
+ }
229
+ }
224
230
  return this.action(
225
231
  agent,
226
232
  z.string().parse(this.job.snapshot.source),
@@ -1,5 +1,6 @@
1
1
  // src/sdk-declarations.ts
2
2
  import ts from "typescript";
3
+ import { schemaType } from "./mcp/schema-types.js";
3
4
  import {
4
5
  RESERVED_NAMESPACE_IDENTIFIERS,
5
6
  RESERVED_FUNCTION_KEYS
@@ -129,7 +130,7 @@ function pluginDeclaration(plugin) {
129
130
  if (plugin.available !== true || !safeIdentifier(namespace) || RESERVED_NAMESPACE_IDENTIFIERS.has(namespace) || builtinNames.has(namespace))
130
131
  return;
131
132
  const fallback = `const ${namespace}: Readonly<Record<string, (...args: unknown[]) => Promise<unknown>>>;`;
132
- if (plugin.metadata_complete !== true || !Array.isArray(plugin.tools) || plugin.tools.length > 100)
133
+ if (plugin.metadata_complete !== true || !Array.isArray(plugin.tools) || plugin.tools.length > 1e3)
133
134
  return fallback;
134
135
  const names = /* @__PURE__ */ new Set();
135
136
  const methods = [];
@@ -138,6 +139,12 @@ function pluginDeclaration(plugin) {
138
139
  if (!tool || !safeIdentifier(tool.name) || names.has(tool.name) || !Array.isArray(tool.parameters) || tool.parameters.length > 30)
139
140
  return fallback;
140
141
  names.add(tool.name);
142
+ if (plugin.kind === "mcp" && tool.inputSchema) {
143
+ methods.push(
144
+ `${tool.name}(args: ${schemaType(tool.inputSchema)}): Promise<{content?: Array<unknown>; structuredContent?: ${schemaType(tool.outputSchema)}; [key: string]: unknown}>`
145
+ );
146
+ continue;
147
+ }
141
148
  const isNamed = tool.calling === "named";
142
149
  const parameters = [];
143
150
  const parameterNames = /* @__PURE__ */ new Set();
@@ -0,0 +1,29 @@
1
+ // src/session-job-contract.ts
2
+ import { z } from "zod";
3
+ var sessionScopeSchema = z.object({
4
+ workspaceId: z.string().min(1).max(256),
5
+ projectId: z.uuid(),
6
+ ownerId: z.string().min(1).max(256)
7
+ });
8
+ var sessionCommandSchema = z.discriminatedUnion("operation", [
9
+ z.strictObject({ operation: z.literal("open") }),
10
+ z.strictObject({
11
+ operation: z.literal("execute"),
12
+ id: z.uuid(),
13
+ cellId: z.uuid(),
14
+ generation: z.number().int().positive(),
15
+ expectedSequence: z.number().int().nonnegative(),
16
+ after: z.number().int().nonnegative().optional()
17
+ }),
18
+ z.strictObject({ operation: z.literal("close"), id: z.uuid() }),
19
+ z.strictObject({
20
+ operation: z.literal("read"),
21
+ id: z.uuid(),
22
+ after: z.number().int().nonnegative().optional(),
23
+ limit: z.number().int().positive().max(10).optional()
24
+ })
25
+ ]);
26
+ export {
27
+ sessionCommandSchema,
28
+ sessionScopeSchema
29
+ };
@@ -0,0 +1,256 @@
1
+ // src/session-job.ts
2
+ import { join } from "node:path";
3
+ import { z } from "zod";
4
+ import { Client } from "./client.js";
5
+ import { withRetry } from "./engine/retry.js";
6
+ import { SessionManager } from "./sessions/index.js";
7
+ import { MAX_VALUE_BYTES } from "./sessions/values.js";
8
+ import { spawnJob } from "./spawn-job.js";
9
+ var sdkPluginSchema = z.object({
10
+ slug: z.string(),
11
+ available: z.literal(true),
12
+ namespace: z.string(),
13
+ tools: z.array(z.object({ name: z.string(), calling: z.literal("named") }))
14
+ });
15
+ var sdkSchema = z.object({ plugins: z.array(z.unknown()) });
16
+ var heartbeatSchema = z.object({
17
+ cancel_requested: z.boolean(),
18
+ status: z.string()
19
+ });
20
+ var toolOutputSchema = z.object({ result: z.json() });
21
+ var agentVolume = z.string().regex(/^[a-zA-Z0-9][a-zA-Z0-9_.-]*$/);
22
+ var SessionJobs = class {
23
+ constructor(options) {
24
+ this.options = options;
25
+ const { agentId, directory, mode } = options;
26
+ const volume = mode === "docker" && process.env.EXECUTOR_DATA_BIND !== "1" ? {
27
+ name: agentVolume.parse(process.env.EXECUTOR_DATA_VOLUME),
28
+ subpath: `agents/${agentId}/workspace`
29
+ } : void 0;
30
+ this.manager = new SessionManager({
31
+ mode,
32
+ historyDirectory: join(directory, "..", "..", "session-history", agentId),
33
+ image: process.env.EXECUTOR_IMAGE,
34
+ sourceDirectory: process.env.EXECUTOR_SOURCE_DIR,
35
+ workspaceVolume: volume
36
+ });
37
+ }
38
+ options;
39
+ manager;
40
+ authority;
41
+ activePluginCalls = 0;
42
+ functions(job) {
43
+ const plugins = job.snapshot.agents.find((entry) => entry.id === this.options.agentId)?.plugins ?? [];
44
+ const sdk = sdkSchema.parse(job.snapshot.sdk);
45
+ return sdk.plugins.flatMap((entry) => {
46
+ const parsed = sdkPluginSchema.safeParse(entry);
47
+ if (!parsed.success) return [];
48
+ const metadata = parsed.data;
49
+ const plugin = plugins.find((item) => item.slug === metadata.slug);
50
+ if (plugin?.distribution !== "mcp" && plugin?.distribution !== "external") {
51
+ return [];
52
+ }
53
+ return metadata.tools.map((tool) => ({
54
+ name: `${metadata.namespace}.${tool.name}`,
55
+ handler: (args, context) => {
56
+ if (!context.capability)
57
+ throw new Error("Missing active cell authority");
58
+ return this.pluginCall(
59
+ plugin,
60
+ tool.name,
61
+ args,
62
+ context.capability,
63
+ context.signal
64
+ );
65
+ }
66
+ }));
67
+ });
68
+ }
69
+ async pluginCall(plugin, name, args, capability, signal) {
70
+ const authority = this.authority;
71
+ if (authority?.job.capability !== capability) {
72
+ throw new Error("Missing active cell authority");
73
+ }
74
+ if (this.activePluginCalls >= 4) {
75
+ throw new Error(
76
+ "At most four plugin calls may run concurrently in a cell"
77
+ );
78
+ }
79
+ this.activePluginCalls++;
80
+ try {
81
+ await authority.check();
82
+ signal.throwIfAborted();
83
+ return await this.invokePlugin(plugin, name, args, capability, signal);
84
+ } finally {
85
+ this.activePluginCalls--;
86
+ }
87
+ }
88
+ async invokePlugin(plugin, name, args, capability, signal) {
89
+ if (args.length > 1) {
90
+ throw new Error(
91
+ "Plugin functions accept a single named arguments object"
92
+ );
93
+ }
94
+ const input = z.record(z.string(), z.json()).parse(args.length ? args[0] : {});
95
+ const { child, kill } = spawnJob(
96
+ { ...this.options, name: `orgsdk-session-tool-${crypto.randomUUID()}` },
97
+ "pipe"
98
+ );
99
+ signal.addEventListener("abort", kill, { once: true });
100
+ const exited = child.exited.catch(() => 1);
101
+ try {
102
+ child.stdin.end(
103
+ JSON.stringify({
104
+ type: "session_plugin_call",
105
+ agentId: this.options.agentId,
106
+ capability,
107
+ plugin,
108
+ name,
109
+ args: input
110
+ })
111
+ );
112
+ const chunks = [];
113
+ let bytes = 0;
114
+ for await (const chunk of child.stdout) {
115
+ const buffer = Buffer.from(chunk);
116
+ bytes += buffer.length;
117
+ if (bytes > MAX_VALUE_BYTES + 1024) {
118
+ throw new Error("Plugin function output exceeds session limit");
119
+ }
120
+ chunks.push(buffer);
121
+ }
122
+ const code = await exited;
123
+ signal.throwIfAborted();
124
+ if (code !== 0)
125
+ throw new Error(`Plugin function ${plugin.slug}.${name} failed`);
126
+ const output = Buffer.concat(chunks).toString("utf8").trim();
127
+ return toolOutputSchema.parse(JSON.parse(output.split("\n").at(-1) ?? "")).result;
128
+ } finally {
129
+ signal.removeEventListener("abort", kill);
130
+ kill();
131
+ await exited;
132
+ }
133
+ }
134
+ summary(history) {
135
+ return {
136
+ id: history.id,
137
+ generation: history.generation,
138
+ status: history.status,
139
+ cursor: history.cursor,
140
+ sequence: history.cells.length,
141
+ worker: history.worker
142
+ };
143
+ }
144
+ async execute(job, signal) {
145
+ const { session: command, session_scope: scope } = job.snapshot;
146
+ if (!command || !scope) throw new Error("Invalid session command");
147
+ const workspaceDirectory = join(this.options.directory, "workspace");
148
+ const revision = z.string().min(1).parse(job.snapshot.configuration_revision);
149
+ signal.throwIfAborted();
150
+ switch (command.operation) {
151
+ case "open": {
152
+ const history = await this.manager.open({
153
+ ...scope,
154
+ workspaceDirectory,
155
+ configurationRevision: revision,
156
+ functions: this.functions(job)
157
+ });
158
+ if (signal.aborted) {
159
+ await this.manager.close(history.id, scope);
160
+ signal.throwIfAborted();
161
+ }
162
+ return this.summary(history);
163
+ }
164
+ case "execute": {
165
+ const reply = await this.manager.execute(command.id, scope, {
166
+ id: command.cellId,
167
+ generation: command.generation,
168
+ expectedSequence: command.expectedSequence,
169
+ after: command.after,
170
+ source: z.string().parse(job.snapshot.source),
171
+ inputs: job.inputs,
172
+ capability: job.capability,
173
+ configurationRevision: revision,
174
+ signal,
175
+ limit: 10,
176
+ timeoutMs: Math.max(
177
+ 1,
178
+ Math.min(3e5, Date.parse(job.deadline) - Date.now())
179
+ )
180
+ });
181
+ const { cell, ...page } = reply;
182
+ const { source: _source, inputs: _inputs, ...result } = cell;
183
+ return { ...page, cell: result };
184
+ }
185
+ case "read": {
186
+ const history = await this.manager.inspect(command.id, scope);
187
+ const page = await this.manager.readEvents(command.id, scope, {
188
+ after: command.after,
189
+ limit: command.limit ?? 10
190
+ });
191
+ return { ...this.summary(history), ...page };
192
+ }
193
+ case "close":
194
+ return this.summary(await this.manager.close(command.id, scope));
195
+ }
196
+ }
197
+ async run(job, parentSignal) {
198
+ const controller = new AbortController();
199
+ const signal = AbortSignal.any([parentSignal, controller.signal]);
200
+ const client = new Client(this.options.base, job.capability, parentSignal);
201
+ const check = async () => {
202
+ try {
203
+ const state = heartbeatSchema.parse(await client.heartbeat(job.run_id));
204
+ if (state.cancel_requested || state.status !== "running")
205
+ controller.abort();
206
+ } catch {
207
+ controller.abort();
208
+ }
209
+ };
210
+ const timer = setInterval(() => void check(), 5e3);
211
+ const deadline = setTimeout(
212
+ () => controller.abort(),
213
+ Math.max(0, Date.parse(job.deadline) - Date.now())
214
+ );
215
+ this.authority = { job, check };
216
+ try {
217
+ let completion;
218
+ try {
219
+ await check();
220
+ const output = await this.execute(job, signal);
221
+ signal.throwIfAborted();
222
+ completion = { status: "succeeded", output: { result: output } };
223
+ } catch (error) {
224
+ completion = {
225
+ status: signal.aborted ? "cancelled" : "failed",
226
+ error: error instanceof Error ? error.message : "Session operation failed"
227
+ };
228
+ }
229
+ await withRetry(
230
+ () => client.complete(job.run_id, completion),
231
+ {
232
+ maxRetries: 2,
233
+ initialDelayMs: 200,
234
+ shouldRetry: (error) => !parentSignal.aborted && !/^API 4(?!29)\d\d:/.test(error.message)
235
+ }
236
+ );
237
+ } catch (error) {
238
+ if (!parentSignal.aborted) {
239
+ console.error(
240
+ `Session run ${job.run_id} completion was not acknowledged:`,
241
+ error instanceof Error ? error.message : "Unknown transport error"
242
+ );
243
+ }
244
+ } finally {
245
+ this.authority = void 0;
246
+ clearTimeout(deadline);
247
+ clearInterval(timer);
248
+ }
249
+ }
250
+ dispose() {
251
+ return this.manager.dispose();
252
+ }
253
+ };
254
+ export {
255
+ SessionJobs
256
+ };
@@ -0,0 +1,33 @@
1
+ // src/session-plugin-call.ts
2
+ import { z } from "zod";
3
+ import { loadPlugin } from "./plugins.js";
4
+ import { mcpPlugin } from "./mcp/functions.js";
5
+ import { pluginSchema } from "./contract.js";
6
+ import { jsonValue } from "./sessions/values.js";
7
+ var pluginCallSchema = z.object({
8
+ type: z.literal("session_plugin_call"),
9
+ agentId: z.uuid(),
10
+ capability: z.string(),
11
+ plugin: pluginSchema,
12
+ name: z.string().regex(/^[a-z][a-zA-Z0-9]*$/),
13
+ args: z.object({}).catchall(z.json())
14
+ });
15
+ async function executePluginCall(request, client) {
16
+ const { plugin, agentId, name, args } = request;
17
+ const remote = plugin.distribution === "mcp" ? mcpPlugin(plugin, client, client.signal ?? new AbortController().signal) : void 0;
18
+ try {
19
+ const functions = remote?.functions ?? await loadPlugin(plugin, client, agentId);
20
+ const fn = functions.find((entry) => entry.name === name);
21
+ if (!fn || fn.calling !== "named") {
22
+ throw new Error("Plugin function is unavailable");
23
+ }
24
+ const result = jsonValue(await fn.handler(args));
25
+ process.stdout.write(JSON.stringify({ result }) + "\n");
26
+ } finally {
27
+ await remote?.runtime.close();
28
+ }
29
+ }
30
+ export {
31
+ executePluginCall,
32
+ pluginCallSchema
33
+ };
@@ -30,7 +30,7 @@ var SessionManager = class {
30
30
  limits;
31
31
  sessions = /* @__PURE__ */ new Map();
32
32
  projects = /* @__PURE__ */ new Map();
33
- runtime(history, directory, events) {
33
+ runtime(history, directory, events, functions) {
34
34
  events ??= new SessionEvents(
35
35
  history,
36
36
  this.limits,
@@ -38,7 +38,7 @@ var SessionManager = class {
38
38
  );
39
39
  return new SessionRuntime(events, directory, {
40
40
  journal: this.journal,
41
- broker: this.broker,
41
+ broker: functions ? new FunctionBroker([...this.options.functions ?? [], ...functions]) : this.broker,
42
42
  limits: this.limits,
43
43
  options: this.options,
44
44
  release: (session) => {
@@ -72,7 +72,9 @@ var SessionManager = class {
72
72
  };
73
73
  const session = this.runtime(
74
74
  newHistory(scope, request.configurationRevision),
75
- request.workspaceDirectory
75
+ request.workspaceDirectory,
76
+ void 0,
77
+ request.functions
76
78
  );
77
79
  this.reserve(session);
78
80
  await session.start("session.opened");
@@ -10,7 +10,7 @@ import { errorText, jsonValue } from "./values.js";
10
10
  import { SessionError } from "./types.js";
11
11
  function sessionCommand(options) {
12
12
  if (options.mode === "host")
13
- return workerCommand(import.meta.url, "./worker");
13
+ return workerCommand(import.meta.url, "./worker-guard");
14
14
  for (const path of [
15
15
  options.workspaceDirectory,
16
16
  options.sourceDirectory
@@ -38,7 +38,7 @@ function sessionCommand(options) {
38
38
  "--user",
39
39
  `${process.getuid?.() || 1e3}:${process.getgid?.() || 1e3}`,
40
40
  "--mount",
41
- `type=bind,src=${options.workspaceDirectory},dst=/project/workspace`,
41
+ options.workspaceVolume ? `type=volume,src=${options.workspaceVolume.name},dst=/project/workspace,volume-subpath=${options.workspaceVolume.subpath}` : `type=bind,src=${options.workspaceDirectory},dst=/project/workspace`,
42
42
  ...options.sourceDirectory ? [
43
43
  "--mount",
44
44
  `type=bind,src=${options.sourceDirectory},dst=/executor/src,readonly`
@@ -49,7 +49,7 @@ function sessionCommand(options) {
49
49
  "bun",
50
50
  options.image ?? process.env.EXECUTOR_IMAGE ?? "orgsdk-job:dev",
51
51
  "--no-env-file",
52
- "/executor/src/sessions/worker.ts"
52
+ "/executor/src/sessions/worker-guard.ts"
53
53
  ];
54
54
  }
55
55
  var messageSchema = z.discriminatedUnion("type", [
@@ -47,7 +47,8 @@ var SessionRuntime = class {
47
47
  mode: options.mode ?? "docker",
48
48
  workspaceDirectory: this.workspaceDirectory,
49
49
  image: options.image,
50
- sourceDirectory: options.sourceDirectory
50
+ sourceDirectory: options.sourceDirectory,
51
+ workspaceVolume: options.workspaceVolume
51
52
  },
52
53
  this.workerHooks()
53
54
  );
@@ -140,8 +141,11 @@ var SessionRuntime = class {
140
141
  if (this.active) interruptCell(this.active.record, reason, this.events);
141
142
  this.history.closedAt = (/* @__PURE__ */ new Date()).toISOString();
142
143
  this.events.append(null, `session.${status}`, { reason });
143
- await this.save();
144
- this.services.release(this);
144
+ try {
145
+ await this.save();
146
+ } finally {
147
+ this.services.release(this);
148
+ }
145
149
  })();
146
150
  return this.finishing;
147
151
  }
@@ -0,0 +1,20 @@
1
+ // src/sessions/worker-guard.ts
2
+ import { spawnProcess, workerCommand } from "../process-runtime.js";
3
+ var worker = spawnProcess(workerCommand(import.meta.url, "./worker"), {
4
+ stdout: "pipe",
5
+ stderr: "ignore"
6
+ });
7
+ var stop = () => {
8
+ worker.kill("SIGKILL");
9
+ process.stdin.destroy();
10
+ };
11
+ process.stdin.on("data", (chunk) => worker.stdin.write(chunk));
12
+ process.stdin.once("end", stop);
13
+ process.stdin.once("error", stop);
14
+ process.stdout.once("error", stop);
15
+ worker.stdout.pipe(process.stdout, { end: false });
16
+ try {
17
+ process.exitCode = await worker.exited;
18
+ } finally {
19
+ process.stdin.destroy();
20
+ }
@@ -0,0 +1,69 @@
1
+ // src/spawn-job.ts
2
+ import { join } from "node:path";
3
+ import { z } from "zod";
4
+ import {
5
+ agentMountArguments,
6
+ developmentSourceArguments,
7
+ jobEnvironment
8
+ } from "./executor-configuration.js";
9
+ import {
10
+ spawnProcess,
11
+ stopHostProcess,
12
+ workerCommand
13
+ } from "./process-runtime.js";
14
+ function spawnJob(options, stdout = "ignore") {
15
+ const { base, agentId, directory, mode, name } = options;
16
+ const host = mode === "host";
17
+ const command = host ? workerCommand(import.meta.url, "./worker") : [
18
+ "docker",
19
+ "run",
20
+ "--add-host",
21
+ "host.docker.internal:host-gateway",
22
+ "--rm",
23
+ "-i",
24
+ "--name",
25
+ name,
26
+ "--network",
27
+ z.string().min(1).parse(process.env.EXECUTION_NETWORK),
28
+ "--read-only",
29
+ "--tmpfs",
30
+ "/tmp:rw,noexec,nosuid,size=128m",
31
+ "--cap-drop=ALL",
32
+ "--security-opt=no-new-privileges",
33
+ "--pids-limit=128",
34
+ "--memory=512m",
35
+ "--cpus=1",
36
+ "--user",
37
+ `${process.getuid?.() || 1e3}:${process.getgid?.() || 1e3}`,
38
+ ...agentMountArguments(agentId, directory),
39
+ ...developmentSourceArguments(),
40
+ "--workdir",
41
+ "/agent/workspace",
42
+ "-e",
43
+ `ORGSDK_SERVER_URL=${base}`,
44
+ "-e",
45
+ "EXECUTOR_AGENT_DIR=/agent",
46
+ z.string().min(1).parse(process.env.EXECUTOR_IMAGE)
47
+ ];
48
+ const child = spawnProcess(command, {
49
+ cwd: join(directory, "workspace"),
50
+ detached: host && process.platform !== "win32",
51
+ env: jobEnvironment(base, directory, host),
52
+ stdout,
53
+ stderr: "ignore"
54
+ });
55
+ const kill = () => {
56
+ if (host) {
57
+ stopHostProcess(child);
58
+ return;
59
+ }
60
+ void spawnProcess(["docker", "kill", name], {
61
+ stdout: "ignore",
62
+ stderr: "ignore"
63
+ }).exited.catch(() => void 0);
64
+ };
65
+ return { child, kill };
66
+ }
67
+ export {
68
+ spawnJob
69
+ };