@mostra/runtime 0.11.0 → 0.13.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 +930 -458
- package/dist/bin.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{instance-DCiUHvgZ.js → instance-D5gh-sMM.js} +1231 -46
- package/dist/instance-D5gh-sMM.js.map +1 -0
- package/dist/reference/cli.md +112 -2
- package/dist/reference/diagnostics.json +29 -2
- package/dist/reference/errors/MOSTRA_REMOTE_QUEUE_FULL.md +2 -2
- 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/self-hosting.md +1 -1
- package/dist/skill/SKILL.md +5 -3
- package/dist/skill/references/answers.md +3 -1
- package/dist/skill/references/mcp.md +2 -2
- package/dist/skill/references/teams.md +78 -0
- package/package.json +6 -6
- package/src/actions/index.ts +5 -2
- package/src/gateway/actions.ts +6 -1
- package/src/gateway/browser.ts +84 -1
- package/src/gateway/capabilities.ts +5 -1
- package/src/gateway/index.ts +43 -1
- package/src/gateway/team.ts +181 -0
- package/src/instance/index.ts +2 -1
- package/src/interaction/ephemeral.ts +21 -0
- package/src/interaction/events.ts +17 -0
- package/src/interaction/index.ts +265 -20
- package/src/interaction/roster.ts +585 -0
- package/src/interaction/team.ts +426 -0
- package/src/interaction/wait.ts +150 -0
- package/src/ledger/migrations.ts +44 -0
- package/src/link/hosted.ts +14 -3
- package/src/link/manager.ts +31 -1
- package/src/server/api.ts +1 -1
- package/src/server/auth.ts +83 -16
- package/src/server/authorize.ts +27 -4
- package/src/server/config.ts +53 -0
- package/src/server/directory.ts +73 -0
- package/src/server/feed.ts +89 -3
- package/src/server/hosted-pages.ts +19 -6
- package/src/server/hosted.ts +108 -49
- package/src/server/index.ts +72 -15
- package/src/server/metering.ts +117 -12
- package/src/server/operator.ts +87 -28
- package/src/server/providers.ts +61 -9
- package/src/server/relay.ts +258 -107
- package/src/share/index.ts +50 -2
- package/src/verify/index.ts +7 -0
- package/src/verify/runner.ts +5 -1
- package/dist/instance-DCiUHvgZ.js.map +0 -1
|
@@ -4,7 +4,7 @@ import { builtinModules, createRequire } from "node:module";
|
|
|
4
4
|
import { accessSync, appendFileSync, chmodSync, closeSync, constants, createReadStream, createWriteStream, existsSync, fsyncSync, linkSync, mkdirSync, openSync, readFileSync, readdirSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, watch, writeFileSync, writeSync } from "node:fs";
|
|
5
5
|
import { basename, delimiter, dirname, extname, isAbsolute, join, relative, resolve, sep, win32 } from "node:path";
|
|
6
6
|
import { fileURLToPath } from "node:url";
|
|
7
|
-
import { ACTION_ARGS_MAX, ACTION_RESULT_MAX, ALL_SCOPES, ARTIFACT_MANIFEST_KEYS, ARTIFACT_PROGRESS, ArtifactId, ArtifactManifest, BROWSER_PROTOCOL_REVISION, BROWSER_PROTOCOL_REVISIONS, BUNDLE_NAME, CLI_CLIENT_NAME, CallRequest, ChooseRequest, DEFAULT_WORKER_LIMITS, DEV_NOTIFY, DeliveryId, EVENTS_NOTIFY, EnterRequest, FRAME_SESSION_HEADER, FieldsRequest, FollowRequest, HOST_PROTOCOL_REVISIONS, LIVE_RING_DEFAULT, LIVE_RING_MAX, LIVE_VALUE_MAX, LineSplitter, LinkId, LiveRequest, MAX_LINE_LENGTH, MutationId, PUBLIC_SHARE_DEFAULT_TTL, PUBLIC_SHARE_MAX_TTL_MS, RUN_LOG_MAX, RUN_LOG_TRUNCATED, RpcError, RpcPeer, RunAttachRequest, RunCancelRequest, RunId, RunRequest, SECRET_NAME_PATTERN, SECRET_VALUE_MAX, SHELL_SESSION_HEADER, SIGNAL_NAME_PATTERN, SIGNAL_PAYLOAD_MAX_BYTES, ServerEmitParams, ServerLiveValueParams, ServerSecretParams, ServerSignalParams, ServerStateGetParams, ServerStatePatchParams, ShareId, ShellSubmitRequest, SignalRequest, StreamTicketRequest, SubmissionEnvelope, SubmissionId, SubmissionPolicy, SubmitRequest, TALLY_LIVE_PREFIX, TokenId, VERIFY_RUNNER_METHODS, VerifyVerdict, VersionId, ViewId, ViewerId, WORKER_METHODS, WorkerBatchParams, WorkerCallOutcome, WorkerPingResult, WorkerStartResult, ariaSummary, artifactCreateMethod, artifactExportMethod, artifactGetMethod, artifactImportMethod, artifactListMethod, artifactPauseMethod, artifactPublishMethod, artifactVerifyMethod, canonicalJson, checkArgumentFrames, checkRequest, createDiagnostic, depsAddMethod, devStartMethod, devStopMethod, durationMs, encodeLine, estimateImageTokens, eventsAckMethod, eventsReadMethod, eventsSubscribeMethod, eventsUnsubscribeMethod, fromBase64, gcRunMethod, hostedPushMethod, hostedSubmissionMethod, instanceCheckMethod, instanceStatusMethod, isFieldId, isFinalRunStatus, livePushMethod, manifestProblem, mostraInitializeMethod, mostraShutdownMethod, negotiateRevision, normalizeScopes, parseParams, portAddressingExternalBaseMethod, portDraftsMirrorMethod, portIdentityResolveMethod, portRelayAuthorMethod, portRelayCallMethod, portRelayCancelMethod, portRelayLiveMethod, portRelayReconcileMethod, portRelayRunMethod, portSecretsGetMethod, portSubmissionsDeliverMethod, portTrustedControlsActivatedMethod, portTrustedControlsPolicyMethod, refusal, relayCallBatchMethod, relayEffectMethod, relayLiveValueMethod, relayRunUpdateMethod, remoteLinkMethod, remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod, remoteStatusMethod, remoteTokenMethod, resultsGetMethod, safeEqual, safePath, scopeAllows, secretDeleteMethod, secretListMethod, secretSetMethod, serializeAll, shareListMethod, shareStartMethod, shareStopMethod, stateGetMethod, statePatchMethod, toBase64, viewDefaultMethod, viewLaunchMethod, viewRevokeMethod, viewRotateMethod, viewUrlMethod, viewportsFor, waitMethod } from "@mostra/protocol";
|
|
7
|
+
import { ACTION_ARGS_MAX, ACTION_RESULT_MAX, ALL_SCOPES, ARTIFACT_MANIFEST_KEYS, ARTIFACT_PROGRESS, ArtifactId, ArtifactManifest, BROWSER_PROTOCOL_REVISION, BROWSER_PROTOCOL_REVISIONS, BUNDLE_NAME, CLI_CLIENT_NAME, CallRequest, ChooseRequest, DEFAULT_TEAM_VISIBILITY, DEFAULT_WORKER_LIMITS, DEV_NOTIFY, DeliveryId, EVENTS_NOTIFY, EnterRequest, FRAME_SESSION_HEADER, FieldsRequest, FollowRequest, HOST_PROTOCOL_REVISIONS, LIVE_RING_DEFAULT, LIVE_RING_MAX, LIVE_VALUE_MAX, LineSplitter, LinkId, LiveRequest, MAX_LINE_LENGTH, MutationId, PUBLIC_SHARE_DEFAULT_TTL, PUBLIC_SHARE_MAX_TTL_MS, PresenceRequest, RESULTS_LIST_MAX, ROSTER_MAX, RUN_LOG_MAX, RUN_LOG_TRUNCATED, RespondentsRequest, RpcError, RpcPeer, RunAttachRequest, RunCancelRequest, RunId, RunRequest, SECRET_NAME_PATTERN, SECRET_VALUE_MAX, SHELL_SESSION_HEADER, SIGNAL_NAME_PATTERN, SIGNAL_PAYLOAD_MAX_BYTES, ServerEmitParams, ServerLiveValueParams, ServerSecretParams, ServerSignalParams, ServerStateGetParams, ServerStatePatchParams, ShareId, ShellSubmitRequest, SignalRequest, StreamTicketRequest, SubmissionEnvelope, SubmissionId, SubmissionPolicy, SubmitRequest, TALLY_LIVE_PREFIX, TokenId, VERIFY_RUNNER_METHODS, VerifyVerdict, VersionId, ViewId, ViewerId, WORKER_METHODS, WorkerBatchParams, WorkerCallOutcome, WorkerPingResult, WorkerStartResult, ariaSummary, artifactCreateMethod, artifactExportMethod, artifactGetMethod, artifactImportMethod, artifactListMethod, artifactPauseMethod, artifactPublishMethod, artifactVerifyMethod, canonicalJson, checkArgumentFrames, checkRequest, createDiagnostic, depsAddMethod, devStartMethod, devStopMethod, durationMs, encodeLine, estimateImageTokens, eventsAckMethod, eventsReadMethod, eventsSubscribeMethod, eventsUnsubscribeMethod, fromBase64, gcRunMethod, hostedPushMethod, hostedSubmissionMethod, instanceCheckMethod, instanceStatusMethod, isFieldId, isFinalRunStatus, livePushMethod, manifestProblem, mostraInitializeMethod, mostraShutdownMethod, negotiateRevision, normalizeScopes, parseParams, portAddressingExternalBaseMethod, portDraftsMirrorMethod, portIdentityResolveMethod, portRelayAuthorMethod, portRelayCallMethod, portRelayCancelMethod, portRelayLiveMethod, portRelayReconcileMethod, portRelayRunMethod, portSecretsGetMethod, portSubmissionsDeliverMethod, portTrustedControlsActivatedMethod, portTrustedControlsPolicyMethod, refusal, relayCallBatchMethod, relayEffectMethod, relayLiveValueMethod, relayRunUpdateMethod, remoteLinkMethod, remoteLoginMethod, remoteLoginWaitMethod, remoteLogoutMethod, remoteStatusMethod, remoteTokenMethod, resultsGetMethod, resultsListMethod, rosterAddMethod, rosterGetMethod, rosterRemoveMethod, safeEqual, safePath, scopeAllows, secretDeleteMethod, secretListMethod, secretSetMethod, serializeAll, shareListMethod, shareStartMethod, shareStopMethod, stateGetMethod, statePatchMethod, toBase64, viewDefaultMethod, viewLaunchMethod, viewRevokeMethod, viewRotateMethod, viewUrlMethod, viewportsFor, waitMethod } from "@mostra/protocol";
|
|
8
8
|
import { createHash, createHmac, randomBytes, randomInt, randomUUID } from "node:crypto";
|
|
9
9
|
import { connect, createConnection, createServer, isIP } from "node:net";
|
|
10
10
|
import { execFile, execFileSync, spawn } from "node:child_process";
|
|
@@ -2898,6 +2898,44 @@ const MIGRATIONS = [
|
|
|
2898
2898
|
ALTER TABLE artifact_pause_by RENAME TO artifact_pause;
|
|
2899
2899
|
`);
|
|
2900
2900
|
}
|
|
2901
|
+
},
|
|
2902
|
+
{
|
|
2903
|
+
version: 16,
|
|
2904
|
+
name: "expected respondents and the roster's rounds",
|
|
2905
|
+
up(db) {
|
|
2906
|
+
db.exec(`
|
|
2907
|
+
CREATE TABLE roster_entry (
|
|
2908
|
+
artifact_id TEXT NOT NULL REFERENCES artifact(id),
|
|
2909
|
+
ref TEXT NOT NULL CHECK (length(ref) BETWEEN 1 AND 256),
|
|
2910
|
+
name TEXT,
|
|
2911
|
+
email TEXT,
|
|
2912
|
+
viewer_id TEXT NOT NULL REFERENCES viewer(id),
|
|
2913
|
+
token_id TEXT REFERENCES token(id),
|
|
2914
|
+
position INTEGER NOT NULL,
|
|
2915
|
+
added_at TEXT NOT NULL,
|
|
2916
|
+
PRIMARY KEY (artifact_id, ref),
|
|
2917
|
+
UNIQUE (artifact_id, viewer_id),
|
|
2918
|
+
UNIQUE (artifact_id, position)
|
|
2919
|
+
);
|
|
2920
|
+
CREATE TABLE roster_state (
|
|
2921
|
+
artifact_id TEXT PRIMARY KEY REFERENCES artifact(id),
|
|
2922
|
+
round INTEGER NOT NULL CHECK (round >= 1),
|
|
2923
|
+
round_cursor INTEGER NOT NULL CHECK (round_cursor >= 0),
|
|
2924
|
+
round_started_at TEXT NOT NULL,
|
|
2925
|
+
complete INTEGER NOT NULL CHECK (complete IN (0, 1))
|
|
2926
|
+
);
|
|
2927
|
+
CREATE TRIGGER roster_state_round_grows BEFORE UPDATE OF round, round_cursor ON roster_state
|
|
2928
|
+
WHEN NEW.round < OLD.round OR NEW.round_cursor < OLD.round_cursor
|
|
2929
|
+
BEGIN SELECT RAISE(ABORT, 'a roster round never goes back'); END;
|
|
2930
|
+
`);
|
|
2931
|
+
}
|
|
2932
|
+
},
|
|
2933
|
+
{
|
|
2934
|
+
version: 17,
|
|
2935
|
+
name: "a link's views",
|
|
2936
|
+
up(db) {
|
|
2937
|
+
db.exec("CREATE INDEX view_token ON view (token_id, opened_at)");
|
|
2938
|
+
}
|
|
2901
2939
|
}
|
|
2902
2940
|
];
|
|
2903
2941
|
//#endregion
|
|
@@ -5654,6 +5692,7 @@ function compactEvents(db, artifactId, before) {
|
|
|
5654
5692
|
let removed = 0;
|
|
5655
5693
|
let from = first.cursor;
|
|
5656
5694
|
let latestVersion;
|
|
5695
|
+
let roster;
|
|
5657
5696
|
for (const row of rows) {
|
|
5658
5697
|
if (row.type === "artifact.compacted") {
|
|
5659
5698
|
const earlier = JSON.parse(row.payload_json);
|
|
@@ -5661,10 +5700,22 @@ function compactEvents(db, artifactId, before) {
|
|
|
5661
5700
|
removed += earlier.removed;
|
|
5662
5701
|
for (const [type, count] of Object.entries(earlier.types)) types[type] = (types[type] ?? 0) + count;
|
|
5663
5702
|
if (earlier.latestVersion) latestVersion = earlier.latestVersion;
|
|
5703
|
+
if (earlier.roster) roster = earlier.roster;
|
|
5664
5704
|
continue;
|
|
5665
5705
|
}
|
|
5666
5706
|
removed += 1;
|
|
5667
5707
|
types[row.type] = (types[row.type] ?? 0) + 1;
|
|
5708
|
+
if (row.type === "roster.completed") roster = {
|
|
5709
|
+
complete: true,
|
|
5710
|
+
completed: eventRecord(row)
|
|
5711
|
+
};
|
|
5712
|
+
else if (row.type === "roster.changed") {
|
|
5713
|
+
const complete = JSON.parse(row.payload_json).complete === true;
|
|
5714
|
+
roster = {
|
|
5715
|
+
complete,
|
|
5716
|
+
...complete && roster?.completed ? { completed: roster.completed } : {}
|
|
5717
|
+
};
|
|
5718
|
+
}
|
|
5668
5719
|
if (row.type === "version.published") {
|
|
5669
5720
|
const payload = JSON.parse(row.payload_json);
|
|
5670
5721
|
latestVersion = {
|
|
@@ -5679,7 +5730,8 @@ function compactEvents(db, artifactId, before) {
|
|
|
5679
5730
|
through: last.cursor,
|
|
5680
5731
|
removed,
|
|
5681
5732
|
types,
|
|
5682
|
-
...latestVersion ? { latestVersion } : {}
|
|
5733
|
+
...latestVersion ? { latestVersion } : {},
|
|
5734
|
+
...roster ? { roster } : {}
|
|
5683
5735
|
};
|
|
5684
5736
|
db.run("DELETE FROM event WHERE artifact_id = ? AND cursor < ?", artifactId, before);
|
|
5685
5737
|
db.run("INSERT INTO event (cursor, artifact_id, seq, type, actor_json, causation_json, payload_json, at) VALUES (?, ?, ?, ?, ?, NULL, ?, ?)", last.cursor, artifactId, last.seq, COMPACTED, JSON.stringify({ kind: "mostra" }), JSON.stringify(summary), (/* @__PURE__ */ new Date()).toISOString());
|
|
@@ -7236,6 +7288,355 @@ function setPause(db, artifactId, change) {
|
|
|
7236
7288
|
};
|
|
7237
7289
|
}
|
|
7238
7290
|
//#endregion
|
|
7291
|
+
//#region src/interaction/roster.ts
|
|
7292
|
+
/**
|
|
7293
|
+
* Expected respondents and their roster (D121, D168; CO-01 to CO-03, CO-07). An artifact names the
|
|
7294
|
+
* people it expects answers from; each acts as one viewer of kind `token` (D104) through a personal
|
|
7295
|
+
* link the gateway mints. The roster has rounds: under `once` one, complete while every respondent
|
|
7296
|
+
* has a submission; under `epochs` a new one after each completion, complete once every respondent
|
|
7297
|
+
* submitted since it began. A completion is a durable `roster.completed`, appended in the same
|
|
7298
|
+
* transaction as the submission (or roster change) that made it, so a wait, a host and the
|
|
7299
|
+
* operator's events hear it exactly once per completion.
|
|
7300
|
+
*
|
|
7301
|
+
* Every function here runs inside the caller's ledger transaction.
|
|
7302
|
+
*/
|
|
7303
|
+
/** The roster's state: round 1 from the start of everything until the roster first changes it. */
|
|
7304
|
+
function stateOf(db, artifactId) {
|
|
7305
|
+
return db.get("SELECT * FROM roster_state WHERE artifact_id = ?", artifactId) ?? {
|
|
7306
|
+
artifact_id: artifactId,
|
|
7307
|
+
round: 1,
|
|
7308
|
+
round_cursor: 0,
|
|
7309
|
+
round_started_at: "",
|
|
7310
|
+
complete: 0
|
|
7311
|
+
};
|
|
7312
|
+
}
|
|
7313
|
+
function entries(db, artifactId) {
|
|
7314
|
+
return db.all("SELECT * FROM roster_entry WHERE artifact_id = ? ORDER BY position", artifactId);
|
|
7315
|
+
}
|
|
7316
|
+
function policyOf(db, artifactId) {
|
|
7317
|
+
return storedPolicy(db.get("SELECT policy_json FROM artifact WHERE id = ?", artifactId)?.policy_json ?? null);
|
|
7318
|
+
}
|
|
7319
|
+
function submissionStanding(db, artifactId, owner) {
|
|
7320
|
+
const policy = policyOf(db, artifactId);
|
|
7321
|
+
return {
|
|
7322
|
+
closesAll: policy.policy === "once" && policy.scope !== "per-viewer",
|
|
7323
|
+
visibility: owner ? "names" : teamVisibility(db, artifactId)
|
|
7324
|
+
};
|
|
7325
|
+
}
|
|
7326
|
+
/**
|
|
7327
|
+
* What viewers see of each other on an artifact (CO-07): its latest version's `team.visibility`,
|
|
7328
|
+
* else `private` (D168). The latest version decides for every view, so a version that narrows it
|
|
7329
|
+
* narrows it for pages of older versions too.
|
|
7330
|
+
*/
|
|
7331
|
+
function teamVisibility(db, artifactId) {
|
|
7332
|
+
const row = db.get(`SELECT version.manifest_json FROM artifact JOIN version ON version.id = artifact.latest_version_id
|
|
7333
|
+
WHERE artifact.id = ?`, artifactId);
|
|
7334
|
+
if (!row) return DEFAULT_TEAM_VISIBILITY;
|
|
7335
|
+
try {
|
|
7336
|
+
const value = JSON.parse(row.manifest_json).team?.visibility;
|
|
7337
|
+
return value === "counts" || value === "names" || value === "private" ? value : DEFAULT_TEAM_VISIBILITY;
|
|
7338
|
+
} catch {
|
|
7339
|
+
return DEFAULT_TEAM_VISIBILITY;
|
|
7340
|
+
}
|
|
7341
|
+
}
|
|
7342
|
+
/**
|
|
7343
|
+
* A viewer's key as pages see it (D168): stable for one viewer of one artifact, different across
|
|
7344
|
+
* artifacts, and no viewer ID, which pages never learn of others (D104).
|
|
7345
|
+
*/
|
|
7346
|
+
function peerKey(artifactId, viewerId) {
|
|
7347
|
+
return `vk_${createHash("sha256").update(`mostra/viewer-key\u0000${artifactId}\u0000${viewerId}`).digest("hex").slice(0, 24)}`;
|
|
7348
|
+
}
|
|
7349
|
+
/**
|
|
7350
|
+
* Where each respondent stands in the round (CO-03): `submitted` with a submission in it (under
|
|
7351
|
+
* `once`, their one submission; under `epochs`, their latest after the round began), else
|
|
7352
|
+
* `drafting` when they opened the artifact or wrote their draft in it, else `not-opened`.
|
|
7353
|
+
*/
|
|
7354
|
+
function standings(db, artifactId, state) {
|
|
7355
|
+
const list = entries(db, artifactId);
|
|
7356
|
+
if (list.length === 0) return [];
|
|
7357
|
+
const inRound = new Map(db.all("SELECT s.viewer_id, s.id, s.created_at, s.position FROM submission s JOIN roster_entry r ON r.artifact_id = s.artifact_id AND r.viewer_id = s.viewer_id WHERE s.artifact_id = ? AND s.position > ? AND s.position = (SELECT MAX(t.position) FROM submission t WHERE t.artifact_id = s.artifact_id AND t.viewer_id = s.viewer_id)", artifactId, state.round_cursor).map((row) => [row.viewer_id, row]));
|
|
7358
|
+
const totals = new Map(db.all("SELECT s.viewer_id, COUNT(*) AS n FROM submission s JOIN roster_entry r ON r.artifact_id = s.artifact_id AND r.viewer_id = s.viewer_id WHERE s.artifact_id = ? GROUP BY s.viewer_id", artifactId).map((row) => [row.viewer_id, row.n]));
|
|
7359
|
+
const views = new Map(db.all("SELECT v.viewer_id, MIN(v.opened_at) AS first, MAX(v.opened_at) AS last FROM view v JOIN roster_entry r ON r.artifact_id = v.artifact_id AND r.viewer_id = v.viewer_id WHERE v.artifact_id = ? GROUP BY v.viewer_id", artifactId).map((row) => [row.viewer_id, row]));
|
|
7360
|
+
const wrote = new Map(db.all("SELECT d.viewer_id, MAX(f.updated_at) AS last FROM field f JOIN document d ON d.id = f.document_id JOIN roster_entry r ON r.artifact_id = d.artifact_id AND r.viewer_id = d.viewer_id WHERE d.artifact_id = ? AND d.scope = 'viewer' GROUP BY d.viewer_id", artifactId).map((row) => [row.viewer_id, row.last]));
|
|
7361
|
+
return list.map((entry) => {
|
|
7362
|
+
const submission = inRound.get(entry.viewer_id);
|
|
7363
|
+
const opened = views.get(entry.viewer_id);
|
|
7364
|
+
const activeAt = [opened?.last, wrote.get(entry.viewer_id)].filter((at) => typeof at === "string").sort().at(-1) ?? void 0;
|
|
7365
|
+
return {
|
|
7366
|
+
entry,
|
|
7367
|
+
status: submission ? "submitted" : activeAt !== void 0 && activeAt >= state.round_started_at ? "drafting" : "not-opened",
|
|
7368
|
+
...opened ? { openedAt: opened.first } : {},
|
|
7369
|
+
...activeAt !== void 0 ? { activeAt } : {},
|
|
7370
|
+
...submission ? { submission: {
|
|
7371
|
+
id: submission.id,
|
|
7372
|
+
at: submission.created_at,
|
|
7373
|
+
position: submission.position
|
|
7374
|
+
} } : {},
|
|
7375
|
+
submissions: totals.get(entry.viewer_id) ?? 0
|
|
7376
|
+
};
|
|
7377
|
+
});
|
|
7378
|
+
}
|
|
7379
|
+
function countsOf(list) {
|
|
7380
|
+
return {
|
|
7381
|
+
total: list.length,
|
|
7382
|
+
notOpened: list.filter((one) => one.status === "not-opened").length,
|
|
7383
|
+
drafting: list.filter((one) => one.status === "drafting").length,
|
|
7384
|
+
submitted: list.filter((one) => one.status === "submitted").length
|
|
7385
|
+
};
|
|
7386
|
+
}
|
|
7387
|
+
/** Whether every respondent submitted in the round; an empty roster never has. */
|
|
7388
|
+
function completeOf(list) {
|
|
7389
|
+
return list.length > 0 && list.every((one) => one.status === "submitted");
|
|
7390
|
+
}
|
|
7391
|
+
/** The whole roster, as agents and hosts read it (`roster/get`, CO-03, CO-07). */
|
|
7392
|
+
function readRoster(db, artifactId, live = () => true) {
|
|
7393
|
+
const state = stateOf(db, artifactId);
|
|
7394
|
+
const list = standings(db, artifactId, state);
|
|
7395
|
+
return {
|
|
7396
|
+
round: state.round,
|
|
7397
|
+
complete: completeOf(list),
|
|
7398
|
+
visibility: teamVisibility(db, artifactId),
|
|
7399
|
+
counts: countsOf(list),
|
|
7400
|
+
respondents: list.map((one) => {
|
|
7401
|
+
const { entry } = one;
|
|
7402
|
+
return {
|
|
7403
|
+
ref: entry.ref,
|
|
7404
|
+
...entry.name !== null ? { name: entry.name } : {},
|
|
7405
|
+
...entry.email !== null ? { email: entry.email } : {},
|
|
7406
|
+
viewerId: entry.viewer_id,
|
|
7407
|
+
status: one.status,
|
|
7408
|
+
...one.openedAt !== void 0 ? { openedAt: one.openedAt } : {},
|
|
7409
|
+
...one.activeAt !== void 0 ? { activeAt: one.activeAt } : {},
|
|
7410
|
+
...one.submission ? { submission: {
|
|
7411
|
+
id: one.submission.id,
|
|
7412
|
+
at: one.submission.at
|
|
7413
|
+
} } : {},
|
|
7414
|
+
submissions: one.submissions,
|
|
7415
|
+
...entry.token_id !== null && live(entry.token_id) ? { tokenId: entry.token_id } : {},
|
|
7416
|
+
addedAt: entry.added_at
|
|
7417
|
+
};
|
|
7418
|
+
})
|
|
7419
|
+
};
|
|
7420
|
+
}
|
|
7421
|
+
/** Whether the artifact has any expected respondent. */
|
|
7422
|
+
function hasRoster(db, artifactId) {
|
|
7423
|
+
return db.get("SELECT 1 FROM roster_entry WHERE artifact_id = ? LIMIT 1", artifactId) !== void 0;
|
|
7424
|
+
}
|
|
7425
|
+
/**
|
|
7426
|
+
* Settles the roster after a change inside its transaction (a submission, an import, a roster
|
|
7427
|
+
* change): when the round became complete, appends `roster.completed` with each respondent's
|
|
7428
|
+
* submission in the round and, under `epochs`, begins the next round; when a roster change made a
|
|
7429
|
+
* complete round incomplete again (someone joined), says so. Returns whether it is complete now.
|
|
7430
|
+
*/
|
|
7431
|
+
function settleRoster(db, artifactId, now) {
|
|
7432
|
+
if (!hasRoster(db, artifactId) && !db.get("SELECT 1 FROM roster_state WHERE artifact_id = ?", artifactId)) return false;
|
|
7433
|
+
const state = stateOf(db, artifactId);
|
|
7434
|
+
const list = standings(db, artifactId, state);
|
|
7435
|
+
const complete = completeOf(list);
|
|
7436
|
+
const ensure = () => {
|
|
7437
|
+
db.run("INSERT OR IGNORE INTO roster_state (artifact_id, round, round_cursor, round_started_at, complete) VALUES (?, 1, 0, '', 0)", artifactId);
|
|
7438
|
+
};
|
|
7439
|
+
if (complete && state.complete === 0) {
|
|
7440
|
+
ensure();
|
|
7441
|
+
const cursor = Number(appendEvent(db, {
|
|
7442
|
+
artifactId,
|
|
7443
|
+
type: "roster.completed",
|
|
7444
|
+
actor: { kind: "mostra" },
|
|
7445
|
+
payload: {
|
|
7446
|
+
round: state.round,
|
|
7447
|
+
respondents: list.length,
|
|
7448
|
+
submissions: list.map((one) => ({
|
|
7449
|
+
ref: one.entry.ref,
|
|
7450
|
+
submissionId: one.submission?.id ?? ""
|
|
7451
|
+
}))
|
|
7452
|
+
}
|
|
7453
|
+
}));
|
|
7454
|
+
if (policyOf(db, artifactId).policy === "epochs") {
|
|
7455
|
+
db.run("UPDATE roster_state SET round = round + 1, round_cursor = ?, round_started_at = ?, complete = 0 WHERE artifact_id = ?", cursor, now, artifactId);
|
|
7456
|
+
return false;
|
|
7457
|
+
}
|
|
7458
|
+
db.run("UPDATE roster_state SET complete = 1 WHERE artifact_id = ?", artifactId);
|
|
7459
|
+
return true;
|
|
7460
|
+
}
|
|
7461
|
+
if (!complete && state.complete === 1) db.run("UPDATE roster_state SET complete = 0 WHERE artifact_id = ?", artifactId);
|
|
7462
|
+
return complete;
|
|
7463
|
+
}
|
|
7464
|
+
function rosterTooLarge(count) {
|
|
7465
|
+
return new RpcError(createDiagnostic("MOSTRA_TEAM_ROSTER_TOO_LARGE", { message: `This change would give the roster ${count} expected respondents, more than ${ROSTER_MAX}.` }));
|
|
7466
|
+
}
|
|
7467
|
+
/**
|
|
7468
|
+
* Adds expected respondents (CO-01), idempotently by `ref`: one already there keeps their row and
|
|
7469
|
+
* link, and a name or email given again replaces theirs. `link` gives each respondent's personal
|
|
7470
|
+
* link's token (`current` is the one their row names, which the caller keeps while it works) and
|
|
7471
|
+
* runs in this transaction. Appends `roster.changed` when anything changed.
|
|
7472
|
+
*/
|
|
7473
|
+
function addRespondents(db, input) {
|
|
7474
|
+
const seen = /* @__PURE__ */ new Set();
|
|
7475
|
+
const specs = input.respondents.filter((spec) => {
|
|
7476
|
+
if (seen.has(spec.ref)) return false;
|
|
7477
|
+
seen.add(spec.ref);
|
|
7478
|
+
return true;
|
|
7479
|
+
});
|
|
7480
|
+
const existing = new Map(entries(db, input.artifactId).map((entry) => [entry.ref, entry]));
|
|
7481
|
+
const fresh = specs.filter((spec) => !existing.has(spec.ref)).length;
|
|
7482
|
+
if (existing.size + fresh > ROSTER_MAX) throw rosterTooLarge(existing.size + fresh);
|
|
7483
|
+
let position = db.get("SELECT MAX(position) AS last FROM roster_entry WHERE artifact_id = ?", input.artifactId)?.last ?? 0;
|
|
7484
|
+
const added = [];
|
|
7485
|
+
const renamed = [];
|
|
7486
|
+
const relinked = [];
|
|
7487
|
+
const tokens = [];
|
|
7488
|
+
for (const spec of specs) {
|
|
7489
|
+
const viewerId = viewerForSpec(db, {
|
|
7490
|
+
ref: spec.ref,
|
|
7491
|
+
...spec.name !== void 0 ? { name: spec.name } : {}
|
|
7492
|
+
});
|
|
7493
|
+
const entry = existing.get(spec.ref);
|
|
7494
|
+
const tokenId = input.link(viewerId, entry?.token_id ?? void 0);
|
|
7495
|
+
tokens.push({
|
|
7496
|
+
ref: spec.ref,
|
|
7497
|
+
tokenId
|
|
7498
|
+
});
|
|
7499
|
+
if (!entry) {
|
|
7500
|
+
position += 1;
|
|
7501
|
+
db.run("INSERT INTO roster_entry (artifact_id, ref, name, email, viewer_id, token_id, position, added_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", input.artifactId, spec.ref, spec.name ?? null, spec.email ?? null, viewerId, tokenId, position, input.now);
|
|
7502
|
+
added.push({
|
|
7503
|
+
ref: spec.ref,
|
|
7504
|
+
...spec.name !== void 0 ? { name: spec.name } : {}
|
|
7505
|
+
});
|
|
7506
|
+
continue;
|
|
7507
|
+
}
|
|
7508
|
+
const name = spec.name ?? entry.name;
|
|
7509
|
+
const email = spec.email ?? entry.email;
|
|
7510
|
+
if (name !== entry.name || email !== entry.email || tokenId !== entry.token_id) {
|
|
7511
|
+
db.run("UPDATE roster_entry SET name = ?, email = ?, token_id = ? WHERE artifact_id = ? AND ref = ?", name, email, tokenId, input.artifactId, spec.ref);
|
|
7512
|
+
if (name !== entry.name) renamed.push({
|
|
7513
|
+
ref: spec.ref,
|
|
7514
|
+
...name !== null ? { name } : {}
|
|
7515
|
+
});
|
|
7516
|
+
if (tokenId !== entry.token_id) relinked.push(spec.ref);
|
|
7517
|
+
}
|
|
7518
|
+
}
|
|
7519
|
+
if (added.length > 0 || renamed.length > 0 || relinked.length > 0) changed(db, input, {
|
|
7520
|
+
added,
|
|
7521
|
+
renamed,
|
|
7522
|
+
relinked,
|
|
7523
|
+
removed: []
|
|
7524
|
+
});
|
|
7525
|
+
return { tokens };
|
|
7526
|
+
}
|
|
7527
|
+
/**
|
|
7528
|
+
* Removes expected respondents by `ref` (D168); unknown ones are ignored. Their links, drafts and
|
|
7529
|
+
* submissions stay. Appends `roster.changed` and, when everyone still expected has answered,
|
|
7530
|
+
* `roster.completed`.
|
|
7531
|
+
*/
|
|
7532
|
+
function removeRespondents(db, input) {
|
|
7533
|
+
const removed = [];
|
|
7534
|
+
for (const ref of new Set(input.refs)) if (db.run("DELETE FROM roster_entry WHERE artifact_id = ? AND ref = ?", input.artifactId, ref).changes > 0) removed.push(ref);
|
|
7535
|
+
if (removed.length > 0) changed(db, input, {
|
|
7536
|
+
added: [],
|
|
7537
|
+
renamed: [],
|
|
7538
|
+
relinked: [],
|
|
7539
|
+
removed
|
|
7540
|
+
});
|
|
7541
|
+
return { removed };
|
|
7542
|
+
}
|
|
7543
|
+
/** Appends `roster.changed` after settling the roster, so the event says where it stands. */
|
|
7544
|
+
function changed(db, input, change) {
|
|
7545
|
+
db.run("INSERT OR IGNORE INTO roster_state (artifact_id, round, round_cursor, round_started_at, complete) VALUES (?, 1, 0, '', 0)", input.artifactId);
|
|
7546
|
+
const before = stateOf(db, input.artifactId);
|
|
7547
|
+
const list = standings(db, input.artifactId, before);
|
|
7548
|
+
appendEvent(db, {
|
|
7549
|
+
artifactId: input.artifactId,
|
|
7550
|
+
type: "roster.changed",
|
|
7551
|
+
actor: input.actor,
|
|
7552
|
+
payload: {
|
|
7553
|
+
round: before.round,
|
|
7554
|
+
respondents: list.length,
|
|
7555
|
+
complete: completeOf(list),
|
|
7556
|
+
...change.added.length > 0 ? { added: change.added } : {},
|
|
7557
|
+
...change.renamed.length > 0 ? { renamed: change.renamed } : {},
|
|
7558
|
+
...change.relinked.length > 0 ? { relinked: change.relinked } : {},
|
|
7559
|
+
...change.removed.length > 0 ? { removed: change.removed } : {}
|
|
7560
|
+
}
|
|
7561
|
+
});
|
|
7562
|
+
settleRoster(db, input.artifactId, input.now);
|
|
7563
|
+
}
|
|
7564
|
+
function peerOf(artifactId, viewer, self) {
|
|
7565
|
+
return {
|
|
7566
|
+
key: peerKey(artifactId, viewer.id),
|
|
7567
|
+
self,
|
|
7568
|
+
kind: viewer.kind,
|
|
7569
|
+
...viewer.name !== void 0 ? { name: viewer.name } : {},
|
|
7570
|
+
...viewer.verified !== void 0 ? { verified: viewer.verified } : {}
|
|
7571
|
+
};
|
|
7572
|
+
}
|
|
7573
|
+
/**
|
|
7574
|
+
* The roster as one page may see it (CO-03, CO-07): the viewer's own entry always (when they are
|
|
7575
|
+
* expected), the counts under `counts` and `names`, every respondent under `names`, and everything
|
|
7576
|
+
* for the artifact's owner. Never another viewer's `ref`, email or viewer ID.
|
|
7577
|
+
*/
|
|
7578
|
+
function rosterForPage(db, input) {
|
|
7579
|
+
const [one] = rosterForPages(db, {
|
|
7580
|
+
artifactId: input.artifactId,
|
|
7581
|
+
pages: [{
|
|
7582
|
+
viewerId: input.viewerId,
|
|
7583
|
+
owner: input.owner
|
|
7584
|
+
}],
|
|
7585
|
+
viewerOf: input.viewerOf
|
|
7586
|
+
});
|
|
7587
|
+
return one;
|
|
7588
|
+
}
|
|
7589
|
+
/**
|
|
7590
|
+
* The roster as each of several pages may see it, from one read of the standings (Opus review 9):
|
|
7591
|
+
* a change heard by many following pages costs one roster read, not one per page.
|
|
7592
|
+
*/
|
|
7593
|
+
function rosterForPages(db, input) {
|
|
7594
|
+
const state = stateOf(db, input.artifactId);
|
|
7595
|
+
const list = standings(db, input.artifactId, state);
|
|
7596
|
+
const visibility = teamVisibility(db, input.artifactId);
|
|
7597
|
+
const viewers = /* @__PURE__ */ new Map();
|
|
7598
|
+
const viewerOf = (viewerId) => {
|
|
7599
|
+
let viewer = viewers.get(viewerId);
|
|
7600
|
+
if (!viewer) {
|
|
7601
|
+
viewer = input.viewerOf(viewerId);
|
|
7602
|
+
viewers.set(viewerId, viewer);
|
|
7603
|
+
}
|
|
7604
|
+
return viewer;
|
|
7605
|
+
};
|
|
7606
|
+
const counts = countsOf(list);
|
|
7607
|
+
const complete = completeOf(list);
|
|
7608
|
+
const byViewer = new Map(list.map((one) => [one.entry.viewer_id, one]));
|
|
7609
|
+
return input.pages.map((page) => {
|
|
7610
|
+
const project = (one) => {
|
|
7611
|
+
const viewer = viewerOf(one.entry.viewer_id);
|
|
7612
|
+
return {
|
|
7613
|
+
...peerOf(input.artifactId, {
|
|
7614
|
+
...viewer,
|
|
7615
|
+
...one.entry.name !== null ? { name: one.entry.name } : {}
|
|
7616
|
+
}, one.entry.viewer_id === page.viewerId),
|
|
7617
|
+
status: one.status,
|
|
7618
|
+
...one.openedAt !== void 0 ? { openedAt: one.openedAt } : {},
|
|
7619
|
+
...one.submission ? { submittedAt: one.submission.at } : {}
|
|
7620
|
+
};
|
|
7621
|
+
};
|
|
7622
|
+
const own = byViewer.get(page.viewerId);
|
|
7623
|
+
const sees = page.owner ? "names" : visibility;
|
|
7624
|
+
return {
|
|
7625
|
+
visibility,
|
|
7626
|
+
owner: page.owner,
|
|
7627
|
+
round: state.round,
|
|
7628
|
+
...own ? { self: project(own) } : {},
|
|
7629
|
+
...sees !== "private" ? {
|
|
7630
|
+
counts,
|
|
7631
|
+
complete
|
|
7632
|
+
} : {},
|
|
7633
|
+
...sees === "names" ? { respondents: list.map(project) } : {}
|
|
7634
|
+
};
|
|
7635
|
+
});
|
|
7636
|
+
}
|
|
7637
|
+
/** The roster's events' types: pages never see them (they name refs and emails, D168). */
|
|
7638
|
+
const ROSTER_EVENTS = /* @__PURE__ */ new Set(["roster.changed", "roster.completed"]);
|
|
7639
|
+
//#endregion
|
|
7239
7640
|
//#region src/interaction/runs.ts
|
|
7240
7641
|
/**
|
|
7241
7642
|
* Action runs in the ledger (D24, D54, AC-02, AC-03; ARCHITECTURE §7): each invocation through
|
|
@@ -7635,6 +8036,87 @@ function submissionEvent(db, row) {
|
|
|
7635
8036
|
};
|
|
7636
8037
|
}
|
|
7637
8038
|
/**
|
|
8039
|
+
* The latest roster event at or before `upTo` (`roster.changed` or `roster.completed`), or the
|
|
8040
|
+
* roster's state a compaction summary kept for the events it replaced (DATA_MODEL §4).
|
|
8041
|
+
*/
|
|
8042
|
+
function latestRosterState(db, artifactId, upTo) {
|
|
8043
|
+
const row = db.get("SELECT * FROM event WHERE artifact_id = ? AND cursor <= ? AND type IN ('roster.changed', 'roster.completed', ?) ORDER BY cursor DESC LIMIT 1", artifactId, upTo, COMPACTED);
|
|
8044
|
+
if (!row) return void 0;
|
|
8045
|
+
const payload = JSON.parse(row.payload_json);
|
|
8046
|
+
if (row.type === "artifact.compacted") return payload["roster"];
|
|
8047
|
+
const lastCompleted = () => {
|
|
8048
|
+
const completed = db.get("SELECT * FROM event WHERE artifact_id = ? AND cursor <= ? AND type = 'roster.completed' ORDER BY cursor DESC LIMIT 1", artifactId, upTo);
|
|
8049
|
+
if (completed) return eventRecord(completed);
|
|
8050
|
+
const summary = db.get(`SELECT * FROM event WHERE artifact_id = ? AND cursor <= ? AND type = '${COMPACTED}' ORDER BY cursor DESC LIMIT 1`, artifactId, upTo);
|
|
8051
|
+
if (!summary) return void 0;
|
|
8052
|
+
return JSON.parse(summary.payload_json).roster?.completed;
|
|
8053
|
+
};
|
|
8054
|
+
if (row.type === "roster.completed") return {
|
|
8055
|
+
complete: true,
|
|
8056
|
+
completed: eventRecord(row)
|
|
8057
|
+
};
|
|
8058
|
+
if (payload["complete"] !== true) return { complete: false };
|
|
8059
|
+
const completed = lastCompleted();
|
|
8060
|
+
return completed ? {
|
|
8061
|
+
complete: true,
|
|
8062
|
+
completed
|
|
8063
|
+
} : { complete: true };
|
|
8064
|
+
}
|
|
8065
|
+
/**
|
|
8066
|
+
* `submitted:all` and `submitted:<N>` (D168, CO-02), under `once` per-viewer and `epochs`:
|
|
8067
|
+
* - `submitted:all` is the roster's completion. Under `once` per-viewer without an explicit
|
|
8068
|
+
* cursor it is level-triggered: the roster is complete now (its latest event says so), and the
|
|
8069
|
+
* latest `roster.completed` answers. Otherwise it is the first `roster.completed` after the
|
|
8070
|
+
* cursor, so an agent waits for each next completion (a roster that grew, an `epochs` round).
|
|
8071
|
+
* It is read from durable events only, so an owner instance answers it for a hosted artifact
|
|
8072
|
+
* from the events it follows.
|
|
8073
|
+
* - `submitted:<N>` counts submissions: under `once` per-viewer without an explicit cursor all of
|
|
8074
|
+
* them, otherwise those after the cursor; the N-th one's `submission.created` answers.
|
|
8075
|
+
* Under `once` per-artifact (one submission in all) only `submitted:1` can ever hold:
|
|
8076
|
+
* `MOSTRA_TEAM_ROSTER_POLICY` for the rest; under `none`, `MOSTRA_SUBMIT_POLICY_NONE`.
|
|
8077
|
+
*/
|
|
8078
|
+
function checkTeamCondition(db, artifactId, until, after, upTo, explicitAfter) {
|
|
8079
|
+
const policy = storedPolicy(db.get("SELECT policy_json FROM artifact WHERE id = ?", artifactId)?.policy_json ?? null);
|
|
8080
|
+
if (policy.policy === "none") throw new RpcError(createDiagnostic("MOSTRA_SUBMIT_POLICY_NONE", { message: "This artifact's submission policy is none: nothing will be submitted to wait for." }));
|
|
8081
|
+
const count = until === "submitted:all" ? void 0 : Number(until.slice(10));
|
|
8082
|
+
if (count !== void 0 && (!Number.isSafeInteger(count) || count < 1 || count > 1e4)) throw new RpcError(createDiagnostic("MOSTRA_HOST_INVALID_PARAMS", { message: "submitted:<N> takes a number of submissions from 1 to 10000." }), -32602);
|
|
8083
|
+
if (policy.policy === "once" && policy.scope !== "per-viewer" && count !== 1) throw new RpcError(createDiagnostic("MOSTRA_TEAM_ROSTER_POLICY", { message: `This artifact takes one submission in all (once, per-artifact), so ${until} could never hold.` }));
|
|
8084
|
+
const level = policy.policy === "once" && !explicitAfter;
|
|
8085
|
+
if (count !== void 0) {
|
|
8086
|
+
const from = level ? 0 : after;
|
|
8087
|
+
if (!level) checkCompaction(db, { artifacts: [artifactId] }, after);
|
|
8088
|
+
const row = db.get("SELECT * FROM submission WHERE artifact_id = ? AND position > ? AND position <= ? ORDER BY position LIMIT 1 OFFSET ?", artifactId, from, upTo, count - 1);
|
|
8089
|
+
if (row) return { event: submissionEvent(db, row) };
|
|
8090
|
+
return { cursor: Math.max(upTo, after) };
|
|
8091
|
+
}
|
|
8092
|
+
if (level) {
|
|
8093
|
+
const state = latestRosterState(db, artifactId, upTo);
|
|
8094
|
+
if (state?.complete && state.completed) return heldHere(db, state.completed) ? { event: state.completed } : { cursor: after };
|
|
8095
|
+
return { cursor: Math.max(upTo, after) };
|
|
8096
|
+
}
|
|
8097
|
+
checkCompaction(db, { artifacts: [artifactId] }, after);
|
|
8098
|
+
const completed = db.get("SELECT * FROM event WHERE artifact_id = ? AND cursor > ? AND cursor <= ? AND type = 'roster.completed' ORDER BY cursor LIMIT 1", artifactId, after, upTo);
|
|
8099
|
+
if (!completed) return { cursor: Math.max(upTo, after) };
|
|
8100
|
+
const event = eventRecord(completed);
|
|
8101
|
+
return heldHere(db, event) ? { event } : { cursor: Math.max(after, completed.cursor - 1) };
|
|
8102
|
+
}
|
|
8103
|
+
/**
|
|
8104
|
+
* Whether this home holds every submission a completion names. A local home always does (they
|
|
8105
|
+
* commit together); an owner instance copies a hosted `roster.completed` through its follow, while
|
|
8106
|
+
* the submissions arrive by delivery, so a wait answers only once the last one is imported and
|
|
8107
|
+
* `results` holds every answer the completion counts (J14). The import's commit wakes the wait.
|
|
8108
|
+
*/
|
|
8109
|
+
function heldHere(db, completed) {
|
|
8110
|
+
const named = completed.payload["submissions"];
|
|
8111
|
+
if (!Array.isArray(named)) return true;
|
|
8112
|
+
for (const entry of named) {
|
|
8113
|
+
const id = entry?.submissionId;
|
|
8114
|
+
if (typeof id !== "string" || id === "") continue;
|
|
8115
|
+
if (!db.get("SELECT 1 FROM submission WHERE id = ?", id)) return false;
|
|
8116
|
+
}
|
|
8117
|
+
return true;
|
|
8118
|
+
}
|
|
8119
|
+
/**
|
|
7638
8120
|
* Checks a condition once, inside the caller's read transaction: the event that satisfies it, or
|
|
7639
8121
|
* the newest cursor examined. Throws `MOSTRA_SUBMIT_POLICY_NONE` for `submitted` on an artifact
|
|
7640
8122
|
* without submissions, and `MOSTRA_HOST_CURSOR_COMPACTED` for a cursor inside a compacted range.
|
|
@@ -7643,6 +8125,7 @@ function checkCondition(db, artifactId, until, after, explicitAfter = true) {
|
|
|
7643
8125
|
const upTo = latestCursor(db);
|
|
7644
8126
|
const first = (sql, ...params) => db.get(`SELECT * FROM event WHERE artifact_id = ? AND cursor > ? AND cursor <= ? AND ${sql} ORDER BY cursor LIMIT 1`, artifactId, after, upTo, ...params);
|
|
7645
8127
|
let found;
|
|
8128
|
+
if (until === "submitted:all" || /^submitted:[0-9]+$/.test(until)) return checkTeamCondition(db, artifactId, until, after, upTo, explicitAfter);
|
|
7646
8129
|
if (until === "submitted") {
|
|
7647
8130
|
const policy = storedPolicy(db.get("SELECT policy_json FROM artifact WHERE id = ?", artifactId)?.policy_json ?? null);
|
|
7648
8131
|
if (policy.policy === "none") throw new RpcError(createDiagnostic("MOSTRA_SUBMIT_POLICY_NONE", { message: "This artifact's submission policy is none: nothing will be submitted to wait for." }));
|
|
@@ -7724,6 +8207,11 @@ const POLL_QUEUE_MAX = 1e3;
|
|
|
7724
8207
|
* - a run's delta that continues the one queued for the run merges into it, losing nothing.
|
|
7725
8208
|
*/
|
|
7726
8209
|
function coalesceInto(view, queue, message) {
|
|
8210
|
+
if (message.kind === "respondents" || message.kind === "presence") {
|
|
8211
|
+
for (let index = queue.length - 1; index >= 0; index--) if (queue[index].kind === message.kind) queue.splice(index, 1);
|
|
8212
|
+
queue.push(message);
|
|
8213
|
+
return;
|
|
8214
|
+
}
|
|
7727
8215
|
if (message.kind === "live") {
|
|
7728
8216
|
if (view.live.get(message.live.key)?.window === void 0 && message.live.value !== void 0) for (let index = queue.length - 1; index >= 0; index--) {
|
|
7729
8217
|
const queued = queue[index];
|
|
@@ -7844,6 +8332,10 @@ function createEphemeralBus(options = {}) {
|
|
|
7844
8332
|
if ((view.live.get(message.live.key)?.until ?? 0) > at) deliver(view, message);
|
|
7845
8333
|
}
|
|
7846
8334
|
},
|
|
8335
|
+
send(artifactId, viewId, message) {
|
|
8336
|
+
const view = views.get(viewId);
|
|
8337
|
+
if (view && view.artifactId === artifactId) deliver(view, message);
|
|
8338
|
+
},
|
|
7847
8339
|
listen(artifactId, viewId, listener) {
|
|
7848
8340
|
const view = viewOf(artifactId, viewId);
|
|
7849
8341
|
view.listeners.add(listener);
|
|
@@ -7902,6 +8394,296 @@ function createEphemeralBus(options = {}) {
|
|
|
7902
8394
|
};
|
|
7903
8395
|
}
|
|
7904
8396
|
//#endregion
|
|
8397
|
+
//#region src/interaction/team.ts
|
|
8398
|
+
/** How long a page stays present without posting again; pages post every 10 s. */
|
|
8399
|
+
const PRESENCE_LEASE_MS = 3e4;
|
|
8400
|
+
/** How long a view follows its roster after it read it; pages read again every 20 s. */
|
|
8401
|
+
const RESPONDENTS_LEASE_MS = 6e4;
|
|
8402
|
+
/** Creates team traffic over a bus. */
|
|
8403
|
+
function createTeamTraffic(options) {
|
|
8404
|
+
const { bus, source } = options;
|
|
8405
|
+
const now = options.now ?? Date.now;
|
|
8406
|
+
const present = /* @__PURE__ */ new Map();
|
|
8407
|
+
/** Each artifact's present views, so a fan-out reads only its own artifact's (Opus review 9). */
|
|
8408
|
+
const presentOn = /* @__PURE__ */ new Map();
|
|
8409
|
+
const put = (entry) => {
|
|
8410
|
+
present.set(entry.viewId, entry);
|
|
8411
|
+
let views = presentOn.get(entry.artifactId);
|
|
8412
|
+
if (!views) {
|
|
8413
|
+
views = /* @__PURE__ */ new Set();
|
|
8414
|
+
presentOn.set(entry.artifactId, views);
|
|
8415
|
+
}
|
|
8416
|
+
views.add(entry.viewId);
|
|
8417
|
+
};
|
|
8418
|
+
const drop = (viewId) => {
|
|
8419
|
+
const entry = present.get(viewId);
|
|
8420
|
+
if (!entry) return;
|
|
8421
|
+
present.delete(viewId);
|
|
8422
|
+
const views = presentOn.get(entry.artifactId);
|
|
8423
|
+
views?.delete(viewId);
|
|
8424
|
+
if (views?.size === 0) presentOn.delete(entry.artifactId);
|
|
8425
|
+
};
|
|
8426
|
+
const presentFor = function* (artifactId) {
|
|
8427
|
+
for (const viewId of presentOn.get(artifactId) ?? []) {
|
|
8428
|
+
const entry = present.get(viewId);
|
|
8429
|
+
if (entry) yield entry;
|
|
8430
|
+
}
|
|
8431
|
+
};
|
|
8432
|
+
const buckets = /* @__PURE__ */ new Map();
|
|
8433
|
+
const following = /* @__PURE__ */ new Map();
|
|
8434
|
+
const fanout = /* @__PURE__ */ new Map();
|
|
8435
|
+
const settle = /* @__PURE__ */ new Map();
|
|
8436
|
+
/** Lookups for one fan-out: each viewer's peer, the owner check and the visibility, read once. */
|
|
8437
|
+
const memo = (artifactId) => {
|
|
8438
|
+
const peers = /* @__PURE__ */ new Map();
|
|
8439
|
+
const owners = /* @__PURE__ */ new Map();
|
|
8440
|
+
let visibility;
|
|
8441
|
+
return {
|
|
8442
|
+
visibility: () => visibility ??= source.visibility(artifactId),
|
|
8443
|
+
isOwner: (viewerId) => {
|
|
8444
|
+
let owner = owners.get(viewerId);
|
|
8445
|
+
if (owner === void 0) {
|
|
8446
|
+
owner = source.isOwner(viewerId);
|
|
8447
|
+
owners.set(viewerId, owner);
|
|
8448
|
+
}
|
|
8449
|
+
return owner;
|
|
8450
|
+
},
|
|
8451
|
+
peer: (viewerId) => {
|
|
8452
|
+
let peer = peers.get(viewerId);
|
|
8453
|
+
if (!peer) {
|
|
8454
|
+
peer = source.peer(artifactId, viewerId);
|
|
8455
|
+
peers.set(viewerId, peer);
|
|
8456
|
+
}
|
|
8457
|
+
return peer;
|
|
8458
|
+
}
|
|
8459
|
+
};
|
|
8460
|
+
};
|
|
8461
|
+
/** Who is present on an artifact, as one viewer may see it. */
|
|
8462
|
+
const stateFor = (artifactId, viewerId, lookups = memo(artifactId)) => {
|
|
8463
|
+
const visibility = lookups.visibility();
|
|
8464
|
+
const sees = lookups.isOwner(viewerId) ? "names" : visibility;
|
|
8465
|
+
const at = now();
|
|
8466
|
+
const byViewer = /* @__PURE__ */ new Map();
|
|
8467
|
+
for (const entry of presentFor(artifactId)) {
|
|
8468
|
+
if (entry.until <= at) continue;
|
|
8469
|
+
const kept = byViewer.get(entry.viewerId);
|
|
8470
|
+
if (!kept || kept.at < entry.at) byViewer.set(entry.viewerId, entry);
|
|
8471
|
+
}
|
|
8472
|
+
const peerOf = (entry) => {
|
|
8473
|
+
const peer = lookups.peer(entry.viewerId);
|
|
8474
|
+
return {
|
|
8475
|
+
key: peer.key,
|
|
8476
|
+
self: entry.viewerId === viewerId,
|
|
8477
|
+
kind: peer.kind,
|
|
8478
|
+
...peer.name !== void 0 ? { name: peer.name } : {},
|
|
8479
|
+
...peer.verified !== void 0 ? { verified: peer.verified } : {},
|
|
8480
|
+
...entry.cursor ? { cursor: entry.cursor } : {},
|
|
8481
|
+
...entry.selection ? { selection: entry.selection } : {},
|
|
8482
|
+
at: new Date(entry.at).toISOString()
|
|
8483
|
+
};
|
|
8484
|
+
};
|
|
8485
|
+
const own = byViewer.get(viewerId);
|
|
8486
|
+
const others = [...byViewer.values()].filter((entry) => entry.viewerId !== viewerId);
|
|
8487
|
+
const peers = own ? [peerOf(own)] : [];
|
|
8488
|
+
if (sees === "names") {
|
|
8489
|
+
others.sort((a, b) => b.at - a.at);
|
|
8490
|
+
for (const entry of others.slice(0, 200)) peers.push(peerOf(entry));
|
|
8491
|
+
}
|
|
8492
|
+
return {
|
|
8493
|
+
visibility,
|
|
8494
|
+
peers,
|
|
8495
|
+
...sees !== "private" ? { others: others.length } : {}
|
|
8496
|
+
};
|
|
8497
|
+
};
|
|
8498
|
+
/**
|
|
8499
|
+
* Sends each present view of an artifact what it may see now, when that differs from what it
|
|
8500
|
+
* last got: a view under `private` sees only itself, so others coming, moving and going send it
|
|
8501
|
+
* nothing (Opus review 2), and under `counts` only a change of the count does.
|
|
8502
|
+
*/
|
|
8503
|
+
const fanOut = (artifactId) => {
|
|
8504
|
+
fanout.delete(artifactId);
|
|
8505
|
+
const at = now();
|
|
8506
|
+
const lookups = memo(artifactId);
|
|
8507
|
+
for (const entry of presentFor(artifactId)) {
|
|
8508
|
+
if (entry.until <= at) continue;
|
|
8509
|
+
try {
|
|
8510
|
+
const presence = stateFor(artifactId, entry.viewerId, lookups);
|
|
8511
|
+
const text = JSON.stringify(presence);
|
|
8512
|
+
if (text === entry.last) continue;
|
|
8513
|
+
entry.last = text;
|
|
8514
|
+
bus.send(artifactId, entry.viewId, {
|
|
8515
|
+
kind: "presence",
|
|
8516
|
+
presence
|
|
8517
|
+
});
|
|
8518
|
+
} catch (error) {
|
|
8519
|
+
options.log?.error("team.presence_failed", { error });
|
|
8520
|
+
}
|
|
8521
|
+
}
|
|
8522
|
+
};
|
|
8523
|
+
/** Schedules the artifact's next presence message, at most every {@link PRESENCE_FANOUT_MS}. */
|
|
8524
|
+
const changedPresence = (artifactId) => {
|
|
8525
|
+
if (fanout.has(artifactId)) return;
|
|
8526
|
+
const timer = setTimeout(() => fanOut(artifactId), 50);
|
|
8527
|
+
timer.unref?.();
|
|
8528
|
+
fanout.set(artifactId, timer);
|
|
8529
|
+
};
|
|
8530
|
+
/** Sends each following view its roster when it changed, from one read for all of them. */
|
|
8531
|
+
const sendRosters = (artifactId) => {
|
|
8532
|
+
settle.delete(artifactId);
|
|
8533
|
+
const at = now();
|
|
8534
|
+
const views = [];
|
|
8535
|
+
for (const [viewId, entry] of following) {
|
|
8536
|
+
if (entry.artifactId !== artifactId) continue;
|
|
8537
|
+
if (entry.until <= at) following.delete(viewId);
|
|
8538
|
+
else views.push([viewId, entry]);
|
|
8539
|
+
}
|
|
8540
|
+
if (views.length === 0) return;
|
|
8541
|
+
let rosters;
|
|
8542
|
+
try {
|
|
8543
|
+
rosters = source.rostersForPages(artifactId, views.map(([, entry]) => entry.viewerId));
|
|
8544
|
+
} catch (error) {
|
|
8545
|
+
options.log?.error("team.respondents_failed", { error });
|
|
8546
|
+
return;
|
|
8547
|
+
}
|
|
8548
|
+
views.forEach(([viewId, entry], index) => {
|
|
8549
|
+
const roster = rosters[index];
|
|
8550
|
+
if (!roster) return;
|
|
8551
|
+
const text = JSON.stringify(roster);
|
|
8552
|
+
if (text === entry.last) return;
|
|
8553
|
+
entry.last = text;
|
|
8554
|
+
try {
|
|
8555
|
+
bus.send(artifactId, viewId, {
|
|
8556
|
+
kind: "respondents",
|
|
8557
|
+
respondents: roster
|
|
8558
|
+
});
|
|
8559
|
+
} catch (error) {
|
|
8560
|
+
options.log?.error("team.respondents_failed", { error });
|
|
8561
|
+
}
|
|
8562
|
+
});
|
|
8563
|
+
};
|
|
8564
|
+
const stopTeam = source.onTeam((artifactId) => {
|
|
8565
|
+
let any = false;
|
|
8566
|
+
for (const entry of following.values()) if (entry.artifactId === artifactId) {
|
|
8567
|
+
any = true;
|
|
8568
|
+
break;
|
|
8569
|
+
}
|
|
8570
|
+
if (!any || settle.has(artifactId)) return;
|
|
8571
|
+
const timer = setTimeout(() => sendRosters(artifactId), 100);
|
|
8572
|
+
timer.unref?.();
|
|
8573
|
+
settle.set(artifactId, timer);
|
|
8574
|
+
});
|
|
8575
|
+
const sweep = setInterval(() => {
|
|
8576
|
+
const at = now();
|
|
8577
|
+
const left = /* @__PURE__ */ new Set();
|
|
8578
|
+
for (const [viewId, entry] of present) if (entry.until <= at) {
|
|
8579
|
+
drop(viewId);
|
|
8580
|
+
left.add(entry.artifactId);
|
|
8581
|
+
}
|
|
8582
|
+
for (const [viewId, entry] of following) if (entry.until <= at) following.delete(viewId);
|
|
8583
|
+
for (const [viewId, bucket] of buckets) if (bucket.refilled + 3e4 <= at) buckets.delete(viewId);
|
|
8584
|
+
for (const artifactId of left) changedPresence(artifactId);
|
|
8585
|
+
}, 1e3);
|
|
8586
|
+
sweep.unref?.();
|
|
8587
|
+
return {
|
|
8588
|
+
presence(page, request) {
|
|
8589
|
+
const at = now();
|
|
8590
|
+
const viewId = request.viewId;
|
|
8591
|
+
let entry = present.get(viewId);
|
|
8592
|
+
if (entry && (entry.artifactId !== page.artifactId || entry.viewerId !== page.viewerId)) {
|
|
8593
|
+
drop(viewId);
|
|
8594
|
+
entry = void 0;
|
|
8595
|
+
}
|
|
8596
|
+
const known = buckets.get(viewId);
|
|
8597
|
+
const stale = request.seq !== void 0 && known?.seq !== void 0 && request.seq <= known.seq;
|
|
8598
|
+
if (request.seq !== void 0 && !stale) {
|
|
8599
|
+
const remembered = known ?? {
|
|
8600
|
+
tokens: 20,
|
|
8601
|
+
refilled: at
|
|
8602
|
+
};
|
|
8603
|
+
remembered.seq = request.seq;
|
|
8604
|
+
buckets.set(viewId, remembered);
|
|
8605
|
+
}
|
|
8606
|
+
if (request.leave === true && entry && !stale) {
|
|
8607
|
+
drop(viewId);
|
|
8608
|
+
changedPresence(page.artifactId);
|
|
8609
|
+
return { state: stateFor(page.artifactId, page.viewerId) };
|
|
8610
|
+
}
|
|
8611
|
+
const bucket = buckets.get(viewId) ?? {
|
|
8612
|
+
tokens: 20,
|
|
8613
|
+
refilled: at
|
|
8614
|
+
};
|
|
8615
|
+
bucket.tokens = Math.min(20, bucket.tokens + (at - bucket.refilled) / 1e3 * 20);
|
|
8616
|
+
bucket.refilled = at;
|
|
8617
|
+
buckets.set(viewId, bucket);
|
|
8618
|
+
if (bucket.tokens < 1) return {
|
|
8619
|
+
limited: true,
|
|
8620
|
+
retryAfterMs: Math.ceil((1 - bucket.tokens) / 20 * 1e3)
|
|
8621
|
+
};
|
|
8622
|
+
bucket.tokens -= 1;
|
|
8623
|
+
if (stale || request.leave === true) return { state: stateFor(page.artifactId, page.viewerId) };
|
|
8624
|
+
if (!entry) {
|
|
8625
|
+
entry = {
|
|
8626
|
+
artifactId: page.artifactId,
|
|
8627
|
+
viewId,
|
|
8628
|
+
viewerId: page.viewerId,
|
|
8629
|
+
at,
|
|
8630
|
+
until: at + PRESENCE_LEASE_MS
|
|
8631
|
+
};
|
|
8632
|
+
put(entry);
|
|
8633
|
+
}
|
|
8634
|
+
if (request.cursor !== void 0) {
|
|
8635
|
+
if (request.cursor === null) delete entry.cursor;
|
|
8636
|
+
else entry.cursor = {
|
|
8637
|
+
x: request.cursor.x,
|
|
8638
|
+
y: request.cursor.y
|
|
8639
|
+
};
|
|
8640
|
+
}
|
|
8641
|
+
if (request.selection !== void 0) {
|
|
8642
|
+
if (request.selection === null) delete entry.selection;
|
|
8643
|
+
else entry.selection = {
|
|
8644
|
+
...request.selection.element !== void 0 ? { element: request.selection.element } : {},
|
|
8645
|
+
...request.selection.start !== void 0 ? { start: request.selection.start } : {},
|
|
8646
|
+
...request.selection.end !== void 0 ? { end: request.selection.end } : {}
|
|
8647
|
+
};
|
|
8648
|
+
}
|
|
8649
|
+
entry.at = at;
|
|
8650
|
+
entry.until = at + PRESENCE_LEASE_MS;
|
|
8651
|
+
changedPresence(page.artifactId);
|
|
8652
|
+
const state = stateFor(page.artifactId, page.viewerId);
|
|
8653
|
+
entry.last = JSON.stringify(state);
|
|
8654
|
+
return { state };
|
|
8655
|
+
},
|
|
8656
|
+
respondents(page, viewId) {
|
|
8657
|
+
const roster = source.rosterForPage(page);
|
|
8658
|
+
following.set(viewId, {
|
|
8659
|
+
artifactId: page.artifactId,
|
|
8660
|
+
viewerId: page.viewerId,
|
|
8661
|
+
until: now() + RESPONDENTS_LEASE_MS,
|
|
8662
|
+
last: JSON.stringify(roster)
|
|
8663
|
+
});
|
|
8664
|
+
return roster;
|
|
8665
|
+
},
|
|
8666
|
+
presentCount() {
|
|
8667
|
+
const at = now();
|
|
8668
|
+
let count = 0;
|
|
8669
|
+
for (const entry of present.values()) if (entry.until > at) count += 1;
|
|
8670
|
+
return count;
|
|
8671
|
+
},
|
|
8672
|
+
close() {
|
|
8673
|
+
clearInterval(sweep);
|
|
8674
|
+
present.clear();
|
|
8675
|
+
presentOn.clear();
|
|
8676
|
+
buckets.clear();
|
|
8677
|
+
following.clear();
|
|
8678
|
+
stopTeam();
|
|
8679
|
+
for (const timer of fanout.values()) clearTimeout(timer);
|
|
8680
|
+
for (const timer of settle.values()) clearTimeout(timer);
|
|
8681
|
+
fanout.clear();
|
|
8682
|
+
settle.clear();
|
|
8683
|
+
}
|
|
8684
|
+
};
|
|
8685
|
+
}
|
|
8686
|
+
//#endregion
|
|
7905
8687
|
//#region src/interaction/index.ts
|
|
7906
8688
|
/**
|
|
7907
8689
|
* The interaction core (ARCHITECTURE §6; IN-01 to IN-12, LL-01, LL-02): drafts and artifact
|
|
@@ -7939,6 +8721,7 @@ function versionNumber(db, versionId) {
|
|
|
7939
8721
|
*/
|
|
7940
8722
|
function visibleTo(event, page, run) {
|
|
7941
8723
|
const viewerId = page.viewerId;
|
|
8724
|
+
if (ROSTER_EVENTS.has(event.type)) return false;
|
|
7942
8725
|
if (event.type.startsWith("draft.")) return event.payload["viewerId"] === viewerId;
|
|
7943
8726
|
if (event.type.startsWith("host.")) return false;
|
|
7944
8727
|
if (event.type.startsWith("action.")) {
|
|
@@ -7950,16 +8733,36 @@ function visibleTo(event, page, run) {
|
|
|
7950
8733
|
return true;
|
|
7951
8734
|
}
|
|
7952
8735
|
/**
|
|
7953
|
-
* Another viewer as a page sees them: kind
|
|
7954
|
-
* (D104; Claude review finding 12). The name stays, so a conflict can say
|
|
8736
|
+
* Another viewer as a page sees them: kind, display name and their key on this artifact, never
|
|
8737
|
+
* their viewer or view IDs (D104; Claude review finding 12). The name stays, so a conflict can say
|
|
8738
|
+
* who changed a field, and the key lets a page tell two people of one name apart and match the
|
|
8739
|
+
* writer of a shared field to a respondent or a present viewer (D168, CO-05).
|
|
7955
8740
|
*/
|
|
7956
|
-
function actorForPage(actor, viewerId) {
|
|
7957
|
-
if (actor.kind !== "viewer" || actor.id ===
|
|
8741
|
+
function actorForPage(actor, viewerId, artifactId) {
|
|
8742
|
+
if (actor.kind !== "viewer" || actor.id === void 0) return actor;
|
|
8743
|
+
const key = peerKey(artifactId, actor.id);
|
|
8744
|
+
if (actor.id === viewerId) return {
|
|
8745
|
+
...actor,
|
|
8746
|
+
key
|
|
8747
|
+
};
|
|
7958
8748
|
return {
|
|
7959
8749
|
kind: "viewer",
|
|
7960
|
-
...actor.name !== void 0 ? { name: actor.name } : {}
|
|
8750
|
+
...actor.name !== void 0 ? { name: actor.name } : {},
|
|
8751
|
+
key
|
|
7961
8752
|
};
|
|
7962
8753
|
}
|
|
8754
|
+
/**
|
|
8755
|
+
* How a page sees an event of a submission (CO-07, D168): its own as it is; another viewer's
|
|
8756
|
+
* under `once` for the whole artifact as it is, since it closes every draft; otherwise only its
|
|
8757
|
+
* `submission.created`, and only as the visibility allows: none under `private`, without a name
|
|
8758
|
+
* or key under `counts`, named under `names`. Another viewer's deliveries tell a page nothing it
|
|
8759
|
+
* needs, so they never reach it there.
|
|
8760
|
+
*/
|
|
8761
|
+
function submissionShown(event, viewerId, standing, submitterOf) {
|
|
8762
|
+
if ((event.type === "submission.created" ? String(event.payload["viewerId"] ?? "") : submitterOf(String(event.payload["submissionId"] ?? ""))) === viewerId || standing.closesAll) return "as-is";
|
|
8763
|
+
if (event.type !== "submission.created" || standing.visibility === "private") return "hidden";
|
|
8764
|
+
return standing.visibility === "counts" ? "anonymous" : "as-is";
|
|
8765
|
+
}
|
|
7963
8766
|
/** An event as a page sees it: other viewers' identities left out. */
|
|
7964
8767
|
function eventForPage(event, viewerId) {
|
|
7965
8768
|
if (event.type === "worker.crashed") {
|
|
@@ -7976,21 +8779,24 @@ function eventForPage(event, viewerId) {
|
|
|
7976
8779
|
payload
|
|
7977
8780
|
};
|
|
7978
8781
|
}
|
|
7979
|
-
if (event.actor.kind !== "viewer" || event.actor.id === viewerId) return event
|
|
8782
|
+
if (event.actor.kind !== "viewer" || event.actor.id === viewerId) return event.actor.kind === "viewer" ? {
|
|
8783
|
+
...event,
|
|
8784
|
+
actor: actorForPage(event.actor, viewerId, event.artifactId ?? "")
|
|
8785
|
+
} : event;
|
|
7980
8786
|
const { viewerId: _viewer, viewId: _view, ...payload } = event.payload;
|
|
7981
8787
|
const causation = event.causation ? Object.fromEntries(Object.entries(event.causation).filter(([key]) => key !== "viewId")) : void 0;
|
|
7982
8788
|
return {
|
|
7983
8789
|
...event,
|
|
7984
|
-
actor: actorForPage(event.actor, viewerId),
|
|
8790
|
+
actor: actorForPage(event.actor, viewerId, event.artifactId ?? ""),
|
|
7985
8791
|
...causation ? { causation } : {},
|
|
7986
8792
|
payload
|
|
7987
8793
|
};
|
|
7988
8794
|
}
|
|
7989
8795
|
/** Fields as a page sees them: who last wrote each, without another viewer's ID. */
|
|
7990
|
-
function fieldsForPage(fields, viewerId) {
|
|
8796
|
+
function fieldsForPage(fields, viewerId, artifactId) {
|
|
7991
8797
|
return Object.fromEntries(Object.entries(fields).map(([id, field]) => [id, field.updatedBy ? {
|
|
7992
8798
|
...field,
|
|
7993
|
-
updatedBy: actorForPage(field.updatedBy, viewerId)
|
|
8799
|
+
updatedBy: actorForPage(field.updatedBy, viewerId, artifactId)
|
|
7994
8800
|
} : field]));
|
|
7995
8801
|
}
|
|
7996
8802
|
/**
|
|
@@ -8023,6 +8829,15 @@ function createInteraction(options) {
|
|
|
8023
8829
|
}
|
|
8024
8830
|
};
|
|
8025
8831
|
const tallyListeners = /* @__PURE__ */ new Set();
|
|
8832
|
+
const teamListeners = /* @__PURE__ */ new Set();
|
|
8833
|
+
/** Tells the team routes an artifact's respondents' status may have changed (D168). */
|
|
8834
|
+
const touched = (artifactId) => {
|
|
8835
|
+
for (const listener of teamListeners) try {
|
|
8836
|
+
listener(artifactId);
|
|
8837
|
+
} catch (error) {
|
|
8838
|
+
log.error("interaction.team_listener_failed", { error });
|
|
8839
|
+
}
|
|
8840
|
+
};
|
|
8026
8841
|
const { ledger, log, hosts } = options;
|
|
8027
8842
|
const outbox = new Outbox({
|
|
8028
8843
|
ledger,
|
|
@@ -8059,6 +8874,15 @@ function createInteraction(options) {
|
|
|
8059
8874
|
kind: as,
|
|
8060
8875
|
...session.client ? { id: session.client.name } : {}
|
|
8061
8876
|
});
|
|
8877
|
+
/** Whether a viewer is the artifact's owner (CO-07): the local user, or a hosted home's account. */
|
|
8878
|
+
const ownerOf = (db, viewerId) => {
|
|
8879
|
+
const row = db.get("SELECT kind, external_ref FROM viewer WHERE id = ?", viewerId);
|
|
8880
|
+
if (!row) return false;
|
|
8881
|
+
return options.isOwner ? options.isOwner({
|
|
8882
|
+
kind: row.kind,
|
|
8883
|
+
ref: row.external_ref
|
|
8884
|
+
}) : row.kind === "local";
|
|
8885
|
+
};
|
|
8062
8886
|
return {
|
|
8063
8887
|
start() {
|
|
8064
8888
|
outbox.start();
|
|
@@ -8083,7 +8907,9 @@ function createInteraction(options) {
|
|
|
8083
8907
|
pause: (artifactId, change) => ledger.write((db) => setPause(db, artifactId, change)),
|
|
8084
8908
|
pauseOf: (artifactId) => ledger.read((db) => pauseOf(db, artifactId)),
|
|
8085
8909
|
openView(input) {
|
|
8086
|
-
|
|
8910
|
+
const viewId = ledger.write((db) => openView(db, input));
|
|
8911
|
+
touched(input.artifactId);
|
|
8912
|
+
return viewId;
|
|
8087
8913
|
},
|
|
8088
8914
|
viewControls(page, viewId) {
|
|
8089
8915
|
return ledger.read((db) => viewControls(viewFor(db, viewId, page.artifactId, page.viewerId, page.tokenId)));
|
|
@@ -8122,20 +8948,31 @@ function createInteraction(options) {
|
|
|
8122
8948
|
...outcome.result,
|
|
8123
8949
|
conflicts: outcome.result.conflicts.map((conflict) => conflict.updatedBy ? {
|
|
8124
8950
|
...conflict,
|
|
8125
|
-
updatedBy: actorForPage(conflict.updatedBy, page.viewerId)
|
|
8951
|
+
updatedBy: actorForPage(conflict.updatedBy, page.viewerId, page.artifactId)
|
|
8126
8952
|
} : conflict)
|
|
8127
8953
|
};
|
|
8128
|
-
if (outcome.changed && input.scope === "viewer")
|
|
8954
|
+
if (outcome.changed && input.scope === "viewer") {
|
|
8955
|
+
outbox.mirror(page.artifactId, page.viewerId);
|
|
8956
|
+
touched(page.artifactId);
|
|
8957
|
+
}
|
|
8129
8958
|
return result;
|
|
8130
8959
|
},
|
|
8131
8960
|
importSubmission(envelope, source) {
|
|
8132
8961
|
const owners = options.deliveryOwners?.(envelope.artifactId) ?? outbox.owners();
|
|
8133
|
-
|
|
8134
|
-
|
|
8135
|
-
|
|
8136
|
-
|
|
8137
|
-
|
|
8138
|
-
|
|
8962
|
+
let created = false;
|
|
8963
|
+
const answer = ledger.write((db) => {
|
|
8964
|
+
const held = db.get("SELECT 1 FROM submission WHERE id = ?", envelope.submissionId);
|
|
8965
|
+
const result = importSubmission(db, {
|
|
8966
|
+
envelope,
|
|
8967
|
+
source,
|
|
8968
|
+
owners,
|
|
8969
|
+
owned: (inner, artifactId) => inner.get("SELECT 1 FROM hosted_artifact WHERE artifact_id = ? AND server = ?", artifactId, source.server) !== void 0
|
|
8970
|
+
});
|
|
8971
|
+
created = held === void 0 && db.get("SELECT 1 FROM submission WHERE id = ?", envelope.submissionId) !== void 0;
|
|
8972
|
+
if (created) settleRoster(db, envelope.artifactId, (/* @__PURE__ */ new Date()).toISOString());
|
|
8973
|
+
return result;
|
|
8974
|
+
});
|
|
8975
|
+
if (created) touched(envelope.artifactId);
|
|
8139
8976
|
log.info("interaction.imported", {
|
|
8140
8977
|
artifactId: envelope.artifactId,
|
|
8141
8978
|
submissionId: envelope.submissionId,
|
|
@@ -8177,16 +9014,21 @@ function createInteraction(options) {
|
|
|
8177
9014
|
},
|
|
8178
9015
|
submit(page, input) {
|
|
8179
9016
|
const owners = options.deliveryOwners?.(page.artifactId) ?? outbox.owners();
|
|
8180
|
-
const outcome = asPage(() => ledger.write((db) =>
|
|
8181
|
-
|
|
8182
|
-
|
|
8183
|
-
|
|
8184
|
-
|
|
8185
|
-
|
|
8186
|
-
|
|
8187
|
-
|
|
8188
|
-
|
|
8189
|
-
|
|
9017
|
+
const outcome = asPage(() => ledger.write((db) => {
|
|
9018
|
+
const made = submit(db, {
|
|
9019
|
+
artifactId: page.artifactId,
|
|
9020
|
+
viewerId: page.viewerId,
|
|
9021
|
+
...page.tokenId !== void 0 ? { tokenId: page.tokenId } : {},
|
|
9022
|
+
viewId: input.viewId,
|
|
9023
|
+
expectedRevision: input.expectedRevision,
|
|
9024
|
+
channel: input.channel,
|
|
9025
|
+
owners,
|
|
9026
|
+
covers: options.coverage
|
|
9027
|
+
});
|
|
9028
|
+
if (made.created) settleRoster(db, page.artifactId, (/* @__PURE__ */ new Date()).toISOString());
|
|
9029
|
+
return made;
|
|
9030
|
+
}));
|
|
9031
|
+
if (outcome.created) touched(page.artifactId);
|
|
8190
9032
|
if (outcome.tallied) for (const listener of tallyListeners) try {
|
|
8191
9033
|
listener(page.artifactId, outcome.tallied);
|
|
8192
9034
|
} catch (error) {
|
|
@@ -8287,7 +9129,7 @@ function createInteraction(options) {
|
|
|
8287
9129
|
const state = documentSnapshot(db, page.artifactId, null);
|
|
8288
9130
|
return {
|
|
8289
9131
|
...state,
|
|
8290
|
-
fields: fieldsForPage(state.fields, page.viewerId)
|
|
9132
|
+
fields: fieldsForPage(state.fields, page.viewerId, page.artifactId)
|
|
8291
9133
|
};
|
|
8292
9134
|
})(),
|
|
8293
9135
|
...latestOwn ? { submission: forPage(submissionSummary(db, latestOwn)) } : {},
|
|
@@ -8312,6 +9154,12 @@ function createInteraction(options) {
|
|
|
8312
9154
|
if (!runs.has(runId)) runs.set(runId, runById(db, page.artifactId, runId));
|
|
8313
9155
|
return runs.get(runId);
|
|
8314
9156
|
};
|
|
9157
|
+
const standing = submissionStanding(db, page.artifactId, ownerOf(db, page.viewerId));
|
|
9158
|
+
const submitters = /* @__PURE__ */ new Map();
|
|
9159
|
+
const submitterOf = (submissionId) => {
|
|
9160
|
+
if (!submitters.has(submissionId)) submitters.set(submissionId, db.get("SELECT viewer_id FROM submission WHERE id = ?", submissionId)?.viewer_id);
|
|
9161
|
+
return submitters.get(submissionId);
|
|
9162
|
+
};
|
|
8315
9163
|
for (;;) {
|
|
8316
9164
|
const read = readEvents(db, {
|
|
8317
9165
|
filter: { artifacts: [page.artifactId] },
|
|
@@ -8325,6 +9173,16 @@ function createInteraction(options) {
|
|
|
8325
9173
|
};
|
|
8326
9174
|
cursor = Number(event.cursor);
|
|
8327
9175
|
if (options.sentOnly && DELIVERY_EVENTS.has(event.type)) continue;
|
|
9176
|
+
if (event.type.startsWith("submission.")) {
|
|
9177
|
+
const shown = submissionShown(event, page.viewerId, standing, submitterOf);
|
|
9178
|
+
if (shown === "hidden") continue;
|
|
9179
|
+
const seen = eventForPage(event, page.viewerId);
|
|
9180
|
+
events.push(shown === "anonymous" ? {
|
|
9181
|
+
...seen,
|
|
9182
|
+
actor: { kind: seen.actor.kind }
|
|
9183
|
+
} : seen);
|
|
9184
|
+
continue;
|
|
9185
|
+
}
|
|
8328
9186
|
if (visibleTo(event, page, runOf)) events.push(eventForPage(event, page.viewerId));
|
|
8329
9187
|
}
|
|
8330
9188
|
cursor = Math.max(cursor, Number(read.cursor));
|
|
@@ -8374,6 +9232,26 @@ function createInteraction(options) {
|
|
|
8374
9232
|
};
|
|
8375
9233
|
});
|
|
8376
9234
|
}),
|
|
9235
|
+
handler(resultsListMethod, (params) => {
|
|
9236
|
+
const artifactId = options.artifacts.resolve(params.artifact);
|
|
9237
|
+
const after = params.after === void 0 ? 0 : Number(params.after);
|
|
9238
|
+
const limit = params.limit ?? RESULTS_LIST_MAX;
|
|
9239
|
+
return ledger.read((db) => {
|
|
9240
|
+
const rows = db.all("SELECT * FROM submission WHERE artifact_id = ? AND position > ? ORDER BY position LIMIT ?", artifactId, after, limit + 1);
|
|
9241
|
+
const page = rows.slice(0, limit);
|
|
9242
|
+
return {
|
|
9243
|
+
results: page.map((row) => {
|
|
9244
|
+
const results = buildResults(db, row);
|
|
9245
|
+
return params.format === "md" ? {
|
|
9246
|
+
submissionId: row.id,
|
|
9247
|
+
markdown: resultsMarkdown(results, JSON.parse(row.snapshot_json))
|
|
9248
|
+
} : results;
|
|
9249
|
+
}),
|
|
9250
|
+
cursor: String(page.at(-1)?.position ?? after),
|
|
9251
|
+
more: rows.length > limit
|
|
9252
|
+
};
|
|
9253
|
+
});
|
|
9254
|
+
}),
|
|
8377
9255
|
handler(waitMethod, (params, session) => waitFor({
|
|
8378
9256
|
ledger,
|
|
8379
9257
|
artifactId: options.artifacts.resolve(params.artifact),
|
|
@@ -8568,7 +9446,58 @@ function createInteraction(options) {
|
|
|
8568
9446
|
tallyListeners.add(listener);
|
|
8569
9447
|
return () => tallyListeners.delete(listener);
|
|
8570
9448
|
},
|
|
8571
|
-
subscriptionCount: () => subscriptions.size
|
|
9449
|
+
subscriptionCount: () => subscriptions.size,
|
|
9450
|
+
addRespondents(db, input) {
|
|
9451
|
+
const added = addRespondents(db, {
|
|
9452
|
+
...input,
|
|
9453
|
+
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
9454
|
+
});
|
|
9455
|
+
queueMicrotask(() => touched(input.artifactId));
|
|
9456
|
+
return added;
|
|
9457
|
+
},
|
|
9458
|
+
removeRespondents(db, input) {
|
|
9459
|
+
const removed = removeRespondents(db, {
|
|
9460
|
+
...input,
|
|
9461
|
+
now: (/* @__PURE__ */ new Date()).toISOString()
|
|
9462
|
+
});
|
|
9463
|
+
queueMicrotask(() => touched(input.artifactId));
|
|
9464
|
+
return removed;
|
|
9465
|
+
},
|
|
9466
|
+
roster: (artifactId, live) => ledger.read((db) => readRoster(db, artifactId, live)),
|
|
9467
|
+
rosterForPage(page) {
|
|
9468
|
+
return ledger.read((db) => rosterForPage(db, {
|
|
9469
|
+
artifactId: page.artifactId,
|
|
9470
|
+
viewerId: page.viewerId,
|
|
9471
|
+
owner: ownerOf(db, page.viewerId),
|
|
9472
|
+
viewerOf: (viewerId) => viewer(db, viewerId)
|
|
9473
|
+
}));
|
|
9474
|
+
},
|
|
9475
|
+
rostersForPages(artifactId, viewerIds) {
|
|
9476
|
+
return ledger.read((db) => rosterForPages(db, {
|
|
9477
|
+
artifactId,
|
|
9478
|
+
pages: viewerIds.map((viewerId) => ({
|
|
9479
|
+
viewerId,
|
|
9480
|
+
owner: ownerOf(db, viewerId)
|
|
9481
|
+
})),
|
|
9482
|
+
viewerOf: (viewerId) => viewer(db, viewerId)
|
|
9483
|
+
}));
|
|
9484
|
+
},
|
|
9485
|
+
visibility: (artifactId) => ledger.read((db) => teamVisibility(db, artifactId)),
|
|
9486
|
+
isOwner: (viewerId) => ledger.read((db) => ownerOf(db, viewerId)),
|
|
9487
|
+
peer(artifactId, viewerId) {
|
|
9488
|
+
const record = ledger.read((db) => viewer(db, viewerId));
|
|
9489
|
+
return {
|
|
9490
|
+
key: peerKey(artifactId, viewerId),
|
|
9491
|
+
id: record.id,
|
|
9492
|
+
kind: record.kind,
|
|
9493
|
+
...record.name !== void 0 ? { name: record.name } : {},
|
|
9494
|
+
...record.verified !== void 0 ? { verified: record.verified } : {}
|
|
9495
|
+
};
|
|
9496
|
+
},
|
|
9497
|
+
onTeam(listener) {
|
|
9498
|
+
teamListeners.add(listener);
|
|
9499
|
+
return () => teamListeners.delete(listener);
|
|
9500
|
+
}
|
|
8572
9501
|
};
|
|
8573
9502
|
}
|
|
8574
9503
|
//#endregion
|
|
@@ -9205,9 +10134,12 @@ const STATUS$1 = {
|
|
|
9205
10134
|
MOSTRA_HOME_GONE: 503,
|
|
9206
10135
|
MOSTRA_REMOTE_OWNER_OFFLINE: 503,
|
|
9207
10136
|
MOSTRA_REMOTE_QUEUE_FULL: 503,
|
|
10137
|
+
MOSTRA_REMOTE_LIMIT_REACHED: 403,
|
|
9208
10138
|
MOSTRA_REMOTE_SIGN_IN_REQUIRED: 403,
|
|
9209
10139
|
MOSTRA_REMOTE_RATE_LIMITED: 429,
|
|
9210
|
-
MOSTRA_ACTION_PAUSED: 423
|
|
10140
|
+
MOSTRA_ACTION_PAUSED: 423,
|
|
10141
|
+
MOSTRA_HYGIENE_TOKEN_REVOKED: 410,
|
|
10142
|
+
MOSTRA_ACTION_CANCELLED: 409
|
|
9211
10143
|
};
|
|
9212
10144
|
function answer$1(diagnostic, status) {
|
|
9213
10145
|
return jsonResponse({ ...diagnostic }, { status });
|
|
@@ -9325,7 +10257,7 @@ function actionRoutes(options) {
|
|
|
9325
10257
|
const pausedNow = paused(page);
|
|
9326
10258
|
if (pausedNow) return pausedNow;
|
|
9327
10259
|
try {
|
|
9328
|
-
return jsonResponse(actions.startRun(page, {
|
|
10260
|
+
return jsonResponse(await actions.startRun(page, {
|
|
9329
10261
|
viewId: request.viewId,
|
|
9330
10262
|
fnId: request.fnId,
|
|
9331
10263
|
args: request.args,
|
|
@@ -9413,7 +10345,8 @@ const STATUS = {
|
|
|
9413
10345
|
MOSTRA_HOME_DISK_FULL: 507,
|
|
9414
10346
|
MOSTRA_HOME_GONE: 503,
|
|
9415
10347
|
MOSTRA_HYGIENE_SCOPE_DENIED: 403,
|
|
9416
|
-
MOSTRA_SUBMIT_PAUSED: 423
|
|
10348
|
+
MOSTRA_SUBMIT_PAUSED: 423,
|
|
10349
|
+
MOSTRA_TEAM_PRESENCE_RATE_LIMITED: 429
|
|
9417
10350
|
};
|
|
9418
10351
|
/** A refusal or a diagnostic as the browser gets it. */
|
|
9419
10352
|
function answer(diagnostic, status, extra = {}) {
|
|
@@ -9425,6 +10358,15 @@ function answer(diagnostic, status, extra = {}) {
|
|
|
9425
10358
|
function malformed(message) {
|
|
9426
10359
|
return answer(refusal("MOSTRA_HYGIENE_REQUEST_MALFORMED", message).diagnostic, 400);
|
|
9427
10360
|
}
|
|
10361
|
+
/** What an ephemeral message's SSE `data` carries: the message's own payload, by its kind. */
|
|
10362
|
+
function ephemeralData(message) {
|
|
10363
|
+
switch (message.kind) {
|
|
10364
|
+
case "run": return message.run;
|
|
10365
|
+
case "live": return message.live;
|
|
10366
|
+
case "respondents": return message.respondents;
|
|
10367
|
+
case "presence": return message.presence;
|
|
10368
|
+
}
|
|
10369
|
+
}
|
|
9428
10370
|
/** Turns an interaction refusal into its response; anything else is a defect for `onError`. */
|
|
9429
10371
|
function failure(error) {
|
|
9430
10372
|
if (error instanceof SubmitConflict) return answer(error.diagnostic, 409, { submission: error.submission });
|
|
@@ -9592,7 +10534,7 @@ function browserRoutes(options) {
|
|
|
9592
10534
|
wake?.();
|
|
9593
10535
|
});
|
|
9594
10536
|
const held = [];
|
|
9595
|
-
const heldText = () => held.splice(0).map((message) => `event: ${message.kind}\ndata: ${JSON.stringify(message
|
|
10537
|
+
const heldText = () => held.splice(0).map((message) => `event: ${message.kind}\ndata: ${JSON.stringify(ephemeralData(message))}\n\n`).join("");
|
|
9596
10538
|
const unlisten = options.bus?.listen(page.artifactId, viewIdOf(context), (message) => {
|
|
9597
10539
|
options.bus?.coalesce(page.artifactId, viewIdOf(context), held, message);
|
|
9598
10540
|
if (held.length > EPHEMERAL_HELD) held.splice(0, held.length - EPHEMERAL_HELD);
|
|
@@ -9859,6 +10801,43 @@ function browserRoutes(options) {
|
|
|
9859
10801
|
return failure(error);
|
|
9860
10802
|
}
|
|
9861
10803
|
};
|
|
10804
|
+
/** A handler of a team route without team traffic: this gateway serves neither (verify's). */
|
|
10805
|
+
const noTeam = () => answer(refusal("MOSTRA_HYGIENE_NOT_SERVED", "This gateway serves no respondents or presence.", 404).diagnostic, 404);
|
|
10806
|
+
/** `respondents` (D168): the roster as the page may see it, followed for a minute. */
|
|
10807
|
+
const respondents = async (context) => {
|
|
10808
|
+
const refused = knownRevision(context);
|
|
10809
|
+
if (refused) return refused;
|
|
10810
|
+
if (!options.team) return noTeam();
|
|
10811
|
+
const request = await body(context, RespondentsRequest);
|
|
10812
|
+
if (request instanceof Response) return request;
|
|
10813
|
+
const page = pageOf(context);
|
|
10814
|
+
try {
|
|
10815
|
+
interaction.checkView(page, request.viewId);
|
|
10816
|
+
return jsonResponse(options.team.respondents(page, request.viewId));
|
|
10817
|
+
} catch (error) {
|
|
10818
|
+
return failure(error);
|
|
10819
|
+
}
|
|
10820
|
+
};
|
|
10821
|
+
/** `presence` (D168, CO-04): joins, shares or leaves; never stored. */
|
|
10822
|
+
const presence = async (context) => {
|
|
10823
|
+
const refused = knownRevision(context);
|
|
10824
|
+
if (refused) return refused;
|
|
10825
|
+
if (!options.team) return noTeam();
|
|
10826
|
+
const request = await body(context, PresenceRequest);
|
|
10827
|
+
if (request instanceof Response) return request;
|
|
10828
|
+
const page = pageOf(context);
|
|
10829
|
+
try {
|
|
10830
|
+
interaction.checkView(page, request.viewId);
|
|
10831
|
+
} catch (error) {
|
|
10832
|
+
return failure(error);
|
|
10833
|
+
}
|
|
10834
|
+
const outcome = options.team.presence(page, request);
|
|
10835
|
+
if ("limited" in outcome) return jsonResponse(createDiagnostic("MOSTRA_TEAM_PRESENCE_RATE_LIMITED", { message: "This page sends presence faster than 20 updates a second." }), {
|
|
10836
|
+
status: 429,
|
|
10837
|
+
headers: { "retry-after": String(Math.max(1, Math.ceil(outcome.retryAfterMs / 1e3))) }
|
|
10838
|
+
});
|
|
10839
|
+
return jsonResponse(outcome.state);
|
|
10840
|
+
};
|
|
9862
10841
|
return {
|
|
9863
10842
|
fields,
|
|
9864
10843
|
submit,
|
|
@@ -9866,6 +10845,8 @@ function browserRoutes(options) {
|
|
|
9866
10845
|
stream,
|
|
9867
10846
|
poll: pollFor(true),
|
|
9868
10847
|
shellPoll: pollFor(false),
|
|
10848
|
+
respondents,
|
|
10849
|
+
presence,
|
|
9869
10850
|
shellSubmit,
|
|
9870
10851
|
choose,
|
|
9871
10852
|
follow,
|
|
@@ -10005,6 +10986,7 @@ var Capabilities = class {
|
|
|
10005
10986
|
/** Failure times per artifact (`""` for tokens of no artifact in this home). */
|
|
10006
10987
|
#failures = /* @__PURE__ */ new Map();
|
|
10007
10988
|
#touched = /* @__PURE__ */ new Map();
|
|
10989
|
+
#touchIntervalMs;
|
|
10008
10990
|
constructor(options) {
|
|
10009
10991
|
this.#ledger = options.ledger;
|
|
10010
10992
|
this.#log = options.log;
|
|
@@ -10013,6 +10995,7 @@ var Capabilities = class {
|
|
|
10013
10995
|
this.#shellOrigin = options.shellOrigin;
|
|
10014
10996
|
this.#servesShell = options.servesShell ?? ((origin) => origin === this.#shellOrigin());
|
|
10015
10997
|
this.#onMinted = options.onMinted;
|
|
10998
|
+
this.#touchIntervalMs = options.touchIntervalMs ?? TOUCH_INTERVAL_MS;
|
|
10016
10999
|
}
|
|
10017
11000
|
/** Runs `fn` in the caller's transaction, or in a new one. */
|
|
10018
11001
|
#tx(db, fn) {
|
|
@@ -10288,7 +11271,7 @@ var Capabilities = class {
|
|
|
10288
11271
|
/** Writes `last_seen_at` at most hourly, so serving files doesn't write the ledger per request. */
|
|
10289
11272
|
#touch(sessionId) {
|
|
10290
11273
|
const now = this.#now();
|
|
10291
|
-
if (now - (this.#touched.get(sessionId) ?? 0) <
|
|
11274
|
+
if (now - (this.#touched.get(sessionId) ?? 0) < this.#touchIntervalMs) return;
|
|
10292
11275
|
this.#touched.set(sessionId, now);
|
|
10293
11276
|
this.#ledger.write((db) => db.run("UPDATE session SET last_seen_at = ? WHERE id = ?", this.#iso(now), sessionId));
|
|
10294
11277
|
}
|
|
@@ -11263,6 +12246,124 @@ function fileResponse(file, request, headers) {
|
|
|
11263
12246
|
});
|
|
11264
12247
|
}
|
|
11265
12248
|
//#endregion
|
|
12249
|
+
//#region src/gateway/team.ts
|
|
12250
|
+
/**
|
|
12251
|
+
* The roster's host methods (D121, D168; CO-01, CO-03, CO-07): `roster/add` names expected
|
|
12252
|
+
* respondents and gives each a personal link, `roster/remove` stops expecting them, `roster/get`
|
|
12253
|
+
* reads everyone's status. They live with the gateway because a personal link is a capability
|
|
12254
|
+
* link (D97): minted here, with the respondent's viewer (D104), in the same transaction as the
|
|
12255
|
+
* roster's change. The roster itself, its rounds and its completion are the interaction core's.
|
|
12256
|
+
*/
|
|
12257
|
+
/** Who changed the roster: the client that called. */
|
|
12258
|
+
function actorOf(session) {
|
|
12259
|
+
return {
|
|
12260
|
+
kind: "agent",
|
|
12261
|
+
...session.client ? { id: session.client.name } : {}
|
|
12262
|
+
};
|
|
12263
|
+
}
|
|
12264
|
+
/** The roster's host methods. */
|
|
12265
|
+
function rosterMethods(options) {
|
|
12266
|
+
const { ledger, interaction, capabilities } = options;
|
|
12267
|
+
const live = (tokenId) => capabilities.grant(tokenId)?.live === true;
|
|
12268
|
+
const roster = (artifactId) => interaction.roster(artifactId, live);
|
|
12269
|
+
return [
|
|
12270
|
+
handler(rosterAddMethod, async (params, session) => {
|
|
12271
|
+
const detail = options.artifacts.get(params.artifact);
|
|
12272
|
+
const version = options.versionOf(detail, params.version);
|
|
12273
|
+
if (!version) throw new RpcError(createDiagnostic("MOSTRA_ARTIFACT_VERSION_NOT_FOUND", { message: params.version === void 0 ? `The artifact ${detail.id} has no published version.` : `The artifact ${detail.id} has no version ${params.version}.` }));
|
|
12274
|
+
if (version.collected !== void 0) throw options.collected(version.number);
|
|
12275
|
+
const base = await options.linkBase(detail.id);
|
|
12276
|
+
const scopes = normalizeScopes(params.scopes ?? ALL_SCOPES).join(" ");
|
|
12277
|
+
const pinned = params.version === void 0 ? void 0 : version.number;
|
|
12278
|
+
/**
|
|
12279
|
+
* Whether a respondent's link is the one this request would mint: it works here (D97 items
|
|
12280
|
+
* 5, 10) with the same scopes, the same pinned version, and an expiry exactly when a `ttl` is
|
|
12281
|
+
* asked for (Opus review 6). Otherwise the respondent gets a new link; the old one isn't
|
|
12282
|
+
* revoked, since they may hold it already.
|
|
12283
|
+
*/
|
|
12284
|
+
const reusable = (tokenId) => {
|
|
12285
|
+
const grant = capabilities.grant(tokenId);
|
|
12286
|
+
return grant?.live === true && grant.shellOrigin === base && normalizeScopes(grant.scopes).join(" ") === scopes && grant.pinnedVersion === pinned && grant.expiresAt !== void 0 === (params.ttl !== void 0);
|
|
12287
|
+
};
|
|
12288
|
+
const key = requestKey("roster/add", params);
|
|
12289
|
+
if (options.linkLimit) {
|
|
12290
|
+
if (!(key !== void 0 && ledger.read((db) => recordedResult(db, key)) !== void 0)) {
|
|
12291
|
+
const current = new Map(interaction.roster(detail.id, live).respondents.map((one) => [one.ref, one.tokenId]));
|
|
12292
|
+
let fresh = 0;
|
|
12293
|
+
for (const ref of new Set(params.respondents.map((one) => one.ref))) {
|
|
12294
|
+
const tokenId = current.get(ref);
|
|
12295
|
+
if (tokenId === void 0 || !reusable(tokenId)) fresh += 1;
|
|
12296
|
+
}
|
|
12297
|
+
if (fresh > 0) await options.linkLimit(detail.id, fresh);
|
|
12298
|
+
}
|
|
12299
|
+
}
|
|
12300
|
+
const minted = /* @__PURE__ */ new Map();
|
|
12301
|
+
const links = ledger.write((db) => {
|
|
12302
|
+
if (key !== void 0) {
|
|
12303
|
+
const row = recordedResult(db, key);
|
|
12304
|
+
if (row) return row.tokens;
|
|
12305
|
+
}
|
|
12306
|
+
const recorded = interaction.addRespondents(db, {
|
|
12307
|
+
artifactId: detail.id,
|
|
12308
|
+
respondents: params.respondents,
|
|
12309
|
+
actor: actorOf(session),
|
|
12310
|
+
link: (viewerId, current) => {
|
|
12311
|
+
if (current !== void 0 && reusable(current)) return current;
|
|
12312
|
+
const token = capabilities.mint({
|
|
12313
|
+
artifactId: detail.id,
|
|
12314
|
+
scopes: params.scopes,
|
|
12315
|
+
ttlMs: params.ttl === void 0 ? void 0 : durationMs(params.ttl),
|
|
12316
|
+
pinnedVersion: pinned,
|
|
12317
|
+
viewerId,
|
|
12318
|
+
shellOrigin: base
|
|
12319
|
+
}, db);
|
|
12320
|
+
minted.set(token.tokenId, token);
|
|
12321
|
+
return token.tokenId;
|
|
12322
|
+
}
|
|
12323
|
+
}).tokens.map((token) => ({
|
|
12324
|
+
ref: token.ref,
|
|
12325
|
+
tokenId: token.tokenId
|
|
12326
|
+
}));
|
|
12327
|
+
if (key !== void 0) recordResult(db, key, { tokens: recorded });
|
|
12328
|
+
return recorded;
|
|
12329
|
+
}).map(({ ref, tokenId }) => {
|
|
12330
|
+
const token = minted.get(tokenId) ?? capabilities.reveal(tokenId);
|
|
12331
|
+
if (!token) throw new RpcError(createDiagnostic("MOSTRA_HYGIENE_TOKEN_REVOKED", { message: `The personal link of ${ref} can't be shown again: the home's capability key changed. Add them again to give them a new one.` }));
|
|
12332
|
+
return {
|
|
12333
|
+
ref,
|
|
12334
|
+
link: options.link(token)
|
|
12335
|
+
};
|
|
12336
|
+
});
|
|
12337
|
+
return {
|
|
12338
|
+
roster: roster(detail.id),
|
|
12339
|
+
links
|
|
12340
|
+
};
|
|
12341
|
+
}),
|
|
12342
|
+
handler(rosterRemoveMethod, (params, session) => {
|
|
12343
|
+
const detail = options.artifacts.get(params.artifact);
|
|
12344
|
+
const key = requestKey("roster/remove", params);
|
|
12345
|
+
const removed = ledger.write((db) => {
|
|
12346
|
+
if (key !== void 0) {
|
|
12347
|
+
const row = recordedResult(db, key);
|
|
12348
|
+
if (row) return row.removed;
|
|
12349
|
+
}
|
|
12350
|
+
const outcome = interaction.removeRespondents(db, {
|
|
12351
|
+
artifactId: detail.id,
|
|
12352
|
+
refs: params.refs,
|
|
12353
|
+
actor: actorOf(session)
|
|
12354
|
+
});
|
|
12355
|
+
if (key !== void 0) recordResult(db, key, { removed: outcome.removed });
|
|
12356
|
+
return [...outcome.removed];
|
|
12357
|
+
});
|
|
12358
|
+
return {
|
|
12359
|
+
roster: roster(detail.id),
|
|
12360
|
+
removed
|
|
12361
|
+
};
|
|
12362
|
+
}),
|
|
12363
|
+
handler(rosterGetMethod, (params) => roster(options.artifacts.get(params.artifact).id))
|
|
12364
|
+
];
|
|
12365
|
+
}
|
|
12366
|
+
//#endregion
|
|
11266
12367
|
//#region src/gateway/worker.ts
|
|
11267
12368
|
/**
|
|
11268
12369
|
* Worker-mode frame sessions (D70, D158 item 5): where the shell and the artifact are two sites,
|
|
@@ -11635,6 +12736,20 @@ function laterArtifactRoutes(served, acting, ticket) {
|
|
|
11635
12736
|
auth: "session",
|
|
11636
12737
|
...acting ? { handler: acting.live } : {}
|
|
11637
12738
|
},
|
|
12739
|
+
{
|
|
12740
|
+
method: "POST",
|
|
12741
|
+
path: "/_mostra/v/:rev/respondents",
|
|
12742
|
+
intent: "mutation",
|
|
12743
|
+
auth: "session",
|
|
12744
|
+
handler: served.respondents
|
|
12745
|
+
},
|
|
12746
|
+
{
|
|
12747
|
+
method: "POST",
|
|
12748
|
+
path: "/_mostra/v/:rev/presence",
|
|
12749
|
+
intent: "mutation",
|
|
12750
|
+
auth: "session",
|
|
12751
|
+
handler: served.presence
|
|
12752
|
+
},
|
|
11638
12753
|
{
|
|
11639
12754
|
method: "POST",
|
|
11640
12755
|
path: "/_mostra/v/:rev/ticket",
|
|
@@ -11662,7 +12777,13 @@ function laterArtifactRoutes(served, acting, ticket) {
|
|
|
11662
12777
|
/** Creates the gateway; nothing is bound until {@link Gateway.start}. */
|
|
11663
12778
|
function createGateway(options) {
|
|
11664
12779
|
const { addressing, capabilities, artifacts, log, interaction } = options;
|
|
12780
|
+
const team = options.bus ? createTeamTraffic({
|
|
12781
|
+
bus: options.bus,
|
|
12782
|
+
source: interaction,
|
|
12783
|
+
log
|
|
12784
|
+
}) : void 0;
|
|
11665
12785
|
const served = browserRoutes({
|
|
12786
|
+
...team ? { team } : {},
|
|
11666
12787
|
interaction,
|
|
11667
12788
|
capabilities,
|
|
11668
12789
|
log,
|
|
@@ -12254,6 +13375,7 @@ function createGateway(options) {
|
|
|
12254
13375
|
artifactId,
|
|
12255
13376
|
versionId: version.id,
|
|
12256
13377
|
tokenId: session.grant.tokenId,
|
|
13378
|
+
sessionId: session.id,
|
|
12257
13379
|
client: context.client
|
|
12258
13380
|
});
|
|
12259
13381
|
if (refused) return refuse(checks, refused, meta);
|
|
@@ -12902,6 +14024,17 @@ function createGateway(options) {
|
|
|
12902
14024
|
by: entry.spec.by
|
|
12903
14025
|
})),
|
|
12904
14026
|
methods: () => [
|
|
14027
|
+
...rosterMethods({
|
|
14028
|
+
ledger: options.ledger,
|
|
14029
|
+
interaction,
|
|
14030
|
+
capabilities,
|
|
14031
|
+
artifacts,
|
|
14032
|
+
versionOf,
|
|
14033
|
+
linkBase,
|
|
14034
|
+
link,
|
|
14035
|
+
collected: (number) => new RpcError(collectedDiagnostic(number)),
|
|
14036
|
+
...options.linkLimit ? { linkLimit: options.linkLimit } : {}
|
|
14037
|
+
}),
|
|
12905
14038
|
handler(viewUrlMethod, async (params) => {
|
|
12906
14039
|
const detail = artifacts.get(params.artifact);
|
|
12907
14040
|
const version = versionOf(detail, params.version);
|
|
@@ -12946,6 +14079,7 @@ function createGateway(options) {
|
|
|
12946
14079
|
],
|
|
12947
14080
|
artifactOrigins: () => new Map([...artifactListeners].map(([artifactId, entry]) => [artifactId, addressing.origin(entry.port)])),
|
|
12948
14081
|
async close() {
|
|
14082
|
+
team?.close();
|
|
12949
14083
|
await Promise.allSettled([...opening.values(), ...openingFaces.values()]);
|
|
12950
14084
|
await Promise.all([
|
|
12951
14085
|
shellListener?.close(),
|
|
@@ -14667,7 +15801,11 @@ function runnerEnvironment(env, browsers) {
|
|
|
14667
15801
|
if (browsers !== void 0) out["PLAYWRIGHT_BROWSERS_PATH"] = browsers;
|
|
14668
15802
|
const idle = env["MOSTRA_TEST_VERIFY_IDLE_MS"];
|
|
14669
15803
|
if (idle) out["MOSTRA_TEST_VERIFY_IDLE_MS"] = idle;
|
|
14670
|
-
for (const name of [
|
|
15804
|
+
for (const name of [
|
|
15805
|
+
"MOSTRA_TEST_VERIFY_LOSE_BROWSER",
|
|
15806
|
+
"MOSTRA_TEST_VERIFY_FAIL_ONCE",
|
|
15807
|
+
"MOSTRA_TEST_VERIFY_COLLIDE_ONCE"
|
|
15808
|
+
]) {
|
|
14671
15809
|
const value = env[name];
|
|
14672
15810
|
if (value) out[name] = value;
|
|
14673
15811
|
}
|
|
@@ -15070,6 +16208,10 @@ function createVerifier(options) {
|
|
|
15070
16208
|
if (error instanceof RpcError && error.diagnostic.code === "MOSTRA_VERIFY_TIMEOUT") return { timedOut: true };
|
|
15071
16209
|
throw error;
|
|
15072
16210
|
});
|
|
16211
|
+
if (result.renderedAgain !== void 0) options.log.info("verify.rendered_again", {
|
|
16212
|
+
name,
|
|
16213
|
+
why: options.redactor.redact(result.renderedAgain)
|
|
16214
|
+
});
|
|
15073
16215
|
if (result.aria) {
|
|
15074
16216
|
const text = options.redactor.redact(result.aria.text);
|
|
15075
16217
|
await writeFile(result.aria.path, text);
|
|
@@ -18611,7 +19753,10 @@ function ownerInitialize(input) {
|
|
|
18611
19753
|
const FORWARDED = /* @__PURE__ */ new Set([
|
|
18612
19754
|
stateGetMethod.method,
|
|
18613
19755
|
statePatchMethod.method,
|
|
18614
|
-
livePushMethod.method
|
|
19756
|
+
livePushMethod.method,
|
|
19757
|
+
rosterAddMethod.method,
|
|
19758
|
+
rosterRemoveMethod.method,
|
|
19759
|
+
rosterGetMethod.method
|
|
18615
19760
|
]);
|
|
18616
19761
|
/** Server code's `state` for an artifact hosted somewhere, else `undefined`. */
|
|
18617
19762
|
function hostedState(link, artifactId) {
|
|
@@ -18634,8 +19779,8 @@ function hostedState(link, artifactId) {
|
|
|
18634
19779
|
};
|
|
18635
19780
|
}
|
|
18636
19781
|
/**
|
|
18637
|
-
* Wraps the instance's `state/get`, `state/patch
|
|
18638
|
-
* they act on its hosted home: the same params, the artifact named by its ID there.
|
|
19782
|
+
* Wraps the instance's `state/get`, `state/patch`, `live/push` and `roster/*` so that, for a hosted
|
|
19783
|
+
* artifact, they act on its hosted home: the same params, the artifact named by its ID there.
|
|
18639
19784
|
*/
|
|
18640
19785
|
function forwardHosted(link, resolve, handlers) {
|
|
18641
19786
|
return handlers.map((entry) => {
|
|
@@ -19196,6 +20341,14 @@ function createLink(options) {
|
|
|
19196
20341
|
const secret = /#t=([^&]+)/.exec(url)?.[1];
|
|
19197
20342
|
if (secret !== void 0) options.protect(secret);
|
|
19198
20343
|
};
|
|
20344
|
+
/** Protects every capability link a value holds, at any depth. */
|
|
20345
|
+
const protectLinksIn = (value, depth = 0) => {
|
|
20346
|
+
if (depth > 16) return;
|
|
20347
|
+
if (typeof value === "string") {
|
|
20348
|
+
if (value.includes("#t=")) protectLink(value);
|
|
20349
|
+
} else if (Array.isArray(value)) for (const item of value) protectLinksIn(item, depth + 1);
|
|
20350
|
+
else if (value !== null && typeof value === "object") for (const item of Object.values(value)) protectLinksIn(item, depth + 1);
|
|
20351
|
+
};
|
|
19199
20352
|
const linkRow = (db, server) => db.get("SELECT * FROM remote_link WHERE server = ?", server);
|
|
19200
20353
|
const owned = (server) => (db, artifactId) => db.get("SELECT 1 FROM hosted_artifact WHERE artifact_id = ? AND server = ?", artifactId, server) !== void 0;
|
|
19201
20354
|
/** A fresh access token, refreshing (and rotating the refresh token) when it's due. */
|
|
@@ -19998,7 +21151,9 @@ function createLink(options) {
|
|
|
19998
21151
|
if (error instanceof RpcError) throw error;
|
|
19999
21152
|
throw new RpcError(createDiagnostic("MOSTRA_REMOTE_UNREACHABLE", { message: `${server} can't be reached now; the hosted artifact's state lives there, so nothing was written.` }));
|
|
20000
21153
|
}
|
|
20001
|
-
|
|
21154
|
+
const answer = await session.call(definition, params, { timeoutMs: 3e4 });
|
|
21155
|
+
protectLinksIn(answer);
|
|
21156
|
+
return answer;
|
|
20002
21157
|
},
|
|
20003
21158
|
shares: () => ({
|
|
20004
21159
|
mint: async (input) => {
|
|
@@ -20023,6 +21178,16 @@ function createLink(options) {
|
|
|
20023
21178
|
...minted.expiresAt !== void 0 ? { expiresAt: minted.expiresAt } : {}
|
|
20024
21179
|
};
|
|
20025
21180
|
},
|
|
21181
|
+
respondents: async (input) => {
|
|
21182
|
+
const added = await (await self.session(input.server)).call(rosterAddMethod, {
|
|
21183
|
+
artifact: { artifactId: input.artifactId },
|
|
21184
|
+
respondents: [...input.respondents],
|
|
21185
|
+
...input.scopes !== void 0 ? { scopes: input.scopes } : {},
|
|
21186
|
+
...input.ttl !== void 0 ? { ttl: input.ttl } : {}
|
|
21187
|
+
});
|
|
21188
|
+
for (const entry of added.links) protectLink(entry.link.url);
|
|
21189
|
+
return added.links;
|
|
21190
|
+
},
|
|
20026
21191
|
url: (server, tokenId) => readLinks(server)[tokenId],
|
|
20027
21192
|
revoke: async (server, tokenId) => {
|
|
20028
21193
|
await (await self.session(server)).call(viewRevokeMethod, { tokenId });
|
|
@@ -21447,13 +22612,33 @@ function createShares(options) {
|
|
|
21447
22612
|
const start = async (params) => {
|
|
21448
22613
|
const detail = options.artifacts.get(params.artifact);
|
|
21449
22614
|
if (!detail.latestVersion && detail.versions.length === 0) throw new RpcError(createDiagnostic("MOSTRA_ARTIFACT_VERSION_NOT_FOUND", { message: `The artifact ${detail.id} has no published version to share.` }));
|
|
22615
|
+
if (params.respondents !== void 0 && params.respondents.length > 0) {
|
|
22616
|
+
if (params.via !== "remote") throw new RpcError(createDiagnostic("MOSTRA_HOST_INVALID_PARAMS", { message: "Expected respondents are named on a share to a remote server (via remote); for local links use roster/add." }), -32602);
|
|
22617
|
+
if (params.viewer !== void 0) throw new RpcError(createDiagnostic("MOSTRA_HOST_INVALID_PARAMS", { message: "A share names either one viewer for its link or expected respondents, each with a link of their own: not both." }), -32602);
|
|
22618
|
+
}
|
|
22619
|
+
const withRespondents = async (share) => {
|
|
22620
|
+
const respondents = params.respondents;
|
|
22621
|
+
if (respondents === void 0 || respondents.length === 0 || !options.remote) return share;
|
|
22622
|
+
const plan = JSON.parse(row(share.shareId).plan_json);
|
|
22623
|
+
const links = await options.remote.respondents({
|
|
22624
|
+
server: plan.server,
|
|
22625
|
+
artifactId: detail.id,
|
|
22626
|
+
respondents,
|
|
22627
|
+
scopes: params.scopes,
|
|
22628
|
+
ttl: params.ttl
|
|
22629
|
+
});
|
|
22630
|
+
return {
|
|
22631
|
+
...share,
|
|
22632
|
+
respondents: [...links]
|
|
22633
|
+
};
|
|
22634
|
+
};
|
|
21450
22635
|
const key = requestKey("share/start", params);
|
|
21451
22636
|
if (key !== void 0) {
|
|
21452
22637
|
const replay = ledger.read((db) => recordedResult(db, key));
|
|
21453
22638
|
const found = replay ? row(replay.shareId) : void 0;
|
|
21454
|
-
if (found) return withUrl(toShare(found));
|
|
22639
|
+
if (found) return withRespondents(withUrl(toShare(found)));
|
|
21455
22640
|
}
|
|
21456
|
-
if (params.via === "remote") return startRemote(params, detail, key);
|
|
22641
|
+
if (params.via === "remote") return withRespondents(await startRemote(params, detail, key));
|
|
21457
22642
|
const ttlMs = lifetime(params.via, params.ttl);
|
|
21458
22643
|
const shareId = ShareId.create();
|
|
21459
22644
|
const { shell, artifact, plan, hostname } = await setUp(shareId, detail.id, params.via, void 0);
|
|
@@ -22289,7 +23474,7 @@ async function assemble(home, options) {
|
|
|
22289
23474
|
dependenciesAdded: (artifact) => dev.dependenciesChanged(artifact)
|
|
22290
23475
|
}),
|
|
22291
23476
|
...dev.methods(),
|
|
22292
|
-
...gateway.methods(),
|
|
23477
|
+
...forwardHosted(link, (ref) => registry.get(canonicalRef(ref)).id, gateway.methods()),
|
|
22293
23478
|
...shares.methods(),
|
|
22294
23479
|
...link.methods(),
|
|
22295
23480
|
...forwardHosted(link, (ref) => registry.get(canonicalRef(ref)).id, interaction.methods()),
|
|
@@ -22519,4 +23704,4 @@ function sourceDirectory(path) {
|
|
|
22519
23704
|
//#endregion
|
|
22520
23705
|
export { markRunning as A, handler as B, jsonResponse as C, createEphemeralBus as D, createInteraction as E, BINDING_SUBPROTOCOL as F, readFieldCoverage as G, openLedger as H, MAX_FRAME_BYTES as I, coverageMatcher as J, readServerFunctions as K, serveWebSocket as L, markWaiting as M, runState as N, appendRunOutput as O, appendEvent as P, attachInProcess as R, isRefusal as S, openRegistry as T, faultsFrom as U, holdLock as V, noFaults as W, openFileLog as Y, resetOnClose as _, uninstallService as a, BASE_HEADERS as b, resolveHomePath as c, versionIdFor as d, createLive as f, shellAssetResponse as g, locateShell as h, serviceStatus as i, markUnknown as j, finishRun as k, canonicalRef as l, createGateway as m, startInstance as n, checkPlatform as o, liveMethods as p, readProcess as q, installService as r, platformName as s, runtimeVersion as t, listingDigest as u, Capabilities as v, readJsonObject as w, documentHeaders as x, capabilityKey as y, ProtocolServer as z };
|
|
22521
23706
|
|
|
22522
|
-
//# sourceMappingURL=instance-
|
|
23707
|
+
//# sourceMappingURL=instance-D5gh-sMM.js.map
|