@0xmaxma/claude-gateway 2.1.9 → 2.1.11

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/config.template.json +4 -0
  2. package/dist/agent/runner.d.ts +93 -6
  3. package/dist/agent/runner.d.ts.map +1 -1
  4. package/dist/agent/runner.js +342 -108
  5. package/dist/agent/runner.js.map +1 -1
  6. package/dist/api/async-guard.d.ts +13 -0
  7. package/dist/api/async-guard.d.ts.map +1 -0
  8. package/dist/api/async-guard.js +38 -0
  9. package/dist/api/async-guard.js.map +1 -0
  10. package/dist/api/auth.d.ts +5 -0
  11. package/dist/api/auth.d.ts.map +1 -1
  12. package/dist/api/auth.js +3 -0
  13. package/dist/api/auth.js.map +1 -1
  14. package/dist/api/browser-bindings-router.d.ts.map +1 -1
  15. package/dist/api/browser-bindings-router.js +2 -0
  16. package/dist/api/browser-bindings-router.js.map +1 -1
  17. package/dist/api/capabilities.d.ts +47 -2
  18. package/dist/api/capabilities.d.ts.map +1 -1
  19. package/dist/api/capabilities.js +51 -8
  20. package/dist/api/capabilities.js.map +1 -1
  21. package/dist/api/files-router.d.ts +23 -0
  22. package/dist/api/files-router.d.ts.map +1 -0
  23. package/dist/api/files-router.js +102 -0
  24. package/dist/api/files-router.js.map +1 -0
  25. package/dist/api/gateway-router.d.ts +4 -2
  26. package/dist/api/gateway-router.d.ts.map +1 -1
  27. package/dist/api/gateway-router.js +20 -2
  28. package/dist/api/gateway-router.js.map +1 -1
  29. package/dist/api/git-router.d.ts +4 -0
  30. package/dist/api/git-router.d.ts.map +1 -0
  31. package/dist/api/git-router.js +51 -0
  32. package/dist/api/git-router.js.map +1 -0
  33. package/dist/api/manifest-sources.d.ts.map +1 -1
  34. package/dist/api/manifest-sources.js +6 -0
  35. package/dist/api/manifest-sources.js.map +1 -1
  36. package/dist/api/processes-router.d.ts +28 -0
  37. package/dist/api/processes-router.d.ts.map +1 -0
  38. package/dist/api/processes-router.js +179 -0
  39. package/dist/api/processes-router.js.map +1 -0
  40. package/dist/api/router.d.ts +41 -1
  41. package/dist/api/router.d.ts.map +1 -1
  42. package/dist/api/router.js +112 -25
  43. package/dist/api/router.js.map +1 -1
  44. package/dist/api/voice-router.d.ts.map +1 -1
  45. package/dist/api/voice-router.js +2 -0
  46. package/dist/api/voice-router.js.map +1 -1
  47. package/dist/automation/browser-outcome.d.ts +3 -1
  48. package/dist/automation/browser-outcome.d.ts.map +1 -1
  49. package/dist/automation/browser-outcome.js +2 -2
  50. package/dist/automation/browser-outcome.js.map +1 -1
  51. package/dist/automation/command-speech.d.ts +9 -1
  52. package/dist/automation/command-speech.d.ts.map +1 -1
  53. package/dist/automation/command-speech.js +18 -0
  54. package/dist/automation/command-speech.js.map +1 -1
  55. package/dist/automation/command-steps.d.ts +2 -0
  56. package/dist/automation/command-steps.d.ts.map +1 -1
  57. package/dist/automation/command-steps.js +34 -2
  58. package/dist/automation/command-steps.js.map +1 -1
  59. package/dist/automation/computer-command.d.ts +1 -0
  60. package/dist/automation/computer-command.d.ts.map +1 -1
  61. package/dist/automation/computer-command.js +31 -5
  62. package/dist/automation/computer-command.js.map +1 -1
  63. package/dist/automation/computer-outcome.d.ts +26 -3
  64. package/dist/automation/computer-outcome.d.ts.map +1 -1
  65. package/dist/automation/computer-outcome.js +183 -13
  66. package/dist/automation/computer-outcome.js.map +1 -1
  67. package/dist/automation/computer-policy.d.ts +10 -1
  68. package/dist/automation/computer-policy.d.ts.map +1 -1
  69. package/dist/automation/computer-policy.js +20 -6
  70. package/dist/automation/computer-policy.js.map +1 -1
  71. package/dist/automation/computer-use.d.ts +34 -0
  72. package/dist/automation/computer-use.d.ts.map +1 -1
  73. package/dist/automation/computer-use.js +211 -17
  74. package/dist/automation/computer-use.js.map +1 -1
  75. package/dist/automation/direct-command.d.ts +8 -0
  76. package/dist/automation/direct-command.d.ts.map +1 -1
  77. package/dist/automation/direct-command.js +12 -0
  78. package/dist/automation/direct-command.js.map +1 -1
  79. package/dist/automation/model-choice-evaluator.d.ts +3 -0
  80. package/dist/automation/model-choice-evaluator.d.ts.map +1 -1
  81. package/dist/automation/model-choice-evaluator.js +3 -1
  82. package/dist/automation/model-choice-evaluator.js.map +1 -1
  83. package/dist/automation/vision-decider.d.ts +4 -2
  84. package/dist/automation/vision-decider.d.ts.map +1 -1
  85. package/dist/automation/vision-decider.js +69 -15
  86. package/dist/automation/vision-decider.js.map +1 -1
  87. package/dist/build-provenance.json +4 -4
  88. package/dist/cli/redact.d.ts +1 -0
  89. package/dist/cli/redact.d.ts.map +1 -1
  90. package/dist/cli/redact.js +12 -0
  91. package/dist/cli/redact.js.map +1 -1
  92. package/dist/config/loader.d.ts +5 -0
  93. package/dist/config/loader.d.ts.map +1 -1
  94. package/dist/config/loader.js +121 -0
  95. package/dist/config/loader.js.map +1 -1
  96. package/dist/config/reload-policy.d.ts.map +1 -1
  97. package/dist/config/reload-policy.js +1 -0
  98. package/dist/config/reload-policy.js.map +1 -1
  99. package/dist/config/watcher.d.ts.map +1 -1
  100. package/dist/config/watcher.js +1 -0
  101. package/dist/config/watcher.js.map +1 -1
  102. package/dist/files/config.d.ts +6 -0
  103. package/dist/files/config.d.ts.map +1 -0
  104. package/dist/files/config.js +15 -0
  105. package/dist/files/config.js.map +1 -0
  106. package/dist/files/delete.d.ts +27 -0
  107. package/dist/files/delete.d.ts.map +1 -0
  108. package/dist/files/delete.js +143 -0
  109. package/dist/files/delete.js.map +1 -0
  110. package/dist/files/fs.d.ts +70 -0
  111. package/dist/files/fs.d.ts.map +1 -0
  112. package/dist/files/fs.js +319 -0
  113. package/dist/files/fs.js.map +1 -0
  114. package/dist/files/holds.d.ts +11 -0
  115. package/dist/files/holds.d.ts.map +1 -0
  116. package/dist/files/holds.js +20 -0
  117. package/dist/files/holds.js.map +1 -0
  118. package/dist/files/paths.d.ts +26 -0
  119. package/dist/files/paths.d.ts.map +1 -0
  120. package/dist/files/paths.js +112 -0
  121. package/dist/files/paths.js.map +1 -0
  122. package/dist/files/session-cwd.d.ts +8 -0
  123. package/dist/files/session-cwd.d.ts.map +1 -0
  124. package/dist/files/session-cwd.js +139 -0
  125. package/dist/files/session-cwd.js.map +1 -0
  126. package/dist/git/read.d.ts +25 -0
  127. package/dist/git/read.d.ts.map +1 -0
  128. package/dist/git/read.js +166 -0
  129. package/dist/git/read.js.map +1 -0
  130. package/dist/git/runner.d.ts +46 -0
  131. package/dist/git/runner.d.ts.map +1 -0
  132. package/dist/git/runner.js +176 -0
  133. package/dist/git/runner.js.map +1 -0
  134. package/dist/git/status.d.ts +119 -0
  135. package/dist/git/status.d.ts.map +1 -0
  136. package/dist/git/status.js +273 -0
  137. package/dist/git/status.js.map +1 -0
  138. package/dist/index.js +7 -2
  139. package/dist/index.js.map +1 -1
  140. package/dist/jev/browser-contract.d.ts +3 -0
  141. package/dist/jev/browser-contract.d.ts.map +1 -1
  142. package/dist/jev/browser-contract.js +6 -0
  143. package/dist/jev/browser-contract.js.map +1 -1
  144. package/dist/orchestration/agent-tool-schemas.d.ts +18 -0
  145. package/dist/orchestration/agent-tool-schemas.d.ts.map +1 -1
  146. package/dist/orchestration/agent-tool-schemas.js +11 -3
  147. package/dist/orchestration/agent-tool-schemas.js.map +1 -1
  148. package/dist/orchestration/bridge.d.ts.map +1 -1
  149. package/dist/orchestration/bridge.js +26 -5
  150. package/dist/orchestration/bridge.js.map +1 -1
  151. package/dist/orchestration/browser-routing.d.ts.map +1 -1
  152. package/dist/orchestration/browser-routing.js +2 -1
  153. package/dist/orchestration/browser-routing.js.map +1 -1
  154. package/dist/orchestration/computer-decisions.d.ts +1 -1
  155. package/dist/orchestration/computer-decisions.d.ts.map +1 -1
  156. package/dist/orchestration/computer-decisions.js +21 -7
  157. package/dist/orchestration/computer-decisions.js.map +1 -1
  158. package/dist/orchestration/computer-live.d.ts +62 -0
  159. package/dist/orchestration/computer-live.d.ts.map +1 -0
  160. package/dist/orchestration/computer-live.js +126 -0
  161. package/dist/orchestration/computer-live.js.map +1 -0
  162. package/dist/orchestration/container-tool-schemas.d.ts.map +1 -1
  163. package/dist/orchestration/container-tool-schemas.js +3 -0
  164. package/dist/orchestration/container-tool-schemas.js.map +1 -1
  165. package/dist/orchestration/decisions.d.ts +3 -1
  166. package/dist/orchestration/decisions.d.ts.map +1 -1
  167. package/dist/orchestration/decisions.js +4 -2
  168. package/dist/orchestration/decisions.js.map +1 -1
  169. package/dist/orchestration/gateway-tasks/browser.d.ts +1 -1
  170. package/dist/orchestration/gateway-tasks/browser.d.ts.map +1 -1
  171. package/dist/orchestration/gateway-tasks/browser.js +4 -3
  172. package/dist/orchestration/gateway-tasks/browser.js.map +1 -1
  173. package/dist/orchestration/gateway-tasks/computer-context.d.ts +4 -1
  174. package/dist/orchestration/gateway-tasks/computer-context.d.ts.map +1 -1
  175. package/dist/orchestration/gateway-tasks/computer-context.js +3 -1
  176. package/dist/orchestration/gateway-tasks/computer-context.js.map +1 -1
  177. package/dist/orchestration/gateway-tasks/computer.d.ts +78 -15
  178. package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
  179. package/dist/orchestration/gateway-tasks/computer.js +298 -31
  180. package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
  181. package/dist/orchestration/gateway-tasks/controller.d.ts +14 -2
  182. package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
  183. package/dist/orchestration/gateway-tasks/controller.js +63 -2
  184. package/dist/orchestration/gateway-tasks/controller.js.map +1 -1
  185. package/dist/orchestration/notification-mailbox.js +3 -3
  186. package/dist/orchestration/notification-mailbox.js.map +1 -1
  187. package/dist/orchestration/process-turn.d.ts.map +1 -1
  188. package/dist/orchestration/process-turn.js +4 -1
  189. package/dist/orchestration/process-turn.js.map +1 -1
  190. package/dist/orchestration/response-errors.d.ts.map +1 -1
  191. package/dist/orchestration/response-errors.js +2 -0
  192. package/dist/orchestration/response-errors.js.map +1 -1
  193. package/dist/orchestration/runtime.d.ts +32 -2
  194. package/dist/orchestration/runtime.d.ts.map +1 -1
  195. package/dist/orchestration/runtime.js +106 -10
  196. package/dist/orchestration/runtime.js.map +1 -1
  197. package/dist/orchestration/task-controls.d.ts +8 -0
  198. package/dist/orchestration/task-controls.d.ts.map +1 -1
  199. package/dist/orchestration/task-controls.js +3 -2
  200. package/dist/orchestration/task-controls.js.map +1 -1
  201. package/dist/orchestration/tasks/automation-session.d.ts +42 -11
  202. package/dist/orchestration/tasks/automation-session.d.ts.map +1 -1
  203. package/dist/orchestration/tasks/automation-session.js +101 -21
  204. package/dist/orchestration/tasks/automation-session.js.map +1 -1
  205. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  206. package/dist/orchestration/tasks/driver.js +19 -1
  207. package/dist/orchestration/tasks/driver.js.map +1 -1
  208. package/dist/orchestration/tasks/service.d.ts +48 -2
  209. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  210. package/dist/orchestration/tasks/service.js +165 -16
  211. package/dist/orchestration/tasks/service.js.map +1 -1
  212. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -1
  213. package/dist/orchestration/telegram-tool-status.js +2 -0
  214. package/dist/orchestration/telegram-tool-status.js.map +1 -1
  215. package/dist/orchestration/types.d.ts +21 -0
  216. package/dist/orchestration/types.d.ts.map +1 -1
  217. package/dist/orchestration/types.js.map +1 -1
  218. package/dist/processes/listeners.d.ts +41 -0
  219. package/dist/processes/listeners.d.ts.map +1 -0
  220. package/dist/processes/listeners.js +140 -0
  221. package/dist/processes/listeners.js.map +1 -0
  222. package/dist/processes/start.d.ts +39 -0
  223. package/dist/processes/start.d.ts.map +1 -0
  224. package/dist/processes/start.js +208 -0
  225. package/dist/processes/start.js.map +1 -0
  226. package/dist/processes/stop.d.ts +37 -0
  227. package/dist/processes/stop.d.ts.map +1 -0
  228. package/dist/processes/stop.js +94 -0
  229. package/dist/processes/stop.js.map +1 -0
  230. package/dist/session/cwd.d.ts +65 -0
  231. package/dist/session/cwd.d.ts.map +1 -0
  232. package/dist/session/cwd.js +24 -0
  233. package/dist/session/cwd.js.map +1 -0
  234. package/dist/session/process.d.ts +17 -0
  235. package/dist/session/process.d.ts.map +1 -1
  236. package/dist/session/process.js +58 -3
  237. package/dist/session/process.js.map +1 -1
  238. package/dist/session/runtime-profile.d.ts +4 -0
  239. package/dist/session/runtime-profile.d.ts.map +1 -1
  240. package/dist/session/runtime-profile.js +1 -0
  241. package/dist/session/runtime-profile.js.map +1 -1
  242. package/dist/session/store.d.ts +13 -1
  243. package/dist/session/store.d.ts.map +1 -1
  244. package/dist/session/store.js +50 -4
  245. package/dist/session/store.js.map +1 -1
  246. package/dist/types.d.ts +19 -0
  247. package/dist/types.d.ts.map +1 -1
  248. package/dist/ui/voice-call-client.d.ts +3 -0
  249. package/dist/ui/voice-call-client.d.ts.map +1 -1
  250. package/dist/ui/voice-call-client.js +10 -1
  251. package/dist/ui/voice-call-client.js.map +1 -1
  252. package/dist/utils/paths.d.ts +5 -0
  253. package/dist/utils/paths.d.ts.map +1 -1
  254. package/dist/utils/paths.js +15 -0
  255. package/dist/utils/paths.js.map +1 -1
  256. package/dist/utils/result.d.ts +16 -0
  257. package/dist/utils/result.d.ts.map +1 -0
  258. package/dist/utils/result.js +8 -0
  259. package/dist/utils/result.js.map +1 -0
  260. package/dist/voice/errors.js +1 -1
  261. package/dist/voice/errors.js.map +1 -1
  262. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -1
  263. package/dist/voice/providers/elevenlabs-tts.js +17 -1
  264. package/dist/voice/providers/elevenlabs-tts.js.map +1 -1
  265. package/dist/voice/providers/socket.js +25 -6
  266. package/dist/voice/providers/socket.js.map +1 -1
  267. package/dist/voice/session.js +3 -2
  268. package/dist/voice/session.js.map +1 -1
  269. package/mcp/server.ts +1 -1
  270. package/mcp/tools/tasks/module.ts +2 -1
  271. package/package.json +1 -1
@@ -0,0 +1,179 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.PROCESSES_ERRORS = void 0;
37
+ exports.createProcessesRouter = createProcessesRouter;
38
+ const express_1 = require("express");
39
+ const os = __importStar(require("os"));
40
+ const path = __importStar(require("path"));
41
+ const auth_1 = require("./auth");
42
+ const async_guard_1 = require("./async-guard");
43
+ const route_registry_1 = require("./route-registry");
44
+ const files_router_1 = require("./files-router");
45
+ const fs_1 = require("../files/fs");
46
+ const paths_1 = require("../files/paths");
47
+ const listeners_1 = require("../processes/listeners");
48
+ const stop_1 = require("../processes/stop");
49
+ const start_1 = require("../processes/start");
50
+ const paths_2 = require("../utils/paths");
51
+ /** Every error code the processes routes answer, with its status. Path errors are the files API's. */
52
+ exports.PROCESSES_ERRORS = {
53
+ invalid_path: files_router_1.FILES_ERRORS.invalid_path,
54
+ invalid_name: files_router_1.FILES_ERRORS.invalid_name,
55
+ not_a_directory: files_router_1.FILES_ERRORS.not_a_directory,
56
+ invalid_port: { status: 400, message: 'port must be an integer from 1024 to 65535' },
57
+ invalid_script: { status: 400, message: 'script must be a relative path to a regular file in the working folder' },
58
+ invalid_executable: { status: 400, message: 'executable must be sh or bash' },
59
+ path_escape: files_router_1.FILES_ERRORS.path_escape,
60
+ permission_denied: files_router_1.FILES_ERRORS.permission_denied,
61
+ forbidden_key: files_router_1.FILES_ERRORS.forbidden_key,
62
+ not_found: files_router_1.FILES_ERRORS.not_found,
63
+ already_exists: files_router_1.FILES_ERRORS.already_exists,
64
+ symlink_in_path: files_router_1.FILES_ERRORS.symlink_in_path,
65
+ cross_device: files_router_1.FILES_ERRORS.cross_device,
66
+ already_running: { status: 409, message: 'A process working in this folder already listens, or a start of it is running' },
67
+ port_in_use: { status: 409, message: 'Something already listens on this port' },
68
+ no_free_port: { status: 409, message: 'No free port is available in the search range' },
69
+ no_start_command: { status: 422, message: 'The requested script is missing or not a regular file' },
70
+ internal: files_router_1.FILES_ERRORS.internal,
71
+ start_failed: { status: 502, message: 'The start script exited or did not listen in time' },
72
+ };
73
+ function fail(res, error) {
74
+ const body = typeof error === 'string' ? { code: error } : error;
75
+ const { status, message } = exports.PROCESSES_ERRORS[body.code];
76
+ res.status(status).json({ error: message, ...body });
77
+ }
78
+ function requireAdmin(req, res, next) {
79
+ if ((0, auth_1.isAdmin)(req.apiKey))
80
+ next();
81
+ else
82
+ fail(res, 'forbidden_key');
83
+ }
84
+ /** A non-empty folder path under the root, as the files API parses it. */
85
+ function folderPath(raw) {
86
+ const rel = (0, paths_1.parseRelPath)(raw, true);
87
+ if (!rel.ok)
88
+ return rel;
89
+ return rel.value === '' ? { ok: false, error: 'invalid_path' } : rel;
90
+ }
91
+ /**
92
+ * Which servers folders under the files root run, starting one with a requested script, and
93
+ * stopping them. All routes need an admin key.
94
+ */
95
+ function createProcessesRouter(apiKeys, root, deps) {
96
+ const { logger } = deps;
97
+ const startOptions = {
98
+ logDir: path.join(os.homedir(), '.claude-gateway', 'process-logs'),
99
+ portRange: start_1.DEFAULT_PORT_RANGE,
100
+ timeoutMs: start_1.START_TIMEOUT_MS,
101
+ ...deps.start,
102
+ };
103
+ const stopOptions = { termWaitMs: stop_1.STOP_TERM_WAIT_MS, ...deps.stop };
104
+ const router = (0, async_guard_1.guardAsyncRoutes)((0, express_1.Router)(), (req, res, e) => {
105
+ const code = e?.code;
106
+ logger.error(`processes: ${req.method} ${req.path} failed: ${e instanceof Error ? e.name : typeof e}${typeof code === 'string' ? ` ${code}` : ''}`);
107
+ if (res.headersSent)
108
+ res.end();
109
+ else
110
+ fail(res, 'internal');
111
+ });
112
+ const auth = (0, auth_1.createApiAuthMiddleware)(apiKeys);
113
+ (0, route_registry_1.defineRoute)(router, { method: 'GET', path: '/v1/processes', auth: 'admin', summary: 'The TCP listeners of processes working in a folder under the files root', cli: null }, auth, requireAdmin, async (req, res) => {
114
+ if (req.query.path === undefined) {
115
+ const rootDir = await (0, fs_1.resolveDir)(root, '', true);
116
+ if (!rootDir.ok)
117
+ return fail(res, rootDir.error);
118
+ const realRoot = rootDir.value;
119
+ const grouped = new Map();
120
+ for (const listener of await (0, listeners_1.collectListeners)()) {
121
+ for (const owner of listener.owners) {
122
+ if (!owner.cwd || !(0, paths_2.pathWithin)(realRoot, owner.cwd) || owner.cwd === realRoot)
123
+ continue;
124
+ const folder = path.relative(realRoot, owner.cwd).split(path.sep)[0];
125
+ if (!folder)
126
+ continue;
127
+ const listed = grouped.get(folder) ?? [];
128
+ if (!listed.some((entry) => entry.port === listener.port && entry.address === listener.address)) {
129
+ const attributed = (0, listeners_1.listenersIn)([listener], path.join(realRoot, folder))[0];
130
+ if (attributed)
131
+ listed.push(attributed);
132
+ }
133
+ grouped.set(folder, listed);
134
+ }
135
+ }
136
+ return res.json({ processes: [...grouped].sort(([a], [b]) => a.localeCompare(b)).map(([folder, listeners]) => ({ path: folder, running: true, listeners: listeners.sort((a, b) => a.port - b.port) })) });
137
+ }
138
+ const rel = folderPath(req.query.path);
139
+ if (!rel.ok)
140
+ return fail(res, rel.error);
141
+ const dir = await (0, fs_1.resolveRealDir)(root, rel.value);
142
+ if (!dir.ok)
143
+ return fail(res, dir.error);
144
+ const listeners = (0, listeners_1.listenersIn)(await (0, listeners_1.collectListeners)(), dir.value);
145
+ const body = { path: rel.value, running: listeners.length > 0, listeners };
146
+ res.json(body);
147
+ });
148
+ (0, route_registry_1.defineRoute)(router, { method: 'POST', path: '/v1/processes/start', auth: 'admin', summary: 'Start a script in a folder under the files root', cli: null }, auth, requireAdmin, async (req, res) => {
149
+ const body = (req.body ?? {});
150
+ const rel = folderPath(body.path);
151
+ if (!rel.ok)
152
+ return fail(res, rel.error);
153
+ const port = (0, start_1.parsePort)(body.port);
154
+ if (!port.ok)
155
+ return fail(res, port.error);
156
+ const started = await (0, start_1.startFolder)(root, rel.value, body.script, body.executable, port.value, startOptions);
157
+ if (!started.ok) {
158
+ if (started.error.code === 'start_failed')
159
+ logger.warn(`processes: start of ${rel.value} failed`);
160
+ return fail(res, started.error);
161
+ }
162
+ logger.info(`processes: started ${rel.value} on port ${started.value.port} (pid ${started.value.pid})`);
163
+ res.status(202).json(started.value);
164
+ });
165
+ (0, route_registry_1.defineRoute)(router, { method: 'POST', path: '/v1/processes/stop', auth: 'admin', summary: 'Stop the processes that listen and work in a folder under the files root', cli: null }, auth, requireAdmin, async (req, res) => {
166
+ const rel = folderPath((req.body ?? {}).path);
167
+ if (!rel.ok)
168
+ return fail(res, rel.error);
169
+ const stopped = await (0, stop_1.stopFolder)(root, rel.value, stopOptions);
170
+ if (!stopped.ok)
171
+ return fail(res, stopped.error);
172
+ if (stopped.value.stopped.length + stopped.value.remaining.length > 0) {
173
+ logger.info(`processes: stopped ${rel.value}: ports ${stopped.value.stopped.map((p) => p.port).join(',') || '-'}, remaining ${stopped.value.remaining.map((p) => p.port).join(',') || '-'}`);
174
+ }
175
+ res.json(stopped.value);
176
+ });
177
+ return router;
178
+ }
179
+ //# sourceMappingURL=processes-router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"processes-router.js","sourceRoot":"","sources":["../../src/api/processes-router.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2EA,sDA4FC;AAvKD,qCAAkE;AAClE,uCAAyB;AACzB,2CAA6B;AAE7B,iCAA0D;AAC1D,+CAAiD;AACjD,qDAA+C;AAC/C,iDAA8C;AAC9C,oCAAyD;AACzD,0CAAuD;AACvD,sDAAiF;AACjF,4CAA+E;AAC/E,8CAA8I;AAC9I,0CAA4C;AAI5C,sGAAsG;AACzF,QAAA,gBAAgB,GAAgE;IAC3F,YAAY,EAAE,2BAAY,CAAC,YAAY;IACvC,YAAY,EAAE,2BAAY,CAAC,YAAY;IACvC,eAAe,EAAE,2BAAY,CAAC,eAAe;IAC7C,YAAY,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,4CAA4C,EAAE;IACpF,cAAc,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,wEAAwE,EAAE;IAClH,kBAAkB,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,+BAA+B,EAAE;IAC7E,WAAW,EAAE,2BAAY,CAAC,WAAW;IACrC,iBAAiB,EAAE,2BAAY,CAAC,iBAAiB;IACjD,aAAa,EAAE,2BAAY,CAAC,aAAa;IACzC,SAAS,EAAE,2BAAY,CAAC,SAAS;IACjC,cAAc,EAAE,2BAAY,CAAC,cAAc;IAC3C,eAAe,EAAE,2BAAY,CAAC,eAAe;IAC7C,YAAY,EAAE,2BAAY,CAAC,YAAY;IACvC,eAAe,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,+EAA+E,EAAE;IAC1H,WAAW,EAAE,EAAE,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,wCAAwC,EAAE;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AC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,eAAe,OAAO,CAAC,KAAK,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC;QAC/L,CAAC;QACD,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;IAC1B,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -1,8 +1,48 @@
1
- import { Router, Response } from 'express';
1
+ import { Router, Request, Response, NextFunction } from 'express';
2
2
  import { AgentRunner } from '../agent/runner';
3
3
  import { AgentConfig, ApiKey, ModelConfig } from '../types';
4
4
  export declare function isValidSessionId(v: unknown): v is string;
5
+ /** `router.param('sessionId', requireValidSessionId)`: a malformed id gets 400 before auth or any handler. */
6
+ export declare function requireValidSessionId(_req: Request, res: Response, next: NextFunction, value: string): void;
5
7
  export declare function isValidAgentId(v: unknown): v is string;
8
+ /**
9
+ * The structured part of a built-in command reply, beside its text: `command`
10
+ * (the base command), `result` (its fields) and `actions` (buttons; each
11
+ * `command` is sent back as the next message, so it runs with the same key,
12
+ * session and checks as anything typed).
13
+ */
14
+ /**
15
+ * Every error POST /v1/agents/:agentId/sessions answers for its `cwd` . website/api/sessions.md
16
+ * publishes this table.
17
+ * A turn on a session whose folder stopped resolving answers the uppercase send-time codes instead.
18
+ */
19
+ export declare const SESSION_CWD_ERRORS: {
20
+ readonly invalid_cwd: {
21
+ readonly status: 400;
22
+ readonly message: "cwd must be an absolute path under the files root, or a path relative to it";
23
+ };
24
+ readonly cwd_outside_root: {
25
+ readonly status: 403;
26
+ readonly message: "cwd resolves outside the files root, or is the root itself";
27
+ };
28
+ readonly cwd_not_found: {
29
+ readonly status: 404;
30
+ readonly message: "cwd does not exist";
31
+ };
32
+ readonly files_disabled: {
33
+ readonly status: 409;
34
+ readonly message: "The files API is disabled on this gateway";
35
+ };
36
+ readonly cwd_unavailable: {
37
+ readonly status: 409;
38
+ readonly message: "cwd is not a folder the session can run in";
39
+ };
40
+ readonly cwd_unsupported_agent: {
41
+ readonly status: 409;
42
+ readonly message: "This agent cannot run a chat in a folder";
43
+ };
44
+ };
45
+ export type SessionCwdErrorCode = keyof typeof SESSION_CWD_ERRORS;
6
46
  /**
7
47
  * Write SSE headers and start the idle keepalive. Exported for tests: the
8
48
  * keepalive is time-based and only observable on a stream deliberately held
@@ -1 +1 @@
1
- {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAW,QAAQ,EAAE,MAAM,SAAS,CAAC;AASpD,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAe,WAAW,EAAe,MAAM,UAAU,CAAC;AA2FtF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAExD;AAMD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAEtD;AAkFD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CA4CjD;AAmUD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EACtC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EACtC,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,WAAW,EAAE,GAAG,SAAS,CAAC,GACzD,MAAM,CA81IR"}
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/api/router.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASlE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAE,WAAW,EAAE,MAAM,EAAe,WAAW,EAAe,MAAM,UAAU,CAAC;AA6FtF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAExD;AAED,8GAA8G;AAC9G,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAG3G;AAMD,wBAAgB,cAAc,CAAC,CAAC,EAAE,OAAO,GAAG,CAAC,IAAI,MAAM,CAEtD;AAED;;;;;GAKG;AACH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;CAOrB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG,MAAM,OAAO,kBAAkB,CAAC;AA2FlE;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI,CA4CjD;AAmUD,wBAAgB,eAAe,CAC7B,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EACtC,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,EACtC,OAAO,EAAE,MAAM,EAAE,EACjB,UAAU,CAAC,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,WAAW,EAAE,GAAG,CAAC,MAAM,WAAW,EAAE,GAAG,SAAS,CAAC,GACzD,MAAM,CAs4IR"}
@@ -33,7 +33,9 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.SESSION_CWD_ERRORS = void 0;
36
37
  exports.isValidSessionId = isValidSessionId;
38
+ exports.requireValidSessionId = requireValidSessionId;
37
39
  exports.isValidAgentId = isValidAgentId;
38
40
  exports.openSseStream = openSseStream;
39
41
  exports.createApiRouter = createApiRouter;
@@ -55,7 +57,10 @@ const custom_1 = require("../connectors/custom");
55
57
  const agent_env_1 = require("../config/agent-env");
56
58
  const config_write_lock_1 = require("../config/config-write-lock");
57
59
  const auth_1 = require("./auth");
60
+ const async_guard_1 = require("./async-guard");
61
+ const cwd_1 = require("../session/cwd");
58
62
  const media_store_1 = require("../history/media-store");
63
+ const store_1 = require("../session/store");
59
64
  const share_store_1 = require("../share/share-store");
60
65
  const db_1 = require("../history/db");
61
66
  const types_2 = require("../history/types");
@@ -114,19 +119,25 @@ async function verifyWhatsAppCloudCredentials(accessToken, phoneNumberId) {
114
119
  }
115
120
  const AGENT_ID_RE = /^[a-z][a-z0-9_-]{1,31}$/;
116
121
  const SAFE_FILENAME_RE = /^[a-zA-Z0-9._\-() ]+$/;
117
- // session_id becomes a filesystem key (sessions/<id>.jsonl, .sessions/<id>/) so it
118
- // must be constrained to the same safe charset as chat_id — no '/' or '.' that could
119
- // escape the agent's directory. Clients may pass custom (non-UUID) session ids, so
120
- // this preserves that while blocking path traversal.
121
- const SESSION_ID_RE = /^[a-zA-Z0-9_-]{1,64}$/;
122
122
  // Task and command ids are server/client-generated UUIDs; controlByUser rejects anything else.
123
123
  const TASK_CONTROL_UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
124
124
  const TASK_CONTROL_ERROR_STATUS = {
125
125
  INVALID_INPUT: 400, EXECUTION_DENIED: 403, AUTOMATION_SESSION_CLOSED: 410, COMMAND_QUEUE_FULL: 429,
126
126
  REVISION_CONFLICT: 409, STATE_CONFLICT: 409, NOTHING_TO_RESUME: 409, IDEMPOTENCY_CONFLICT: 409, ORCHESTRATION_DISABLED: 409,
127
127
  };
128
+ // session_id becomes a filesystem key (sessions/<id>.jsonl, .sessions/<id>/) so it
129
+ // must be constrained to the same safe charset as chat_id — no '/' or '.' that could
130
+ // escape the agent's directory. Clients may pass custom (non-UUID) session ids, so
131
+ // this preserves that while blocking path traversal.
128
132
  function isValidSessionId(v) {
129
- return typeof v === 'string' && SESSION_ID_RE.test(v);
133
+ return typeof v === 'string' && store_1.SESSION_ID_RE.test(v);
134
+ }
135
+ /** `router.param('sessionId', requireValidSessionId)`: a malformed id gets 400 before auth or any handler. */
136
+ function requireValidSessionId(_req, res, next, value) {
137
+ if (isValidSessionId(value))
138
+ next();
139
+ else
140
+ res.status(400).json({ error: 'Invalid session id', code: 'INVALID_INPUT' });
130
141
  }
131
142
  // agent_id likewise becomes a filesystem key (agents/<id>/media/…), so any
132
143
  // endpoint that joins it into a path MUST format-validate it first — a bare
@@ -141,6 +152,34 @@ function isValidAgentId(v) {
141
152
  * `command` is sent back as the next message, so it runs with the same key,
142
153
  * session and checks as anything typed).
143
154
  */
155
+ /**
156
+ * Every error POST /v1/agents/:agentId/sessions answers for its `cwd` . website/api/sessions.md
157
+ * publishes this table.
158
+ * A turn on a session whose folder stopped resolving answers the uppercase send-time codes instead.
159
+ */
160
+ exports.SESSION_CWD_ERRORS = {
161
+ invalid_cwd: { status: 400, message: 'cwd must be an absolute path under the files root, or a path relative to it' },
162
+ cwd_outside_root: { status: 403, message: 'cwd resolves outside the files root, or is the root itself' },
163
+ cwd_not_found: { status: 404, message: 'cwd does not exist' },
164
+ files_disabled: { status: 409, message: 'The files API is disabled on this gateway' },
165
+ cwd_unavailable: { status: 409, message: 'cwd is not a folder the session can run in' },
166
+ cwd_unsupported_agent: { status: 409, message: 'This agent cannot run a chat in a folder' },
167
+ };
168
+ function sessionCwdError(failure) {
169
+ const code = failure === 'invalid' ? 'invalid_cwd'
170
+ : failure.code === 'unsupported_agent' ? 'cwd_unsupported_agent'
171
+ : { disabled: 'files_disabled', outside_root: 'cwd_outside_root', not_found: 'cwd_not_found' }[failure.reason] ?? 'cwd_unavailable';
172
+ const reason = failure !== 'invalid' && (code === 'cwd_unavailable' || code === 'cwd_unsupported_agent') ? failure.reason : undefined;
173
+ return { status: exports.SESSION_CWD_ERRORS[code].status, error: exports.SESSION_CWD_ERRORS[code].message, code, ...(reason ? { reason } : {}) };
174
+ }
175
+ /** A session route failed: 409 when the session id belongs to another chat, else 500. */
176
+ function sessionRouteError(res, err) {
177
+ const code = (0, turn_stream_1.errorCode)(err);
178
+ if (code === 'SESSION_ID_IN_USE')
179
+ res.status(409).json({ error: err.message, code });
180
+ else
181
+ res.status(500).json({ error: err.message });
182
+ }
144
183
  function commandReplyFields(message, reply) {
145
184
  return { command: message.trim().split(/\s+/)[0], result: reply.result, actions: reply.actions ?? [] };
146
185
  }
@@ -583,8 +622,11 @@ function apiKeyId(key) {
583
622
  return (0, crypto_1.createHash)('sha256').update(key).digest('hex').slice(0, 16);
584
623
  }
585
624
  function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models) {
586
- const router = (0, express_1.Router)();
625
+ const router = (0, async_guard_1.guardAsyncRoutes)((0, express_1.Router)());
587
626
  const auth = (0, auth_1.createApiAuthMiddleware)(apiKeys);
627
+ // A session id becomes a file name (index entries, bindings, media, history) and a lookup key. Anything but a plain
628
+ // id names no session, so every route with :sessionId answers 400 before its handler runs, whoever the caller is.
629
+ router.param('sessionId', requireValidSessionId);
588
630
  router.use((0, voice_settings_router_1.voiceSettingsRouter)(agentConfigs, agentRunners, apiKeys, configPath));
589
631
  async function writeAgentsToConfigImpl(cfgPath, mutate, newId) {
590
632
  const raw = await fsp.readFile(cfgPath, 'utf-8');
@@ -849,7 +891,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
849
891
  }
850
892
  catch (error) {
851
893
  const code = error.code;
852
- res.status(code === 'NOT_SUPPORTED' || code === 'IDEMPOTENCY_CONFLICT' ? 409 : code === 'QUEUE_FULL' ? 429 : code === 'ACCESS_DENIED' ? 403 : 503).json({ error: error.message, code });
894
+ res.status(code === 'NOT_SUPPORTED' || code === 'IDEMPOTENCY_CONFLICT' || cwd_1.CWD_SEND_ERRORS.has(code ?? '') ? 409 : code === 'QUEUE_FULL' ? 429 : code === 'ACCESS_DENIED' ? 403 : 503).json({ error: error.message, code });
853
895
  }
854
896
  return;
855
897
  }
@@ -894,7 +936,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
894
936
  res.status(409).json({ error: 'Session already has a pending request' });
895
937
  }
896
938
  else {
897
- res.status(code === 'PROVIDER_CAPACITY' || code === 'PROVIDER_UNAVAILABLE' ? 503 : 500).json({ error: (0, response_errors_1.responseFailureMessage)(err), ...((0, turn_stream_1.errorCode)(err) ? { code: (0, turn_stream_1.errorCode)(err) } : {}) });
939
+ res.status(code === 'PROVIDER_CAPACITY' || code === 'PROVIDER_UNAVAILABLE' ? 503 : cwd_1.CWD_SEND_ERRORS.has(code ?? '') ? 409 : 500).json({ error: (0, response_errors_1.responseFailureMessage)(err), ...((0, turn_stream_1.errorCode)(err) ? { code: (0, turn_stream_1.errorCode)(err) } : {}) });
898
940
  }
899
941
  }
900
942
  else {
@@ -958,7 +1000,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
958
1000
  res.status(409).json({ error: 'Session already has a pending request' });
959
1001
  }
960
1002
  else {
961
- res.status(code === 'PROVIDER_CAPACITY' || code === 'PROVIDER_UNAVAILABLE' ? 503 : 500).json({ error: (0, response_errors_1.responseFailureMessage)(err), ...((0, turn_stream_1.errorCode)(err) ? { code: (0, turn_stream_1.errorCode)(err) } : {}) });
1003
+ res.status(code === 'PROVIDER_CAPACITY' || code === 'PROVIDER_UNAVAILABLE' ? 503 : cwd_1.CWD_SEND_ERRORS.has(code ?? '') ? 409 : 500).json({ error: (0, response_errors_1.responseFailureMessage)(err), ...((0, turn_stream_1.errorCode)(err) ? { code: (0, turn_stream_1.errorCode)(err) } : {}) });
962
1004
  }
963
1005
  }
964
1006
  }
@@ -1098,10 +1140,10 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
1098
1140
  return {
1099
1141
  agentId,
1100
1142
  description: cfg?.description ?? '',
1101
- sessions: sessions.map((s) => {
1143
+ sessions: await Promise.all(sessions.map(async (s) => {
1102
1144
  const meta = metaMap.get(s.sessionId);
1103
- return { ...s, sessionName: meta?.name ?? null, imageConfig: meta?.imageConfig ?? null, videoConfig: meta?.videoConfig ?? null, model: meta?.model ?? null };
1104
- }),
1145
+ return { ...s, sessionName: meta?.name ?? null, imageConfig: meta?.imageConfig ?? null, videoConfig: meta?.videoConfig ?? null, model: meta?.model ?? null, ...await runner.sessionCwdView(s.sessionId) };
1146
+ })),
1105
1147
  };
1106
1148
  }));
1107
1149
  res.json({ agents });
@@ -4162,6 +4204,10 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4162
4204
  return;
4163
4205
  }
4164
4206
  const query = req.query;
4207
+ if (query['session_id'] !== undefined && typeof query['session_id'] !== 'string') {
4208
+ res.status(400).json({ error: 'session_id must be a single string', code: 'INVALID_INPUT' });
4209
+ return;
4210
+ }
4165
4211
  // Ceiling reuses MAX_HISTORY_LIMIT from the history layer so this HTTP-boundary
4166
4212
  // clamp and the db clamp can never drift (both 1000; see #1798).
4167
4213
  const limit = query['limit'] ? Math.min(parseInt(query['limit'], 10) || 50, db_1.MAX_HISTORY_LIMIT) : 50;
@@ -4235,6 +4281,10 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4235
4281
  return;
4236
4282
  }
4237
4283
  const query = req.query;
4284
+ if (query['q'] !== undefined && typeof query['q'] !== 'string') {
4285
+ res.status(400).json({ error: 'q must be a single string', code: 'INVALID_INPUT' });
4286
+ return;
4287
+ }
4238
4288
  const q = (query['q'] ?? '').trim();
4239
4289
  if (!q) {
4240
4290
  res.status(400).json({ error: 'q is required' });
@@ -4822,10 +4872,11 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4822
4872
  const roleMap = new Map(historySessions.map((s) => [s.sessionId, s.lastMessageRole]));
4823
4873
  const enriched = {
4824
4874
  ...index,
4825
- sessions: index.sessions.map((s) => {
4875
+ sessions: await Promise.all(index.sessions.map(async (s) => {
4826
4876
  const lastMessageRole = roleMap.get(s.id) ?? undefined;
4827
- return lastMessageRole !== undefined ? { ...s, lastMessageRole } : s;
4828
- }),
4877
+ const view = { ...s, ...await runner.sessionCwdView(s.id) };
4878
+ return lastMessageRole !== undefined ? { ...view, lastMessageRole } : view;
4879
+ })),
4829
4880
  };
4830
4881
  res.json(enriched);
4831
4882
  }
@@ -4845,9 +4896,23 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4845
4896
  const body = req.body;
4846
4897
  const promptText = typeof body.prompt === 'string' ? body.prompt.trim() : undefined;
4847
4898
  const explicitName = typeof body.name === 'string' ? body.name.trim() : undefined;
4899
+ let cwd;
4900
+ // Clients serialize an unset optional field as null.
4901
+ if (body.cwd !== undefined && body.cwd !== null) {
4902
+ if (!(0, auth_1.canWriteAgent)(req.apiKey, agentId)) {
4903
+ res.status(403).json({ error: 'Write permission required' });
4904
+ return;
4905
+ }
4906
+ cwd = await runner.parseApiCwd(body.cwd);
4907
+ if (!cwd.ok) {
4908
+ const { status, error, code, reason } = sessionCwdError(cwd.error);
4909
+ res.status(status).json({ error, code, ...(reason ? { reason } : {}) });
4910
+ return;
4911
+ }
4912
+ }
4848
4913
  try {
4849
- const meta = await runner.createApiSession(chatId, promptText, explicitName);
4850
- res.status(201).json({ sessionId: meta.id, sessionName: meta.name, createdAt: meta.createdAt });
4914
+ const meta = await runner.createApiSession(chatId, promptText, explicitName, cwd?.ok ? cwd.value : undefined);
4915
+ res.status(201).json({ sessionId: meta.id, sessionName: meta.name, createdAt: meta.createdAt, ...await runner.sessionCwdView(meta.id) });
4851
4916
  }
4852
4917
  catch (err) {
4853
4918
  res.status(500).json({ error: err.message });
@@ -4897,7 +4962,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4897
4962
  res.json(result);
4898
4963
  }
4899
4964
  catch (err) {
4900
- res.status(500).json({ error: err.message });
4965
+ sessionRouteError(res, err);
4901
4966
  }
4902
4967
  });
4903
4968
  /**
@@ -4914,7 +4979,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4914
4979
  res.status(204).send();
4915
4980
  }
4916
4981
  catch (err) {
4917
- res.status(500).json({ error: err.message });
4982
+ sessionRouteError(res, err);
4918
4983
  }
4919
4984
  });
4920
4985
  /**
@@ -4931,7 +4996,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4931
4996
  res.json(result);
4932
4997
  }
4933
4998
  catch (err) {
4934
- res.status(500).json({ error: err.message });
4999
+ sessionRouteError(res, err);
4935
5000
  }
4936
5001
  });
4937
5002
  /**
@@ -4948,7 +5013,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4948
5013
  res.json(result);
4949
5014
  }
4950
5015
  catch (err) {
4951
- res.status(500).json({ error: err.message });
5016
+ sessionRouteError(res, err);
4952
5017
  }
4953
5018
  });
4954
5019
  /**
@@ -4965,7 +5030,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4965
5030
  res.json(result);
4966
5031
  }
4967
5032
  catch (err) {
4968
- res.status(500).json({ error: err.message });
5033
+ sessionRouteError(res, err);
4969
5034
  }
4970
5035
  });
4971
5036
  /**
@@ -4982,7 +5047,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
4982
5047
  res.json(result);
4983
5048
  }
4984
5049
  catch (err) {
4985
- res.status(500).json({ error: err.message });
5050
+ sessionRouteError(res, err);
4986
5051
  }
4987
5052
  });
4988
5053
  /**
@@ -5239,6 +5304,20 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
5239
5304
  res.status(403).json({ error: 'Task unavailable for this principal' });
5240
5305
  }
5241
5306
  });
5307
+ // The desktop app's on-screen overlay (getpod-app overlay.ts) asks what the run controlling it is doing. The relay
5308
+ // forwards no extra command fields, so the app reads it here through its pod, keyed by its own relay grant.
5309
+ router.get('/v1/computer/activity', auth, (req, res) => {
5310
+ const apiKey = req.apiKey;
5311
+ const grantId = typeof req.query.grant_id === 'string' ? req.query.grant_id : '';
5312
+ if (!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(grantId)) {
5313
+ res.status(400).json({ error: 'grant_id must be a UUID' });
5314
+ return;
5315
+ }
5316
+ const runs = [...agentRunners].filter(([agentId]) => (0, auth_1.canAccessAgent)(apiKey, agentId))
5317
+ .flatMap(([, runner]) => { const run = runner.computerActivity(grantId, (0, identity_1.apiPrincipal)(apiKey)); return run ? [run] : []; })
5318
+ .sort((a, b) => b.updatedAt - a.updatedAt);
5319
+ res.set('Cache-Control', 'no-store').json({ run: runs[0] ?? null });
5320
+ });
5242
5321
  router.get('/v1/agents/:agentId/sessions/:sessionId/activity', auth, async (req, res) => {
5243
5322
  const { agentId, sessionId } = req.params;
5244
5323
  const apiKey = req.apiKey;
@@ -5433,6 +5512,14 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
5433
5512
  res.status(204).send();
5434
5513
  return;
5435
5514
  }
5515
+ // Decided before the unlink: a greeting must not be consumed by a turn that cannot run.
5516
+ try {
5517
+ await runner.assertApiCwdAvailable(sessionId);
5518
+ }
5519
+ catch (err) {
5520
+ res.status(409).json({ error: (0, response_errors_1.responseFailureMessage)(err), code: (0, turn_stream_1.errorCode)(err) });
5521
+ return;
5522
+ }
5436
5523
  // Unlink before streaming — prevents re-read race if the client retries immediately
5437
5524
  try {
5438
5525
  await fsp.unlink(greetingPath);
@@ -5460,7 +5547,7 @@ function createApiRouter(agentRunners, agentConfigs, apiKeys, configPath, models
5460
5547
  res.status(409).json({ error: 'Session already has a pending request' });
5461
5548
  }
5462
5549
  else {
5463
- res.status(500).json({ error: (0, response_errors_1.responseFailureMessage)(err), ...((0, turn_stream_1.errorCode)(err) ? { code: (0, turn_stream_1.errorCode)(err) } : {}) });
5550
+ res.status(cwd_1.CWD_SEND_ERRORS.has(code ?? '') ? 409 : 500).json({ error: (0, response_errors_1.responseFailureMessage)(err), ...((0, turn_stream_1.errorCode)(err) ? { code: (0, turn_stream_1.errorCode)(err) } : {}) });
5464
5551
  }
5465
5552
  }
5466
5553
  else {