@code-yeongyu/senpi 2026.10.25-2 → 2026.10.25-3

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 (199) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/bundle/chunks/{args-JXULI4EH.js → args-B444OQBK.js} +1 -1
  3. package/dist/bundle/chunks/{auth-4NUNUSTF.js → auth-C77UQA55.js} +1 -1
  4. package/dist/bundle/chunks/chunk-6O4SEW2W.js +5 -0
  5. package/dist/bundle/chunks/{chunk-Y5OTHMXO.js → chunk-7CNOCJCN.js} +1 -1
  6. package/dist/bundle/chunks/{chunk-JRXKLIEQ.js → chunk-7W7OJDIY.js} +4 -4
  7. package/dist/bundle/chunks/chunk-AX72VNRS.js +27 -0
  8. package/dist/bundle/chunks/{chunk-LYGAV6KU.js → chunk-C5UFJ7B3.js} +1 -1
  9. package/dist/bundle/chunks/{chunk-G2UETS2R.js → chunk-CNL6QSUB.js} +4 -4
  10. package/dist/bundle/chunks/{chunk-2EFVQWXZ.js → chunk-FFQOEC76.js} +3 -3
  11. package/dist/bundle/chunks/chunk-H3HNMY2W.js +13 -0
  12. package/dist/bundle/chunks/{chunk-W2BKZBYJ.js → chunk-HVJI5T75.js} +1 -1
  13. package/dist/bundle/chunks/{chunk-YN7ELQ43.js → chunk-JA2R2ZSE.js} +1 -1
  14. package/dist/bundle/chunks/chunk-JPGT64RV.js +2 -0
  15. package/dist/bundle/chunks/chunk-KXB5WIS5.js +4 -0
  16. package/dist/bundle/chunks/chunk-L73UYAH5.js +3 -0
  17. package/dist/bundle/chunks/chunk-LTU6UFEX.js +2 -0
  18. package/dist/bundle/chunks/{chunk-KUE4AQN6.js → chunk-MJ5NNWX4.js} +1 -1
  19. package/dist/bundle/chunks/{chunk-WFXUCVIR.js → chunk-O3Q2ET6W.js} +2 -5
  20. package/dist/bundle/chunks/{chunk-MXZPAUFB.js → chunk-ODTGC6YU.js} +1 -1
  21. package/dist/bundle/chunks/chunk-P3M2PF6K.js +27 -0
  22. package/dist/bundle/chunks/{chunk-VNN2V74Y.js → chunk-SWJXRC2I.js} +1 -1
  23. package/dist/bundle/chunks/{chunk-RXKNOEQQ.js → chunk-UQNRW3VU.js} +1 -1
  24. package/dist/bundle/chunks/{chunk-U67ML6CQ.js → chunk-WD6WBYC5.js} +1 -1
  25. package/dist/bundle/chunks/chunk-WJOT3DFL.js +2 -0
  26. package/dist/bundle/chunks/{chunk-XBUSVKWC.js → chunk-WLHNEUGD.js} +1 -1
  27. package/dist/bundle/chunks/chunk-YI7SPFDN.js +5 -0
  28. package/dist/bundle/chunks/{chunk-J2U5VDG7.js → chunk-YRF4I43T.js} +28 -28
  29. package/dist/bundle/chunks/chunk-Z3UYNSVR.js +3 -0
  30. package/dist/bundle/chunks/cli-main-HEKFFB5S.js +3 -0
  31. package/dist/bundle/chunks/{client-KWTLTKVV.js → client-WTYEICLH.js} +3 -3
  32. package/dist/bundle/chunks/dispatch-NYAULNVW.js +9 -0
  33. package/dist/bundle/chunks/{help-fast-path-ZHZGXAUG.js → help-fast-path-3Z26DQSV.js} +1 -1
  34. package/dist/bundle/chunks/host-command-Z3WPHJOW.js +2 -0
  35. package/dist/bundle/chunks/host-lifecycle-ONQIMWMX.js +3 -0
  36. package/dist/bundle/chunks/host-lifecycle.js +7 -5
  37. package/dist/bundle/chunks/host-session-command-J65ENSV5.js +20 -0
  38. package/dist/bundle/chunks/{host-socket-request-AS2OCRLP.js → host-socket-request-3CWE4265.js} +1 -1
  39. package/dist/bundle/chunks/interactive-mode-DEPQC6TX.js +2 -0
  40. package/dist/bundle/chunks/mcp-presenter-bootstrap-XUSCQVRC.js +2 -0
  41. package/dist/bundle/chunks/{multi-session-host-VTTY5MFT.js → multi-session-host-YI2WZOET.js} +12 -9
  42. package/dist/bundle/chunks/{package-manager-cli-DZFOC3MF.js → package-manager-cli-GHZPJMRF.js} +1 -1
  43. package/dist/bundle/chunks/{rotation-stream-U7YQMC7H.js → rotation-stream-ZPVCFOVD.js} +1 -1
  44. package/dist/bundle/chunks/rpc-mode-ORHBGBBV.js +2 -0
  45. package/dist/bundle/chunks/{rpc-monitor-source-B5NQ4ZVH.js → rpc-monitor-source-FFEQS744.js} +1 -1
  46. package/dist/bundle/chunks/{schedule-command-SLISTG4V.js → schedule-command-YWG6D6ZF.js} +1 -1
  47. package/dist/bundle/chunks/session-control-endpoint-36HAQSQO.js +3 -0
  48. package/dist/bundle/chunks/{session-picker-465FVXQG.js → session-picker-25H5KNYP.js} +1 -1
  49. package/dist/bundle/chunks/session-worker.js +278 -264
  50. package/dist/bundle/chunks/{stdio-IEC635SY.js → stdio-YXDKKKQZ.js} +1 -1
  51. package/dist/bundle/chunks/{streamableHttp-KJI5KE4K.js → streamableHttp-DKIBUWVY.js} +1 -1
  52. package/dist/bundle/chunks/{types-LLNV23LW.js → types-BJUEQ4II.js} +1 -1
  53. package/dist/bundle/chunks/zod-compat-RJDXCU7S.js +2 -0
  54. package/dist/bundle/cli.js +2 -2
  55. package/dist/bundle/host-supervisor.js +7 -5
  56. package/dist/bundle/index.js +1 -1
  57. package/dist/bundle/rpc-entry.js +1 -1
  58. package/dist/bundle/runtime-manifest.json +1 -1
  59. package/dist/cli/args.d.ts +2 -0
  60. package/dist/cli/args.js +9 -0
  61. package/dist/cli/host-command-args.d.ts +1 -0
  62. package/dist/cli/host-command-args.js +7 -1
  63. package/dist/cli/host-command.js +3 -1
  64. package/dist/core/agent-session.js +22 -7
  65. package/dist/core/extensions/builtin/goal/index.js +1 -0
  66. package/dist/core/extensions/builtin/goal/lifecycle-facts.d.ts +3 -0
  67. package/dist/core/extensions/builtin/mcp/catalog.d.ts +3 -1
  68. package/dist/core/extensions/builtin/mcp/catalog.js +2 -0
  69. package/dist/core/extensions/builtin/mcp/connection.d.ts +1 -0
  70. package/dist/core/extensions/builtin/mcp/connection.js +46 -1
  71. package/dist/core/extensions/builtin/mcp/elicitation.d.ts +6 -1
  72. package/dist/core/extensions/builtin/mcp/elicitation.js +56 -2
  73. package/dist/core/extensions/builtin/mcp/expose/call.js +6 -2
  74. package/dist/core/extensions/builtin/mcp/expose/session.d.ts +4 -1
  75. package/dist/core/extensions/builtin/mcp/expose/session.js +7 -0
  76. package/dist/core/extensions/builtin/mcp/health.js +5 -0
  77. package/dist/core/extensions/builtin/mcp/host-registry.js +7 -1
  78. package/dist/core/extensions/builtin/mcp/index.js +2 -0
  79. package/dist/core/extensions/builtin/mcp/modern/client.d.ts +5 -0
  80. package/dist/core/extensions/builtin/mcp/modern/client.js +15 -0
  81. package/dist/core/extensions/builtin/mcp/modern/consent-queue.d.ts +2 -0
  82. package/dist/core/extensions/builtin/mcp/modern/consent-queue.js +59 -0
  83. package/dist/core/extensions/builtin/mcp/modern/diagnostics.d.ts +4 -0
  84. package/dist/core/extensions/builtin/mcp/modern/diagnostics.js +39 -0
  85. package/dist/core/extensions/builtin/mcp/modern/dispatch.js +21 -11
  86. package/dist/core/extensions/builtin/mcp/modern/elicitation.d.ts +14 -0
  87. package/dist/core/extensions/builtin/mcp/modern/elicitation.js +145 -0
  88. package/dist/core/extensions/builtin/mcp/modern/errors.d.ts +21 -0
  89. package/dist/core/extensions/builtin/mcp/modern/errors.js +23 -0
  90. package/dist/core/extensions/builtin/mcp/modern/form-schema.d.ts +20 -0
  91. package/dist/core/extensions/builtin/mcp/modern/form-schema.js +153 -0
  92. package/dist/core/extensions/builtin/mcp/modern/http-fetch.d.ts +3 -1
  93. package/dist/core/extensions/builtin/mcp/modern/http-fetch.js +8 -2
  94. package/dist/core/extensions/builtin/mcp/modern/inputs.d.ts +11 -0
  95. package/dist/core/extensions/builtin/mcp/modern/inputs.js +65 -0
  96. package/dist/core/extensions/builtin/mcp/modern/parameter-headers.d.ts +11 -0
  97. package/dist/core/extensions/builtin/mcp/modern/parameter-headers.js +109 -0
  98. package/dist/core/extensions/builtin/mcp/modern/request.d.ts +20 -0
  99. package/dist/core/extensions/builtin/mcp/modern/request.js +292 -0
  100. package/dist/core/extensions/builtin/mcp/modern/stdio-probe.d.ts +1 -1
  101. package/dist/core/extensions/builtin/mcp/modern/stdio-probe.js +54 -6
  102. package/dist/core/extensions/builtin/mcp/modern/transport.js +80 -14
  103. package/dist/core/extensions/builtin/mcp/modern/wire.js +11 -7
  104. package/dist/core/extensions/builtin/mcp/prompts.d.ts +5 -1
  105. package/dist/core/extensions/builtin/mcp/prompts.js +6 -1
  106. package/dist/core/extensions/builtin/mcp/request-origin.d.ts +47 -0
  107. package/dist/core/extensions/builtin/mcp/request-origin.js +59 -0
  108. package/dist/core/extensions/builtin/mcp/resources.d.ts +4 -1
  109. package/dist/core/extensions/builtin/mcp/resources.js +19 -4
  110. package/dist/core/extensions/builtin/mcp/sdk.lazy.d.ts +3 -1
  111. package/dist/core/extensions/builtin/mcp/sdk.lazy.js +3 -1
  112. package/dist/core/extensions/builtin/mcp/service-register.d.ts +4 -1
  113. package/dist/core/extensions/builtin/mcp/service-register.js +3 -0
  114. package/dist/core/extensions/builtin/mcp/service-types.d.ts +2 -1
  115. package/dist/core/extensions/builtin/mcp/service.d.ts +1 -0
  116. package/dist/core/extensions/builtin/mcp/service.js +79 -4
  117. package/dist/core/extensions/builtin/mcp/shared-connection.js +36 -2
  118. package/dist/core/extensions/builtin/mcp/shared-lease.d.ts +1 -0
  119. package/dist/core/extensions/builtin/mcp/shared-lease.js +9 -0
  120. package/dist/core/extensions/builtin/mcp/transport-sdk.d.ts +3 -2
  121. package/dist/core/extensions/builtin/mcp/transport-sdk.js +56 -25
  122. package/dist/core/extensions/builtin/mcp/wrap.d.ts +7 -0
  123. package/dist/core/extensions/builtin/mcp/wrap.js +6 -0
  124. package/dist/core/extensions/runner.js +3 -2
  125. package/dist/core/extensions/types.d.ts +2 -0
  126. package/dist/core/lifecycle-ledger.d.ts +1 -0
  127. package/dist/core/lifecycle-ledger.js +7 -2
  128. package/dist/core/lifecycle-record.js +3 -0
  129. package/dist/core/lifecycle-session-binding.d.ts +11 -1
  130. package/dist/core/lifecycle-session-binding.js +29 -2
  131. package/dist/core/lifecycle-stop.d.ts +41 -0
  132. package/dist/core/lifecycle-stop.js +92 -0
  133. package/dist/core/mcp-form-types.d.ts +89 -0
  134. package/dist/core/mcp-form-types.js +23 -0
  135. package/dist/core/mcp-mrtr-presentations.d.ts +15 -0
  136. package/dist/core/mcp-mrtr-presentations.js +17 -0
  137. package/dist/core/session-lifecycle-types.d.ts +15 -0
  138. package/dist/core/session-lifecycle.d.ts +17 -1
  139. package/dist/core/session-lifecycle.js +40 -2
  140. package/dist/main.js +5 -1
  141. package/dist/modes/interactive/components/extension-selector.d.ts +1 -0
  142. package/dist/modes/interactive/components/extension-selector.js +4 -0
  143. package/dist/modes/interactive/interactive-mode.d.ts +4 -0
  144. package/dist/modes/interactive/interactive-mode.js +34 -8
  145. package/dist/modes/interactive/mcp-local-presenter.d.ts +5 -0
  146. package/dist/modes/interactive/mcp-local-presenter.js +109 -0
  147. package/dist/modes/rpc/connection-handler.d.ts +1 -0
  148. package/dist/modes/rpc/connection-handler.js +7 -1
  149. package/dist/modes/rpc/host-capabilities.d.ts +1 -0
  150. package/dist/modes/rpc/host-capabilities.js +2 -1
  151. package/dist/modes/rpc/host-ensure-start.js +13 -2
  152. package/dist/modes/rpc/host-ensure-types.d.ts +2 -0
  153. package/dist/modes/rpc/host-ensure.js +1 -0
  154. package/dist/modes/rpc/host-handoff.d.ts +2 -0
  155. package/dist/modes/rpc/host-handover-wire.d.ts +2 -0
  156. package/dist/modes/rpc/host-handover-wire.js +1 -0
  157. package/dist/modes/rpc/host-lifecycle-launch.d.ts +1 -0
  158. package/dist/modes/rpc/host-lifecycle-launch.js +43 -2
  159. package/dist/modes/rpc/host-runner.d.ts +2 -0
  160. package/dist/modes/rpc/host-runner.js +8 -6
  161. package/dist/modes/rpc/host-successor.js +11 -1
  162. package/dist/modes/rpc/mcp-form-dialog.d.ts +45 -0
  163. package/dist/modes/rpc/mcp-form-dialog.js +159 -0
  164. package/dist/modes/rpc/mcp-form-worker.d.ts +14 -0
  165. package/dist/modes/rpc/mcp-form-worker.js +167 -0
  166. package/dist/modes/rpc/mcp-presenter-authority.d.ts +53 -0
  167. package/dist/modes/rpc/mcp-presenter-authority.js +309 -0
  168. package/dist/modes/rpc/mcp-presenter-bootstrap.d.ts +8 -0
  169. package/dist/modes/rpc/mcp-presenter-bootstrap.js +111 -0
  170. package/dist/modes/rpc/mcp-presenter-control.d.ts +24 -0
  171. package/dist/modes/rpc/mcp-presenter-control.js +330 -0
  172. package/dist/modes/rpc/multi-session-host.d.ts +3 -0
  173. package/dist/modes/rpc/multi-session-host.js +36 -1
  174. package/dist/modes/rpc/session-binding.js +6 -1
  175. package/dist/modes/rpc/session-event-writer.d.ts +14 -0
  176. package/dist/modes/rpc/session-event-writer.js +128 -1
  177. package/dist/modes/rpc/session-router-routing.js +1 -0
  178. package/dist/modes/rpc/session-worker-client.d.ts +3 -0
  179. package/dist/modes/rpc/session-worker-client.js +89 -0
  180. package/dist/modes/rpc/session-worker-protocol.d.ts +41 -0
  181. package/dist/modes/rpc/session-worker.js +9 -0
  182. package/docs/extensions.md +5 -0
  183. package/docs/mcp.md +20 -3
  184. package/docs/rpc.md +111 -0
  185. package/package.json +6 -6
  186. package/dist/bundle/chunks/chunk-B6TPQDBW.js +0 -5
  187. package/dist/bundle/chunks/chunk-CDRFFHLL.js +0 -4
  188. package/dist/bundle/chunks/chunk-HPCS4HM4.js +0 -27
  189. package/dist/bundle/chunks/chunk-KJZAY5YH.js +0 -27
  190. package/dist/bundle/chunks/chunk-OI4NMCKP.js +0 -3
  191. package/dist/bundle/chunks/chunk-SCVRKIFK.js +0 -2
  192. package/dist/bundle/chunks/cli-main-SWKFMTZQ.js +0 -3
  193. package/dist/bundle/chunks/dispatch-DEP4PEDZ.js +0 -10
  194. package/dist/bundle/chunks/host-command-BC6UWP33.js +0 -2
  195. package/dist/bundle/chunks/host-lifecycle-TN5NEGNF.js +0 -3
  196. package/dist/bundle/chunks/host-session-command-MGVBLBRV.js +0 -20
  197. package/dist/bundle/chunks/interactive-mode-SCSROHD5.js +0 -2
  198. package/dist/bundle/chunks/rpc-mode-TOXYD4XA.js +0 -2
  199. package/dist/bundle/chunks/session-control-endpoint-HFFMBALG.js +0 -3
@@ -0,0 +1,45 @@
1
+ import type { McpFormInput, McpFormOutcome, McpFormRequest, McpFormResolved } from "../../core/mcp-form-types.ts";
2
+ export interface McpFormClock {
3
+ now(): number;
4
+ schedule(callback: () => void, delay: number): object;
5
+ cancel(timer: object): void;
6
+ }
7
+ export declare const mcpFormClock: McpFormClock;
8
+ type Termination = "presentation_lost" | "presentation_timeout" | "operation_aborted";
9
+ export type McpPresenterReply = {
10
+ readonly ok: true;
11
+ readonly form?: McpFormRequest;
12
+ } | {
13
+ readonly error: "presenter_not_authorized" | "invalid_form_response" | "form_stale" | "form_expired";
14
+ };
15
+ /** One private entry. Lifecycle closures retain this object even after its grant is removed. */
16
+ export declare class McpFormDialog {
17
+ readonly result: Promise<McpFormOutcome>;
18
+ readonly deadline: number;
19
+ private stage;
20
+ private request;
21
+ private readonly token;
22
+ private readonly cleanups;
23
+ private resolve;
24
+ private readonly input;
25
+ private readonly context;
26
+ constructor(input: McpFormInput, context: {
27
+ readonly clock: McpFormClock;
28
+ readonly envelope: Omit<McpFormRequest, "type" | "server" | "message" | "schema" | "deadlineAtMs" | "dialogToken">;
29
+ readonly current: () => boolean;
30
+ readonly remove: () => void;
31
+ readonly admit: () => void;
32
+ readonly send: (frame: McpFormRequest | McpFormResolved) => boolean;
33
+ });
34
+ start(): void;
35
+ sync(): McpFormRequest | undefined;
36
+ matches(token: string, revision: string): boolean;
37
+ presented(): McpPresenterReply;
38
+ respond(action: string, content: unknown): McpPresenterReply;
39
+ /** Internal-only: never called with a cause or entry reference decoded from RPC. */
40
+ terminate(cause: Termination): void;
41
+ private live;
42
+ private commit;
43
+ }
44
+ export {};
45
+ //# sourceMappingURL=mcp-form-dialog.d.ts.map
@@ -0,0 +1,159 @@
1
+ import { randomBytes, timingSafeEqual } from "node:crypto";
2
+ import { validMcpFormContent } from "../../core/extensions/builtin/mcp/modern/form-schema.js";
3
+ export const mcpFormClock = {
4
+ now: () => performance.now(),
5
+ schedule: (callback, delay) => setTimeout(callback, delay),
6
+ cancel: (timer) => {
7
+ if ("close" in timer && typeof timer.close === "function")
8
+ timer.close();
9
+ },
10
+ };
11
+ /** One private entry. Lifecycle closures retain this object even after its grant is removed. */
12
+ export class McpFormDialog {
13
+ constructor(input, context) {
14
+ this.stage = "prepared";
15
+ this.token = randomBytes(32);
16
+ this.cleanups = [];
17
+ this.resolve = () => { };
18
+ this.input = input;
19
+ this.context = context;
20
+ this.deadline = context.clock.now() + Math.max(0, input.deadlineMs);
21
+ this.result = new Promise((resolve) => {
22
+ this.resolve = resolve;
23
+ });
24
+ this.request = {
25
+ ...context.envelope,
26
+ type: "mcp_form_request",
27
+ dialogToken: this.token.toString("hex"),
28
+ server: structuredClone(input.server),
29
+ message: input.message,
30
+ schema: structuredClone(input.schema),
31
+ deadlineAtMs: Date.now() + Math.max(0, input.deadlineMs),
32
+ };
33
+ }
34
+ start() {
35
+ const watch = (signal, cause) => {
36
+ const stop = () => this.terminate(cause);
37
+ signal.addEventListener("abort", stop, { once: true });
38
+ this.cleanups.push(() => signal.removeEventListener("abort", stop));
39
+ if (signal.aborted)
40
+ stop();
41
+ };
42
+ watch(this.input.operationSignal, "operation_aborted");
43
+ watch(this.input.presentationSignal, "presentation_lost");
44
+ if (this.stage === "settled") {
45
+ for (const cleanup of this.cleanups.splice(0))
46
+ cleanup();
47
+ return;
48
+ }
49
+ const timer = this.context.clock.schedule(() => this.terminate("presentation_timeout"), this.input.deadlineMs);
50
+ this.cleanups.push(() => this.context.clock.cancel(timer));
51
+ if (!this.context.current() || !this.request || !this.context.send(this.request))
52
+ this.terminate("presentation_lost");
53
+ }
54
+ sync() {
55
+ if (!this.live())
56
+ return undefined;
57
+ return this.request === undefined ? undefined : structuredClone(this.request);
58
+ }
59
+ matches(token, revision) {
60
+ return (this.request?.formRevision === revision &&
61
+ /^[a-f0-9]{64}$/.test(token) &&
62
+ timingSafeEqual(this.token, Buffer.from(token, "hex")));
63
+ }
64
+ presented() {
65
+ if (!this.live())
66
+ return { error: "form_expired" };
67
+ this.stage = "presented";
68
+ return { ok: true };
69
+ }
70
+ respond(action, content) {
71
+ if (!this.live())
72
+ return { error: "form_expired" };
73
+ if (this.stage !== "presented" || !this.request)
74
+ return { error: "invalid_form_response" };
75
+ let result;
76
+ switch (action) {
77
+ case "accept":
78
+ if (!validMcpFormContent(this.request.schema, content) ||
79
+ Buffer.byteLength(JSON.stringify(content)) > 1024 * 1024)
80
+ return { error: "invalid_form_response" };
81
+ result = { action, content: structuredClone(content) };
82
+ break;
83
+ case "decline":
84
+ case "cancel":
85
+ if (content !== undefined)
86
+ return { error: "invalid_form_response" };
87
+ result = { action };
88
+ break;
89
+ default:
90
+ return { error: "invalid_form_response" };
91
+ }
92
+ if (!this.live())
93
+ return { error: "form_expired" };
94
+ this.commit({ kind: "result", result, source: "presenter_action", humanAdmission: true });
95
+ return { ok: true };
96
+ }
97
+ /** Internal-only: never called with a cause or entry reference decoded from RPC. */
98
+ terminate(cause) {
99
+ const provenance = { source: "host_termination", humanAdmission: false };
100
+ if (cause === "operation_aborted" ||
101
+ this.input.operationSignal.aborted ||
102
+ this.input.operationCurrent?.() === false) {
103
+ this.commit({ kind: "operation_aborted", ...provenance });
104
+ }
105
+ else if (this.stage === "presented") {
106
+ this.commit({ kind: "result", result: { action: "cancel" }, ...provenance });
107
+ }
108
+ else {
109
+ this.commit({ kind: "processing_failure", ...provenance });
110
+ }
111
+ }
112
+ live() {
113
+ if (this.stage === "settled")
114
+ return false;
115
+ if (this.input.operationSignal.aborted || this.input.operationCurrent?.() === false) {
116
+ this.terminate("operation_aborted");
117
+ return false;
118
+ }
119
+ if (this.context.clock.now() >= this.deadline || !this.context.current()) {
120
+ this.terminate("presentation_timeout");
121
+ return false;
122
+ }
123
+ return true;
124
+ }
125
+ commit(outcome) {
126
+ if (this.stage === "settled")
127
+ return;
128
+ this.stage = "settled";
129
+ const request = this.request;
130
+ this.request = undefined;
131
+ this.token.fill(0);
132
+ this.context.remove();
133
+ for (const cleanup of this.cleanups.splice(0))
134
+ cleanup();
135
+ // No callback, promise resolution or admission precedes the synchronous terminal claim.
136
+ if (outcome.humanAdmission)
137
+ this.context.admit();
138
+ this.resolve(outcome);
139
+ if (request && this.context.current()) {
140
+ const reason = outcome.kind === "result"
141
+ ? outcome.result.action === "accept"
142
+ ? "answered"
143
+ : outcome.result.action === "decline"
144
+ ? "declined"
145
+ : "cancelled"
146
+ : outcome.kind === "operation_aborted"
147
+ ? "operation_aborted"
148
+ : "processing_failed";
149
+ this.context.send({
150
+ type: "mcp_form_resolved",
151
+ sessionId: request.sessionId,
152
+ grantId: request.grantId,
153
+ dialogId: request.dialogId,
154
+ reason,
155
+ });
156
+ }
157
+ }
158
+ }
159
+ //# sourceMappingURL=mcp-form-dialog.js.map
@@ -0,0 +1,14 @@
1
+ import type { HostToSessionWorker, SessionWorkerToHost } from "./session-worker-protocol.ts";
2
+ /** Private worker messages never pass through WorkerEventWriter.enqueue or a snapshot. */
3
+ export declare class McpFormWorker {
4
+ private readonly send;
5
+ private readonly binds;
6
+ private readonly ready;
7
+ private readonly settlements;
8
+ private readonly bindings;
9
+ private readonly entries;
10
+ constructor(send: (message: SessionWorkerToHost) => void);
11
+ bind(durableId: string, ui: object, admit: () => void): Promise<() => void>;
12
+ receive(message: HostToSessionWorker): boolean;
13
+ }
14
+ //# sourceMappingURL=mcp-form-worker.d.ts.map
@@ -0,0 +1,167 @@
1
+ import { randomUUID } from "node:crypto";
2
+ import { bindPrivateMcpForms } from "../../core/mcp-form-types.js";
3
+ /** Private worker messages never pass through WorkerEventWriter.enqueue or a snapshot. */
4
+ export class McpFormWorker {
5
+ constructor(send) {
6
+ this.binds = new Map();
7
+ this.ready = new Map();
8
+ this.settlements = new Set();
9
+ this.bindings = new Map();
10
+ this.entries = new Map();
11
+ this.send = send;
12
+ }
13
+ async bind(durableId, ui, admit) {
14
+ const id = randomUUID();
15
+ const bound = Promise.withResolvers();
16
+ this.binds.set(id, bound.resolve);
17
+ const timer = setTimeout(() => bound.reject(new Error("private_form_unavailable")), 5_000);
18
+ timer.unref();
19
+ let message;
20
+ try {
21
+ this.send({ type: "mcp_form_bind", id, durableId });
22
+ message = await bound.promise;
23
+ }
24
+ finally {
25
+ clearTimeout(timer);
26
+ this.binds.delete(id);
27
+ }
28
+ const lifetime = new AbortController();
29
+ const state = { version: message.version, active: true, admit, listeners: new Set() };
30
+ this.bindings.set(message.epoch, state);
31
+ const binding = {
32
+ epoch: message.epoch,
33
+ signal: lifetime.signal,
34
+ subscribe: (listener) => {
35
+ state.listeners.add(listener);
36
+ return () => {
37
+ state.listeners.delete(listener);
38
+ };
39
+ },
40
+ capture: () => {
41
+ const version = state.version;
42
+ if (!state.active || version === undefined)
43
+ return undefined;
44
+ return {
45
+ signal: new AbortController().signal,
46
+ ready: () => state.active && state.version === version,
47
+ synchronize: () => {
48
+ const request = randomUUID();
49
+ const answer = new Promise((resolve) => this.ready.set(request, resolve));
50
+ this.send({ type: "mcp_form_ready", id: request, epoch: message.epoch });
51
+ return answer;
52
+ },
53
+ present: (input) => new Promise((resolve) => {
54
+ const request = randomUUID();
55
+ const operationFence = new SharedArrayBuffer(4);
56
+ const fence = new Int32Array(operationFence);
57
+ const cancelOperation = () => {
58
+ Atomics.store(fence, 0, 1);
59
+ this.send({
60
+ type: "mcp_form_cancel",
61
+ id: request,
62
+ epoch: message.epoch,
63
+ lifetime: "operation",
64
+ });
65
+ };
66
+ const cancelPresentation = () => this.send({
67
+ type: "mcp_form_cancel",
68
+ id: request,
69
+ epoch: message.epoch,
70
+ lifetime: "presentation",
71
+ });
72
+ input.operationSignal.addEventListener("abort", cancelOperation, { once: true });
73
+ input.presentationSignal.addEventListener("abort", cancelPresentation, { once: true });
74
+ this.entries.set(request, {
75
+ epoch: message.epoch,
76
+ resolve,
77
+ fence,
78
+ cleanup: () => {
79
+ input.operationSignal.removeEventListener("abort", cancelOperation);
80
+ input.presentationSignal.removeEventListener("abort", cancelPresentation);
81
+ },
82
+ });
83
+ const { operationSignal, presentationSignal, operationCurrent: _current, ...wire } = input;
84
+ if (operationSignal.aborted)
85
+ Atomics.store(fence, 0, 1);
86
+ this.send({
87
+ type: "mcp_form_create",
88
+ id: request,
89
+ epoch: message.epoch,
90
+ version,
91
+ operationFence,
92
+ input: wire,
93
+ });
94
+ if (operationSignal.aborted)
95
+ cancelOperation();
96
+ if (presentationSignal.aborted)
97
+ cancelPresentation();
98
+ }),
99
+ };
100
+ },
101
+ dispose: () => {
102
+ lifetime.abort();
103
+ state.active = false;
104
+ for (const entry of this.entries.values())
105
+ if (entry.epoch === message.epoch)
106
+ Atomics.store(entry.fence, 0, 1);
107
+ this.bindings.delete(message.epoch);
108
+ state.listeners.clear();
109
+ this.send({ type: "mcp_form_release", epoch: message.epoch });
110
+ },
111
+ };
112
+ bindPrivateMcpForms(ui, binding);
113
+ return binding.dispose;
114
+ }
115
+ receive(message) {
116
+ switch (message.type) {
117
+ case "mcp_form_bound": {
118
+ const resolve = this.binds.get(message.id);
119
+ if (resolve)
120
+ resolve(message);
121
+ else
122
+ this.send({ type: "mcp_form_release", epoch: message.epoch });
123
+ this.binds.delete(message.id);
124
+ return true;
125
+ }
126
+ case "mcp_form_availability": {
127
+ const binding = this.bindings.get(message.epoch);
128
+ if (binding && binding.version !== message.version) {
129
+ binding.version = message.version;
130
+ for (const listener of binding.listeners)
131
+ listener();
132
+ }
133
+ if (message.id) {
134
+ this.ready.get(message.id)?.();
135
+ this.ready.delete(message.id);
136
+ }
137
+ return true;
138
+ }
139
+ case "mcp_form_settlement": {
140
+ const entry = this.entries.get(message.id);
141
+ if (!entry || entry.epoch !== message.epoch || this.settlements.has(message.settlementId))
142
+ return true;
143
+ this.settlements.add(message.settlementId);
144
+ if (this.settlements.size > 256) {
145
+ const oldest = this.settlements.values().next().value;
146
+ if (oldest !== undefined)
147
+ this.settlements.delete(oldest);
148
+ }
149
+ this.entries.delete(message.id);
150
+ entry.cleanup();
151
+ const binding = this.bindings.get(message.epoch);
152
+ if (!binding?.active) {
153
+ entry.resolve({ kind: "operation_aborted", source: "host_termination", humanAdmission: false });
154
+ return true;
155
+ }
156
+ // Host-only union provenance, never inferred from cancel/decline/accept alone.
157
+ if (message.outcome.source === "presenter_action" && message.outcome.humanAdmission)
158
+ binding.admit();
159
+ entry.resolve(message.outcome);
160
+ return true;
161
+ }
162
+ default:
163
+ return false;
164
+ }
165
+ }
166
+ }
167
+ //# sourceMappingURL=mcp-form-worker.js.map
@@ -0,0 +1,53 @@
1
+ import type { McpFormBinding, McpFormRequest, McpFormResolved, McpFormScope } from "../../core/mcp-form-types.ts";
2
+ import { type McpFormClock, type McpPresenterReply } from "./mcp-form-dialog.ts";
3
+ type Sender = (frame: McpFormRequest | McpFormResolved) => boolean;
4
+ export interface McpPresenterConnection {
5
+ readonly id: string;
6
+ readonly epoch: string;
7
+ readonly nonce: string;
8
+ }
9
+ export interface McpPresenterRegistration {
10
+ readonly id: string;
11
+ }
12
+ /** Host-owned only. No public session command can call enrollment or install a registration. */
13
+ export declare class McpPresenterAuthority {
14
+ readonly instance: `${string}-${string}-${string}-${string}-${string}`;
15
+ private readonly clock;
16
+ private readonly connections;
17
+ private readonly bindings;
18
+ private readonly registrations;
19
+ constructor(options?: {
20
+ readonly clock?: McpFormClock;
21
+ });
22
+ dispose(): void;
23
+ connect(id: string, send: Sender): McpPresenterConnection;
24
+ attach(sender: McpPresenterConnection, handle: McpFormBinding): void;
25
+ connectionContext(sender: McpPresenterConnection, sessionId: string): {
26
+ hostInstance: string;
27
+ connectionNonce: string;
28
+ bindingEpoch: string;
29
+ attachmentId: string;
30
+ attachmentEpoch: string;
31
+ } | undefined;
32
+ detach(sender: McpPresenterConnection, handle?: McpFormBinding): void;
33
+ withdraw(sender: McpPresenterConnection): void;
34
+ bind(sessionId: string, durableId: string, admit: () => void): McpFormBinding;
35
+ /** Called only after the protected bootstrap has pinned and authenticated its launch principal. */
36
+ enroll(principal?: string): {
37
+ register: (handle: McpFormBinding, sender: McpPresenterConnection, options: {
38
+ readonly kind: McpFormScope["presenterKind"];
39
+ }) => McpPresenterRegistration;
40
+ acquire: (handle: McpPresenterRegistration) => {
41
+ readonly grantId: string;
42
+ readonly scope: McpFormScope;
43
+ };
44
+ revoke: (handle: McpPresenterRegistration) => void;
45
+ };
46
+ receive(sender: McpPresenterConnection, value: unknown): McpPresenterReply;
47
+ private current;
48
+ private revoke;
49
+ private presentation;
50
+ private present;
51
+ }
52
+ export {};
53
+ //# sourceMappingURL=mcp-presenter-authority.d.ts.map