@mostra/runtime 0.10.0 → 0.12.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 +4178 -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-CBUlOmzG.js} +1892 -85
- package/dist/instance-CBUlOmzG.js.map +1 -0
- package/dist/reference/cli.md +1432 -0
- package/dist/reference/diagnostics.json +1579 -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_TEAM_PRESENCE_RATE_LIMITED.md +23 -0
- package/dist/reference/errors/MOSTRA_TEAM_ROSTER_POLICY.md +23 -0
- package/dist/reference/errors/MOSTRA_TEAM_ROSTER_TOO_LARGE.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 +124 -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 +219 -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/teams.md +78 -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 +128 -1
- package/src/gateway/capabilities.ts +8 -0
- package/src/gateway/http.ts +12 -1
- package/src/gateway/index.ts +210 -6
- package/src/gateway/listener.ts +31 -6
- package/src/gateway/routes.ts +8 -0
- package/src/gateway/team.ts +181 -0
- package/src/gc/index.ts +5 -0
- package/src/instance/index.ts +22 -2
- package/src/interaction/ephemeral.ts +21 -0
- package/src/interaction/events.ts +17 -0
- package/src/interaction/index.ts +325 -20
- package/src/interaction/pause.ts +106 -0
- package/src/interaction/roster.ts +585 -0
- package/src/interaction/submissions.ts +42 -1
- package/src/interaction/team.ts +426 -0
- package/src/interaction/viewers.ts +34 -1
- package/src/interaction/wait.ts +150 -0
- package/src/ledger/index.ts +20 -1
- package/src/ledger/migrations.ts +86 -0
- package/src/link/author.ts +215 -0
- package/src/link/hosted.ts +51 -4
- package/src/link/http.ts +6 -1
- package/src/link/index.ts +3 -1
- package/src/link/manager.ts +169 -35
- 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 +91 -0
- package/src/server/feed.ts +277 -0
- package/src/server/handle.ts +172 -0
- package/src/server/hosted-pages.ts +532 -0
- package/src/server/hosted.ts +551 -18
- package/src/server/index.ts +353 -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 +557 -0
- package/src/server/providers.ts +284 -0
- package/src/server/remove.ts +148 -0
- package/src/server/routing.ts +275 -0
- package/src/share/index.ts +50 -2
- package/src/verify/index.ts +7 -0
- package/src/verify/runner.ts +27 -2
- package/dist/instance-FExcyENK.js.map +0 -1
package/src/server/hosted.ts
CHANGED
|
@@ -12,13 +12,14 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import { createHash, randomBytes } from "node:crypto";
|
|
14
14
|
import { linkSync, mkdirSync, writeFileSync } from "node:fs";
|
|
15
|
-
import { copyFile, readFile, rm } from "node:fs/promises";
|
|
15
|
+
import { copyFile, readFile, rm, stat } from "node:fs/promises";
|
|
16
16
|
import type { IncomingMessage, ServerResponse } from "node:http";
|
|
17
17
|
import { isAbsolute, join, relative } from "node:path";
|
|
18
18
|
import {
|
|
19
19
|
ArtifactManifest,
|
|
20
20
|
artifactGetMethod,
|
|
21
21
|
artifactListMethod,
|
|
22
|
+
artifactPauseMethod,
|
|
22
23
|
createDiagnostic,
|
|
23
24
|
type HostedPushParams,
|
|
24
25
|
type HostedPushResult,
|
|
@@ -26,13 +27,15 @@ import {
|
|
|
26
27
|
hostedPushMethod,
|
|
27
28
|
hostedSubmissionMethod,
|
|
28
29
|
type InstanceInfo,
|
|
30
|
+
type PausedBy,
|
|
29
31
|
RouteId,
|
|
30
32
|
RpcError,
|
|
31
33
|
remoteTokenMethod,
|
|
34
|
+
viewUrlMethod,
|
|
32
35
|
} from "@mostra/protocol";
|
|
33
36
|
import type { Addressing } from "../addressing/index.ts";
|
|
34
37
|
import { coverageMatcher, readFieldCoverage, readServerFunctions } from "../builder/index.ts";
|
|
35
|
-
import { noFaults } from "../faults.ts";
|
|
38
|
+
import { type Faults, noFaults } from "../faults.ts";
|
|
36
39
|
import {
|
|
37
40
|
Capabilities,
|
|
38
41
|
capabilityKey,
|
|
@@ -45,12 +48,25 @@ import { createEphemeralBus, createInteraction, type Interaction } from "../inte
|
|
|
45
48
|
import type { Ledger } from "../ledger/index.ts";
|
|
46
49
|
import { createLive, liveMethods } from "../live/index.ts";
|
|
47
50
|
import type { Log } from "../log.ts";
|
|
48
|
-
import {
|
|
51
|
+
import { removeTree } from "../platform/index.ts";
|
|
52
|
+
import {
|
|
53
|
+
handler,
|
|
54
|
+
type MethodHandler,
|
|
55
|
+
ProtocolServer,
|
|
56
|
+
type Session,
|
|
57
|
+
} from "../protocol-server/index.ts";
|
|
49
58
|
import { canonicalRef, listingDigest, versionIdFor } from "../publish/index.ts";
|
|
50
59
|
import { openRegistry, type Registry } from "../registry/index.ts";
|
|
51
60
|
import type { Authorization } from "./auth.ts";
|
|
61
|
+
import type { ClientAddresses, RateLimiter } from "./clients.ts";
|
|
52
62
|
import { rotateIncarnation } from "./data.ts";
|
|
63
|
+
import { createOperatorFeed, type OperatorFeed } from "./feed.ts";
|
|
64
|
+
import { type HomeOwner, type HostedPagesOptions, hostedPages } from "./hosted-pages.ts";
|
|
65
|
+
import type { Meter } from "./metering.ts";
|
|
66
|
+
import type { Operator } from "./operator.ts";
|
|
53
67
|
import { createHostedRelay } from "./relay.ts";
|
|
68
|
+
import { purgeArtifact } from "./remove.ts";
|
|
69
|
+
import type { Routing } from "./routing.ts";
|
|
54
70
|
|
|
55
71
|
/** Lower-case Crockford base32, for route labels (one DNS label, 130 bits). */
|
|
56
72
|
const LABEL_ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
@@ -92,10 +108,44 @@ export interface HostedHome {
|
|
|
92
108
|
readonly protocol: ProtocolServer;
|
|
93
109
|
/** The home's current incarnation (DATA_MODEL §7.2). */
|
|
94
110
|
incarnation(): string;
|
|
95
|
-
/**
|
|
96
|
-
|
|
111
|
+
/**
|
|
112
|
+
* The size a pending push of this home gives a client file it names as missing, or `undefined`
|
|
113
|
+
* when none names it: an upload must bring exactly those bytes (Fable review of WP-30, 2).
|
|
114
|
+
*/
|
|
115
|
+
wanted(sha256: string): number | undefined;
|
|
97
116
|
/** Records a file this home uploaded (`PUT /files/<sha256>`, §18.2). */
|
|
98
117
|
uploaded(sha256: string): void;
|
|
118
|
+
/** Pauses or resumes an artifact as its owner or the operator (D165 item 14). */
|
|
119
|
+
pause(
|
|
120
|
+
artifactId: string,
|
|
121
|
+
change: { readonly paused: boolean; readonly by: PausedBy; readonly reason?: string },
|
|
122
|
+
): { readonly paused: boolean; readonly by?: PausedBy };
|
|
123
|
+
/** Quarantines an artifact, or one version of it, here only (D165 item 9). */
|
|
124
|
+
quarantine(artifactId: string, versionId: string | undefined, reason: string): void;
|
|
125
|
+
/** Ends a quarantine: the artifact's, or one version's. */
|
|
126
|
+
release(artifactId: string, versionId: string | undefined): void;
|
|
127
|
+
/** Revokes every live link of an artifact; answers how many were live. */
|
|
128
|
+
revokeLinks(artifactId: string): number;
|
|
129
|
+
/** Revokes one link; `false` when this home has no such link. */
|
|
130
|
+
revokeLink(tokenId: string): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* A personal link's URL and expiry, built from its token now (an invitation's, D168), or
|
|
133
|
+
* `undefined` when it no longer works: revoked, expired, or made where it can't be shown again.
|
|
134
|
+
*/
|
|
135
|
+
invitationLink(
|
|
136
|
+
tokenId: string,
|
|
137
|
+
): { readonly url: string; readonly expiresAt?: string } | undefined;
|
|
138
|
+
/**
|
|
139
|
+
* Removes an artifact and everything of it from this home (`ServerHandle.remove`): its rows, its
|
|
140
|
+
* version files no other version of the home names, and its route; its label is kept issued
|
|
141
|
+
* forever, never served again (DATA_MODEL §7.5).
|
|
142
|
+
*/
|
|
143
|
+
remove(artifactId: string): Promise<{ readonly rows: number }>;
|
|
144
|
+
/**
|
|
145
|
+
* The session of the account's default owner instance, while it is connected: where remote MCP's
|
|
146
|
+
* authoring goes (D165 items 1b, 5). The newest session of the link is its own.
|
|
147
|
+
*/
|
|
148
|
+
defaultOwnerSession(): number | undefined;
|
|
99
149
|
/** Whether a binding is open, a stream or poll is served, or a delivery waits. */
|
|
100
150
|
busy(): boolean;
|
|
101
151
|
/**
|
|
@@ -131,6 +181,8 @@ export interface HostedHomeOptions {
|
|
|
131
181
|
/** The shell's built files. */
|
|
132
182
|
readonly shellDir: string | undefined;
|
|
133
183
|
/** The relay's server settings (`relay` in the configuration, D165 item 4). */
|
|
184
|
+
/** The test fault points (`MOSTRA_TEST_FAULTS`); none by default. */
|
|
185
|
+
readonly faults?: Faults;
|
|
134
186
|
readonly relay?: {
|
|
135
187
|
readonly waitingRunsPerArtifact?: number | undefined;
|
|
136
188
|
readonly drainPerSecond?: number | undefined;
|
|
@@ -141,6 +193,26 @@ export interface HostedHomeOptions {
|
|
|
141
193
|
/** `rateLimits.perLink.relayedRuns`, in milliseconds. */
|
|
142
194
|
readonly perLink?: { readonly count: number; readonly perMs: number } | undefined;
|
|
143
195
|
};
|
|
196
|
+
/** What the server lends every hosted home: its operator, client addresses and rates (WP-30). */
|
|
197
|
+
readonly services?: HostedServices;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** What the server lends every hosted home (WP-30). */
|
|
201
|
+
export interface HostedServices {
|
|
202
|
+
readonly operator: Operator;
|
|
203
|
+
readonly clients: ClientAddresses;
|
|
204
|
+
readonly rates: RateLimiter;
|
|
205
|
+
readonly rateLimits: HostedPagesOptions["rateLimits"];
|
|
206
|
+
/** Who owns a home, as its pages' sender line names them. */
|
|
207
|
+
readonly owner: (homeId: string) => HomeOwner;
|
|
208
|
+
readonly signInOffered: () => boolean;
|
|
209
|
+
readonly madeWith?: { readonly href?: string } | undefined;
|
|
210
|
+
/** The server's routing by exact `Host`: operator hosts, their frames and link hosts (D167). */
|
|
211
|
+
readonly routing: Routing;
|
|
212
|
+
/** The server's meter: views here, submissions through the operator feed. */
|
|
213
|
+
readonly meter: Meter;
|
|
214
|
+
/** Viewer sign-in on the authorization server (INTERFACES §18.4). */
|
|
215
|
+
readonly signin?: HostedPagesOptions["signin"];
|
|
144
216
|
}
|
|
145
217
|
|
|
146
218
|
function refuse(code: Parameters<typeof createDiagnostic>[0], message: string): RpcError {
|
|
@@ -149,10 +221,11 @@ function refuse(code: Parameters<typeof createDiagnostic>[0], message: string):
|
|
|
149
221
|
|
|
150
222
|
/** Opens the parts of a hosted home over its ledger. */
|
|
151
223
|
export async function openHostedHome(options: HostedHomeOptions): Promise<HostedHome> {
|
|
224
|
+
const faults = options.faults ?? noFaults;
|
|
152
225
|
const { id, dir, ledger, directory, log } = options;
|
|
153
226
|
const registry = await openRegistry({ home: dir, ledger });
|
|
154
|
-
/** Pending pushes: version ID →
|
|
155
|
-
const pending = new Map<string,
|
|
227
|
+
/** Pending pushes: version ID → each missing client file's SHA-256 and the size its listing gives. */
|
|
228
|
+
const pending = new Map<string, Map<string, number>>();
|
|
156
229
|
let incarnation = options.incarnation;
|
|
157
230
|
|
|
158
231
|
const ownerLinkOf = (artifactId: string): string | undefined =>
|
|
@@ -182,6 +255,12 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
182
255
|
const interaction = createInteraction({
|
|
183
256
|
// A respondent on a hosted link learns only that the answer was sent (D165 item 1a).
|
|
184
257
|
sentOnly: true,
|
|
258
|
+
// The owner is the account the home belongs to, signed in on its page (CO-07): it sees every
|
|
259
|
+
// respondent and every present viewer, whatever the artifact's visibility.
|
|
260
|
+
isOwner: (viewer) =>
|
|
261
|
+
options.services !== undefined &&
|
|
262
|
+
viewer.kind === "account" &&
|
|
263
|
+
viewer.ref === options.services.owner(id).account,
|
|
185
264
|
ledger,
|
|
186
265
|
log,
|
|
187
266
|
faults: noFaults,
|
|
@@ -207,11 +286,22 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
207
286
|
/** The route of an artifact on this home, minted on its first push by `link`. */
|
|
208
287
|
const routeFor = (artifactId: string, link: string): HostedRoute =>
|
|
209
288
|
directory.write((db) => {
|
|
210
|
-
const found = db.get<{
|
|
211
|
-
|
|
289
|
+
const found = db.get<{
|
|
290
|
+
id: string;
|
|
291
|
+
label: string;
|
|
292
|
+
owner_link_id: string;
|
|
293
|
+
removing_json: string | null;
|
|
294
|
+
}>(
|
|
295
|
+
"SELECT id, label, owner_link_id, removing_json FROM artifact_route WHERE home_id = ? AND artifact_id = ?",
|
|
212
296
|
id,
|
|
213
297
|
artifactId,
|
|
214
298
|
);
|
|
299
|
+
if (found?.removing_json != null) {
|
|
300
|
+
throw refuse(
|
|
301
|
+
"MOSTRA_REMOTE_HOME_MOVING",
|
|
302
|
+
"This artifact is being removed from the server; push it again once that's done.",
|
|
303
|
+
);
|
|
304
|
+
}
|
|
215
305
|
if (found) {
|
|
216
306
|
if (found.owner_link_id !== link) {
|
|
217
307
|
const owner = db.get<{ name: string }>(
|
|
@@ -252,10 +342,11 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
252
342
|
|
|
253
343
|
// ── Hosted pages (INTERFACES §18.4) ────────────────────────────────────────────────────
|
|
254
344
|
|
|
345
|
+
// A route being removed serves nothing (its removal finishes on the next call).
|
|
255
346
|
const routeOf = (artifactId: string): { id: string; label: string } | undefined =>
|
|
256
347
|
directory.read((db) =>
|
|
257
348
|
db.get<{ id: string; label: string }>(
|
|
258
|
-
"SELECT id, label FROM artifact_route WHERE home_id = ? AND artifact_id = ?",
|
|
349
|
+
"SELECT id, label FROM artifact_route WHERE home_id = ? AND artifact_id = ? AND removing_json IS NULL",
|
|
259
350
|
id,
|
|
260
351
|
artifactId,
|
|
261
352
|
),
|
|
@@ -264,20 +355,44 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
264
355
|
directory.read(
|
|
265
356
|
(db) =>
|
|
266
357
|
db.get<{ artifact_id: string }>(
|
|
267
|
-
"SELECT artifact_id FROM artifact_route WHERE id = ? AND home_id = ?",
|
|
358
|
+
"SELECT artifact_id FROM artifact_route WHERE id = ? AND home_id = ? AND removing_json IS NULL",
|
|
268
359
|
routeId,
|
|
269
360
|
id,
|
|
270
361
|
)?.artifact_id,
|
|
271
362
|
);
|
|
272
363
|
const domains = [options.domains.active, ...options.domains.spares];
|
|
273
364
|
const originOf = (host: string): string => `${options.scheme}://${host}`;
|
|
365
|
+
/** The host of one of this server's origins, or `undefined` for another scheme. */
|
|
366
|
+
const hostOfOrigin = (origin: string): string | undefined =>
|
|
367
|
+
origin.startsWith(`${options.scheme}://`) ? origin.slice(options.scheme.length + 3) : undefined;
|
|
368
|
+
/** Whether a shell origin is this home's: a configured apex, or an operator host of it. */
|
|
369
|
+
const servesShell = (origin: string): boolean => {
|
|
370
|
+
const host = hostOfOrigin(origin);
|
|
371
|
+
if (host === undefined) return false;
|
|
372
|
+
return options.services
|
|
373
|
+
? options.services.routing.servesShell(id, host)
|
|
374
|
+
: domains.includes(host);
|
|
375
|
+
};
|
|
274
376
|
const capabilities: Capabilities = new Capabilities({
|
|
275
377
|
ledger,
|
|
276
378
|
log,
|
|
277
379
|
key: capabilityKey(dir, log),
|
|
278
380
|
now: () => Date.now(),
|
|
279
381
|
shellOrigin: () => originOf(options.domains.active),
|
|
280
|
-
servesShell
|
|
382
|
+
servesShell,
|
|
383
|
+
// Every hosted link is indexed in the directory, so the operator's `revokeLink` finds its home.
|
|
384
|
+
onMinted: ({ tokenId, artifactId }) => {
|
|
385
|
+
const route = routeOf(artifactId);
|
|
386
|
+
if (!route) return;
|
|
387
|
+
directory.write((db) =>
|
|
388
|
+
db.run(
|
|
389
|
+
"INSERT OR IGNORE INTO hosted_token (token_id, home_id, route_id) VALUES (?, ?, ?)",
|
|
390
|
+
tokenId,
|
|
391
|
+
id,
|
|
392
|
+
route.id,
|
|
393
|
+
),
|
|
394
|
+
);
|
|
395
|
+
},
|
|
281
396
|
});
|
|
282
397
|
// A hosted home binds nothing: its faces are served through the front. These answer the few
|
|
283
398
|
// questions the gateway asks of loopback addressing, none of which a hosted face reaches.
|
|
@@ -375,6 +490,8 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
375
490
|
shellDir: options.shellDir,
|
|
376
491
|
interaction,
|
|
377
492
|
bus,
|
|
493
|
+
// `roster/add` asks the operator's `limits` for the personal links it mints (D168).
|
|
494
|
+
linkLimit: (artifactId, count) => linkLimit(artifactId, count),
|
|
378
495
|
actions: relay,
|
|
379
496
|
live: hostedLive,
|
|
380
497
|
// Both channels: a hosted home has no host to narrow them (its owner is a host of it, D165).
|
|
@@ -382,13 +499,68 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
382
499
|
activated: () => undefined,
|
|
383
500
|
hosted: {
|
|
384
501
|
shellOrigin: () => originOf(options.domains.active),
|
|
385
|
-
servesShell
|
|
502
|
+
servesShell,
|
|
386
503
|
shellPath: (artifactId) => `/a/${routeOf(artifactId)?.id ?? artifactId}`,
|
|
387
504
|
artifactOrigin: (artifactId, shellOrigin) => {
|
|
388
505
|
const route = routeOf(artifactId);
|
|
389
|
-
const
|
|
390
|
-
|
|
506
|
+
const host = hostOfOrigin(shellOrigin);
|
|
507
|
+
if (!route || host === undefined) return undefined;
|
|
508
|
+
const frameDomain = options.services
|
|
509
|
+
? options.services.routing.frameDomainOf(id, route.id, host)
|
|
510
|
+
: domains.includes(host)
|
|
511
|
+
? host
|
|
512
|
+
: undefined;
|
|
513
|
+
return frameDomain === undefined ? undefined : originOf(`${route.label}.${frameDomain}`);
|
|
391
514
|
},
|
|
515
|
+
...(options.services
|
|
516
|
+
? {
|
|
517
|
+
// A new link goes on the operator's host for it when it names one that serves this
|
|
518
|
+
// route (D167, `routing.linkHost`), else on the active domain.
|
|
519
|
+
linkOrigin: async (artifactId: string) => {
|
|
520
|
+
const services = options.services as HostedServices;
|
|
521
|
+
const route = routeOf(artifactId);
|
|
522
|
+
if (!route || !services.operator.has.linkHost) return undefined;
|
|
523
|
+
const wanted = await services.operator.linkHost({
|
|
524
|
+
account: services.owner(id).account,
|
|
525
|
+
home: id,
|
|
526
|
+
routeId: route.id,
|
|
527
|
+
});
|
|
528
|
+
if (wanted === null) return undefined;
|
|
529
|
+
const host = await services.routing.linkHost(id, route.id, wanted);
|
|
530
|
+
return host === undefined ? undefined : originOf(host);
|
|
531
|
+
},
|
|
532
|
+
frameAncestors: (artifactId: string, frameOrigin: string) => {
|
|
533
|
+
const route = routeOf(artifactId);
|
|
534
|
+
const host = hostOfOrigin(frameOrigin);
|
|
535
|
+
if (!route || host === undefined) return "";
|
|
536
|
+
const frameDomain = host.slice(host.indexOf(".") + 1);
|
|
537
|
+
return (options.services as HostedServices).routing
|
|
538
|
+
.ancestorsOf(id, route.id, frameDomain)
|
|
539
|
+
.map(originOf)
|
|
540
|
+
.join(" ");
|
|
541
|
+
},
|
|
542
|
+
}
|
|
543
|
+
: {}),
|
|
544
|
+
...(options.services
|
|
545
|
+
? hostedPages({
|
|
546
|
+
homeId: id,
|
|
547
|
+
ledger,
|
|
548
|
+
interaction,
|
|
549
|
+
capabilities,
|
|
550
|
+
artifact: (artifactId) => registry.get({ artifactId }),
|
|
551
|
+
routeOf,
|
|
552
|
+
owner: () => (options.services as HostedServices).owner(id),
|
|
553
|
+
signInOffered: options.services.signInOffered,
|
|
554
|
+
operator: options.services.operator,
|
|
555
|
+
clients: options.services.clients,
|
|
556
|
+
rates: options.services.rates,
|
|
557
|
+
rateLimits: options.services.rateLimits,
|
|
558
|
+
madeWith: options.services.madeWith,
|
|
559
|
+
...(options.services.signin ? { signin: options.services.signin } : {}),
|
|
560
|
+
viewed: (input) => metered(input.artifactId, input.viewerId),
|
|
561
|
+
log,
|
|
562
|
+
})
|
|
563
|
+
: {}),
|
|
392
564
|
},
|
|
393
565
|
});
|
|
394
566
|
/** The faces of a domain: its shell, and a route's frames, opened when first asked for. */
|
|
@@ -469,6 +641,101 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
469
641
|
),
|
|
470
642
|
);
|
|
471
643
|
|
|
644
|
+
/**
|
|
645
|
+
* Quarantines a route's artifact, or one version of it, in this home only (D165 item 9): its
|
|
646
|
+
* links show the neutral "under review" page and its files are withheld; data is kept. An
|
|
647
|
+
* identical version in another home is untouched, since the row is this home's.
|
|
648
|
+
*/
|
|
649
|
+
const quarantine = (artifactId: string, versionId: string | undefined, reason: string): void => {
|
|
650
|
+
ledger.write((db) =>
|
|
651
|
+
db.run(
|
|
652
|
+
`INSERT INTO quarantine (artifact_id, version_id, reason, at) VALUES (?, ?, ?, ?)
|
|
653
|
+
ON CONFLICT (artifact_id, version_id) DO UPDATE SET reason = excluded.reason`,
|
|
654
|
+
artifactId,
|
|
655
|
+
versionId ?? "",
|
|
656
|
+
reason.slice(0, 1_000),
|
|
657
|
+
new Date().toISOString(),
|
|
658
|
+
),
|
|
659
|
+
);
|
|
660
|
+
log.info("server.quarantined", { home: id, artifactId, versionId: versionId ?? null });
|
|
661
|
+
};
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* New links on a hosted home under the operator's `limits` (`link`): `view/url`'s one, and the
|
|
665
|
+
* personal links `roster/add` mints (D168); refused with the operator's words, and refused for now
|
|
666
|
+
* when it doesn't answer, since a link creates something (D165 item 9).
|
|
667
|
+
*/
|
|
668
|
+
const linkLimit = async (artifactId: string, quantity?: number): Promise<void> => {
|
|
669
|
+
const services = options.services;
|
|
670
|
+
if (!services) return;
|
|
671
|
+
const route = routeOf(artifactId);
|
|
672
|
+
const verdict = await services.operator.limit({
|
|
673
|
+
account: services.owner(id).account,
|
|
674
|
+
home: id,
|
|
675
|
+
artifact: artifactId,
|
|
676
|
+
...(route ? { routeId: route.id } : {}),
|
|
677
|
+
operation: "link",
|
|
678
|
+
...(quantity !== undefined ? { quantity } : {}),
|
|
679
|
+
});
|
|
680
|
+
if (verdict.allowed === "unavailable") {
|
|
681
|
+
throw refuse(
|
|
682
|
+
"MOSTRA_REMOTE_OPERATOR_UNAVAILABLE",
|
|
683
|
+
"The server's operator didn't answer in time; try minting the link again.",
|
|
684
|
+
);
|
|
685
|
+
}
|
|
686
|
+
if (verdict.allowed === false) throw refuse("MOSTRA_REMOTE_LIMIT_REACHED", verdict.message);
|
|
687
|
+
};
|
|
688
|
+
const limitedLinks = (method: MethodHandler): MethodHandler => ({
|
|
689
|
+
definition: method.definition,
|
|
690
|
+
async handle(params, session) {
|
|
691
|
+
const ref = (params as { artifact?: unknown }).artifact;
|
|
692
|
+
await linkLimit(registry.get(canonicalRef(ref as never)).id);
|
|
693
|
+
return method.handle(params, session);
|
|
694
|
+
},
|
|
695
|
+
});
|
|
696
|
+
|
|
697
|
+
/**
|
|
698
|
+
* A view for metering, under the viewer's monthly pseudonymous key (D167): the account for a
|
|
699
|
+
* signed-in viewer, the viewer for a link minted with one, the route's key for anyone else.
|
|
700
|
+
*/
|
|
701
|
+
const metered = (artifactId: string, viewerId: string): void => {
|
|
702
|
+
const meter = options.services?.meter;
|
|
703
|
+
if (!meter?.on) return;
|
|
704
|
+
const viewer = ledger.read((db) =>
|
|
705
|
+
db.get<{ kind: string; external_ref: string | null }>(
|
|
706
|
+
"SELECT kind, external_ref FROM viewer WHERE id = ?",
|
|
707
|
+
viewerId,
|
|
708
|
+
),
|
|
709
|
+
);
|
|
710
|
+
const subject =
|
|
711
|
+
viewer?.kind === "account" || viewer?.kind === "anonymous"
|
|
712
|
+
? `${viewer.kind}:${viewer.external_ref ?? viewerId}`
|
|
713
|
+
: `viewer:${id}:${viewerId}`;
|
|
714
|
+
const route = routeOf(artifactId);
|
|
715
|
+
meter.add("views", {
|
|
716
|
+
account: (options.services as HostedServices).owner(id).account,
|
|
717
|
+
home: id,
|
|
718
|
+
artifactId,
|
|
719
|
+
...(route ? { routeId: route.id } : {}),
|
|
720
|
+
dimensions: { viewerKey: meter.viewerKey(subject) },
|
|
721
|
+
});
|
|
722
|
+
};
|
|
723
|
+
|
|
724
|
+
/** The live links of an artifact, revoked; answers how many were live. */
|
|
725
|
+
const revokeLinks = (artifactId: string): number => {
|
|
726
|
+
const tokens = ledger.read((db) =>
|
|
727
|
+
db
|
|
728
|
+
.all<{ id: string }>(
|
|
729
|
+
"SELECT id FROM token WHERE artifact_id = ? AND revoked_at IS NULL",
|
|
730
|
+
artifactId,
|
|
731
|
+
)
|
|
732
|
+
.map((row) => row.id),
|
|
733
|
+
);
|
|
734
|
+
let revoked = 0;
|
|
735
|
+
for (const tokenId of tokens) if (capabilities.revoke(tokenId) === "revoked") revoked += 1;
|
|
736
|
+
return revoked;
|
|
737
|
+
};
|
|
738
|
+
|
|
472
739
|
const push = async (params: HostedPushParams, session: Session): Promise<HostedPushResult> => {
|
|
473
740
|
const link = session.link?.instanceId;
|
|
474
741
|
if (link === undefined || session.attributes["linkId"] !== link) {
|
|
@@ -527,6 +794,24 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
527
794
|
if (!manifest.success)
|
|
528
795
|
throw refuse("MOSTRA_HOME_INTEGRITY", "The pushed artifact manifest isn't valid.");
|
|
529
796
|
|
|
797
|
+
const services = options.services;
|
|
798
|
+
// A first push hosts the artifact: the operator's `limits` judge it as a share, failing
|
|
799
|
+
// closed when it doesn't answer (D165 item 9).
|
|
800
|
+
if (services && routeOf(params.artifactId) === undefined) {
|
|
801
|
+
const verdict = await services.operator.limit({
|
|
802
|
+
account: services.owner(id).account,
|
|
803
|
+
home: id,
|
|
804
|
+
artifact: params.artifactId,
|
|
805
|
+
operation: "share",
|
|
806
|
+
});
|
|
807
|
+
if (verdict.allowed === "unavailable") {
|
|
808
|
+
throw refuse(
|
|
809
|
+
"MOSTRA_REMOTE_OPERATOR_UNAVAILABLE",
|
|
810
|
+
"The server's operator didn't answer in time; the share is tried again later.",
|
|
811
|
+
);
|
|
812
|
+
}
|
|
813
|
+
if (verdict.allowed === false) throw refuse("MOSTRA_REMOTE_LIMIT_REACHED", verdict.message);
|
|
814
|
+
}
|
|
530
815
|
const route = routeFor(params.artifactId, link);
|
|
531
816
|
if (registry.hasVersion(version.versionId)) {
|
|
532
817
|
const known = registry
|
|
@@ -541,9 +826,66 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
541
826
|
}
|
|
542
827
|
// Only client files are stored: server code never reaches the server (D165 item 3).
|
|
543
828
|
const clientFiles = version.listing.filter(([path]) => path.startsWith("client/"));
|
|
829
|
+
// The sizes a listing gives are what the storage limit is asked with, so each is held to the
|
|
830
|
+
// bytes: one file has one size, a file this home holds already has the size it has on disk, and
|
|
831
|
+
// an upload brings exactly the size given (Fable review of WP-30, 2).
|
|
832
|
+
const sizes = new Map<string, number>();
|
|
833
|
+
for (const [path, , sha, size] of clientFiles) {
|
|
834
|
+
if (!Number.isSafeInteger(size) || size < 0 || (sizes.get(sha) ?? size) !== size) {
|
|
835
|
+
throw refuse(
|
|
836
|
+
"MOSTRA_HOME_INTEGRITY",
|
|
837
|
+
`The listing gives ${path} a size its bytes can't have.`,
|
|
838
|
+
);
|
|
839
|
+
}
|
|
840
|
+
sizes.set(sha, size);
|
|
841
|
+
}
|
|
842
|
+
for (const [sha, size] of sizes) {
|
|
843
|
+
const held = directory.read((db) =>
|
|
844
|
+
db.get("SELECT 1 FROM home_file WHERE home_id = ? AND sha256 = ?", id, sha),
|
|
845
|
+
);
|
|
846
|
+
if (held === undefined) continue;
|
|
847
|
+
const onDisk = await stat(join(options.filesDir, sha)).then(
|
|
848
|
+
(found) => found.size,
|
|
849
|
+
() => undefined,
|
|
850
|
+
);
|
|
851
|
+
if (onDisk !== undefined && onDisk !== size) {
|
|
852
|
+
throw refuse(
|
|
853
|
+
"MOSTRA_HOME_INTEGRITY",
|
|
854
|
+
"The listing gives a held file another size than its bytes.",
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
// The operator's `limits` on a push and the bytes it stores: refused for good with its words,
|
|
859
|
+
// and refused for now (fail closed) when the operator doesn't answer (D165 item 9).
|
|
860
|
+
if (services) {
|
|
861
|
+
const owner = services.owner(id).account;
|
|
862
|
+
for (const [operation, quantity] of [
|
|
863
|
+
["version.push", 1],
|
|
864
|
+
["storage", [...sizes.values()].reduce((sum, size) => sum + size, 0)],
|
|
865
|
+
] as const) {
|
|
866
|
+
const verdict = await services.operator.limit({
|
|
867
|
+
account: owner,
|
|
868
|
+
home: id,
|
|
869
|
+
artifact: params.artifactId,
|
|
870
|
+
routeId: route.routeId,
|
|
871
|
+
operation,
|
|
872
|
+
quantity,
|
|
873
|
+
});
|
|
874
|
+
if (verdict.allowed === "unavailable") {
|
|
875
|
+
throw refuse(
|
|
876
|
+
"MOSTRA_REMOTE_OPERATOR_UNAVAILABLE",
|
|
877
|
+
"The server's operator didn't answer in time; the push is tried again later.",
|
|
878
|
+
);
|
|
879
|
+
}
|
|
880
|
+
if (verdict.allowed === false) throw refuse("MOSTRA_REMOTE_LIMIT_REACHED", verdict.message);
|
|
881
|
+
}
|
|
882
|
+
}
|
|
544
883
|
const missing = missingOf([...new Set(clientFiles.map(([, , sha]) => sha))]);
|
|
545
884
|
if (missing.length > 0) {
|
|
546
|
-
pending.set(
|
|
885
|
+
pending.set(
|
|
886
|
+
version.versionId,
|
|
887
|
+
new Map(missing.map((sha) => [sha, sizes.get(sha) as number])),
|
|
888
|
+
);
|
|
547
889
|
return { status: "missing", files: missing, route };
|
|
548
890
|
}
|
|
549
891
|
pending.delete(version.versionId);
|
|
@@ -615,6 +957,31 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
615
957
|
artifactId: params.artifactId,
|
|
616
958
|
versionId: version.versionId,
|
|
617
959
|
});
|
|
960
|
+
// The operator's after-push hook reads the client files; its answer can quarantine the
|
|
961
|
+
// version afterwards, never holding up serving it (D165 item 9).
|
|
962
|
+
if (services?.operator.has.pushed) {
|
|
963
|
+
const files = clientFiles.map(([path]) => path);
|
|
964
|
+
const shaOf = new Map(clientFiles.map(([path, , sha]) => [path, sha]));
|
|
965
|
+
services.operator.pushed(
|
|
966
|
+
{
|
|
967
|
+
routeId: route.routeId,
|
|
968
|
+
label: route.label,
|
|
969
|
+
artifactId: params.artifactId,
|
|
970
|
+
home: id,
|
|
971
|
+
versionId: version.versionId,
|
|
972
|
+
manifest: manifest.data,
|
|
973
|
+
files,
|
|
974
|
+
read: async (path) => {
|
|
975
|
+
const sha = shaOf.get(path);
|
|
976
|
+
if (sha === undefined) throw new Error(`No client file ${path} in this version.`);
|
|
977
|
+
return new Uint8Array(await readFile(join(options.filesDir, sha)));
|
|
978
|
+
},
|
|
979
|
+
},
|
|
980
|
+
async (reason) => {
|
|
981
|
+
quarantine(params.artifactId, version.versionId, reason);
|
|
982
|
+
},
|
|
983
|
+
);
|
|
984
|
+
}
|
|
618
985
|
return { status: "complete", versionId: version.versionId, number: committed.version, route };
|
|
619
986
|
};
|
|
620
987
|
|
|
@@ -726,7 +1093,21 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
726
1093
|
}
|
|
727
1094
|
return envelope;
|
|
728
1095
|
}),
|
|
729
|
-
...gateway
|
|
1096
|
+
...gateway
|
|
1097
|
+
.methods()
|
|
1098
|
+
.map((method) =>
|
|
1099
|
+
method.definition.method === viewUrlMethod.method ? limitedLinks(method) : method,
|
|
1100
|
+
),
|
|
1101
|
+
handler(artifactPauseMethod, (params) => {
|
|
1102
|
+
// The account's own instances pause and resume as the owner; only the operator, through
|
|
1103
|
+
// its handle, resumes an operator's pause (D165 item 14).
|
|
1104
|
+
const artifactId = registry.get(canonicalRef(params.artifact)).id;
|
|
1105
|
+
return interaction.pause(artifactId, {
|
|
1106
|
+
paused: params.paused,
|
|
1107
|
+
by: "owner",
|
|
1108
|
+
...(params.reason !== undefined ? { reason: params.reason } : {}),
|
|
1109
|
+
});
|
|
1110
|
+
}),
|
|
730
1111
|
...relay.methods(),
|
|
731
1112
|
...liveMethods(live, (ref) => registry.get(canonicalRef(ref)).id),
|
|
732
1113
|
handler(remoteTokenMethod, (params, session) => {
|
|
@@ -747,6 +1128,27 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
747
1128
|
});
|
|
748
1129
|
interaction.start();
|
|
749
1130
|
live.start();
|
|
1131
|
+
// The operator's feed of this home's events, and its submissions for metering (§18.6).
|
|
1132
|
+
const feed: OperatorFeed | undefined = options.services
|
|
1133
|
+
? createOperatorFeed({
|
|
1134
|
+
homeId: id,
|
|
1135
|
+
ledger,
|
|
1136
|
+
interaction,
|
|
1137
|
+
operator: options.services.operator,
|
|
1138
|
+
meter: options.services.meter,
|
|
1139
|
+
account: () => (options.services as HostedServices).owner(id).account,
|
|
1140
|
+
sender: () => {
|
|
1141
|
+
const owner = (options.services as HostedServices).owner(id);
|
|
1142
|
+
return {
|
|
1143
|
+
...(owner.name !== undefined ? { name: owner.name } : {}),
|
|
1144
|
+
...(owner.verifiedBy !== undefined ? { verifiedBy: owner.verifiedBy } : {}),
|
|
1145
|
+
};
|
|
1146
|
+
},
|
|
1147
|
+
routeOf,
|
|
1148
|
+
incarnation: () => incarnation,
|
|
1149
|
+
log,
|
|
1150
|
+
})
|
|
1151
|
+
: undefined;
|
|
750
1152
|
|
|
751
1153
|
return {
|
|
752
1154
|
id,
|
|
@@ -756,7 +1158,13 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
756
1158
|
interaction,
|
|
757
1159
|
protocol,
|
|
758
1160
|
incarnation: () => incarnation,
|
|
759
|
-
wanted: (sha) =>
|
|
1161
|
+
wanted: (sha) => {
|
|
1162
|
+
for (const files of pending.values()) {
|
|
1163
|
+
const size = files.get(sha);
|
|
1164
|
+
if (size !== undefined) return size;
|
|
1165
|
+
}
|
|
1166
|
+
return undefined;
|
|
1167
|
+
},
|
|
760
1168
|
uploaded(sha) {
|
|
761
1169
|
directory.write((db) => {
|
|
762
1170
|
const added = db.run(
|
|
@@ -773,9 +1181,134 @@ export async function openHostedHome(options: HostedHomeOptions): Promise<Hosted
|
|
|
773
1181
|
});
|
|
774
1182
|
for (const files of pending.values()) files.delete(sha);
|
|
775
1183
|
},
|
|
1184
|
+
pause: (artifactId, change) => interaction.pause(artifactId, change),
|
|
1185
|
+
quarantine,
|
|
1186
|
+
release(artifactId, versionId) {
|
|
1187
|
+
ledger.write((db) =>
|
|
1188
|
+
db.run(
|
|
1189
|
+
versionId === undefined
|
|
1190
|
+
? "DELETE FROM quarantine WHERE artifact_id = ?"
|
|
1191
|
+
: "DELETE FROM quarantine WHERE artifact_id = ? AND version_id = ?",
|
|
1192
|
+
...(versionId === undefined ? [artifactId] : [artifactId, versionId]),
|
|
1193
|
+
),
|
|
1194
|
+
);
|
|
1195
|
+
},
|
|
1196
|
+
revokeLinks,
|
|
1197
|
+
revokeLink: (tokenId) => capabilities.revoke(tokenId) !== "unknown",
|
|
1198
|
+
invitationLink(tokenId) {
|
|
1199
|
+
const grant = capabilities.grant(tokenId);
|
|
1200
|
+
if (!grant?.live) return undefined;
|
|
1201
|
+
const url = gateway.reveal(tokenId);
|
|
1202
|
+
if (url === undefined) return undefined;
|
|
1203
|
+
return { url, ...(grant.expiresAt !== undefined ? { expiresAt: grant.expiresAt } : {}) };
|
|
1204
|
+
},
|
|
1205
|
+
async remove(artifactId) {
|
|
1206
|
+
/** The client files a version's listing names. */
|
|
1207
|
+
const clientFilesOf = async (versionId: string): Promise<string[]> => {
|
|
1208
|
+
try {
|
|
1209
|
+
const listing = JSON.parse(
|
|
1210
|
+
await readFile(join(registry.store.versionDir(versionId), "listing.json"), "utf8"),
|
|
1211
|
+
) as [string, boolean, string, number][];
|
|
1212
|
+
return listing.filter(([path]) => path.startsWith("client/")).map(([, , sha]) => sha);
|
|
1213
|
+
} catch {
|
|
1214
|
+
return [];
|
|
1215
|
+
}
|
|
1216
|
+
};
|
|
1217
|
+
// The plan is recorded in the directory before anything goes, so a removal cut off between
|
|
1218
|
+
// the two databases is finished by the next call, from the same plan (Fable review, 4).
|
|
1219
|
+
const recorded = directory.read(
|
|
1220
|
+
(db) =>
|
|
1221
|
+
db.get<{ removing_json: string | null }>(
|
|
1222
|
+
"SELECT removing_json FROM artifact_route WHERE home_id = ? AND artifact_id = ?",
|
|
1223
|
+
id,
|
|
1224
|
+
artifactId,
|
|
1225
|
+
)?.removing_json,
|
|
1226
|
+
);
|
|
1227
|
+
let plan: { readonly versions: string[]; readonly going: string[] };
|
|
1228
|
+
if (recorded != null) plan = JSON.parse(recorded) as typeof plan;
|
|
1229
|
+
else {
|
|
1230
|
+
const versions = registry.get({ artifactId }).versions.map((version) => version.id);
|
|
1231
|
+
const files = new Set<string>();
|
|
1232
|
+
for (const versionId of versions)
|
|
1233
|
+
for (const sha of await clientFilesOf(versionId)) files.add(sha);
|
|
1234
|
+
plan = { versions, going: [...files] };
|
|
1235
|
+
directory.write((db) =>
|
|
1236
|
+
db.run(
|
|
1237
|
+
"UPDATE artifact_route SET removing_json = ? WHERE home_id = ? AND artifact_id = ?",
|
|
1238
|
+
JSON.stringify(plan),
|
|
1239
|
+
id,
|
|
1240
|
+
artifactId,
|
|
1241
|
+
),
|
|
1242
|
+
);
|
|
1243
|
+
}
|
|
1244
|
+
const versions = plan.versions;
|
|
1245
|
+
const going = new Set(plan.going);
|
|
1246
|
+
if (registry.list({}).some((summary) => summary.id === artifactId)) revokeLinks(artifactId);
|
|
1247
|
+
const removed = ledger.removal((db) => purgeArtifact(db, artifactId));
|
|
1248
|
+
// A test cuts the removal off here, between its two databases (`remove:after-purge`).
|
|
1249
|
+
faults.at("remove:after-purge");
|
|
1250
|
+
// Files another version of this home still names stay this home's.
|
|
1251
|
+
const kept = new Set<string>();
|
|
1252
|
+
for (const other of registry.list({})) {
|
|
1253
|
+
for (const version of registry.get({ artifactId: other.id }).versions) {
|
|
1254
|
+
for (const sha of await clientFilesOf(version.id)) kept.add(sha);
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
const route = directory.read((db) =>
|
|
1258
|
+
db.get<{ id: string }>(
|
|
1259
|
+
"SELECT id FROM artifact_route WHERE home_id = ? AND artifact_id = ?",
|
|
1260
|
+
id,
|
|
1261
|
+
artifactId,
|
|
1262
|
+
),
|
|
1263
|
+
);
|
|
1264
|
+
directory.write((db) => {
|
|
1265
|
+
for (const sha of going) {
|
|
1266
|
+
if (kept.has(sha)) continue;
|
|
1267
|
+
if (
|
|
1268
|
+
db.run("DELETE FROM home_file WHERE home_id = ? AND sha256 = ?", id, sha).changes > 0
|
|
1269
|
+
) {
|
|
1270
|
+
db.run(
|
|
1271
|
+
`UPDATE file_ref SET homes = homes - 1,
|
|
1272
|
+
unreferenced_at = CASE WHEN homes - 1 = 0 THEN ? ELSE NULL END
|
|
1273
|
+
WHERE sha256 = ?`,
|
|
1274
|
+
new Date().toISOString(),
|
|
1275
|
+
sha,
|
|
1276
|
+
);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
if (route) {
|
|
1280
|
+
db.run("DELETE FROM hosted_token WHERE route_id = ?", route.id);
|
|
1281
|
+
// The route goes; its label stays in `label_issued`, never issued again.
|
|
1282
|
+
db.run("DELETE FROM artifact_route WHERE id = ?", route.id);
|
|
1283
|
+
}
|
|
1284
|
+
});
|
|
1285
|
+
for (const versionId of versions) {
|
|
1286
|
+
await removeTree(registry.store.versionDir(versionId)).catch((error: unknown) =>
|
|
1287
|
+
log.warn("server.remove_files_failed", { versionId, error }),
|
|
1288
|
+
);
|
|
1289
|
+
}
|
|
1290
|
+
const rows = Object.values(removed).reduce((sum, count) => sum + count, 0);
|
|
1291
|
+
log.info("server.artifact_removed", { home: id, artifactId, rows });
|
|
1292
|
+
return { rows };
|
|
1293
|
+
},
|
|
1294
|
+
defaultOwnerSession() {
|
|
1295
|
+
const link = directory.read(
|
|
1296
|
+
(db) =>
|
|
1297
|
+
db.get<{ id: string }>(
|
|
1298
|
+
"SELECT id FROM instance_link WHERE home_id = ? AND is_default = 1 AND revoked_at IS NULL",
|
|
1299
|
+
id,
|
|
1300
|
+
)?.id,
|
|
1301
|
+
);
|
|
1302
|
+
if (link === undefined) return undefined;
|
|
1303
|
+
return protocol
|
|
1304
|
+
.registrants("relay")
|
|
1305
|
+
.filter((entry) => entry.owner === link)
|
|
1306
|
+
.at(-1)?.session;
|
|
1307
|
+
},
|
|
776
1308
|
busy: () => protocol.connections > 0 || bus.activeViews() > 0 || relay.busy(),
|
|
777
1309
|
serve,
|
|
778
1310
|
async stop() {
|
|
1311
|
+
feed?.stop();
|
|
779
1312
|
relay.stop();
|
|
780
1313
|
live.stop();
|
|
781
1314
|
interaction.stop();
|