@mostra/protocol 0.9.0 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/actions.d.ts +30 -4
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +14 -4
- package/dist/actions.js.map +1 -1
- package/dist/artifact.d.ts +2 -1
- package/dist/artifact.d.ts.map +1 -1
- package/dist/artifact.js +2 -1
- package/dist/artifact.js.map +1 -1
- package/dist/browser.d.ts +47 -0
- package/dist/browser.d.ts.map +1 -1
- package/dist/browser.js +36 -3
- package/dist/browser.js.map +1 -1
- package/dist/capability.d.ts +0 -9
- package/dist/capability.d.ts.map +1 -1
- package/dist/capability.js +1 -17
- package/dist/capability.js.map +1 -1
- package/dist/diagnostics/codes/action.d.ts +1 -1
- package/dist/diagnostics/codes/action.d.ts.map +1 -1
- package/dist/diagnostics/codes/action.js +12 -1
- package/dist/diagnostics/codes/action.js.map +1 -1
- package/dist/diagnostics/codes/artifact.d.ts +1 -1
- package/dist/diagnostics/codes/artifact.d.ts.map +1 -1
- package/dist/diagnostics/codes/artifact.js +12 -1
- package/dist/diagnostics/codes/artifact.js.map +1 -1
- package/dist/diagnostics/codes/home.d.ts +1 -1
- package/dist/diagnostics/codes/home.d.ts.map +1 -1
- package/dist/diagnostics/codes/home.js +12 -1
- package/dist/diagnostics/codes/home.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/remote.d.ts +8 -0
- package/dist/diagnostics/codes/remote.d.ts.map +1 -0
- package/dist/diagnostics/codes/remote.js +176 -0
- package/dist/diagnostics/codes/remote.js.map +1 -0
- package/dist/diagnostics/codes/submit.d.ts +1 -1
- package/dist/diagnostics/codes/submit.d.ts.map +1 -1
- package/dist/diagnostics/codes/submit.js +12 -1
- package/dist/diagnostics/codes/submit.js.map +1 -1
- package/dist/diagnostics/diagnostic.d.ts +1 -1
- package/dist/diagnostics/diagnostic.d.ts.map +1 -1
- package/dist/diagnostics/diagnostic.js +2 -1
- package/dist/diagnostics/diagnostic.js.map +1 -1
- package/dist/duration.d.ts +13 -0
- package/dist/duration.d.ts.map +1 -0
- package/dist/duration.js +27 -0
- package/dist/duration.js.map +1 -0
- package/dist/ids.d.ts +17 -1
- package/dist/ids.d.ts.map +1 -1
- package/dist/ids.js +9 -1
- package/dist/ids.js.map +1 -1
- package/dist/index.d.ts +33 -8
- package/dist/index.js +33 -8
- package/dist/interaction.d.ts +33 -2
- package/dist/interaction.d.ts.map +1 -1
- package/dist/interaction.js +22 -6
- package/dist/interaction.js.map +1 -1
- package/dist/manifest.d.ts +59 -14
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +63 -15
- package/dist/manifest.js.map +1 -1
- package/dist/methods/artifact/export.d.ts +40 -0
- package/dist/methods/artifact/export.d.ts.map +1 -0
- package/dist/methods/artifact/export.js +36 -0
- package/dist/methods/artifact/export.js.map +1 -0
- package/dist/methods/artifact/import.d.ts +23 -0
- package/dist/methods/artifact/import.d.ts.map +1 -0
- package/dist/methods/artifact/import.js +25 -0
- package/dist/methods/artifact/import.js.map +1 -0
- package/dist/methods/artifact/pause.d.ts +33 -0
- package/dist/methods/artifact/pause.d.ts.map +1 -0
- package/dist/methods/artifact/pause.js +33 -0
- package/dist/methods/artifact/pause.js.map +1 -0
- package/dist/methods/artifact/publish.d.ts +2 -1
- package/dist/methods/artifact/publish.d.ts.map +1 -1
- package/dist/methods/artifact/publish.js +1 -1
- package/dist/methods/hosted/push.d.ts +76 -0
- package/dist/methods/hosted/push.d.ts.map +1 -0
- package/dist/methods/hosted/push.js +71 -0
- package/dist/methods/hosted/push.js.map +1 -0
- package/dist/methods/hosted/submission.d.ts +18 -0
- package/dist/methods/hosted/submission.d.ts.map +1 -0
- package/dist/methods/hosted/submission.js +23 -0
- package/dist/methods/hosted/submission.js.map +1 -0
- package/dist/methods/index.d.ts.map +1 -1
- package/dist/methods/index.js +44 -2
- package/dist/methods/index.js.map +1 -1
- package/dist/methods/instance/status.d.ts +3 -0
- package/dist/methods/instance/status.d.ts.map +1 -1
- package/dist/methods/instance/status.js +3 -1
- package/dist/methods/instance/status.js.map +1 -1
- package/dist/methods/mostra/initialize.d.ts +17 -3
- package/dist/methods/mostra/initialize.d.ts.map +1 -1
- package/dist/methods/mostra/initialize.js +11 -3
- package/dist/methods/mostra/initialize.js.map +1 -1
- package/dist/methods/port/relay-author.d.ts +28 -0
- package/dist/methods/port/relay-author.d.ts.map +1 -0
- package/dist/methods/port/relay-author.js +42 -0
- package/dist/methods/port/relay-author.js.map +1 -0
- package/dist/methods/port/relay-call.d.ts +33 -0
- package/dist/methods/port/relay-call.d.ts.map +1 -0
- package/dist/methods/port/relay-call.js +31 -0
- package/dist/methods/port/relay-call.js.map +1 -0
- package/dist/methods/port/relay-cancel.d.ts +16 -0
- package/dist/methods/port/relay-cancel.d.ts.map +1 -0
- package/dist/methods/port/relay-cancel.js +21 -0
- package/dist/methods/port/relay-cancel.js.map +1 -0
- package/dist/methods/port/relay-live.d.ts +25 -0
- package/dist/methods/port/relay-live.d.ts.map +1 -0
- package/dist/methods/port/relay-live.js +32 -0
- package/dist/methods/port/relay-live.js.map +1 -0
- package/dist/methods/port/relay-reconcile.d.ts +39 -0
- package/dist/methods/port/relay-reconcile.d.ts.map +1 -0
- package/dist/methods/port/relay-reconcile.js +35 -0
- package/dist/methods/port/relay-reconcile.js.map +1 -0
- package/dist/methods/port/relay-run.d.ts +47 -0
- package/dist/methods/port/relay-run.d.ts.map +1 -0
- package/dist/methods/port/relay-run.js +41 -0
- package/dist/methods/port/relay-run.js.map +1 -0
- package/dist/methods/port/submissions-deliver.d.ts +8 -0
- package/dist/methods/port/submissions-deliver.d.ts.map +1 -1
- package/dist/methods/port/submissions-deliver.js +4 -2
- package/dist/methods/port/submissions-deliver.js.map +1 -1
- package/dist/methods/relay/call-batch.d.ts +26 -0
- package/dist/methods/relay/call-batch.d.ts.map +1 -0
- package/dist/methods/relay/call-batch.js +30 -0
- package/dist/methods/relay/call-batch.js.map +1 -0
- package/dist/methods/relay/effect.d.ts +31 -0
- package/dist/methods/relay/effect.d.ts.map +1 -0
- package/dist/methods/relay/effect.js +30 -0
- package/dist/methods/relay/effect.js.map +1 -0
- package/dist/methods/relay/live-value.d.ts +33 -0
- package/dist/methods/relay/live-value.d.ts.map +1 -0
- package/dist/methods/relay/live-value.js +32 -0
- package/dist/methods/relay/live-value.js.map +1 -0
- package/dist/methods/relay/run-update.d.ts +46 -0
- package/dist/methods/relay/run-update.d.ts.map +1 -0
- package/dist/methods/relay/run-update.js +45 -0
- package/dist/methods/relay/run-update.js.map +1 -0
- package/dist/methods/remote/link.d.ts +40 -0
- package/dist/methods/remote/link.d.ts.map +1 -0
- package/dist/methods/remote/link.js +40 -0
- package/dist/methods/remote/link.js.map +1 -0
- package/dist/methods/remote/login-wait.d.ts +30 -0
- package/dist/methods/remote/login-wait.d.ts.map +1 -0
- package/dist/methods/remote/login-wait.js +36 -0
- package/dist/methods/remote/login-wait.js.map +1 -0
- package/dist/methods/remote/login.d.ts +41 -0
- package/dist/methods/remote/login.d.ts.map +1 -0
- package/dist/methods/remote/login.js +37 -0
- package/dist/methods/remote/login.js.map +1 -0
- package/dist/methods/remote/logout.d.ts +25 -0
- package/dist/methods/remote/logout.d.ts.map +1 -0
- package/dist/methods/remote/logout.js +28 -0
- package/dist/methods/remote/logout.js.map +1 -0
- package/dist/methods/remote/status.d.ts +14 -0
- package/dist/methods/remote/status.d.ts.map +1 -0
- package/dist/methods/remote/status.js +22 -0
- package/dist/methods/remote/status.js.map +1 -0
- package/dist/methods/remote/token.d.ts +19 -0
- package/dist/methods/remote/token.d.ts.map +1 -0
- package/dist/methods/remote/token.js +24 -0
- package/dist/methods/remote/token.js.map +1 -0
- package/dist/methods/share/start.d.ts +5 -2
- package/dist/methods/share/start.d.ts.map +1 -1
- package/dist/methods/share/start.js +6 -3
- package/dist/methods/share/start.js.map +1 -1
- package/dist/methods/state/patch.d.ts +7 -0
- package/dist/methods/state/patch.d.ts.map +1 -1
- package/dist/methods/state/patch.js +2 -1
- package/dist/methods/state/patch.js.map +1 -1
- package/dist/methods/view/url.d.ts +2 -1
- package/dist/methods/view/url.d.ts.map +1 -1
- package/dist/methods/view/url.js +2 -1
- package/dist/methods/view/url.js.map +1 -1
- package/dist/operator.d.ts +464 -0
- package/dist/operator.d.ts.map +1 -0
- package/dist/operator.js +134 -0
- package/dist/operator.js.map +1 -0
- package/dist/policy.d.ts +18 -0
- package/dist/policy.d.ts.map +1 -0
- package/dist/policy.js +23 -0
- package/dist/policy.js.map +1 -0
- package/dist/remote.d.ts +55 -0
- package/dist/remote.d.ts.map +1 -0
- package/dist/remote.js +52 -0
- package/dist/remote.js.map +1 -0
- package/dist/view.d.ts +1 -1
- package/dist/view.js +1 -1
- package/dist/view.js.map +1 -1
- package/package.json +12 -2
- package/schemas/protocol.draft-07.json +1839 -99
- package/schemas/protocol.schema.json +1787 -111
- package/src/actions.ts +45 -5
- package/src/browser.ts +70 -0
- package/src/capability.ts +0 -23
- package/src/diagnostics/codes/action.ts +12 -0
- package/src/diagnostics/codes/artifact.ts +12 -0
- package/src/diagnostics/codes/home.ts +12 -0
- package/src/diagnostics/codes/index.ts +6 -2
- package/src/diagnostics/codes/remote.ts +197 -0
- package/src/diagnostics/codes/submit.ts +12 -0
- package/src/diagnostics/diagnostic.ts +3 -1
- package/src/duration.ts +29 -0
- package/src/ids.ts +33 -1
- package/src/index.ts +143 -8
- package/src/interaction.ts +48 -2
- package/src/manifest.ts +115 -24
- package/src/methods/artifact/export.ts +68 -0
- package/src/methods/artifact/import.ts +39 -0
- package/src/methods/artifact/pause.ts +59 -0
- package/src/methods/hosted/push.ts +146 -0
- package/src/methods/hosted/submission.ts +34 -0
- package/src/methods/index.ts +42 -0
- package/src/methods/instance/status.ts +4 -0
- package/src/methods/mostra/initialize.ts +19 -3
- package/src/methods/port/relay-author.ts +57 -0
- package/src/methods/port/relay-call.ts +58 -0
- package/src/methods/port/relay-cancel.ts +33 -0
- package/src/methods/port/relay-live.ts +48 -0
- package/src/methods/port/relay-reconcile.ts +71 -0
- package/src/methods/port/relay-run.ts +80 -0
- package/src/methods/port/submissions-deliver.ts +13 -1
- package/src/methods/relay/call-batch.ts +52 -0
- package/src/methods/relay/effect.ts +55 -0
- package/src/methods/relay/live-value.ts +54 -0
- package/src/methods/relay/run-update.ts +81 -0
- package/src/methods/remote/link.ts +65 -0
- package/src/methods/remote/login-wait.ts +55 -0
- package/src/methods/remote/login.ts +72 -0
- package/src/methods/remote/logout.ts +42 -0
- package/src/methods/remote/status.ts +34 -0
- package/src/methods/remote/token.ts +39 -0
- package/src/methods/share/start.ts +12 -4
- package/src/methods/state/patch.ts +6 -0
- package/src/methods/view/url.ts +2 -1
- package/src/operator.ts +621 -0
- package/src/policy.ts +30 -0
- package/src/remote.ts +89 -0
- package/src/view.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operator.js","names":[],"sources":["../src/operator.ts"],"sourcesContent":["/**\n * The operator boundary of a remote server (ARCHITECTURE §15.10, INTERFACES §18.6, D165 items 9\n * and 11): the ports an operating layer implements in an ES module the server loads in process,\n * and the handle the server gives it. Each port is optional and has a no-op default, so a\n * self-hoster needs none of it; each call is async and time-limited, and the server checks every\n * answer against the schemas below before it acts on one (an answer they refuse counts as no\n * answer).\n *\n * An operating layer imports nothing of Mostra but this module (`@mostra/protocol/operator`), so\n * the surface it builds on is this file's, versioned with `@mostra/protocol` and changed only\n * additively (D32).\n *\n * ```ts\n * import { defineOperator } from \"@mostra/protocol/operator\";\n *\n * export default defineOperator((server) => ({\n * limits: { check: async (q) => (q.operation === \"share\" ? { allowed: true } : { allowed: true }) },\n * abuse: { report: async (r) => { await server.quarantine({ routeId: r.routeId }, r.reason); } },\n * }));\n * ```\n *\n * Every port call and every handle target names a hosted route (`rte_…`): an artifact ID, and a\n * version ID derived from it (D89), repeat across homes when a project is copied, so a bare ID\n * would reach every tenant hosting it.\n */\nimport * as z from \"zod\";\n\n/** The operator boundary's own revision, which a module may check (additive within it). */\nexport const OPERATOR_REVISION = \"2026-11-08\";\n\n/** How long the server waits for each port, in milliseconds, before it acts as if none answered. */\nexport const OPERATOR_TIME_LIMITS: {\n readonly limits: number;\n readonly policy: number;\n readonly routing: number;\n readonly identity: number;\n readonly accounts: number;\n readonly authenticate: number;\n readonly pushed: number;\n readonly outbound: number;\n} = {\n limits: 2_000,\n policy: 2_000,\n routing: 2_000,\n identity: 2_000,\n accounts: 5_000,\n authenticate: 5_000,\n pushed: 30_000,\n outbound: 30_000,\n};\n\n// ── limits ──────────────────────────────────────────────────────────────────────────────\n\n/**\n * An operation `limits.check` judges. When the operator doesn't answer in time, `share`,\n * `version.push`, `link` and authoring fail closed, and `view`, `submit` and draft writes proceed,\n * so nothing a person typed is lost (D165 item 9).\n */\nexport type LimitOperation =\n | \"share\"\n | \"version.push\"\n | \"link\"\n | \"view\"\n | \"submit\"\n | \"run\"\n | \"run.wait\"\n | \"call\"\n | \"mcp.call\"\n | \"storage\";\n\n/** What `limits.check` is asked. */\nexport interface LimitQuery {\n /** The account the operation counts against. */\n readonly account: string;\n /** The account's hosted home. */\n readonly home: string;\n /** The artifact, for operations on one. */\n readonly artifact?: string;\n /** The artifact's hosted route, for operations on one (WP-30). */\n readonly routeId?: string;\n /** What is asked for. */\n readonly operation: LimitOperation;\n /** How much: bytes for `storage` and `version.push`, else 1. */\n readonly quantity?: number;\n}\n\n/** How long the server may keep an answer instead of asking again, in milliseconds (WP-30). */\nexport interface Cacheable {\n /** Absent or 0: ask again next time. */\n readonly cacheForMs?: number;\n}\n\n/** `limits.check`'s answer. */\nexport type LimitAnswer =\n | ({ readonly allowed: true } & Cacheable)\n | ({\n readonly allowed: false;\n /** A diagnostic code of the operator's (the server answers `MOSTRA_REMOTE_LIMIT_REACHED`). */\n readonly code: string;\n /** Shown as text to whoever was refused. */\n readonly message: string;\n readonly retryAfterMs?: number;\n } & Cacheable);\n\nconst cacheFor = z.int().min(0).max(86_400_000).exactOptional();\n\n/** The schema the server checks `limits.check`'s answer against. */\nexport const LimitAnswer: z.ZodType<LimitAnswer> = z.union([\n z.object({ allowed: z.literal(true), cacheForMs: cacheFor }),\n z.object({\n allowed: z.literal(false),\n code: z.string().min(1).max(128),\n message: z.string().max(1_000),\n retryAfterMs: z.int().min(0).max(86_400_000).exactOptional(),\n cacheForMs: cacheFor,\n }),\n]);\n\n// ── metering ────────────────────────────────────────────────────────────────────────────\n\n/** A counter's name (INTERFACES §18.6). */\nexport type MeterName =\n | \"views\"\n | \"submissions\"\n | \"requests\"\n | \"bytes.stored\"\n | \"bytes.egress\"\n | \"relay.messages\"\n | \"mcp.calls\"\n | \"home.activeSeconds\"\n | (string & {});\n\n/**\n * One counter of a batch. `views` carry `viewerKey`, a monthly pseudonymous key (an HMAC under a\n * key the server rotates each month), never an identity: per account for a signed-in viewer, per\n * viewer for a link minted with one, and per route for an anonymous viewer, since the shell gives\n * each route a different key and none spans routes (HY-08). `mcp.calls` carry `client`, the MCP\n * client's `clientInfo` name (D148).\n */\nexport interface MeterCounter {\n /** What is counted. */\n readonly name: MeterName;\n /** The account it counts against. */\n readonly account: string;\n /** The account's hosted home. */\n readonly home?: string;\n /** The artifact, for counters of one. */\n readonly artifactId?: string;\n /** The artifact's hosted route, for counters of one. */\n readonly routeId?: string;\n /** How much in the batch's window: a count, bytes or seconds. */\n readonly value: number;\n /** What tells counters of one name apart (`viewerKey`, `client`). */\n readonly dimensions?: Readonly<Record<string, string>>;\n}\n\n/** What `metering.record` receives, at least once, idempotent by `batchId`. */\nexport interface MeterBatch {\n /** Stable across retries: a batch delivered twice is the same batch. */\n readonly batchId: string;\n /** Where the window the counters cover starts. */\n readonly from: string;\n /** Where it ends. */\n readonly to: string;\n /** The counters, one per name, account, route and dimensions. */\n readonly counters: readonly MeterCounter[];\n}\n\n// ── sign-in: identity providers and accounts ────────────────────────────────────────────\n\n/**\n * Who an identity provider says signed in (INTERFACES §18.5). `facts` carries what a provider\n * tells beyond that (GitHub's account age, `createdAt`), for an operator's policy.\n */\nexport interface SignInIdentity {\n /** The provider's ID (`IdentityProvider.id`). */\n readonly provider: string;\n /** The provider's own stable ID for the person. */\n readonly subject: string;\n /** The person's email address, when the provider gives one. */\n readonly email?: string;\n /** Whether the provider verified `email`. */\n readonly emailVerified?: boolean;\n /** The display name the provider gives. */\n readonly name?: string;\n /** What else the provider tells (an account's age as `createdAt`). */\n readonly facts?: Readonly<Record<string, unknown>>;\n}\n\n/** The schema the server checks a provider's `SignInIdentity` against. */\nexport const SignInIdentity: z.ZodType<SignInIdentity> = z.object({\n provider: z.string().regex(/^[a-z][a-z0-9-]{0,31}$/),\n subject: z.string().min(1).max(256),\n email: z.string().max(320).exactOptional(),\n emailVerified: z.boolean().exactOptional(),\n name: z.string().max(256).exactOptional(),\n facts: z.record(z.string(), z.unknown()).exactOptional(),\n});\n\n/** PKCE for one sign-in at a provider: the server makes it; the provider sends `challenge`. */\nexport interface SignInPkce {\n /** The S256 challenge the provider's authorization request carries. */\n readonly challenge: string;\n /** Always S256. */\n readonly method: \"S256\";\n /** The verifier the provider's code exchange sends. */\n readonly verifier: string;\n}\n\n/** What a provider's `authorize` and `callback` are told about the sign-in in progress. */\nexport interface SignInContext {\n /** The provider's return address on the API origin: `<apiOrigin>/signin/<id>/callback`. */\n readonly redirectUri: string;\n /** A fresh value an OpenID Connect provider binds its ID token to. */\n readonly nonce: string;\n}\n\n/**\n * An identity provider behind the sign-in port (D165 item 8): the built-in OpenID Connect and\n * GitHub adapters, a development one for tests, or one an operator module supplies.\n */\nexport interface IdentityProvider {\n /** Lower-case letters, digits and hyphens, at most 32: part of its callback's path. */\n readonly id: string;\n /** What the sign-in page calls it (\"GitHub\"). */\n readonly label: string;\n /** Where to send the person: the provider's authorization URL with `state` and PKCE. */\n authorize(state: string, pkce: SignInPkce, context: SignInContext): string | Promise<string>;\n /**\n * The person the provider names on return, from its callback's query (each parameter once; a\n * repeated one is refused before this is called). The server has already\n * checked `state`; the provider exchanges the code (with `pkce.verifier`) and checks what it\n * gets. Throws when sign-in failed.\n */\n callback(\n params: Readonly<Record<string, string>>,\n context: SignInContext & { readonly state: string; readonly pkce: SignInPkce },\n ): Promise<SignInIdentity>;\n}\n\n/**\n * `accounts.resolve`'s answer: the account (`status` `suspended` refuses sign-in), a **first\n * sign-in step** on the operator's origin, or a refusal shown as text.\n *\n * A step: the server sends the person to `step.url` with `mostra_return` added, an address on the\n * API origin (`/signin/return?step=<handle>`). The handle is single-use, lasts 15 minutes and is\n * bound to the browser that started the sign-in (a `__Host-` cookie on the API origin, never on a\n * user-content domain), so it can't be replayed or swapped. When the person comes back the server\n * calls `resolve` again with the same identity and `context.steps` one higher; at most three steps\n * per sign-in (WP-30, D167).\n */\nexport type AccountResolution =\n | {\n readonly account: string;\n readonly name?: string;\n readonly status: \"active\" | \"suspended\";\n }\n | { readonly step: { readonly url: string } }\n | { readonly refused: { readonly message: string } };\n\n/** The schema the server checks `accounts.resolve`'s answer against. */\nexport const AccountResolution: z.ZodType<AccountResolution> = z.union([\n z.object({\n account: z.string().min(1).max(128),\n name: z.string().max(256).exactOptional(),\n status: z.enum([\"active\", \"suspended\"]),\n }),\n z.object({ step: z.object({ url: z.url({ protocol: /^https$/ }).max(2_048) }) }),\n z.object({ refused: z.object({ message: z.string().max(1_000) }) }),\n]);\n\n/** Where an operator-issued credential was presented (D165 item 9, Opus review of WP-28). */\nexport type CredentialResource = \"host\" | \"mcp\" | \"files\";\n\n/**\n * `accounts.authenticate`'s answer for a credential the operator issued, or `null`. `subject`\n * names the credential stably (a service key's ID): a binding with it is one owner instance link\n * of the account, kept per subject, so a program can run an always-on owner instance.\n */\nexport interface AuthenticatedCredential {\n /** The account the credential acts for. */\n readonly account: string;\n /** What it may do: `mostra` for everything a sign-in may. */\n readonly scope: readonly string[];\n /** The credential's own stable name, which keys its instance link. */\n readonly subject?: string;\n}\n\n/** The schema the server checks `accounts.authenticate`'s answer against. */\nexport const AuthenticatedCredential: z.ZodType<AuthenticatedCredential | null> = z\n .object({\n account: z.string().min(1).max(128),\n scope: z.array(z.string().max(64)).max(32),\n subject: z\n .string()\n .regex(/^[A-Za-z0-9._:-]{1,128}$/)\n .exactOptional(),\n })\n .nullable();\n\n// ── abuse ───────────────────────────────────────────────────────────────────────────────\n\n/** A report from the shell's report control (`POST /a/{routeId}/_mostra/report`). */\nexport interface AbuseReport {\n /** The reported route. */\n readonly routeId: string;\n /** The route's label. */\n readonly label: string;\n /** The artifact's own ID (as its manifest names it). */\n readonly artifactId: string;\n /** The hosted home. */\n readonly home: string;\n /** The version the reporter saw, when the shell knew it. */\n readonly versionId?: string;\n /** The reason the reporter chose. */\n readonly reason: string;\n /** What the reporter wrote, as text. */\n readonly detail?: string;\n /** When the report was made. */\n readonly at: string;\n}\n\n/** What `abuse.pushed` receives after each version push, with read access to its client files. */\nexport interface PushedVersion {\n /** The route the version was pushed to. */\n readonly routeId: string;\n /** The route's label. */\n readonly label: string;\n /** The artifact's own ID (as its manifest names it). */\n readonly artifactId: string;\n /** The hosted home. */\n readonly home: string;\n /** The pushed version. */\n readonly versionId: string;\n /** The version's `manifest.json`, parsed. */\n readonly manifest: unknown;\n /** Every client file's path (`client/…`). */\n readonly files: readonly string[];\n /** A client file's bytes, by its path in the listing. */\n read(path: string): Promise<Uint8Array>;\n}\n\n/** `abuse.pushed`'s answer: quarantine the version, or nothing. */\nexport type PushedAnswer = { readonly quarantine?: { readonly reason: string } } | undefined;\n\n/** The schema the server checks `abuse.pushed`'s answer against. */\nexport const PushedAnswer: z.ZodType<PushedAnswer> = z\n .object({ quarantine: z.object({ reason: z.string().max(1_000) }).exactOptional() })\n .optional();\n\n// ── policy ──────────────────────────────────────────────────────────────────────────────\n\n/** What `policy.link` is asked about one link of one route. */\nexport interface LinkQuery {\n /** The account that owns the route. */\n readonly account: string;\n /** Its hosted home. */\n readonly home: string;\n /** The route. */\n readonly routeId: string;\n /** The artifact's own ID (as its manifest names it). */\n readonly artifactId: string;\n /** The link, once it exists. */\n readonly tokenId?: string;\n}\n\n/**\n * Per link and artifact (D161): an interstitial before the page, the longest link lifetime and an\n * idle expiry (durations such as `7d`), the after-submit line, the footer's wording (it can't be\n * hidden on a public link), and the made-with mark.\n */\nexport interface LinkPolicy extends Cacheable {\n /** A page the shell shows before the artifact, once per browser and link; its message as text. */\n readonly interstitial?: { readonly kind: string; readonly message?: string };\n /** The longest a link may live from when it was minted. */\n readonly maxTtl?: string;\n /** A link unused for this long expires. */\n readonly idleExpiry?: string;\n /** The line after \"Your answer was sent.\", as text. */\n readonly afterSubmit?: string;\n /** The footer's wording in place of \"Never enter passwords\", as text. */\n readonly footer?: string;\n /** Whether the made-with mark shows, and where it links. */\n readonly madeWith?: { readonly show: boolean; readonly href?: string };\n}\n\nconst duration = z.string().regex(/^[1-9][0-9]{0,8}[smhd]$/);\n\n/** The schema the server checks `policy.link`'s answer against. */\nexport const LinkPolicy: z.ZodType<LinkPolicy> = z.object({\n interstitial: z\n .object({ kind: z.string().min(1).max(64), message: z.string().max(2_000).exactOptional() })\n .exactOptional(),\n maxTtl: duration.exactOptional(),\n idleExpiry: duration.exactOptional(),\n afterSubmit: z.string().max(500).exactOptional(),\n footer: z.string().min(1).max(500).exactOptional(),\n madeWith: z\n .object({ show: z.boolean(), href: z.url({ protocol: /^https$/ }).exactOptional() })\n .exactOptional(),\n cacheForMs: cacheFor,\n});\n\n/**\n * How Mostra behaves in one chat host (D160): how a page renders there (an MCP App resource, or\n * the hosted link), and what a reached limit may say (`limit-reached` only, or the operator's\n * message).\n */\nexport interface ChatHostPolicy {\n /** `app`: through the MCP Apps resource; `link`: the hosted link only. */\n readonly render?: \"app\" | \"link\";\n /** What a reached limit may say there. */\n readonly quota?: \"limit-reached\" | \"message\";\n}\n\n/** The schema of the `ChatHostPolicy` type, for configuration and `policy.chatHost`. */\nexport const ChatHostPolicy: z.ZodType<ChatHostPolicy> = z.object({\n render: z.enum([\"app\", \"link\"]).exactOptional(),\n quota: z.enum([\"limit-reached\", \"message\"]).exactOptional(),\n});\n\n// ── routing ─────────────────────────────────────────────────────────────────────────────\n\n/**\n * `routing.resolve`'s answer for an exact `Host` the server doesn't serve by itself (any host but\n * a configured user-content domain's apex and its routes' labels):\n *\n * - `shell`: the host shows the hosted shell (`/a/<routeId>`) for one home's routes, whose frames\n * are served on `<route label>.<domain>`. `domain` is a configured user-content domain, or one\n * the operator supplies (an organization's own, whose TLS the operator's edge terminates for the\n * host and every label under `domain`); the server serves those labels once the host is\n * recorded, without asking again.\n * - `route`: the host shows the shell of one route only (`/a/<routeId>`), with its frames on its\n * label under the active domain: a chosen, readable name.\n * - `null`: nothing is served (421).\n *\n * A host the operator supplies is recorded like the server's own labels, bound to its home\n * forever: never issued to another home, so no origin's storage passes between tenants (D165).\n */\nexport type RoutingAnswer =\n | ({ readonly shell: { readonly domain: string; readonly home: string } } & Cacheable)\n | ({ readonly route: { readonly home: string; readonly routeId: string } } & Cacheable)\n | null;\n\n/**\n * A host name of at least two labels, lower case; a port only as a local test server's hosts carry\n * one (the server's own configuration allows the same).\n */\nconst hostName = z\n .string()\n .regex(\n /^(?=.{1,253}(:|$))[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)+(:\\d{1,5})?$/,\n );\n\n/** The schema the server checks `routing.resolve`'s answer against. */\nexport const RoutingAnswer: z.ZodType<RoutingAnswer> = z.union([\n z.object({\n shell: z.object({ domain: hostName, home: z.string().min(1) }),\n cacheForMs: cacheFor,\n }),\n z.object({\n route: z.object({ home: z.string().min(1), routeId: z.string().min(1) }),\n cacheForMs: cacheFor,\n }),\n z.null(),\n]);\n\n/** The schema of `routing.linkHost`'s answer: a shell host, or `null` for the active domain. */\nexport const LinkHost: z.ZodType<string | null> = hostName.nullable();\n\n// ── events ──────────────────────────────────────────────────────────────────────────────\n\n/** The kind of an outbound event. */\nexport type OperatorEventKind =\n | \"submission.accepted\"\n | \"version.pushed\"\n | \"run.ended\"\n | \"roster.completed\"\n | (string & {});\n\n/**\n * One outbound event, delivered at least once with a stable `eventId`. `payload`:\n * `submission.accepted` carries the submission's `Results` (INTERFACES §8, the `Results` type of `@mostra/protocol`); `version.pushed`\n * `{ versionId, number }`; `run.ended` `{ runId, action, status }`; `roster.completed` is WP-31's.\n * `label` is the route's label, so an operator running several servers behind one front learns\n * which serves which label (WP-30).\n */\nexport interface OperatorEvent {\n /** Stable across retries. */\n readonly eventId: string;\n /** What happened. */\n readonly kind: OperatorEventKind;\n /** The account that owns the route. */\n readonly account: string;\n /** Its hosted home. */\n readonly home: string;\n /** The route. */\n readonly routeId: string;\n /** The route's label. */\n readonly label: string;\n /** The artifact's own ID (as its manifest names it). */\n readonly artifactId: string;\n /** When it happened. */\n readonly at: string;\n /** What the kind carries. */\n readonly payload: unknown;\n}\n\n// ── the module ──────────────────────────────────────────────────────────────────────────\n\n/** The ports an operator module implements; each is optional, with the default named. */\nexport interface OperatorPorts {\n /** Allows or refuses an operation for an account. Default: allow. */\n readonly limits?: { check(q: LimitQuery): Promise<LimitAnswer> };\n /** Counters in batches, at least once. Default: discard. */\n readonly metering?: { record(batch: MeterBatch): Promise<void> };\n /**\n * Identity providers beside the configured ones, asked at each sign-in so the set can change\n * while the server runs (WP-30). Default: none.\n */\n readonly identity?: {\n providers(): Promise<readonly IdentityProvider[]> | readonly IdentityProvider[];\n };\n /**\n * Sign-in identities to accounts, a first sign-in step, and credentials the operator issued.\n * Default: the server's own accounts, no step, no outside credential.\n */\n readonly accounts?: {\n resolve(\n identity: SignInIdentity,\n context: { readonly steps: number },\n ): Promise<AccountResolution>;\n authenticate?(\n bearer: string,\n context: { readonly resource: CredentialResource },\n ): Promise<AuthenticatedCredential | null>;\n status?(account: string): Promise<\"active\" | \"suspended\">;\n };\n /** Reports and the after-push hook. Default: nothing. */\n readonly abuse?: {\n report(r: AbuseReport): Promise<void>;\n pushed?(v: PushedVersion): Promise<PushedAnswer>;\n };\n /** Per link and per chat host. Default: nothing beyond configuration. */\n readonly policy?: {\n link(q: LinkQuery): Promise<LinkPolicy>;\n chatHost?(client: {\n readonly name: string;\n readonly redirectHost?: string;\n }): Promise<ChatHostPolicy | null>;\n };\n /**\n * Hosts the operator supplies, and the host a new link is minted on. Default: the server's own\n * labels, and links on the active domain.\n */\n readonly routing?: {\n resolve(host: string): Promise<RoutingAnswer>;\n /**\n * The shell host a new link of this route is minted on (one `resolve` answers `shell` or\n * `route` for), or `null` for the active domain (WP-30). A link keeps the host it was minted\n * on (D137).\n */\n linkHost?(q: {\n readonly account: string;\n readonly home: string;\n readonly routeId: string;\n }): Promise<string | null>;\n };\n /** Outbound events, at least once with stable IDs. Default: discard. */\n readonly events?: { deliver(e: OperatorEvent): Promise<void> };\n /** Reserved for WP-31 (D121, D165 item 16); no mailer ships. */\n readonly invitations?: unknown;\n}\n\n/** A hosted route, or one version of it: what the handle's quarantine and release act on. */\nexport type RouteTarget =\n | { readonly routeId: string }\n | { readonly routeId: string; readonly versionId: string };\n\n/**\n * What the server gives its operator module (INTERFACES §18.6). Every target names a hosted route.\n * Each call is durable when it resolves.\n */\nexport interface ServerHandle {\n /** The operator boundary's revision this server speaks. */\n readonly revision: string;\n /** The server's API origin. */\n readonly apiOrigin: string;\n /** A neutral \"under review\" page from the shell; data kept; `release` restores it. */\n quarantine(target: RouteTarget, reason: string): Promise<void>;\n /** Ends a quarantine. */\n release(target: RouteTarget): Promise<void>;\n /** Views keep working; submissions and relayed actions are refused; only the operator resumes. */\n pause(routeId: string, reason: string): Promise<void>;\n /** Ends an operator's pause (and an owner's, too). */\n resume(routeId: string): Promise<void>;\n /** Refuses the home's bindings, pushes, links and pages until `resumeHome`. */\n suspendHome(home: string, reason: string): Promise<void>;\n /** Ends a suspension. */\n resumeHome(home: string): Promise<void>;\n /** Revokes every link of a route; answers how many were live. */\n revokeLinks(routeId: string): Promise<number>;\n /** Revokes one link (410 from then on). */\n revokeLink(tokenId: string): Promise<void>;\n /** Closes the home and refuses to reopen it, to move it between data directories. */\n drainHome(home: string): Promise<void>;\n /** Serves a drained home again. */\n releaseHome(home: string): Promise<void>;\n /** A restore from a backup: rotates the home's incarnation before it serves anything. */\n restored(home: string): Promise<void>;\n /** Deletion: explicit, never part of another action. The route's label is never issued again. */\n remove(routeId: string): Promise<void>;\n}\n\n/** An operator module's default export. */\nexport type OperatorModule = (server: ServerHandle) => OperatorPorts | Promise<OperatorPorts>;\n\n/** Types an operator module's default export; returns it unchanged. */\nexport function defineOperator(module: OperatorModule): OperatorModule {\n return module;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA,MAAa,oBAAoB;;AAGjC,MAAa,uBAST;CACF,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,UAAU;CACV,UAAU;CACV,cAAc;CACd,QAAQ;CACR,UAAU;AACZ;AAuDA,MAAM,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAU,CAAC,CAAC,cAAc;;AAG9D,MAAa,cAAsC,EAAE,MAAM,CACzD,EAAE,OAAO;CAAE,SAAS,EAAE,QAAQ,IAAI;CAAG,YAAY;AAAS,CAAC,GAC3D,EAAE,OAAO;CACP,SAAS,EAAE,QAAQ,KAAK;CACxB,MAAM,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG;CAC/B,SAAS,EAAE,OAAO,CAAC,CAAC,IAAI,GAAK;CAC7B,cAAc,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,KAAU,CAAC,CAAC,cAAc;CAC3D,YAAY;AACd,CAAC,CACH,CAAC;;AA0ED,MAAa,iBAA4C,EAAE,OAAO;CAChE,UAAU,EAAE,OAAO,CAAC,CAAC,MAAM,wBAAwB;CACnD,SAAS,EAAE,OAAO,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S,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;EAAE,CAAC;EACvE,YAAY;CACd,CAAC;CACD,EAAE,KAAK;AACT,CAAC;;AAGD,MAAa,WAAqC,SAAS,SAAS;;AAsJpE,SAAgB,eAAe,QAAwC;CACrE,OAAO;AACT"}
|
package/dist/policy.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as z from "zod";
|
|
2
|
+
//#region src/policy.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* The submission policy an artifact requests (D10, D39, D63). The host decides the policy in force;
|
|
5
|
+
* the manifest only asks for one.
|
|
6
|
+
*/
|
|
7
|
+
export type SubmissionPolicy = {
|
|
8
|
+
readonly policy: "once";
|
|
9
|
+
readonly scope?: "per-artifact" | "per-viewer";
|
|
10
|
+
} | {
|
|
11
|
+
readonly policy: "epochs";
|
|
12
|
+
} | {
|
|
13
|
+
readonly policy: "none";
|
|
14
|
+
};
|
|
15
|
+
/** The Zod schema of the `SubmissionPolicy` type. */
|
|
16
|
+
export declare const SubmissionPolicy: z.ZodType<SubmissionPolicy>;
|
|
17
|
+
//#endregion
|
|
18
|
+
//# sourceMappingURL=policy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.d.ts","names":[],"sources":["../src/policy.ts"],"mappings":";;;;;;YAWY;WACG;WAAyB;;WACzB;;WACA;;;qBAGF,kBAAkB,EAAE,QAAQ"}
|
package/dist/policy.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { wireRegistry } from "./wire-registry.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/policy.ts
|
|
4
|
+
/**
|
|
5
|
+
* The submission policy (D10, D39, D63): a module of its own, so the shell bridge's view context
|
|
6
|
+
* reads it without the whole manifest schema in its bundle.
|
|
7
|
+
*/
|
|
8
|
+
/** The Zod schema of the `SubmissionPolicy` type. */
|
|
9
|
+
const SubmissionPolicy = z.discriminatedUnion("policy", [
|
|
10
|
+
z.object({
|
|
11
|
+
policy: z.literal("once"),
|
|
12
|
+
scope: z.enum(["per-artifact", "per-viewer"]).exactOptional()
|
|
13
|
+
}),
|
|
14
|
+
z.object({ policy: z.literal("epochs") }),
|
|
15
|
+
z.object({ policy: z.literal("none") })
|
|
16
|
+
]).register(wireRegistry, {
|
|
17
|
+
id: "SubmissionPolicy",
|
|
18
|
+
description: "A submission policy: once (per-artifact or per-viewer), epochs, or none."
|
|
19
|
+
});
|
|
20
|
+
//#endregion
|
|
21
|
+
export { SubmissionPolicy };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=policy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"policy.js","names":[],"sources":["../src/policy.ts"],"sourcesContent":["/**\n * The submission policy (D10, D39, D63): a module of its own, so the shell bridge's view context\n * reads it without the whole manifest schema in its bundle.\n */\nimport * as z from \"zod\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/**\n * The submission policy an artifact requests (D10, D39, D63). The host decides the policy in force;\n * the manifest only asks for one.\n */\nexport type SubmissionPolicy =\n | { readonly policy: \"once\"; readonly scope?: \"per-artifact\" | \"per-viewer\" }\n | { readonly policy: \"epochs\" }\n | { readonly policy: \"none\" };\n\n/** The Zod schema of the `SubmissionPolicy` type. */\nexport const SubmissionPolicy: z.ZodType<SubmissionPolicy> = z\n .discriminatedUnion(\"policy\", [\n z.object({\n policy: z.literal(\"once\"),\n scope: z.enum([\"per-artifact\", \"per-viewer\"]).exactOptional(),\n }),\n z.object({ policy: z.literal(\"epochs\") }),\n z.object({ policy: z.literal(\"none\") }),\n ])\n .register(wireRegistry, {\n id: \"SubmissionPolicy\",\n description: \"A submission policy: once (per-artifact or per-viewer), epochs, or none.\",\n });\n"],"mappings":";;;;;;;;AAiBA,MAAa,mBAAgD,EAC1D,mBAAmB,UAAU;CAC5B,EAAE,OAAO;EACP,QAAQ,EAAE,QAAQ,MAAM;EACxB,OAAO,EAAE,KAAK,CAAC,gBAAgB,YAAY,CAAC,CAAC,CAAC,cAAc;CAC9D,CAAC;CACD,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,QAAQ,EAAE,CAAC;CACxC,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,MAAM,EAAE,CAAC;AACxC,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC"}
|
package/dist/remote.d.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Cursor } from "./ids.js";
|
|
2
|
+
import * as z from "zod";
|
|
3
|
+
//#region src/remote.d.ts
|
|
4
|
+
/** A server, by its API origin (`https://api.example`). */
|
|
5
|
+
export type ServerOrigin = string;
|
|
6
|
+
/** The Zod schema of the `ServerOrigin` type: an origin with no path. */
|
|
7
|
+
export declare const ServerOrigin: z.ZodType<ServerOrigin>;
|
|
8
|
+
/** The state of an instance's link to one server (INTERFACES §18.2). */
|
|
9
|
+
export type RemoteLinkState = "connected" | "connecting" | "offline" | "signed-out";
|
|
10
|
+
/** One server this home is linked to (`remote/status`). */
|
|
11
|
+
export interface RemoteLink {
|
|
12
|
+
/** The server's API origin. */
|
|
13
|
+
readonly server: ServerOrigin;
|
|
14
|
+
/** The account signed in there. */
|
|
15
|
+
readonly account: {
|
|
16
|
+
readonly id: string;
|
|
17
|
+
readonly name?: string;
|
|
18
|
+
};
|
|
19
|
+
/** This home's instance link on that server (`lnk_…`), kept across sign-outs. */
|
|
20
|
+
readonly instanceId: string;
|
|
21
|
+
/** The link's name, as the account's other instances see it. */
|
|
22
|
+
readonly name: string;
|
|
23
|
+
/** Whether this instance is the account's default instance (D165 item 1b). */
|
|
24
|
+
readonly default: boolean;
|
|
25
|
+
/** Whether the binding is open, being dialled, offline, or signed out. */
|
|
26
|
+
readonly state: RemoteLinkState;
|
|
27
|
+
/** When the link reached its state. */
|
|
28
|
+
readonly since: string;
|
|
29
|
+
/** Publishes of shared artifacts waiting to reach the server. */
|
|
30
|
+
readonly pendingPushes: number;
|
|
31
|
+
/** Why the link isn't connected, when it failed. */
|
|
32
|
+
readonly lastError?: string;
|
|
33
|
+
}
|
|
34
|
+
/** The Zod schema of the `RemoteLink` type. */
|
|
35
|
+
export declare const RemoteLink: z.ZodType<RemoteLink>;
|
|
36
|
+
/**
|
|
37
|
+
* What an owner instance tells its hosted home as it opens a binding session (INTERFACES §18.2):
|
|
38
|
+
* its link, the highest relay sequence it accepted, and the hosted home's position it committed,
|
|
39
|
+
* so a home restored to an earlier copy is found before it answers (D165, FAILURE_MODEL §11.2).
|
|
40
|
+
*/
|
|
41
|
+
export interface OwnerLinkInfo {
|
|
42
|
+
/** The instance's `lnk_` ID on this server. */
|
|
43
|
+
readonly instanceId: string;
|
|
44
|
+
/** The highest relay sequence the owner's ledger accepted. */
|
|
45
|
+
readonly relayMark: number;
|
|
46
|
+
/** The hosted home's position the owner committed: its incarnation and cursor. */
|
|
47
|
+
readonly followed?: {
|
|
48
|
+
readonly incarnation: string;
|
|
49
|
+
readonly cursor: Cursor;
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
/** The Zod schema of the `OwnerLinkInfo` type. */
|
|
53
|
+
export declare const OwnerLinkInfo: z.ZodType<OwnerLinkInfo>;
|
|
54
|
+
//#endregion
|
|
55
|
+
//# sourceMappingURL=remote.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.d.ts","names":[],"sources":["../src/remote.ts"],"mappings":";;;;YASY;;qBAGC,cAAc,EAAE,QAAQ;;YASzB;;iBAGK;;WAEN,QAAQ;;WAER;aAAoB;aAAqB;;;WAEzC;;WAEA;;WAEA;;WAEA,OAAO;;WAEP;;WAEA;;WAEA;;;qBAIE,YAAY,EAAE,QAAQ;;;;;;iBAsBlB;;WAEN;;WAEA;;WAEA;aAAsB;aAA8B,QAAQ;;;;qBAI1D,eAAe,EAAE,QAAQ"}
|
package/dist/remote.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { wireRegistry } from "./wire-registry.js";
|
|
2
|
+
import { Cursor } from "./ids.js";
|
|
3
|
+
import * as z from "zod";
|
|
4
|
+
//#region src/remote.ts
|
|
5
|
+
/**
|
|
6
|
+
* The owner instance's links to remote servers (INTERFACES §18.2, D165 items 1, 2): what
|
|
7
|
+
* `remote/status` reports and `mostra/initialize` carries on a binding.
|
|
8
|
+
*/
|
|
9
|
+
/** The Zod schema of the `ServerOrigin` type: an origin with no path. */
|
|
10
|
+
const ServerOrigin = z.string().regex(/^https?:\/\/[^/?#\s]+$/).register(wireRegistry, {
|
|
11
|
+
id: "ServerOrigin",
|
|
12
|
+
description: "A remote server, by its API origin, such as https://api.example."
|
|
13
|
+
});
|
|
14
|
+
/** The Zod schema of the `RemoteLink` type. */
|
|
15
|
+
const RemoteLink = z.object({
|
|
16
|
+
server: ServerOrigin,
|
|
17
|
+
account: z.object({
|
|
18
|
+
id: z.string(),
|
|
19
|
+
name: z.string().exactOptional()
|
|
20
|
+
}),
|
|
21
|
+
instanceId: z.string(),
|
|
22
|
+
name: z.string(),
|
|
23
|
+
default: z.boolean(),
|
|
24
|
+
state: z.enum([
|
|
25
|
+
"connected",
|
|
26
|
+
"connecting",
|
|
27
|
+
"offline",
|
|
28
|
+
"signed-out"
|
|
29
|
+
]),
|
|
30
|
+
since: z.string(),
|
|
31
|
+
pendingPushes: z.int().min(0),
|
|
32
|
+
lastError: z.string().exactOptional()
|
|
33
|
+
}).register(wireRegistry, {
|
|
34
|
+
id: "RemoteLink",
|
|
35
|
+
description: "One remote server this home is linked to, and the state of the link."
|
|
36
|
+
});
|
|
37
|
+
/** The Zod schema of the `OwnerLinkInfo` type. */
|
|
38
|
+
const OwnerLinkInfo = z.object({
|
|
39
|
+
instanceId: z.string().min(1),
|
|
40
|
+
relayMark: z.int().min(0),
|
|
41
|
+
followed: z.object({
|
|
42
|
+
incarnation: z.string().min(1),
|
|
43
|
+
cursor: Cursor.schema
|
|
44
|
+
}).exactOptional()
|
|
45
|
+
}).register(wireRegistry, {
|
|
46
|
+
id: "OwnerLinkInfo",
|
|
47
|
+
description: "An owner instance's link on its binding session: its link ID, its relay mark and the hosted home's position it committed."
|
|
48
|
+
});
|
|
49
|
+
//#endregion
|
|
50
|
+
export { OwnerLinkInfo, RemoteLink, ServerOrigin };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=remote.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remote.js","names":[],"sources":["../src/remote.ts"],"sourcesContent":["/**\n * The owner instance's links to remote servers (INTERFACES §18.2, D165 items 1, 2): what\n * `remote/status` reports and `mostra/initialize` carries on a binding.\n */\nimport * as z from \"zod\";\nimport { Cursor } from \"./ids.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** A server, by its API origin (`https://api.example`). */\nexport type ServerOrigin = string;\n\n/** The Zod schema of the `ServerOrigin` type: an origin with no path. */\nexport const ServerOrigin: z.ZodType<ServerOrigin> = z\n .string()\n .regex(/^https?:\\/\\/[^/?#\\s]+$/)\n .register(wireRegistry, {\n id: \"ServerOrigin\",\n description: \"A remote server, by its API origin, such as https://api.example.\",\n });\n\n/** The state of an instance's link to one server (INTERFACES §18.2). */\nexport type RemoteLinkState = \"connected\" | \"connecting\" | \"offline\" | \"signed-out\";\n\n/** One server this home is linked to (`remote/status`). */\nexport interface RemoteLink {\n /** The server's API origin. */\n readonly server: ServerOrigin;\n /** The account signed in there. */\n readonly account: { readonly id: string; readonly name?: string };\n /** This home's instance link on that server (`lnk_…`), kept across sign-outs. */\n readonly instanceId: string;\n /** The link's name, as the account's other instances see it. */\n readonly name: string;\n /** Whether this instance is the account's default instance (D165 item 1b). */\n readonly default: boolean;\n /** Whether the binding is open, being dialled, offline, or signed out. */\n readonly state: RemoteLinkState;\n /** When the link reached its state. */\n readonly since: string;\n /** Publishes of shared artifacts waiting to reach the server. */\n readonly pendingPushes: number;\n /** Why the link isn't connected, when it failed. */\n readonly lastError?: string;\n}\n\n/** The Zod schema of the `RemoteLink` type. */\nexport const RemoteLink: z.ZodType<RemoteLink> = z\n .object({\n server: ServerOrigin,\n account: z.object({ id: z.string(), name: z.string().exactOptional() }),\n instanceId: z.string(),\n name: z.string(),\n default: z.boolean(),\n state: z.enum([\"connected\", \"connecting\", \"offline\", \"signed-out\"]),\n since: z.string(),\n pendingPushes: z.int().min(0),\n lastError: z.string().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"RemoteLink\",\n description: \"One remote server this home is linked to, and the state of the link.\",\n });\n\n/**\n * What an owner instance tells its hosted home as it opens a binding session (INTERFACES §18.2):\n * its link, the highest relay sequence it accepted, and the hosted home's position it committed,\n * so a home restored to an earlier copy is found before it answers (D165, FAILURE_MODEL §11.2).\n */\nexport interface OwnerLinkInfo {\n /** The instance's `lnk_` ID on this server. */\n readonly instanceId: string;\n /** The highest relay sequence the owner's ledger accepted. */\n readonly relayMark: number;\n /** The hosted home's position the owner committed: its incarnation and cursor. */\n readonly followed?: { readonly incarnation: string; readonly cursor: Cursor };\n}\n\n/** The Zod schema of the `OwnerLinkInfo` type. */\nexport const OwnerLinkInfo: z.ZodType<OwnerLinkInfo> = z\n .object({\n instanceId: z.string().min(1),\n relayMark: z.int().min(0),\n followed: z.object({ incarnation: z.string().min(1), cursor: Cursor.schema }).exactOptional(),\n })\n .register(wireRegistry, {\n id: \"OwnerLinkInfo\",\n description:\n \"An owner instance's link on its binding session: its link ID, its relay mark and the hosted home's position it committed.\",\n });\n"],"mappings":";;;;;;;;;AAYA,MAAa,eAAwC,EAClD,OAAO,CAAC,CACR,MAAM,wBAAwB,CAAC,CAC/B,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AA4BH,MAAa,aAAoC,EAC9C,OAAO;CACN,QAAQ;CACR,SAAS,EAAE,OAAO;EAAE,IAAI,EAAE,OAAO;EAAG,MAAM,EAAE,OAAO,CAAC,CAAC,cAAc;CAAE,CAAC;CACtE,YAAY,EAAE,OAAO;CACrB,MAAM,EAAE,OAAO;CACf,SAAS,EAAE,QAAQ;CACnB,OAAO,EAAE,KAAK;EAAC;EAAa;EAAc;EAAW;CAAY,CAAC;CAClE,OAAO,EAAE,OAAO;CAChB,eAAe,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;CAC5B,WAAW,EAAE,OAAO,CAAC,CAAC,cAAc;AACtC,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAiBH,MAAa,gBAA0C,EACpD,OAAO;CACN,YAAY,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;CAC5B,WAAW,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;CACxB,UAAU,EAAE,OAAO;EAAE,aAAa,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;EAAG,QAAQ,OAAO;CAAO,CAAC,CAAC,CAAC,cAAc;AAC9F,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aACE;AACJ,CAAC"}
|
package/dist/view.d.ts
CHANGED
package/dist/view.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { wireRegistry } from "./wire-registry.js";
|
|
2
2
|
import { ArtifactId, VersionId, ViewId } from "./ids.js";
|
|
3
|
-
import { SubmissionPolicy } from "./
|
|
3
|
+
import { SubmissionPolicy } from "./policy.js";
|
|
4
4
|
import * as z from "zod";
|
|
5
5
|
//#region src/view.ts
|
|
6
6
|
/**
|
package/dist/view.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"view.js","names":[],"sources":["../src/view.ts"],"sourcesContent":["/**\n * What one view is (D104, D108): its artifact, version, policy, submit channels and trusted\n * controls. The browser protocol's frame ticket, the bridge's `ui/initialize` result and the\n * interaction core's channel policy share these shapes, so they live in a module of their own:\n * the bridge, which every version embeds, imports them without the interaction schemas.\n */\nimport * as z from \"zod\";\nimport { ArtifactId, VersionId, ViewId } from \"./ids.ts\";\nimport { SubmissionPolicy } from \"./manifest.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** Where a submit came from (D40). */\nexport type SubmitChannel = \"shell\" | \"artifact\";\n\n/** The Zod schema of the `SubmitChannel` type. */\nexport const SubmitChannel: z.ZodType<SubmitChannel> = z\n .enum([\"shell\", \"artifact\"])\n .register(wireRegistry, {\n id: \"SubmitChannel\",\n description: \"Where a submit comes from: the shell's trusted Submit, or the artifact's code.\",\n });\n\n/**\n * A trusted control the shell renders outside the artifact's frame (D06, PRODUCT vocabulary):\n * Submit, Choose (review sets) and Approve. Open for later controls on the wire.\n */\nexport type TrustedControl = \"submit\" | \"choose\" | \"approve\" | (string & {});\n\n/** The Zod schema of the `TrustedControl` type. */\nexport const TrustedControl: z.ZodType<TrustedControl> = z\n .string()\n .regex(/^[a-z][a-z0-9-]{0,31}$/)\n .register(wireRegistry, {\n id: \"TrustedControl\",\n description: \"A trusted control the shell renders: submit, choose, approve; open for more.\",\n });\n\n/**\n * Which submit channels a view accepts and which trusted controls its shell renders (D40, D108):\n * the `trustedControls` port's answer, or the home's `HomeConfig.submitChannels`.\n */\nexport interface ControlsPolicy {\n /** The channels submissions may come through; at least one. */\n readonly submitChannels: readonly SubmitChannel[];\n /** The trusted controls the shell may render; absent: every control the artifact asks for. */\n readonly controls?: readonly TrustedControl[];\n}\n\n/** The Zod schema of the `ControlsPolicy` type. */\nexport const ControlsPolicy: z.ZodType<ControlsPolicy> = z\n .object({\n submitChannels: z.array(SubmitChannel).min(1).max(2).readonly(),\n controls: z.array(TrustedControl).max(32).readonly().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"ControlsPolicy\",\n description:\n \"Which submit channels a view accepts and which trusted controls its shell renders (D108).\",\n });\n\n/** A review set's ID: letters, digits, `_` and `-` (its choice is the field `review.<id>.choice`). */\nexport const REVIEW_SET_ID_PATTERN: RegExp = /^[A-Za-z0-9_-]{1,64}$/;\n\n/** Where a client runtime runs (D111): Mostra's gateway, a static export, an MCP App, or `verify`. */\nexport type DeliveryTarget = \"live\" | \"static\" | \"mcp-app\" | \"verify\";\n\n/** A version by ID and number. */\nexport interface VersionRef {\n /** The version's ID. */\n readonly id: string;\n /** Its number, for people. */\n readonly number: number;\n}\n\n/** The Zod schema of the `VersionRef` type. */\nexport const VersionRef: z.ZodType<VersionRef> = z\n .object({ id: VersionId.schema, number: z.int().min(1) })\n .register(wireRegistry, {\n id: \"VersionRef\",\n description: \"A version by ID and number.\",\n });\n\n/**\n * What one view is (D104, D108): the shell learns it from its frame ticket and hands it to the\n * frame in `ui/initialize`'s result, so the client runtime names the view in every request and\n * knows what the host allows.\n */\nexport interface ViewContext {\n /** The artifact. */\n readonly artifactId: string;\n /** The view this frame load is; every mutation and submit names it (D104). */\n readonly viewId: string;\n /** The version the view shows. */\n readonly version: VersionRef;\n /** The artifact's latest version when the view opened. */\n readonly latest: VersionRef;\n /** The submission policy in force (D102). */\n readonly policy: SubmissionPolicy;\n /** The submit channels this view accepts (D108). */\n readonly submitChannels: readonly SubmitChannel[];\n /** The trusted controls the shell renders for this view (D108). */\n readonly controls: readonly TrustedControl[];\n /** Always `live` in a frame Mostra's shell hosts. */\n readonly target: DeliveryTarget;\n}\n\n/** The Zod schema of the `ViewContext` type. */\nexport const ViewContext: z.ZodType<ViewContext> = 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 })\n .register(wireRegistry, {\n id: \"ViewContext\",\n description:\n \"What one view is: its artifact, view ID, version, latest version, policy, channels and controls.\",\n });\n\n/**\n * A view as a page reads it from `ui/initialize` (Claude review finding 5): every published\n * version embeds the page's reader, so it takes values a later Mostra may add (a channel, a\n * policy, a target) without refusing the whole view; {@link readViewContext} reads them safely.\n */\nexport interface ViewContextWire {\n /** The artifact. */\n readonly artifactId: string;\n /** The view this frame load is (D104). */\n readonly viewId: string;\n /** The version the view shows. */\n readonly version: VersionRef;\n /** The artifact's latest version when the view opened. */\n readonly latest: VersionRef;\n /** The submission policy in force (D102); a later policy or scope is read as `once` per viewer. */\n readonly policy: {\n /** `once`, `epochs`, `none`, or one a later release adds. */\n readonly policy: string;\n /** `per-artifact` or `per-viewer` under `once`, or one a later release adds. */\n readonly scope?: string;\n };\n /** The submit channels the view accepts (D108); channels this release doesn't know are not allowed. */\n readonly submitChannels: readonly string[];\n /** The trusted controls the shell renders for the view (D108). */\n readonly controls: readonly string[];\n /** Where the page runs (D111); a target this release doesn't know is read as `live`. */\n readonly target: string;\n}\n\n/** The Zod schema of the `ViewContextWire` type: open where later revisions may add values. */\nexport const ViewContextWire: z.ZodType<ViewContextWire> = z.looseObject({\n artifactId: ArtifactId.schema,\n viewId: ViewId.schema,\n version: VersionRef,\n latest: VersionRef,\n policy: z.looseObject({ policy: z.string(), scope: z.string().exactOptional() }),\n submitChannels: z.array(z.string()).max(16).readonly(),\n controls: z.array(z.string()).max(32).readonly(),\n target: z.string(),\n}) as z.ZodType<ViewContextWire>;\n\nconst CONTROL_NAME = /^[a-z][a-z0-9-]{0,31}$/;\n\n/**\n * The view a page acts on, with every value this release doesn't know read the safe way: an\n * unknown channel isn't allowed (the shell's stays), an unknown policy or `once` scope is read as\n * `once` per viewer (the page may submit and the server decides; it closes on its own submission\n * only), and an unknown target as `live`.\n */\nexport function readViewContext(wire: ViewContextWire): ViewContext {\n const channels = ([\"shell\", \"artifact\"] as const).filter((channel) =>\n wire.submitChannels.includes(channel),\n );\n const { policy: name, scope } = wire.policy;\n const policy: SubmissionPolicy =\n name === \"none\"\n ? { policy: \"none\" }\n : name === \"epochs\"\n ? { policy: \"epochs\" }\n : name === \"once\" && (scope === undefined || scope === \"per-artifact\")\n ? { policy: \"once\", scope: \"per-artifact\" }\n : { policy: \"once\", scope: \"per-viewer\" };\n const target = ([\"live\", \"static\", \"mcp-app\", \"verify\"] as const).find(\n (known) => known === wire.target,\n );\n return {\n artifactId: wire.artifactId,\n viewId: wire.viewId,\n version: wire.version,\n latest: wire.latest,\n policy,\n submitChannels: channels.length > 0 ? channels : [\"shell\"],\n controls: wire.controls.filter((control) => CONTROL_NAME.test(control)),\n target: target ?? \"live\",\n };\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,gBAA0C,EACpD,KAAK,CAAC,SAAS,UAAU,CAAC,CAAC,CAC3B,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AASH,MAAa,iBAA4C,EACtD,OAAO,CAAC,CACR,MAAM,wBAAwB,CAAC,CAC/B,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAcH,MAAa,iBAA4C,EACtD,OAAO;CACN,gBAAgB,EAAE,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;CAC9D,UAAU,EAAE,MAAM,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc;AACrE,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aACE;AACJ,CAAC;;AAGH,MAAa,wBAAgC;;AAc7C,MAAa,aAAoC,EAC9C,OAAO;CAAE,IAAI,UAAU;CAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;AAAE,CAAC,CAAC,CACxD,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AA2BH,MAAa,cAAsC,EAChD,OAAO;CACN,YAAY,WAAW;CACvB,QAAQ,OAAO;CACf,SAAS;CACT,QAAQ;CACR,QAAQ;CACR,gBAAgB,EAAE,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;CAC9D,UAAU,EAAE,MAAM,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS;CACnD,QAAQ,EAAE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B;AACF"}
|
|
1
|
+
{"version":3,"file":"view.js","names":[],"sources":["../src/view.ts"],"sourcesContent":["/**\n * What one view is (D104, D108): its artifact, version, policy, submit channels and trusted\n * controls. The browser protocol's frame ticket, the bridge's `ui/initialize` result and the\n * interaction core's channel policy share these shapes, so they live in a module of their own:\n * the bridge, which every version embeds, imports them without the interaction schemas.\n */\nimport * as z from \"zod\";\nimport { ArtifactId, VersionId, ViewId } from \"./ids.ts\";\nimport { SubmissionPolicy } from \"./policy.ts\";\nimport { wireRegistry } from \"./wire-registry.ts\";\n\n/** Where a submit came from (D40). */\nexport type SubmitChannel = \"shell\" | \"artifact\";\n\n/** The Zod schema of the `SubmitChannel` type. */\nexport const SubmitChannel: z.ZodType<SubmitChannel> = z\n .enum([\"shell\", \"artifact\"])\n .register(wireRegistry, {\n id: \"SubmitChannel\",\n description: \"Where a submit comes from: the shell's trusted Submit, or the artifact's code.\",\n });\n\n/**\n * A trusted control the shell renders outside the artifact's frame (D06, PRODUCT vocabulary):\n * Submit, Choose (review sets) and Approve. Open for later controls on the wire.\n */\nexport type TrustedControl = \"submit\" | \"choose\" | \"approve\" | (string & {});\n\n/** The Zod schema of the `TrustedControl` type. */\nexport const TrustedControl: z.ZodType<TrustedControl> = z\n .string()\n .regex(/^[a-z][a-z0-9-]{0,31}$/)\n .register(wireRegistry, {\n id: \"TrustedControl\",\n description: \"A trusted control the shell renders: submit, choose, approve; open for more.\",\n });\n\n/**\n * Which submit channels a view accepts and which trusted controls its shell renders (D40, D108):\n * the `trustedControls` port's answer, or the home's `HomeConfig.submitChannels`.\n */\nexport interface ControlsPolicy {\n /** The channels submissions may come through; at least one. */\n readonly submitChannels: readonly SubmitChannel[];\n /** The trusted controls the shell may render; absent: every control the artifact asks for. */\n readonly controls?: readonly TrustedControl[];\n}\n\n/** The Zod schema of the `ControlsPolicy` type. */\nexport const ControlsPolicy: z.ZodType<ControlsPolicy> = z\n .object({\n submitChannels: z.array(SubmitChannel).min(1).max(2).readonly(),\n controls: z.array(TrustedControl).max(32).readonly().exactOptional(),\n })\n .register(wireRegistry, {\n id: \"ControlsPolicy\",\n description:\n \"Which submit channels a view accepts and which trusted controls its shell renders (D108).\",\n });\n\n/** A review set's ID: letters, digits, `_` and `-` (its choice is the field `review.<id>.choice`). */\nexport const REVIEW_SET_ID_PATTERN: RegExp = /^[A-Za-z0-9_-]{1,64}$/;\n\n/** Where a client runtime runs (D111): Mostra's gateway, a static export, an MCP App, or `verify`. */\nexport type DeliveryTarget = \"live\" | \"static\" | \"mcp-app\" | \"verify\";\n\n/** A version by ID and number. */\nexport interface VersionRef {\n /** The version's ID. */\n readonly id: string;\n /** Its number, for people. */\n readonly number: number;\n}\n\n/** The Zod schema of the `VersionRef` type. */\nexport const VersionRef: z.ZodType<VersionRef> = z\n .object({ id: VersionId.schema, number: z.int().min(1) })\n .register(wireRegistry, {\n id: \"VersionRef\",\n description: \"A version by ID and number.\",\n });\n\n/**\n * What one view is (D104, D108): the shell learns it from its frame ticket and hands it to the\n * frame in `ui/initialize`'s result, so the client runtime names the view in every request and\n * knows what the host allows.\n */\nexport interface ViewContext {\n /** The artifact. */\n readonly artifactId: string;\n /** The view this frame load is; every mutation and submit names it (D104). */\n readonly viewId: string;\n /** The version the view shows. */\n readonly version: VersionRef;\n /** The artifact's latest version when the view opened. */\n readonly latest: VersionRef;\n /** The submission policy in force (D102). */\n readonly policy: SubmissionPolicy;\n /** The submit channels this view accepts (D108). */\n readonly submitChannels: readonly SubmitChannel[];\n /** The trusted controls the shell renders for this view (D108). */\n readonly controls: readonly TrustedControl[];\n /** Always `live` in a frame Mostra's shell hosts. */\n readonly target: DeliveryTarget;\n}\n\n/** The Zod schema of the `ViewContext` type. */\nexport const ViewContext: z.ZodType<ViewContext> = 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 })\n .register(wireRegistry, {\n id: \"ViewContext\",\n description:\n \"What one view is: its artifact, view ID, version, latest version, policy, channels and controls.\",\n });\n\n/**\n * A view as a page reads it from `ui/initialize` (Claude review finding 5): every published\n * version embeds the page's reader, so it takes values a later Mostra may add (a channel, a\n * policy, a target) without refusing the whole view; {@link readViewContext} reads them safely.\n */\nexport interface ViewContextWire {\n /** The artifact. */\n readonly artifactId: string;\n /** The view this frame load is (D104). */\n readonly viewId: string;\n /** The version the view shows. */\n readonly version: VersionRef;\n /** The artifact's latest version when the view opened. */\n readonly latest: VersionRef;\n /** The submission policy in force (D102); a later policy or scope is read as `once` per viewer. */\n readonly policy: {\n /** `once`, `epochs`, `none`, or one a later release adds. */\n readonly policy: string;\n /** `per-artifact` or `per-viewer` under `once`, or one a later release adds. */\n readonly scope?: string;\n };\n /** The submit channels the view accepts (D108); channels this release doesn't know are not allowed. */\n readonly submitChannels: readonly string[];\n /** The trusted controls the shell renders for the view (D108). */\n readonly controls: readonly string[];\n /** Where the page runs (D111); a target this release doesn't know is read as `live`. */\n readonly target: string;\n}\n\n/** The Zod schema of the `ViewContextWire` type: open where later revisions may add values. */\nexport const ViewContextWire: z.ZodType<ViewContextWire> = z.looseObject({\n artifactId: ArtifactId.schema,\n viewId: ViewId.schema,\n version: VersionRef,\n latest: VersionRef,\n policy: z.looseObject({ policy: z.string(), scope: z.string().exactOptional() }),\n submitChannels: z.array(z.string()).max(16).readonly(),\n controls: z.array(z.string()).max(32).readonly(),\n target: z.string(),\n}) as z.ZodType<ViewContextWire>;\n\nconst CONTROL_NAME = /^[a-z][a-z0-9-]{0,31}$/;\n\n/**\n * The view a page acts on, with every value this release doesn't know read the safe way: an\n * unknown channel isn't allowed (the shell's stays), an unknown policy or `once` scope is read as\n * `once` per viewer (the page may submit and the server decides; it closes on its own submission\n * only), and an unknown target as `live`.\n */\nexport function readViewContext(wire: ViewContextWire): ViewContext {\n const channels = ([\"shell\", \"artifact\"] as const).filter((channel) =>\n wire.submitChannels.includes(channel),\n );\n const { policy: name, scope } = wire.policy;\n const policy: SubmissionPolicy =\n name === \"none\"\n ? { policy: \"none\" }\n : name === \"epochs\"\n ? { policy: \"epochs\" }\n : name === \"once\" && (scope === undefined || scope === \"per-artifact\")\n ? { policy: \"once\", scope: \"per-artifact\" }\n : { policy: \"once\", scope: \"per-viewer\" };\n const target = ([\"live\", \"static\", \"mcp-app\", \"verify\"] as const).find(\n (known) => known === wire.target,\n );\n return {\n artifactId: wire.artifactId,\n viewId: wire.viewId,\n version: wire.version,\n latest: wire.latest,\n policy,\n submitChannels: channels.length > 0 ? channels : [\"shell\"],\n controls: wire.controls.filter((control) => CONTROL_NAME.test(control)),\n target: target ?? \"live\",\n };\n}\n"],"mappings":";;;;;;;;;;;;AAeA,MAAa,gBAA0C,EACpD,KAAK,CAAC,SAAS,UAAU,CAAC,CAAC,CAC3B,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AASH,MAAa,iBAA4C,EACtD,OAAO,CAAC,CACR,MAAM,wBAAwB,CAAC,CAC/B,SAAS,cAAc;CACtB,IAAI;CACJ,aAAa;AACf,CAAC;;AAcH,MAAa,iBAA4C,EACtD,OAAO;CACN,gBAAgB,EAAE,MAAM,aAAa,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS;CAC9D,UAAU,EAAE,MAAM,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc;AACrE,CAAC,CAAC,CACD,SAAS,cAAc;CACtB,IAAI;CACJ,aACE;AACJ,CAAC;;AAGH,MAAa,wBAAgC;;AAc7C,MAAa,aAAoC,EAC9C,OAAO;CAAE,IAAI,UAAU;CAAQ,QAAQ,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC;AAAE,CAAC,CAAC,CACxD,SAAS,cAAc;CACtB,IAAI;CACJ,aA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AAM,SAAU;EAAC;EAAQ;EAAU;EAAW;CAAQ,CAAC,CAAW,MAC/D,UAAU,UAAU,KAAK,MAC5B;CACA,OAAO;EACL,YAAY,KAAK;EACjB,QAAQ,KAAK;EACb,SAAS,KAAK;EACd,QAAQ,KAAK;EACb;EACA,gBAAgB,SAAS,SAAS,IAAI,WAAW,CAAC,OAAO;EACzD,UAAU,KAAK,SAAS,QAAQ,YAAY,aAAa,KAAK,OAAO,CAAC;EACtE,QAAQ,UAAU;CACpB;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mostra/protocol",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "Mostra's shared protocol vocabulary: IDs, dated revisions and diagnostics, with Zod schemas and generated JSON Schema.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "The Mostra Authors",
|
|
@@ -26,6 +26,11 @@
|
|
|
26
26
|
"types": "./dist/index.d.ts",
|
|
27
27
|
"default": "./dist/index.js"
|
|
28
28
|
},
|
|
29
|
+
"./operator": {
|
|
30
|
+
"@mostra/source": "./src/operator.ts",
|
|
31
|
+
"types": "./dist/operator.d.ts",
|
|
32
|
+
"default": "./dist/operator.js"
|
|
33
|
+
},
|
|
29
34
|
"./schemas/*": "./schemas/*",
|
|
30
35
|
"./package.json": "./package.json"
|
|
31
36
|
},
|
|
@@ -66,7 +71,7 @@
|
|
|
66
71
|
"ignore": [
|
|
67
72
|
"zod"
|
|
68
73
|
],
|
|
69
|
-
"limit": "
|
|
74
|
+
"limit": "60 kB"
|
|
70
75
|
},
|
|
71
76
|
{
|
|
72
77
|
"name": "@mostra/protocol JSON-RPC core (D83, zod excluded)",
|
|
@@ -105,6 +110,11 @@
|
|
|
105
110
|
"limit": "5 kB"
|
|
106
111
|
}
|
|
107
112
|
],
|
|
113
|
+
"mostra": {
|
|
114
|
+
"apiReports": [
|
|
115
|
+
"./operator"
|
|
116
|
+
]
|
|
117
|
+
},
|
|
108
118
|
"scripts": {
|
|
109
119
|
"build": "tsdown",
|
|
110
120
|
"typecheck": "tsc -b",
|