@mostra/runtime 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/bin.js +6628 -9
- package/dist/bin.js.map +1 -1
- package/dist/builder/child/main.js +2 -2
- package/dist/{child-Chiavhdx.js → child-BmNZ4a70.js} +2 -2
- package/dist/{child-Chiavhdx.js.map → child-BmNZ4a70.js.map} +1 -1
- package/dist/deps/child/install.js +1 -1
- package/dist/{directories-mJ1qlVht.js → directories-BLJjeSPD.js} +5 -5
- package/dist/directories-BLJjeSPD.js.map +1 -0
- package/dist/{files-FygSJIzK.js → files-DGeWuE4I.js} +2 -2
- package/dist/{files-FygSJIzK.js.map → files-DGeWuE4I.js.map} +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -2
- package/dist/{instance-EnaZPs14.js → instance-DCiUHvgZ.js} +3835 -255
- 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 +12 -5
- package/src/actions/index.ts +163 -10
- package/src/bin.ts +78 -1
- package/src/gateway/actions.ts +40 -4
- package/src/gateway/browser.ts +162 -95
- package/src/gateway/capabilities.ts +23 -6
- package/src/gateway/http.ts +12 -1
- package/src/gateway/index.ts +282 -20
- package/src/gateway/listener.ts +31 -6
- package/src/gateway/routes.ts +23 -7
- package/src/gc/index.ts +19 -0
- package/src/instance/index.ts +60 -2
- package/src/interaction/ephemeral.ts +32 -23
- package/src/interaction/events.ts +21 -1
- package/src/interaction/imports.ts +317 -0
- package/src/interaction/index.ts +228 -15
- package/src/interaction/outbox.ts +9 -0
- package/src/interaction/pause.ts +106 -0
- package/src/interaction/results.ts +8 -1
- package/src/interaction/runs.ts +52 -2
- package/src/interaction/submissions.ts +59 -2
- package/src/interaction/tally.ts +129 -0
- package/src/interaction/viewers.ts +34 -1
- package/src/ledger/index.ts +124 -10
- package/src/ledger/migrations.ts +234 -0
- package/src/ledger/types.ts +8 -0
- package/src/link/author.ts +215 -0
- package/src/link/binding.ts +289 -0
- package/src/link/hosted.ts +101 -0
- package/src/link/http.ts +141 -0
- package/src/link/index.ts +10 -0
- package/src/link/manager.ts +1489 -0
- package/src/link/relay.ts +512 -0
- package/src/live/index.ts +112 -2
- package/src/platform/filesystems.ts +78 -0
- package/src/platform/index.ts +1 -0
- package/src/protocol-server/client.ts +53 -0
- package/src/protocol-server/index.ts +19 -2
- package/src/protocol-server/server.ts +38 -7
- package/src/protocol-server/websocket.ts +161 -0
- package/src/publish/bundle.ts +398 -0
- package/src/publish/manifest.ts +9 -0
- package/src/publish/methods.ts +12 -1
- package/src/publish/publisher.ts +127 -0
- package/src/registry/index.ts +35 -14
- package/src/server/api.ts +881 -0
- package/src/server/auth.ts +1139 -0
- package/src/server/authorize.ts +816 -0
- package/src/server/clients.ts +235 -0
- package/src/server/config.ts +228 -0
- package/src/server/data.ts +427 -0
- package/src/server/directory.ts +210 -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 +1323 -0
- package/src/server/index.ts +650 -0
- 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/relay.ts +1163 -0
- package/src/server/remove.ts +148 -0
- package/src/server/routing.ts +275 -0
- package/src/share/index.ts +110 -6
- package/src/verify/runner.ts +23 -2
- package/dist/directories-mJ1qlVht.js.map +0 -1
- package/dist/instance-EnaZPs14.js.map +0 -1
package/src/gateway/index.ts
CHANGED
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
*/
|
|
26
26
|
import { existsSync, readFileSync } from "node:fs";
|
|
27
27
|
import { readFile } from "node:fs/promises";
|
|
28
|
-
import type { IncomingMessage } from "node:http";
|
|
28
|
+
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
29
29
|
import { join, resolve } from "node:path";
|
|
30
30
|
import type { Duplex } from "node:stream";
|
|
31
31
|
import {
|
|
@@ -44,11 +44,13 @@ 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,
|
|
50
51
|
RpcError,
|
|
51
52
|
refusal,
|
|
53
|
+
SHELL_SESSION_HEADER,
|
|
52
54
|
StreamTicketRequest,
|
|
53
55
|
safePath,
|
|
54
56
|
scopeAllows,
|
|
@@ -96,6 +98,9 @@ import {
|
|
|
96
98
|
import { type IdentityOutcome, tailnetPerson } from "./identity.ts";
|
|
97
99
|
import { versionIntegrity } from "./integrity.ts";
|
|
98
100
|
import { createListener, type Listener } from "./listener.ts";
|
|
101
|
+
|
|
102
|
+
export { resetOnClose } from "./listener.ts";
|
|
103
|
+
|
|
99
104
|
import { type ListenerChecks, mount, type RouteContext, type RouteSpec, refuse } from "./routes.ts";
|
|
100
105
|
import { fileResponse, findFile } from "./serve.ts";
|
|
101
106
|
import { BOOTSTRAP_PAGE, SERVICE_WORKER_PATH, SERVICE_WORKER_SOURCE } from "./worker.ts";
|
|
@@ -103,7 +108,9 @@ import { BOOTSTRAP_PAGE, SERVICE_WORKER_PATH, SERVICE_WORKER_SOURCE } from "./wo
|
|
|
103
108
|
export { Capabilities, capabilityKey } from "./capabilities.ts";
|
|
104
109
|
export { CONTROLS_POLICY_TIMEOUT_MS, controlsPolicy } from "./controls.ts";
|
|
105
110
|
export type { DevUpstream } from "./dev.ts";
|
|
111
|
+
export { BASE_HEADERS, documentHeaders, isRefusal, jsonResponse, readJsonObject } from "./http.ts";
|
|
106
112
|
export { IDENTITY_TIMEOUT_MS, resolveIdentity } from "./identity.ts";
|
|
113
|
+
export type { RouteContext, RouteSpec } from "./routes.ts";
|
|
107
114
|
|
|
108
115
|
/** What the gateway reads about artifacts and versions. */
|
|
109
116
|
export interface GatewayArtifacts {
|
|
@@ -116,7 +123,7 @@ export interface GatewayArtifacts {
|
|
|
116
123
|
}
|
|
117
124
|
|
|
118
125
|
/** Who keeps a face (D158 item 1): a share's tunnel, or a host's addressing port. */
|
|
119
|
-
export type FaceBy = "tailnet" | "funnel" | "cloudflare" | "host";
|
|
126
|
+
export type FaceBy = "tailnet" | "funnel" | "cloudflare" | "host" | "hosted";
|
|
120
127
|
|
|
121
128
|
/** What a share asks the gateway to open: one external address of the shell or an artifact. */
|
|
122
129
|
export interface FaceSpec {
|
|
@@ -216,8 +223,8 @@ export interface GatewayOptions {
|
|
|
216
223
|
* Server functions and live data (WP-08): plain calls, action runs and live sources. Absent,
|
|
217
224
|
* their routes answer 501 behind their checks, as before WP-08.
|
|
218
225
|
*/
|
|
219
|
-
readonly actions?: Actions
|
|
220
|
-
readonly live?: Live
|
|
226
|
+
readonly actions?: Pick<Actions, "call" | "startRun" | "attach" | "cancel">;
|
|
227
|
+
readonly live?: Pick<Live, "read">;
|
|
221
228
|
/** Run and live updates for page streams and polls (WP-08). */
|
|
222
229
|
readonly bus?: EphemeralBus;
|
|
223
230
|
/** Whether a version's worker is parked (WP-08): its frame ticket tells the shell. */
|
|
@@ -235,6 +242,78 @@ export interface GatewayOptions {
|
|
|
235
242
|
* development preview. `upstream` is where that server listens now.
|
|
236
243
|
*/
|
|
237
244
|
readonly dev?: { readonly upstream: () => DevUpstream | undefined };
|
|
245
|
+
/**
|
|
246
|
+
* A hosted home's gateway on a remote server (ARCHITECTURE §15.6, INTERFACES §18.4): it binds
|
|
247
|
+
* nothing (the server's front hands it each request by exact `Host`, {@link Gateway.dispatch}),
|
|
248
|
+
* its shell lives on each user-content domain's apex at `/a/<routeId>` with its session in a
|
|
249
|
+
* header, and its frames on the route's label, always in worker mode.
|
|
250
|
+
*/
|
|
251
|
+
readonly hosted?: HostedAddressing;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/** Where a hosted home's pages live (INTERFACES §18.4). */
|
|
255
|
+
export interface HostedAddressing {
|
|
256
|
+
/** The active domain's shell origin, where new links are minted (D137). */
|
|
257
|
+
readonly shellOrigin: () => string;
|
|
258
|
+
/** Whether an origin is a domain's shell the server serves (the active domain or a spare). */
|
|
259
|
+
readonly servesShell: (origin: string) => boolean;
|
|
260
|
+
/** The shell's path of an artifact: `/a/<routeId>`. */
|
|
261
|
+
readonly shellPath: (artifactId: string) => string;
|
|
262
|
+
/** The origin of an artifact's frames beside a domain's shell: its route's label there. */
|
|
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;
|
|
238
317
|
}
|
|
239
318
|
|
|
240
319
|
/** The gateway of one instance. */
|
|
@@ -283,6 +362,11 @@ export interface Gateway {
|
|
|
283
362
|
methods(): MethodHandler[];
|
|
284
363
|
/** The origins of the artifact listeners that are bound, by artifact ID. */
|
|
285
364
|
artifactOrigins(): ReadonlyMap<string, string>;
|
|
365
|
+
/**
|
|
366
|
+
* Hands a request to an open face's listener without binding it (a hosted home's faces, served
|
|
367
|
+
* by the server's front): `false` when no such face is open.
|
|
368
|
+
*/
|
|
369
|
+
dispatch(key: string, request: IncomingMessage, response: ServerResponse): boolean;
|
|
286
370
|
/** Stops every listener. */
|
|
287
371
|
close(): Promise<void>;
|
|
288
372
|
}
|
|
@@ -464,6 +548,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
464
548
|
: undefined;
|
|
465
549
|
},
|
|
466
550
|
activated: options.activated,
|
|
551
|
+
...(options.hosted?.admitSubmit ? { admitSubmit: options.hosted.admitSubmit } : {}),
|
|
467
552
|
...(options.revisions ? { revisions: options.revisions } : {}),
|
|
468
553
|
...(options.bus ? { bus: options.bus } : {}),
|
|
469
554
|
});
|
|
@@ -478,7 +563,9 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
478
563
|
})
|
|
479
564
|
: undefined;
|
|
480
565
|
let shellPort: number | undefined;
|
|
566
|
+
const hosted = options.hosted;
|
|
481
567
|
const shellOrigin = (): string => {
|
|
568
|
+
if (hosted) return hosted.shellOrigin();
|
|
482
569
|
if (shellPort === undefined) throw new Error("The gateway hasn't started.");
|
|
483
570
|
return addressing.origin(shellPort);
|
|
484
571
|
};
|
|
@@ -550,7 +637,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
550
637
|
|
|
551
638
|
/** Whether the gateway serves a shell at this origin now: launch tickets go only there. */
|
|
552
639
|
const servesShell = (origin: string): boolean =>
|
|
553
|
-
origin === shellOrigin() ||
|
|
640
|
+
(hosted ? hosted.servesShell(origin) : origin === shellOrigin()) ||
|
|
554
641
|
[...faces.values()].some((entry) => entry.spec.listener === "shell" && entry.origin === origin);
|
|
555
642
|
|
|
556
643
|
/** The answer for a damaged version: a plain page for a navigation, else the diagnostic. */
|
|
@@ -571,7 +658,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
571
658
|
);
|
|
572
659
|
|
|
573
660
|
const link = (token: MintedToken): CapabilityLink => ({
|
|
574
|
-
url: `${token.shellOrigin}
|
|
661
|
+
url: `${token.shellOrigin}${hosted ? hosted.shellPath(token.artifactId) : `/a/${token.artifactId}`}${token.pinnedVersion !== undefined ? `/v/${token.pinnedVersion}` : ""}#t=${token.secret}`,
|
|
575
662
|
tokenId: token.tokenId,
|
|
576
663
|
scopes: token.scopes,
|
|
577
664
|
...(token.expiresAt !== undefined ? { expiresAt: token.expiresAt } : {}),
|
|
@@ -637,9 +724,13 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
637
724
|
: {}),
|
|
638
725
|
...(options.traceRequests ? { traceRequests: true } : {}),
|
|
639
726
|
});
|
|
640
|
-
// A withdrawn face of this key may still hold its leased port for a moment.
|
|
727
|
+
// A withdrawn face of this key may still hold its leased port for a moment. A hosted face
|
|
728
|
+
// binds nothing: the server's front hands it its requests (`dispatch`).
|
|
641
729
|
await endLingering(key);
|
|
642
|
-
const port =
|
|
730
|
+
const port =
|
|
731
|
+
spec.by === "hosted"
|
|
732
|
+
? 0
|
|
733
|
+
: await addressing.listenFace(listener.server, { key, lease: spec.lease });
|
|
643
734
|
entry = { key, spec, listener, port, origin };
|
|
644
735
|
faces.set(key, entry);
|
|
645
736
|
log.info("gateway.face_open", {
|
|
@@ -857,6 +948,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
857
948
|
|
|
858
949
|
/** Where an artifact's links point: a host's external base when it gives one, else loopback. */
|
|
859
950
|
const linkBase = async (artifactId: string): Promise<string> => {
|
|
951
|
+
if (hosted?.linkOrigin) return (await hosted.linkOrigin(artifactId)) ?? shellOrigin();
|
|
860
952
|
const face = await hostFace(artifactId, "shell");
|
|
861
953
|
return face?.origin ?? shellOrigin();
|
|
862
954
|
};
|
|
@@ -871,6 +963,26 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
871
963
|
const port = await openArtifact(artifactId);
|
|
872
964
|
return { way: loopbackArtifact(artifactId, () => port), group: undefined };
|
|
873
965
|
}
|
|
966
|
+
if (shell.by === "hosted") {
|
|
967
|
+
const origin = hosted?.artifactOrigin(artifactId, shell.origin() ?? "");
|
|
968
|
+
if (origin === undefined) {
|
|
969
|
+
return refusal("MOSTRA_HYGIENE_NOT_SERVED", "This artifact isn't hosted here.");
|
|
970
|
+
}
|
|
971
|
+
const entry = await openFace(
|
|
972
|
+
{
|
|
973
|
+
by: "hosted",
|
|
974
|
+
group,
|
|
975
|
+
listener: "artifact",
|
|
976
|
+
artifactId,
|
|
977
|
+
via: "token",
|
|
978
|
+
lease: false,
|
|
979
|
+
mode: "worker",
|
|
980
|
+
},
|
|
981
|
+
origin,
|
|
982
|
+
);
|
|
983
|
+
entry.origin = origin;
|
|
984
|
+
return { way: faceWay(entry), group };
|
|
985
|
+
}
|
|
874
986
|
if (shell.by === "host") {
|
|
875
987
|
const entry = await hostFace(artifactId, "artifact");
|
|
876
988
|
if (entry?.origin === undefined) {
|
|
@@ -901,6 +1013,8 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
901
1013
|
capabilities,
|
|
902
1014
|
log,
|
|
903
1015
|
cookieName: () => `mostra-${way().port()}`,
|
|
1016
|
+
// A hosted shell's session travels in a header, never a cookie (D165 item 8).
|
|
1017
|
+
mode: () => (way().by === "hosted" ? "header" : "cookie"),
|
|
904
1018
|
frameAncestors: () => "'none'",
|
|
905
1019
|
artifactOf: (params) => {
|
|
906
1020
|
const id = params["artifactId"];
|
|
@@ -913,6 +1027,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
913
1027
|
},
|
|
914
1028
|
// The shell's own stream is refused where streams don't pass, as the frame's is (D158 item 5).
|
|
915
1029
|
streams: () => way().streams(),
|
|
1030
|
+
...(hosted?.client ? { client: hosted.client } : {}),
|
|
916
1031
|
});
|
|
917
1032
|
|
|
918
1033
|
const shellMissing = (): Response =>
|
|
@@ -969,7 +1084,13 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
969
1084
|
const found = await artifactWayFor(way, group, context.artifactId).catch(() => undefined);
|
|
970
1085
|
frames = found && !isRefusal(found) ? (found.way.origin() ?? "'none'") : "'none'";
|
|
971
1086
|
}
|
|
972
|
-
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;
|
|
973
1094
|
return new Response(context.request.method === "HEAD" ? null : html, {
|
|
974
1095
|
headers: {
|
|
975
1096
|
...BASE_HEADERS,
|
|
@@ -980,6 +1101,16 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
980
1101
|
});
|
|
981
1102
|
};
|
|
982
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
|
+
|
|
983
1114
|
const shellAsset = async (context: RouteContext): Promise<Response> => {
|
|
984
1115
|
if (options.shellDir === undefined) return shellMissing();
|
|
985
1116
|
const url = new URL(context.request.url);
|
|
@@ -1003,8 +1134,16 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1003
1134
|
* 2): the home's local user on loopback; over a tunnel the tailnet person Tailscale Serve
|
|
1004
1135
|
* named, else the link's own viewer, never the home's local user.
|
|
1005
1136
|
*/
|
|
1006
|
-
const defaultViewer = (
|
|
1137
|
+
const defaultViewer = (
|
|
1138
|
+
way: Way,
|
|
1139
|
+
context: RouteContext,
|
|
1140
|
+
grant: Grant,
|
|
1141
|
+
browser: string | undefined,
|
|
1142
|
+
): string | undefined => {
|
|
1007
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);
|
|
1008
1147
|
if (way.via === "tailnet") {
|
|
1009
1148
|
const person = tailnetPerson(context.request.headers, context.remote);
|
|
1010
1149
|
if (person) return interaction.viewerForTailnet(person);
|
|
@@ -1050,11 +1189,19 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1050
1189
|
if (isRefusal(grant)) return refuse(checks, grant, meta);
|
|
1051
1190
|
// A live session from another link is never replaced silently (D98 item 8): a page elsewhere
|
|
1052
1191
|
// could send the viewer to its own, narrower link and take over their tabs.
|
|
1053
|
-
const
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1192
|
+
const inHeader = way.by === "hosted";
|
|
1193
|
+
const existing = inHeader
|
|
1194
|
+
? capabilities.session(
|
|
1195
|
+
[context.request.headers.get(SHELL_SESSION_HEADER) ?? ""],
|
|
1196
|
+
origin,
|
|
1197
|
+
artifactId,
|
|
1198
|
+
"header",
|
|
1199
|
+
)
|
|
1200
|
+
: capabilities.session(
|
|
1201
|
+
cookieValues(context.request.headers.get("cookie"), checks.cookieName()),
|
|
1202
|
+
origin,
|
|
1203
|
+
artifactId,
|
|
1204
|
+
);
|
|
1058
1205
|
if (!isRefusal(existing)) {
|
|
1059
1206
|
if (existing.grant.tokenId === grant.tokenId) {
|
|
1060
1207
|
if (launch) capabilities.spendLaunch(body["launch"]);
|
|
@@ -1089,7 +1236,14 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1089
1236
|
viewerId =
|
|
1090
1237
|
outcome.kind === "person"
|
|
1091
1238
|
? interaction.viewerForHost(outcome.viewer)
|
|
1092
|
-
: defaultViewer(
|
|
1239
|
+
: defaultViewer(
|
|
1240
|
+
way,
|
|
1241
|
+
context,
|
|
1242
|
+
grant,
|
|
1243
|
+
typeof body["browser"] === "string" && browser !== undefined
|
|
1244
|
+
? body["browser"]
|
|
1245
|
+
: undefined,
|
|
1246
|
+
);
|
|
1093
1247
|
}
|
|
1094
1248
|
// Everything is judged again after the await, in one synchronous step with the session's
|
|
1095
1249
|
// creation: a link revoked or expired meanwhile gets no session (Opus review of WP-12,
|
|
@@ -1120,7 +1274,12 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1120
1274
|
{ status: 409 },
|
|
1121
1275
|
);
|
|
1122
1276
|
}
|
|
1123
|
-
const session = capabilities.createSession({
|
|
1277
|
+
const session = capabilities.createSession({
|
|
1278
|
+
tokenId: grant.tokenId,
|
|
1279
|
+
origin,
|
|
1280
|
+
viewerId,
|
|
1281
|
+
...(inHeader ? { mode: "header" as const } : {}),
|
|
1282
|
+
});
|
|
1124
1283
|
if (browser !== undefined) {
|
|
1125
1284
|
exchangeOrder += 1;
|
|
1126
1285
|
madeSessions.delete(browser);
|
|
@@ -1129,6 +1288,15 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1129
1288
|
madeSessions.delete(madeSessions.keys().next().value as string);
|
|
1130
1289
|
}
|
|
1131
1290
|
log.info("gateway.session_started", { origin, artifactId, tokenId: grant.tokenId });
|
|
1291
|
+
// A hosted shell keeps its session's secret itself and sends it as a header (§18.4).
|
|
1292
|
+
if (inHeader) {
|
|
1293
|
+
return jsonResponse({
|
|
1294
|
+
csrf: session.csrf,
|
|
1295
|
+
session: session.cookie,
|
|
1296
|
+
hosted: true,
|
|
1297
|
+
...sessionFacts(artifactId, grant),
|
|
1298
|
+
});
|
|
1299
|
+
}
|
|
1132
1300
|
return jsonResponse(
|
|
1133
1301
|
{ csrf: session.csrf, ...sessionFacts(artifactId, grant) },
|
|
1134
1302
|
{
|
|
@@ -1203,6 +1371,17 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1203
1371
|
// A dev preview has no stored build to check: Vite serves the source (D140 item 12).
|
|
1204
1372
|
const damage = options.dev ? undefined : await integrity.check(version.id);
|
|
1205
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
|
+
}
|
|
1206
1385
|
// The frame opens on the artifact's way in this shell's group: its loopback listener, or
|
|
1207
1386
|
// the artifact's face at this address (D158 item 1), in the mode the pair needs (D70).
|
|
1208
1387
|
const found = await artifactWayFor(way, group, artifactId);
|
|
@@ -1222,6 +1401,10 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1222
1401
|
// the channels and controls in force for it (D108).
|
|
1223
1402
|
const controls = await options.controls(detail);
|
|
1224
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;
|
|
1225
1408
|
const viewId = interaction.openView({
|
|
1226
1409
|
artifactId,
|
|
1227
1410
|
versionId: version.id,
|
|
@@ -1256,6 +1439,15 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1256
1439
|
...(options.parked?.(version.id) ? { serverParked: true as const } : {}),
|
|
1257
1440
|
...(options.dev ? { devPreview: true as const } : {}),
|
|
1258
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 } : {}),
|
|
1259
1451
|
};
|
|
1260
1452
|
return jsonResponse(answer);
|
|
1261
1453
|
};
|
|
@@ -1344,7 +1536,7 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1344
1536
|
path: "/a/:artifactId/_mostra/v/:rev/events/poll",
|
|
1345
1537
|
intent: "stream",
|
|
1346
1538
|
auth: "session",
|
|
1347
|
-
handler: served.
|
|
1539
|
+
handler: served.shellPoll,
|
|
1348
1540
|
},
|
|
1349
1541
|
{
|
|
1350
1542
|
method: "POST",
|
|
@@ -1353,6 +1545,11 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1353
1545
|
auth: "session",
|
|
1354
1546
|
scope: () => "review",
|
|
1355
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
|
+
}) ?? []),
|
|
1356
1553
|
];
|
|
1357
1554
|
};
|
|
1358
1555
|
|
|
@@ -1367,10 +1564,17 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1367
1564
|
capabilities,
|
|
1368
1565
|
log,
|
|
1369
1566
|
cookieName: () => `mostra-${wayOf().port()}`,
|
|
1370
|
-
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
|
+
},
|
|
1371
1574
|
artifactOf: () => artifactId,
|
|
1372
1575
|
mode: () => modeOf(wayOf(), group),
|
|
1373
1576
|
streams: () => wayOf().streams(),
|
|
1577
|
+
...(hosted?.client ? { client: hosted.client } : {}),
|
|
1374
1578
|
});
|
|
1375
1579
|
|
|
1376
1580
|
const artifactRoutes = (
|
|
@@ -1380,12 +1584,15 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1380
1584
|
): RouteSpec[] => {
|
|
1381
1585
|
const origin = (): string => wayOf().origin() ?? "";
|
|
1382
1586
|
const shell = (): string => shellOf(wayOf(), group)?.origin() ?? "";
|
|
1587
|
+
const checks = artifactChecks(artifactId, wayOf, group);
|
|
1383
1588
|
const kind = (): ListenerKind => ({
|
|
1384
1589
|
kind: "artifact",
|
|
1385
1590
|
origin: origin(),
|
|
1386
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() } : {}),
|
|
1387
1595
|
});
|
|
1388
|
-
const checks = artifactChecks(artifactId, wayOf, group);
|
|
1389
1596
|
const mode = (): FrameMode => modeOf(wayOf(), group);
|
|
1390
1597
|
const notServed = (context: RouteContext, message: string): Response =>
|
|
1391
1598
|
refuse(checks, refusal("MOSTRA_HYGIENE_NOT_SERVED", message), {
|
|
@@ -1664,6 +1871,9 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1664
1871
|
// again whenever a file changed since (FAILURE_MODEL §3).
|
|
1665
1872
|
const checked =
|
|
1666
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);
|
|
1667
1877
|
if (checked) {
|
|
1668
1878
|
const damage = await integrity.serve(from, checked);
|
|
1669
1879
|
if (damage !== undefined) {
|
|
@@ -1948,6 +2158,12 @@ export function createGateway(options: GatewayOptions): Gateway {
|
|
|
1948
2158
|
async openFace(spec) {
|
|
1949
2159
|
return handleOf(await openFace(spec));
|
|
1950
2160
|
},
|
|
2161
|
+
dispatch(key, request, response) {
|
|
2162
|
+
const entry = faces.get(key);
|
|
2163
|
+
if (!entry) return false;
|
|
2164
|
+
entry.listener.server.emit("request", request, response);
|
|
2165
|
+
return true;
|
|
2166
|
+
},
|
|
1951
2167
|
face(key) {
|
|
1952
2168
|
const entry = faces.get(key);
|
|
1953
2169
|
return entry ? handleOf(entry) : undefined;
|
|
@@ -2117,7 +2333,53 @@ async function verifyDocument(
|
|
|
2117
2333
|
* instance still starts, artifact frames are still served, and the shell's pages answer
|
|
2118
2334
|
* `MOSTRA_ENV_SHELL_MISSING`.
|
|
2119
2335
|
*/
|
|
2336
|
+
/**
|
|
2337
|
+
* Answers a request for one of the shell's own built files (`/_mostra/shell/assets/*`): a remote
|
|
2338
|
+
* server's front serves them on every user-content domain's apex before any hosted home is
|
|
2339
|
+
* known, since they are the same for every route (INTERFACES §18.4).
|
|
2340
|
+
*/
|
|
2341
|
+
export async function shellAssetResponse(
|
|
2342
|
+
shellDir: string,
|
|
2343
|
+
request: Request,
|
|
2344
|
+
): Promise<Response | undefined> {
|
|
2345
|
+
const path = safePath(new URL(request.url).pathname);
|
|
2346
|
+
if (path === undefined || !path.startsWith("/_mostra/shell/assets/")) return undefined;
|
|
2347
|
+
const file = await findFile(shellDir, path.slice("/_mostra/shell".length));
|
|
2348
|
+
if (!file) return undefined;
|
|
2349
|
+
return fileResponse(file, request, { "cache-control": "public, max-age=31536000, immutable" });
|
|
2350
|
+
}
|
|
2351
|
+
|
|
2120
2352
|
export function locateShell(env: Environment): string | undefined {
|
|
2121
2353
|
const dir = env["MOSTRA_SHELL_DIR"] ?? resolve(runtimeRoot(), "..", "shell", "dist");
|
|
2122
2354
|
return existsSync(join(dir, "index.html")) ? dir : undefined;
|
|
2123
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
|
@@ -24,11 +24,12 @@ import {
|
|
|
24
24
|
type RequestIntent,
|
|
25
25
|
type RequestPolicy,
|
|
26
26
|
refusal,
|
|
27
|
+
SHELL_SESSION_HEADER,
|
|
27
28
|
scopeAllows,
|
|
28
29
|
} from "@mostra/protocol";
|
|
29
30
|
import type { Context, Hono } from "hono";
|
|
30
31
|
import type { Log } from "../log.ts";
|
|
31
|
-
import type { Capabilities, ResolvedSession } from "./capabilities.ts";
|
|
32
|
+
import type { Capabilities, ResolvedSession, SessionMode } from "./capabilities.ts";
|
|
32
33
|
import {
|
|
33
34
|
cookieValues,
|
|
34
35
|
type HttpEnv,
|
|
@@ -74,6 +75,11 @@ export interface RouteContext {
|
|
|
74
75
|
readonly document: boolean;
|
|
75
76
|
/** The address of the connection's peer: on a face, the tunnel's own process (D158 item 2). */
|
|
76
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;
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
/** What a listener contributes to every route's checks. */
|
|
@@ -92,9 +98,11 @@ export interface ListenerChecks {
|
|
|
92
98
|
* How this listener's sessions authenticate (D70): `cookie` (the default), or `worker`, where a
|
|
93
99
|
* frame's service worker sends the session's secret as `X-Mostra-Frame`.
|
|
94
100
|
*/
|
|
95
|
-
readonly mode?: () =>
|
|
101
|
+
readonly mode?: () => SessionMode;
|
|
96
102
|
/** Whether event streams pass to this listener's browsers; `false` behind a quick tunnel. */
|
|
97
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;
|
|
98
106
|
}
|
|
99
107
|
|
|
100
108
|
/** Logs a refusal without any of the request's capability material, and answers it. */
|
|
@@ -195,11 +203,18 @@ export function mount(
|
|
|
195
203
|
artifactId,
|
|
196
204
|
"worker",
|
|
197
205
|
)
|
|
198
|
-
:
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
206
|
+
: mode === "header"
|
|
207
|
+
? checks.capabilities.session(
|
|
208
|
+
[request.headers.get(SHELL_SESSION_HEADER) ?? ""],
|
|
209
|
+
policy.origin,
|
|
210
|
+
artifactId,
|
|
211
|
+
"header",
|
|
212
|
+
)
|
|
213
|
+
: checks.capabilities.session(
|
|
214
|
+
cookieValues(request.headers.get("cookie"), checks.cookieName()),
|
|
215
|
+
policy.origin,
|
|
216
|
+
artifactId,
|
|
217
|
+
);
|
|
203
218
|
if (isRefusal(resolved)) return refuse(checks, resolved, meta);
|
|
204
219
|
session = resolved;
|
|
205
220
|
// 4. The CSRF token of this session.
|
|
@@ -234,6 +249,7 @@ export function mount(
|
|
|
234
249
|
...(session ? { session } : {}),
|
|
235
250
|
document,
|
|
236
251
|
remote: incoming.socket.remoteAddress,
|
|
252
|
+
client: checks.client ? checks.client(incoming) : incoming.socket.remoteAddress,
|
|
237
253
|
});
|
|
238
254
|
};
|
|
239
255
|
if (route.method === "GET") app.get(route.path, handle);
|