@mostra/protocol 0.6.2 → 0.7.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/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/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/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;;WAEA;;WAEA;;;;;iBAMM;;WAEN;;WAEA,UAAU;;WAEV,kBAAkB,SAAS;;WAE3B,aAAa;;WAEb,SAAS;;;qBAIP,cAAc,cAAc,oBAAoB;;qBA2BhD,eAAe,cAAc,SAAS;;qB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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;EACpB,iBAAiB,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;EACjC,UAAU;EACV,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;EAClD,aAAa,EAAE,YAAY;GACzB,O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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,CAAC,CAAC,IAAI,CAAC;EACjC,UAAU;EACV,kBAAkB,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC;EAClD,aAAa,EAAE,YAAY;GACzB,OAAO,EAAE,KAAK,CAAC,SAAS,M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AO,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;;;qBAIP,gBAAgB,EAAE,QAAQ;;iBAetB;;WAEN;;WAEA,iBAAiB;;WAEjB,WAAW;;;;;WAKX,qBAAqB;;;qBAInB,YAAY,EAAE,QAAQ;;;;;iBAgBlB,oBAAoB;;WAE1B;;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;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
|
package/dist/browser.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.js","names":[],"sources":["../src/browser.ts"],"sourcesContent":["/**\n * The browser protocol (INTERFACES §4, D106): what the client runtime in an artifact's frame sends\n * to the gateway and receives from it. Published versions embed the client runtime, so a gateway\n * serves every revision it ever shipped (FAILURE_MODEL §7); within a revision payloads only grow.\n * Paths are `/_mostra/v/{revision}/…` on the artifact's origin.\n *\n * ```ts\n * const body: FieldsRequest = { mutationId, scope: \"viewer\", baseRevision: \"3\", viewId, ops };\n * await fetch(`/_mostra/v/${BROWSER_PROTOCOL_REVISION}/fields`, { method: \"POST\", body: … });\n * ```\n */\nimport * as z from \"zod\";\nimport type { EphemeralMessage } from \"./actions.ts\";\nimport { ArtifactId, Cursor, MutationId, ViewId } from \"./ids.ts\";\nimport {\n DocumentRevision,\n EventRecord,\n FieldOp,\n FieldState,\n SubmissionSummary,\n Viewer,\n} from \"./interaction.ts\";\nimport { SubmissionPolicy } from \"./manifest.ts\";\nimport {\n REVIEW_SET_ID_PATTERN,\n SubmitChannel,\n TrustedControl,\n VersionRef,\n type ViewContext,\n} from \"./view.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\nexport {\n type DeliveryTarget,\n REVIEW_SET_ID_PATTERN,\n readViewContext,\n VersionRef,\n ViewContext,\n ViewContextWire,\n} from \"./view.ts\";\n\n/** Every browser-protocol revision this release serves, oldest first. */\nexport const BROWSER_PROTOCOL_REVISIONS: readonly [\"2026-10-15\"] = [\"2026-10-15\"];\n\n/** The newest browser-protocol revision: what a client runtime built now speaks. */\nexport const BROWSER_PROTOCOL_REVISION = \"2026-10-15\";\n\n/** The longest JSON a signal's payload may be, in UTF-8 bytes (D106). */\nexport const SIGNAL_PAYLOAD_MAX_BYTES: number = 64 * 1024;\n\n/** `POST …/fields`: one mutation of the viewer's draft or the artifact's state. */\nexport interface FieldsRequest {\n /** A fresh `mut_` ID per change; a retry repeats it and gets the recorded result. */\n readonly mutationId: string;\n /** Which document: the viewer's draft or the artifact's shared state. */\n readonly scope: \"viewer\" | \"artifact\";\n /** The document revision the page last saw; fields changed after it come back as conflicts. */\n readonly baseRevision: DocumentRevision;\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** The field changes, applied together under one revision. */\n readonly ops: readonly FieldOp[];\n}\n\n/** The Zod schema of the `FieldsRequest` type. */\nexport const FieldsRequest: z.ZodType<FieldsRequest> = z\n .object({\n mutationId: MutationId.schema,\n scope: z.enum([\"viewer\", \"artifact\"]),\n baseRevision: DocumentRevision,\n viewId: ViewId.schema,\n ops: z.array(FieldOp).min(1).max(1000).readonly(),\n })\n .register(wireRegistry, {\n id: \"FieldsRequest\",\n description: \"A browser mutation: its ID, scope, base revision, view and field ops.\",\n });\n\n/** `POST …/submit`: submit the viewer's draft from the artifact's own code (D40). */\nexport interface SubmitRequest {\n /** The view the page was opened as (D104); its version is what the submission names. */\n readonly viewId: string;\n /** The draft revision the viewer saw; another one is `MOSTRA_SUBMIT_REVISION_MOVED`. */\n readonly expectedRevision: DocumentRevision;\n /** Always `artifact` on this route; the shell's trusted Submit is the `shell` channel (D40). */\n readonly channel: \"artifact\";\n}\n\n/** The Zod schema of the `SubmitRequest` type. */\nexport const SubmitRequest: z.ZodType<SubmitRequest> = z\n .object({\n viewId: ViewId.schema,\n expectedRevision: DocumentRevision,\n channel: z.literal(\"artifact\"),\n })\n .register(wireRegistry, {\n id: \"SubmitRequest\",\n description: \"A browser submit: the view and the draft revision the viewer saw.\",\n });\n\n/** `POST …/signal`: raise a named signal for the host's attention (IN-09). */\nexport interface SignalRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** Letters, digits, `.`, `_` and `-`; `submit` is reserved. */\n readonly name: string;\n /** Any JSON, at most 64 KiB. */\n readonly payload?: unknown;\n}\n\n/** The Zod schema of the `SignalRequest` type. */\nexport const SignalRequest: z.ZodType<SignalRequest> = z\n .object({\n viewId: ViewId.schema,\n name: z.string().min(1).max(64),\n payload: z.unknown().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"SignalRequest\",\n description: \"A browser signal: the view, the signal's name and an optional JSON payload.\",\n }) as z.ZodType<SignalRequest>;\n\n/** A document as the page loads it: its revision and fields. */\nexport interface DocumentSnapshot {\n /** The document's revision. */\n readonly revision: DocumentRevision;\n /** The draft's epoch (D103); 1 for artifact state. */\n readonly epoch: number;\n /** Every field by ID. */\n readonly fields: Readonly<Record<string, FieldState>>;\n}\n\n/** The Zod schema of the `DocumentSnapshot` type. */\nexport const DocumentSnapshot: z.ZodType<DocumentSnapshot> = z\n .object({\n revision: DocumentRevision,\n epoch: z.int().min(1),\n fields: z.record(z.string(), FieldState),\n })\n .register(wireRegistry, {\n id: \"DocumentSnapshot\",\n description: \"A document's revision, epoch and fields, as a page loads it.\",\n });\n\n/**\n * The first message of a browser event stream, and a poll's `snapshot`: where the page stands,\n * so it renders the canonical draft and state before applying events after `cursor`.\n */\nexport interface StreamSnapshot {\n /** Events after this cursor follow. */\n readonly cursor: string;\n /** Who the page acts as. */\n readonly viewer: Viewer;\n /** The viewer's draft. */\n readonly draft: DocumentSnapshot;\n /** The artifact's shared state. */\n readonly state: DocumentSnapshot;\n /** The submission that closed this draft, or this viewer's latest under `epochs`. */\n readonly submission?: SubmissionSummary;\n /**\n * The artifact's latest version when the snapshot was read (WP-07): a reader that missed its\n * `version.published` event (published between a frame ticket and the stream, or compacted)\n * still learns of it.\n */\n readonly latest?: VersionRef;\n}\n\n/** The Zod schema of the `StreamSnapshot` type. */\nexport const StreamSnapshot: z.ZodType<StreamSnapshot> = z\n .object({\n cursor: Cursor.schema,\n viewer: Viewer,\n draft: DocumentSnapshot,\n state: DocumentSnapshot,\n submission: SubmissionSummary.exactOptional(),\n latest: VersionRef.exactOptional(),\n })\n .register(wireRegistry, {\n id: \"StreamSnapshot\",\n description: \"Where a page stands: cursor, viewer, draft, artifact state and its submission.\",\n });\n\n/** `GET …/events/poll`: the long-poll answer on the same cursor as the stream (D47). */\nexport interface PollResult {\n /** Where the next poll continues. */\n readonly cursor: string;\n /** The events for this page after the cursor asked for, in order. */\n readonly events: readonly EventRecord[];\n /** Present when the poll asked for none or its cursor was compacted away. */\n readonly snapshot?: StreamSnapshot;\n /**\n * Run and live updates for this view since its last poll (WP-08): lossy and never stored as\n * events, the long-poll's counterpart of the stream's `run` and `live` messages.\n */\n readonly ephemeral?: readonly EphemeralMessage[];\n}\n\n/** The Zod schema of the `PollResult` type. */\nexport const PollResult: z.ZodType<PollResult> = z\n .object({\n cursor: Cursor.schema,\n events: z.array(EventRecord).readonly(),\n snapshot: StreamSnapshot.exactOptional(),\n ephemeral: z.array(z.record(z.string(), z.unknown())).readonly().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"PollResult\",\n description: \"A long-poll answer: the cursor, the events after the asked one, and a snapshot.\",\n }) as unknown as z.ZodType<PollResult>;\n\n/**\n * `POST /a/{artifactId}/_mostra/ticket`'s answer on the shell origin: a single-use frame ticket,\n * the view it opens and what the shell needs to render the view's trusted controls (D104, D108).\n */\nexport interface FrameTicket extends ViewContext {\n /** The frame's entry URL, carrying the single-use ticket. */\n readonly src: string;\n /** The artifact's origin: the only origin the bridge accepts messages from. */\n readonly artifactOrigin: string;\n /** Whether this viewer follows the artifact's new versions (D63). */\n readonly follow: boolean;\n /** Whether the link opens this version only (D97 item 9): then the shell offers no newer one. */\n readonly pinned: boolean;\n /**\n * The version's server code keeps crashing and is parked (WP-08, FAILURE_MODEL §2): the shell\n * says so, since the page's actions and live data won't work until a new publish.\n */\n readonly serverParked?: true;\n /**\n * The frame shows `mostra dev`'s development preview of unpublished source (D140 item 12): the\n * shell says so, and it is never a published version.\n */\n readonly devPreview?: true;\n}\n\n/** The Zod schema of the `FrameTicket` type. */\nexport const FrameTicket: z.ZodType<FrameTicket> = z\n .object({\n artifactId: ArtifactId.schema,\n viewId: ViewId.schema,\n version: VersionRef,\n latest: VersionRef,\n policy: SubmissionPolicy,\n submitChannels: z.array(SubmitChannel).min(1).max(2).readonly(),\n controls: z.array(TrustedControl).max(32).readonly(),\n target: z.enum([\"live\", \"static\", \"mcp-app\", \"verify\"]),\n src: z.string().min(1),\n artifactOrigin: z.string().min(1),\n follow: z.boolean(),\n pinned: z.boolean(),\n serverParked: z.literal(true).exactOptional(),\n devPreview: z.literal(true).exactOptional(),\n })\n .register(wireRegistry, {\n id: \"FrameTicket\",\n description: \"A frame ticket: the view it opens, where to load it, and the view's controls.\",\n });\n\n// ── The shell's own routes (WP-07, on the shell origin) ──────────────────────────────────\n\n/**\n * `POST /a/{artifactId}/_mostra/v/{rev}/submit`: the shell's trusted Submit (the `shell` channel,\n * D40). Only the shell's page can send it: the route takes the shell's session, its exact origin\n * and its CSRF token, none of which an artifact's page has.\n */\nexport interface ShellSubmitRequest {\n /** The view the shell's frame shows (D104); its version is what the submission names. */\n readonly viewId: string;\n /** The draft revision the viewer saw, after the frame flushed its saves. */\n readonly expectedRevision: DocumentRevision;\n}\n\n/** The Zod schema of the `ShellSubmitRequest` type. */\nexport const ShellSubmitRequest: z.ZodType<ShellSubmitRequest> = z\n .object({ viewId: ViewId.schema, expectedRevision: DocumentRevision })\n .register(wireRegistry, {\n id: \"ShellSubmitRequest\",\n description: \"The shell's trusted Submit: the view and the draft revision the viewer saw.\",\n });\n\n/**\n * `POST /a/{artifactId}/_mostra/v/{rev}/review/choose`: the shell's trusted Choose (D65, D113).\n * It writes the viewer's draft field `review.<reviewSetId>.choice` like any mutation, so a stale\n * base revision comes back as a conflict.\n */\nexport interface ChooseRequest {\n /** The view the shell's frame shows. */\n readonly viewId: string;\n /** A fresh `mut_` ID; a retry repeats it. */\n readonly mutationId: string;\n /** The draft revision the shell last saw. */\n readonly baseRevision: DocumentRevision;\n /** The review set. */\n readonly reviewSetId: string;\n /** The chosen candidate's ID. */\n readonly candidateId: string;\n /** The candidate's label, kept with the choice for results. */\n readonly label?: string;\n}\n\n/** The Zod schema of the `ChooseRequest` type. */\nexport const ChooseRequest: z.ZodType<ChooseRequest> = z\n .object({\n viewId: ViewId.schema,\n mutationId: MutationId.schema,\n baseRevision: DocumentRevision,\n reviewSetId: z.string().regex(REVIEW_SET_ID_PATTERN),\n candidateId: z.string().min(1).max(256),\n label: z.string().max(256).exactOptional(),\n })\n .register(wireRegistry, {\n id: \"ChooseRequest\",\n description:\n \"The shell's trusted Choose: the view, mutation, base revision, set and candidate.\",\n });\n\n/** `POST /a/{artifactId}/_mostra/v/{rev}/follow`: the viewer's \"Always follow this artifact\" (D63). */\nexport interface FollowRequest {\n /** `true` to load new versions automatically, `false` to stop. */\n readonly follow: boolean;\n}\n\n/** The Zod schema of the `FollowRequest` type. */\nexport const FollowRequest: z.ZodType<FollowRequest> = z\n .object({ follow: z.boolean() })\n .register(wireRegistry, {\n id: \"FollowRequest\",\n description: \"Whether the viewer follows the artifact's new versions.\",\n });\n\n/** A draft field a version doesn't cover (D42, D109): kept, shown read-only and delivered. */\nexport interface OrphanedField {\n /** The field's ID. */\n readonly id: string;\n /** Its label, when it has one. */\n readonly label?: string;\n /** Its value. */\n readonly value: unknown;\n /** The version whose view last wrote it. */\n readonly fromVersion: number;\n}\n\n/** The Zod schema of the `OrphanedField` type. */\nexport const OrphanedField: z.ZodType<OrphanedField> = z\n .object({\n id: z.string(),\n label: z.string().exactOptional(),\n value: z.unknown(),\n fromVersion: z.int().min(1),\n })\n .register(wireRegistry, {\n id: \"OrphanedField\",\n description: \"A draft field a version doesn't cover: its ID, label, value and source version.\",\n }) as z.ZodType<OrphanedField>;\n\n/**\n * `GET /a/{artifactId}/_mostra/v/{rev}/carry?version=<number>`: which of the viewer's answers a\n * version doesn't carry over (D42, D109). The banner counts them before a switch; the \"Not\n * carried over\" panel lists them for the version shown.\n */\nexport interface CarryOver {\n /** The version asked about. */\n readonly version: VersionRef;\n /** The viewer's draft fields the version doesn't cover. */\n readonly orphans: readonly OrphanedField[];\n}\n\n/** The Zod schema of the `CarryOver` type. */\nexport const CarryOver: z.ZodType<CarryOver> = z\n .object({ version: VersionRef, orphans: z.array(OrphanedField).readonly() })\n .register(wireRegistry, {\n id: \"CarryOver\",\n description: \"The viewer's answers a version doesn't carry over.\",\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0CA,MAAa,6BAAsD,CAAC,YAAY;;AAGhF,MAAa,4BAA4B;;AAGzC,MAAa,2BAAmC;;AAiBhD,MAAa,gBAA0C,EACpD,OAAO;CACN,YAAY,WAAW;CACvB,OAAO,EAAE,KAAK,CAAC,UAAU,UAAU,CAAC;CACpC,cAAc;CACd,QAAQ,OAAO;CACf,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAI,CAAC,CAAC,SAAS;AAClD,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAaH,MAAa,gBAA0C,EACpD,OAAO;CACN,QAAQ,OAAO;CACf,kBAAkB;CAClB,SAAS,EAAE,QAAQ,UAAU;AAC/B,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAaH,MAAa,gBAA0C,EACpD,OAAO;CACN,QAAQ,OAAO;CACf,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;CAC9B,SAAS,EAAE,QAAQ,CAAC,C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B,IAAI;CACJ,aAAa;AACf,CAAC"}
|
|
1
|
+
{"version":3,"file":"browser.js","names":[],"sources":["../src/browser.ts"],"sourcesContent":["/**\n * The browser protocol (INTERFACES §4, D106): what the client runtime in an artifact's frame sends\n * to the gateway and receives from it. Published versions embed the client runtime, so a gateway\n * serves every revision it ever shipped (FAILURE_MODEL §7); within a revision payloads only grow.\n * Paths are `/_mostra/v/{revision}/…` on the artifact's origin.\n *\n * ```ts\n * const body: FieldsRequest = { mutationId, scope: \"viewer\", baseRevision: \"3\", viewId, ops };\n * await fetch(`/_mostra/v/${BROWSER_PROTOCOL_REVISION}/fields`, { method: \"POST\", body: … });\n * ```\n */\nimport * as z from \"zod\";\nimport type { EphemeralMessage } from \"./actions.ts\";\nimport { ArtifactId, Cursor, MutationId, ViewId } from \"./ids.ts\";\nimport {\n DocumentRevision,\n EventRecord,\n FieldOp,\n FieldState,\n SubmissionSummary,\n Viewer,\n} from \"./interaction.ts\";\nimport { SubmissionPolicy } from \"./manifest.ts\";\nimport {\n REVIEW_SET_ID_PATTERN,\n SubmitChannel,\n TrustedControl,\n VersionRef,\n type ViewContext,\n} from \"./view.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\nexport {\n type DeliveryTarget,\n REVIEW_SET_ID_PATTERN,\n readViewContext,\n VersionRef,\n ViewContext,\n ViewContextWire,\n} from \"./view.ts\";\n\n/** Every browser-protocol revision this release serves, oldest first. */\nexport const BROWSER_PROTOCOL_REVISIONS: readonly [\"2026-10-15\"] = [\"2026-10-15\"];\n\n/** The newest browser-protocol revision: what a client runtime built now speaks. */\nexport const BROWSER_PROTOCOL_REVISION = \"2026-10-15\";\n\n/** The longest JSON a signal's payload may be, in UTF-8 bytes (D106). */\nexport const SIGNAL_PAYLOAD_MAX_BYTES: number = 64 * 1024;\n\n/** `POST …/fields`: one mutation of the viewer's draft or the artifact's state. */\nexport interface FieldsRequest {\n /** A fresh `mut_` ID per change; a retry repeats it and gets the recorded result. */\n readonly mutationId: string;\n /** Which document: the viewer's draft or the artifact's shared state. */\n readonly scope: \"viewer\" | \"artifact\";\n /** The document revision the page last saw; fields changed after it come back as conflicts. */\n readonly baseRevision: DocumentRevision;\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** The field changes, applied together under one revision. */\n readonly ops: readonly FieldOp[];\n}\n\n/** The Zod schema of the `FieldsRequest` type. */\nexport const FieldsRequest: z.ZodType<FieldsRequest> = z\n .object({\n mutationId: MutationId.schema,\n scope: z.enum([\"viewer\", \"artifact\"]),\n baseRevision: DocumentRevision,\n viewId: ViewId.schema,\n ops: z.array(FieldOp).min(1).max(1000).readonly(),\n })\n .register(wireRegistry, {\n id: \"FieldsRequest\",\n description: \"A browser mutation: its ID, scope, base revision, view and field ops.\",\n });\n\n/** `POST …/submit`: submit the viewer's draft from the artifact's own code (D40). */\nexport interface SubmitRequest {\n /** The view the page was opened as (D104); its version is what the submission names. */\n readonly viewId: string;\n /** The draft revision the viewer saw; another one is `MOSTRA_SUBMIT_REVISION_MOVED`. */\n readonly expectedRevision: DocumentRevision;\n /** Always `artifact` on this route; the shell's trusted Submit is the `shell` channel (D40). */\n readonly channel: \"artifact\";\n}\n\n/** The Zod schema of the `SubmitRequest` type. */\nexport const SubmitRequest: z.ZodType<SubmitRequest> = z\n .object({\n viewId: ViewId.schema,\n expectedRevision: DocumentRevision,\n channel: z.literal(\"artifact\"),\n })\n .register(wireRegistry, {\n id: \"SubmitRequest\",\n description: \"A browser submit: the view and the draft revision the viewer saw.\",\n });\n\n/** `POST …/signal`: raise a named signal for the host's attention (IN-09). */\nexport interface SignalRequest {\n /** The view the page was opened as (D104). */\n readonly viewId: string;\n /** Letters, digits, `.`, `_` and `-`; `submit` is reserved. */\n readonly name: string;\n /** Any JSON, at most 64 KiB. */\n readonly payload?: unknown;\n}\n\n/** The Zod schema of the `SignalRequest` type. */\nexport const SignalRequest: z.ZodType<SignalRequest> = z\n .object({\n viewId: ViewId.schema,\n name: z.string().min(1).max(64),\n payload: z.unknown().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"SignalRequest\",\n description: \"A browser signal: the view, the signal's name and an optional JSON payload.\",\n }) as z.ZodType<SignalRequest>;\n\n/** A document as the page loads it: its revision and fields. */\nexport interface DocumentSnapshot {\n /** The document's revision. */\n readonly revision: DocumentRevision;\n /** The draft's epoch (D103); 1 for artifact state. */\n readonly epoch: number;\n /** Every field by ID. */\n readonly fields: Readonly<Record<string, FieldState>>;\n}\n\n/** The Zod schema of the `DocumentSnapshot` type. */\nexport const DocumentSnapshot: z.ZodType<DocumentSnapshot> = z\n .object({\n revision: DocumentRevision,\n epoch: z.int().min(1),\n fields: z.record(z.string(), FieldState),\n })\n .register(wireRegistry, {\n id: \"DocumentSnapshot\",\n description: \"A document's revision, epoch and fields, as a page loads it.\",\n });\n\n/**\n * The first message of a browser event stream, and a poll's `snapshot`: where the page stands,\n * so it renders the canonical draft and state before applying events after `cursor`.\n */\nexport interface StreamSnapshot {\n /** Events after this cursor follow. */\n readonly cursor: string;\n /** Who the page acts as. */\n readonly viewer: Viewer;\n /** The viewer's draft. */\n readonly draft: DocumentSnapshot;\n /** The artifact's shared state. */\n readonly state: DocumentSnapshot;\n /** The submission that closed this draft, or this viewer's latest under `epochs`. */\n readonly submission?: SubmissionSummary;\n /**\n * The artifact's latest version when the snapshot was read (WP-07): a reader that missed its\n * `version.published` event (published between a frame ticket and the stream, or compacted)\n * still learns of it.\n */\n readonly latest?: VersionRef;\n}\n\n/** The Zod schema of the `StreamSnapshot` type. */\nexport const StreamSnapshot: z.ZodType<StreamSnapshot> = z\n .object({\n cursor: Cursor.schema,\n viewer: Viewer,\n draft: DocumentSnapshot,\n state: DocumentSnapshot,\n submission: SubmissionSummary.exactOptional(),\n latest: VersionRef.exactOptional(),\n })\n .register(wireRegistry, {\n id: \"StreamSnapshot\",\n description: \"Where a page stands: cursor, viewer, draft, artifact state and its submission.\",\n });\n\n/** `GET …/events/poll`: the long-poll answer on the same cursor as the stream (D47). */\nexport interface PollResult {\n /** Where the next poll continues. */\n readonly cursor: string;\n /** The events for this page after the cursor asked for, in order. */\n readonly events: readonly EventRecord[];\n /** Present when the poll asked for none or its cursor was compacted away. */\n readonly snapshot?: StreamSnapshot;\n /**\n * Run and live updates for this view since its last poll (WP-08): lossy and never stored as\n * events, the long-poll's counterpart of the stream's `run` and `live` messages.\n */\n readonly ephemeral?: readonly EphemeralMessage[];\n}\n\n/** The Zod schema of the `PollResult` type. */\nexport const PollResult: z.ZodType<PollResult> = z\n .object({\n cursor: Cursor.schema,\n events: z.array(EventRecord).readonly(),\n snapshot: StreamSnapshot.exactOptional(),\n ephemeral: z.array(z.record(z.string(), z.unknown())).readonly().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"PollResult\",\n description: \"A long-poll answer: the cursor, the events after the asked one, and a snapshot.\",\n }) as unknown as z.ZodType<PollResult>;\n\n/**\n * `POST /a/{artifactId}/_mostra/ticket`'s answer on the shell origin: a single-use frame ticket,\n * the view it opens and what the shell needs to render the view's trusted controls (D104, D108).\n */\nexport interface FrameTicket extends ViewContext {\n /** The frame's entry URL, carrying the single-use ticket. */\n readonly src: string;\n /** The artifact's origin: the only origin the bridge accepts messages from. */\n readonly artifactOrigin: string;\n /** Whether this viewer follows the artifact's new versions (D63). */\n readonly follow: boolean;\n /** Whether the link opens this version only (D97 item 9): then the shell offers no newer one. */\n readonly pinned: boolean;\n /**\n * The version's server code keeps crashing and is parked (WP-08, FAILURE_MODEL §2): the shell\n * says so, since the page's actions and live data won't work until a new publish.\n */\n readonly serverParked?: true;\n /**\n * The frame shows `mostra dev`'s development preview of unpublished source (D140 item 12): the\n * shell says so, and it is never a published version.\n */\n readonly devPreview?: true;\n /**\n * `worker` when the shell and the artifact are two sites (a Cloudflare quick tunnel, a host's\n * addresses on two hosts): the frame enters through the bootstrap page and a service worker\n * (D70, D158 item 5). Absent: cookie mode.\n */\n readonly mode?: \"worker\";\n}\n\n/** The Zod schema of the `FrameTicket` type. */\nexport const FrameTicket: z.ZodType<FrameTicket> = z\n .object({\n artifactId: ArtifactId.schema,\n viewId: ViewId.schema,\n version: VersionRef,\n latest: VersionRef,\n policy: SubmissionPolicy,\n submitChannels: z.array(SubmitChannel).min(1).max(2).readonly(),\n controls: z.array(TrustedControl).max(32).readonly(),\n target: z.enum([\"live\", \"static\", \"mcp-app\", \"verify\"]),\n src: z.string().min(1),\n artifactOrigin: z.string().min(1),\n follow: z.boolean(),\n pinned: z.boolean(),\n serverParked: z.literal(true).exactOptional(),\n devPreview: z.literal(true).exactOptional(),\n mode: z.literal(\"worker\").exactOptional(),\n })\n .register(wireRegistry, {\n id: \"FrameTicket\",\n description: \"A frame ticket: the view it opens, where to load it, and the view's controls.\",\n });\n\n// ── Frame sessions in worker mode (WP-13, D70, D158 item 5) ───────────────────────────────\n\n/**\n * The header Mostra's service worker adds to every same-origin request of a worker-mode frame:\n * its frame session's secret, which no cookie can carry across sites.\n */\nexport const FRAME_SESSION_HEADER = \"x-mostra-frame\";\n\n/**\n * `POST /_mostra/enter` on the artifact's origin: the bootstrap page exchanges the shell's\n * single-use frame ticket, from `/_mostra/enter#t=…`, for a worker-mode frame session.\n */\nexport interface EnterRequest {\n /** The frame ticket. */\n readonly ticket: string;\n}\n\n/** The Zod schema of the `EnterRequest` type. */\nexport const EnterRequest: z.ZodType<EnterRequest> = z\n .object({ ticket: z.string().min(1).max(64) })\n .register(wireRegistry, { id: \"EnterRequest\", description: \"A frame ticket to exchange.\" });\n\n/** The answer to `EnterRequest`. */\nexport interface EnterResult {\n /** The frame session's secret, which the service worker sends as `X-Mostra-Frame`. */\n readonly session: string;\n /** The shell's origin: the only page the bootstrap reports to. */\n readonly shellOrigin: string;\n}\n\n/** The Zod schema of the `EnterResult` type. */\nexport const EnterResult: z.ZodType<EnterResult> = z\n .object({ session: z.string().min(1), shellOrigin: z.string().min(1) })\n .register(wireRegistry, {\n id: \"EnterResult\",\n description: \"A worker-mode frame session's secret and the shell's origin.\",\n });\n\n/**\n * `POST /_mostra/v/{rev}/ticket`: a single-use ticket that opens one event stream, long poll or\n * WebSocket of this session without it (`?ticket=`), so the request can bypass the service\n * worker (VERIFIED_FACTS: Firefox stalls on endless responses a worker passes on).\n */\nexport interface StreamTicketRequest {\n /** What it opens: `stream` (events and polls, the default) or `socket` (a WebSocket). */\n readonly purpose?: \"stream\" | \"socket\";\n}\n\n/** The Zod schema of the `StreamTicketRequest` type. */\nexport const StreamTicketRequest: z.ZodType<StreamTicketRequest> = z\n .object({ purpose: z.enum([\"stream\", \"socket\"]).exactOptional() })\n .register(wireRegistry, { id: \"StreamTicketRequest\" });\n\n/** The answer to a `StreamTicketRequest`. */\nexport interface StreamTicket {\n /** The ticket: 130 bits, single-use. */\n readonly ticket: string;\n /** When it stops working, 60 s after it was minted. */\n readonly expiresAt: string;\n}\n\n/** The Zod schema of the `StreamTicket` type. */\nexport const StreamTicket: z.ZodType<StreamTicket> = z\n .object({ ticket: z.string().min(1), expiresAt: z.iso.datetime() })\n .register(wireRegistry, {\n id: \"StreamTicket\",\n description: \"A single-use ticket for one stream, poll or WebSocket.\",\n });\n\n/**\n * `GET /_mostra/session` on the artifact's origin: the frame session's facts for same-origin code.\n */\nexport interface FrameSessionFacts {\n /** The CSRF token every mutation sends as `X-Mostra-CSRF`. */\n readonly csrf: string;\n /** The artifact the frame shows. */\n readonly artifactId: string;\n /** The shell's exact origin: the bridge's only peer. */\n readonly shellOrigin: string;\n /** The link's scopes. */\n readonly scopes: readonly string[];\n /** The viewer the page acts as (WP-07). */\n readonly viewer?: Viewer;\n /** The version the frame session entered. */\n readonly version?: VersionRef;\n /** How the frame authenticates (D70): absent means `cookie`. */\n readonly mode?: \"cookie\" | \"worker\";\n /**\n * `false` where event streams don't pass (a Cloudflare quick tunnel holds responses back until\n * they end): the page long-polls from the start (D47). Absent means streams pass.\n */\n readonly streams?: boolean;\n}\n\n/** The Zod schema of the `FrameSessionFacts` type. */\nexport const FrameSessionFacts: z.ZodType<FrameSessionFacts> = z\n .object({\n csrf: z.string().min(1),\n artifactId: ArtifactId.schema,\n shellOrigin: z.string().min(1),\n scopes: z.array(z.string()).readonly(),\n viewer: Viewer.exactOptional(),\n version: VersionRef.exactOptional(),\n mode: z.enum([\"cookie\", \"worker\"]).exactOptional(),\n streams: z.boolean().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"FrameSessionFacts\",\n description: \"A frame session's CSRF token, shell origin, scopes, viewer, version and mode.\",\n });\n\n// ── The shell's own routes (WP-07, on the shell origin) ──────────────────────────────────\n\n/**\n * `POST /a/{artifactId}/_mostra/v/{rev}/submit`: the shell's trusted Submit (the `shell` channel,\n * D40). Only the shell's page can send it: the route takes the shell's session, its exact origin\n * and its CSRF token, none of which an artifact's page has.\n */\nexport interface ShellSubmitRequest {\n /** The view the shell's frame shows (D104); its version is what the submission names. */\n readonly viewId: string;\n /** The draft revision the viewer saw, after the frame flushed its saves. */\n readonly expectedRevision: DocumentRevision;\n}\n\n/** The Zod schema of the `ShellSubmitRequest` type. */\nexport const ShellSubmitRequest: z.ZodType<ShellSubmitRequest> = z\n .object({ viewId: ViewId.schema, expectedRevision: DocumentRevision })\n .register(wireRegistry, {\n id: \"ShellSubmitRequest\",\n description: \"The shell's trusted Submit: the view and the draft revision the viewer saw.\",\n });\n\n/**\n * `POST /a/{artifactId}/_mostra/v/{rev}/review/choose`: the shell's trusted Choose (D65, D113).\n * It writes the viewer's draft field `review.<reviewSetId>.choice` like any mutation, so a stale\n * base revision comes back as a conflict.\n */\nexport interface ChooseRequest {\n /** The view the shell's frame shows. */\n readonly viewId: string;\n /** A fresh `mut_` ID; a retry repeats it. */\n readonly mutationId: string;\n /** The draft revision the shell last saw. */\n readonly baseRevision: DocumentRevision;\n /** The review set. */\n readonly reviewSetId: string;\n /** The chosen candidate's ID. */\n readonly candidateId: string;\n /** The candidate's label, kept with the choice for results. */\n readonly label?: string;\n}\n\n/** The Zod schema of the `ChooseRequest` type. */\nexport const ChooseRequest: z.ZodType<ChooseRequest> = z\n .object({\n viewId: ViewId.schema,\n mutationId: MutationId.schema,\n baseRevision: DocumentRevision,\n reviewSetId: z.string().regex(REVIEW_SET_ID_PATTERN),\n candidateId: z.string().min(1).max(256),\n label: z.string().max(256).exactOptional(),\n })\n .register(wireRegistry, {\n id: \"ChooseRequest\",\n description:\n \"The shell's trusted Choose: the view, mutation, base revision, set and candidate.\",\n });\n\n/** `POST /a/{artifactId}/_mostra/v/{rev}/follow`: the viewer's \"Always follow this artifact\" (D63). */\nexport interface FollowRequest {\n /** `true` to load new versions automatically, `false` to stop. */\n readonly follow: boolean;\n}\n\n/** The Zod schema of the `FollowRequest` type. */\nexport const FollowRequest: z.ZodType<FollowRequest> = z\n .object({ follow: z.boolean() })\n .register(wireRegistry, {\n id: \"FollowRequest\",\n description: \"Whether the viewer follows the artifact's new versions.\",\n });\n\n/** A draft field a version doesn't cover (D42, D109): kept, shown read-only and delivered. */\nexport interface OrphanedField {\n /** The field's ID. */\n readonly id: string;\n /** Its label, when it has one. */\n readonly label?: string;\n /** Its value. */\n readonly value: unknown;\n /** The version whose view last wrote it. */\n readonly fromVersion: number;\n}\n\n/** The Zod schema of the `OrphanedField` type. */\nexport const OrphanedField: z.ZodType<OrphanedField> = z\n .object({\n id: z.string(),\n label: z.string().exactOptional(),\n value: z.unknown(),\n fromVersion: z.int().min(1),\n })\n .register(wireRegistry, {\n id: \"OrphanedField\",\n description: \"A draft field a version doesn't cover: its ID, label, value and source version.\",\n }) as z.ZodType<OrphanedField>;\n\n/**\n * `GET /a/{artifactId}/_mostra/v/{rev}/carry?version=<number>`: which of the viewer's answers a\n * version doesn't carry over (D42, D109). The banner counts them before a switch; the \"Not\n * carried over\" panel lists them for the version shown.\n */\nexport interface CarryOver {\n /** The version asked about. */\n readonly version: VersionRef;\n /** The viewer's draft fields the version doesn't cover. */\n readonly orphans: readonly OrphanedField[];\n}\n\n/** The Zod schema of the `CarryOver` type. */\nexport const CarryOver: z.ZodType<CarryOver> = z\n .object({ version: VersionRef, orphans: z.array(OrphanedField).readonly() })\n .register(wireRegistry, {\n id: \"CarryOver\",\n description: \"The viewer's answers a version doesn't carry over.\",\n });\n"],"mappings":";;;;;;;;;;;;;;;;;;;AA0CA,MAAa,6BAAsD,CAAC,YAAY;;AAGhF,MAAa,4BAA4B;;AAGzC,MAAa,2BAAmC;;AAiBhD,MAAa,gBAA0C,EACpD,OAAO;CACN,YAAY,WAAW;CACvB,OAAO,EAAE,KAAK,CAAC,UAAU,UAAU,CAAC;CACpC,cAAc;CACd,QAAQ,OAAO;CACf,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAI,CAAC,CAAC,SAAS;AAClD,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAaH,MAAa,gBAA0C,EACpD,OAAO;CACN,QAAQ,OAAO;CACf,kBAAkB;CAClB,SAAS,EAAE,QAAQ,UAAU;AAC/B,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAaH,MAAa,gBAA0C,EACpD,OAAO;CACN,QAAQ,OAAO;CACf,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE;CAC9B,SAAS,EAAE,QAAQ,CAAC,CAAC,cAAc;AACrC,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAaH,MAAa,mBAAgD,EAC1D,OAAO;CACN,UAAU;CACV,OAAO,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;CACpB,QAAQ,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU;AACzC,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AA0BH,MAAa,iBAA4C,EACtD,OAAO;CACN,QAAQ,OAAO;CACf,QAAQ;CACR,OAAO;CACP,OAAO;CACP,YAAY,kBAAkB,cAAc;CAC5C,QAAQ,WAAW,cAA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pD,OAAO;CACN,QAAQ,OAAO;CACf,YAAY,WAAW;CACvB,cAAc;CACd,aAAa,EAAE,OAAO,CAAC,CAAC,MAAM,qBAAqB;CACnD,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CACtC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,cAAc;AAC3C,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aACE;AACJ,CAAC;;AASH,MAAa,gBAA0C,EACpD,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,CAAC,CAAC,CAC/B,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAeH,MAAa,gBAA0C,EACpD,OAAO;CACN,IAAI,EAAE,OAAO;CACb,OAAO,EAAE,OAAO,CAAC,CAAC,cAAc;CAChC,OAAO,EAAE,QAAQ;CACjB,aAAa,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;AAC5B,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAeH,MAAa,YAAkC,EAC5C,OAAO;CAAE,SAAS;CAAY,SAAS,EAAE,MAAM,aAAa,CAAC,CAAC,SAAS;AAAE,CAAC,CAAC,CAC3E,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "../spec.js";
|
|
2
2
|
//#region src/diagnostics/codes/hygiene.d.ts
|
|
3
3
|
/** The codes of the HYGIENE area, in the order they were added. */
|
|
4
|
-
export declare const hygieneDiagnosticCodes: readonly ["MOSTRA_HYGIENE_HOST_REFUSED", "MOSTRA_HYGIENE_ORIGIN_REFUSED", "MOSTRA_HYGIENE_CSRF_MISSING", "MOSTRA_HYGIENE_CONTENT_TYPE", "MOSTRA_HYGIENE_REQUEST_MALFORMED", "MOSTRA_HYGIENE_SESSION_MISSING", "MOSTRA_HYGIENE_TOKEN_INVALID", "MOSTRA_HYGIENE_TOKEN_REVOKED", "MOSTRA_HYGIENE_SCOPE_DENIED", "MOSTRA_HYGIENE_RATE_LIMITED", "MOSTRA_HYGIENE_NOT_SERVED", "MOSTRA_HYGIENE_SESSION_CONFLICT", "MOSTRA_HYGIENE_HEADERS_TOO_LARGE"];
|
|
4
|
+
export declare const hygieneDiagnosticCodes: readonly ["MOSTRA_HYGIENE_HOST_REFUSED", "MOSTRA_HYGIENE_ORIGIN_REFUSED", "MOSTRA_HYGIENE_CSRF_MISSING", "MOSTRA_HYGIENE_CONTENT_TYPE", "MOSTRA_HYGIENE_REQUEST_MALFORMED", "MOSTRA_HYGIENE_SESSION_MISSING", "MOSTRA_HYGIENE_TOKEN_INVALID", "MOSTRA_HYGIENE_TOKEN_REVOKED", "MOSTRA_HYGIENE_SCOPE_DENIED", "MOSTRA_HYGIENE_RATE_LIMITED", "MOSTRA_HYGIENE_NOT_SERVED", "MOSTRA_HYGIENE_SESSION_CONFLICT", "MOSTRA_HYGIENE_HEADERS_TOO_LARGE", "MOSTRA_HYGIENE_FRAME_SESSION"];
|
|
5
5
|
/** The codes of the HYGIENE area. */
|
|
6
6
|
export type HygieneDiagnosticCode = (typeof hygieneDiagnosticCodes)[number];
|
|
7
7
|
//#endregion
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hygiene.d.ts","names":[],"sources":["../../../src/diagnostics/codes/hygiene.ts"],"mappings":";;;qBAQa;;
|
|
1
|
+
{"version":3,"file":"hygiene.d.ts","names":[],"sources":["../../../src/diagnostics/codes/hygiene.ts"],"mappings":";;;qBAQa;;YAmBD,gCAAgC"}
|
|
@@ -13,7 +13,8 @@ const hygieneDiagnosticCodes = [
|
|
|
13
13
|
"MOSTRA_HYGIENE_RATE_LIMITED",
|
|
14
14
|
"MOSTRA_HYGIENE_NOT_SERVED",
|
|
15
15
|
"MOSTRA_HYGIENE_SESSION_CONFLICT",
|
|
16
|
-
"MOSTRA_HYGIENE_HEADERS_TOO_LARGE"
|
|
16
|
+
"MOSTRA_HYGIENE_HEADERS_TOO_LARGE",
|
|
17
|
+
"MOSTRA_HYGIENE_FRAME_SESSION"
|
|
17
18
|
];
|
|
18
19
|
/** The HYGIENE area's catalog entries. */
|
|
19
20
|
const hygieneDiagnostics = {
|
|
@@ -146,6 +147,16 @@ const hygieneDiagnostics = {
|
|
|
146
147
|
explanation: "The request's headers passed the gateway's limit of 1 MiB, more than any browser sends for one host's cookies. Every port of the loopback host shares one cookie jar, so a page on any of them can fill it. The gateway answers 431 with `Clear-Site-Data: \"cookies\"`, which empties the host's cookies, so the next request works. Mostra's sessions go with them and come back when a link is opened again.",
|
|
147
148
|
fix: "Open the artifact's link again. If it keeps happening, find the page that sets the cookies: it runs on this host."
|
|
148
149
|
}
|
|
150
|
+
},
|
|
151
|
+
MOSTRA_HYGIENE_FRAME_SESSION: {
|
|
152
|
+
severity: "error",
|
|
153
|
+
phase: "hygiene",
|
|
154
|
+
title: "Frame session couldn't start",
|
|
155
|
+
hint: "Open the artifact's tailnet or Funnel link, or this link in a normal window of another browser.",
|
|
156
|
+
docs: {
|
|
157
|
+
explanation: "Where the shell and the artifact are two sites (a Cloudflare quick tunnel, or a host's addresses on two hosts), the artifact's frame can't use a cookie: it enters through a bootstrap page that installs Mostra's service worker at `/`, which signs every request of the frame (worker mode, D70). Mostra reports this code when that can't happen: the browser offers the frame no service worker (a private window, a setting that blocks third-party storage), refuses to install it, or the gateway refused the frame's entry. The client runtime reports it too when the artifact's own code registers another service worker at `/`, which would replace Mostra's and end the frame's session.",
|
|
158
|
+
fix: "Open the artifact through a tailnet or Funnel share, where the frame uses a cookie, or in a browser window that allows service workers in frames. An artifact that needs its own service worker registers it at a narrower scope than `/`."
|
|
159
|
+
}
|
|
149
160
|
}
|
|
150
161
|
};
|
|
151
162
|
//#endregion
|