@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/link/manager.ts
CHANGED
|
@@ -26,17 +26,22 @@ import {
|
|
|
26
26
|
type HostedRoute,
|
|
27
27
|
hostedPushMethod,
|
|
28
28
|
hostedSubmissionMethod,
|
|
29
|
+
LinkId,
|
|
29
30
|
type ListingEntry,
|
|
30
31
|
type MethodDefinition,
|
|
32
|
+
portRelayAuthorMethod,
|
|
31
33
|
portSubmissionsDeliverMethod,
|
|
32
34
|
type RemoteLink,
|
|
35
|
+
type RemoteLinkResult,
|
|
33
36
|
type RemoteLoginResult,
|
|
34
37
|
RpcError,
|
|
38
|
+
remoteLinkMethod,
|
|
35
39
|
remoteLoginMethod,
|
|
36
40
|
remoteLoginWaitMethod,
|
|
37
41
|
remoteLogoutMethod,
|
|
38
42
|
remoteStatusMethod,
|
|
39
43
|
remoteTokenMethod,
|
|
44
|
+
rosterAddMethod,
|
|
40
45
|
type ServerLiveValueParams,
|
|
41
46
|
SubmissionEnvelope,
|
|
42
47
|
type SubmissionPolicy,
|
|
@@ -126,11 +131,17 @@ function loginFailed(message: string): RpcError {
|
|
|
126
131
|
}
|
|
127
132
|
|
|
128
133
|
/** What the link keeps for a server in `<home>/keys/remote/<server key>.json` (DATA_MODEL §7.3). */
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
+
/**
|
|
135
|
+
* How this home signs in to a server: a person's sign-in (the device grant's refresh token, rotated
|
|
136
|
+
* at every use) or a key the server's operator issued (`remote/link`, D167), used as is.
|
|
137
|
+
*/
|
|
138
|
+
type Credentials =
|
|
139
|
+
| { readonly server: string; readonly instanceId: string; readonly refreshToken: string }
|
|
140
|
+
| { readonly server: string; readonly instanceId: string; readonly key: string };
|
|
141
|
+
|
|
142
|
+
/** The secret a home's credentials hold. */
|
|
143
|
+
const credentialSecret = (credentials: Credentials): string =>
|
|
144
|
+
"key" in credentials ? credentials.key : credentials.refreshToken;
|
|
134
145
|
|
|
135
146
|
/** A `remote_link` row. */
|
|
136
147
|
interface LinkRow {
|
|
@@ -166,6 +177,8 @@ export interface LinkOptions {
|
|
|
166
177
|
readonly actions: OwnerRelayOptions["actions"];
|
|
167
178
|
/** Hosted pages' live interest changed. */
|
|
168
179
|
readonly liveChanged?: () => void;
|
|
180
|
+
/** Answers remote MCP's relayed authoring (`port/relay.author`, D165 item 5). */
|
|
181
|
+
readonly author?: (server: string, params: unknown) => Promise<unknown>;
|
|
169
182
|
/** The clock (tests move it). */
|
|
170
183
|
readonly now?: () => number;
|
|
171
184
|
}
|
|
@@ -209,6 +222,8 @@ export interface Link {
|
|
|
209
222
|
* first it was shared to.
|
|
210
223
|
*/
|
|
211
224
|
hostedOn(artifactId: string): string | undefined;
|
|
225
|
+
/** Every server an artifact is hosted on now, in the order it was shared to them. */
|
|
226
|
+
hostedServers(artifactId: string): string[];
|
|
212
227
|
/**
|
|
213
228
|
* Calls a method on a server's hosted home for this home's client: a hosted artifact's
|
|
214
229
|
* `state/*` and `live/push` (D165 item 1). `MOSTRA_REMOTE_UNREACHABLE` when it can't be reached.
|
|
@@ -272,8 +287,11 @@ export function createLink(options: LinkOptions): Link {
|
|
|
272
287
|
if (!existsSync(file)) return undefined;
|
|
273
288
|
try {
|
|
274
289
|
const parsed = JSON.parse(readFileSync(file, "utf8")) as Credentials;
|
|
275
|
-
|
|
276
|
-
|
|
290
|
+
const secret =
|
|
291
|
+
(parsed as { refreshToken?: unknown; key?: unknown }).refreshToken ??
|
|
292
|
+
(parsed as { key?: unknown }).key;
|
|
293
|
+
if (parsed.server !== server || typeof secret !== "string") return undefined;
|
|
294
|
+
options.protect(secret);
|
|
277
295
|
return parsed;
|
|
278
296
|
} catch {
|
|
279
297
|
return undefined;
|
|
@@ -281,7 +299,7 @@ export function createLink(options: LinkOptions): Link {
|
|
|
281
299
|
};
|
|
282
300
|
const writeCredentials = (credentials: Credentials): void => {
|
|
283
301
|
mkdirSync(keysDir, { recursive: true, mode: 0o700 });
|
|
284
|
-
options.protect(credentials
|
|
302
|
+
options.protect(credentialSecret(credentials));
|
|
285
303
|
// Written beside it, then renamed: a crash never leaves half a token (as secrets are, D131).
|
|
286
304
|
const target = credentialsFile(credentials.server);
|
|
287
305
|
const temporary = `${target}.${process.pid}.tmp`;
|
|
@@ -318,6 +336,17 @@ export function createLink(options: LinkOptions): Link {
|
|
|
318
336
|
const secret = /#t=([^&]+)/.exec(url)?.[1];
|
|
319
337
|
if (secret !== undefined) options.protect(secret);
|
|
320
338
|
};
|
|
339
|
+
/** Protects every capability link a value holds, at any depth. */
|
|
340
|
+
const protectLinksIn = (value: unknown, depth = 0): void => {
|
|
341
|
+
if (depth > 16) return;
|
|
342
|
+
if (typeof value === "string") {
|
|
343
|
+
if (value.includes("#t=")) protectLink(value);
|
|
344
|
+
} else if (Array.isArray(value)) {
|
|
345
|
+
for (const item of value) protectLinksIn(item, depth + 1);
|
|
346
|
+
} else if (value !== null && typeof value === "object") {
|
|
347
|
+
for (const item of Object.values(value)) protectLinksIn(item, depth + 1);
|
|
348
|
+
}
|
|
349
|
+
};
|
|
321
350
|
|
|
322
351
|
const linkRow = (db: LedgerDb, server: string): LinkRow | undefined =>
|
|
323
352
|
db.get<LinkRow>("SELECT * FROM remote_link WHERE server = ?", server);
|
|
@@ -343,6 +372,9 @@ export function createLink(options: LinkOptions): Link {
|
|
|
343
372
|
try {
|
|
344
373
|
const credentials = readCredentials(connection.server);
|
|
345
374
|
if (!credentials) throw loginFailed(`This home isn't signed in to ${connection.server}.`);
|
|
375
|
+
// An operator's key is the bearer itself: nothing to refresh, and the server asks the
|
|
376
|
+
// operator again while the binding is open.
|
|
377
|
+
if ("key" in credentials) return credentials.key;
|
|
346
378
|
const answer = await postForm(
|
|
347
379
|
connection.server,
|
|
348
380
|
"/oauth/token",
|
|
@@ -555,6 +587,16 @@ export function createLink(options: LinkOptions): Link {
|
|
|
555
587
|
const onRequest =
|
|
556
588
|
(connection: Connection) =>
|
|
557
589
|
(method: string, params: unknown): unknown => {
|
|
590
|
+
if (method === portRelayAuthorMethod.method) {
|
|
591
|
+
if (!options.author) {
|
|
592
|
+
throw new RpcError(
|
|
593
|
+
createDiagnostic("MOSTRA_REMOTE_NO_INSTANCE", {
|
|
594
|
+
message: "This instance takes no authoring from a chat host.",
|
|
595
|
+
}),
|
|
596
|
+
);
|
|
597
|
+
}
|
|
598
|
+
return options.author(connection.server, params);
|
|
599
|
+
}
|
|
558
600
|
if (relay.handles(method)) {
|
|
559
601
|
return relay.request(
|
|
560
602
|
connection.server,
|
|
@@ -960,6 +1002,91 @@ export function createLink(options: LinkOptions): Link {
|
|
|
960
1002
|
return last.server;
|
|
961
1003
|
};
|
|
962
1004
|
|
|
1005
|
+
/** Records this home's link to a server, rebinding its marks only to the same link (WP-29). */
|
|
1006
|
+
const recordLink = (
|
|
1007
|
+
server: string,
|
|
1008
|
+
account: { readonly id: string; readonly name?: string | undefined },
|
|
1009
|
+
instanceId: string,
|
|
1010
|
+
isDefault: boolean,
|
|
1011
|
+
): void => {
|
|
1012
|
+
ledger.write((db) =>
|
|
1013
|
+
db.run(
|
|
1014
|
+
`INSERT INTO remote_link (server, account_id, account_name, instance_id, is_default, linked_at, state)
|
|
1015
|
+
VALUES (?, ?, ?, ?, ?, ?, 'signed-in')
|
|
1016
|
+
ON CONFLICT (server) DO UPDATE SET
|
|
1017
|
+
-- Another link (after --forget, or another account) starts with no marks: a mark
|
|
1018
|
+
-- of the old link would make the new one's home look restored (Opus review of
|
|
1019
|
+
-- WP-29, 9).
|
|
1020
|
+
relay_mark = CASE WHEN remote_link.instance_id IS excluded.instance_id
|
|
1021
|
+
AND remote_link.account_id = excluded.account_id THEN remote_link.relay_mark ELSE 0 END,
|
|
1022
|
+
follow_cursor = CASE WHEN remote_link.instance_id IS excluded.instance_id
|
|
1023
|
+
AND remote_link.account_id = excluded.account_id THEN remote_link.follow_cursor ELSE NULL END,
|
|
1024
|
+
incarnation = CASE WHEN remote_link.instance_id IS excluded.instance_id
|
|
1025
|
+
AND remote_link.account_id = excluded.account_id THEN remote_link.incarnation ELSE NULL END,
|
|
1026
|
+
account_id = excluded.account_id, account_name = excluded.account_name,
|
|
1027
|
+
instance_id = excluded.instance_id, is_default = excluded.is_default, linked_at = excluded.linked_at,
|
|
1028
|
+
state = 'signed-in'`,
|
|
1029
|
+
server,
|
|
1030
|
+
account.id,
|
|
1031
|
+
account.name ?? null,
|
|
1032
|
+
instanceId,
|
|
1033
|
+
isDefault ? 1 : 0,
|
|
1034
|
+
new Date(now()).toISOString(),
|
|
1035
|
+
),
|
|
1036
|
+
);
|
|
1037
|
+
};
|
|
1038
|
+
|
|
1039
|
+
/**
|
|
1040
|
+
* Links this home with a key the server's operator issued (`remote/link`, D167): the server says
|
|
1041
|
+
* which account and instance link the key binds, the key is kept like a refresh token, and the
|
|
1042
|
+
* binding opens with it at once.
|
|
1043
|
+
*/
|
|
1044
|
+
const linkWithKey = async (
|
|
1045
|
+
requested: string,
|
|
1046
|
+
key: string,
|
|
1047
|
+
makeDefault: boolean,
|
|
1048
|
+
): Promise<RemoteLinkResult> => {
|
|
1049
|
+
const server = serverOrigin(requested);
|
|
1050
|
+
options.protect(key);
|
|
1051
|
+
const answer = await postForm(
|
|
1052
|
+
server,
|
|
1053
|
+
"/link",
|
|
1054
|
+
makeDefault ? { default: "1" } : {},
|
|
1055
|
+
connectTo,
|
|
1056
|
+
key,
|
|
1057
|
+
);
|
|
1058
|
+
const account = answer.json["account"] as { id?: unknown; name?: unknown } | undefined;
|
|
1059
|
+
const instanceId = answer.json["instanceId"];
|
|
1060
|
+
if (
|
|
1061
|
+
answer.status !== 200 ||
|
|
1062
|
+
typeof account?.id !== "string" ||
|
|
1063
|
+
typeof instanceId !== "string" ||
|
|
1064
|
+
!LinkId.is(instanceId)
|
|
1065
|
+
) {
|
|
1066
|
+
throw loginFailed(
|
|
1067
|
+
`${server} didn't admit this key (${String(answer.json["message"] ?? answer.status)}).`,
|
|
1068
|
+
);
|
|
1069
|
+
}
|
|
1070
|
+
const name = typeof account.name === "string" ? account.name : undefined;
|
|
1071
|
+
const isDefault = answer.json["default"] === true;
|
|
1072
|
+
writeCredentials({ server, key, instanceId });
|
|
1073
|
+
recordLink(server, { id: account.id, name }, instanceId, isDefault);
|
|
1074
|
+
const previous = connections.get(server);
|
|
1075
|
+
if (previous) {
|
|
1076
|
+
await previous.binding.stop();
|
|
1077
|
+
if (previous.refreshTimer) clearTimeout(previous.refreshTimer);
|
|
1078
|
+
connections.delete(server);
|
|
1079
|
+
}
|
|
1080
|
+
connect(server);
|
|
1081
|
+
log.info("link.linked_with_key", { server, instanceId });
|
|
1082
|
+
return {
|
|
1083
|
+
server,
|
|
1084
|
+
account: { id: account.id, ...(name !== undefined ? { name } : {}) },
|
|
1085
|
+
instanceId,
|
|
1086
|
+
default: isDefault,
|
|
1087
|
+
};
|
|
1088
|
+
};
|
|
1089
|
+
|
|
963
1090
|
/** Starts a sign-in: the device grant's code, then polls for the token in the background. */
|
|
964
1091
|
const login = async (
|
|
965
1092
|
requested: string | undefined,
|
|
@@ -1047,31 +1174,7 @@ export function createLink(options: LinkOptions): Link {
|
|
|
1047
1174
|
const accessToken = String(answer.json["access_token"]);
|
|
1048
1175
|
options.protect(accessToken);
|
|
1049
1176
|
writeCredentials({ server, refreshToken, instanceId });
|
|
1050
|
-
|
|
1051
|
-
db.run(
|
|
1052
|
-
`INSERT INTO remote_link (server, account_id, account_name, instance_id, is_default, linked_at, state)
|
|
1053
|
-
VALUES (?, ?, ?, ?, ?, ?, 'signed-in')
|
|
1054
|
-
ON CONFLICT (server) DO UPDATE SET
|
|
1055
|
-
-- Another link (after --forget, or another account) starts with no marks: a mark
|
|
1056
|
-
-- of the old link would make the new one's home look restored (Opus review of
|
|
1057
|
-
-- WP-29, 9).
|
|
1058
|
-
relay_mark = CASE WHEN remote_link.instance_id IS excluded.instance_id
|
|
1059
|
-
AND remote_link.account_id = excluded.account_id THEN remote_link.relay_mark ELSE 0 END,
|
|
1060
|
-
follow_cursor = CASE WHEN remote_link.instance_id IS excluded.instance_id
|
|
1061
|
-
AND remote_link.account_id = excluded.account_id THEN remote_link.follow_cursor ELSE NULL END,
|
|
1062
|
-
incarnation = CASE WHEN remote_link.instance_id IS excluded.instance_id
|
|
1063
|
-
AND remote_link.account_id = excluded.account_id THEN remote_link.incarnation ELSE NULL END,
|
|
1064
|
-
account_id = excluded.account_id, account_name = excluded.account_name,
|
|
1065
|
-
instance_id = excluded.instance_id, is_default = excluded.is_default, linked_at = excluded.linked_at,
|
|
1066
|
-
state = 'signed-in'`,
|
|
1067
|
-
server,
|
|
1068
|
-
account.id,
|
|
1069
|
-
account.name ?? null,
|
|
1070
|
-
instanceId,
|
|
1071
|
-
answer.json["mostra_default"] === true ? 1 : 0,
|
|
1072
|
-
new Date(now()).toISOString(),
|
|
1073
|
-
),
|
|
1074
|
-
);
|
|
1177
|
+
recordLink(server, account, instanceId, answer.json["mostra_default"] === true);
|
|
1075
1178
|
const previous = connections.get(server);
|
|
1076
1179
|
if (previous) {
|
|
1077
1180
|
await previous.binding.stop();
|
|
@@ -1132,6 +1235,9 @@ export function createLink(options: LinkOptions): Link {
|
|
|
1132
1235
|
methods() {
|
|
1133
1236
|
return [
|
|
1134
1237
|
handler(remoteLoginMethod, (params) => login(params.server, params.default === true)),
|
|
1238
|
+
handler(remoteLinkMethod, (params) =>
|
|
1239
|
+
linkWithKey(params.server, params.key, params.default === true),
|
|
1240
|
+
),
|
|
1135
1241
|
handler(remoteLoginWaitMethod, async (params) => {
|
|
1136
1242
|
const pending = logins.get(params.loginId);
|
|
1137
1243
|
if (!pending) throw invalid(`No sign-in ${params.loginId} is in progress.`);
|
|
@@ -1175,7 +1281,8 @@ export function createLink(options: LinkOptions): Link {
|
|
|
1175
1281
|
if (connection.pushTimer) clearTimeout(connection.pushTimer);
|
|
1176
1282
|
connections.delete(server);
|
|
1177
1283
|
}
|
|
1178
|
-
|
|
1284
|
+
// An operator's key is the operator's to revoke: signing out only forgets it here.
|
|
1285
|
+
if (credentials && "refreshToken" in credentials) {
|
|
1179
1286
|
try {
|
|
1180
1287
|
await postForm(
|
|
1181
1288
|
server,
|
|
@@ -1328,6 +1435,15 @@ export function createLink(options: LinkOptions): Link {
|
|
|
1328
1435
|
}
|
|
1329
1436
|
return true;
|
|
1330
1437
|
},
|
|
1438
|
+
hostedServers: (artifactId) =>
|
|
1439
|
+
ledger.read((db) =>
|
|
1440
|
+
db
|
|
1441
|
+
.all<{ server: string }>(
|
|
1442
|
+
"SELECT server FROM hosted_artifact WHERE artifact_id = ? AND stopped_at IS NULL AND route_id != '' ORDER BY shared_at",
|
|
1443
|
+
artifactId,
|
|
1444
|
+
)
|
|
1445
|
+
.map((row) => row.server),
|
|
1446
|
+
),
|
|
1331
1447
|
hostedOn: (artifactId) =>
|
|
1332
1448
|
ledger.read(
|
|
1333
1449
|
(db) =>
|
|
@@ -1348,7 +1464,12 @@ export function createLink(options: LinkOptions): Link {
|
|
|
1348
1464
|
}),
|
|
1349
1465
|
);
|
|
1350
1466
|
}
|
|
1351
|
-
|
|
1467
|
+
const answer = await session.call(definition, params, { timeoutMs: 30_000 });
|
|
1468
|
+
// A forwarded answer may carry the hosted home's capability links (`roster/add`'s personal
|
|
1469
|
+
// links, D168): whatever it carries is protected from the logs here, as the share's own link
|
|
1470
|
+
// is (Opus review 3).
|
|
1471
|
+
protectLinksIn(answer);
|
|
1472
|
+
return answer;
|
|
1352
1473
|
},
|
|
1353
1474
|
shares: () => ({
|
|
1354
1475
|
mint: async (input) => {
|
|
@@ -1371,6 +1492,19 @@ export function createLink(options: LinkOptions): Link {
|
|
|
1371
1492
|
...(minted.expiresAt !== undefined ? { expiresAt: minted.expiresAt } : {}),
|
|
1372
1493
|
};
|
|
1373
1494
|
},
|
|
1495
|
+
respondents: async (input) => {
|
|
1496
|
+
// The roster is the hosted home's, its personal links hosted links (D168): each is
|
|
1497
|
+
// protected from the logs here as the share's own link is.
|
|
1498
|
+
const session = await self.session(input.server);
|
|
1499
|
+
const added = await session.call(rosterAddMethod, {
|
|
1500
|
+
artifact: { artifactId: input.artifactId },
|
|
1501
|
+
respondents: [...input.respondents],
|
|
1502
|
+
...(input.scopes !== undefined ? { scopes: input.scopes } : {}),
|
|
1503
|
+
...(input.ttl !== undefined ? { ttl: input.ttl } : {}),
|
|
1504
|
+
});
|
|
1505
|
+
for (const entry of added.links) protectLink(entry.link.url);
|
|
1506
|
+
return added.links;
|
|
1507
|
+
},
|
|
1374
1508
|
url: (server, tokenId) => readLinks(server)[tokenId],
|
|
1375
1509
|
revoke: async (server, tokenId) => {
|
|
1376
1510
|
const session = await self.session(server);
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* The client end of the home socket, used by a starter that finds another supervisor holding the
|
|
3
3
|
* home (D81) and by tests. SDKs and the CLI implement the same few steps in their own packages.
|
|
4
4
|
*/
|
|
5
|
+
|
|
6
|
+
import { PassThrough } from "node:stream";
|
|
5
7
|
import {
|
|
6
8
|
type ClientInfo,
|
|
7
9
|
createDiagnostic,
|
|
@@ -12,6 +14,7 @@ import {
|
|
|
12
14
|
RpcPeer,
|
|
13
15
|
} from "@mostra/protocol";
|
|
14
16
|
import { ControlConnectError, connectControl } from "../platform/index.ts";
|
|
17
|
+
import type { ProtocolServer } from "./server.ts";
|
|
15
18
|
import { pump, writeLine } from "./streams.ts";
|
|
16
19
|
|
|
17
20
|
/** An open client connection to an instance's socket. */
|
|
@@ -93,3 +96,53 @@ export async function attach(
|
|
|
93
96
|
throw error;
|
|
94
97
|
}
|
|
95
98
|
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Opens a session with a protocol server in this process, over a pair of in-memory streams, so a
|
|
102
|
+
* part of the runtime acts as a client exactly as any host does (invariant 11): the same framing,
|
|
103
|
+
* initialize, validation and session rules. `attributes` are the session's, as a transport sets
|
|
104
|
+
* them (a remote MCP request's account and home). The caller closes the returned client.
|
|
105
|
+
*/
|
|
106
|
+
export async function attachInProcess(
|
|
107
|
+
server: ProtocolServer,
|
|
108
|
+
client: ClientInfo,
|
|
109
|
+
attributes: Readonly<Record<string, unknown>> = {},
|
|
110
|
+
timeoutMs = 5000,
|
|
111
|
+
): Promise<{ client: SocketClient; result: MostraInitializeResult }> {
|
|
112
|
+
const toServer = new PassThrough();
|
|
113
|
+
const toClient = new PassThrough();
|
|
114
|
+
const peer = new RpcPeer({ send: (message) => void writeLine(toServer, message) });
|
|
115
|
+
let markClosed: () => void = () => {};
|
|
116
|
+
const closed = new Promise<void>((done) => {
|
|
117
|
+
markClosed = done;
|
|
118
|
+
});
|
|
119
|
+
server.serve("stdio", toServer, toClient, undefined, attributes);
|
|
120
|
+
pump(
|
|
121
|
+
{ input: toClient, output: toServer },
|
|
122
|
+
() => peer,
|
|
123
|
+
() => {
|
|
124
|
+
peer.close();
|
|
125
|
+
markClosed();
|
|
126
|
+
},
|
|
127
|
+
);
|
|
128
|
+
const connection: SocketClient = {
|
|
129
|
+
peer,
|
|
130
|
+
closed,
|
|
131
|
+
close: () => {
|
|
132
|
+
peer.close();
|
|
133
|
+
toServer.end();
|
|
134
|
+
toClient.end();
|
|
135
|
+
},
|
|
136
|
+
};
|
|
137
|
+
try {
|
|
138
|
+
const result = await peer.call(
|
|
139
|
+
mostraInitializeMethod,
|
|
140
|
+
{ client, revisions: [...HOST_PROTOCOL_REVISIONS], capabilities: {}, ports: [] },
|
|
141
|
+
{ timeoutMs },
|
|
142
|
+
);
|
|
143
|
+
return { client: connection, result };
|
|
144
|
+
} catch (error) {
|
|
145
|
+
connection.close();
|
|
146
|
+
throw error;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
@@ -20,7 +20,7 @@ import {
|
|
|
20
20
|
} from "@mostra/protocol";
|
|
21
21
|
import { handler, type MethodHandler } from "./server.ts";
|
|
22
22
|
|
|
23
|
-
export { attach, type SocketClient } from "./client.ts";
|
|
23
|
+
export { attach, attachInProcess, type SocketClient } from "./client.ts";
|
|
24
24
|
export {
|
|
25
25
|
handler,
|
|
26
26
|
type MethodHandler,
|