@mostra/runtime 0.10.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/bin.js +4058 -310
- package/dist/bin.js.map +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{instance-FExcyENK.js → instance-DCiUHvgZ.js} +682 -47
- package/dist/instance-DCiUHvgZ.js.map +1 -0
- package/dist/reference/cli.md +1322 -0
- package/dist/reference/diagnostics.json +1552 -0
- package/dist/reference/errors/MOSTRA_A11Y_MINOR.md +23 -0
- package/dist/reference/errors/MOSTRA_A11Y_SERIOUS.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_CANCELLED.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_EVENT_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_EXPORT_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_INTERRUPTED.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_PAUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_RUN_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_THREW.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_TOO_LARGE.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_UNKNOWN_FUNCTION.md +23 -0
- package/dist/reference/errors/MOSTRA_ACTION_UNSERIALIZABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_BUNDLE_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_DIR_NOT_EMPTY.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_ENTRY_AMBIGUOUS.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_ID_DROPPED.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_NO_ENTRY.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_NO_PAGE.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_PATCH_REJECTED.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_PATH_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_SOURCE_UNREADABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_TEMPLATE_UNKNOWN.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_COLLECTED.md +23 -0
- package/dist/reference/errors/MOSTRA_ARTIFACT_VERSION_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_BUILD_CRASHED.md +23 -0
- package/dist/reference/errors/MOSTRA_BUILD_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_BUILD_TIMEOUT.md +23 -0
- package/dist/reference/errors/MOSTRA_BUILD_UNRESOLVED.md +23 -0
- package/dist/reference/errors/MOSTRA_CLI_CONFIG_UNWRITABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_CLI_UNKNOWN_COMMAND.md +23 -0
- package/dist/reference/errors/MOSTRA_CLI_USAGE.md +23 -0
- package/dist/reference/errors/MOSTRA_CONSOLE_ERROR.md +23 -0
- package/dist/reference/errors/MOSTRA_CONSOLE_WARNING.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_INSTALL_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_OFFLINE.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_SPEC_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_TIMEOUT.md +23 -0
- package/dist/reference/errors/MOSTRA_DEP_WARM_CONFLICT.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_BIND_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_BROWSER_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_BUNDLE_DOWNLOAD_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_BUNDLE_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_BUNDLE_UNAVAILABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_HELPER_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_NODE_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_PORT_TAKEN.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_RUNTIME_INSTALLING.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_RUNTIME_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_SERVICE_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_SHELL_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_ENV_WARM_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_CONFLICT.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_DUPLICATE_ID.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_ID_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_ID_UNSTABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_MUTATION_ID_REUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_SHARED.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_TOO_LARGE.md +23 -0
- package/dist/reference/errors/MOSTRA_FIELD_UNBOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_DISK_FULL.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_GC_INCOMPLETE.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_GONE.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_INTEGRITY.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_LEDGER_UNREADABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_LOCKED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_MISMATCH.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_NETWORK_FILESYSTEM.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_NOT_ALWAYS_ON.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_NOT_OWNED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_SOCKET_TOO_LONG.md +23 -0
- package/dist/reference/errors/MOSTRA_HOME_TOO_NEW.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_CONNECTION_CLOSED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_CURSOR_COMPACTED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_IDENTITY_UNAVAILABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_INITIALIZE_ORDER.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_INTERNAL_ERROR.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_INVALID_PARAMS.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_MALFORMED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_MESSAGE_TOO_LARGE.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_METHOD_UNKNOWN.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_NOTIFICATION_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_PORT_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_REQUEST_ID_REUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_REVISION_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_SHUTDOWN_REFUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_SUBSCRIPTION_UNKNOWN.md +23 -0
- package/dist/reference/errors/MOSTRA_HOST_TIMEOUT.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_CONTENT_TYPE.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_CSRF_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_FRAME_SESSION.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_HEADERS_TOO_LARGE.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_HOST_REFUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_NOT_SERVED.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_ORIGIN_REFUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_RATE_LIMITED.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_REQUEST_MALFORMED.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_SCOPE_DENIED.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_CONFLICT.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_SESSION_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_HYGIENE_TOKEN_REVOKED.md +23 -0
- package/dist/reference/errors/MOSTRA_LIVE_SOURCE_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_LIVE_TOO_LARGE.md +23 -0
- package/dist/reference/errors/MOSTRA_MANIFEST_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_MANIFEST_NOT_LITERAL.md +23 -0
- package/dist/reference/errors/MOSTRA_MANIFEST_UNKNOWN_KEY.md +23 -0
- package/dist/reference/errors/MOSTRA_NETWORK_EXTERNAL_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_NETWORK_REQUEST_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_PLATFORM_UNSUPPORTED.md +23 -0
- package/dist/reference/errors/MOSTRA_PUBLISH_ID_CONFLICT.md +23 -0
- package/dist/reference/errors/MOSTRA_PUBLISH_SOURCE_CHANGED.md +23 -0
- package/dist/reference/errors/MOSTRA_PUBLISH_VERIFY_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_REGRESSION_ACTION_REMOVED.md +23 -0
- package/dist/reference/errors/MOSTRA_REGRESSION_ARIA.md +23 -0
- package/dist/reference/errors/MOSTRA_REGRESSION_FIELD_REMOVED.md +23 -0
- package/dist/reference/errors/MOSTRA_REGRESSION_LIVE_REMOVED.md +23 -0
- package/dist/reference/errors/MOSTRA_REGRESSION_PAGE_REMOVED.md +23 -0
- package/dist/reference/errors/MOSTRA_REGRESSION_PIXELS.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_CONFIG_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_HOME_MOVING.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_HOME_SUSPENDED.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_LIMIT_REACHED.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_LOGIN_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_NOT_OWNER_INSTANCE.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_NO_INSTANCE.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_OPERATOR_UNAVAILABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_OWNER_OFFLINE.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_PAUSED_BY_OPERATOR.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_QUEUE_FULL.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_RATE_LIMITED.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_SIGN_IN_REQUIRED.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_UNDER_REVIEW.md +23 -0
- package/dist/reference/errors/MOSTRA_REMOTE_UNREACHABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_RUNTIME_BLANK.md +23 -0
- package/dist/reference/errors/MOSTRA_RUNTIME_NOT_READY.md +23 -0
- package/dist/reference/errors/MOSTRA_RUNTIME_PAGE_ERROR.md +23 -0
- package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_CRASHED.md +23 -0
- package/dist/reference/errors/MOSTRA_RUNTIME_WORKER_PARKED.md +23 -0
- package/dist/reference/errors/MOSTRA_SECRET_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_NOT_ENABLED.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_PORTS_EXHAUSTED.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TOOL_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TOOL_NOT_READY.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TTL_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_SHARE_TUNNEL_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_SMOKE_BUDGET.md +23 -0
- package/dist/reference/errors/MOSTRA_SMOKE_NO_EFFECT.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_ALREADY.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_BLOCKED.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_CHANNEL_DENIED.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_NOT_FOUND.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_PAUSED.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_POLICY_NONE.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_REVISION_MOVED.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_SIGNAL_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_SUBMIT_VIEW_INVALID.md +23 -0
- package/dist/reference/errors/MOSTRA_TARGET_UNAVAILABLE.md +23 -0
- package/dist/reference/errors/MOSTRA_TYPE_ERROR.md +23 -0
- package/dist/reference/errors/MOSTRA_TYPE_UNTYPED_PACKAGE.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_ACTION_SKIPPED.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_BASELINE_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_CRASHED.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_LIVE_FAILED.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_NO_BASELINE.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_SECRET_MISSING.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_SKIP_CONSEQUENCE.md +23 -0
- package/dist/reference/errors/MOSTRA_VERIFY_TIMEOUT.md +23 -0
- package/dist/reference/self-hosting.md +130 -0
- package/dist/reference/telemetry.md +84 -0
- package/dist/skill/SKILL.md +122 -0
- package/dist/skill/assets/examples/dashboard/index.tsx +161 -0
- package/dist/skill/assets/examples/dashboard/live.ts +25 -0
- package/dist/skill/assets/examples/dashboard/styles.css +125 -0
- package/dist/skill/assets/examples/decision/index.tsx +95 -0
- package/dist/skill/assets/examples/decision/styles.css +125 -0
- package/dist/skill/assets/examples/inbox/actions.ts +23 -0
- package/dist/skill/assets/examples/inbox/index.tsx +109 -0
- package/dist/skill/assets/examples/inbox/styles.css +125 -0
- package/dist/skill/assets/studio.css +125 -0
- package/dist/skill/references/answers.md +217 -0
- package/dist/skill/references/design.md +154 -0
- package/dist/skill/references/libraries.md +167 -0
- package/dist/skill/references/long-lived.md +148 -0
- package/dist/skill/references/mcp.md +68 -0
- package/dist/skill/references/page.md +131 -0
- package/dist/skill/references/server.md +146 -0
- package/dist/skill/references/sharing.md +123 -0
- package/dist/skill/references/verify.md +71 -0
- package/package.json +10 -5
- package/src/gateway/actions.ts +20 -0
- package/src/gateway/browser.ts +44 -0
- package/src/gateway/capabilities.ts +8 -0
- package/src/gateway/http.ts +12 -1
- package/src/gateway/index.ts +170 -5
- package/src/gateway/listener.ts +31 -6
- package/src/gateway/routes.ts +8 -0
- package/src/gc/index.ts +5 -0
- package/src/instance/index.ts +20 -1
- package/src/interaction/index.ts +60 -0
- package/src/interaction/pause.ts +106 -0
- package/src/interaction/submissions.ts +42 -1
- package/src/interaction/viewers.ts +34 -1
- package/src/ledger/index.ts +20 -1
- package/src/ledger/migrations.ts +51 -0
- package/src/link/author.ts +215 -0
- package/src/link/hosted.ts +37 -1
- package/src/link/http.ts +6 -1
- package/src/link/index.ts +3 -1
- package/src/link/manager.ts +138 -34
- package/src/protocol-server/client.ts +53 -0
- package/src/protocol-server/index.ts +1 -1
- package/src/server/api.ts +514 -72
- package/src/server/auth.ts +600 -74
- package/src/server/authorize.ts +816 -0
- package/src/server/clients.ts +235 -0
- package/src/server/config.ts +7 -0
- package/src/server/data.ts +59 -1
- package/src/server/directory.ts +69 -0
- package/src/server/feed.ts +191 -0
- package/src/server/handle.ts +172 -0
- package/src/server/hosted-pages.ts +532 -0
- package/src/server/hosted.ts +519 -18
- package/src/server/index.ts +343 -61
- package/src/server/mcp.ts +330 -0
- package/src/server/metering.ts +156 -0
- package/src/server/oauth-clients.ts +510 -0
- package/src/server/operator.ts +498 -0
- package/src/server/providers.ts +284 -0
- package/src/server/remove.ts +148 -0
- package/src/server/routing.ts +275 -0
- package/src/verify/runner.ts +23 -2
- package/dist/instance-FExcyENK.js.map +0 -1
package/src/gateway/index.ts
CHANGED
|
@@ -44,6 +44,7 @@ import {
|
|
|
44
44
|
FRAME_SESSION_HEADER,
|
|
45
45
|
type FrameSessionFacts,
|
|
46
46
|
type FrameTicket,
|
|
47
|
+
type HostedChrome,
|
|
47
48
|
type IdentityVia,
|
|
48
49
|
type PortAddressingExternalBaseResult,
|
|
49
50
|
type Refusal,
|
|
@@ -97,6 +98,9 @@ import {
|
|
|
97
98
|
import { type IdentityOutcome, tailnetPerson } from "./identity.ts";
|
|
98
99
|
import { versionIntegrity } from "./integrity.ts";
|
|
99
100
|
import { createListener, type Listener } from "./listener.ts";
|
|
101
|
+
|
|
102
|
+
export { resetOnClose } from "./listener.ts";
|
|
103
|
+
|
|
100
104
|
import { type ListenerChecks, mount, type RouteContext, type RouteSpec, refuse } from "./routes.ts";
|
|
101
105
|
import { fileResponse, findFile } from "./serve.ts";
|
|
102
106
|
import { BOOTSTRAP_PAGE, SERVICE_WORKER_PATH, SERVICE_WORKER_SOURCE } from "./worker.ts";
|
|
@@ -104,7 +108,9 @@ import { BOOTSTRAP_PAGE, SERVICE_WORKER_PATH, SERVICE_WORKER_SOURCE } from "./wo
|
|
|
104
108
|
export { Capabilities, capabilityKey } from "./capabilities.ts";
|
|
105
109
|
export { CONTROLS_POLICY_TIMEOUT_MS, controlsPolicy } from "./controls.ts";
|
|
106
110
|
export type { DevUpstream } from "./dev.ts";
|
|
111
|
+
export { BASE_HEADERS, documentHeaders, isRefusal, jsonResponse, readJsonObject } from "./http.ts";
|
|
107
112
|
export { IDENTITY_TIMEOUT_MS, resolveIdentity } from "./identity.ts";
|
|
113
|
+
export type { RouteContext, RouteSpec } from "./routes.ts";
|
|
108
114
|
|
|
109
115
|
/** What the gateway reads about artifacts and versions. */
|
|
110
116
|
export interface GatewayArtifacts {
|
|
@@ -255,6 +261,59 @@ export interface HostedAddressing {
|
|
|
255
261
|
readonly shellPath: (artifactId: string) => string;
|
|
256
262
|
/** The origin of an artifact's frames beside a domain's shell: its route's label there. */
|
|
257
263
|
readonly artifactOrigin: (artifactId: string, shellOrigin: string) => string | undefined;
|
|
264
|
+
/** The client's address of a request, through the server's trusted proxies (D165 item 13). */
|
|
265
|
+
readonly client?: (incoming: IncomingMessage) => string | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* The shell origin a new link of an artifact is minted on (an operator's host for it, D167), or
|
|
268
|
+
* `undefined` for the active domain's apex.
|
|
269
|
+
*/
|
|
270
|
+
readonly linkOrigin?: (artifactId: string) => Promise<string | undefined>;
|
|
271
|
+
/**
|
|
272
|
+
* The shells that may frame an artifact's documents at a frame origin: the apex of the domain the
|
|
273
|
+
* frame is served on, and the operator hosts that serve the route's shell with frames there
|
|
274
|
+
* (D167). Space-separated origins, for `frame-ancestors`.
|
|
275
|
+
*/
|
|
276
|
+
readonly frameAncestors?: (artifactId: string, frameOrigin: string) => string;
|
|
277
|
+
/**
|
|
278
|
+
* Who a browser is that exchanges a link minted without a viewer (D165 item 8): an anonymous
|
|
279
|
+
* viewer per browser, by the route's derived key (`browser`), or a fresh one when the shell
|
|
280
|
+
* sent none. Sign-in turns a session's viewer into its account's later.
|
|
281
|
+
*/
|
|
282
|
+
readonly anonymousViewer?: (browser: string | undefined) => string;
|
|
283
|
+
/**
|
|
284
|
+
* Before a view's frame ticket (WP-30): a quarantined route or version shows the neutral "under
|
|
285
|
+
* review" page, and the operator's `limits` may refuse a view. A refusal, or nothing.
|
|
286
|
+
*/
|
|
287
|
+
readonly admitView?: (input: {
|
|
288
|
+
readonly artifactId: string;
|
|
289
|
+
readonly versionId: string;
|
|
290
|
+
readonly tokenId: string;
|
|
291
|
+
readonly client: string | undefined;
|
|
292
|
+
}) => Promise<(Refusal & { readonly retryAfter?: number }) | undefined>;
|
|
293
|
+
/** A version whose files are withheld now (a quarantine): refused even to an open frame. */
|
|
294
|
+
readonly blocked?: (artifactId: string, versionId: string) => Refusal | undefined;
|
|
295
|
+
/** The hosted shell's trusted chrome for a view (D161). */
|
|
296
|
+
readonly chrome?: (input: {
|
|
297
|
+
readonly artifactId: string;
|
|
298
|
+
readonly tokenId: string;
|
|
299
|
+
readonly viewerId: string;
|
|
300
|
+
}) => Promise<HostedChrome>;
|
|
301
|
+
/**
|
|
302
|
+
* Before a submit from the shell or the frame (D165 item 13): sign-in when the artifact asks for
|
|
303
|
+
* it, the per-IP and per-link rates, and the operator's `limits`. A refusal, or nothing.
|
|
304
|
+
*/
|
|
305
|
+
readonly admitSubmit?: BrowserRoutesOptions["admitSubmit"];
|
|
306
|
+
/** Shell routes of a hosted home of its own (sign-in, the report control, a viewer's name). */
|
|
307
|
+
readonly shellRoutes?: (helpers: HostedRouteHelpers) => readonly RouteSpec[];
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/** What a hosted home's own shell routes may use of the gateway. */
|
|
311
|
+
export interface HostedRouteHelpers {
|
|
312
|
+
/** Turns a refusal into the answer every route gives. */
|
|
313
|
+
readonly refuse: (
|
|
314
|
+
refused: Refusal & { readonly retryAfter?: number },
|
|
315
|
+
request: { readonly method: string; readonly path: string; readonly document: boolean },
|
|
316
|
+
) => Response;
|
|
258
317
|
}
|
|
259
318
|
|
|
260
319
|
/** The gateway of one instance. */
|
|
@@ -489,6 +548,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
489
548
|
: undefined;
|
|
490
549
|
},
|
|
491
550
|
activated: options.activated,
|
|
551
|
+
...(options.hosted?.admitSubmit ? { admitSubmit: options.hosted.admitSubmit } : {}),
|
|
492
552
|
...(options.revisions ? { revisions: options.revisions } : {}),
|
|
493
553
|
...(options.bus ? { bus: options.bus } : {}),
|
|
494
554
|
});
|
|
@@ -888,6 +948,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
888
948
|
|
|
889
949
|
/** Where an artifact's links point: a host's external base when it gives one, else loopback. */
|
|
890
950
|
const linkBase = async (artifactId: string): Promise<string> => {
|
|
951
|
+
if (hosted?.linkOrigin) return (await hosted.linkOrigin(artifactId)) ?? shellOrigin();
|
|
891
952
|
const face = await hostFace(artifactId, "shell");
|
|
892
953
|
return face?.origin ?? shellOrigin();
|
|
893
954
|
};
|
|
@@ -966,6 +1027,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
966
1027
|
},
|
|
967
1028
|
// The shell's own stream is refused where streams don't pass, as the frame's is (D158 item 5).
|
|
968
1029
|
streams: () => way().streams(),
|
|
1030
|
+
...(hosted?.client ? { client: hosted.client } : {}),
|
|
969
1031
|
});
|
|
970
1032
|
|
|
971
1033
|
const shellMissing = (): Response =>
|
|
@@ -1022,7 +1084,13 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1022
1084
|
const found = await artifactWayFor(way, group, context.artifactId).catch(() => undefined);
|
|
1023
1085
|
frames = found && !isRefusal(found) ? (found.way.origin() ?? "'none'") : "'none'";
|
|
1024
1086
|
}
|
|
1025
|
-
const
|
|
1087
|
+
const file = readFileSync(join(options.shellDir, "index.html"));
|
|
1088
|
+
// A hosted page's link preview is the same for every artifact (D161): an unfurl in a chat
|
|
1089
|
+
// app shows neither its title, text nor images unless its owner opted in to the title.
|
|
1090
|
+
const html =
|
|
1091
|
+
way.by === "hosted"
|
|
1092
|
+
? hostedPreview(file.toString("utf8"), previewTitle(context.artifactId))
|
|
1093
|
+
: file;
|
|
1026
1094
|
return new Response(context.request.method === "HEAD" ? null : html, {
|
|
1027
1095
|
headers: {
|
|
1028
1096
|
...BASE_HEADERS,
|
|
@@ -1033,6 +1101,16 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1033
1101
|
});
|
|
1034
1102
|
};
|
|
1035
1103
|
|
|
1104
|
+
/** The title a hosted page's preview may show: its own only when the manifest asks (D161). */
|
|
1105
|
+
const previewTitle = (artifactId: string): string | undefined => {
|
|
1106
|
+
try {
|
|
1107
|
+
const detail = artifacts.get({ artifactId });
|
|
1108
|
+
return detail.manifest.hosted?.preview === "title" ? detail.title : undefined;
|
|
1109
|
+
} catch {
|
|
1110
|
+
return undefined;
|
|
1111
|
+
}
|
|
1112
|
+
};
|
|
1113
|
+
|
|
1036
1114
|
const shellAsset = async (context: RouteContext): Promise<Response> => {
|
|
1037
1115
|
if (options.shellDir === undefined) return shellMissing();
|
|
1038
1116
|
const url = new URL(context.request.url);
|
|
@@ -1056,8 +1134,16 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1056
1134
|
* 2): the home's local user on loopback; over a tunnel the tailnet person Tailscale Serve
|
|
1057
1135
|
* named, else the link's own viewer, never the home's local user.
|
|
1058
1136
|
*/
|
|
1059
|
-
const defaultViewer = (
|
|
1137
|
+
const defaultViewer = (
|
|
1138
|
+
way: Way,
|
|
1139
|
+
context: RouteContext,
|
|
1140
|
+
grant: Grant,
|
|
1141
|
+
browser: string | undefined,
|
|
1142
|
+
): string | undefined => {
|
|
1060
1143
|
if (way.via === "local") return undefined;
|
|
1144
|
+
// On a remote server, one anonymous viewer per browser, by the route's own key (D165 item 8):
|
|
1145
|
+
// a public page answered by thousands needs one draft per person.
|
|
1146
|
+
if (way.by === "hosted" && hosted?.anonymousViewer) return hosted.anonymousViewer(browser);
|
|
1061
1147
|
if (way.via === "tailnet") {
|
|
1062
1148
|
const person = tailnetPerson(context.request.headers, context.remote);
|
|
1063
1149
|
if (person) return interaction.viewerForTailnet(person);
|
|
@@ -1150,7 +1236,14 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1150
1236
|
viewerId =
|
|
1151
1237
|
outcome.kind === "person"
|
|
1152
1238
|
? interaction.viewerForHost(outcome.viewer)
|
|
1153
|
-
: defaultViewer(
|
|
1239
|
+
: defaultViewer(
|
|
1240
|
+
way,
|
|
1241
|
+
context,
|
|
1242
|
+
grant,
|
|
1243
|
+
typeof body["browser"] === "string" && browser !== undefined
|
|
1244
|
+
? body["browser"]
|
|
1245
|
+
: undefined,
|
|
1246
|
+
);
|
|
1154
1247
|
}
|
|
1155
1248
|
// Everything is judged again after the await, in one synchronous step with the session's
|
|
1156
1249
|
// creation: a link revoked or expired meanwhile gets no session (Opus review of WP-12,
|
|
@@ -1278,6 +1371,17 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1278
1371
|
// A dev preview has no stored build to check: Vite serves the source (D140 item 12).
|
|
1279
1372
|
const damage = options.dev ? undefined : await integrity.check(version.id);
|
|
1280
1373
|
if (damage !== undefined) return damaged(version.number, damage, false, "'none'");
|
|
1374
|
+
// On a remote server: a quarantined route or version, or a view the operator's `limits`
|
|
1375
|
+
// refused, gets no frame; the shell shows why (WP-30).
|
|
1376
|
+
if (hosted?.admitView) {
|
|
1377
|
+
const refused = await hosted.admitView({
|
|
1378
|
+
artifactId,
|
|
1379
|
+
versionId: version.id,
|
|
1380
|
+
tokenId: session.grant.tokenId,
|
|
1381
|
+
client: context.client,
|
|
1382
|
+
});
|
|
1383
|
+
if (refused) return refuse(checks, refused, meta);
|
|
1384
|
+
}
|
|
1281
1385
|
// The frame opens on the artifact's way in this shell's group: its loopback listener, or
|
|
1282
1386
|
// the artifact's face at this address (D158 item 1), in the mode the pair needs (D70).
|
|
1283
1387
|
const found = await artifactWayFor(way, group, artifactId);
|
|
@@ -1297,6 +1401,10 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1297
1401
|
// the channels and controls in force for it (D108).
|
|
1298
1402
|
const controls = await options.controls(detail);
|
|
1299
1403
|
const viewerId = interaction.viewerOf(session.viewerId);
|
|
1404
|
+
const pause = interaction.pauseOf(artifactId);
|
|
1405
|
+
const chrome = hosted?.chrome
|
|
1406
|
+
? await hosted.chrome({ artifactId, tokenId: session.grant.tokenId, viewerId })
|
|
1407
|
+
: undefined;
|
|
1300
1408
|
const viewId = interaction.openView({
|
|
1301
1409
|
artifactId,
|
|
1302
1410
|
versionId: version.id,
|
|
@@ -1331,6 +1439,15 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1331
1439
|
...(options.parked?.(version.id) ? { serverParked: true as const } : {}),
|
|
1332
1440
|
...(options.dev ? { devPreview: true as const } : {}),
|
|
1333
1441
|
...(mode === "worker" ? { mode: "worker" as const } : {}),
|
|
1442
|
+
...(pause
|
|
1443
|
+
? {
|
|
1444
|
+
paused: {
|
|
1445
|
+
by: pause.by,
|
|
1446
|
+
...(pause.reason !== undefined ? { reason: pause.reason } : {}),
|
|
1447
|
+
},
|
|
1448
|
+
}
|
|
1449
|
+
: {}),
|
|
1450
|
+
...(chrome ? { hosted: chrome } : {}),
|
|
1334
1451
|
};
|
|
1335
1452
|
return jsonResponse(answer);
|
|
1336
1453
|
};
|
|
@@ -1428,6 +1545,11 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1428
1545
|
auth: "session",
|
|
1429
1546
|
scope: () => "review",
|
|
1430
1547
|
},
|
|
1548
|
+
// A hosted home's own shell routes (sign-in, the report control, a viewer's name), behind
|
|
1549
|
+
// the same checks as every other route (D96).
|
|
1550
|
+
...(hosted?.shellRoutes?.({
|
|
1551
|
+
refuse: (refused, request) => refuse(checks, refused, request),
|
|
1552
|
+
}) ?? []),
|
|
1431
1553
|
];
|
|
1432
1554
|
};
|
|
1433
1555
|
|
|
@@ -1442,10 +1564,17 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1442
1564
|
capabilities,
|
|
1443
1565
|
log,
|
|
1444
1566
|
cookieName: () => `mostra-${wayOf().port()}`,
|
|
1445
|
-
frameAncestors: () =>
|
|
1567
|
+
frameAncestors: () => {
|
|
1568
|
+
const way = wayOf();
|
|
1569
|
+
if (way.by === "hosted" && hosted?.frameAncestors) {
|
|
1570
|
+
return hosted.frameAncestors(artifactId, way.origin() ?? "") || "'none'";
|
|
1571
|
+
}
|
|
1572
|
+
return shellOf(way, group)?.origin() ?? "'none'";
|
|
1573
|
+
},
|
|
1446
1574
|
artifactOf: () => artifactId,
|
|
1447
1575
|
mode: () => modeOf(wayOf(), group),
|
|
1448
1576
|
streams: () => wayOf().streams(),
|
|
1577
|
+
...(hosted?.client ? { client: hosted.client } : {}),
|
|
1449
1578
|
});
|
|
1450
1579
|
|
|
1451
1580
|
const artifactRoutes = (
|
|
@@ -1455,12 +1584,15 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1455
1584
|
): RouteSpec[] => {
|
|
1456
1585
|
const origin = (): string => wayOf().origin() ?? "";
|
|
1457
1586
|
const shell = (): string => shellOf(wayOf(), group)?.origin() ?? "";
|
|
1587
|
+
const checks = artifactChecks(artifactId, wayOf, group);
|
|
1458
1588
|
const kind = (): ListenerKind => ({
|
|
1459
1589
|
kind: "artifact",
|
|
1460
1590
|
origin: origin(),
|
|
1461
1591
|
shellOrigin: shell(),
|
|
1592
|
+
// A hosted label's documents name exactly the framers its refusals do: its domain's shell,
|
|
1593
|
+
// and the outside hosts an operator serves its shell on (D165 item 7, Opus review of WP-28).
|
|
1594
|
+
...(wayOf().by === "hosted" ? { frameAncestors: checks.frameAncestors() } : {}),
|
|
1462
1595
|
});
|
|
1463
|
-
const checks = artifactChecks(artifactId, wayOf, group);
|
|
1464
1596
|
const mode = (): FrameMode => modeOf(wayOf(), group);
|
|
1465
1597
|
const notServed = (context: RouteContext, message: string): Response =>
|
|
1466
1598
|
refuse(checks, refusal("MOSTRA_HYGIENE_NOT_SERVED", message), {
|
|
@@ -1739,6 +1871,9 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1739
1871
|
// again whenever a file changed since (FAILURE_MODEL §3).
|
|
1740
1872
|
const checked =
|
|
1741
1873
|
file ?? (context.document ? await findFile(root(versionId), "/index.html") : undefined);
|
|
1874
|
+
// A quarantined version's files are withheld even from a frame that entered it before.
|
|
1875
|
+
const withheld = hosted?.blocked?.(artifactId, from);
|
|
1876
|
+
if (withheld) return refuse(checks, withheld, meta);
|
|
1742
1877
|
if (checked) {
|
|
1743
1878
|
const damage = await integrity.serve(from, checked);
|
|
1744
1879
|
if (damage !== undefined) {
|
|
@@ -2218,3 +2353,33 @@ export function locateShell(env: Environment): string | undefined {
|
|
|
2218
2353
|
const dir = env["MOSTRA_SHELL_DIR"] ?? resolve(runtimeRoot(), "..", "shell", "dist");
|
|
2219
2354
|
return existsSync(join(dir, "index.html")) ? dir : undefined;
|
|
2220
2355
|
}
|
|
2356
|
+
|
|
2357
|
+
/** The generic preview of every hosted page (D161): one title, one description, no image. */
|
|
2358
|
+
export const HOSTED_PREVIEW = {
|
|
2359
|
+
title: "A page sent with Mostra",
|
|
2360
|
+
description: "Someone sent you this page. Open it to see it.",
|
|
2361
|
+
} as const;
|
|
2362
|
+
|
|
2363
|
+
/** Text for an HTML attribute or element: nothing a tenant writes is ever markup. */
|
|
2364
|
+
function previewText(text: string): string {
|
|
2365
|
+
return text.replace(/[&<>"']/g, (character) => `&#${character.charCodeAt(0)};`);
|
|
2366
|
+
}
|
|
2367
|
+
|
|
2368
|
+
/**
|
|
2369
|
+
* The hosted shell's page with its link preview (D161): the generic title and description, or
|
|
2370
|
+
* the artifact's title alone when its manifest asks (`hosted.preview: "title"`), never its text or
|
|
2371
|
+
* images, and `noindex`.
|
|
2372
|
+
*/
|
|
2373
|
+
function hostedPreview(html: string, title: string | undefined): string {
|
|
2374
|
+
const shown = previewText(title ?? HOSTED_PREVIEW.title);
|
|
2375
|
+
const description = previewText(HOSTED_PREVIEW.description);
|
|
2376
|
+
const tags = [
|
|
2377
|
+
`<meta name="robots" content="noindex, nofollow">`,
|
|
2378
|
+
`<meta name="description" content="${description}">`,
|
|
2379
|
+
`<meta property="og:title" content="${shown}">`,
|
|
2380
|
+
`<meta property="og:description" content="${description}">`,
|
|
2381
|
+
`<meta property="og:site_name" content="Mostra">`,
|
|
2382
|
+
`<meta name="twitter:card" content="summary">`,
|
|
2383
|
+
].join("\n ");
|
|
2384
|
+
return html.replace(/<title>[^<]*<\/title>/, `<title>${shown}</title>\n ${tags}`);
|
|
2385
|
+
}
|
package/src/gateway/listener.ts
CHANGED
|
@@ -39,6 +39,35 @@ export const MAX_HEADER_SIZE: number = 1024 * 1024;
|
|
|
39
39
|
*/
|
|
40
40
|
export const KEEP_ALIVE_MS: number = 305_000;
|
|
41
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Ends a server's connections when it stops, without leaving them in TIME_WAIT on its side (#132):
|
|
44
|
+
* a connection the server closes first stays in TIME_WAIT on the server's port for minutes, and
|
|
45
|
+
* Windows refuses a browser's next connect from a random local port that meets one of them with
|
|
46
|
+
* `ERR_NO_BUFFER_SPACE`, the more often as a restarted instance listens on the same leased ports
|
|
47
|
+
* (D99). A reset (`SO_LINGER` 0) leaves nothing behind; whatever a stopping server still had on a
|
|
48
|
+
* connection was being cut anyway. Answers the function that stops it.
|
|
49
|
+
*/
|
|
50
|
+
export function resetOnClose(server: Server): () => Promise<void> {
|
|
51
|
+
const sockets = new Set<Socket>();
|
|
52
|
+
server.on("connection", (socket: Socket) => {
|
|
53
|
+
sockets.add(socket);
|
|
54
|
+
socket.once("close", () => sockets.delete(socket));
|
|
55
|
+
});
|
|
56
|
+
return () =>
|
|
57
|
+
new Promise((resolve) => {
|
|
58
|
+
if (!server.listening) return resolve();
|
|
59
|
+
// Before `close()`, which since Node.js 19 ends idle connections itself, with a FIN.
|
|
60
|
+
for (const socket of sockets) {
|
|
61
|
+
if (socket.destroyed) continue;
|
|
62
|
+
if (typeof socket.resetAndDestroy === "function" && socket.readyState === "open") {
|
|
63
|
+
socket.resetAndDestroy();
|
|
64
|
+
} else socket.destroy();
|
|
65
|
+
}
|
|
66
|
+
server.close(() => resolve());
|
|
67
|
+
server.closeAllConnections();
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
/** A listener: its server and its Hono app. */
|
|
43
72
|
export interface Listener {
|
|
44
73
|
readonly server: Server;
|
|
@@ -302,15 +331,11 @@ export function createListener(options: {
|
|
|
302
331
|
// An idle connection waits for its next request without these two limits, which count from a
|
|
303
332
|
// request's first byte.
|
|
304
333
|
server.keepAliveTimeout = KEEP_ALIVE_MS;
|
|
334
|
+
const stop = resetOnClose(server);
|
|
305
335
|
|
|
306
336
|
return {
|
|
307
337
|
server,
|
|
308
338
|
app,
|
|
309
|
-
close:
|
|
310
|
-
new Promise((resolve) => {
|
|
311
|
-
if (!server.listening) return resolve();
|
|
312
|
-
server.close(() => resolve());
|
|
313
|
-
server.closeAllConnections();
|
|
314
|
-
}),
|
|
339
|
+
close: stop,
|
|
315
340
|
};
|
|
316
341
|
}
|
package/src/gateway/routes.ts
CHANGED
|
@@ -75,6 +75,11 @@ export interface RouteContext {
|
|
|
75
75
|
readonly document: boolean;
|
|
76
76
|
/** The address of the connection's peer: on a face, the tunnel's own process (D158 item 2). */
|
|
77
77
|
readonly remote: string | undefined;
|
|
78
|
+
/**
|
|
79
|
+
* The client's address: on a remote server the one its trusted proxies name (the forwarded
|
|
80
|
+
* address read from the right, D165 item 13), elsewhere the connection's peer.
|
|
81
|
+
*/
|
|
82
|
+
readonly client: string | undefined;
|
|
78
83
|
}
|
|
79
84
|
|
|
80
85
|
/** What a listener contributes to every route's checks. */
|
|
@@ -96,6 +101,8 @@ export interface ListenerChecks {
|
|
|
96
101
|
readonly mode?: () => SessionMode;
|
|
97
102
|
/** Whether event streams pass to this listener's browsers; `false` behind a quick tunnel. */
|
|
98
103
|
readonly streams?: () => boolean;
|
|
104
|
+
/** The client's address of a request (a remote server's trusted proxies); default its peer. */
|
|
105
|
+
readonly client?: (incoming: import("node:http").IncomingMessage) => string | undefined;
|
|
99
106
|
}
|
|
100
107
|
|
|
101
108
|
/** Logs a refusal without any of the request's capability material, and answers it. */
|
|
@@ -242,6 +249,7 @@ export function mount(
|
|
|
242
249
|
...(session ? { session } : {}),
|
|
243
250
|
document,
|
|
244
251
|
remote: incoming.socket.remoteAddress,
|
|
252
|
+
client: checks.client ? checks.client(incoming) : incoming.socket.remoteAddress,
|
|
245
253
|
});
|
|
246
254
|
};
|
|
247
255
|
if (route.method === "GET") app.get(route.path, handle);
|
package/src/gc/index.ts
CHANGED
|
@@ -213,6 +213,11 @@ export const EXEMPT_COLUMNS: readonly ExemptColumn[] = [
|
|
|
213
213
|
column: "schema_migration.runtime_version",
|
|
214
214
|
reason: "the runtime release that ran a migration",
|
|
215
215
|
},
|
|
216
|
+
{
|
|
217
|
+
column: "quarantine.version_id",
|
|
218
|
+
reason:
|
|
219
|
+
"an operator's quarantine of a hosted version (WP-30), which withholds it and keeps nothing; a hosted home runs no gc",
|
|
220
|
+
},
|
|
216
221
|
];
|
|
217
222
|
|
|
218
223
|
/** The versions some source keeps. */
|
package/src/instance/index.ts
CHANGED
|
@@ -80,7 +80,14 @@ import {
|
|
|
80
80
|
type Interaction,
|
|
81
81
|
redactEvents,
|
|
82
82
|
} from "../interaction/index.ts";
|
|
83
|
-
import {
|
|
83
|
+
import {
|
|
84
|
+
createLink,
|
|
85
|
+
createOwnerAuthor,
|
|
86
|
+
forwardHosted,
|
|
87
|
+
hostedState,
|
|
88
|
+
type Link,
|
|
89
|
+
pauseHandler,
|
|
90
|
+
} from "../link/index.ts";
|
|
84
91
|
import { createLive, type LatestLive, liveMethods } from "../live/index.ts";
|
|
85
92
|
import type { Environment, Log } from "../log.ts";
|
|
86
93
|
import { helperPath, type LaunchPipe, realPath } from "../platform/index.ts";
|
|
@@ -760,6 +767,16 @@ async function assemble(home: OwnedHome, options: StartInstanceOptions): Promise
|
|
|
760
767
|
actions,
|
|
761
768
|
liveChanged: () => live.reconcile(),
|
|
762
769
|
now: () => Date.now() + clockOffset,
|
|
770
|
+
// Remote MCP's authoring runs here, on this home's own protocol server (D165 item 5).
|
|
771
|
+
author: (from, params) => author(from, params),
|
|
772
|
+
});
|
|
773
|
+
const author = createOwnerAuthor({
|
|
774
|
+
home: home.path,
|
|
775
|
+
env: environment,
|
|
776
|
+
log,
|
|
777
|
+
runtimeVersion: runtimeVersion(),
|
|
778
|
+
protocol: () => server,
|
|
779
|
+
hostedOn: (artifactId) => link.hostedServers(artifactId),
|
|
763
780
|
});
|
|
764
781
|
const stopPushingPublishes = interaction.onPublished((artifactId, versionId) =>
|
|
765
782
|
link.published(artifactId, versionId),
|
|
@@ -881,6 +898,8 @@ async function assemble(home: OwnedHome, options: StartInstanceOptions): Promise
|
|
|
881
898
|
...link.methods(),
|
|
882
899
|
// A hosted artifact's state and live values act on its hosted home (D165 item 1).
|
|
883
900
|
...forwardHosted(link, (ref) => registry.get(canonicalRef(ref)).id, interaction.methods()),
|
|
901
|
+
// Pausing acts here and on every server the artifact is hosted on (D165 item 14).
|
|
902
|
+
pauseHandler(link, (ref) => registry.get(canonicalRef(ref)).id, interaction.pause),
|
|
884
903
|
...secretMethods(secrets, (ref) => registry.get(canonicalRef(ref)).id),
|
|
885
904
|
...gcMethods(
|
|
886
905
|
createGc({
|
package/src/interaction/index.ts
CHANGED
|
@@ -31,6 +31,7 @@ import {
|
|
|
31
31
|
type FieldState,
|
|
32
32
|
MutationId,
|
|
33
33
|
type MutationResult,
|
|
34
|
+
type PausedBy,
|
|
34
35
|
type Results,
|
|
35
36
|
RpcError,
|
|
36
37
|
type RunState,
|
|
@@ -62,6 +63,7 @@ import {
|
|
|
62
63
|
} from "./fields.ts";
|
|
63
64
|
import { type ImportSource, importSubmission } from "./imports.ts";
|
|
64
65
|
import { type HostConnections, Outbox } from "./outbox.ts";
|
|
66
|
+
import { type Pause, pauseOf, setPause } from "./pause.ts";
|
|
65
67
|
import { buildResults, CHOICE, resultsMarkdown, submissionFor } from "./results.ts";
|
|
66
68
|
import {
|
|
67
69
|
appendRunOutput,
|
|
@@ -88,13 +90,17 @@ import {
|
|
|
88
90
|
SubmitConflict,
|
|
89
91
|
submissionSummary,
|
|
90
92
|
submit,
|
|
93
|
+
wouldRecord,
|
|
91
94
|
} from "./submissions.ts";
|
|
92
95
|
import { Subscriptions } from "./subscriptions.ts";
|
|
93
96
|
import {
|
|
94
97
|
localViewerId,
|
|
98
|
+
nameAnonymous,
|
|
95
99
|
openView,
|
|
96
100
|
viewControls,
|
|
97
101
|
viewer,
|
|
102
|
+
viewerForAccount,
|
|
103
|
+
viewerForAnonymous,
|
|
98
104
|
viewerForHost,
|
|
99
105
|
viewerForLink,
|
|
100
106
|
viewerForSpec,
|
|
@@ -191,6 +197,17 @@ export interface Interaction {
|
|
|
191
197
|
/** Stops delivering; pending deliveries stay in the outbox. */
|
|
192
198
|
stop(): void;
|
|
193
199
|
|
|
200
|
+
/**
|
|
201
|
+
* Pauses or resumes an artifact as its owner or its server's operator (D165 item 14, RM-09);
|
|
202
|
+
* the owner resuming an operator's pause is `MOSTRA_REMOTE_PAUSED_BY_OPERATOR`.
|
|
203
|
+
*/
|
|
204
|
+
pause(
|
|
205
|
+
artifactId: string,
|
|
206
|
+
change: { readonly paused: boolean; readonly by: PausedBy; readonly reason?: string },
|
|
207
|
+
): { readonly paused: boolean; readonly by?: PausedBy };
|
|
208
|
+
/** The artifact's pause, or `undefined` when it isn't paused. */
|
|
209
|
+
pauseOf(artifactId: string): Pause | undefined;
|
|
210
|
+
|
|
194
211
|
/** The viewer a capability token's sessions act as (D104): its own, or the home's local user. */
|
|
195
212
|
viewerOf(tokenViewerId: string | undefined): string;
|
|
196
213
|
/** A viewer by ID (D104). */
|
|
@@ -203,6 +220,12 @@ export interface Interaction {
|
|
|
203
220
|
viewerForTailnet(spec: ViewerSpec): string;
|
|
204
221
|
/** A link's own viewer, for a tunnel visitor nobody named (D158 item 2). */
|
|
205
222
|
viewerForLink(tokenId: string, name: string): string;
|
|
223
|
+
/** A signed-in account on a hosted link (D165 item 8), named as its provider verified it. */
|
|
224
|
+
viewerForAccount(accountId: string, name?: string): string;
|
|
225
|
+
/** An anonymous viewer on a hosted link, by the route's derived browser key (D165 item 8). */
|
|
226
|
+
viewerForAnonymous(key: string): string;
|
|
227
|
+
/** Sets an anonymous viewer's self-chosen name, unverified; `false` for any other viewer. */
|
|
228
|
+
nameAnonymous(viewerId: string, name: string | null): boolean;
|
|
206
229
|
/** Records a frame load of a version (D104), with the controls in force (D108); returns its ID. */
|
|
207
230
|
openView(input: {
|
|
208
231
|
readonly artifactId: string;
|
|
@@ -235,6 +258,16 @@ export interface Interaction {
|
|
|
235
258
|
* `hosted/submission`, FAILURE_MODEL §11.2); `undefined` when `owner` has no delivery of it.
|
|
236
259
|
*/
|
|
237
260
|
envelopeFor(submissionId: string, owner: string): SubmissionEnvelope | undefined;
|
|
261
|
+
/** A submission's full Results (§8), built from the immutable submission alone. */
|
|
262
|
+
resultsOf(submissionId: string): Results | undefined;
|
|
263
|
+
/**
|
|
264
|
+
* Whether a page's submit would be judged afresh: not a repeat of a recorded one, not refused by
|
|
265
|
+
* its view or a pause. Only such a submit is admitted by a hosted home's rates and limits.
|
|
266
|
+
*/
|
|
267
|
+
wouldRecord(
|
|
268
|
+
page: PageIdentity,
|
|
269
|
+
input: { readonly viewId: string; readonly expectedRevision: number },
|
|
270
|
+
): boolean;
|
|
238
271
|
/** A viewer's submit (IN-05); `SubmitConflict` under a closed `once`. */
|
|
239
272
|
submit(
|
|
240
273
|
page: PageIdentity,
|
|
@@ -588,6 +621,12 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
588
621
|
viewerForHost: (spec) => ledger.write((db) => viewerForHost(db, spec)),
|
|
589
622
|
viewerForTailnet: (spec) => ledger.write((db) => viewerForTailnet(db, spec)),
|
|
590
623
|
viewerForLink: (tokenId, name) => ledger.write((db) => viewerForLink(db, tokenId, name)),
|
|
624
|
+
viewerForAccount: (accountId, name) =>
|
|
625
|
+
ledger.write((db) => viewerForAccount(db, accountId, name)),
|
|
626
|
+
viewerForAnonymous: (key) => ledger.write((db) => viewerForAnonymous(db, key)),
|
|
627
|
+
nameAnonymous: (viewerId, name) => ledger.write((db) => nameAnonymous(db, viewerId, name)),
|
|
628
|
+
pause: (artifactId, change) => ledger.write((db) => setPause(db, artifactId, change)),
|
|
629
|
+
pauseOf: (artifactId) => ledger.read((db) => pauseOf(db, artifactId)),
|
|
591
630
|
openView(input) {
|
|
592
631
|
return ledger.write((db) => openView(db, input));
|
|
593
632
|
},
|
|
@@ -667,6 +706,15 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
667
706
|
});
|
|
668
707
|
return answer;
|
|
669
708
|
},
|
|
709
|
+
resultsOf(submissionId) {
|
|
710
|
+
return ledger.read((db) => {
|
|
711
|
+
const submission = db.get<SubmissionRow>(
|
|
712
|
+
"SELECT * FROM submission WHERE id = ?",
|
|
713
|
+
submissionId,
|
|
714
|
+
);
|
|
715
|
+
return submission ? buildResults(db, submission) : undefined;
|
|
716
|
+
});
|
|
717
|
+
},
|
|
670
718
|
envelopeFor(submissionId, owner) {
|
|
671
719
|
return ledger.read((db) => {
|
|
672
720
|
const delivery = db.get<{ id: string; attempts: number }>(
|
|
@@ -691,6 +739,18 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
691
739
|
};
|
|
692
740
|
});
|
|
693
741
|
},
|
|
742
|
+
wouldRecord(page, input) {
|
|
743
|
+
return ledger.read((db) =>
|
|
744
|
+
wouldRecord(db, {
|
|
745
|
+
artifactId: page.artifactId,
|
|
746
|
+
viewerId: page.viewerId,
|
|
747
|
+
...(page.tokenId !== undefined ? { tokenId: page.tokenId } : {}),
|
|
748
|
+
viewId: input.viewId,
|
|
749
|
+
expectedRevision: input.expectedRevision,
|
|
750
|
+
}),
|
|
751
|
+
);
|
|
752
|
+
},
|
|
753
|
+
|
|
694
754
|
submit(page, input) {
|
|
695
755
|
const owners = options.deliveryOwners?.(page.artifactId) ?? outbox.owners();
|
|
696
756
|
const outcome = asPage(() =>
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pausing an artifact (D165 item 14, RM-09): a paused artifact stays viewable and its shell says
|
|
3
|
+
* so; it takes no submissions (the submit transaction refuses them) and runs no actions until it
|
|
4
|
+
* is resumed, and every draft is kept. The owner pauses and resumes its own pause; an operator's
|
|
5
|
+
* pause is resumed only by the operator. One row per party that paused it (`artifact_pause`,
|
|
6
|
+
* DATA_MODEL §7.2), in local and hosted homes alike; each change appends `artifact.paused` or
|
|
7
|
+
* `artifact.resumed`, so open pages learn of it.
|
|
8
|
+
*/
|
|
9
|
+
import { createDiagnostic, type PausedBy, RpcError } from "@mostra/protocol";
|
|
10
|
+
import type { LedgerDb } from "../ledger/index.ts";
|
|
11
|
+
import { appendEvent } from "./events.ts";
|
|
12
|
+
|
|
13
|
+
/** An artifact's pause, while it is paused. */
|
|
14
|
+
export interface Pause {
|
|
15
|
+
readonly by: PausedBy;
|
|
16
|
+
readonly reason?: string;
|
|
17
|
+
readonly at: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* The artifact's pause, or `undefined` when it isn't paused: the operator's when both paused it,
|
|
22
|
+
* since only the operator lifts that one.
|
|
23
|
+
*/
|
|
24
|
+
export function pauseOf(db: LedgerDb, artifactId: string): Pause | undefined {
|
|
25
|
+
const row = db.get<{ by: PausedBy; reason: string | null; paused_at: string }>(
|
|
26
|
+
"SELECT by, reason, paused_at FROM artifact_pause WHERE artifact_id = ? ORDER BY by = 'operator' DESC LIMIT 1",
|
|
27
|
+
artifactId,
|
|
28
|
+
);
|
|
29
|
+
return row
|
|
30
|
+
? { by: row.by, ...(row.reason !== null ? { reason: row.reason } : {}), at: row.paused_at }
|
|
31
|
+
: undefined;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Pauses or resumes an artifact, in the caller's write transaction, as `by`. The owner's pause and
|
|
36
|
+
* the operator's are kept apart (one row each): pausing again keeps the earlier pause of the same
|
|
37
|
+
* party, and a resume lifts only its own party's, so the artifact takes answers again once no
|
|
38
|
+
* pause is left. The owner resuming while the operator's pause stands is
|
|
39
|
+
* `MOSTRA_REMOTE_PAUSED_BY_OPERATOR`, and changes nothing.
|
|
40
|
+
*/
|
|
41
|
+
export function setPause(
|
|
42
|
+
db: LedgerDb,
|
|
43
|
+
artifactId: string,
|
|
44
|
+
change: { readonly paused: boolean; readonly by: PausedBy; readonly reason?: string },
|
|
45
|
+
): { readonly paused: boolean; readonly by?: PausedBy } {
|
|
46
|
+
const own = db.get<{ by: PausedBy }>(
|
|
47
|
+
"SELECT by FROM artifact_pause WHERE artifact_id = ? AND by = ?",
|
|
48
|
+
artifactId,
|
|
49
|
+
change.by,
|
|
50
|
+
);
|
|
51
|
+
const actor = change.by === "operator" ? { kind: "mostra" as const } : { kind: "agent" as const };
|
|
52
|
+
if (change.paused) {
|
|
53
|
+
if (!own) {
|
|
54
|
+
const before = pauseOf(db, artifactId);
|
|
55
|
+
db.run(
|
|
56
|
+
"INSERT INTO artifact_pause (artifact_id, by, reason, paused_at) VALUES (?, ?, ?, ?)",
|
|
57
|
+
artifactId,
|
|
58
|
+
change.by,
|
|
59
|
+
change.reason ?? null,
|
|
60
|
+
new Date().toISOString(),
|
|
61
|
+
);
|
|
62
|
+
// Open pages learn of a change they can see: a first pause, or the operator's over the owner's.
|
|
63
|
+
if (before === undefined || change.by === "operator") {
|
|
64
|
+
appendEvent(db, {
|
|
65
|
+
artifactId,
|
|
66
|
+
type: "artifact.paused",
|
|
67
|
+
actor,
|
|
68
|
+
payload: {
|
|
69
|
+
by: change.by,
|
|
70
|
+
...(change.reason !== undefined ? { reason: change.reason } : {}),
|
|
71
|
+
},
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
const now = pauseOf(db, artifactId) as Pause;
|
|
76
|
+
return { paused: true, by: now.by };
|
|
77
|
+
}
|
|
78
|
+
// The owner can't lift a pause while the operator's stands: nothing changes, its own included.
|
|
79
|
+
if (change.by === "owner" && pauseOf(db, artifactId)?.by === "operator") {
|
|
80
|
+
throw new RpcError(
|
|
81
|
+
createDiagnostic("MOSTRA_REMOTE_PAUSED_BY_OPERATOR", {
|
|
82
|
+
message: "The server's operator paused this artifact; only the operator resumes it.",
|
|
83
|
+
}),
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
if (own) {
|
|
87
|
+
db.run("DELETE FROM artifact_pause WHERE artifact_id = ? AND by = ?", artifactId, change.by);
|
|
88
|
+
}
|
|
89
|
+
const left = pauseOf(db, artifactId);
|
|
90
|
+
if (left === undefined) {
|
|
91
|
+
if (own) {
|
|
92
|
+
appendEvent(db, { artifactId, type: "artifact.resumed", actor, payload: { by: change.by } });
|
|
93
|
+
}
|
|
94
|
+
return { paused: false };
|
|
95
|
+
}
|
|
96
|
+
// The operator lifted its own pause; the owner's stays, and so does the page's notice.
|
|
97
|
+
if (own) {
|
|
98
|
+
appendEvent(db, {
|
|
99
|
+
artifactId,
|
|
100
|
+
type: "artifact.paused",
|
|
101
|
+
actor: { kind: "agent" },
|
|
102
|
+
payload: { by: left.by, ...(left.reason !== undefined ? { reason: left.reason } : {}) },
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
return { paused: true, by: left.by };
|
|
106
|
+
}
|