@qlairoslabs/acp-client 0.12.1 → 0.13.1-alpha.1

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 (288) hide show
  1. package/CHANGELOG-consumer-fixes.md +17 -10
  2. package/CHANGELOG-controller-interface.md +258 -0
  3. package/CHANGELOG-metering.md +29 -0
  4. package/CHANGELOG-operation-lifecycle.md +15 -1
  5. package/CONSUMER_GUIDE.md +984 -6
  6. package/MIGRATION-0.10-to-0.12.md +4 -1
  7. package/MIGRATION-0.12-to-0.13.md +288 -0
  8. package/README.md +17 -16
  9. package/package.json +11 -2
  10. package/src/acp-client-handlers.ts +48 -0
  11. package/src/activity.ts +3 -0
  12. package/src/adapters.ts +25 -0
  13. package/src/agent/adoption/provider-attachment.ts +33 -0
  14. package/src/agent/adoption/provider-session-delete.ts +1 -1
  15. package/src/agent/adoption/provider-sessions.ts +3 -2
  16. package/src/agent/append-assistant-message.ts +91 -0
  17. package/src/agent/config.ts +54 -6
  18. package/src/agent/conversation-manager.ts +95 -158
  19. package/src/agent/manager-settings.ts +1 -0
  20. package/src/agent/native-channel-lifecycle.ts +111 -0
  21. package/src/agent/native-operations.ts +39 -0
  22. package/src/agent/persisted-lifecycle.ts +44 -4
  23. package/src/agent/persistence-policy/context.ts +13 -0
  24. package/src/agent/persistence-policy/resolver.ts +7 -0
  25. package/src/agent/persistence-policy/types.ts +1 -0
  26. package/src/agent/record-capture.ts +1 -0
  27. package/src/agent-adapter-registry.ts +33 -7
  28. package/src/agent-conversation-contracts.ts +14 -1
  29. package/src/agent-conversation-errors.ts +8 -0
  30. package/src/agent-conversation-owner.ts +9 -4
  31. package/src/agent-session-config.ts +137 -0
  32. package/src/agent-session.ts +440 -934
  33. package/src/agent.ts +168 -0
  34. package/src/capabilities.ts +2 -0
  35. package/src/checkpointing/recovery.ts +3 -0
  36. package/src/cli/index.ts +3 -3
  37. package/src/cli/managed.ts +2 -2
  38. package/src/client.ts +56 -96
  39. package/src/connection-attempt.ts +95 -0
  40. package/src/controller-connection.ts +115 -0
  41. package/src/controller.ts +158 -148
  42. package/src/conversation-controller/capabilities.ts +88 -0
  43. package/src/conversation-controller/contracts.ts +208 -0
  44. package/src/conversation-controller/factory.ts +39 -0
  45. package/src/conversation-controller/guards.ts +98 -0
  46. package/src/conversation-controller/index.ts +20 -0
  47. package/src/conversation-startup.ts +35 -0
  48. package/src/conversation-turns/backend-turns.ts +373 -0
  49. package/src/conversation-turns/clear-operations.ts +37 -0
  50. package/src/conversation-turns/context.ts +135 -0
  51. package/src/conversation-turns/index.ts +4 -0
  52. package/src/conversation-turns/record-helpers.ts +75 -0
  53. package/src/conversation-turns/recording.ts +235 -0
  54. package/src/conversation-turns/run-turn.ts +367 -0
  55. package/src/conversation-turns/turn-run.ts +57 -0
  56. package/src/errors.ts +41 -0
  57. package/src/handoff-options.ts +81 -0
  58. package/src/identity/checkpoint-backed.ts +1 -1
  59. package/src/index.ts +59 -3
  60. package/src/internal-inference/coordination/manager.ts +11 -0
  61. package/src/internal-inference/runtime/harness-runtime.ts +4 -4
  62. package/src/launcher.ts +37 -2
  63. package/src/media/parts.ts +5 -0
  64. package/src/message-status.ts +83 -0
  65. package/src/metering/engine.ts +39 -64
  66. package/src/metering/measurement-provenance.ts +36 -0
  67. package/src/metering/native/durability.ts +115 -0
  68. package/src/metering/native/ledger.ts +104 -0
  69. package/src/metering/native/operation.ts +85 -0
  70. package/src/metering/native/projection.ts +114 -0
  71. package/src/metering/native/proof.ts +51 -0
  72. package/src/metering/native/requirements.ts +10 -0
  73. package/src/metering/native/retirement.ts +92 -0
  74. package/src/metering/native/source.ts +90 -0
  75. package/src/metering/record.ts +38 -1
  76. package/src/metering/state.ts +13 -3
  77. package/src/native/approvals.ts +186 -0
  78. package/src/native/capabilities.ts +17 -0
  79. package/src/native/channel-changes.ts +211 -0
  80. package/src/native/connection.ts +56 -0
  81. package/src/native/controller.ts +592 -0
  82. package/src/native/delegation-sender.ts +26 -0
  83. package/src/native/errors.ts +35 -0
  84. package/src/native/functions.ts +156 -0
  85. package/src/native/host-config.ts +59 -0
  86. package/src/native/host.ts +978 -0
  87. package/src/native/item-receipts.ts +15 -0
  88. package/src/native/metering.ts +12 -0
  89. package/src/native/records.ts +166 -0
  90. package/src/native/recovery.ts +186 -0
  91. package/src/native/reminders/fixtures/schema21.sqlite.gz +0 -0
  92. package/src/native/reminders/idle.ts +70 -0
  93. package/src/native/reminders/limits.ts +19 -0
  94. package/src/native/reminders/notifications.ts +29 -0
  95. package/src/native/reminders/routine-guard.ts +66 -0
  96. package/src/native/reminders/routine-schedule.ts +25 -0
  97. package/src/native/reminders/routine-wire.ts +21 -0
  98. package/src/native/reminders/schedule.ts +97 -0
  99. package/src/native/reminders/service.ts +280 -0
  100. package/src/native/reminders/supervisor.ts +91 -0
  101. package/src/native/reminders/sync.ts +301 -0
  102. package/src/native/reminders/wire.ts +197 -0
  103. package/src/native/submission-withdrawal.ts +65 -0
  104. package/src/native/usage.ts +15 -0
  105. package/src/native/worker-delivery.ts +61 -0
  106. package/src/native-harness/README.md +726 -0
  107. package/src/native-harness/package.json +24 -0
  108. package/src/native-harness/scripts/build-routine-zones.py +47 -0
  109. package/src/native-harness/src/capabilities/context/build.ts +59 -0
  110. package/src/native-harness/src/capabilities/context/instructions/agent-demo.md +11 -0
  111. package/src/native-harness/src/capabilities/context/instructions/agent.md +5 -0
  112. package/src/native-harness/src/capabilities/context/instructions/harness.md +7 -0
  113. package/src/native-harness/src/capabilities/context/load-instructions.ts +22 -0
  114. package/src/native-harness/src/capabilities/context/session.ts +93 -0
  115. package/src/native-harness/src/capabilities/model/attempt.ts +27 -0
  116. package/src/native-harness/src/capabilities/model/openrouter-stream.ts +72 -0
  117. package/src/native-harness/src/capabilities/model/openrouter.ts +62 -0
  118. package/src/native-harness/src/capabilities/model/runner.ts +116 -0
  119. package/src/native-harness/src/capabilities/model/scenario-attempt.ts +50 -0
  120. package/src/native-harness/src/capabilities/model/scenario-file.ts +125 -0
  121. package/src/native-harness/src/capabilities/model/scripted-error.ts +6 -0
  122. package/src/native-harness/src/capabilities/model/scripted.ts +81 -0
  123. package/src/native-harness/src/capabilities/model/usage.ts +15 -0
  124. package/src/native-harness/src/capabilities/reminders/cron-calendar.ts +50 -0
  125. package/src/native-harness/src/capabilities/reminders/cron-fields.ts +46 -0
  126. package/src/native-harness/src/capabilities/reminders/cron-proof.ts +32 -0
  127. package/src/native-harness/src/capabilities/reminders/cron-zone.ts +53 -0
  128. package/src/native-harness/src/capabilities/reminders/iana-zones.json.gz +0 -0
  129. package/src/native-harness/src/capabilities/reminders/iana-zones.ts +34 -0
  130. package/src/native-harness/src/capabilities/reminders/interval.ts +30 -0
  131. package/src/native-harness/src/capabilities/reminders/routine-advance.ts +47 -0
  132. package/src/native-harness/src/capabilities/reminders/routine-backlog.ts +47 -0
  133. package/src/native-harness/src/capabilities/reminders/routine-expiry.ts +15 -0
  134. package/src/native-harness/src/capabilities/reminders/routine-occurrence.ts +65 -0
  135. package/src/native-harness/src/capabilities/reminders/routine-schedule.ts +70 -0
  136. package/src/native-harness/src/capabilities/reminders/unattended.ts +8 -0
  137. package/src/native-harness/src/capabilities/tools/builtin/current-time.ts +28 -0
  138. package/src/native-harness/src/capabilities/tools/builtin/notify-channel.ts +17 -0
  139. package/src/native-harness/src/capabilities/tools/debug/index.ts +13 -0
  140. package/src/native-harness/src/capabilities/tools/debug/result.ts +12 -0
  141. package/src/native-harness/src/capabilities/tools/debug/test-echo.ts +16 -0
  142. package/src/native-harness/src/capabilities/tools/debug/test-fail.ts +14 -0
  143. package/src/native-harness/src/capabilities/tools/debug/test-wait.ts +19 -0
  144. package/src/native-harness/src/capabilities/tools/reminders/index.ts +97 -0
  145. package/src/native-harness/src/capabilities/tools/runtime/catalog.ts +103 -0
  146. package/src/native-harness/src/capabilities/tools/runtime/functions.ts +130 -0
  147. package/src/native-harness/src/capabilities/tools/runtime/invocations.ts +48 -0
  148. package/src/native-harness/src/capabilities/tools/testing/echo.ts +18 -0
  149. package/src/native-harness/src/capabilities/tools/testing/record.ts +47 -0
  150. package/src/native-harness/src/capabilities/tools/timeline/index.ts +41 -0
  151. package/src/native-harness/src/client.ts +18 -0
  152. package/src/native-harness/src/contracts/agent.ts +105 -0
  153. package/src/native-harness/src/contracts/config-permissions.ts +49 -0
  154. package/src/native-harness/src/contracts/context.ts +112 -0
  155. package/src/native-harness/src/contracts/events.ts +47 -0
  156. package/src/native-harness/src/contracts/input-limits.ts +7 -0
  157. package/src/native-harness/src/contracts/inspection.ts +22 -0
  158. package/src/native-harness/src/contracts/loop.ts +31 -0
  159. package/src/native-harness/src/contracts/model-execution.ts +83 -0
  160. package/src/native-harness/src/contracts/operator-controls.ts +106 -0
  161. package/src/native-harness/src/contracts/output.ts +13 -0
  162. package/src/native-harness/src/contracts/protocol.ts +320 -0
  163. package/src/native-harness/src/contracts/reminders.ts +134 -0
  164. package/src/native-harness/src/contracts/routines.ts +20 -0
  165. package/src/native-harness/src/contracts/scenario.ts +42 -0
  166. package/src/native-harness/src/contracts/session-file.ts +20 -0
  167. package/src/native-harness/src/contracts/session.ts +184 -0
  168. package/src/native-harness/src/contracts/storage.ts +597 -0
  169. package/src/native-harness/src/contracts/timeline-retrieval.ts +40 -0
  170. package/src/native-harness/src/contracts/tools.ts +133 -0
  171. package/src/native-harness/src/governance/permissions/gate.ts +129 -0
  172. package/src/native-harness/src/governance/policy/resolve.ts +32 -0
  173. package/src/native-harness/src/index.ts +322 -0
  174. package/src/native-harness/src/interfaces/cli/chat.ts +83 -0
  175. package/src/native-harness/src/interfaces/cli/development.ts +145 -0
  176. package/src/native-harness/src/interfaces/cli/format-reply.ts +27 -0
  177. package/src/native-harness/src/interfaces/cli/listeners.ts +74 -0
  178. package/src/native-harness/src/interfaces/cli/main.ts +47 -0
  179. package/src/native-harness/src/interfaces/cli/scenario.ts +37 -0
  180. package/src/native-harness/src/interfaces/cli/serve.ts +21 -0
  181. package/src/native-harness/src/interfaces/cli/start.ts +106 -0
  182. package/src/native-harness/src/interfaces/client.ts +225 -0
  183. package/src/native-harness/src/interfaces/inspector/index.html +283 -0
  184. package/src/native-harness/src/interfaces/inspector/observe.ts +35 -0
  185. package/src/native-harness/src/interfaces/inspector/server.ts +56 -0
  186. package/src/native-harness/src/interfaces/inspector/state.ts +92 -0
  187. package/src/native-harness/src/interfaces/protocol/channel-changes.ts +153 -0
  188. package/src/native-harness/src/interfaces/protocol/framing.ts +47 -0
  189. package/src/native-harness/src/interfaces/protocol/functions.ts +87 -0
  190. package/src/native-harness/src/interfaces/protocol/in-process.ts +67 -0
  191. package/src/native-harness/src/interfaces/protocol/live-queue.ts +55 -0
  192. package/src/native-harness/src/interfaces/protocol/load.ts +60 -0
  193. package/src/native-harness/src/interfaces/protocol/local.ts +120 -0
  194. package/src/native-harness/src/interfaces/protocol/operator.ts +120 -0
  195. package/src/native-harness/src/interfaces/protocol/output.ts +59 -0
  196. package/src/native-harness/src/interfaces/protocol/server.ts +519 -0
  197. package/src/native-harness/src/interfaces/protocol/stdio-client.ts +126 -0
  198. package/src/native-harness/src/interfaces/protocol/stdio-server.ts +82 -0
  199. package/src/native-harness/src/interfaces/protocol/subscribe.ts +41 -0
  200. package/src/native-harness/src/interfaces/protocol/transfers.ts +146 -0
  201. package/src/native-harness/src/interfaces/web-chat/index.html +94 -0
  202. package/src/native-harness/src/interfaces/web-chat/server.ts +34 -0
  203. package/src/native-harness/src/kernel/channels.ts +409 -0
  204. package/src/native-harness/src/kernel/loop.ts +45 -0
  205. package/src/native-harness/src/runtime/config/development.ts +23 -0
  206. package/src/native-harness/src/runtime/config/managed.ts +2 -0
  207. package/src/native-harness/src/runtime/config/paths.ts +33 -0
  208. package/src/native-harness/src/runtime/reminder-timer.ts +42 -0
  209. package/src/native-harness/src/runtime/reminder-validation.ts +125 -0
  210. package/src/native-harness/src/runtime/reminders.ts +66 -0
  211. package/src/native-harness/src/state/storage/archive.ts +257 -0
  212. package/src/native-harness/src/state/storage/engine.ts +1204 -0
  213. package/src/native-harness/src/state/storage/inference.ts +124 -0
  214. package/src/native-harness/src/state/storage/memory-reminders.ts +103 -0
  215. package/src/native-harness/src/state/storage/memory.ts +354 -0
  216. package/src/native-harness/src/state/storage/policy-metadata.ts +32 -0
  217. package/src/native-harness/src/state/storage/reminder-archive.ts +104 -0
  218. package/src/native-harness/src/state/storage/reminder-change.ts +138 -0
  219. package/src/native-harness/src/state/storage/reminder-tables.ts +35 -0
  220. package/src/native-harness/src/state/storage/retrieval.ts +122 -0
  221. package/src/native-harness/src/state/storage/routine-row.ts +25 -0
  222. package/src/native-harness/src/state/storage/script-identity.ts +7 -0
  223. package/src/native-harness/src/state/storage/session-file.ts +85 -0
  224. package/src/native-harness/src/state/storage/sqlite-reminders.ts +174 -0
  225. package/src/native-harness/src/state/storage/sqlite.ts +632 -0
  226. package/src/native-harness/src/testing.ts +190 -0
  227. package/src/native-harness/src/util/config.ts +66 -0
  228. package/src/native-harness/src/util/intake.ts +7 -0
  229. package/src/native-harness/src/util/json.ts +41 -0
  230. package/src/native-harness/src/util/message-position.ts +3 -0
  231. package/src/native-harness/src/util/reminder-schedule.ts +44 -0
  232. package/src/native-harness/src/util/schema.ts +40 -0
  233. package/src/native-harness/src/util/timeline-text.ts +72 -0
  234. package/src/native-harness/src/util/timeline-tool-names.ts +3 -0
  235. package/src/native-harness/tsconfig.json +20 -0
  236. package/src/observation/agent-event-bus.ts +44 -18
  237. package/src/observation/index.ts +1 -0
  238. package/src/operations/contracts.ts +11 -3
  239. package/src/operations/errors.ts +5 -0
  240. package/src/operations/stale-policy.ts +1 -1
  241. package/src/operations/supervisor.ts +34 -10
  242. package/src/orchestrator/acp-delivery.ts +68 -0
  243. package/src/orchestrator/assignments.ts +27 -0
  244. package/src/orchestrator/busy.ts +15 -0
  245. package/src/orchestrator/config.ts +41 -0
  246. package/src/orchestrator/consumer-api.ts +24 -0
  247. package/src/orchestrator/contracts.ts +71 -0
  248. package/src/orchestrator/durable-assignments.ts +111 -0
  249. package/src/orchestrator/native-delegation.ts +103 -0
  250. package/src/orchestrator/orchestrator.ts +318 -0
  251. package/src/orchestrator/permissions.ts +28 -0
  252. package/src/orchestrator/policy.ts +44 -0
  253. package/src/orchestrator/pool.ts +123 -0
  254. package/src/orchestrator/tool-descriptions.ts +11 -0
  255. package/src/permissions/acp.ts +18 -0
  256. package/src/permissions/arrival.ts +13 -0
  257. package/src/permissions/consumer-config.ts +19 -0
  258. package/src/permissions/conversation.ts +288 -0
  259. package/src/permissions/matcher.ts +87 -0
  260. package/src/permissions/outcome.ts +26 -0
  261. package/src/permissions/policy.ts +86 -0
  262. package/src/permissions/request.ts +26 -0
  263. package/src/persistence/activity-projection.ts +1 -0
  264. package/src/persistence/backend.ts +34 -1
  265. package/src/persistence/channels.ts +23 -0
  266. package/src/persistence/index.ts +4 -0
  267. package/src/persistence/protocol-method.ts +5 -0
  268. package/src/persistence/reminder-wake.ts +49 -0
  269. package/src/persistence/reminders.ts +385 -0
  270. package/src/persistence/sqlite-backend.ts +84 -6
  271. package/src/persistence/sqlite-channels.ts +65 -0
  272. package/src/persistence/sqlite-reminders.ts +85 -0
  273. package/src/persistence/sqlite-schema.ts +108 -3
  274. package/src/persistence/sqlite-worker-delivery.ts +374 -0
  275. package/src/persistence/sqlite-workers.ts +59 -0
  276. package/src/persistence/worker-delivery-contract.ts +104 -0
  277. package/src/persistence/worker-terminal-reason.ts +29 -0
  278. package/src/persistence/workers.ts +19 -0
  279. package/src/provider-notices.ts +137 -0
  280. package/src/repl/commands.ts +2 -2
  281. package/src/steering/combine.ts +3 -1
  282. package/src/steering/contracts.ts +11 -2
  283. package/src/steering/controller.ts +3 -2
  284. package/src/terminals.ts +9 -6
  285. package/src/transport/acp-transport.ts +24 -14
  286. package/src/types.ts +15 -12
  287. package/src/updates.ts +14 -2
  288. package/src/wire-log.ts +1 -1
@@ -0,0 +1,318 @@
1
+ import { ownPermissions } from "../permissions/policy.ts";
2
+ import type { PermissionSettings } from "../permissions/matcher.ts";
3
+ import { workerPermissionHandler, type FindGivingConversation } from "./permissions.ts";
4
+ import { WorkerPolicyError } from "../errors.ts";
5
+ import { canSeeWorker, checkWorkerOpenLimit, requireWorkerRedirect, requireWorkerUse } from "./policy.ts";
6
+ import type { AssignmentPlan, WorkerAssignmentPort } from "./assignments.ts";
7
+ import { planAssignment } from "./busy.ts";
8
+ import type { AgentConversationManager, DeleteConversationResult } from "../agent/config.ts";
9
+ import { workerTerminalFailure } from "../persistence/worker-terminal-reason.ts";
10
+ import type { Logger } from "../logger.ts";
11
+ import type { WorkerPersistence, WorkerRow } from "../persistence/workers.ts";
12
+ import type { OrchestratorConfig } from "./config.ts";
13
+ import type { OpenWorkerResult, SendWorkerInput, SendWorkerResult, WorkerActor, WorkerEvent, WorkerInput, WorkerSummary } from "./contracts.ts";
14
+ import { WorkerPool } from "./pool.ts";
15
+ import { WorkerAssignmentConflict } from "./durable-assignments.ts";
16
+
17
+ export class Orchestrator {
18
+ private readonly pool: WorkerPool;
19
+ private readonly completions = new Set<Promise<void>>();
20
+ private closed = false;
21
+ private readonly defaultWorkerPermissions: readonly PermissionSettings[];
22
+ private readonly evicted = (row: WorkerRow) => this.emit({ ...this.identity(row), kind: "worker_stopped", reason: "eviction" });
23
+
24
+ constructor(
25
+ private readonly workers: WorkerPersistence,
26
+ private readonly conversations: AgentConversationManager,
27
+ private readonly options: OrchestratorConfig["workers"] & { readonly defaultPermissions?: PermissionSettings },
28
+ private readonly log: Logger,
29
+ private readonly emit: (event: WorkerEvent) => void,
30
+ private readonly assignments?: WorkerAssignmentPort,
31
+ private readonly findGivingConversation?: FindGivingConversation,
32
+ ) {
33
+ this.pool = new WorkerPool(options.limit, options.idleStopMs ?? 600_000);
34
+ const defaults = ownPermissions(options.defaultPermissions);
35
+ this.defaultWorkerPermissions = defaults ? [defaults] : [];
36
+ }
37
+
38
+ open(actor: WorkerActor, input: WorkerInput): Promise<OpenWorkerResult> {
39
+ return this.run(async () => {
40
+ requireWorkerUse(actor);
41
+ this.assertInput(input);
42
+ const rows = await this.workers.list();
43
+ checkWorkerOpenLimit(actor, await this.activeRows(rows));
44
+ if (!await this.pool.makeRoom(this.evicted)) return { status: "no_worker_free", workers: await this.summaries(actor) };
45
+ const ordinal = rows.reduce((highest, row) => /^w[1-9][0-9]*$/.test(row.handle)
46
+ ? Math.max(highest, Number(row.handle.slice(1))) : highest, 0) + 1;
47
+ if (!Number.isSafeInteger(ordinal)) throw new RangeError("worker handle space exhausted");
48
+ const handle = `w${ordinal}`;
49
+ const conversation = await this.conversations.create({ role: "worker", ...this.startOptions() });
50
+ const row: WorkerRow = {
51
+ handle, conversationId: conversation.id, createdAt: new Date().toISOString(),
52
+ openedBy: actor.kind === "consumer" ? "consumer" : actor.conversationId,
53
+ ...(actor.kind === "conversation" ? { lastConversation: actor.conversationId } : {}),
54
+ ...(input.about === undefined ? {} : { about: input.about }),
55
+ };
56
+ try {
57
+ await this.workers.create(row);
58
+ } catch (error) {
59
+ try {
60
+ await this.conversations.delete(conversation.id);
61
+ } catch (cleanup) {
62
+ throw new AggregateError([error, cleanup], "worker registration and conversation cleanup failed");
63
+ }
64
+ throw error;
65
+ }
66
+ const slot = this.pool.attach(row, conversation);
67
+ this.emit({ ...this.identity(row), kind: "worker_opened" });
68
+ this.dispatch(slot, actor, input.text, planAssignment(actor, input)!);
69
+ return { status: "sent", handle };
70
+ });
71
+ }
72
+
73
+ send(actor: WorkerActor, handle: string, input: SendWorkerInput): Promise<SendWorkerResult> {
74
+ return this.run(async () => {
75
+ requireWorkerUse(actor);
76
+ this.assertInput(input);
77
+ const row = await this.requireWorker(actor, handle);
78
+ let slot = this.pool.get(handle);
79
+ const running = slot?.work?.assignment;
80
+ const plan = planAssignment(actor, input, running);
81
+ if (!plan || (slot && this.pool.busy(slot) && !running)) return { status: "busy", worker: await this.summary(row) };
82
+ if (running && running.destination !== plan.assignment.destination) requireWorkerRedirect(actor);
83
+ if (!slot) {
84
+ if (!await this.pool.makeRoom(this.evicted)) return { status: "no_worker_free", workers: await this.summaries(actor) };
85
+ const { conversation } = await this.conversations.open(row.conversationId, this.startOptions());
86
+ slot = this.pool.attach(row, conversation);
87
+ this.emit({ ...this.identity(row), kind: "worker_reloaded" });
88
+ }
89
+ const change = {
90
+ ...(input.about === undefined ? {} : { about: input.about }),
91
+ ...(actor.kind === "conversation" ? { lastConversation: actor.conversationId } : {}),
92
+ };
93
+ const workerSlot = slot;
94
+ const update = async () => {
95
+ if (!await this.workers.update(handle, change)) throw new Error(`worker is unavailable: ${handle}`);
96
+ workerSlot.row = { ...workerSlot.row, ...change };
97
+ };
98
+ const redirected = running && running.destination !== plan.assignment.destination;
99
+ if (!redirected) await update();
100
+ this.dispatch(slot, actor, input.text, plan, redirected ? async () => {
101
+ await update();
102
+ const event = { ...this.identity(workerSlot.row), kind: "worker_redirected" as const,
103
+ ...(running.destination ? { previousConversation: running.destination } : {}) };
104
+ return () => this.emit(event);
105
+ } : undefined);
106
+ return { status: running ? "steered" : "sent" };
107
+ });
108
+ }
109
+
110
+ check(actor: WorkerActor, handle: string): Promise<WorkerSummary> {
111
+ return this.run(async () => {
112
+ return this.summary(await this.requireWorker(actor, handle));
113
+ });
114
+ }
115
+
116
+ list(actor: WorkerActor): Promise<readonly WorkerSummary[]> {
117
+ return this.run(async () => {
118
+ return this.summaries(actor);
119
+ });
120
+ }
121
+
122
+ retryDelivery(handle: string): Promise<void> {
123
+ return this.run(async () => {
124
+ const row = await this.requireWorker({ kind: "consumer" }, handle);
125
+ if (!this.assignments?.retryDelivery) throw new Error(`worker ${handle} has no policy-blocked delivery to retry`);
126
+ await this.assignments.retryDelivery(row);
127
+ });
128
+ }
129
+
130
+ stop(actor: WorkerActor, handle: string): Promise<"stopped" | "idle"> {
131
+ return this.run(async () => {
132
+ const row = await this.requireWorker(actor, handle);
133
+ const running = this.pool.get(handle)?.work;
134
+ if (actor.kind === "conversation" && running && running.assignment.destination !== actor.conversationId) {
135
+ requireWorkerRedirect(actor);
136
+ }
137
+ if (!await this.interrupt(handle)) return "idle";
138
+ this.emit({ ...this.identity(row), kind: "worker_stopped", reason: "requested" });
139
+ return "stopped";
140
+ });
141
+ }
142
+
143
+ drop(actor: WorkerActor, handle: string): Promise<DeleteConversationResult> {
144
+ return this.run(async () => {
145
+ requireWorkerRedirect(actor);
146
+ const row = await this.requireWorker(actor, handle, true);
147
+ if (!await this.reconcileWorker(row)) return { providerDeleted: false, checkpointsDeleted: 0 };
148
+ await this.interrupt(handle);
149
+ let result: DeleteConversationResult;
150
+ try {
151
+ result = await this.conversations.delete(row.conversationId, { providerSession: "best-effort" });
152
+ } catch (error) {
153
+ if ((await this.conversations.get(row.conversationId))?.deletedAt) await this.markDropped(row);
154
+ throw error;
155
+ }
156
+ await this.markDropped(row);
157
+ return result;
158
+ });
159
+ }
160
+
161
+ close(): Promise<void> {
162
+ this.closed = true;
163
+ this.pool.closeIdleTimers();
164
+ return this.pool.run(async () => {});
165
+ }
166
+
167
+ async waitForCompletions(): Promise<void> { await Promise.allSettled(this.completions); }
168
+
169
+ private run<T>(work: () => Promise<T>): Promise<T> {
170
+ if (this.closed) return Promise.reject(new Error("orchestrator is closed"));
171
+ return this.pool.run(work);
172
+ }
173
+
174
+ private async markDropped(row: WorkerRow): Promise<void> {
175
+ const dropped = await this.workers.drop(row.handle, new Date().toISOString());
176
+ try {
177
+ await this.pool.release(row.handle);
178
+ } finally {
179
+ if (dropped) this.emit({ ...this.identity(row), kind: "worker_dropped" });
180
+ }
181
+ }
182
+
183
+ private async interrupt(handle: string): Promise<boolean> {
184
+ const slot = this.pool.get(handle);
185
+ if (!slot || !this.pool.busy(slot)) return false;
186
+ slot.conversation.interrupt({ clearQueue: true });
187
+ await Promise.allSettled(slot.completions);
188
+ return true;
189
+ }
190
+
191
+ private identity({ handle, conversationId, openedBy, lastConversation }: WorkerRow) {
192
+ return { handle, conversationId, openedBy, ...(lastConversation ? { lastConversation } : {}) };
193
+ }
194
+
195
+ private startOptions() {
196
+ const { adapterId, cwd } = this.options;
197
+ return {
198
+ adapterId,
199
+ runtime: {
200
+ ...(cwd === undefined ? {} : { cwd }),
201
+ permissions: { default: "ask" as const },
202
+ // The delegated actor owns the worker's decision. Always enter its prompt handler.
203
+ permissionRule: () => "ask" as const,
204
+ },
205
+ };
206
+ }
207
+
208
+ private assertInput(input: WorkerInput): void {
209
+ if (!input.text.trim()) throw new Error("worker prompt cannot be blank");
210
+ }
211
+
212
+ private async requireWorker(actor: WorkerActor, handle: string, allowMissingConversation = false): Promise<WorkerRow> {
213
+ const row = await this.workers.get(handle);
214
+ if (actor.kind === "conversation" && actor.policy.scope === "none" &&
215
+ (!row || !canSeeWorker(actor, row, this.pool.get(handle)?.work?.assignment))) throw new WorkerPolicyError("scope");
216
+ if (!row || row.droppedAt) throw new Error(`unknown active worker: ${handle}`);
217
+ if (!allowMissingConversation && !await this.reconcileWorker(row)) throw new Error(`worker conversation is unavailable: ${handle}`);
218
+ return row;
219
+ }
220
+
221
+ private async summaries(actor: WorkerActor): Promise<readonly WorkerSummary[]> {
222
+ const visible = (await this.activeRows(await this.workers.list()))
223
+ .filter(row => canSeeWorker(actor, row, this.pool.get(row.handle)?.work?.assignment));
224
+ return Promise.all(visible.map(row => this.summary(row)));
225
+ }
226
+
227
+ private async summary(row: WorkerRow): Promise<WorkerSummary> {
228
+ const latest = await this.assignments?.latestOutcome?.(row);
229
+ const result = latest?.assignmentId.startsWith("refused-steer:")
230
+ ? (await this.assignments?.latestResult?.(row))?.outcome : undefined;
231
+ return { ...this.pool.summary(row), ...(latest ? { latestOutcome: latest.outcome, deliveryState: latest.delivery.state } : {}),
232
+ ...(result?.kind === "result" ? { latestResult: result } : {}) };
233
+ }
234
+
235
+ private async activeRows(rows: readonly WorkerRow[]): Promise<WorkerRow[]> {
236
+ const active: WorkerRow[] = [];
237
+ for (const row of rows) {
238
+ if (!row.droppedAt && await this.reconcileWorker(row)) active.push(row);
239
+ }
240
+ return active;
241
+ }
242
+
243
+ private async reconcileWorker(row: WorkerRow): Promise<boolean> {
244
+ const summary = await this.conversations.get(row.conversationId);
245
+ if (summary && !summary.deletedAt) return true;
246
+ await this.markDropped(row);
247
+ return false;
248
+ }
249
+
250
+ private dispatch(
251
+ slot: ReturnType<WorkerPool["attach"]>, actor: WorkerActor, text: string, plan: AssignmentPlan,
252
+ accepted?: () => Promise<() => void>,
253
+ ): void {
254
+ const sender = actor.kind === "conversation" ? actor.sender : undefined;
255
+ const active = this.pool.start(slot, plan.assignment, sender);
256
+ const row = slot.row;
257
+ const identity = this.identity(row);
258
+ if (plan.kind === "start") this.emit({ ...identity, kind: "worker_busy" });
259
+ const policyNames = actor.kind === "conversation" ? [...actor.policyNames] : [];
260
+ let crossedDispatch = false;
261
+ let announceRedirect: (() => void) | undefined;
262
+ const confirmDispatch = () => {
263
+ const announce = announceRedirect;
264
+ announceRedirect = undefined;
265
+ announce?.();
266
+ };
267
+ const input = {
268
+ text,
269
+ handlers: {
270
+ onPermissionRequest: workerPermissionHandler(actor, row, this.findGivingConversation, this.defaultWorkerPermissions),
271
+ ...(accepted ? { onUpdate: confirmDispatch } : {}),
272
+ },
273
+ delivery: plan.kind === "start" ? "queue" as const : "steer" as const,
274
+ ...(actor.kind === "conversation" || accepted ? { beforeDispatch: async (messageId: string) => {
275
+ const assignment = await this.assignments?.beforeDispatch(row, plan, messageId, policyNames, actor.kind === "conversation" ? actor : undefined);
276
+ if (assignment) active.assignment = assignment;
277
+ crossedDispatch = true;
278
+ // Reservation and retarget have committed. Bookkeeping errors must not refuse that accepted dispatch.
279
+ try { announceRedirect = await accepted?.(); }
280
+ catch (error) { this.log.warn("worker_dispatch_bookkeeping_failed", { handle: row.handle, error: String(error) }); }
281
+ } } : {}),
282
+ };
283
+ const work = sender === undefined ? slot.conversation.prompt(input) : slot.conversation.promptFrom({ ...input, participantId: sender });
284
+ const completion = work.then(result => {
285
+ if (result.status === "completed") {
286
+ confirmDispatch();
287
+ this.emit({ ...identity, kind: "worker_replied" });
288
+ } else if (result.status === "error") this.emit({ ...identity, kind: "worker_failed", reason: workerTerminalFailure(false).reason });
289
+ }, async (error: unknown) => {
290
+ this.log.warn("worker_prompt_failed", { conversationId: slot.conversation.id, error: String(error) });
291
+ if (!crossedDispatch && actor.kind === "conversation") {
292
+ const cause = error instanceof WorkerAssignmentConflict ? "conflict" : "hook_error";
293
+ this.emit({ ...identity, kind: "worker_failed", reason: "refused", cause, destination: actor.conversationId });
294
+ try { await this.assignments?.refuse?.(row, plan, { actor, cause }); }
295
+ catch (failure) { this.log.warn("worker_refusal_persistence_failed", { handle: row.handle, error: String(failure) }); }
296
+ return;
297
+ }
298
+ this.emit({ ...identity, kind: "worker_failed", reason: workerTerminalFailure(false, error).reason });
299
+ }).finally(() => {
300
+ slot.completions.delete(completion);
301
+ this.pool.finish(slot, active);
302
+ const touched = slot.touched;
303
+ const idle = () => {
304
+ if (slot.touched !== touched || this.pool.get(row.handle) !== slot || this.pool.busy(slot)) return;
305
+ this.emit({ ...this.identity(slot.row), kind: "worker_idle" });
306
+ this.pool.armIdle(slot, row => this.emit({ ...this.identity(row), kind: "worker_stopped", reason: "idle" }),
307
+ error => this.log.warn("worker_idle_stop_failed", { handle: slot.row.handle, error: String(error) }));
308
+ };
309
+ const flush = actor.kind === "conversation" && this.assignments?.settled?.();
310
+ if (flush) return flush.finally(idle);
311
+ idle();
312
+ });
313
+ slot.completions.add(completion);
314
+ this.completions.add(completion);
315
+ const forget = () => { this.completions.delete(completion); };
316
+ void completion.then(forget, forget);
317
+ }
318
+ }
@@ -0,0 +1,28 @@
1
+ import type { PermissionSettings } from "../permissions/matcher.ts";
2
+ import type { AgentConversationId } from "../agent-ids.ts";
3
+ import { forwardPermission } from "../permissions/conversation.ts";
4
+ import { selectPermissionOutcome, unansweredPermissionOutcome } from "../permissions/outcome.ts";
5
+ import type { WorkerRow } from "../persistence/workers.ts";
6
+ import type { PromptHandlers } from "../types.ts";
7
+ import type { WorkerActor } from "./contracts.ts";
8
+ import { matchWorkerPermissionLevel } from "./policy.ts";
9
+
10
+ export type FindGivingConversation = (id: AgentConversationId) => object | undefined;
11
+
12
+ export function workerPermissionHandler(
13
+ actor: WorkerActor, worker: WorkerRow, findGivingConversation?: FindGivingConversation, defaults: readonly PermissionSettings[] = [],
14
+ ): NonNullable<PromptHandlers["onPermissionRequest"]> {
15
+ return (request, signal) => {
16
+ const policies = actor.kind === "consumer" ? defaults : actor.workerPermissions;
17
+ const level = matchWorkerPermissionLevel(request, policies);
18
+ if (level !== "ask") return selectPermissionOutcome(level, request.options)!;
19
+ const unanswered = policies.some(policy => policy.unanswered === "cancel") ? "cancel" : "reject";
20
+ if (actor.kind === "consumer") return unansweredPermissionOutcome(request.options, unanswered);
21
+ return forwardPermission(findGivingConversation?.(actor.conversationId), request, {
22
+ source: { kind: "worker", handle: worker.handle, conversationId: worker.conversationId },
23
+ includeAllowAlways: actor.isOwner === true,
24
+ unanswered,
25
+ signal,
26
+ });
27
+ };
28
+ }
@@ -0,0 +1,44 @@
1
+ import type { RunningAssignment } from "./assignments.ts";
2
+ import { matchPermissionLevel, mostRestrictivePermissionLevel, type PermissionLevel, type PermissionSettings } from "../permissions/matcher.ts";
3
+ import type { NeutralPermissionRequest } from "../permissions/request.ts";
4
+ import { WorkerPolicyError } from "../errors.ts";
5
+ import type { WorkerRow } from "../persistence/workers.ts";
6
+ import type { DelegationPolicy, WorkerActor } from "./contracts.ts";
7
+
8
+ export function canSeeWorker(actor: WorkerActor, row: WorkerRow, running?: RunningAssignment): boolean {
9
+ return actor.kind === "consumer" || actor.policy.scope === "all"
10
+ || row.openedBy === actor.conversationId || running?.destination === actor.conversationId;
11
+ }
12
+
13
+ export function requireWorkerUse(actor: WorkerActor): void {
14
+ if (actor.kind === "conversation" && !actor.policy.use) throw new WorkerPolicyError("use");
15
+ }
16
+
17
+ export function composeDelegationPolicy(policies: readonly DelegationPolicy[]): DelegationPolicy {
18
+ if (!policies.length) throw new Error("at least one delegation policy is required");
19
+ const cap = Math.min(...policies.map(policy => policy.maxOpen ?? Infinity));
20
+ return {
21
+ use: policies.every(policy => policy.use),
22
+ scope: policies.every(policy => policy.scope === "all") ? "all" : "none",
23
+ redirect: policies.every(policy => policy.redirect),
24
+ ...(cap === Infinity ? {} : { maxOpen: cap }),
25
+ };
26
+ }
27
+
28
+ /** Match within each policy before reducing so each policy uses its own fallback. */
29
+ export function matchWorkerPermissionLevel(
30
+ request: Partial<Pick<NeutralPermissionRequest, "tool">>, policies: readonly PermissionSettings[],
31
+ ): PermissionLevel {
32
+ if (!policies.length) return "ask";
33
+ return policies.map(policy => matchPermissionLevel(request, policy)).reduce(mostRestrictivePermissionLevel);
34
+ }
35
+
36
+ export function requireWorkerRedirect(actor: WorkerActor): void {
37
+ if (actor.kind === "conversation" && !actor.policy.redirect) throw new WorkerPolicyError("redirect");
38
+ }
39
+
40
+ export function checkWorkerOpenLimit(actor: WorkerActor, rows: readonly WorkerRow[]): void {
41
+ if (actor.kind === "consumer" || actor.policy.maxOpen === undefined) return;
42
+ const count = rows.filter(row => row.openedBy === actor.conversationId && row.droppedAt === undefined).length;
43
+ if (count >= actor.policy.maxOpen) throw new WorkerPolicyError("maxOpen");
44
+ }
@@ -0,0 +1,123 @@
1
+ import type { RunningAssignment } from "./assignments.ts";
2
+ import type { AgentConversation } from "../agent-session.ts";
3
+ import type { WorkerRow } from "../persistence/workers.ts";
4
+ import type { WorkerSummary } from "./contracts.ts";
5
+
6
+ interface Slot {
7
+ readonly conversation: AgentConversation;
8
+ row: WorkerRow;
9
+ readonly completions: Set<Promise<void>>;
10
+ touched: number;
11
+ idleTimer?: ReturnType<typeof setTimeout>;
12
+ work?: { readonly started: number; readonly sender?: string; assignment: RunningAssignment };
13
+ }
14
+
15
+ export class WorkerPool {
16
+ private readonly slots = new Map<string, Slot>();
17
+ private tail = Promise.resolve();
18
+ private access = 0;
19
+ private idleTimersClosed = false;
20
+
21
+ constructor(private readonly limit: number, private readonly idleStopMs: number | false) {}
22
+
23
+ run<T>(work: () => Promise<T>): Promise<T> {
24
+ const result = this.tail.then(work);
25
+ this.tail = result.then(() => undefined, () => undefined);
26
+ return result;
27
+ }
28
+
29
+ attach(row: WorkerRow, conversation: AgentConversation): Slot {
30
+ const slot: Slot = { row, conversation, touched: ++this.access, completions: new Set() };
31
+ this.slots.set(row.handle, slot);
32
+ return slot;
33
+ }
34
+
35
+ get(handle: string): Slot | undefined {
36
+ const slot = this.slots.get(handle);
37
+ return slot?.conversation.state.phase === "stopped" ? undefined : slot;
38
+ }
39
+
40
+ async release(handle: string): Promise<void> {
41
+ const slot = this.slots.get(handle);
42
+ if (!slot) return;
43
+ this.cancelIdle(slot);
44
+ try {
45
+ await slot.conversation.stop();
46
+ } finally {
47
+ if (this.slots.get(handle) === slot) this.slots.delete(handle);
48
+ }
49
+ }
50
+
51
+ async makeRoom(onEvicted: (row: WorkerRow) => void): Promise<boolean> {
52
+ for (const [handle, slot] of this.slots) {
53
+ if (slot.conversation.state.phase !== "stopped") continue;
54
+ await this.release(handle);
55
+ }
56
+ if (this.slots.size < this.limit) return true;
57
+ const oldest = [...this.slots.entries()].filter(([, slot]) => !this.busy(slot))
58
+ .sort(([, left], [, right]) => left.touched - right.touched)[0];
59
+ if (!oldest) return false;
60
+ const [handle, slot] = oldest;
61
+ await this.release(handle);
62
+ onEvicted(slot.row);
63
+ return true;
64
+ }
65
+
66
+ busy(slot: Slot): boolean {
67
+ return Boolean(slot.work || slot.completions.size || slot.conversation.isBusy);
68
+ }
69
+
70
+ start(slot: Slot, assignment: RunningAssignment, sender?: string): NonNullable<Slot["work"]> {
71
+ this.cancelIdle(slot);
72
+ slot.touched = ++this.access;
73
+ const started = slot.work?.started ?? performance.now();
74
+ return slot.work = { started, sender, assignment };
75
+ }
76
+
77
+ finish(slot: Slot, work: Slot["work"]): void {
78
+ if (slot.work !== work) return;
79
+ slot.work = undefined;
80
+ slot.touched = ++this.access;
81
+ }
82
+
83
+ armIdle(slot: Slot, onStopped: (row: WorkerRow) => void, onError: (error: unknown) => void): void {
84
+ if (this.idleTimersClosed || this.idleStopMs === false) return;
85
+ this.cancelIdle(slot);
86
+ const handle = slot.row.handle;
87
+ const timer = setTimeout(() => {
88
+ void this.run(async () => {
89
+ // The callback may have entered the queue before a send or teardown cancelled it.
90
+ if (slot.idleTimer !== timer) return;
91
+ slot.idleTimer = undefined;
92
+ if (this.idleTimersClosed || this.get(handle) !== slot || this.busy(slot)) return;
93
+ await this.release(handle);
94
+ onStopped(slot.row);
95
+ }).catch(onError);
96
+ }, this.idleStopMs);
97
+ timer.unref?.();
98
+ slot.idleTimer = timer;
99
+ }
100
+
101
+ closeIdleTimers(): void {
102
+ this.idleTimersClosed = true;
103
+ for (const slot of this.slots.values()) this.cancelIdle(slot);
104
+ }
105
+
106
+ private cancelIdle(slot: Slot): void {
107
+ clearTimeout(slot.idleTimer);
108
+ slot.idleTimer = undefined;
109
+ }
110
+
111
+ summary(row: WorkerRow): WorkerSummary {
112
+ const slot = this.get(row.handle);
113
+ if (!slot) return { ...row, state: "offline" };
114
+ const operation = slot.conversation.state.operation;
115
+ return {
116
+ ...row,
117
+ state: this.busy(slot) ? "busy" : "idle",
118
+ ...(operation ? { operation } : {}),
119
+ ...(slot.work?.sender === undefined ? {} : { sender: slot.work.sender }),
120
+ ...(slot.work ? { busyMs: Math.max(0, performance.now() - slot.work.started) } : {}),
121
+ };
122
+ }
123
+ }
@@ -0,0 +1,11 @@
1
+ /** Used when the delegation route installs the worker send operation. */
2
+ export const WORKER_SEND_DESCRIPTION = [
3
+ "Send work to a worker. Use about to give the worker a short label for check and list.",
4
+ 'A busy send continues its running assignment by default. Set assignment to "new" to interrupt that assignment and start a separate one.',
5
+ "Set redirect to true to take over work from another conversation when policy permits.",
6
+ "Returns immediately without waiting for the worker's reply.",
7
+ '"sent" means work was accepted for a new run (with a handle when opening).',
8
+ '"steered" means a busy worker accepted the input.',
9
+ '"busy" means nothing was sent or queued.',
10
+ '"no_worker_free" means no slot is available and nothing was sent or queued.',
11
+ ].join(" ");
@@ -0,0 +1,18 @@
1
+ import type { RequestPermissionRequest } from "@agentclientprotocol/sdk";
2
+ import type { PermissionRequest } from "../types.ts";
3
+
4
+ /** Project the ACP packet while keeping the existing prompt callback fields and raw packet. */
5
+ export function toPermissionRequest(params: RequestPermissionRequest): PermissionRequest {
6
+ const call = params.toolCall;
7
+ const tool = {
8
+ ...(call?.kind == null ? {} : { kind: call.kind }),
9
+ ...(call?.rawInput === undefined ? {} : { rawInput: call.rawInput }),
10
+ };
11
+ return {
12
+ toolCallId: call?.toolCallId ?? "",
13
+ title: call?.title ?? undefined,
14
+ options: (params.options ?? []).map(({ optionId, name, kind }) => ({ optionId, name, kind })),
15
+ ...(call?.kind != null || call?.rawInput !== undefined ? { tool } : {}),
16
+ raw: params,
17
+ };
18
+ }
@@ -0,0 +1,13 @@
1
+ import type { PermissionRequest } from "../types.ts";
2
+
3
+ export function permissionArrival() {
4
+ return { wallTime: Date.now(), monotonicTime: performance.now() };
5
+ }
6
+ export type PermissionArrival = ReturnType<typeof permissionArrival>;
7
+
8
+ export const acpPermissionArrivals = new WeakMap<PermissionRequest, PermissionArrival>();
9
+
10
+ export function stampAcpPermission(request: PermissionRequest): PermissionRequest {
11
+ acpPermissionArrivals.set(request, permissionArrival());
12
+ return request;
13
+ }
@@ -0,0 +1,19 @@
1
+ export interface PermissionConsumerConfig {
2
+ /** Wait for answerPermission on asks that have no prompt handler. Defaults to false. */
3
+ readonly answersPermissions?: boolean;
4
+ /** Time from request ingress for a consumer to answer. Defaults to five minutes. */
5
+ readonly permissionTimeoutMs?: number;
6
+ }
7
+
8
+ export const DEFAULT_PERMISSION_TIMEOUT_MS = 300_000;
9
+
10
+ export function validatePermissionConsumerConfig(config: PermissionConsumerConfig | undefined): void {
11
+ const answers = config?.answersPermissions;
12
+ if (answers !== undefined && typeof answers !== "boolean") {
13
+ throw new TypeError("answersPermissions must be a boolean");
14
+ }
15
+ const timeout = config?.permissionTimeoutMs;
16
+ if (timeout !== undefined && (!Number.isSafeInteger(timeout) || timeout <= 0 || timeout >= 600_000)) {
17
+ throw new RangeError("permissionTimeoutMs must be a positive integer below 600000");
18
+ }
19
+ }