@mostra/protocol 0.6.2 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +12 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js.map +1 -1
- package/dist/bridge.d.ts +25 -0
- package/dist/bridge.d.ts.map +1 -1
- package/dist/bridge.js +32 -2
- package/dist/bridge.js.map +1 -1
- package/dist/browser.d.ts +76 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +45 -2
- package/dist/browser.js.map +1 -1
- package/dist/diagnostics/codes/hygiene.d.ts +1 -1
- package/dist/diagnostics/codes/hygiene.d.ts.map +1 -1
- package/dist/diagnostics/codes/hygiene.js +12 -1
- package/dist/diagnostics/codes/hygiene.js.map +1 -1
- package/dist/diagnostics/codes/index.d.ts +3 -2
- package/dist/diagnostics/codes/index.d.ts.map +1 -1
- package/dist/diagnostics/codes/index.js +3 -1
- package/dist/diagnostics/codes/index.js.map +1 -1
- package/dist/diagnostics/codes/share.d.ts +8 -0
- package/dist/diagnostics/codes/share.d.ts.map +1 -0
- package/dist/diagnostics/codes/share.js +88 -0
- package/dist/diagnostics/codes/share.js.map +1 -0
- package/dist/hygiene.d.ts.map +1 -1
- package/dist/hygiene.js +2 -1
- package/dist/hygiene.js.map +1 -1
- package/dist/ids.d.ts +5 -1
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +3 -1
- package/dist/ids.js.map +1 -1
- package/dist/index.d.ts +10 -5
- package/dist/index.js +9 -4
- package/dist/methods/index.d.ts.map +1 -1
- package/dist/methods/index.js +9 -1
- package/dist/methods/index.js.map +1 -1
- package/dist/methods/instance/status.d.ts +24 -0
- package/dist/methods/instance/status.d.ts.map +1 -1
- package/dist/methods/instance/status.js +11 -2
- package/dist/methods/instance/status.js.map +1 -1
- package/dist/methods/port/addressing-external-base.d.ts +52 -0
- package/dist/methods/port/addressing-external-base.d.ts.map +1 -0
- package/dist/methods/port/addressing-external-base.js +61 -0
- package/dist/methods/port/addressing-external-base.js.map +1 -0
- package/dist/methods/share/list.d.ts +23 -0
- package/dist/methods/share/list.d.ts.map +1 -0
- package/dist/methods/share/list.js +29 -0
- package/dist/methods/share/list.js.map +1 -0
- package/dist/methods/share/start.d.ts +96 -0
- package/dist/methods/share/start.d.ts.map +1 -0
- package/dist/methods/share/start.js +73 -0
- package/dist/methods/share/start.js.map +1 -0
- package/dist/methods/share/stop.d.ts +29 -0
- package/dist/methods/share/stop.d.ts.map +1 -0
- package/dist/methods/share/stop.js +32 -0
- package/dist/methods/share/stop.js.map +1 -0
- package/package.json +2 -2
- package/schemas/protocol.draft-07.json +535 -0
- package/schemas/protocol.schema.json +507 -0
- package/src/actions.ts +12 -0
- package/src/bridge.ts +49 -0
- package/src/browser.ts +118 -0
- package/src/diagnostics/codes/hygiene.ts +12 -0
- package/src/diagnostics/codes/index.ts +6 -2
- package/src/diagnostics/codes/share.ts +100 -0
- package/src/hygiene.ts +1 -0
- package/src/ids.ts +9 -1
- package/src/index.ts +39 -0
- package/src/methods/index.ts +8 -0
- package/src/methods/instance/status.ts +38 -0
- package/src/methods/port/addressing-external-base.ts +113 -0
- package/src/methods/share/list.ts +42 -0
- package/src/methods/share/start.ts +150 -0
- package/src/methods/share/stop.ts +50 -0
package/dist/actions.d.ts
CHANGED
|
@@ -139,6 +139,13 @@ export interface LiveState {
|
|
|
139
139
|
}[];
|
|
140
140
|
/** The producer's last failure, while the last good value stays (FAILURE_MODEL §6). */
|
|
141
141
|
readonly error?: WireError;
|
|
142
|
+
/**
|
|
143
|
+
* `true` while the source has no value and no failure and the artifact's latest version has a
|
|
144
|
+
* producer whose first `load` is on its way: the page shows it loading, and verify waits for it.
|
|
145
|
+
* Absent for a key nothing produces (one only `mostra push` writes) and for a source that only
|
|
146
|
+
* streams, whose first value may never come (WP-14's Opus review).
|
|
147
|
+
*/
|
|
148
|
+
readonly awaiting?: boolean;
|
|
142
149
|
}
|
|
143
150
|
/** One live update on the event stream: never stored as an event (D63, LL-04). */
|
|
144
151
|
export interface LiveUpdate {
|
|
@@ -152,6 +159,11 @@ export interface LiveUpdate {
|
|
|
152
159
|
readonly value?: Batches;
|
|
153
160
|
/** What went wrong. */
|
|
154
161
|
readonly error?: WireError;
|
|
162
|
+
/**
|
|
163
|
+
* `false` when a source read as {@link LiveState.awaiting} turned out to have no first `load`
|
|
164
|
+
* (its producer only streams): the page stops waiting for a first value.
|
|
165
|
+
*/
|
|
166
|
+
readonly awaiting?: boolean;
|
|
155
167
|
}
|
|
156
168
|
/**
|
|
157
169
|
* An ephemeral message on a page's event stream (SSE `event: run` or `event: live`, without an
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","names":[],"sources":["../src/actions.ts"],"mappings":";;;;YAgBY,6BAA6B;;;;;qBAM5B,SAAS,EAAE,QAAQ;;iBASf,oBAAoB;;WAE1B;;;qBAIE,aAAa,EAAE,QAAQ;;qBAYvB;;qBAGA;;qBAGA;;qBAGA;;qBAGA;;;;;;;YAQD;;qBAGC,uBAAuB;;wBAUpB,iBAAiB,QAAQ;;;;;;;YAU7B;;iBAGK;;WAEN;;WAEA;;;qBAIE,aAAa,EAAE,QAAQ;;;;;iBAcnB;;WAEN;;WAEA;;WAEA;;WAEA,QAAQ;;WAER,SAAS;;WAET,WAAW;;WAEX;;WAEA,SAAS;;WAET,QAAQ;;WAER;;WAEA;;WAEA;;;;;WAKA;;WAEA;;;qBAIE,UAAU,EAAE,QAAQ;;;;;;iBA2BhB;;WAEN;;WAEA,QAAQ;;WAER,SAAS;;WAET,WAAW;;WAEX;;WAEA;;WAEA;;WAEA,SAAS;;WAET,QAAQ;;WAER;;;iBAIM;;WAEN;;WAEA;;WAEA;;WAEA,QAAQ;;;;;WAKR;aACE;aACA;aACA,OAAO;;;WAGT,QAAQ;;;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","names":[],"sources":["../src/actions.ts"],"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;;;WAKA;aACE;aACA;aACA;;;;qBAKA,aAAa,EAAE,QAAQ;;qBAoBvB,qBAAqB;;qBAGrB"}
|
package/dist/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.js","names":[],"sources":["../src/actions.ts"],"sourcesContent":["/**\n * Actions, live data and secrets (INTERFACES §2.4, §4, §6; D24, D44, D54, D56): the shapes the\n * browser protocol, the host protocol and the worker channel share. Server-function arguments and\n * results travel as the serializer's batches (`Batches`).\n *\n * ```ts\n * const run: RunState = await post(\"runs\", { viewId, fnId: \"actions.ts#sendReply\", args, clientKey });\n * if (run.status === \"succeeded\") show(await deserializeAll(run.batches));\n * ```\n */\nimport * as z from \"zod\";\nimport { ViewId } from \"./ids.ts\";\nimport type { Frame, WireError } from \"./serializer.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** A value written by the serializer: its batches, in order (`serializeAll`). */\nexport type Batches = readonly (readonly Frame[])[];\n\n/**\n * The Zod schema of the `Batches` type: a list of batches, each a list of frames. The frames\n * themselves are checked by the reader (`ValueReader`), which refuses anything malformed.\n */\nexport const Batches: z.ZodType<Batches> = z\n .array(z.array(z.record(z.string(), z.unknown())).readonly())\n .readonly()\n .register(wireRegistry, {\n id: \"Batches\",\n description: \"A serialized server-function value: its batches of frames, in order.\",\n }) as unknown as z.ZodType<Batches>;\n\n/** An error as runs, calls and live sources report it. */\nexport interface ActionError extends WireError {\n /** The stack of the thrown error, kept in the run log and never sent to a page. */\n readonly stack?: string;\n}\n\n/** The Zod schema of the `ActionError` type. */\nexport const ActionError: z.ZodType<ActionError> = z\n .object({\n message: z.string(),\n code: z.string().exactOptional(),\n stack: z.string().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"ActionError\",\n description: \"An error from server code: its message and diagnostic code.\",\n });\n\n/** The largest serialized arguments a call or run takes, in characters of JSON. */\nexport const ACTION_ARGS_MAX: number = 16 * 1024 * 1024;\n\n/** The largest serialized result a run keeps, in characters of JSON (larger fails the run). */\nexport const ACTION_RESULT_MAX: number = 16 * 1024 * 1024;\n\n/** The cap of a run's log, in UTF-16 code units of its lines (D47's 1 MB). */\nexport const RUN_LOG_MAX: number = 1024 * 1024;\n\n/** The line a capped log ends with. */\nexport const RUN_LOG_TRUNCATED = \"[log truncated at 1 MB]\";\n\n/** The longest run key, in characters. */\nexport const RUN_KEY_MAX = 256;\n\n/**\n * A run's state (D24, ARCHITECTURE §7). `queued`: recorded, not yet started in a worker.\n * `running`: started. `waiting` is reserved for a remote server's run that waits for its owner's\n * instance (WP-28, D117); a page that doesn't know it treats it like `queued`. The others are\n * final.\n */\nexport type RunStatus = \"queued\" | \"running\" | \"waiting\" | \"succeeded\" | \"failed\" | \"cancelled\";\n\n/** Every run status. */\nexport const RUN_STATUSES: readonly RunStatus[] = [\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n];\n\n/** Whether a run in `status` has ended. */\nexport function isFinalRunStatus(status: RunStatus): boolean {\n return status === \"succeeded\" || status === \"failed\" || status === \"cancelled\";\n}\n\n/**\n * Why a run ended the way it did, beside its status: `interrupted` (its worker or the instance\n * stopped while it ran, D24), `threw` (the action threw), `unserializable` (its result is outside\n * the type set), `too-large`, `parked` (its artifact's worker keeps crashing), `cancelled` (by a\n * viewer), `unknown-function`. Later releases add reasons.\n */\nexport type RunReason = string;\n\n/** A run's progress, as the action last reported it. */\nexport interface RunProgress {\n /** From 0 to 1. */\n readonly fraction?: number;\n /** One short line for people. */\n readonly message?: string;\n}\n\n/** The Zod schema of the `RunProgress` type. */\nexport const RunProgress: z.ZodType<RunProgress> = z\n .object({\n fraction: z.number().min(0).max(1).exactOptional(),\n message: z.string().max(1000).exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RunProgress\",\n description: \"A run's progress: fraction and message.\",\n });\n\n/**\n * One action run as a page reads it (D54): its state, progress, log and the result written so far.\n * A result that is an async iterable grows item by item while the run is `running`.\n */\nexport interface RunState {\n /** The run's `run_` ID. */\n readonly runId: string;\n /** The server function it runs: `<module path>#<export>`. */\n readonly fnId: string;\n /** The idempotency key it was started with, if any. */\n readonly key?: string;\n /** The run's state. */\n readonly status: RunStatus;\n /** Why it ended, for `failed` and `cancelled`. */\n readonly reason?: RunReason;\n /** Its latest progress. */\n readonly progress?: RunProgress;\n /** The log lines, capped at 1 MB with a marker line. */\n readonly log: readonly string[];\n /** The result's batches so far. */\n readonly batches: Batches;\n /** For `failed`: what went wrong, without the stack. */\n readonly error?: WireError;\n /** When it was recorded. */\n readonly startedAt: string;\n /** When it ended. */\n readonly finishedAt?: string;\n /** Whether this request joined a run that already existed (a key or a retried `clientKey`). */\n readonly joined?: boolean;\n /**\n * The index of the first line in `log`, when the request said which lines the page holds\n * (`RunAttachRequest.held`); absent: 0, the whole log.\n */\n readonly logFrom?: number;\n /** The index of the first batch in `batches`, as `logFrom`; absent: 0. */\n readonly batchFrom?: number;\n}\n\n/** The Zod schema of the `RunState` type. */\nexport const RunState: z.ZodType<RunState> = z\n .object({\n runId: z.string(),\n fnId: z.string(),\n key: z.string().exactOptional(),\n status: z.enum(RUN_STATUSES as [RunStatus, ...RunStatus[]]),\n reason: z.string().exactOptional(),\n progress: RunProgress.exactOptional(),\n log: z.array(z.string()).readonly(),\n batches: Batches,\n error: z.object({ message: z.string(), code: z.string().exactOptional() }).exactOptional(),\n startedAt: z.string(),\n finishedAt: z.string().exactOptional(),\n joined: z.boolean().exactOptional(),\n logFrom: z.number().int().nonnegative().exactOptional(),\n batchFrom: z.number().int().nonnegative().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RunState\",\n description: \"An action run: status, progress, log and the result written so far.\",\n });\n\n/**\n * What changed in a run since a page last heard: a lossy notification on the event stream. Lines\n * start at `logFrom` and batches at `batchFrom`; a page that holds fewer reads the run again\n * (`runs/attach`).\n */\nexport interface RunDelta {\n /** The run's `run_` ID. */\n readonly runId: string;\n /** The run's state. */\n readonly status: RunStatus;\n /** Why it ended so, for `failed` and `cancelled`. */\n readonly reason?: RunReason;\n /** Its latest progress. */\n readonly progress?: RunProgress;\n /** The index of the first line in `log`. */\n readonly logFrom: number;\n /** Log lines, starting at `logFrom`. */\n readonly log: readonly string[];\n /** The index of the first batch in `batches`. */\n readonly batchFrom: number;\n /** Result batches, starting at `batchFrom`. */\n readonly batches: Batches;\n /** What went wrong. */\n readonly error?: WireError;\n /** When it ended. */\n readonly finishedAt?: string;\n}\n\n/** A live source's value as a page reads it (D56). */\nexport interface LiveState {\n /** The idempotency key it was started with, if any. */\n readonly key: string;\n /** The value's revision, a decimal string that only grows; absent before any value. */\n readonly revision?: string;\n /** When the value was produced. */\n readonly at?: string;\n /** The latest value, serialized. */\n readonly value?: Batches;\n /**\n * Append mode (`useLive(key, { mode: \"append\" })`): the values kept in the source's ring, oldest\n * first, at most the window the page asked for.\n */\n readonly ring?: readonly {\n readonly revision: string;\n readonly at: string;\n readonly value: Batches;\n }[];\n /** The producer's last failure, while the last good value stays (FAILURE_MODEL §6). */\n readonly error?: WireError;\n}\n\n/** One live update on the event stream: never stored as an event (D63, LL-04). */\nexport interface LiveUpdate {\n /** The live source's key. */\n readonly key: string;\n /** The value's revision. */\n readonly revision?: string;\n /** When the value was produced. */\n readonly at?: string;\n /** The value, serialized. */\n readonly value?: Batches;\n /** What went wrong. */\n readonly error?: WireError;\n}\n\n/**\n * An ephemeral message on a page's event stream (SSE `event: run` or `event: live`, without an\n * `id`, so a reconnect's cursor is untouched) or in a poll's `ephemeral`: lossy, coalesced, and\n * never stored as an event.\n */\nexport type EphemeralMessage =\n | { readonly kind: \"run\"; readonly run: RunDelta }\n | { readonly kind: \"live\"; readonly live: LiveUpdate };\n\n/** `POST …/call/{fnId}`: a plain server-function call, no durable record (D54). */\nexport interface CallRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** The arguments, serialized as one array value. */\n readonly args: Batches;\n}\n\n/** The Zod schema of the `CallRequest` type. */\nexport const CallRequest: z.ZodType<CallRequest> = z\n .object({ viewId: ViewId.schema, args: Batches })\n .register(wireRegistry, {\n id: \"CallRequest\",\n description: \"A plain server-function call: the view and the serialized arguments.\",\n });\n\n/**\n * One line of a plain call's answer (`application/x-ndjson`): a batch of the result, then the end.\n */\nexport type CallLine =\n | { readonly batch: readonly Frame[] }\n | { readonly end: { readonly status: \"succeeded\" } }\n | { readonly end: { readonly status: \"failed\"; readonly error: WireError } };\n\n/** `POST …/runs`: start a durable action run, or join one (D54, AC-02, AC-03). */\nexport interface RunRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** `<module path>#<export>`. */\n readonly fnId: string;\n /** The arguments, serialized as one array value. */\n readonly args: Batches;\n /** The author's idempotency key: one run per artifact, function and key, ever. */\n readonly key?: string;\n /** A fresh ID per invocation, so a retried request joins the run it already started. */\n readonly clientKey: string;\n}\n\n/** The Zod schema of the `RunRequest` type. */\nexport const RunRequest: z.ZodType<RunRequest> = z\n .object({\n viewId: ViewId.schema,\n fnId: z.string().min(3).max(1024),\n args: Batches,\n key: z.string().min(1).max(RUN_KEY_MAX).exactOptional(),\n clientKey: z.string().min(8).max(64),\n })\n .register(wireRegistry, {\n id: \"RunRequest\",\n description: \"Start or join an action run: the function, its arguments and keys.\",\n });\n\n/**\n * `POST …/runs/attach`: read runs and hear their changes on the event stream for the next minute\n * (re-attach after a reload, AC-02). By ID, or by function and key.\n */\nexport interface RunAttachRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** Runs by ID. */\n readonly runIds?: readonly string[];\n /** Runs by function and key. */\n readonly keyed?: readonly { readonly fnId: string; readonly key: string }[];\n /**\n * What the page already holds of runs it names by ID: so many log lines and batches. Each such\n * run's answer starts there (`RunState.logFrom`, `batchFrom`), so a page renewing its interest\n * doesn't read the whole run again (Opus review 14).\n */\n readonly held?: readonly {\n readonly runId: string;\n readonly log: number;\n readonly batches: number;\n }[];\n}\n\n/** The Zod schema of the `RunAttachRequest` type. */\nexport const RunAttachRequest: z.ZodType<RunAttachRequest> = z\n .object({\n viewId: ViewId.schema,\n runIds: z.array(z.string().max(64)).max(100).readonly().exactOptional(),\n keyed: z\n .array(\n z.object({ fnId: z.string().min(3).max(1024), key: z.string().min(1).max(RUN_KEY_MAX) }),\n )\n .max(100)\n .readonly()\n .exactOptional(),\n held: z\n .array(\n z.object({\n runId: z.string().max(64),\n log: z.number().int().nonnegative(),\n batches: z.number().int().nonnegative(),\n }),\n )\n .max(100)\n .readonly()\n .exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RunAttachRequest\",\n description: \"Runs a page reads and follows: by ID, or by function and key.\",\n });\n\n/** `POST …/runs/{id}/cancel`. */\nexport interface RunCancelRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n}\n\n/** The Zod schema of the `RunCancelRequest` type. */\nexport const RunCancelRequest: z.ZodType<RunCancelRequest> = z\n .object({ viewId: ViewId.schema })\n .register(wireRegistry, { id: \"RunCancelRequest\", description: \"Cancel a run, from a view.\" });\n\n/** The keys of live sources: like JavaScript export names, which is what `live.ts` declares. */\nexport const LIVE_KEY_PATTERN: RegExp = /^[A-Za-z_$][A-Za-z0-9_$]{0,127}$/;\n\n/** The largest live value, in characters of serialized JSON (DATA_MODEL §5's 4 MiB). */\nexport const LIVE_VALUE_MAX: number = 4 * 1024 * 1024;\n\n/** The ring size of a pushed source in append mode that no `defineLive` sized. */\nexport const LIVE_RING_DEFAULT = 1024;\n\n/** The largest ring a source may keep. */\nexport const LIVE_RING_MAX = 100_000;\n\n/**\n * `POST …/live`: read live sources and keep their producers running for this view for the next\n * minute (D56, LL-04); a page asks again while it shows them.\n */\nexport interface LiveRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /**\n * The sources, each with its append window; `refresh` asks the source's producer to load again\n * now (`useLive`'s `refresh()`).\n */\n readonly keys: readonly {\n readonly key: string;\n readonly window?: number;\n readonly refresh?: boolean;\n }[];\n}\n\n/** The Zod schema of the `LiveRequest` type. */\nexport const LiveRequest: z.ZodType<LiveRequest> = z\n .object({\n viewId: ViewId.schema,\n keys: z\n .array(\n z.object({\n key: z.string().regex(LIVE_KEY_PATTERN),\n window: z.int().min(1).max(LIVE_RING_MAX).exactOptional(),\n refresh: z.boolean().exactOptional(),\n }),\n )\n .max(256)\n .readonly(),\n })\n .register(wireRegistry, {\n id: \"LiveRequest\",\n description: \"Live sources a page reads and keeps running: keys and append windows.\",\n });\n\n/** Secret names: letters, digits, `_`, `.` and `-`, starting with a letter or `_` (D44). */\nexport const SECRET_NAME_PATTERN: RegExp = /^[A-Za-z_][A-Za-z0-9_.-]{0,127}$/;\n\n/** The largest secret value, in UTF-8 bytes. */\nexport const SECRET_VALUE_MAX: number = 64 * 1024;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,MAAa,UAA8B,EACxC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAC5D,SAAS,CAAC,CACV,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AASH,MAAa,cAAsC,EAChD,OAAO;CACN,SAAS,EAAE,OAAO;CAClB,MAAM,EAAE,OAAO,CAAC,CAAC,cAAc;CAC/B,OAAO,EAAE,OAAO,CAAC,CAAC,cAAc;AAClC,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,kBAA0B;;AAGvC,MAAa,oBAA4B;;AAGzC,MAAa,cAAsB;;AAGnC,MAAa,oBAAoB;;AAGjC,MAAa,cAAc;;AAW3B,MAAa,eAAqC;CAChD;CACA;CACA;CACA;CACA;CACA;AACF;;AAGA,SAAgB,iBAAiB,QAA4B;CAC3D,OAAO,WAAW,eAAe,WAAW,YAAY,WAAW;AACrE;;AAmBA,MAAa,cAAsC,EAChD,OAAO;CACN,UAAU,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,cAAc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MACC,EAAE,OAAO;EACP,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,gBAAgB;EACtC,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,cAAc;EACxD,SAAS,EAAE,QAAQ,CAAC,CAAC,cAAc;CACrC,CAAC,CACH,CAAC,CACA,IAAI,GAAG,CAAC,CACR,SAAS;AACd,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,sBAA8B;;AAG3C,MAAa,mBAA2B"}
|
|
1
|
+
{"version":3,"file":"actions.js","names":[],"sources":["../src/actions.ts"],"sourcesContent":["/**\n * Actions, live data and secrets (INTERFACES §2.4, §4, §6; D24, D44, D54, D56): the shapes the\n * browser protocol, the host protocol and the worker channel share. Server-function arguments and\n * results travel as the serializer's batches (`Batches`).\n *\n * ```ts\n * const run: RunState = await post(\"runs\", { viewId, fnId: \"actions.ts#sendReply\", args, clientKey });\n * if (run.status === \"succeeded\") show(await deserializeAll(run.batches));\n * ```\n */\nimport * as z from \"zod\";\nimport { ViewId } from \"./ids.ts\";\nimport type { Frame, WireError } from \"./serializer.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** A value written by the serializer: its batches, in order (`serializeAll`). */\nexport type Batches = readonly (readonly Frame[])[];\n\n/**\n * The Zod schema of the `Batches` type: a list of batches, each a list of frames. The frames\n * themselves are checked by the reader (`ValueReader`), which refuses anything malformed.\n */\nexport const Batches: z.ZodType<Batches> = z\n .array(z.array(z.record(z.string(), z.unknown())).readonly())\n .readonly()\n .register(wireRegistry, {\n id: \"Batches\",\n description: \"A serialized server-function value: its batches of frames, in order.\",\n }) as unknown as z.ZodType<Batches>;\n\n/** An error as runs, calls and live sources report it. */\nexport interface ActionError extends WireError {\n /** The stack of the thrown error, kept in the run log and never sent to a page. */\n readonly stack?: string;\n}\n\n/** The Zod schema of the `ActionError` type. */\nexport const ActionError: z.ZodType<ActionError> = z\n .object({\n message: z.string(),\n code: z.string().exactOptional(),\n stack: z.string().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"ActionError\",\n description: \"An error from server code: its message and diagnostic code.\",\n });\n\n/** The largest serialized arguments a call or run takes, in characters of JSON. */\nexport const ACTION_ARGS_MAX: number = 16 * 1024 * 1024;\n\n/** The largest serialized result a run keeps, in characters of JSON (larger fails the run). */\nexport const ACTION_RESULT_MAX: number = 16 * 1024 * 1024;\n\n/** The cap of a run's log, in UTF-16 code units of its lines (D47's 1 MB). */\nexport const RUN_LOG_MAX: number = 1024 * 1024;\n\n/** The line a capped log ends with. */\nexport const RUN_LOG_TRUNCATED = \"[log truncated at 1 MB]\";\n\n/** The longest run key, in characters. */\nexport const RUN_KEY_MAX = 256;\n\n/**\n * A run's state (D24, ARCHITECTURE §7). `queued`: recorded, not yet started in a worker.\n * `running`: started. `waiting` is reserved for a remote server's run that waits for its owner's\n * instance (WP-28, D117); a page that doesn't know it treats it like `queued`. The others are\n * final.\n */\nexport type RunStatus = \"queued\" | \"running\" | \"waiting\" | \"succeeded\" | \"failed\" | \"cancelled\";\n\n/** Every run status. */\nexport const RUN_STATUSES: readonly RunStatus[] = [\n \"queued\",\n \"running\",\n \"waiting\",\n \"succeeded\",\n \"failed\",\n \"cancelled\",\n];\n\n/** Whether a run in `status` has ended. */\nexport function isFinalRunStatus(status: RunStatus): boolean {\n return status === \"succeeded\" || status === \"failed\" || status === \"cancelled\";\n}\n\n/**\n * Why a run ended the way it did, beside its status: `interrupted` (its worker or the instance\n * stopped while it ran, D24), `threw` (the action threw), `unserializable` (its result is outside\n * the type set), `too-large`, `parked` (its artifact's worker keeps crashing), `cancelled` (by a\n * viewer), `unknown-function`. Later releases add reasons.\n */\nexport type RunReason = string;\n\n/** A run's progress, as the action last reported it. */\nexport interface RunProgress {\n /** From 0 to 1. */\n readonly fraction?: number;\n /** One short line for people. */\n readonly message?: string;\n}\n\n/** The Zod schema of the `RunProgress` type. */\nexport const RunProgress: z.ZodType<RunProgress> = z\n .object({\n fraction: z.number().min(0).max(1).exactOptional(),\n message: z.string().max(1000).exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RunProgress\",\n description: \"A run's progress: fraction and message.\",\n });\n\n/**\n * One action run as a page reads it (D54): its state, progress, log and the result written so far.\n * A result that is an async iterable grows item by item while the run is `running`.\n */\nexport interface RunState {\n /** The run's `run_` ID. */\n readonly runId: string;\n /** The server function it runs: `<module path>#<export>`. */\n readonly fnId: string;\n /** The idempotency key it was started with, if any. */\n readonly key?: string;\n /** The run's state. */\n readonly status: RunStatus;\n /** Why it ended, for `failed` and `cancelled`. */\n readonly reason?: RunReason;\n /** Its latest progress. */\n readonly progress?: RunProgress;\n /** The log lines, capped at 1 MB with a marker line. */\n readonly log: readonly string[];\n /** The result's batches so far. */\n readonly batches: Batches;\n /** For `failed`: what went wrong, without the stack. */\n readonly error?: WireError;\n /** When it was recorded. */\n readonly startedAt: string;\n /** When it ended. */\n readonly finishedAt?: string;\n /** Whether this request joined a run that already existed (a key or a retried `clientKey`). */\n readonly joined?: boolean;\n /**\n * The index of the first line in `log`, when the request said which lines the page holds\n * (`RunAttachRequest.held`); absent: 0, the whole log.\n */\n readonly logFrom?: number;\n /** The index of the first batch in `batches`, as `logFrom`; absent: 0. */\n readonly batchFrom?: number;\n}\n\n/** The Zod schema of the `RunState` type. */\nexport const RunState: z.ZodType<RunState> = z\n .object({\n runId: z.string(),\n fnId: z.string(),\n key: z.string().exactOptional(),\n status: z.enum(RUN_STATUSES as [RunStatus, ...RunStatus[]]),\n reason: z.string().exactOptional(),\n progress: RunProgress.exactOptional(),\n log: z.array(z.string()).readonly(),\n batches: Batches,\n error: z.object({ message: z.string(), code: z.string().exactOptional() }).exactOptional(),\n startedAt: z.string(),\n finishedAt: z.string().exactOptional(),\n joined: z.boolean().exactOptional(),\n logFrom: z.number().int().nonnegative().exactOptional(),\n batchFrom: z.number().int().nonnegative().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RunState\",\n description: \"An action run: status, progress, log and the result written so far.\",\n });\n\n/**\n * What changed in a run since a page last heard: a lossy notification on the event stream. Lines\n * start at `logFrom` and batches at `batchFrom`; a page that holds fewer reads the run again\n * (`runs/attach`).\n */\nexport interface RunDelta {\n /** The run's `run_` ID. */\n readonly runId: string;\n /** The run's state. */\n readonly status: RunStatus;\n /** Why it ended so, for `failed` and `cancelled`. */\n readonly reason?: RunReason;\n /** Its latest progress. */\n readonly progress?: RunProgress;\n /** The index of the first line in `log`. */\n readonly logFrom: number;\n /** Log lines, starting at `logFrom`. */\n readonly log: readonly string[];\n /** The index of the first batch in `batches`. */\n readonly batchFrom: number;\n /** Result batches, starting at `batchFrom`. */\n readonly batches: Batches;\n /** What went wrong. */\n readonly error?: WireError;\n /** When it ended. */\n readonly finishedAt?: string;\n}\n\n/** A live source's value as a page reads it (D56). */\nexport interface LiveState {\n /** The idempotency key it was started with, if any. */\n readonly key: string;\n /** The value's revision, a decimal string that only grows; absent before any value. */\n readonly revision?: string;\n /** When the value was produced. */\n readonly at?: string;\n /** The latest value, serialized. */\n readonly value?: Batches;\n /**\n * Append mode (`useLive(key, { mode: \"append\" })`): the values kept in the source's ring, oldest\n * first, at most the window the page asked for.\n */\n readonly ring?: readonly {\n readonly revision: string;\n readonly at: string;\n readonly value: Batches;\n }[];\n /** The producer's last failure, while the last good value stays (FAILURE_MODEL §6). */\n readonly error?: WireError;\n /**\n * `true` while the source has no value and no failure and the artifact's latest version has a\n * producer whose first `load` is on its way: the page shows it loading, and verify waits for it.\n * Absent for a key nothing produces (one only `mostra push` writes) and for a source that only\n * streams, whose first value may never come (WP-14's Opus review).\n */\n readonly awaiting?: boolean;\n}\n\n/** One live update on the event stream: never stored as an event (D63, LL-04). */\nexport interface LiveUpdate {\n /** The live source's key. */\n readonly key: string;\n /** The value's revision. */\n readonly revision?: string;\n /** When the value was produced. */\n readonly at?: string;\n /** The value, serialized. */\n readonly value?: Batches;\n /** What went wrong. */\n readonly error?: WireError;\n /**\n * `false` when a source read as {@link LiveState.awaiting} turned out to have no first `load`\n * (its producer only streams): the page stops waiting for a first value.\n */\n readonly awaiting?: boolean;\n}\n\n/**\n * An ephemeral message on a page's event stream (SSE `event: run` or `event: live`, without an\n * `id`, so a reconnect's cursor is untouched) or in a poll's `ephemeral`: lossy, coalesced, and\n * never stored as an event.\n */\nexport type EphemeralMessage =\n | { readonly kind: \"run\"; readonly run: RunDelta }\n | { readonly kind: \"live\"; readonly live: LiveUpdate };\n\n/** `POST …/call/{fnId}`: a plain server-function call, no durable record (D54). */\nexport interface CallRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** The arguments, serialized as one array value. */\n readonly args: Batches;\n}\n\n/** The Zod schema of the `CallRequest` type. */\nexport const CallRequest: z.ZodType<CallRequest> = z\n .object({ viewId: ViewId.schema, args: Batches })\n .register(wireRegistry, {\n id: \"CallRequest\",\n description: \"A plain server-function call: the view and the serialized arguments.\",\n });\n\n/**\n * One line of a plain call's answer (`application/x-ndjson`): a batch of the result, then the end.\n */\nexport type CallLine =\n | { readonly batch: readonly Frame[] }\n | { readonly end: { readonly status: \"succeeded\" } }\n | { readonly end: { readonly status: \"failed\"; readonly error: WireError } };\n\n/** `POST …/runs`: start a durable action run, or join one (D54, AC-02, AC-03). */\nexport interface RunRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** `<module path>#<export>`. */\n readonly fnId: string;\n /** The arguments, serialized as one array value. */\n readonly args: Batches;\n /** The author's idempotency key: one run per artifact, function and key, ever. */\n readonly key?: string;\n /** A fresh ID per invocation, so a retried request joins the run it already started. */\n readonly clientKey: string;\n}\n\n/** The Zod schema of the `RunRequest` type. */\nexport const RunRequest: z.ZodType<RunRequest> = z\n .object({\n viewId: ViewId.schema,\n fnId: z.string().min(3).max(1024),\n args: Batches,\n key: z.string().min(1).max(RUN_KEY_MAX).exactOptional(),\n clientKey: z.string().min(8).max(64),\n })\n .register(wireRegistry, {\n id: \"RunRequest\",\n description: \"Start or join an action run: the function, its arguments and keys.\",\n });\n\n/**\n * `POST …/runs/attach`: read runs and hear their changes on the event stream for the next minute\n * (re-attach after a reload, AC-02). By ID, or by function and key.\n */\nexport interface RunAttachRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** Runs by ID. */\n readonly runIds?: readonly string[];\n /** Runs by function and key. */\n readonly keyed?: readonly { readonly fnId: string; readonly key: string }[];\n /**\n * What the page already holds of runs it names by ID: so many log lines and batches. Each such\n * run's answer starts there (`RunState.logFrom`, `batchFrom`), so a page renewing its interest\n * doesn't read the whole run again (Opus review 14).\n */\n readonly held?: readonly {\n readonly runId: string;\n readonly log: number;\n readonly batches: number;\n }[];\n}\n\n/** The Zod schema of the `RunAttachRequest` type. */\nexport const RunAttachRequest: z.ZodType<RunAttachRequest> = z\n .object({\n viewId: ViewId.schema,\n runIds: z.array(z.string().max(64)).max(100).readonly().exactOptional(),\n keyed: z\n .array(\n z.object({ fnId: z.string().min(3).max(1024), key: z.string().min(1).max(RUN_KEY_MAX) }),\n )\n .max(100)\n .readonly()\n .exactOptional(),\n held: z\n .array(\n z.object({\n runId: z.string().max(64),\n log: z.number().int().nonnegative(),\n batches: z.number().int().nonnegative(),\n }),\n )\n .max(100)\n .readonly()\n .exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RunAttachRequest\",\n description: \"Runs a page reads and follows: by ID, or by function and key.\",\n });\n\n/** `POST …/runs/{id}/cancel`. */\nexport interface RunCancelRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n}\n\n/** The Zod schema of the `RunCancelRequest` type. */\nexport const RunCancelRequest: z.ZodType<RunCancelRequest> = z\n .object({ viewId: ViewId.schema })\n .register(wireRegistry, { id: \"RunCancelRequest\", description: \"Cancel a run, from a view.\" });\n\n/** The keys of live sources: like JavaScript export names, which is what `live.ts` declares. */\nexport const LIVE_KEY_PATTERN: RegExp = /^[A-Za-z_$][A-Za-z0-9_$]{0,127}$/;\n\n/** The largest live value, in characters of serialized JSON (DATA_MODEL §5's 4 MiB). */\nexport const LIVE_VALUE_MAX: number = 4 * 1024 * 1024;\n\n/** The ring size of a pushed source in append mode that no `defineLive` sized. */\nexport const LIVE_RING_DEFAULT = 1024;\n\n/** The largest ring a source may keep. */\nexport const LIVE_RING_MAX = 100_000;\n\n/**\n * `POST …/live`: read live sources and keep their producers running for this view for the next\n * minute (D56, LL-04); a page asks again while it shows them.\n */\nexport interface LiveRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /**\n * The sources, each with its append window; `refresh` asks the source's producer to load again\n * now (`useLive`'s `refresh()`).\n */\n readonly keys: readonly {\n readonly key: string;\n readonly window?: number;\n readonly refresh?: boolean;\n }[];\n}\n\n/** The Zod schema of the `LiveRequest` type. */\nexport const LiveRequest: z.ZodType<LiveRequest> = z\n .object({\n viewId: ViewId.schema,\n keys: z\n .array(\n z.object({\n key: z.string().regex(LIVE_KEY_PATTERN),\n window: z.int().min(1).max(LIVE_RING_MAX).exactOptional(),\n refresh: z.boolean().exactOptional(),\n }),\n )\n .max(256)\n .readonly(),\n })\n .register(wireRegistry, {\n id: \"LiveRequest\",\n description: \"Live sources a page reads and keeps running: keys and append windows.\",\n });\n\n/** Secret names: letters, digits, `_`, `.` and `-`, starting with a letter or `_` (D44). */\nexport const SECRET_NAME_PATTERN: RegExp = /^[A-Za-z_][A-Za-z0-9_.-]{0,127}$/;\n\n/** The largest secret value, in UTF-8 bytes. */\nexport const SECRET_VALUE_MAX: number = 64 * 1024;\n"],"mappings":";;;;;;;;;;;;;;;;;;AAsBA,MAAa,UAA8B,EACxC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAC5D,SAAS,CAAC,CACV,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AASH,MAAa,cAAsC,EAChD,OAAO;CACN,SAAS,EAAE,OAAO;CAClB,MAAM,EAAE,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,CAAC,YAAY;EAClC,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY;CACxC,CAAC,CACH,CAAC,CACA,IAAI,GAAG,CAAC,CACR,SAAS,CAAC,CACV,cAAc;AACnB,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AASH,MAAa,mBAAgD,EAC1D,OAAO,EAAE,QAAQ,OAAO,OAAO,CAAC,CAAC,CACjC,SAAS,cAAc;CAAE,IAAI;CAAoB,aAAa;AAA6B,CAAC;;AAG/F,MAAa,mBAA2B;;AAGxC,MAAa,iBAAyB;;AAGtC,MAAa,oBAAoB;;AAGjC,MAAa,gBAAgB;;AAqB7B,MAAa,cAAsC,EAChD,OAAO;CACN,QAAQ,OAAO;CACf,MAAM,EACH,MACC,EAAE,OAAO;EACP,KAAK,EAAE,OAAO,CAAC,CAAC,MAAM,gBAAgB;EACtC,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC,CAAC,cAAc;EACxD,SAAS,EAAE,QAAQ,CAAC,CAAC,cAAc;CACrC,CAAC,CACH,CAAC,CACA,IAAI,GAAG,CAAC,CACR,SAAS;AACd,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAGH,MAAa,sBAA8B;;AAG3C,MAAa,mBAA2B"}
|
package/dist/bridge.d.ts
CHANGED
|
@@ -230,6 +230,31 @@ export declare const mostraVersionAvailable: BridgeMessage<VersionAvailableParam
|
|
|
230
230
|
export declare const mostraFieldFocus: BridgeMessage<{
|
|
231
231
|
readonly id: string;
|
|
232
232
|
}, undefined>;
|
|
233
|
+
/** The params of `mostra/frameSession.failed`. */
|
|
234
|
+
export interface FrameSessionFailedParams {
|
|
235
|
+
/** `MOSTRA_HYGIENE_FRAME_SESSION`. */
|
|
236
|
+
readonly code: string;
|
|
237
|
+
/** What went wrong, for the shell to show. */
|
|
238
|
+
readonly message: string;
|
|
239
|
+
/**
|
|
240
|
+
* Why: `unsupported` (this browser offers the frame no service worker, as in a private window),
|
|
241
|
+
* `blocked` (the browser refused to install it), `conflict` (another service worker holds `/`
|
|
242
|
+
* on the artifact's origin), or `refused` (the gateway refused the frame's entry).
|
|
243
|
+
*/
|
|
244
|
+
readonly reason: "unsupported" | "blocked" | "conflict" | "refused" | (string & {});
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
247
|
+
* `mostra/frameSession.failed`: the worker-mode bootstrap page (D70, D158 item 5) couldn't start
|
|
248
|
+
* the frame's session. It is sent before any client runtime runs, so the shell shows why instead
|
|
249
|
+
* of a frame that never greets.
|
|
250
|
+
*/
|
|
251
|
+
export declare const mostraFrameSessionFailed: BridgeMessage<FrameSessionFailedParams, undefined>;
|
|
252
|
+
/**
|
|
253
|
+
* `mostra/frameSession.entered`: the worker-mode bootstrap page (D70, D158 item 5) has its
|
|
254
|
+
* session and its service worker, and is loading the version. The shell's wait for the frame's
|
|
255
|
+
* page starts here: the bootstrap's own load is not the page's (WP-13).
|
|
256
|
+
*/
|
|
257
|
+
export declare const mostraFrameSessionEntered: BridgeMessage<Readonly<Record<string, unknown>>, undefined>;
|
|
233
258
|
/**
|
|
234
259
|
* Every message of the bridge in this release. WP-20 adds review messages; a message never
|
|
235
260
|
* changes meaning once released (D32).
|
package/dist/bridge.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.d.ts","names":[],"sources":["../src/bridge.ts"],"mappings":";;;;YA2BY;;iBAGK,cAAc,GAAG;;WAEvB;;WAEA,MAAM;;WAEN;;WAEA,QAAQ,EAAE,QAAQ;;WAElB,QAAQ,EAAE,QAAQ;;;YAIjB,mBAAmB;;qBAGlB;;iBAGI;;WAEN;;WAEA;;WAEA;;;iBAUM;;WAEN,SAAS;;WAET,iBAAiB,SAAS;;WAE1B;;;;;;WAMA;aAAoB;;;;iBAId;;WAEN;;WAEA;;WAEA;;WAEA;;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Ae,QAAQ;;EAExD;;;;;;wBAec,cAAc,SAAS,gBAAgB"}
|
package/dist/bridge.js
CHANGED
|
@@ -245,6 +245,34 @@ const mostraFieldFocus = {
|
|
|
245
245
|
result: z.undefined()
|
|
246
246
|
};
|
|
247
247
|
/**
|
|
248
|
+
* `mostra/frameSession.failed`: the worker-mode bootstrap page (D70, D158 item 5) couldn't start
|
|
249
|
+
* the frame's session. It is sent before any client runtime runs, so the shell shows why instead
|
|
250
|
+
* of a frame that never greets.
|
|
251
|
+
*/
|
|
252
|
+
const mostraFrameSessionFailed = {
|
|
253
|
+
method: "mostra/frameSession.failed",
|
|
254
|
+
from: "artifact",
|
|
255
|
+
kind: "notification",
|
|
256
|
+
params: z.looseObject({
|
|
257
|
+
code: z.string().min(1).max(128),
|
|
258
|
+
message: z.string().max(BRIDGE_TEXT_MAX),
|
|
259
|
+
reason: z.string().min(1).max(64)
|
|
260
|
+
}),
|
|
261
|
+
result: z.undefined()
|
|
262
|
+
};
|
|
263
|
+
/**
|
|
264
|
+
* `mostra/frameSession.entered`: the worker-mode bootstrap page (D70, D158 item 5) has its
|
|
265
|
+
* session and its service worker, and is loading the version. The shell's wait for the frame's
|
|
266
|
+
* page starts here: the bootstrap's own load is not the page's (WP-13).
|
|
267
|
+
*/
|
|
268
|
+
const mostraFrameSessionEntered = {
|
|
269
|
+
method: "mostra/frameSession.entered",
|
|
270
|
+
from: "artifact",
|
|
271
|
+
kind: "notification",
|
|
272
|
+
params: z.looseObject({}),
|
|
273
|
+
result: z.undefined()
|
|
274
|
+
};
|
|
275
|
+
/**
|
|
248
276
|
* Every message of the bridge in this release. WP-20 adds review messages; a message never
|
|
249
277
|
* changes meaning once released (D32).
|
|
250
278
|
*/
|
|
@@ -259,7 +287,9 @@ const BRIDGE_MESSAGES = [
|
|
|
259
287
|
mostraControlsRequest,
|
|
260
288
|
mostraFlush,
|
|
261
289
|
mostraVersionAvailable,
|
|
262
|
-
mostraFieldFocus
|
|
290
|
+
mostraFieldFocus,
|
|
291
|
+
mostraFrameSessionFailed,
|
|
292
|
+
mostraFrameSessionEntered
|
|
263
293
|
];
|
|
264
294
|
const asMethod = (message) => ({
|
|
265
295
|
method: message.method,
|
|
@@ -338,6 +368,6 @@ function connectBridge(options) {
|
|
|
338
368
|
};
|
|
339
369
|
}
|
|
340
370
|
//#endregion
|
|
341
|
-
export { BRIDGE_FIELDS_MAX, BRIDGE_MESSAGES, BRIDGE_TEXT_MAX, CONTROL_LABEL_MAX, MCP_APPS_PROTOCOL_VERSION, OPEN_LINK_SCHEMES, connectBridge, mostraControlsRequest, mostraFieldFocus, mostraFields, mostraFlush, mostraPage, mostraReady, mostraVersionAvailable, uiInitialize, uiInitialized, uiOpenLink, uiSizeChanged };
|
|
371
|
+
export { BRIDGE_FIELDS_MAX, BRIDGE_MESSAGES, BRIDGE_TEXT_MAX, CONTROL_LABEL_MAX, MCP_APPS_PROTOCOL_VERSION, OPEN_LINK_SCHEMES, connectBridge, mostraControlsRequest, mostraFieldFocus, mostraFields, mostraFlush, mostraFrameSessionEntered, mostraFrameSessionFailed, mostraPage, mostraReady, mostraVersionAvailable, uiInitialize, uiInitialized, uiOpenLink, uiSizeChanged };
|
|
342
372
|
|
|
343
373
|
//# sourceMappingURL=bridge.js.map
|
package/dist/bridge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","names":[],"sources":["../src/bridge.ts"],"sourcesContent":["/**\n * The shell ↔ artifact bridge (INTERFACES §5, ROUND-3 §8, SH-04): JSON-RPC 2.0 over\n * `postMessage`, shaped like MCP Apps so exporting an artifact as an MCP App only swaps the\n * transport. Both ends accept a message only when it comes from the one window they talk to, at\n * its exact origin, and only when it is a message of the bridge's set with valid params; anything\n * else is dropped (or, for a request from the right window, answered with an error). It has no\n * I/O of its own: the caller hands it the window objects.\n *\n * ```ts\n * // In the shell:\n * const bridge = connectBridge({\n * side: \"shell\",\n * receiver: window,\n * peer: () => frame.contentWindow,\n * peerOrigin: \"http://127.0.0.1:23457\",\n * onRequest: (message, params) => (message === uiInitialize ? initializeResult : undefined),\n * });\n * ```\n */\nimport * as z from \"zod\";\nimport type { MethodDefinition } from \"./method.ts\";\nimport { hostDiagnostic, JSON_RPC_ERROR_CODES, RpcError } from \"./rpc/error.ts\";\nimport { classifyMessage } from \"./rpc/messages.ts\";\nimport { RpcPeer } from \"./rpc/peer.ts\";\nimport { REVIEW_SET_ID_PATTERN, ViewContextWire } from \"./view.ts\";\n\n/** Which end of the bridge: the trusted shell, or the artifact's frame. */\nexport type BridgeSide = \"shell\" | \"artifact\";\n\n/** One message of the bridge's set. */\nexport interface BridgeMessage<P, R> {\n /** The JSON-RPC method name; MCP Apps' name where the concept exists. */\n readonly method: string;\n /** The side that sends it. */\n readonly from: BridgeSide;\n /** A request is answered; a notification isn't. */\n readonly kind: \"request\" | \"notification\";\n /** The schema of its params. */\n readonly params: z.ZodType<P>;\n /** The schema of a request's result (`z.undefined()` for notifications). */\n readonly result: z.ZodType<R>;\n}\n\n/** A bridge message of any params and result type. */\nexport type AnyBridgeMessage = BridgeMessage<unknown, unknown>;\n\n/** The version of MCP Apps whose message shapes the bridge follows (VERIFIED_FACTS, MCP). */\nexport const MCP_APPS_PROTOCOL_VERSION = \"2026-01-26\";\n\n/** An application's name and version (MCP's `Implementation`). */\nexport interface BridgeImplementation {\n /** A stable machine name, such as `mostra-shell`. */\n readonly name: string;\n /** Its release. */\n readonly version: string;\n /** A name for people. */\n readonly title?: string;\n}\n\nconst Implementation: z.ZodType<BridgeImplementation> = z.looseObject({\n name: z.string(),\n version: z.string(),\n title: z.string().exactOptional(),\n});\n\n/** The params of `ui/initialize`: the artifact introduces itself (MCP Apps). */\nexport interface UiInitializeParams {\n /** The artifact's client runtime. */\n readonly appInfo: BridgeImplementation;\n /** What the artifact offers (MCP Apps' `McpUiAppCapabilities`). */\n readonly appCapabilities: Readonly<Record<string, unknown>>;\n /** The MCP Apps revision the artifact speaks, {@link MCP_APPS_PROTOCOL_VERSION}. */\n readonly protocolVersion: string;\n /**\n * What the page is (WP-07): the version whose build the frame loaded. An artifact origin serves\n * the version its frame session last entered (D98 item 5), so a frame reloaded after another\n * tab switched versions may hold another version than its view; the shell re-enters its own.\n */\n readonly mostra?: { readonly versionId: string };\n}\n\n/** What the shell tells the artifact about where it is shown (MCP Apps' `HostContext`). */\nexport interface BridgeHostContext {\n /** The viewer's color scheme. */\n readonly theme?: \"light\" | \"dark\";\n /** How the artifact is shown: the shell shows it `fullscreen`. */\n readonly displayMode?: \"inline\" | \"fullscreen\" | \"pip\";\n /** The display modes the shell offers. */\n readonly availableDisplayModes?: readonly string[];\n /** The viewer's language (BCP 47). */\n readonly locale?: string;\n /** The viewer's time zone (IANA). */\n readonly timeZone?: string;\n /** The kind of device. */\n readonly platform?: \"web\" | \"desktop\" | \"mobile\";\n /** Further MCP Apps context, passed through. */\n readonly [key: string]: unknown;\n}\n\n/** The result of `ui/initialize`: the shell introduces itself (MCP Apps). */\nexport interface UiInitializeResult {\n /** The MCP Apps revision both ends speak. */\n readonly protocolVersion: string;\n /** The shell. */\n readonly hostInfo: BridgeImplementation;\n /** What the shell offers (MCP Apps' `McpUiHostCapabilities`). */\n readonly hostCapabilities: Readonly<Record<string, unknown>>;\n /** Where and how the artifact is shown. */\n readonly hostContext: BridgeHostContext;\n /** Mostra's shell: the view this frame load is, and what the host allows in it (WP-07). */\n readonly mostra?: ViewContextWire;\n}\n\n/** `ui/initialize`: the artifact's first request, answered with the shell's context. */\nexport const uiInitialize: BridgeMessage<UiInitializeParams, UiInitializeResult> = {\n method: \"ui/initialize\",\n from: \"artifact\",\n kind: \"request\",\n params: z.looseObject({\n appInfo: Implementation,\n appCapabilities: z.record(z.string(), z.unknown()),\n protocolVersion: z.string().min(1),\n mostra: z.looseObject({ versionId: z.string().min(1).max(64) }).exactOptional(),\n }),\n result: z.looseObject({\n protocolVersion: z.string().min(1),\n hostInfo: Implementation,\n hostCapabilities: z.record(z.string(), z.unknown()),\n hostContext: z.looseObject({\n theme: z.enum([\"light\", \"dark\"]).exactOptional(),\n displayMode: z.enum([\"inline\", \"fullscreen\", \"pip\"]).exactOptional(),\n availableDisplayModes: z.array(z.string()).readonly().exactOptional(),\n locale: z.string().exactOptional(),\n timeZone: z.string().exactOptional(),\n platform: z.enum([\"web\", \"desktop\", \"mobile\"]).exactOptional(),\n }),\n mostra: ViewContextWire.exactOptional(),\n }),\n};\n\n/** `ui/notifications/initialized`: the artifact finished initializing; the shell may now send. */\nexport const uiInitialized: BridgeMessage<Readonly<Record<string, unknown>>, undefined> = {\n method: \"ui/notifications/initialized\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.record(z.string(), z.unknown()),\n result: z.undefined(),\n};\n\n/** `ui/notifications/size-changed`: the artifact's rendered size (MCP Apps). */\nexport const uiSizeChanged: BridgeMessage<\n { readonly width?: number; readonly height?: number },\n undefined\n> = {\n method: \"ui/notifications/size-changed\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n width: z.number().min(0).exactOptional(),\n height: z.number().min(0).exactOptional(),\n }),\n result: z.undefined(),\n};\n\n/**\n * The URL schemes `ui/open-link` opens: the web, mail and phone numbers. Anything else, such as\n * `javascript:` or `data:`, would run or show content in the shell's own context.\n */\nexport const OPEN_LINK_SCHEMES: readonly string[] = [\"http:\", \"https:\", \"mailto:\", \"tel:\"];\n\n/**\n * `ui/open-link`: the artifact asks the shell to open a URL in a new tab (MCP Apps). The frame\n * can't navigate the viewer's tab itself (D98 item 7), so this is how an artifact sends the\n * viewer anywhere. `isError` is `true` when the shell couldn't open it.\n */\nexport const uiOpenLink: BridgeMessage<\n { readonly url: string },\n { readonly isError?: boolean; readonly [key: string]: unknown }\n> = {\n method: \"ui/open-link\",\n from: \"artifact\",\n kind: \"request\",\n params: z.looseObject({ url: z.string().min(1).max(8192) }),\n result: z.looseObject({ isError: z.boolean().exactOptional() }),\n};\n\n/** `mostra/ready`: the artifact's page has rendered; `verify` waits for it (ROUND-3 §8). */\nexport const mostraReady: BridgeMessage<Readonly<Record<string, unknown>>, undefined> = {\n method: \"mostra/ready\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.record(z.string(), z.unknown()),\n result: z.undefined(),\n};\n\n// ── Fields, pages, controls and versions (WP-07, INTERFACES §5, ROUND-3 §8) ──────────────\n\n/** The page's save state, as the shell's rail shows it (D47). */\nexport type SaveState = \"saved\" | \"saving\" | \"offline\" | \"conflict\";\n\n/** Why a field blocks a submit (INTERFACES §2.3). */\nexport interface SubmitBlocker {\n /** The field's ID. */\n readonly fieldId: string;\n /** Its label, when it has one. */\n readonly label?: string;\n /** `required` without a value, `invalid` by its `validate`, or a `conflict` not yet resolved. */\n readonly reason: \"required\" | \"invalid\" | \"conflict\";\n}\n\n/**\n * The longest label, validation message or other text a field carries over the bridge; a page\n * shortens longer ones before it sends them (Claude review finding 11).\n */\nexport const BRIDGE_TEXT_MAX = 1024;\n\n/** The most fields or blockers one bridge message lists; a page sends those that matter first. */\nexport const BRIDGE_FIELDS_MAX = 10_000;\n\nconst SubmitBlockerSchema: z.ZodType<SubmitBlocker> = z.looseObject({\n fieldId: z.string().min(1).max(256),\n label: z.string().max(BRIDGE_TEXT_MAX).exactOptional(),\n reason: z.enum([\"required\", \"invalid\", \"conflict\"]),\n});\n\n/**\n * A field the page has mounted, with what the shell needs to list blockers by label (D52, D106).\n * The page reports it; the shell checks `required` against the draft it reads itself.\n */\nexport interface FieldRegistration {\n /** The field's ID. */\n readonly id: string;\n /** The label people see. */\n readonly label?: string;\n /** Whether a submit needs a value. */\n readonly required?: boolean;\n /** The viewer's draft or the artifact's shared state. */\n readonly scope: \"viewer\" | \"artifact\";\n /** Whether its value is kept out of events and logs. */\n readonly sensitive?: boolean;\n /** Its `validate` message for the current value, if any. */\n readonly error?: string;\n /** Whether it has a conflict the viewer hasn't resolved. */\n readonly conflict?: boolean;\n}\n\n/** The params of `mostra/fields`. */\nexport interface FieldsParams {\n /** Every mounted field, once per ID. */\n readonly fields: readonly FieldRegistration[];\n /** The page's save state. */\n readonly save: SaveState;\n /** Whether edits are waiting to be saved (typed, offline, or in the journal). */\n readonly unsaved: boolean;\n}\n\n/**\n * `mostra/fields`: the page's mounted fields and save state, sent whenever they change, so the\n * shell lists blockers by label and its rail shows \"Saving\" and \"Saved\" (INTERFACES §5).\n */\nexport const mostraFields: BridgeMessage<FieldsParams, undefined> = {\n method: \"mostra/fields\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n fields: z\n .array(\n z.looseObject({\n id: z.string().min(1).max(256),\n label: z.string().max(BRIDGE_TEXT_MAX).exactOptional(),\n required: z.boolean().exactOptional(),\n scope: z.enum([\"viewer\", \"artifact\"]),\n sensitive: z.boolean().exactOptional(),\n error: z.string().max(BRIDGE_TEXT_MAX).exactOptional(),\n conflict: z.boolean().exactOptional(),\n }),\n )\n .max(BRIDGE_FIELDS_MAX)\n .readonly(),\n save: z.enum([\"saved\", \"saving\", \"offline\", \"conflict\"]),\n unsaved: z.boolean(),\n }),\n result: z.undefined(),\n};\n\n/**\n * `mostra/page`: the page the viewer is on, inside a `pages/` artifact (D57), so comments record\n * it (WP-20). `path` is the route's path with its search and hash, whatever the history mode.\n */\nexport const mostraPage: BridgeMessage<\n { readonly path: string; readonly title?: string },\n undefined\n> = {\n method: \"mostra/page\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n path: z.string().min(1).max(2048),\n title: z.string().max(1024).exactOptional(),\n }),\n result: z.undefined(),\n};\n\n/** A trusted control the artifact asks the shell for (INTERFACES §5): the artifact asks, the shell decides. */\nexport type ControlRequest =\n | {\n /** Relabel the shell's trusted Submit, with an optional confirmation text. */\n readonly control: \"submit\";\n readonly label?: string;\n readonly confirm?: string;\n }\n | {\n /** Render a trusted Choose for a review set's candidates (D113). */\n readonly control: \"choose\";\n readonly reviewSetId: string;\n readonly candidates: readonly { readonly id: string; readonly label?: string }[];\n /** The candidate the page shows now, which Choose names. */\n readonly current?: string;\n }\n | {\n /** Withdraw an earlier request: the Submit label, or a review set's Choose. */\n readonly control: \"release\";\n readonly submit?: true;\n readonly reviewSetId?: string;\n };\n\n/** The longest Submit label the shell renders: one short line. */\nexport const CONTROL_LABEL_MAX = 48;\n\n/**\n * `mostra/controls.request`: the artifact asks the shell for a trusted control (D06, SH-02). The\n * shell renders it in its own origin, where the artifact can neither click nor reach it, and\n * answers whether it is shown: a control the host's policy leaves out is not (D108).\n */\nexport const mostraControlsRequest: BridgeMessage<ControlRequest, { readonly shown: boolean }> = {\n method: \"mostra/controls.request\",\n from: \"artifact\",\n kind: \"request\",\n params: z.discriminatedUnion(\"control\", [\n z.looseObject({\n control: z.literal(\"submit\"),\n label: z.string().min(1).max(CONTROL_LABEL_MAX).exactOptional(),\n confirm: z.string().min(1).max(500).exactOptional(),\n }),\n z.looseObject({\n control: z.literal(\"choose\"),\n reviewSetId: z.string().regex(REVIEW_SET_ID_PATTERN),\n candidates: z\n .array(\n z.looseObject({\n id: z.string().min(1).max(256),\n label: z.string().max(CONTROL_LABEL_MAX).exactOptional(),\n }),\n )\n .min(1)\n .max(64)\n .readonly(),\n current: z.string().min(1).max(256).exactOptional(),\n }),\n z.looseObject({\n control: z.literal(\"release\"),\n submit: z.literal(true).exactOptional(),\n reviewSetId: z.string().regex(REVIEW_SET_ID_PATTERN).exactOptional(),\n }),\n ]) as unknown as z.ZodType<ControlRequest>,\n result: z.looseObject({ shown: z.boolean() }),\n};\n\n/** What the page answers `mostra/flush`. */\nexport interface FlushResult {\n /** The viewer's draft revision once every save landed. */\n readonly revision: string;\n /** Whether edits still wait (offline, or a save failed). */\n readonly unsaved: boolean;\n /** What blocks a submit now: invalid values and open conflicts, and required fields the page sees empty. */\n readonly blockers: readonly SubmitBlocker[];\n}\n\n/**\n * `mostra/flush`: the shell asks the page to save everything now, before its trusted Submit or a\n * switch to a newer version (IN-02, D110). For a submit, the page first writes the defaults the\n * viewer saw. The shell checks the answer against the draft it reads itself.\n */\nexport const mostraFlush: BridgeMessage<{ readonly reason: \"submit\" | \"switch\" }, FlushResult> = {\n method: \"mostra/flush\",\n from: \"shell\",\n kind: \"request\",\n params: z.looseObject({ reason: z.enum([\"submit\", \"switch\"]) }),\n result: z.looseObject({\n revision: z.string().regex(/^(0|[1-9][0-9]{0,15})$/),\n unsaved: z.boolean(),\n blockers: z.array(SubmitBlockerSchema).max(BRIDGE_FIELDS_MAX).readonly(),\n }),\n};\n\n/** The params of `mostra/version.available`. */\nexport interface VersionAvailableParams {\n /** The newer version's ID. */\n readonly versionId: string;\n /** Its number. */\n readonly version: number;\n /** How many of the viewer's answers it doesn't carry over (D42). */\n readonly orphans: number;\n}\n\n/**\n * `mostra/version.available`: a newer version was published while the page is open (VR-04). The\n * shell always shows its own trusted banner; the page may show a notice too.\n */\nexport const mostraVersionAvailable: BridgeMessage<VersionAvailableParams, undefined> = {\n method: \"mostra/version.available\",\n from: \"shell\",\n kind: \"notification\",\n params: z.looseObject({\n versionId: z.string().min(1),\n version: z.int().min(1),\n orphans: z.int().min(0),\n }),\n result: z.undefined(),\n};\n\n/** `mostra/field.focus`: the viewer picked a blocker in the shell; the page focuses that field. */\nexport const mostraFieldFocus: BridgeMessage<{ readonly id: string }, undefined> = {\n method: \"mostra/field.focus\",\n from: \"shell\",\n kind: \"notification\",\n params: z.looseObject({ id: z.string().min(1).max(256) }),\n result: z.undefined(),\n};\n\n/**\n * Every message of the bridge in this release. WP-20 adds review messages; a message never\n * changes meaning once released (D32).\n */\nexport const BRIDGE_MESSAGES: readonly AnyBridgeMessage[] = [\n uiInitialize,\n uiInitialized,\n uiSizeChanged,\n uiOpenLink,\n mostraReady,\n mostraFields,\n mostraPage,\n mostraControlsRequest,\n mostraFlush,\n mostraVersionAvailable,\n mostraFieldFocus,\n] as readonly AnyBridgeMessage[];\n\n/** The window events arrive on (`window` itself). */\nexport interface BridgeReceiver {\n /** Starts delivering `message` events to `listener`. */\n addEventListener(type: \"message\", listener: (event: BridgeEvent) => void): void;\n /** Stops delivering them. */\n removeEventListener(type: \"message\", listener: (event: BridgeEvent) => void): void;\n}\n\n/** The parts of a `MessageEvent` the bridge reads. */\nexport interface BridgeEvent {\n /** The message. */\n readonly data: unknown;\n /** The sender's origin, as the browser reports it. */\n readonly origin: string;\n /** The sending window. */\n readonly source: unknown;\n}\n\n/** The window messages go to: the frame's `contentWindow`, or the shell (`window.parent`). */\nexport interface BridgePeer {\n /** Posts `message` to the window, delivered only if its origin is `targetOrigin`. */\n postMessage(message: unknown, targetOrigin: string): void;\n}\n\n/** Why the bridge dropped a message, for logs and tests. */\nexport type BridgeRejection =\n | \"wrong-source\"\n | \"wrong-origin\"\n | \"not-json-rpc\"\n | \"unknown-method\"\n | \"wrong-direction\"\n | \"invalid-params\";\n\n/** Options for {@link connectBridge}. */\nexport interface BridgeOptions {\n /** This end. It accepts only messages the other side sends. */\n readonly side: BridgeSide;\n /** Where messages arrive. */\n readonly receiver: BridgeReceiver;\n /** The window this end talks to, looked up on every message (a frame's window changes on reload). */\n readonly peer: () => BridgePeer | null | undefined;\n /** The peer's exact origin. Messages from any other origin are dropped. */\n readonly peerOrigin: string;\n /** Answers a request from the peer; throw an {@link RpcError} to answer with an error. */\n readonly onRequest?: (message: AnyBridgeMessage, params: unknown) => unknown;\n /** Receives a notification from the peer. */\n readonly onNotification?: (message: AnyBridgeMessage, params: unknown) => void;\n /** Hears about every dropped message. */\n readonly onRejected?: (reason: BridgeRejection, event: BridgeEvent) => void;\n}\n\n/** One end of a connected bridge. */\nexport interface Bridge {\n /** Sends a request this side may send and resolves with its validated result. */\n call<P, R>(message: BridgeMessage<P, R>, params: P, options?: { timeoutMs?: number }): Promise<R>;\n /** Sends a notification this side may send. */\n notify<P>(message: BridgeMessage<P, undefined>, params: P): void;\n /** Stops listening; waiting calls reject. */\n close(): void;\n}\n\nconst asMethod = <P, R>(message: BridgeMessage<P, R>): MethodDefinition<P, R> => ({\n method: message.method,\n direction: \"client-to-instance\",\n mutating: false,\n params: message.params,\n result: message.result,\n});\n\n/**\n * Connects one end of the bridge. Every incoming message must come from `peer()` at exactly\n * `peerOrigin`, be a JSON-RPC message, name a message the other side sends, and carry valid params.\n */\nexport function connectBridge(options: BridgeOptions): Bridge {\n const known = new Map(BRIDGE_MESSAGES.map((message) => [message.method, message]));\n const send = (message: unknown): void => {\n const peer = options.peer();\n if (!peer) throw new Error(\"The bridge's peer window is gone.\");\n peer.postMessage(message, options.peerOrigin);\n };\n const rpc = new RpcPeer({\n send,\n onRequest: (method, params) => {\n const message = known.get(method);\n if (!message || message.from === options.side || message.kind !== \"request\") {\n throw new RpcError(\n hostDiagnostic(\"MOSTRA_HOST_METHOD_UNKNOWN\", {\n message: `The bridge has no request ${method} for this side.`,\n }),\n JSON_RPC_ERROR_CODES.methodNotFound,\n );\n }\n if (!options.onRequest) {\n throw new RpcError(\n hostDiagnostic(\"MOSTRA_HOST_METHOD_UNKNOWN\", {\n message: `This side doesn't answer ${method}.`,\n }),\n JSON_RPC_ERROR_CODES.methodNotFound,\n );\n }\n const parsed = message.params.safeParse(params ?? {});\n if (!parsed.success) {\n throw new RpcError(\n hostDiagnostic(\"MOSTRA_HOST_INVALID_PARAMS\", {\n message: `Invalid params for ${method}.`,\n }),\n JSON_RPC_ERROR_CODES.invalidParams,\n );\n }\n return options.onRequest(message, parsed.data);\n },\n onNotification: (method, params) => {\n const message = known.get(method);\n if (message?.kind !== \"notification\" || message.from === options.side) return;\n const parsed = message.params.safeParse(params ?? {});\n if (parsed.success) options.onNotification?.(message, parsed.data);\n },\n });\n\n /** Why an incoming message must be dropped, or `undefined` when the RPC peer may take it. */\n const screen = (event: BridgeEvent): BridgeRejection | undefined => {\n const peer = options.peer();\n if (!peer || event.source !== peer) return \"wrong-source\";\n if (event.origin !== options.peerOrigin) return \"wrong-origin\";\n const classified = classifyMessage(event.data);\n if (classified.kind === \"invalid\") return \"not-json-rpc\";\n if (classified.kind !== \"request\" && classified.kind !== \"notification\") return undefined;\n const message = known.get(classified.message.method);\n if (!message) return \"unknown-method\";\n if (message.from === options.side) return \"wrong-direction\";\n if (!message.params.safeParse(classified.message.params ?? {}).success) return \"invalid-params\";\n return undefined;\n };\n const listener = (event: BridgeEvent): void => {\n const rejection = screen(event);\n if (rejection !== undefined) {\n options.onRejected?.(rejection, event);\n // A request from the right window still gets its error answer from the RPC peer.\n const answerable =\n rejection !== \"wrong-source\" &&\n rejection !== \"wrong-origin\" &&\n rejection !== \"not-json-rpc\" &&\n classifyMessage(event.data).kind === \"request\";\n if (!answerable) return;\n }\n rpc.receive(event.data);\n };\n options.receiver.addEventListener(\"message\", listener);\n\n const sendable = (message: AnyBridgeMessage): void => {\n if (message.from !== options.side) {\n throw new Error(`The ${options.side} doesn't send ${message.method}.`);\n }\n };\n return {\n call(message, params, callOptions) {\n sendable(message as AnyBridgeMessage);\n return rpc.call(asMethod(message), params, callOptions ?? {});\n },\n notify(message, params) {\n sendable(message as AnyBridgeMessage);\n const parsed = message.params.parse(params);\n rpc.notify(message.method, parsed as Readonly<Record<string, unknown>>);\n },\n close() {\n options.receiver.removeEventListener(\"message\", listener);\n rpc.close();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,4BAA4B;AAYzC,MAAM,iBAAkD,EAAE,YAAY;CACpE,MAAM,EAAE,OAAO;CACf,SAAS,EAAE,OAAO;CAClB,OAAO,EAAE,OAAO,CAAC,CAAC,cAAc;AAClC,CAAC;;AAmDD,MAAa,eAAsE;CACjF,QAAQ;CACR,MAAM;CACN,MAAM;CACN,QAAQ,EAAE,YAAY;EACpB,SAAS;EACT,iBAAiB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;EACjD,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;EACjC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc;CAChF,CAAC;CACD,QAAQ,EAAE,YAAY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C,IAAI,WAAW,SAAS,aAAa,WAAW,SAAS,gBAAgB,OAAO,KAAA;EAChF,MAAM,UAAU,MAAM,IAAI,WAAW,QAAQ,MAAM;EACnD,IAAI,CAAC,SAAS,OAAO;EACrB,IAAI,QAAQ,SAAS,QAAQ,MAAM,OAAO;EAC1C,IAAI,CAAC,QAAQ,OAAO,UAAU,WAAW,QAAQ,UAAU,CAAC,CAAC,CAAC,CAAC,SAAS,OAAO;CAEjF;CACA,MAAM,YAAY,UAA6B;EAC7C,MAAM,YAAY,OAAO,KAAK;EAC9B,IAAI,cAAc,KAAA,GAAW;GAC3B,QAAQ,aAAa,WAAW,KAAK;GAOrC,IAAI,EAJF,cAAc,kBACd,cAAc,kBACd,cAAc,kBACd,gBAAgB,MAAM,IAAI,CAAC,CAAC,SAAS,YACtB;EACnB;EACA,IAAI,QAAQ,MAAM,IAAI;CACxB;CACA,QAAQ,SAAS,iBAAiB,WAAW,QAAQ;CAErD,MAAM,YAAY,YAAoC;EACpD,IAAI,QAAQ,SAAS,QAAQ,MAC3B,MAAM,IAAI,MAAM,OAAO,QAAQ,KAAK,gBAAgB,QAAQ,OAAO,EAAE;CAEzE;CACA,OAAO;EACL,KAAK,SAAS,QAAQ,aAAa;GACjC,SAAS,OAA2B;GACpC,OAAO,IAAI,KAAK,SAAS,OAAO,GAAG,QAAQ,eAAe,CAAC,CAAC;EAC9D;EACA,OAAO,SAAS,QAAQ;GACtB,SAAS,OAA2B;GACpC,MAAM,SAAS,QAAQ,OAAO,MAAM,MAAM;GAC1C,IAAI,OAAO,QAAQ,QAAQ,MAA2C;EACxE;EACA,QAAQ;GACN,QAAQ,SAAS,oBAAoB,WAAW,QAAQ;GACxD,IAAI,MAAM;EACZ;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"bridge.js","names":[],"sources":["../src/bridge.ts"],"sourcesContent":["/**\n * The shell ↔ artifact bridge (INTERFACES §5, ROUND-3 §8, SH-04): JSON-RPC 2.0 over\n * `postMessage`, shaped like MCP Apps so exporting an artifact as an MCP App only swaps the\n * transport. Both ends accept a message only when it comes from the one window they talk to, at\n * its exact origin, and only when it is a message of the bridge's set with valid params; anything\n * else is dropped (or, for a request from the right window, answered with an error). It has no\n * I/O of its own: the caller hands it the window objects.\n *\n * ```ts\n * // In the shell:\n * const bridge = connectBridge({\n * side: \"shell\",\n * receiver: window,\n * peer: () => frame.contentWindow,\n * peerOrigin: \"http://127.0.0.1:23457\",\n * onRequest: (message, params) => (message === uiInitialize ? initializeResult : undefined),\n * });\n * ```\n */\nimport * as z from \"zod\";\nimport type { MethodDefinition } from \"./method.ts\";\nimport { hostDiagnostic, JSON_RPC_ERROR_CODES, RpcError } from \"./rpc/error.ts\";\nimport { classifyMessage } from \"./rpc/messages.ts\";\nimport { RpcPeer } from \"./rpc/peer.ts\";\nimport { REVIEW_SET_ID_PATTERN, ViewContextWire } from \"./view.ts\";\n\n/** Which end of the bridge: the trusted shell, or the artifact's frame. */\nexport type BridgeSide = \"shell\" | \"artifact\";\n\n/** One message of the bridge's set. */\nexport interface BridgeMessage<P, R> {\n /** The JSON-RPC method name; MCP Apps' name where the concept exists. */\n readonly method: string;\n /** The side that sends it. */\n readonly from: BridgeSide;\n /** A request is answered; a notification isn't. */\n readonly kind: \"request\" | \"notification\";\n /** The schema of its params. */\n readonly params: z.ZodType<P>;\n /** The schema of a request's result (`z.undefined()` for notifications). */\n readonly result: z.ZodType<R>;\n}\n\n/** A bridge message of any params and result type. */\nexport type AnyBridgeMessage = BridgeMessage<unknown, unknown>;\n\n/** The version of MCP Apps whose message shapes the bridge follows (VERIFIED_FACTS, MCP). */\nexport const MCP_APPS_PROTOCOL_VERSION = \"2026-01-26\";\n\n/** An application's name and version (MCP's `Implementation`). */\nexport interface BridgeImplementation {\n /** A stable machine name, such as `mostra-shell`. */\n readonly name: string;\n /** Its release. */\n readonly version: string;\n /** A name for people. */\n readonly title?: string;\n}\n\nconst Implementation: z.ZodType<BridgeImplementation> = z.looseObject({\n name: z.string(),\n version: z.string(),\n title: z.string().exactOptional(),\n});\n\n/** The params of `ui/initialize`: the artifact introduces itself (MCP Apps). */\nexport interface UiInitializeParams {\n /** The artifact's client runtime. */\n readonly appInfo: BridgeImplementation;\n /** What the artifact offers (MCP Apps' `McpUiAppCapabilities`). */\n readonly appCapabilities: Readonly<Record<string, unknown>>;\n /** The MCP Apps revision the artifact speaks, {@link MCP_APPS_PROTOCOL_VERSION}. */\n readonly protocolVersion: string;\n /**\n * What the page is (WP-07): the version whose build the frame loaded. An artifact origin serves\n * the version its frame session last entered (D98 item 5), so a frame reloaded after another\n * tab switched versions may hold another version than its view; the shell re-enters its own.\n */\n readonly mostra?: { readonly versionId: string };\n}\n\n/** What the shell tells the artifact about where it is shown (MCP Apps' `HostContext`). */\nexport interface BridgeHostContext {\n /** The viewer's color scheme. */\n readonly theme?: \"light\" | \"dark\";\n /** How the artifact is shown: the shell shows it `fullscreen`. */\n readonly displayMode?: \"inline\" | \"fullscreen\" | \"pip\";\n /** The display modes the shell offers. */\n readonly availableDisplayModes?: readonly string[];\n /** The viewer's language (BCP 47). */\n readonly locale?: string;\n /** The viewer's time zone (IANA). */\n readonly timeZone?: string;\n /** The kind of device. */\n readonly platform?: \"web\" | \"desktop\" | \"mobile\";\n /** Further MCP Apps context, passed through. */\n readonly [key: string]: unknown;\n}\n\n/** The result of `ui/initialize`: the shell introduces itself (MCP Apps). */\nexport interface UiInitializeResult {\n /** The MCP Apps revision both ends speak. */\n readonly protocolVersion: string;\n /** The shell. */\n readonly hostInfo: BridgeImplementation;\n /** What the shell offers (MCP Apps' `McpUiHostCapabilities`). */\n readonly hostCapabilities: Readonly<Record<string, unknown>>;\n /** Where and how the artifact is shown. */\n readonly hostContext: BridgeHostContext;\n /** Mostra's shell: the view this frame load is, and what the host allows in it (WP-07). */\n readonly mostra?: ViewContextWire;\n}\n\n/** `ui/initialize`: the artifact's first request, answered with the shell's context. */\nexport const uiInitialize: BridgeMessage<UiInitializeParams, UiInitializeResult> = {\n method: \"ui/initialize\",\n from: \"artifact\",\n kind: \"request\",\n params: z.looseObject({\n appInfo: Implementation,\n appCapabilities: z.record(z.string(), z.unknown()),\n protocolVersion: z.string().min(1),\n mostra: z.looseObject({ versionId: z.string().min(1).max(64) }).exactOptional(),\n }),\n result: z.looseObject({\n protocolVersion: z.string().min(1),\n hostInfo: Implementation,\n hostCapabilities: z.record(z.string(), z.unknown()),\n hostContext: z.looseObject({\n theme: z.enum([\"light\", \"dark\"]).exactOptional(),\n displayMode: z.enum([\"inline\", \"fullscreen\", \"pip\"]).exactOptional(),\n availableDisplayModes: z.array(z.string()).readonly().exactOptional(),\n locale: z.string().exactOptional(),\n timeZone: z.string().exactOptional(),\n platform: z.enum([\"web\", \"desktop\", \"mobile\"]).exactOptional(),\n }),\n mostra: ViewContextWire.exactOptional(),\n }),\n};\n\n/** `ui/notifications/initialized`: the artifact finished initializing; the shell may now send. */\nexport const uiInitialized: BridgeMessage<Readonly<Record<string, unknown>>, undefined> = {\n method: \"ui/notifications/initialized\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.record(z.string(), z.unknown()),\n result: z.undefined(),\n};\n\n/** `ui/notifications/size-changed`: the artifact's rendered size (MCP Apps). */\nexport const uiSizeChanged: BridgeMessage<\n { readonly width?: number; readonly height?: number },\n undefined\n> = {\n method: \"ui/notifications/size-changed\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n width: z.number().min(0).exactOptional(),\n height: z.number().min(0).exactOptional(),\n }),\n result: z.undefined(),\n};\n\n/**\n * The URL schemes `ui/open-link` opens: the web, mail and phone numbers. Anything else, such as\n * `javascript:` or `data:`, would run or show content in the shell's own context.\n */\nexport const OPEN_LINK_SCHEMES: readonly string[] = [\"http:\", \"https:\", \"mailto:\", \"tel:\"];\n\n/**\n * `ui/open-link`: the artifact asks the shell to open a URL in a new tab (MCP Apps). The frame\n * can't navigate the viewer's tab itself (D98 item 7), so this is how an artifact sends the\n * viewer anywhere. `isError` is `true` when the shell couldn't open it.\n */\nexport const uiOpenLink: BridgeMessage<\n { readonly url: string },\n { readonly isError?: boolean; readonly [key: string]: unknown }\n> = {\n method: \"ui/open-link\",\n from: \"artifact\",\n kind: \"request\",\n params: z.looseObject({ url: z.string().min(1).max(8192) }),\n result: z.looseObject({ isError: z.boolean().exactOptional() }),\n};\n\n/** `mostra/ready`: the artifact's page has rendered; `verify` waits for it (ROUND-3 §8). */\nexport const mostraReady: BridgeMessage<Readonly<Record<string, unknown>>, undefined> = {\n method: \"mostra/ready\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.record(z.string(), z.unknown()),\n result: z.undefined(),\n};\n\n// ── Fields, pages, controls and versions (WP-07, INTERFACES §5, ROUND-3 §8) ──────────────\n\n/** The page's save state, as the shell's rail shows it (D47). */\nexport type SaveState = \"saved\" | \"saving\" | \"offline\" | \"conflict\";\n\n/** Why a field blocks a submit (INTERFACES §2.3). */\nexport interface SubmitBlocker {\n /** The field's ID. */\n readonly fieldId: string;\n /** Its label, when it has one. */\n readonly label?: string;\n /** `required` without a value, `invalid` by its `validate`, or a `conflict` not yet resolved. */\n readonly reason: \"required\" | \"invalid\" | \"conflict\";\n}\n\n/**\n * The longest label, validation message or other text a field carries over the bridge; a page\n * shortens longer ones before it sends them (Claude review finding 11).\n */\nexport const BRIDGE_TEXT_MAX = 1024;\n\n/** The most fields or blockers one bridge message lists; a page sends those that matter first. */\nexport const BRIDGE_FIELDS_MAX = 10_000;\n\nconst SubmitBlockerSchema: z.ZodType<SubmitBlocker> = z.looseObject({\n fieldId: z.string().min(1).max(256),\n label: z.string().max(BRIDGE_TEXT_MAX).exactOptional(),\n reason: z.enum([\"required\", \"invalid\", \"conflict\"]),\n});\n\n/**\n * A field the page has mounted, with what the shell needs to list blockers by label (D52, D106).\n * The page reports it; the shell checks `required` against the draft it reads itself.\n */\nexport interface FieldRegistration {\n /** The field's ID. */\n readonly id: string;\n /** The label people see. */\n readonly label?: string;\n /** Whether a submit needs a value. */\n readonly required?: boolean;\n /** The viewer's draft or the artifact's shared state. */\n readonly scope: \"viewer\" | \"artifact\";\n /** Whether its value is kept out of events and logs. */\n readonly sensitive?: boolean;\n /** Its `validate` message for the current value, if any. */\n readonly error?: string;\n /** Whether it has a conflict the viewer hasn't resolved. */\n readonly conflict?: boolean;\n}\n\n/** The params of `mostra/fields`. */\nexport interface FieldsParams {\n /** Every mounted field, once per ID. */\n readonly fields: readonly FieldRegistration[];\n /** The page's save state. */\n readonly save: SaveState;\n /** Whether edits are waiting to be saved (typed, offline, or in the journal). */\n readonly unsaved: boolean;\n}\n\n/**\n * `mostra/fields`: the page's mounted fields and save state, sent whenever they change, so the\n * shell lists blockers by label and its rail shows \"Saving\" and \"Saved\" (INTERFACES §5).\n */\nexport const mostraFields: BridgeMessage<FieldsParams, undefined> = {\n method: \"mostra/fields\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n fields: z\n .array(\n z.looseObject({\n id: z.string().min(1).max(256),\n label: z.string().max(BRIDGE_TEXT_MAX).exactOptional(),\n required: z.boolean().exactOptional(),\n scope: z.enum([\"viewer\", \"artifact\"]),\n sensitive: z.boolean().exactOptional(),\n error: z.string().max(BRIDGE_TEXT_MAX).exactOptional(),\n conflict: z.boolean().exactOptional(),\n }),\n )\n .max(BRIDGE_FIELDS_MAX)\n .readonly(),\n save: z.enum([\"saved\", \"saving\", \"offline\", \"conflict\"]),\n unsaved: z.boolean(),\n }),\n result: z.undefined(),\n};\n\n/**\n * `mostra/page`: the page the viewer is on, inside a `pages/` artifact (D57), so comments record\n * it (WP-20). `path` is the route's path with its search and hash, whatever the history mode.\n */\nexport const mostraPage: BridgeMessage<\n { readonly path: string; readonly title?: string },\n undefined\n> = {\n method: \"mostra/page\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n path: z.string().min(1).max(2048),\n title: z.string().max(1024).exactOptional(),\n }),\n result: z.undefined(),\n};\n\n/** A trusted control the artifact asks the shell for (INTERFACES §5): the artifact asks, the shell decides. */\nexport type ControlRequest =\n | {\n /** Relabel the shell's trusted Submit, with an optional confirmation text. */\n readonly control: \"submit\";\n readonly label?: string;\n readonly confirm?: string;\n }\n | {\n /** Render a trusted Choose for a review set's candidates (D113). */\n readonly control: \"choose\";\n readonly reviewSetId: string;\n readonly candidates: readonly { readonly id: string; readonly label?: string }[];\n /** The candidate the page shows now, which Choose names. */\n readonly current?: string;\n }\n | {\n /** Withdraw an earlier request: the Submit label, or a review set's Choose. */\n readonly control: \"release\";\n readonly submit?: true;\n readonly reviewSetId?: string;\n };\n\n/** The longest Submit label the shell renders: one short line. */\nexport const CONTROL_LABEL_MAX = 48;\n\n/**\n * `mostra/controls.request`: the artifact asks the shell for a trusted control (D06, SH-02). The\n * shell renders it in its own origin, where the artifact can neither click nor reach it, and\n * answers whether it is shown: a control the host's policy leaves out is not (D108).\n */\nexport const mostraControlsRequest: BridgeMessage<ControlRequest, { readonly shown: boolean }> = {\n method: \"mostra/controls.request\",\n from: \"artifact\",\n kind: \"request\",\n params: z.discriminatedUnion(\"control\", [\n z.looseObject({\n control: z.literal(\"submit\"),\n label: z.string().min(1).max(CONTROL_LABEL_MAX).exactOptional(),\n confirm: z.string().min(1).max(500).exactOptional(),\n }),\n z.looseObject({\n control: z.literal(\"choose\"),\n reviewSetId: z.string().regex(REVIEW_SET_ID_PATTERN),\n candidates: z\n .array(\n z.looseObject({\n id: z.string().min(1).max(256),\n label: z.string().max(CONTROL_LABEL_MAX).exactOptional(),\n }),\n )\n .min(1)\n .max(64)\n .readonly(),\n current: z.string().min(1).max(256).exactOptional(),\n }),\n z.looseObject({\n control: z.literal(\"release\"),\n submit: z.literal(true).exactOptional(),\n reviewSetId: z.string().regex(REVIEW_SET_ID_PATTERN).exactOptional(),\n }),\n ]) as unknown as z.ZodType<ControlRequest>,\n result: z.looseObject({ shown: z.boolean() }),\n};\n\n/** What the page answers `mostra/flush`. */\nexport interface FlushResult {\n /** The viewer's draft revision once every save landed. */\n readonly revision: string;\n /** Whether edits still wait (offline, or a save failed). */\n readonly unsaved: boolean;\n /** What blocks a submit now: invalid values and open conflicts, and required fields the page sees empty. */\n readonly blockers: readonly SubmitBlocker[];\n}\n\n/**\n * `mostra/flush`: the shell asks the page to save everything now, before its trusted Submit or a\n * switch to a newer version (IN-02, D110). For a submit, the page first writes the defaults the\n * viewer saw. The shell checks the answer against the draft it reads itself.\n */\nexport const mostraFlush: BridgeMessage<{ readonly reason: \"submit\" | \"switch\" }, FlushResult> = {\n method: \"mostra/flush\",\n from: \"shell\",\n kind: \"request\",\n params: z.looseObject({ reason: z.enum([\"submit\", \"switch\"]) }),\n result: z.looseObject({\n revision: z.string().regex(/^(0|[1-9][0-9]{0,15})$/),\n unsaved: z.boolean(),\n blockers: z.array(SubmitBlockerSchema).max(BRIDGE_FIELDS_MAX).readonly(),\n }),\n};\n\n/** The params of `mostra/version.available`. */\nexport interface VersionAvailableParams {\n /** The newer version's ID. */\n readonly versionId: string;\n /** Its number. */\n readonly version: number;\n /** How many of the viewer's answers it doesn't carry over (D42). */\n readonly orphans: number;\n}\n\n/**\n * `mostra/version.available`: a newer version was published while the page is open (VR-04). The\n * shell always shows its own trusted banner; the page may show a notice too.\n */\nexport const mostraVersionAvailable: BridgeMessage<VersionAvailableParams, undefined> = {\n method: \"mostra/version.available\",\n from: \"shell\",\n kind: \"notification\",\n params: z.looseObject({\n versionId: z.string().min(1),\n version: z.int().min(1),\n orphans: z.int().min(0),\n }),\n result: z.undefined(),\n};\n\n/** `mostra/field.focus`: the viewer picked a blocker in the shell; the page focuses that field. */\nexport const mostraFieldFocus: BridgeMessage<{ readonly id: string }, undefined> = {\n method: \"mostra/field.focus\",\n from: \"shell\",\n kind: \"notification\",\n params: z.looseObject({ id: z.string().min(1).max(256) }),\n result: z.undefined(),\n};\n\n/** The params of `mostra/frameSession.failed`. */\nexport interface FrameSessionFailedParams {\n /** `MOSTRA_HYGIENE_FRAME_SESSION`. */\n readonly code: string;\n /** What went wrong, for the shell to show. */\n readonly message: string;\n /**\n * Why: `unsupported` (this browser offers the frame no service worker, as in a private window),\n * `blocked` (the browser refused to install it), `conflict` (another service worker holds `/`\n * on the artifact's origin), or `refused` (the gateway refused the frame's entry).\n */\n readonly reason: \"unsupported\" | \"blocked\" | \"conflict\" | \"refused\" | (string & {});\n}\n\n/**\n * `mostra/frameSession.failed`: the worker-mode bootstrap page (D70, D158 item 5) couldn't start\n * the frame's session. It is sent before any client runtime runs, so the shell shows why instead\n * of a frame that never greets.\n */\nexport const mostraFrameSessionFailed: BridgeMessage<FrameSessionFailedParams, undefined> = {\n method: \"mostra/frameSession.failed\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({\n code: z.string().min(1).max(128),\n message: z.string().max(BRIDGE_TEXT_MAX),\n reason: z.string().min(1).max(64),\n }),\n result: z.undefined(),\n};\n\n/**\n * `mostra/frameSession.entered`: the worker-mode bootstrap page (D70, D158 item 5) has its\n * session and its service worker, and is loading the version. The shell's wait for the frame's\n * page starts here: the bootstrap's own load is not the page's (WP-13).\n */\nexport const mostraFrameSessionEntered: BridgeMessage<\n Readonly<Record<string, unknown>>,\n undefined\n> = {\n method: \"mostra/frameSession.entered\",\n from: \"artifact\",\n kind: \"notification\",\n params: z.looseObject({}),\n result: z.undefined(),\n};\n\n/**\n * Every message of the bridge in this release. WP-20 adds review messages; a message never\n * changes meaning once released (D32).\n */\nexport const BRIDGE_MESSAGES: readonly AnyBridgeMessage[] = [\n uiInitialize,\n uiInitialized,\n uiSizeChanged,\n uiOpenLink,\n mostraReady,\n mostraFields,\n mostraPage,\n mostraControlsRequest,\n mostraFlush,\n mostraVersionAvailable,\n mostraFieldFocus,\n mostraFrameSessionFailed,\n mostraFrameSessionEntered,\n] as readonly AnyBridgeMessage[];\n\n/** The window events arrive on (`window` itself). */\nexport interface BridgeReceiver {\n /** Starts delivering `message` events to `listener`. */\n addEventListener(type: \"message\", listener: (event: BridgeEvent) => void): void;\n /** Stops delivering them. */\n removeEventListener(type: \"message\", listener: (event: BridgeEvent) => void): void;\n}\n\n/** The parts of a `MessageEvent` the bridge reads. */\nexport interface BridgeEvent {\n /** The message. */\n readonly data: unknown;\n /** The sender's origin, as the browser reports it. */\n readonly origin: string;\n /** The sending window. */\n readonly source: unknown;\n}\n\n/** The window messages go to: the frame's `contentWindow`, or the shell (`window.parent`). */\nexport interface BridgePeer {\n /** Posts `message` to the window, delivered only if its origin is `targetOrigin`. */\n postMessage(message: unknown, targetOrigin: string): void;\n}\n\n/** Why the bridge dropped a message, for logs and tests. */\nexport type BridgeRejection =\n | \"wrong-source\"\n | \"wrong-origin\"\n | \"not-json-rpc\"\n | \"unknown-method\"\n | \"wrong-direction\"\n | \"invalid-params\";\n\n/** Options for {@link connectBridge}. */\nexport interface BridgeOptions {\n /** This end. It accepts only messages the other side sends. */\n readonly side: BridgeSide;\n /** Where messages arrive. */\n readonly receiver: BridgeReceiver;\n /** The window this end talks to, looked up on every message (a frame's window changes on reload). */\n readonly peer: () => BridgePeer | null | undefined;\n /** The peer's exact origin. Messages from any other origin are dropped. */\n readonly peerOrigin: string;\n /** Answers a request from the peer; throw an {@link RpcError} to answer with an error. */\n readonly onRequest?: (message: AnyBridgeMessage, params: unknown) => unknown;\n /** Receives a notification from the peer. */\n readonly onNotification?: (message: AnyBridgeMessage, params: unknown) => void;\n /** Hears about every dropped message. */\n readonly onRejected?: (reason: BridgeRejection, event: BridgeEvent) => void;\n}\n\n/** One end of a connected bridge. */\nexport interface Bridge {\n /** Sends a request this side may send and resolves with its validated result. */\n call<P, R>(message: BridgeMessage<P, R>, params: P, options?: { timeoutMs?: number }): Promise<R>;\n /** Sends a notification this side may send. */\n notify<P>(message: BridgeMessage<P, undefined>, params: P): void;\n /** Stops listening; waiting calls reject. */\n close(): void;\n}\n\nconst asMethod = <P, R>(message: BridgeMessage<P, R>): MethodDefinition<P, R> => ({\n method: message.method,\n direction: \"client-to-instance\",\n mutating: false,\n params: message.params,\n result: message.result,\n});\n\n/**\n * Connects one end of the bridge. Every incoming message must come from `peer()` at exactly\n * `peerOrigin`, be a JSON-RPC message, name a message the other side sends, and carry valid params.\n */\nexport function connectBridge(options: BridgeOptions): Bridge {\n const known = new Map(BRIDGE_MESSAGES.map((message) => [message.method, message]));\n const send = (message: unknown): void => {\n const peer = options.peer();\n if (!peer) throw new Error(\"The bridge's peer window is gone.\");\n peer.postMessage(message, options.peerOrigin);\n };\n const rpc = new RpcPeer({\n send,\n onRequest: (method, params) => {\n const message = known.get(method);\n if (!message || message.from === options.side || message.kind !== \"request\") {\n throw new RpcError(\n hostDiagnostic(\"MOSTRA_HOST_METHOD_UNKNOWN\", {\n message: `The bridge has no request ${method} for this side.`,\n }),\n JSON_RPC_ERROR_CODES.methodNotFound,\n );\n }\n if (!options.onRequest) {\n throw new RpcError(\n hostDiagnostic(\"MOSTRA_HOST_METHOD_UNKNOWN\", {\n message: `This side doesn't answer ${method}.`,\n }),\n JSON_RPC_ERROR_CODES.methodNotFound,\n );\n }\n const parsed = message.params.safeParse(params ?? {});\n if (!parsed.success) {\n throw new RpcError(\n hostDiagnostic(\"MOSTRA_HOST_INVALID_PARAMS\", {\n message: `Invalid params for ${method}.`,\n }),\n JSON_RPC_ERROR_CODES.invalidParams,\n );\n }\n return options.onRequest(message, parsed.data);\n },\n onNotification: (method, params) => {\n const message = known.get(method);\n if (message?.kind !== \"notification\" || message.from === options.side) return;\n const parsed = message.params.safeParse(params ?? {});\n if (parsed.success) options.onNotification?.(message, parsed.data);\n },\n });\n\n /** Why an incoming message must be dropped, or `undefined` when the RPC peer may take it. */\n const screen = (event: BridgeEvent): BridgeRejection | undefined => {\n const peer = options.peer();\n if (!peer || event.source !== peer) return \"wrong-source\";\n if (event.origin !== options.peerOrigin) return \"wrong-origin\";\n const classified = classifyMessage(event.data);\n if (classified.kind === \"invalid\") return \"not-json-rpc\";\n if (classified.kind !== \"request\" && classified.kind !== \"notification\") return undefined;\n const message = known.get(classified.message.method);\n if (!message) return \"unknown-method\";\n if (message.from === options.side) return \"wrong-direction\";\n if (!message.params.safeParse(classified.message.params ?? {}).success) return \"invalid-params\";\n return undefined;\n };\n const listener = (event: BridgeEvent): void => {\n const rejection = screen(event);\n if (rejection !== undefined) {\n options.onRejected?.(rejection, event);\n // A request from the right window still gets its error answer from the RPC peer.\n const answerable =\n rejection !== \"wrong-source\" &&\n rejection !== \"wrong-origin\" &&\n rejection !== \"not-json-rpc\" &&\n classifyMessage(event.data).kind === \"request\";\n if (!answerable) return;\n }\n rpc.receive(event.data);\n };\n options.receiver.addEventListener(\"message\", listener);\n\n const sendable = (message: AnyBridgeMessage): void => {\n if (message.from !== options.side) {\n throw new Error(`The ${options.side} doesn't send ${message.method}.`);\n }\n };\n return {\n call(message, params, callOptions) {\n sendable(message as AnyBridgeMessage);\n return rpc.call(asMethod(message), params, callOptions ?? {});\n },\n notify(message, params) {\n sendable(message as AnyBridgeMessage);\n const parsed = message.params.parse(params);\n rpc.notify(message.method, parsed as Readonly<Record<string, unknown>>);\n },\n close() {\n options.receiver.removeEventListener(\"message\", listener);\n rpc.close();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA+CA,MAAa,4BAA4B;AAYzC,MAAM,iBAAkD,EAAE,YAAY;CACpE,MAAM,EAAE,OAAO;CACf,SAAS,EAAE,OAAO;CAClB,OAAO,EAAE,OAAO,CAAC,CAAC,cAAc;AAClC,CAAC;;AAmDD,MAAa,eAAsE;CACjF,QAAQ;CACR,MAAM;CACN,MAAM;CACN,QAAQ,EAAE,YAAY;EACpB,SAAS;EACT,iBAAiB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;EACjD,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;EACjC,QAAQ,EAAE,YAAY,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,cAAc;CAChF,CAAC;CACD,QAAQ,EAAE,YAAY;EACpB,iBAAiB,EAAE,OAAO,CA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AAK,SAAS,OAAO,GAAG,QAAQ,eAAe,CAAC,CAAC;EAC9D;EACA,OAAO,SAAS,QAAQ;GACtB,SAAS,OAA2B;GACpC,MAAM,SAAS,QAAQ,OAAO,MAAM,MAAM;GAC1C,IAAI,OAAO,QAAQ,QAAQ,MAA2C;EACxE;EACA,QAAQ;GACN,QAAQ,SAAS,oBAAoB,WAAW,QAAQ;GACxD,IAAI,MAAM;EACZ;CACF;AACF"}
|
package/dist/browser.d.ts
CHANGED
|
@@ -120,9 +120,85 @@ export interface FrameTicket extends ViewContext {
|
|
|
120
120
|
* shell says so, and it is never a published version.
|
|
121
121
|
*/
|
|
122
122
|
readonly devPreview?: true;
|
|
123
|
+
/**
|
|
124
|
+
* `worker` when the shell and the artifact are two sites (a Cloudflare quick tunnel, a host's
|
|
125
|
+
* addresses on two hosts): the frame enters through the bootstrap page and a service worker
|
|
126
|
+
* (D70, D158 item 5). Absent: cookie mode.
|
|
127
|
+
*/
|
|
128
|
+
readonly mode?: "worker";
|
|
123
129
|
}
|
|
124
130
|
/** The Zod schema of the `FrameTicket` type. */
|
|
125
131
|
export declare const FrameTicket: z.ZodType<FrameTicket>;
|
|
132
|
+
/**
|
|
133
|
+
* The header Mostra's service worker adds to every same-origin request of a worker-mode frame:
|
|
134
|
+
* its frame session's secret, which no cookie can carry across sites.
|
|
135
|
+
*/
|
|
136
|
+
export declare const FRAME_SESSION_HEADER = "x-mostra-frame";
|
|
137
|
+
/**
|
|
138
|
+
* `POST /_mostra/enter` on the artifact's origin: the bootstrap page exchanges the shell's
|
|
139
|
+
* single-use frame ticket, from `/_mostra/enter#t=…`, for a worker-mode frame session.
|
|
140
|
+
*/
|
|
141
|
+
export interface EnterRequest {
|
|
142
|
+
/** The frame ticket. */
|
|
143
|
+
readonly ticket: string;
|
|
144
|
+
}
|
|
145
|
+
/** The Zod schema of the `EnterRequest` type. */
|
|
146
|
+
export declare const EnterRequest: z.ZodType<EnterRequest>;
|
|
147
|
+
/** The answer to `EnterRequest`. */
|
|
148
|
+
export interface EnterResult {
|
|
149
|
+
/** The frame session's secret, which the service worker sends as `X-Mostra-Frame`. */
|
|
150
|
+
readonly session: string;
|
|
151
|
+
/** The shell's origin: the only page the bootstrap reports to. */
|
|
152
|
+
readonly shellOrigin: string;
|
|
153
|
+
}
|
|
154
|
+
/** The Zod schema of the `EnterResult` type. */
|
|
155
|
+
export declare const EnterResult: z.ZodType<EnterResult>;
|
|
156
|
+
/**
|
|
157
|
+
* `POST /_mostra/v/{rev}/ticket`: a single-use ticket that opens one event stream, long poll or
|
|
158
|
+
* WebSocket of this session without it (`?ticket=`), so the request can bypass the service
|
|
159
|
+
* worker (VERIFIED_FACTS: Firefox stalls on endless responses a worker passes on).
|
|
160
|
+
*/
|
|
161
|
+
export interface StreamTicketRequest {
|
|
162
|
+
/** What it opens: `stream` (events and polls, the default) or `socket` (a WebSocket). */
|
|
163
|
+
readonly purpose?: "stream" | "socket";
|
|
164
|
+
}
|
|
165
|
+
/** The Zod schema of the `StreamTicketRequest` type. */
|
|
166
|
+
export declare const StreamTicketRequest: z.ZodType<StreamTicketRequest>;
|
|
167
|
+
/** The answer to a `StreamTicketRequest`. */
|
|
168
|
+
export interface StreamTicket {
|
|
169
|
+
/** The ticket: 130 bits, single-use. */
|
|
170
|
+
readonly ticket: string;
|
|
171
|
+
/** When it stops working, 60 s after it was minted. */
|
|
172
|
+
readonly expiresAt: string;
|
|
173
|
+
}
|
|
174
|
+
/** The Zod schema of the `StreamTicket` type. */
|
|
175
|
+
export declare const StreamTicket: z.ZodType<StreamTicket>;
|
|
176
|
+
/**
|
|
177
|
+
* `GET /_mostra/session` on the artifact's origin: the frame session's facts for same-origin code.
|
|
178
|
+
*/
|
|
179
|
+
export interface FrameSessionFacts {
|
|
180
|
+
/** The CSRF token every mutation sends as `X-Mostra-CSRF`. */
|
|
181
|
+
readonly csrf: string;
|
|
182
|
+
/** The artifact the frame shows. */
|
|
183
|
+
readonly artifactId: string;
|
|
184
|
+
/** The shell's exact origin: the bridge's only peer. */
|
|
185
|
+
readonly shellOrigin: string;
|
|
186
|
+
/** The link's scopes. */
|
|
187
|
+
readonly scopes: readonly string[];
|
|
188
|
+
/** The viewer the page acts as (WP-07). */
|
|
189
|
+
readonly viewer?: Viewer;
|
|
190
|
+
/** The version the frame session entered. */
|
|
191
|
+
readonly version?: VersionRef;
|
|
192
|
+
/** How the frame authenticates (D70): absent means `cookie`. */
|
|
193
|
+
readonly mode?: "cookie" | "worker";
|
|
194
|
+
/**
|
|
195
|
+
* `false` where event streams don't pass (a Cloudflare quick tunnel holds responses back until
|
|
196
|
+
* they end): the page long-polls from the start (D47). Absent means streams pass.
|
|
197
|
+
*/
|
|
198
|
+
readonly streams?: boolean;
|
|
199
|
+
}
|
|
200
|
+
/** The Zod schema of the `FrameSessionFacts` type. */
|
|
201
|
+
export declare const FrameSessionFacts: z.ZodType<FrameSessionFacts>;
|
|
126
202
|
/**
|
|
127
203
|
* `POST /a/{artifactId}/_mostra/v/{rev}/submit`: the shell's trusted Submit (the `shell` channel,
|
|
128
204
|
* D40). Only the shell's page can send it: the route takes the shell's session, its exact origin
|
package/dist/browser.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","names":[],"sources":["../src/browser.ts"],"mappings":";;;;;;qBA0Ca;;qBAGA;;qBAGA;;iBAGI;;WAEN;;WAEA;;WAEA,cAAc;;WAEd;;WAEA,cAAc;;;qBAIZ,eAAe,EAAE,QAAQ;;iBAcrB;;WAEN;;WAEA,kBAAkB;;WAElB;;;qBAIE,eAAe,EAAE,QAAQ;;iBAYrB;;WAEN;;WAEA;;WAEA;;;qBAIE,eAAe,EAAE,QAAQ;;iBAYrB;;WAEN,UAAU;;WAEV;;WAEA,QAAQ,SAAS,eAAe;;;qBAI9B,kBAAkB,EAAE,QAAQ;;;;;iBAexB;;WAEN;;WAEA,QAAQ;;WAER,OAAO;;WAEP,OAAO;;WAEP,aAAa;;;;;;WAMb,SAAS;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AEA,SAAS;;WAET,UAAU;;WAEV;;;;;WAKA;;;qBAIE,mBAAmB,EAAE,QAAQ;;;;;;iBAuBzB;;WAEN;;WAEA,kBAAkB;;;qBAIhB,oBAAoB,EAAE,QAAQ;;;;;;iBAY1B;;WAEN;;WAEA;;WAEA,cAAc;;WAEd;;WAEA;;WAEA;;;qBAIE,eAAe,EAAE,QAAQ;;iBAgBrB;;WAEN;;;qBAIE,eAAe,EAAE,QAAQ;;iBAQrB;;WAEN;;WAEA;;WAEA;;WAEA;;;qBAIE,eAAe,EAAE,QAAQ;;;;;;iBAiBrB;;WAEN,SAAS;;WAET,kBAAkB;;;qBAIhB,WAAW,EAAE,QAAQ"}
|
package/dist/browser.js
CHANGED
|
@@ -102,11 +102,54 @@ const FrameTicket = z.object({
|
|
|
102
102
|
follow: z.boolean(),
|
|
103
103
|
pinned: z.boolean(),
|
|
104
104
|
serverParked: z.literal(true).exactOptional(),
|
|
105
|
-
devPreview: z.literal(true).exactOptional()
|
|
105
|
+
devPreview: z.literal(true).exactOptional(),
|
|
106
|
+
mode: z.literal("worker").exactOptional()
|
|
106
107
|
}).register(wireRegistry, {
|
|
107
108
|
id: "FrameTicket",
|
|
108
109
|
description: "A frame ticket: the view it opens, where to load it, and the view's controls."
|
|
109
110
|
});
|
|
111
|
+
/**
|
|
112
|
+
* The header Mostra's service worker adds to every same-origin request of a worker-mode frame:
|
|
113
|
+
* its frame session's secret, which no cookie can carry across sites.
|
|
114
|
+
*/
|
|
115
|
+
const FRAME_SESSION_HEADER = "x-mostra-frame";
|
|
116
|
+
/** The Zod schema of the `EnterRequest` type. */
|
|
117
|
+
const EnterRequest = z.object({ ticket: z.string().min(1).max(64) }).register(wireRegistry, {
|
|
118
|
+
id: "EnterRequest",
|
|
119
|
+
description: "A frame ticket to exchange."
|
|
120
|
+
});
|
|
121
|
+
/** The Zod schema of the `EnterResult` type. */
|
|
122
|
+
const EnterResult = z.object({
|
|
123
|
+
session: z.string().min(1),
|
|
124
|
+
shellOrigin: z.string().min(1)
|
|
125
|
+
}).register(wireRegistry, {
|
|
126
|
+
id: "EnterResult",
|
|
127
|
+
description: "A worker-mode frame session's secret and the shell's origin."
|
|
128
|
+
});
|
|
129
|
+
/** The Zod schema of the `StreamTicketRequest` type. */
|
|
130
|
+
const StreamTicketRequest = z.object({ purpose: z.enum(["stream", "socket"]).exactOptional() }).register(wireRegistry, { id: "StreamTicketRequest" });
|
|
131
|
+
/** The Zod schema of the `StreamTicket` type. */
|
|
132
|
+
const StreamTicket = z.object({
|
|
133
|
+
ticket: z.string().min(1),
|
|
134
|
+
expiresAt: z.iso.datetime()
|
|
135
|
+
}).register(wireRegistry, {
|
|
136
|
+
id: "StreamTicket",
|
|
137
|
+
description: "A single-use ticket for one stream, poll or WebSocket."
|
|
138
|
+
});
|
|
139
|
+
/** The Zod schema of the `FrameSessionFacts` type. */
|
|
140
|
+
const FrameSessionFacts = z.object({
|
|
141
|
+
csrf: z.string().min(1),
|
|
142
|
+
artifactId: ArtifactId.schema,
|
|
143
|
+
shellOrigin: z.string().min(1),
|
|
144
|
+
scopes: z.array(z.string()).readonly(),
|
|
145
|
+
viewer: Viewer.exactOptional(),
|
|
146
|
+
version: VersionRef.exactOptional(),
|
|
147
|
+
mode: z.enum(["cookie", "worker"]).exactOptional(),
|
|
148
|
+
streams: z.boolean().exactOptional()
|
|
149
|
+
}).register(wireRegistry, {
|
|
150
|
+
id: "FrameSessionFacts",
|
|
151
|
+
description: "A frame session's CSRF token, shell origin, scopes, viewer, version and mode."
|
|
152
|
+
});
|
|
110
153
|
/** The Zod schema of the `ShellSubmitRequest` type. */
|
|
111
154
|
const ShellSubmitRequest = z.object({
|
|
112
155
|
viewId: ViewId.schema,
|
|
@@ -151,6 +194,6 @@ const CarryOver = z.object({
|
|
|
151
194
|
description: "The viewer's answers a version doesn't carry over."
|
|
152
195
|
});
|
|
153
196
|
//#endregion
|
|
154
|
-
export { BROWSER_PROTOCOL_REVISION, BROWSER_PROTOCOL_REVISIONS, CarryOver, ChooseRequest, DocumentSnapshot, FieldsRequest, FollowRequest, FrameTicket, OrphanedField, PollResult, REVIEW_SET_ID_PATTERN, SIGNAL_PAYLOAD_MAX_BYTES, ShellSubmitRequest, SignalRequest, StreamSnapshot, SubmitRequest, VersionRef, ViewContext, ViewContextWire, readViewContext };
|
|
197
|
+
export { BROWSER_PROTOCOL_REVISION, BROWSER_PROTOCOL_REVISIONS, CarryOver, ChooseRequest, DocumentSnapshot, EnterRequest, EnterResult, FRAME_SESSION_HEADER, FieldsRequest, FollowRequest, FrameSessionFacts, FrameTicket, OrphanedField, PollResult, REVIEW_SET_ID_PATTERN, SIGNAL_PAYLOAD_MAX_BYTES, ShellSubmitRequest, SignalRequest, StreamSnapshot, StreamTicket, StreamTicketRequest, SubmitRequest, VersionRef, ViewContext, ViewContextWire, readViewContext };
|
|
155
198
|
|
|
156
199
|
//# sourceMappingURL=browser.js.map
|