@multiplayer-app/agent 0.1.20 → 0.1.22

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 (298) hide show
  1. package/README.md +14 -7
  2. package/dist/agent/definition.test.js +8 -3
  3. package/dist/agent/definition.test.js.map +1 -1
  4. package/dist/agent/profiles/coding.d.ts +1 -1
  5. package/dist/agent/profiles/coding.d.ts.map +1 -1
  6. package/dist/agent/profiles/coding.js +21 -4
  7. package/dist/agent/profiles/coding.js.map +1 -1
  8. package/dist/agent/profiles/index.js +1 -1
  9. package/dist/agent/profiles/index.js.map +1 -1
  10. package/dist/agent/profiles/research.d.ts.map +1 -1
  11. package/dist/agent/profiles/research.js +2 -2
  12. package/dist/agent/profiles/research.js.map +1 -1
  13. package/dist/agent/turn-history.d.ts.map +1 -1
  14. package/dist/agent/turn-history.js +7 -1
  15. package/dist/agent/turn-history.js.map +1 -1
  16. package/dist/agent/turn-runner.d.ts +8 -0
  17. package/dist/agent/turn-runner.d.ts.map +1 -1
  18. package/dist/agent/turn-runner.js +35 -10
  19. package/dist/agent/turn-runner.js.map +1 -1
  20. package/dist/app/app-host.d.ts +57 -0
  21. package/dist/app/app-host.d.ts.map +1 -0
  22. package/dist/app/app-host.js +252 -0
  23. package/dist/app/app-host.js.map +1 -0
  24. package/dist/app/app-host.test.d.ts +2 -0
  25. package/dist/app/app-host.test.d.ts.map +1 -0
  26. package/dist/app/app-host.test.js +639 -0
  27. package/dist/app/app-host.test.js.map +1 -0
  28. package/dist/app/build-log.d.ts +14 -0
  29. package/dist/app/build-log.d.ts.map +1 -0
  30. package/dist/app/build-log.js +173 -0
  31. package/dist/app/build-log.js.map +1 -0
  32. package/dist/app/build-log.test.d.ts +2 -0
  33. package/dist/app/build-log.test.d.ts.map +1 -0
  34. package/dist/app/build-log.test.js +255 -0
  35. package/dist/app/build-log.test.js.map +1 -0
  36. package/dist/app/config.d.ts +196 -0
  37. package/dist/app/config.d.ts.map +1 -0
  38. package/dist/app/config.js +362 -0
  39. package/dist/app/config.js.map +1 -0
  40. package/dist/app/config.test.d.ts +2 -0
  41. package/dist/app/config.test.d.ts.map +1 -0
  42. package/dist/app/config.test.js +224 -0
  43. package/dist/app/config.test.js.map +1 -0
  44. package/dist/app/detect.d.ts +68 -0
  45. package/dist/app/detect.d.ts.map +1 -0
  46. package/dist/app/detect.js +449 -0
  47. package/dist/app/detect.js.map +1 -0
  48. package/dist/app/detect.test.d.ts +2 -0
  49. package/dist/app/detect.test.d.ts.map +1 -0
  50. package/dist/app/detect.test.js +267 -0
  51. package/dist/app/detect.test.js.map +1 -0
  52. package/dist/app/env.d.ts +5 -0
  53. package/dist/app/env.d.ts.map +1 -0
  54. package/dist/app/env.js +22 -0
  55. package/dist/app/env.js.map +1 -0
  56. package/dist/app/functions-cli.d.ts +3 -0
  57. package/dist/app/functions-cli.d.ts.map +1 -0
  58. package/dist/app/functions-cli.js +27 -0
  59. package/dist/app/functions-cli.js.map +1 -0
  60. package/dist/app/functions-host.d.ts +15 -0
  61. package/dist/app/functions-host.d.ts.map +1 -0
  62. package/dist/app/functions-host.js +276 -0
  63. package/dist/app/functions-host.js.map +1 -0
  64. package/dist/app/functions-host.test.d.ts +2 -0
  65. package/dist/app/functions-host.test.d.ts.map +1 -0
  66. package/dist/app/functions-host.test.js +117 -0
  67. package/dist/app/functions-host.test.js.map +1 -0
  68. package/dist/app/functions-routes.d.ts +23 -0
  69. package/dist/app/functions-routes.d.ts.map +1 -0
  70. package/dist/app/functions-routes.js +85 -0
  71. package/dist/app/functions-routes.js.map +1 -0
  72. package/dist/app/functions-routes.test.d.ts +2 -0
  73. package/dist/app/functions-routes.test.d.ts.map +1 -0
  74. package/dist/app/functions-routes.test.js +40 -0
  75. package/dist/app/functions-routes.test.js.map +1 -0
  76. package/dist/app/manifest.d.ts +17 -0
  77. package/dist/app/manifest.d.ts.map +1 -0
  78. package/dist/app/manifest.js +64 -0
  79. package/dist/app/manifest.js.map +1 -0
  80. package/dist/app/manifest.test.d.ts +2 -0
  81. package/dist/app/manifest.test.d.ts.map +1 -0
  82. package/dist/app/manifest.test.js +173 -0
  83. package/dist/app/manifest.test.js.map +1 -0
  84. package/dist/app/release-artifacts.d.ts +43 -0
  85. package/dist/app/release-artifacts.d.ts.map +1 -0
  86. package/dist/app/release-artifacts.js +239 -0
  87. package/dist/app/release-artifacts.js.map +1 -0
  88. package/dist/app/release-artifacts.test.d.ts +2 -0
  89. package/dist/app/release-artifacts.test.d.ts.map +1 -0
  90. package/dist/app/release-artifacts.test.js +326 -0
  91. package/dist/app/release-artifacts.test.js.map +1 -0
  92. package/dist/app/route-pattern.d.ts +23 -0
  93. package/dist/app/route-pattern.d.ts.map +1 -0
  94. package/dist/app/route-pattern.js +339 -0
  95. package/dist/app/route-pattern.js.map +1 -0
  96. package/dist/app/route-pattern.test.d.ts +2 -0
  97. package/dist/app/route-pattern.test.d.ts.map +1 -0
  98. package/dist/app/route-pattern.test.js +187 -0
  99. package/dist/app/route-pattern.test.js.map +1 -0
  100. package/dist/app/rules.d.ts +61 -0
  101. package/dist/app/rules.d.ts.map +1 -0
  102. package/dist/app/rules.js +90 -0
  103. package/dist/app/rules.js.map +1 -0
  104. package/dist/app/rules.test.d.ts +2 -0
  105. package/dist/app/rules.test.d.ts.map +1 -0
  106. package/dist/app/rules.test.js +69 -0
  107. package/dist/app/rules.test.js.map +1 -0
  108. package/dist/app/runner.d.ts +109 -0
  109. package/dist/app/runner.d.ts.map +1 -0
  110. package/dist/app/runner.js +429 -0
  111. package/dist/app/runner.js.map +1 -0
  112. package/dist/app/site.d.ts +73 -0
  113. package/dist/app/site.d.ts.map +1 -0
  114. package/dist/app/site.js +161 -0
  115. package/dist/app/site.js.map +1 -0
  116. package/dist/app/site.test.d.ts +2 -0
  117. package/dist/app/site.test.d.ts.map +1 -0
  118. package/dist/app/site.test.js +291 -0
  119. package/dist/app/site.test.js.map +1 -0
  120. package/dist/app/static-server.d.ts +20 -0
  121. package/dist/app/static-server.d.ts.map +1 -0
  122. package/dist/app/static-server.js +145 -0
  123. package/dist/app/static-server.js.map +1 -0
  124. package/dist/persistence/conversation-store.d.ts +21 -0
  125. package/dist/persistence/conversation-store.d.ts.map +1 -0
  126. package/dist/persistence/conversation-store.js +59 -0
  127. package/dist/persistence/conversation-store.js.map +1 -0
  128. package/dist/persistence/conversation-store.test.d.ts +2 -0
  129. package/dist/persistence/conversation-store.test.d.ts.map +1 -0
  130. package/dist/persistence/conversation-store.test.js +98 -0
  131. package/dist/persistence/conversation-store.test.js.map +1 -0
  132. package/dist/persistence/git-sync.d.ts +14 -1
  133. package/dist/persistence/git-sync.d.ts.map +1 -1
  134. package/dist/persistence/git-sync.js +73 -17
  135. package/dist/persistence/git-sync.js.map +1 -1
  136. package/dist/persistence/git-sync.test.js +155 -6
  137. package/dist/persistence/git-sync.test.js.map +1 -1
  138. package/dist/persistence/snapshot-sync.d.ts +19 -2
  139. package/dist/persistence/snapshot-sync.d.ts.map +1 -1
  140. package/dist/persistence/snapshot-sync.js +194 -83
  141. package/dist/persistence/snapshot-sync.js.map +1 -1
  142. package/dist/persistence/snapshot-sync.test.js +145 -27
  143. package/dist/persistence/snapshot-sync.test.js.map +1 -1
  144. package/dist/persistence/workspace.d.ts +3 -0
  145. package/dist/persistence/workspace.d.ts.map +1 -1
  146. package/dist/persistence/workspace.js +1 -0
  147. package/dist/persistence/workspace.js.map +1 -1
  148. package/dist/research/extract-texts.d.ts.map +1 -1
  149. package/dist/research/extract-texts.js +6 -13
  150. package/dist/research/extract-texts.js.map +1 -1
  151. package/dist/research/filingramp/attachment-tools.d.ts.map +1 -1
  152. package/dist/research/filingramp/attachment-tools.js +7 -4
  153. package/dist/research/filingramp/attachment-tools.js.map +1 -1
  154. package/dist/research/filingramp/shared.d.ts.map +1 -1
  155. package/dist/research/filingramp/shared.js +5 -5
  156. package/dist/research/filingramp/shared.js.map +1 -1
  157. package/dist/runtime/app-mode.d.ts +10 -0
  158. package/dist/runtime/app-mode.d.ts.map +1 -0
  159. package/dist/runtime/app-mode.js +172 -0
  160. package/dist/runtime/app-mode.js.map +1 -0
  161. package/dist/runtime/app-mode.test.d.ts +2 -0
  162. package/dist/runtime/app-mode.test.d.ts.map +1 -0
  163. package/dist/runtime/app-mode.test.js +130 -0
  164. package/dist/runtime/app-mode.test.js.map +1 -0
  165. package/dist/runtime/app-rehearsal.d.ts +2 -0
  166. package/dist/runtime/app-rehearsal.d.ts.map +1 -0
  167. package/dist/runtime/app-rehearsal.js +56 -0
  168. package/dist/runtime/app-rehearsal.js.map +1 -0
  169. package/dist/runtime/build-mode.d.ts +18 -0
  170. package/dist/runtime/build-mode.d.ts.map +1 -0
  171. package/dist/runtime/build-mode.js +108 -0
  172. package/dist/runtime/build-mode.js.map +1 -0
  173. package/dist/runtime/build-mode.test.d.ts +2 -0
  174. package/dist/runtime/build-mode.test.d.ts.map +1 -0
  175. package/dist/runtime/build-mode.test.js +159 -0
  176. package/dist/runtime/build-mode.test.js.map +1 -0
  177. package/dist/runtime/cli.js +7 -2
  178. package/dist/runtime/cli.js.map +1 -1
  179. package/dist/runtime/config.d.ts +4 -0
  180. package/dist/runtime/config.d.ts.map +1 -1
  181. package/dist/runtime/config.js +13 -2
  182. package/dist/runtime/config.js.map +1 -1
  183. package/dist/runtime/guest-server.d.ts +3 -0
  184. package/dist/runtime/guest-server.d.ts.map +1 -0
  185. package/dist/runtime/{lambda-microvm.js → guest-server.js} +49 -18
  186. package/dist/runtime/guest-server.js.map +1 -0
  187. package/dist/runtime/image-hooks.d.ts +5 -0
  188. package/dist/runtime/image-hooks.d.ts.map +1 -0
  189. package/dist/runtime/image-hooks.js +68 -0
  190. package/dist/runtime/image-hooks.js.map +1 -0
  191. package/dist/runtime/image-hooks.test.d.ts +2 -0
  192. package/dist/runtime/image-hooks.test.d.ts.map +1 -0
  193. package/dist/runtime/image-hooks.test.js +74 -0
  194. package/dist/runtime/image-hooks.test.js.map +1 -0
  195. package/dist/runtime/index.d.ts +8 -3
  196. package/dist/runtime/index.d.ts.map +1 -1
  197. package/dist/runtime/index.js +53 -35
  198. package/dist/runtime/index.js.map +1 -1
  199. package/dist/runtime/listening-ports.d.ts +13 -0
  200. package/dist/runtime/listening-ports.d.ts.map +1 -0
  201. package/dist/runtime/listening-ports.js +78 -0
  202. package/dist/runtime/listening-ports.js.map +1 -0
  203. package/dist/runtime/listening-ports.test.d.ts +2 -0
  204. package/dist/runtime/listening-ports.test.d.ts.map +1 -0
  205. package/dist/runtime/listening-ports.test.js +39 -0
  206. package/dist/runtime/listening-ports.test.js.map +1 -0
  207. package/dist/runtime/preview-proxy.d.ts +56 -0
  208. package/dist/runtime/preview-proxy.d.ts.map +1 -0
  209. package/dist/runtime/preview-proxy.js +302 -0
  210. package/dist/runtime/preview-proxy.js.map +1 -0
  211. package/dist/runtime/preview-proxy.test.d.ts +2 -0
  212. package/dist/runtime/preview-proxy.test.d.ts.map +1 -0
  213. package/dist/runtime/preview-proxy.test.js +122 -0
  214. package/dist/runtime/preview-proxy.test.js.map +1 -0
  215. package/dist/runtime/session-mode.d.ts +3 -0
  216. package/dist/runtime/session-mode.d.ts.map +1 -0
  217. package/dist/runtime/session-mode.js +60 -0
  218. package/dist/runtime/session-mode.js.map +1 -0
  219. package/dist/runtime/workload.d.ts +44 -0
  220. package/dist/runtime/workload.d.ts.map +1 -0
  221. package/dist/runtime/workload.js +222 -0
  222. package/dist/runtime/workload.js.map +1 -0
  223. package/dist/runtime/workload.test.d.ts +2 -0
  224. package/dist/runtime/workload.test.d.ts.map +1 -0
  225. package/dist/runtime/workload.test.js +235 -0
  226. package/dist/runtime/workload.test.js.map +1 -0
  227. package/dist/session/conversation.d.ts +3 -2
  228. package/dist/session/conversation.d.ts.map +1 -1
  229. package/dist/session/conversation.js +11 -7
  230. package/dist/session/conversation.js.map +1 -1
  231. package/dist/session/conversation.test.js +2 -3
  232. package/dist/session/conversation.test.js.map +1 -1
  233. package/dist/session/runtime.d.ts +16 -3
  234. package/dist/session/runtime.d.ts.map +1 -1
  235. package/dist/session/runtime.js +80 -13
  236. package/dist/session/runtime.js.map +1 -1
  237. package/dist/session/runtime.test.js +18 -7
  238. package/dist/session/runtime.test.js.map +1 -1
  239. package/dist/session/tools.d.ts.map +1 -1
  240. package/dist/session/tools.js +3 -3
  241. package/dist/session/tools.js.map +1 -1
  242. package/dist/task/loop.d.ts.map +1 -1
  243. package/dist/task/loop.js +6 -4
  244. package/dist/task/loop.js.map +1 -1
  245. package/dist/tools/exec-tools.d.ts +12 -0
  246. package/dist/tools/exec-tools.d.ts.map +1 -1
  247. package/dist/tools/exec-tools.js +46 -3
  248. package/dist/tools/exec-tools.js.map +1 -1
  249. package/dist/tools/exec-tools.test.d.ts +2 -0
  250. package/dist/tools/exec-tools.test.d.ts.map +1 -0
  251. package/dist/tools/exec-tools.test.js +48 -0
  252. package/dist/tools/exec-tools.test.js.map +1 -0
  253. package/dist/tools/fs-tools.d.ts.map +1 -1
  254. package/dist/tools/fs-tools.js +5 -5
  255. package/dist/tools/fs-tools.js.map +1 -1
  256. package/dist/transport/link.d.ts.map +1 -1
  257. package/dist/transport/link.js +16 -5
  258. package/dist/transport/link.js.map +1 -1
  259. package/dist/transport/link.test.js +24 -0
  260. package/dist/transport/link.test.js.map +1 -1
  261. package/dist/transport/protocol.d.ts +215 -3
  262. package/dist/transport/protocol.d.ts.map +1 -1
  263. package/dist/transport/protocol.js +163 -7
  264. package/dist/transport/protocol.js.map +1 -1
  265. package/dist/transport/protocol.test.js +41 -0
  266. package/dist/transport/protocol.test.js.map +1 -1
  267. package/dist/workspace-sync/eligibility.d.ts +14 -0
  268. package/dist/workspace-sync/eligibility.d.ts.map +1 -0
  269. package/dist/workspace-sync/eligibility.js +53 -0
  270. package/dist/workspace-sync/eligibility.js.map +1 -0
  271. package/dist/workspace-sync/merge.d.ts +15 -0
  272. package/dist/workspace-sync/merge.d.ts.map +1 -0
  273. package/dist/workspace-sync/merge.js +66 -0
  274. package/dist/workspace-sync/merge.js.map +1 -0
  275. package/dist/workspace-sync/merge.test.d.ts +2 -0
  276. package/dist/workspace-sync/merge.test.d.ts.map +1 -0
  277. package/dist/workspace-sync/merge.test.js +28 -0
  278. package/dist/workspace-sync/merge.test.js.map +1 -0
  279. package/dist/workspace-sync/workspace-sync.d.ts +48 -0
  280. package/dist/workspace-sync/workspace-sync.d.ts.map +1 -0
  281. package/dist/workspace-sync/workspace-sync.js +308 -0
  282. package/dist/workspace-sync/workspace-sync.js.map +1 -0
  283. package/dist/workspace-sync/workspace-sync.test.d.ts +2 -0
  284. package/dist/workspace-sync/workspace-sync.test.d.ts.map +1 -0
  285. package/dist/workspace-sync/workspace-sync.test.js +111 -0
  286. package/dist/workspace-sync/workspace-sync.test.js.map +1 -0
  287. package/dist/workspace-sync/write-drafts.d.ts +24 -0
  288. package/dist/workspace-sync/write-drafts.d.ts.map +1 -0
  289. package/dist/workspace-sync/write-drafts.js +87 -0
  290. package/dist/workspace-sync/write-drafts.js.map +1 -0
  291. package/dist/workspace-sync/write-drafts.test.d.ts +2 -0
  292. package/dist/workspace-sync/write-drafts.test.d.ts.map +1 -0
  293. package/dist/workspace-sync/write-drafts.test.js +36 -0
  294. package/dist/workspace-sync/write-drafts.test.js.map +1 -0
  295. package/package.json +12 -2
  296. package/dist/runtime/lambda-microvm.d.ts +0 -3
  297. package/dist/runtime/lambda-microvm.d.ts.map +0 -1
  298. package/dist/runtime/lambda-microvm.js.map +0 -1
@@ -3,6 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LIVE_PREVIEW_GUIDANCE = void 0;
6
7
  exports.createExecTools = createExecTools;
7
8
  // Local equivalent of app-vm.tools.ts's runAppCommandTool — a direct child_process.exec
8
9
  // against the workspace, no RPC/session bridge (the agent already runs inside the VM).
@@ -11,7 +12,16 @@ const path_1 = __importDefault(require("path"));
11
12
  const ai_1 = require("ai");
12
13
  const zod_1 = require("zod");
13
14
  const tool_call_repair_1 = require("../tool-call-repair");
15
+ const protocol_1 = require("../transport/protocol");
16
+ const app_host_1 = require("../app/app-host");
17
+ const env_1 = require("../app/env");
18
+ const workload_1 = require("../runtime/workload");
19
+ const runner_1 = require("../app/runner");
14
20
  const MAX_OUTPUT_BYTES = 1024 * 1024;
21
+ /** How to run an app so the user can open it; shared by every coding prompt and these tools. */
22
+ exports.LIVE_PREVIEW_GUIDANCE = `To give the user a running web app or API, build an ordinary project that the platform detects the way Vercel does. Put every service in its own folder under packages/, even when there is only one, so another can be added beside it later: packages/web for the site or frontend (even a single page: packages/web/index.html), packages/api for the server, packages/<name> for anything else. Any backend, even a single endpoint, is its own service in packages/api: a small server with a start script, never code inside a frontend's folder. Each holds its own source, dependencies and lockfile and installs on its own, with no app or package.json at the workspace root. A script, document or data file that nothing serves needs no package. In a workspace that already has its own layout, keep to that layout. A service is a package.json with a framework (Next.js, Vite, Astro, SvelteKit, Nuxt, Create React App, Express, Fastify, Hono, Koa, NestJS) or with dev/build/start scripts, a Python app (main.py or app.py with FastAPI or Flask, and a requirements.txt), or static files with an index.html (in its folder or its public/). The web service answers at /, the api service at /api (give its routes that prefix, and call them from the frontend as /api/...), and any other at /<name>. Static files and a Vite app work below that name as they are, with relative links; another server gets the whole path, so its routes include /<name>, and any other framework needs its base path set (Next.js's basePath). Only when the user asks for serverless functions, a static site or Vite app can have them in an api/ folder of its own with no server, as on Vercel: packages/web/api/hello.js answers /api/hello, packages/web/api/users/[id].js answers /api/users/:id, each exporting \`default function handler(req, res)\` (with req.query, req.body, res.status, res.json) or a named \`GET\`/\`POST\` taking a Request and returning a Response; files and folders starting with _ are helpers. A server listens on 0.0.0.0 and the port in $PORT. Read configuration and secrets from environment variables and never write their values into a file: the user sets them on the project, a deployment gets them when it is built and when it runs, and this session's VM does not have them, so say which ones the app needs and give it a clear behaviour when one is missing. Building belongs in a build script and migrations in the server's own startup, never in a prestart script or a start script: a deployment builds once, then runs what was built with its start script alone. The platform installs and starts it after your turn and on every boot of the VM, serves it at the session's own URL (opening that URL wakes a stopped VM), and writes ${protocol_1.APP_CONFIG_FILE} with what it detected. That file then alone decides what runs. Never create or edit it unless the user asks to change how the app runs or the app lives where it is not detected; it has \`services\` (each with \`root\`, \`framework\`, \`installCommand\`, \`devCommand\`, \`buildCommand\`, \`startCommand\`, \`outputDirectory\`, or \`functions: { directory, path }\`), \`rewrites\` that send a path to a service (\`{ "source": "/api/(.*)", "destination": { "service": "api" } }\`, first match first) and \`daemons\`. Never start the app yourself in the background; call run_app instead to start it now, to restart it after installing packages, or to see why it fails. For a one-off process that is not the app, run it in the background with its output in a file, e.g. \`node worker.js > worker.log 2>&1 &\` (a bare \`nohup … &\` keeps the call open until it times out); any port works except 8080, 2222 and 8022, and every listening port gets a live preview URL of its own.`;
23
+ /** How long run_app waits for every service to listen or fail. */
24
+ const RUN_APP_WAIT_MS = 60000;
15
25
  /** Output kept in the conversation per stream; every later step re-sends it, so the rest belongs in a file. */
16
26
  const MAX_INLINE_OUTPUT_CHARS = 8000;
17
27
  const DEFAULT_TIMEOUT_MS = 60000;
@@ -28,7 +38,7 @@ function truncate(text) {
28
38
  }
29
39
  function createExecTools(workspaceDir) {
30
40
  const runCommandTool = (0, ai_1.tool)({
31
- description: "Run a shell command inside the session's workspace (npm install, build steps, starting a dev server). Returns exit code and captured output. For a long-lived process (a dev server), background it (e.g. `nohup npm run dev &`) so this call returns promptly — the live preview picks it up once it's listening on $PORT.",
41
+ description: `Run a shell command inside the session's workspace (npm install, build steps, starting a dev server). Returns exit code and captured output. Commands run as an unprivileged user: install dependencies inside the project (npm install, a Python venv), since system packages and global installs aren't available. ${exports.LIVE_PREVIEW_GUIDANCE}`,
32
42
  inputSchema: zod_1.z.object({
33
43
  // The chat shows this line instead of the command: users read what is being done, not shell syntax.
34
44
  description: zod_1.z
@@ -45,7 +55,17 @@ function createExecTools(workspaceDir) {
45
55
  const startedAt = Date.now();
46
56
  return new Promise((resolve) => {
47
57
  var _a;
48
- const child = (0, child_process_1.exec)(input.command, { cwd, timeout: (_a = input.timeoutMs) !== null && _a !== void 0 ? _a : DEFAULT_TIMEOUT_MS, maxBuffer: MAX_OUTPUT_BYTES * 2 }, (error, stdout, stderr) => {
58
+ const child = (0, child_process_1.exec)(input.command, {
59
+ cwd,
60
+ // As the unprivileged user, with what the session's app gets: none of the agent's own
61
+ // settings, so no model keys, FilingRamp credentials or VM token in a command the model wrote.
62
+ // $PORT for commands: the guest's own $PORT (8080) is the hook and preview server
63
+ // (runtime/preview-proxy.ts), so an app started on it would fail to bind.
64
+ ...(0, workload_1.workloadIdentity)(),
65
+ env: (0, workload_1.workloadEnv)({ ...(0, env_1.sessionAppEnv)(process.env), PORT: String(protocol_1.DEFAULT_APP_PORT) }),
66
+ timeout: (_a = input.timeoutMs) !== null && _a !== void 0 ? _a : DEFAULT_TIMEOUT_MS,
67
+ maxBuffer: MAX_OUTPUT_BYTES * 2,
68
+ }, (error, stdout, stderr) => {
49
69
  const durationMs = Date.now() - startedAt;
50
70
  const timedOut = Boolean((error === null || error === void 0 ? void 0 : error.killed) && error.signal === 'SIGTERM');
51
71
  const out = truncate(stdout);
@@ -68,6 +88,29 @@ function createExecTools(workspaceDir) {
68
88
  });
69
89
  },
70
90
  });
71
- return { run_command: runCommandTool };
91
+ const runAppTool = (0, ai_1.tool)({
92
+ description: `Start (or restart) the workspace's app as the platform detects it, with any overrides in ${protocol_1.APP_CONFIG_FILE}: installs its dependencies, then runs its dev server (a static site is served as it is). Waits up to a minute for it to listen or fail, and returns the detected framework, its status and the end of the log of anything that failed. ${exports.LIVE_PREVIEW_GUIDANCE}`,
93
+ inputSchema: zod_1.z.object({}),
94
+ execute: async () => {
95
+ var _a, _b;
96
+ const app = (0, app_host_1.appHostFor)(workspaceDir, () => ({ dir: workspaceDir, mode: 'dev', env: (0, env_1.sessionAppEnv)(process.env), schemaUrl: process.env[protocol_1.AGENT_ENV.APP_SCHEMA_URL] }));
97
+ const noApp = {
98
+ error: 'No app found in the workspace: add a package.json with a framework or a dev/start script, a Python app (main.py or app.py with FastAPI or Flask), or an index.html.',
99
+ };
100
+ if (!(await app.start()))
101
+ return noApp;
102
+ const status = await app.settled(RUN_APP_WAIT_MS);
103
+ if (!status)
104
+ return noApp;
105
+ const failedLogs = status.processes.filter((process) => process.state === 'crashed' && process.log).map((process) => process.log);
106
+ // An install or build failure names its log in the error.
107
+ const stepLog = (_b = /see (\S+\.log)$/.exec((_a = status.error) !== null && _a !== void 0 ? _a : '')) === null || _b === void 0 ? void 0 : _b[1];
108
+ const logs = {};
109
+ for (const log of stepLog ? [stepLog, ...failedLogs] : failedLogs)
110
+ logs[log] = await (0, runner_1.logTail)(workspaceDir, log);
111
+ return { ...status, ...(Object.keys(logs).length ? { logs } : {}) };
112
+ },
113
+ });
114
+ return { run_command: runCommandTool, run_app: runAppTool };
72
115
  }
73
116
  //# sourceMappingURL=exec-tools.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exec-tools.js","sourceRoot":"","sources":["../../src/tools/exec-tools.ts"],"names":[],"mappings":";;;;;AAwBA,0CAgDC;AAxED,wFAAwF;AACxF,uFAAuF;AACvF,iDAAoC;AACpC,gDAAuB;AACvB,2BAAyB;AACzB,6BAAuB;AACvB,0DAAyD;AAEzD,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,CAAA;AACpC,+GAA+G;AAC/G,MAAM,uBAAuB,GAAG,IAAK,CAAA;AACrC,MAAM,kBAAkB,GAAG,KAAM,CAAA;AAEjC,wFAAwF;AACxF,SAAS,QAAQ,CAAC,IAAY;IAC5B,IAAI,IAAI,CAAC,MAAM,IAAI,uBAAuB;QAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAA;IAC7E,MAAM,IAAI,GAAG,uBAAuB,GAAG,CAAC,CAAA;IACxC,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,GAAG,uBAAuB,CAAA;IACrD,OAAO;QACL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,CAAC,CAAA;YAC/G,OAAO,EAAE,GAAG,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAA;QACrE,CAAC;KACF,CAAC,CAAA;IAEF,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,OAAO,EAAE,UAAU,EAAE,CAAA;AAC7D,CAAC"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=exec-tools.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-tools.test.d.ts","sourceRoot":"","sources":["../../src/tools/exec-tools.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const strict_1 = __importDefault(require("node:assert/strict"));
7
+ const node_fs_1 = require("node:fs");
8
+ const node_os_1 = __importDefault(require("node:os"));
9
+ const node_path_1 = __importDefault(require("node:path"));
10
+ const node_test_1 = require("node:test");
11
+ const protocol_1 = require("../transport/protocol");
12
+ const exec_tools_1 = require("./exec-tools");
13
+ const AGENT_SETTINGS = [...Object.values(protocol_1.AGENT_ENV), 'AGENT_SSH_PUBLIC_KEYS_B64'];
14
+ (0, node_test_1.describe)('a command the model runs', () => {
15
+ const saved = { ...process.env };
16
+ let dir;
17
+ (0, node_test_1.beforeEach)(async () => {
18
+ dir = await node_fs_1.promises.mkdtemp(node_path_1.default.join(node_os_1.default.tmpdir(), 'exec-tools-'));
19
+ for (const name of AGENT_SETTINGS)
20
+ process.env[name] = `secret-of-${name}`;
21
+ process.env.MY_SETTING = 'kept';
22
+ });
23
+ (0, node_test_1.afterEach)(async () => {
24
+ process.env = { ...saved };
25
+ await node_fs_1.promises.rm(dir, { recursive: true, force: true });
26
+ });
27
+ const environment = async () => {
28
+ const run = (0, exec_tools_1.createExecTools)(dir).run_command.execute;
29
+ strict_1.default.ok(run);
30
+ const result = (await run({ description: 'List the environment', command: 'env' }, { toolCallId: 't', messages: [] }));
31
+ return result.stdout;
32
+ };
33
+ (0, node_test_1.it)('sees no model key, credential or VM token, though the runtime keeps them', async () => {
34
+ const output = await environment();
35
+ const names = output.split('\n').map((line) => line.split('=')[0]);
36
+ for (const name of AGENT_SETTINGS)
37
+ strict_1.default.ok(!names.includes(name), `${name} reached the command`);
38
+ strict_1.default.doesNotMatch(output, /secret-of-/);
39
+ strict_1.default.equal(process.env[protocol_1.AGENT_ENV.ACCESS_TOKEN], `secret-of-${protocol_1.AGENT_ENV.ACCESS_TOKEN}`);
40
+ });
41
+ (0, node_test_1.it)('still has what any command needs, and the port an app should bind', async () => {
42
+ const lines = (await environment()).split('\n');
43
+ strict_1.default.ok(lines.some((line) => line.startsWith('PATH=')));
44
+ strict_1.default.ok(lines.includes('MY_SETTING=kept'));
45
+ strict_1.default.ok(lines.includes(`PORT=${protocol_1.DEFAULT_APP_PORT}`));
46
+ });
47
+ });
48
+ //# sourceMappingURL=exec-tools.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"exec-tools.test.js","sourceRoot":"","sources":["../../src/tools/exec-tools.test.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AACvC,qCAAwC;AACxC,sDAAwB;AACxB,0DAA4B;AAC5B,yCAA+D;AAC/D,oDAAmE;AACnE,6CAA8C;AAE9C,MAAM,cAAc,GAAG,CAAC,GAAG,MAAM,CAAC,MAAM,CAAC,oBAAS,CAAC,EAAE,2BAA2B,CAAC,CAAA;AAEjF,IAAA,oBAAQ,EAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,MAAM,KAAK,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAA;IAChC,IAAI,GAAW,CAAA;IAEf,IAAA,sBAAU,EAAC,KAAK,IAA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,CAAC,CAAC,CAAC,CAAC,CAAA;QAClE,KAAK,MAAM,IAAI,IAAI,cAAc;YAAE,gBAAM,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,EAAE,GAAG,IAAI,sBAAsB,CAAC,CAAA;QAClG,gBAAM,CAAC,YAAY,CAAC,MAAM,EAAE,YAAY,CAAC,CAAA;QACzC,gBAAM,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,oBAAS,CAAC,YAAY,CAAC,EAAE,aAAa,oBAAS,CAAC,YAAY,EAAE,CAAC,CAAA;IAC1F,CAAC,CAAC,CAAA;IAEF,IAAA,cAAE,EAAC,mEAAmE,EAAE,KAAK,IAAI,EAAE;QACjF,MAAM,KAAK,GAAG,CAAC,MAAM,WAAW,EAAE,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QAC/C,gBAAM,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,CAAA;QACzD,gBAAM,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAA;QAC5C,gBAAM,CAAC,EAAE,CAAC,KAAK,CAAC,QAAQ,CAAC,QAAQ,2BAAgB,EAAE,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"fs-tools.d.ts","sourceRoot":"","sources":["../../src/tools/fs-tools.ts"],"names":[],"mappings":"AAmBA,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM;;;;;;;;;kBAiBf,MAAM;mBAAS,MAAM;;;;;;;;;;;;;;;;;;;EAmDvD"}
1
+ {"version":3,"file":"fs-tools.d.ts","sourceRoot":"","sources":["../../src/tools/fs-tools.ts"],"names":[],"mappings":"AAoBA,wBAAgB,aAAa,CAAC,YAAY,EAAE,MAAM;;;;;;;;;kBAiBf,MAAM;mBAAS,MAAM;;;;;;;;;;;;;;;;;;;EAkDvD"}
@@ -11,12 +11,13 @@ const fs_1 = require("fs");
11
11
  const path_1 = __importDefault(require("path"));
12
12
  const ai_1 = require("ai");
13
13
  const zod_1 = require("zod");
14
+ const workload_1 = require("../runtime/workload");
14
15
  /** Resolves a workspace-relative path, rejecting anything that would escape workspaceDir (../, absolute paths). */
15
16
  function resolveWorkspacePath(workspaceDir, relativePath) {
16
17
  const normalized = path_1.default.normalize(relativePath).replace(/^(\.\.(\/|\\|$))+/, '');
17
18
  const resolved = path_1.default.resolve(workspaceDir, normalized);
18
19
  const workspaceRoot = path_1.default.resolve(workspaceDir);
19
- if (resolved !== workspaceRoot && !resolved.startsWith(`${workspaceRoot}${path_1.default.sep}`)) {
20
+ if (!(0, workload_1.isInsideDir)(workspaceRoot, resolved)) {
20
21
  throw new Error(`path "${relativePath}" escapes the workspace directory`);
21
22
  }
22
23
  return resolved;
@@ -38,9 +39,8 @@ function createFsTools(workspaceDir) {
38
39
  const written = [];
39
40
  for (const file of input.files) {
40
41
  const target = resolveWorkspacePath(workspaceDir, file.path);
41
- await fs_1.promises.mkdir(path_1.default.dirname(target), { recursive: true });
42
42
  const buffer = Buffer.from(file.content, file.encoding === 'base64' ? 'base64' : 'utf8');
43
- await fs_1.promises.writeFile(target, buffer);
43
+ await (0, workload_1.writeWorkloadFile)(target, buffer);
44
44
  written.push({ path: file.path, bytes: buffer.byteLength });
45
45
  }
46
46
  return { written };
@@ -54,7 +54,7 @@ function createFsTools(workspaceDir) {
54
54
  }),
55
55
  execute: async (input) => {
56
56
  const target = resolveWorkspacePath(workspaceDir, input.path);
57
- const buffer = await fs_1.promises.readFile(target);
57
+ const buffer = await (0, workload_1.readInside)(workspaceDir, target);
58
58
  return { content: buffer.toString(input.encoding === 'base64' ? 'base64' : 'utf8'), bytes: buffer.byteLength };
59
59
  },
60
60
  });
@@ -68,7 +68,7 @@ function createFsTools(workspaceDir) {
68
68
  const target = resolveWorkspacePath(workspaceDir, (_a = input.path) !== null && _a !== void 0 ? _a : '.');
69
69
  let entries;
70
70
  try {
71
- entries = await fs_1.promises.readdir(target, { withFileTypes: true });
71
+ entries = await fs_1.promises.readdir(await (0, workload_1.realDirInside)(workspaceDir, target), { withFileTypes: true });
72
72
  }
73
73
  catch (error) {
74
74
  if (error.code === 'ENOENT')
@@ -1 +1 @@
1
- {"version":3,"file":"fs-tools.js","sourceRoot":"","sources":["../../src/tools/fs-tools.ts"],"names":[],"mappings":";;;;;AAmBA,sCAoEC;AAvFD,0FAA0F;AAC1F,8FAA8F;AAC9F,8FAA8F;AAC9F,2BAAgD;AAChD,gDAAuB;AACvB,2BAAyB;AACzB,6BAAuB;AAEvB,mHAAmH;AACnH,SAAS,oBAAoB,CAAC,YAAoB,EAAE,YAAoB;IACtE,MAAM,UAAU,GAAG,cAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,mBAAmB,EAAE,EAAE,CAAC,CAAA;IAChF,MAAM,QAAQ,GAAG,cAAI,CAAC,OAAO,CAAC,YAAY,EAAE,UAAU,CAAC,CAAA;IACvD,MAAM,aAAa,GAAG,cAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAA;IAChD,IAAI,QAAQ,KAAK,aAAa,IAAI,CAAC,QAAQ,CAAC,UAAU,CAAC,GAAG,aAAa,GAAG,cAAI,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC;QACtF,MAAM,IAAI,KAAK,CAAC,SAAS,YAAY,mCAAmC,CAAC,CAAA;IAC3E,CAAC;IACD,OAAO,QAAQ,CAAA;AACjB,CAAC;AAED,SAAgB,aAAa,CAAC,YAAoB;IAChD,MAAM,cAAc,GAAG,IAAA,SAAI,EAAC;QAC1B,WAAW,EACT,0MAA0M;QAC5M,WAAW,EAAE,OAAC,CAAC,MAAM,CAAC;YACpB,KAAK,EAAE,OAAC;iBACL,KAAK,CACJ,OAAC,CAAC,MAA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;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC/D,IAAI,CAAC,CAAC,EAAE,WAAW,GAAG,KAAK,GAAG,WAAW,CAAC,GAC1C,KAAK,GACL,KAAK,CAAA;AAET,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,mBAAmB,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAA;AAEnF,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;IAChC,SAAS,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,CAAA;IACxC,2FAA2F;IAC3F,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;IACtB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACvB;AAMD,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,MAAM,EACjB,SAAS,EAAE,MAAM,GAAG,SAAS,EAC7B,WAAW,EAAE,MAAM,GAAG,SAAS,EAC/B,OAAO,GAAE,OAAO,QAAmB,GAClC,WAAW,CAkGb"}
@@ -61,11 +61,17 @@ function createSessionLink(sessionId, socketUrl, socketToken, connect = socket_i
61
61
  // `ready` tells the platform this guest is live. It is sent once at startup, but the socket may
62
62
  // be down then (ready() also resolves on a connect error) or drop later and reconnect — a
63
63
  // fresh connection must re-announce it, or the platform keeps waiting. A new seq each time, so
64
- // the api's per-event de-duplication doesn't swallow the re-announcement.
64
+ // the api's per-event de-duplication doesn't swallow the re-announcement. The latest `ports`
65
+ // is re-announced after it the same way: the platform drops a session's ports with its VM state.
66
+ // So is the latest `app` status, which routes the session URL.
65
67
  let readyEvent;
68
+ let portsEvent;
69
+ let appEvent;
66
70
  socket.on('connect', () => {
67
- if (readyEvent)
68
- socket.emit(protocol_1.AGENT_SESSION_EVENT, stamp(sessionId, instanceId, ++seq, readyEvent));
71
+ for (const event of [readyEvent, portsEvent, appEvent]) {
72
+ if (event)
73
+ socket.emit(protocol_1.AGENT_SESSION_EVENT, stamp(sessionId, instanceId, ++seq, event));
74
+ }
69
75
  });
70
76
  socket.on('connect_error', (error) => console.error('[link] connect error:', error.message));
71
77
  socket.on('disconnect', (reason) => console.warn('[link] disconnected:', reason));
@@ -85,8 +91,13 @@ function createSessionLink(sessionId, socketUrl, socketToken, connect = socket_i
85
91
  });
86
92
  return {
87
93
  send(event) {
88
- if (event.type === 'ready') {
89
- readyEvent = event;
94
+ if (event.type === 'ready' || event.type === 'ports' || event.type === 'app') {
95
+ if (event.type === 'ready')
96
+ readyEvent = event;
97
+ else if (event.type === 'ports')
98
+ portsEvent = event;
99
+ else
100
+ appEvent = event;
90
101
  if (!socket.connected)
91
102
  return; // The next 'connect' announces it.
92
103
  }
@@ -1 +1 @@
1
- {"version":3,"file":"link.js","sourceRoot":"","sources":["../../src/transport/link.ts"],"names":[],"mappings":";;AAuCA,8CA+FC;AAtID,2FAA2F;AAC3F,qFAAqF;AACrF,2FAA2F;AAC3F,uFAAuF;AACvF,2FAA2F;AAC3F,uDAA8D;AAC9D,mCAAmC;AACnC,yCAMmB;AAEnB,4FAA4F;AAC5F,yDAAyD;AACzD,MAAM,cAAc,GAAG,GAAG,CAAA;AAkB1B,SAAS,KAAK,CAAC,SAAiB,EAAE,UAAkB,EAAE,GAAW,EAAE,KAAoB;IACrF,OAAO,EAAE,GAAG,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAuB,CAAA;AAC3G,CAAC;AAED,SAAgB,iBAAiB,CAC/B,SAAiB,EACjB,SAA6B,EAC7B,WAA+B,EAC/B,UAA2B,qBAAQ;IAEnC,IAAI,GAAG,GAAG,CAAC,CAAA;IACX,MAAM,UAAU,GAAG,IAAA,mBAAU,GAAE,CAAA;IAC/B,IAAI,OAAmC,CAAA;IAEvC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO;YACL,IAAI,CAAC,KAAK;gBACR,OAAO,CAAC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UAAU,EAAE,EAAE,GAAG,EAAE,KAAK,CAAC,CAAC,CAAA;QAC9E,CAAC;QACD,SAAS,CAAC,IAAI;YACZ,OAAO,GAAG,IAAI,CAAA;QAChB,CAAC;QACD,KAAK;YACH,OAAO,SAAS,CAAA;QAClB,CAAC;QACD,KAAK,CAAC,KAAK;YACT,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC,CAAA;YACnE,MAAM,CAAC,UAAU,EAAE,CAAA;QACrB,CAAC;KACF,CAAA;AACH,CAAC"}
@@ -60,4 +60,28 @@ const READY = { type: 'ready', mode: 'session', profile: 'research', restored: f
60
60
  link.send({ type: 'text_delta', messageId: 'm', text: 'hi' });
61
61
  strict_1.default.deepEqual(sent.map((event) => event.type), ['ready', 'text_delta']);
62
62
  });
63
+ (0, node_test_1.it)('re-announces the latest app status after ready, for the session URL', () => {
64
+ const { socket, sent, connect } = fakeSocket();
65
+ const link = (0, link_1.createSessionLink)('session-1', 'https://gw.example/v0/gapi/agent-sessions/ws', 'mp_tok_x', connect);
66
+ link.send(READY);
67
+ link.send({ type: 'app', app: { phase: 'installing', processes: [] } });
68
+ link.send({ type: 'app', app: { phase: 'running', processes: [] } });
69
+ socket.connectNow();
70
+ socket.drop();
71
+ socket.connectNow();
72
+ strict_1.default.deepEqual(sent.map((event) => event.type), ['ready', 'app', 'ready', 'app']);
73
+ strict_1.default.equal(sent[3].app.phase, 'running');
74
+ });
75
+ (0, node_test_1.it)('re-announces only the latest ports after ready on every reconnect', () => {
76
+ const { socket, sent, connect } = fakeSocket();
77
+ const link = (0, link_1.createSessionLink)('session-1', 'https://gw.example/v0/gapi/agent-sessions/ws', 'mp_tok_x', connect);
78
+ link.send(READY);
79
+ link.send({ type: 'ports', ports: [3000] });
80
+ link.send({ type: 'ports', ports: [3000, 5173] });
81
+ socket.connectNow();
82
+ socket.drop();
83
+ socket.connectNow();
84
+ strict_1.default.deepEqual(sent.map((event) => event.type), ['ready', 'ports', 'ready', 'ports']);
85
+ strict_1.default.deepEqual(sent[3].ports, [3000, 5173]);
86
+ });
63
87
  //# sourceMappingURL=link.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"link.test.js","sourceRoot":"","sources":["../../src/transport/link.test.ts"],"names":[],"mappings":";;;;;AAAA,gEAAuC;AACvC,6CAA0C;AAC1C,yCAA8B;AAE9B,iCAA0C;AAC1C,yCAAgD;AAKhD,SAAS,UAAU;IACjB,MAAM,IAAI,GAAgB,EAAE,CAAA;IAC5B,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,0BAAY,EAAE,EAAE;QAC/C,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,SAAoB;QAC7B,IAAI,CAAC,KAAa,EAAE,GAAG,IAAe;YACpC,IAAI,KAAK,KAAK,8BAAmB;gBAAE,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAc,CAAC,CAAA;YAClE,OAAO,IAAI,CAAA;QACb,CAAC;QACD,UAAU;YACR,MAAM,CAAC,SAAS,GAAG,IAAI,CAAA;YACvB,0BAAY,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;QACrD,CAAC;QACD,IAAI;YACF,MAAM,CAAC,SAAS,GAAG,KAAK,CAAA;YACxB,0BAAY,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,YAAY,EAAE,cAAc,CAAC,CAAA;QACxE,CAAC;QACD,UAAU,KAAI,CAAC;KAChB,CAAC,CAAA;IACF,MAAM,OAAO,GAAG,CAAC,CAAC,IAAY,EAAE,OAAgB,EAAE,EAAE;QAClD,MAAM,CAAC,OAAO,GAAG,OAAO,CAAA;QACxB,OAAO,MAAM,CAAA;IACf,CAAC,CAAyB,CAAA;IAC1B,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,EAAE,CAAA;AAClC,CAAC;A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U,EAAE,OAAO,CAAC,CAAA;IAChH,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IAChB,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IAC3C,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC,CAAA;IACjD,MAAM,CAAC,UAAU,EAAE,CAAA;IACnB,MAAM,CAAC,IAAI,EAAE,CAAA;IACb,MAAM,CAAC,UAAU,EAAE,CAAA;IACnB,gBAAM,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IACvF,gBAAM,CAAC,SAAS,CAAE,IAAI,CAAC,CAAC,CAAqC,CAAC,KAAK,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,CAAA;AACpF,CAAC,CAAC,CAAA"}
@@ -32,12 +32,17 @@ export interface AgentSessionFile {
32
32
  content: string;
33
33
  }
34
34
  export type AgentSessionCommand =
35
- /** A new user turn. `messageId` is the chat message id the platform already persisted. */
35
+ /**
36
+ * A new user turn. `messageId` is the chat message id the platform already persisted. `profile`
37
+ * is the kind of work it is — deep research, or building apps and code; without one the turn
38
+ * continues the previous turn's (an answer to its question, a "continue").
39
+ */
36
40
  {
37
41
  type: 'message';
38
42
  messageId: string;
39
43
  text: string;
40
44
  attachments?: AgentSessionAttachment[];
45
+ profile?: 'research' | 'coding';
41
46
  }
42
47
  /** Stop the running turn (the user pressed stop, or the session is being shut down). */
43
48
  | {
@@ -49,6 +54,22 @@ export type AgentSessionCommand =
49
54
  requestId?: string;
50
55
  waitForTurn?: boolean;
51
56
  onlyIfIdleForMs?: number;
57
+ }
58
+ /**
59
+ * Workspace live sync: the session's copy of `path` is now `content` (people edited it, or the
60
+ * guest's change was built on an older version), which the guest merges into its file. Without
61
+ * `content`, the session took the guest's own version `hash` as-is.
62
+ */
63
+ | {
64
+ type: 'file_state';
65
+ path: string;
66
+ hash: string;
67
+ content?: string;
68
+ }
69
+ /** Someone deleted `path` in the session. */
70
+ | {
71
+ type: 'file_delete';
72
+ path: string;
52
73
  };
53
74
  export interface AgentSessionCommandAck {
54
75
  ok: boolean;
@@ -117,12 +138,58 @@ export type AgentSessionEvent = BaseEvent & (
117
138
  messageId: string;
118
139
  usage: AgentUsage;
119
140
  }
120
- /** Text files to store as session artifacts. */
141
+ /** Text files to store as session artifacts (guests without workspace live sync). */
121
142
  | {
122
143
  type: 'files';
123
144
  messageId?: string;
124
145
  files: AgentSessionFile[];
125
146
  }
147
+ /**
148
+ * Workspace live sync (src/workspace-sync): a workspace text file changed. `base` is the
149
+ * workspaceFileHash of the session's version this content was built on — absent when the
150
+ * guest has none (a new file, or any file right after a restart). `final` ends a draft: the
151
+ * content replaces the drafted text as-is.
152
+ */
153
+ | {
154
+ type: 'file_changed';
155
+ path: string;
156
+ content: string;
157
+ base?: string;
158
+ final?: boolean;
159
+ } | {
160
+ type: 'file_deleted';
161
+ path: string;
162
+ }
163
+ /** What the model has written so far of a file it is still writing: shown live, not yet on disk. */
164
+ | {
165
+ type: 'file_draft';
166
+ path: string;
167
+ content: string;
168
+ }
169
+ /** The guest wrote the session's version `hash` of `path` (a file_state) to disk unchanged. */
170
+ | {
171
+ type: 'file_synced';
172
+ path: string;
173
+ hash: string;
174
+ }
175
+ /**
176
+ * Every TCP port something in the guest listens on, ascending (minus the guest's own
177
+ * GUEST_RESERVED_PORTS). Sent on startup, on every change and after a reconnect; the
178
+ * platform offers each one as a live preview.
179
+ */
180
+ | {
181
+ type: 'ports';
182
+ ports: number[];
183
+ }
184
+ /**
185
+ * The workspace's app (detected, with builder.json's overrides), as the guest runs it
186
+ * (src/app): sent on every change and after a reconnect; null once no app runs. Its URL
187
+ * routes through it.
188
+ */
189
+ | {
190
+ type: 'app';
191
+ app: AgentAppStatus | null;
192
+ }
126
193
  /** Conversation + workspace persisted (project Git commit or session snapshot). */
127
194
  | {
128
195
  type: 'checkpointed';
@@ -150,11 +217,152 @@ export type AgentSessionEvent = BaseEvent & (
150
217
  export type AgentSessionEventType = AgentSessionEvent['type'];
151
218
  export declare function agentSessionEventKey(event: AgentSessionEvent): string;
152
219
  export declare const AGENT_SESSION_EVENT_TYPES: readonly AgentSessionEventType[];
220
+ export declare const PREVIEW_PORT_HEADER: "x-builder-preview-port";
221
+ /**
222
+ * On what the gateway asks the api about a session's URL. A browser can't set it on a navigation, so
223
+ * a link to the api's route for that never runs a session's page on the api's own origin.
224
+ */
225
+ export declare const SESSION_SITE_HEADER: "x-builder-session-site";
226
+ /**
227
+ * Whether a URL path holds a dotfile or dot-folder at any depth (.env, .git, the platform's own
228
+ * .builder), or a `.`/`..` segment. An app's URL never serves one from its files; .well-known is
229
+ * the exception.
230
+ */
231
+ /**
232
+ * A request's target as a URL, to read its path and query. Anyone can send any target, and
233
+ * `new URL(target, base)` throws on `//` and reads `//host/path` as a host: this does neither,
234
+ * so leading slashes collapse as most servers treat them.
235
+ */
236
+ export declare function requestUrl(target: string | undefined): URL;
237
+ export declare function isHiddenSitePath(pathname: string): boolean;
238
+ /** The guest's own listeners: the hook/preview server, dropbear, and Lambda's shell agent. */
239
+ export declare const GUEST_RESERVED_PORTS: readonly number[];
240
+ /**
241
+ * The port apps are told to listen on ($PORT for the agent's commands). A session's own URL
242
+ * (<sessionId>.apps.<domain>) opens this one when it listens, else the lowest port that does.
243
+ */
244
+ export declare const DEFAULT_APP_PORT = 3000;
245
+ /**
246
+ * PREVIEW_PORT_HEADER's value for a session's own URL (no port in it): the guest picks the target
247
+ * itself, by the app's rewrites when the workspace holds one, else DEFAULT_APP_PORT or the
248
+ * lowest listening port. Never parsed from a hostname.
249
+ */
250
+ export declare const APP_PREVIEW_TARGET: "app";
251
+ /** A header value as a previewable port, or undefined. */
252
+ export declare function parsePreviewPort(value: unknown): number | undefined;
253
+ /** A PREVIEW_PORT_HEADER value: a previewable port, APP_PREVIEW_TARGET, or undefined. */
254
+ export declare function parsePreviewTarget(value: unknown): number | typeof APP_PREVIEW_TARGET | undefined;
255
+ /** The port a session's own URL opens without an app: DEFAULT_APP_PORT when it listens, else the lowest. */
256
+ export declare function defaultAppPort(ports: readonly number[]): number | undefined;
257
+ /**
258
+ * The app manifest, in the workspace's .builder folder; a session VM
259
+ * writes it. The one file of .builder that people see and edit as a session file.
260
+ */
261
+ export declare const APP_CONFIG_FILE: ".builder/builder.json";
262
+ /** Which of a session's stored files are executable: object storage keeps no mode. */
263
+ /**
264
+ * Where a session's conversation used to be saved, in its workspace and so in its branch. It's kept
265
+ * in the runtime's state directory now (persistence/conversation-store.ts), but repos still hold old
266
+ * copies: they stay off main when a session merges, and out of what a new session starts from.
267
+ */
268
+ export declare const SESSION_CONVERSATION_FILE = ".builder/conversation.json";
269
+ export declare const WORKSPACE_EXECUTABLES_FILE: ".builder/executables.json";
270
+ /** Dependencies and build output: saved with a workspace, but not files people open. */
271
+ export declare const WORKSPACE_GENERATED_DIRECTORIES: readonly string[];
272
+ /** Guest-only: a deployment's app status as JSON. `/internal/*` is never routed publicly. */
273
+ export declare const APP_STATUS_PATH: "/internal/app/status";
274
+ /** Asked of a build VM's APP_STATUS_PATH to get the end of its latest log too. */
275
+ export declare const APP_STATUS_WITH_LOG: "log=1";
276
+ /** What a running build has logged, on a build VM: `?cursor=` for what came after that. Answers AgentBuildLog. */
277
+ export declare const APP_BUILD_LOG_PATH: "/internal/app/build-log";
278
+ /** How much of each step's log a person gets: its end, where a failure is. The web app uses builder-types' copy. */
279
+ export declare const BUILD_LOG_BYTES: number;
280
+ /** How much of its latest log a release's record keeps, in case its VM dies before uploading them. */
281
+ export declare const BUILD_LOG_TAIL_BYTES: number;
282
+ /** The longest cursor the API accepts. readBuildLogs keeps every cursor it makes under this. */
283
+ export declare const MAX_BUILD_LOG_CURSOR_CHARS = 8192;
284
+ /** A build's logs in the order they ran: installing comes before any service's build, whatever it's called. */
285
+ export declare function compareBuildLogs(a: string, b: string): number;
286
+ /** A built release's record of what it holds; written last, so a release that has one is complete. */
287
+ export declare const RELEASE_MANIFEST_FILE: "manifest.json";
288
+ /** The compressed copies of a built release's static files, best first. */
289
+ export declare const SITE_ENCODINGS: readonly ["br", "gzip"];
290
+ export type SiteEncoding = (typeof SITE_ENCODINGS)[number];
291
+ /** What a built release's VM runs: its folders as they were built, dependencies and all. */
292
+ export declare const RELEASE_ARCHIVE_FILE: "run.tar.zst";
293
+ /** How far a release's build has got, on a build VM's APP_STATUS_PATH as `{ build }`. */
294
+ export type AgentBuildPhase = 'fetching' | 'installing' | 'building' | 'uploading' | 'done' | 'failed';
295
+ export interface BuildLogChunk {
296
+ /** The step's log file, such as install.log. */
297
+ name: string;
298
+ text: string;
299
+ }
300
+ /** What a running build logged since the cursor it was asked with. */
301
+ export interface AgentBuildLog {
302
+ logs: BuildLogChunk[];
303
+ /** Hand this back to get what comes after. Means nothing to anyone else. */
304
+ cursor: string;
305
+ /** There's more ready now: no need to wait before asking again. */
306
+ more: boolean;
307
+ }
308
+ export interface AgentBuildStatus {
309
+ phase: AgentBuildPhase;
310
+ /** Why it failed. */
311
+ error?: string;
312
+ /** The end of the latest log: of the one that failed, or of the step running when asked for it. */
313
+ log?: string;
314
+ /** What the finished release answers with: files from storage, processes on a VM, or some of each. */
315
+ serves?: 'files' | 'processes' | 'both';
316
+ }
317
+ /** Where the app is: installing and building come before its processes start. */
318
+ export type AgentAppPhase = 'installing' | 'building' | 'starting' | 'running' | 'failed';
319
+ export interface AgentAppProcess {
320
+ name: string;
321
+ kind: 'service' | 'daemon';
322
+ /** A static service is served by the guest itself and always 'running'. */
323
+ state: 'starting' | 'running' | 'crashed' | 'stopped';
324
+ port?: number;
325
+ restarts: number;
326
+ exitCode?: number | null;
327
+ signal?: string | null;
328
+ /** Workspace-relative log file. */
329
+ log?: string;
330
+ }
331
+ export interface AgentAppStatus {
332
+ phase: AgentAppPhase;
333
+ /** Why the app can't run: an invalid builder.json, or the install or build that failed. */
334
+ error?: string;
335
+ processes: AgentAppProcess[];
336
+ /** The framework it runs as (a Vercel slug); null for none: a package's own scripts, static files. */
337
+ framework?: string | null;
338
+ /** Whether builder.json said how it runs, or it was only detected. */
339
+ source?: 'detected' | 'builder.json';
340
+ }
341
+ /** How both sides of workspace live sync name a version of a file. */
342
+ export declare function workspaceFileHash(content: string): string;
153
343
  export declare function isAgentSessionEvent(value: unknown): value is AgentSessionEvent;
154
344
  export declare const AGENT_ENV: {
155
345
  readonly SESSION_ID: "SESSION_ID";
156
- /** 'task' (one AGENT_TASK run, then exit) or 'session' (stay up, serve chat turns). */
346
+ /**
347
+ * 'task' (one AGENT_TASK run, then exit), 'session' (stay up, serve chat turns), 'app' (a
348
+ * deployment: run the release's app on GUEST_HTTP_PORT, no agent) or 'build' (build a release
349
+ * and upload its output, no agent).
350
+ */
157
351
  readonly AGENT_MODE: "AGENT_MODE";
352
+ /** 'build' mode: where the release's output goes (the git service's route for that release). */
353
+ readonly RELEASE_UPLOAD_URL: "RELEASE_UPLOAD_URL";
354
+ /** secret, 'build' mode: may write only that release's output. */
355
+ readonly RELEASE_UPLOAD_TOKEN: "RELEASE_UPLOAD_TOKEN";
356
+ /** 'app' mode: a release built ahead of time: where the files its VM runs are, read with ACCESS_TOKEN. */
357
+ readonly RELEASE_ARTIFACTS_URL: "RELEASE_ARTIFACTS_URL";
358
+ /** 'app' mode: the release being run, so a VM restarted on its own disk skips install and build. */
359
+ readonly APP_RELEASE_ID: "APP_RELEASE_ID";
360
+ /** 'app' and build modes: the app's directory in the release's repository. */
361
+ readonly APP_ROOT_DIR: "APP_ROOT_DIR";
362
+ /** 'app' and build modes: the commit to check out. */
363
+ readonly GIT_COMMIT: "GIT_COMMIT";
364
+ /** The JSON schema the builder.json a session VM writes names as its `$schema`; written down, never fetched. */
365
+ readonly APP_SCHEMA_URL: "APP_SCHEMA_URL";
158
366
  /** 'coding' (default) or 'research'. */
159
367
  readonly AGENT_PROFILE: "AGENT_PROFILE";
160
368
  readonly AGENT_TASK: "AGENT_TASK";
@@ -164,6 +372,8 @@ export declare const AGENT_ENV: {
164
372
  /** Total tokens the session may spend before it pauses and asks whether to continue. */
165
373
  readonly AGENT_TOKEN_BUDGET: "AGENT_TOKEN_BUDGET";
166
374
  readonly AGENT_WORKSPACE_DIR: "AGENT_WORKSPACE_DIR";
375
+ /** The runtime's own files (its conversation, its git data), which nothing it runs can read. */
376
+ readonly AGENT_STATE_DIR: "AGENT_STATE_DIR";
167
377
  /** The gateway's agent socket; the guest authenticates to it with ACCESS_TOKEN (session-scoped). */
168
378
  readonly AGENT_SOCKET_URL: "AGENT_SOCKET_URL";
169
379
  /** secret: model provider keys (one of them) */
@@ -194,6 +404,8 @@ export declare const AGENT_ENV: {
194
404
  */
195
405
  readonly ACCESS_TOKEN: "ACCESS_TOKEN";
196
406
  };
407
+ /** The settings that deliver a release to its VM; the rest of a deployed VM's env is the app's own. */
408
+ export declare const RELEASE_DELIVERY_ENV: readonly string[];
197
409
  export declare const AGENT_SECRET_ENV_KEYS: readonly string[];
198
410
  export {};
199
411
  //# sourceMappingURL=protocol.d.ts.map