@mostra/runtime 0.11.0 → 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin.js +152 -32
- package/dist/bin.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/{instance-DCiUHvgZ.js → instance-CBUlOmzG.js} +1215 -43
- package/dist/instance-CBUlOmzG.js.map +1 -0
- package/dist/reference/cli.md +112 -2
- package/dist/reference/diagnostics.json +27 -0
- package/dist/reference/errors/MOSTRA_TEAM_PRESENCE_RATE_LIMITED.md +23 -0
- package/dist/reference/errors/MOSTRA_TEAM_ROSTER_POLICY.md +23 -0
- package/dist/reference/errors/MOSTRA_TEAM_ROSTER_TOO_LARGE.md +23 -0
- package/dist/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/gateway/browser.ts +84 -1
- package/src/gateway/index.ts +40 -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 +35 -0
- package/src/link/hosted.ts +14 -3
- package/src/link/manager.ts +31 -1
- package/src/server/directory.ts +22 -0
- package/src/server/feed.ts +89 -3
- package/src/server/hosted.ts +54 -22
- package/src/server/index.ts +10 -0
- package/src/server/operator.ts +87 -28
- 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
package/src/interaction/index.ts
CHANGED
|
@@ -32,11 +32,16 @@ import {
|
|
|
32
32
|
MutationId,
|
|
33
33
|
type MutationResult,
|
|
34
34
|
type PausedBy,
|
|
35
|
+
RESULTS_LIST_MAX,
|
|
36
|
+
type RespondentSpec,
|
|
35
37
|
type Results,
|
|
38
|
+
type Roster,
|
|
39
|
+
type RosterForPage,
|
|
36
40
|
RpcError,
|
|
37
41
|
type RunState,
|
|
38
42
|
refusal,
|
|
39
43
|
resultsGetMethod,
|
|
44
|
+
resultsListMethod,
|
|
40
45
|
type StreamSnapshot,
|
|
41
46
|
type SubmissionEnvelope,
|
|
42
47
|
type SubmissionSummary,
|
|
@@ -45,6 +50,7 @@ import {
|
|
|
45
50
|
scopeAllows,
|
|
46
51
|
stateGetMethod,
|
|
47
52
|
statePatchMethod,
|
|
53
|
+
type TeamVisibility,
|
|
48
54
|
type Viewer,
|
|
49
55
|
type ViewerSpec,
|
|
50
56
|
waitMethod,
|
|
@@ -65,6 +71,20 @@ import { type ImportSource, importSubmission } from "./imports.ts";
|
|
|
65
71
|
import { type HostConnections, Outbox } from "./outbox.ts";
|
|
66
72
|
import { type Pause, pauseOf, setPause } from "./pause.ts";
|
|
67
73
|
import { buildResults, CHOICE, resultsMarkdown, submissionFor } from "./results.ts";
|
|
74
|
+
import {
|
|
75
|
+
addRespondents,
|
|
76
|
+
peerKey,
|
|
77
|
+
ROSTER_EVENTS,
|
|
78
|
+
type RosterViewer,
|
|
79
|
+
readRoster,
|
|
80
|
+
removeRespondents,
|
|
81
|
+
rosterForPage,
|
|
82
|
+
rosterForPages,
|
|
83
|
+
type SubmissionStanding,
|
|
84
|
+
settleRoster,
|
|
85
|
+
submissionStanding,
|
|
86
|
+
teamVisibility,
|
|
87
|
+
} from "./roster.ts";
|
|
68
88
|
import {
|
|
69
89
|
appendRunOutput,
|
|
70
90
|
createOrJoinRun,
|
|
@@ -114,6 +134,7 @@ export { appendEvent, compactEvents, redactEvents } from "./events.ts";
|
|
|
114
134
|
export { followEvents, type ImportSource, importedDeliveryId } from "./imports.ts";
|
|
115
135
|
export type { HostConnections } from "./outbox.ts";
|
|
116
136
|
export { policyInForce } from "./policy.ts";
|
|
137
|
+
export { peerKey } from "./roster.ts";
|
|
117
138
|
export {
|
|
118
139
|
appendRunOutput,
|
|
119
140
|
finishRun,
|
|
@@ -128,6 +149,7 @@ export {
|
|
|
128
149
|
} from "./runs.ts";
|
|
129
150
|
export { SubmitConflict } from "./submissions.ts";
|
|
130
151
|
export { tallyField, tallyState } from "./tally.ts";
|
|
152
|
+
export { createTeamTraffic, type TeamTraffic } from "./team.ts";
|
|
131
153
|
|
|
132
154
|
/** How the interaction core finds an artifact a host names. */
|
|
133
155
|
export interface InteractionArtifacts {
|
|
@@ -170,6 +192,12 @@ export interface InteractionOptions {
|
|
|
170
192
|
* get no delivery events. The owner, its agent and hosts keep every delivery state.
|
|
171
193
|
*/
|
|
172
194
|
readonly sentOnly?: boolean;
|
|
195
|
+
/**
|
|
196
|
+
* Whether a viewer is the artifact's owner, who sees every respondent and every present viewer
|
|
197
|
+
* whatever the visibility policy (CO-07): on a local home the home's local user (the default),
|
|
198
|
+
* on a hosted home the account that owns it.
|
|
199
|
+
*/
|
|
200
|
+
readonly isOwner?: (viewer: { readonly kind: string; readonly ref: string }) => boolean;
|
|
173
201
|
}
|
|
174
202
|
|
|
175
203
|
/** The delivery events only the owner, its agent and hosts see on a hosted home (D165 item 1a). */
|
|
@@ -433,6 +461,43 @@ export interface Interaction {
|
|
|
433
461
|
onTallied(listener: (artifactId: string, fields: readonly string[]) => void): () => void;
|
|
434
462
|
/** How many host subscriptions are open. */
|
|
435
463
|
subscriptionCount(): number;
|
|
464
|
+
|
|
465
|
+
// ── Teams (WP-31, D168) ──────────────────────────────────────────────────────────────────────
|
|
466
|
+
/**
|
|
467
|
+
* Adds expected respondents inside the caller's transaction (CO-01); `link` gives each one's
|
|
468
|
+
* personal link's token in the same transaction. Settles the roster.
|
|
469
|
+
*/
|
|
470
|
+
addRespondents(
|
|
471
|
+
db: LedgerDb,
|
|
472
|
+
input: {
|
|
473
|
+
readonly artifactId: string;
|
|
474
|
+
readonly respondents: readonly RespondentSpec[];
|
|
475
|
+
readonly actor: Actor;
|
|
476
|
+
readonly link: (viewerId: string, current: string | undefined) => string;
|
|
477
|
+
},
|
|
478
|
+
): { readonly tokens: readonly { readonly ref: string; readonly tokenId: string }[] };
|
|
479
|
+
/** Removes expected respondents inside the caller's transaction; settles the roster. */
|
|
480
|
+
removeRespondents(
|
|
481
|
+
db: LedgerDb,
|
|
482
|
+
input: { readonly artifactId: string; readonly refs: readonly string[]; readonly actor: Actor },
|
|
483
|
+
): { readonly removed: readonly string[] };
|
|
484
|
+
/** The whole roster (CO-03); `live` says whether a personal link's token still works. */
|
|
485
|
+
roster(artifactId: string, live?: (tokenId: string) => boolean): Roster;
|
|
486
|
+
/** The roster as a page may see it (CO-07). */
|
|
487
|
+
rosterForPage(page: PageIdentity): RosterForPage;
|
|
488
|
+
/** The roster as each of an artifact's pages may see it, from one read (in their order). */
|
|
489
|
+
rostersForPages(artifactId: string, viewerIds: readonly string[]): RosterForPage[];
|
|
490
|
+
/** What viewers of an artifact see of each other (CO-07). */
|
|
491
|
+
visibility(artifactId: string): TeamVisibility;
|
|
492
|
+
/** Whether a page's viewer is the artifact's owner, who sees everyone (CO-07). */
|
|
493
|
+
isOwner(viewerId: string): boolean;
|
|
494
|
+
/** A viewer as a page sees them: their key on this artifact, name and kind (D168). */
|
|
495
|
+
peer(artifactId: string, viewerId: string): { readonly key: string } & RosterViewer;
|
|
496
|
+
/**
|
|
497
|
+
* Hears an artifact whose respondents' status may have changed (a view opened, a draft written,
|
|
498
|
+
* a submission, a roster change), after the commit; returns the stop.
|
|
499
|
+
*/
|
|
500
|
+
onTeam(listener: (artifactId: string) => void): () => void;
|
|
436
501
|
}
|
|
437
502
|
|
|
438
503
|
function runNotFound(runId: string): RpcError {
|
|
@@ -462,6 +527,9 @@ function visibleTo(
|
|
|
462
527
|
run: (runId: string) => RunRow | undefined,
|
|
463
528
|
): boolean {
|
|
464
529
|
const viewerId = page.viewerId;
|
|
530
|
+
// The roster's events name refs and emails: pages read the roster through its own route,
|
|
531
|
+
// under the visibility policy (CO-07, D168).
|
|
532
|
+
if (ROSTER_EVENTS.has(event.type)) return false;
|
|
465
533
|
if (event.type.startsWith("draft.")) return event.payload["viewerId"] === viewerId;
|
|
466
534
|
if (event.type.startsWith("host.")) return false;
|
|
467
535
|
if (event.type.startsWith("action.")) {
|
|
@@ -478,12 +546,38 @@ function visibleTo(
|
|
|
478
546
|
}
|
|
479
547
|
|
|
480
548
|
/**
|
|
481
|
-
* Another viewer as a page sees them: kind
|
|
482
|
-
* (D104; Claude review finding 12). The name stays, so a conflict can say
|
|
549
|
+
* Another viewer as a page sees them: kind, display name and their key on this artifact, never
|
|
550
|
+
* their viewer or view IDs (D104; Claude review finding 12). The name stays, so a conflict can say
|
|
551
|
+
* who changed a field, and the key lets a page tell two people of one name apart and match the
|
|
552
|
+
* writer of a shared field to a respondent or a present viewer (D168, CO-05).
|
|
553
|
+
*/
|
|
554
|
+
function actorForPage(actor: Actor, viewerId: string, artifactId: string): Actor {
|
|
555
|
+
if (actor.kind !== "viewer" || actor.id === undefined) return actor;
|
|
556
|
+
const key = peerKey(artifactId, actor.id);
|
|
557
|
+
if (actor.id === viewerId) return { ...actor, key };
|
|
558
|
+
return { kind: "viewer", ...(actor.name !== undefined ? { name: actor.name } : {}), key };
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* How a page sees an event of a submission (CO-07, D168): its own as it is; another viewer's
|
|
563
|
+
* under `once` for the whole artifact as it is, since it closes every draft; otherwise only its
|
|
564
|
+
* `submission.created`, and only as the visibility allows: none under `private`, without a name
|
|
565
|
+
* or key under `counts`, named under `names`. Another viewer's deliveries tell a page nothing it
|
|
566
|
+
* needs, so they never reach it there.
|
|
483
567
|
*/
|
|
484
|
-
function
|
|
485
|
-
|
|
486
|
-
|
|
568
|
+
function submissionShown(
|
|
569
|
+
event: EventRecord,
|
|
570
|
+
viewerId: string,
|
|
571
|
+
standing: SubmissionStanding,
|
|
572
|
+
submitterOf: (submissionId: string) => string | undefined,
|
|
573
|
+
): "as-is" | "hidden" | "anonymous" {
|
|
574
|
+
const submitter =
|
|
575
|
+
event.type === "submission.created"
|
|
576
|
+
? String(event.payload["viewerId"] ?? "")
|
|
577
|
+
: submitterOf(String(event.payload["submissionId"] ?? ""));
|
|
578
|
+
if (submitter === viewerId || standing.closesAll) return "as-is";
|
|
579
|
+
if (event.type !== "submission.created" || standing.visibility === "private") return "hidden";
|
|
580
|
+
return standing.visibility === "counts" ? "anonymous" : "as-is";
|
|
487
581
|
}
|
|
488
582
|
|
|
489
583
|
/** An event as a page sees it: other viewers' identities left out. */
|
|
@@ -500,14 +594,18 @@ function eventForPage(event: EventRecord, viewerId: string): EventRecord {
|
|
|
500
594
|
if (event.actor.kind !== "viewer") return { ...event, payload };
|
|
501
595
|
}
|
|
502
596
|
const own = event.actor.kind !== "viewer" || event.actor.id === viewerId;
|
|
503
|
-
if (own)
|
|
597
|
+
if (own) {
|
|
598
|
+
return event.actor.kind === "viewer"
|
|
599
|
+
? { ...event, actor: actorForPage(event.actor, viewerId, event.artifactId ?? "") }
|
|
600
|
+
: event;
|
|
601
|
+
}
|
|
504
602
|
const { viewerId: _viewer, viewId: _view, ...payload } = event.payload as Record<string, unknown>;
|
|
505
603
|
const causation = event.causation
|
|
506
604
|
? Object.fromEntries(Object.entries(event.causation).filter(([key]) => key !== "viewId"))
|
|
507
605
|
: undefined;
|
|
508
606
|
return {
|
|
509
607
|
...event,
|
|
510
|
-
actor: actorForPage(event.actor, viewerId),
|
|
608
|
+
actor: actorForPage(event.actor, viewerId, event.artifactId ?? ""),
|
|
511
609
|
...(causation ? { causation } : {}),
|
|
512
610
|
payload,
|
|
513
611
|
};
|
|
@@ -517,11 +615,14 @@ function eventForPage(event: EventRecord, viewerId: string): EventRecord {
|
|
|
517
615
|
function fieldsForPage(
|
|
518
616
|
fields: Record<string, FieldState>,
|
|
519
617
|
viewerId: string,
|
|
618
|
+
artifactId: string,
|
|
520
619
|
): Record<string, FieldState> {
|
|
521
620
|
return Object.fromEntries(
|
|
522
621
|
Object.entries(fields).map(([id, field]) => [
|
|
523
622
|
id,
|
|
524
|
-
field.updatedBy
|
|
623
|
+
field.updatedBy
|
|
624
|
+
? { ...field, updatedBy: actorForPage(field.updatedBy, viewerId, artifactId) }
|
|
625
|
+
: field,
|
|
525
626
|
]),
|
|
526
627
|
);
|
|
527
628
|
}
|
|
@@ -557,6 +658,17 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
557
658
|
}
|
|
558
659
|
};
|
|
559
660
|
const tallyListeners = new Set<(artifactId: string, fields: readonly string[]) => void>();
|
|
661
|
+
const teamListeners = new Set<(artifactId: string) => void>();
|
|
662
|
+
/** Tells the team routes an artifact's respondents' status may have changed (D168). */
|
|
663
|
+
const touched = (artifactId: string): void => {
|
|
664
|
+
for (const listener of teamListeners) {
|
|
665
|
+
try {
|
|
666
|
+
listener(artifactId);
|
|
667
|
+
} catch (error) {
|
|
668
|
+
log.error("interaction.team_listener_failed", { error });
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
};
|
|
560
672
|
const { ledger, log, hosts } = options;
|
|
561
673
|
const outbox = new Outbox({
|
|
562
674
|
ledger,
|
|
@@ -597,6 +709,18 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
597
709
|
...(session.client ? { id: session.client.name } : {}),
|
|
598
710
|
});
|
|
599
711
|
|
|
712
|
+
/** Whether a viewer is the artifact's owner (CO-07): the local user, or a hosted home's account. */
|
|
713
|
+
const ownerOf = (db: LedgerDb, viewerId: string): boolean => {
|
|
714
|
+
const row = db.get<{ kind: string; external_ref: string }>(
|
|
715
|
+
"SELECT kind, external_ref FROM viewer WHERE id = ?",
|
|
716
|
+
viewerId,
|
|
717
|
+
);
|
|
718
|
+
if (!row) return false;
|
|
719
|
+
return options.isOwner
|
|
720
|
+
? options.isOwner({ kind: row.kind, ref: row.external_ref })
|
|
721
|
+
: row.kind === "local";
|
|
722
|
+
};
|
|
723
|
+
|
|
600
724
|
return {
|
|
601
725
|
start() {
|
|
602
726
|
outbox.start();
|
|
@@ -628,7 +752,9 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
628
752
|
pause: (artifactId, change) => ledger.write((db) => setPause(db, artifactId, change)),
|
|
629
753
|
pauseOf: (artifactId) => ledger.read((db) => pauseOf(db, artifactId)),
|
|
630
754
|
openView(input) {
|
|
631
|
-
|
|
755
|
+
const viewId = ledger.write((db) => openView(db, input));
|
|
756
|
+
touched(input.artifactId);
|
|
757
|
+
return viewId;
|
|
632
758
|
},
|
|
633
759
|
viewControls(page, viewId) {
|
|
634
760
|
return ledger.read((db) =>
|
|
@@ -676,18 +802,25 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
676
802
|
...outcome.result,
|
|
677
803
|
conflicts: outcome.result.conflicts.map((conflict) =>
|
|
678
804
|
conflict.updatedBy
|
|
679
|
-
? {
|
|
805
|
+
? {
|
|
806
|
+
...conflict,
|
|
807
|
+
updatedBy: actorForPage(conflict.updatedBy, page.viewerId, page.artifactId),
|
|
808
|
+
}
|
|
680
809
|
: conflict,
|
|
681
810
|
),
|
|
682
811
|
};
|
|
683
|
-
if (outcome.changed && input.scope === "viewer")
|
|
812
|
+
if (outcome.changed && input.scope === "viewer") {
|
|
684
813
|
outbox.mirror(page.artifactId, page.viewerId);
|
|
814
|
+
touched(page.artifactId);
|
|
815
|
+
}
|
|
685
816
|
return result;
|
|
686
817
|
},
|
|
687
818
|
importSubmission(envelope, source) {
|
|
688
819
|
const owners = options.deliveryOwners?.(envelope.artifactId) ?? outbox.owners();
|
|
689
|
-
|
|
690
|
-
|
|
820
|
+
let created = false;
|
|
821
|
+
const answer = ledger.write((db) => {
|
|
822
|
+
const held = db.get("SELECT 1 FROM submission WHERE id = ?", envelope.submissionId);
|
|
823
|
+
const result = importSubmission(db, {
|
|
691
824
|
envelope,
|
|
692
825
|
source,
|
|
693
826
|
owners,
|
|
@@ -697,8 +830,16 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
697
830
|
artifactId,
|
|
698
831
|
source.server,
|
|
699
832
|
) !== undefined,
|
|
700
|
-
})
|
|
701
|
-
|
|
833
|
+
});
|
|
834
|
+
created =
|
|
835
|
+
held === undefined &&
|
|
836
|
+
db.get("SELECT 1 FROM submission WHERE id = ?", envelope.submissionId) !== undefined;
|
|
837
|
+
// An imported submission settles the roster like a local one, in its own transaction
|
|
838
|
+
// (D168 item 3, Opus review 5): whatever it completes is recorded with it.
|
|
839
|
+
if (created) settleRoster(db, envelope.artifactId, new Date().toISOString());
|
|
840
|
+
return result;
|
|
841
|
+
});
|
|
842
|
+
if (created) touched(envelope.artifactId);
|
|
702
843
|
log.info("interaction.imported", {
|
|
703
844
|
artifactId: envelope.artifactId,
|
|
704
845
|
submissionId: envelope.submissionId,
|
|
@@ -754,8 +895,8 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
754
895
|
submit(page, input) {
|
|
755
896
|
const owners = options.deliveryOwners?.(page.artifactId) ?? outbox.owners();
|
|
756
897
|
const outcome = asPage(() =>
|
|
757
|
-
ledger.write((db) =>
|
|
758
|
-
submit(db, {
|
|
898
|
+
ledger.write((db) => {
|
|
899
|
+
const made = submit(db, {
|
|
759
900
|
artifactId: page.artifactId,
|
|
760
901
|
viewerId: page.viewerId,
|
|
761
902
|
...(page.tokenId !== undefined ? { tokenId: page.tokenId } : {}),
|
|
@@ -764,9 +905,13 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
764
905
|
channel: input.channel,
|
|
765
906
|
owners,
|
|
766
907
|
covers: options.coverage,
|
|
767
|
-
})
|
|
768
|
-
|
|
908
|
+
});
|
|
909
|
+
// A roster completed by this submission says so in the same transaction (CO-02).
|
|
910
|
+
if (made.created) settleRoster(db, page.artifactId, new Date().toISOString());
|
|
911
|
+
return made;
|
|
912
|
+
}),
|
|
769
913
|
);
|
|
914
|
+
if (outcome.created) touched(page.artifactId);
|
|
770
915
|
if (outcome.tallied) {
|
|
771
916
|
for (const listener of tallyListeners) {
|
|
772
917
|
try {
|
|
@@ -901,7 +1046,10 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
901
1046
|
draft: documentSnapshot(db, page.artifactId, page.viewerId),
|
|
902
1047
|
state: (() => {
|
|
903
1048
|
const state = documentSnapshot(db, page.artifactId, null);
|
|
904
|
-
return {
|
|
1049
|
+
return {
|
|
1050
|
+
...state,
|
|
1051
|
+
fields: fieldsForPage(state.fields, page.viewerId, page.artifactId),
|
|
1052
|
+
};
|
|
905
1053
|
})(),
|
|
906
1054
|
...(latestOwn ? { submission: forPage(submissionSummary(db, latestOwn)) } : {}),
|
|
907
1055
|
...(() => {
|
|
@@ -936,6 +1084,20 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
936
1084
|
if (!runs.has(runId)) runs.set(runId, runById(db, page.artifactId, runId));
|
|
937
1085
|
return runs.get(runId);
|
|
938
1086
|
};
|
|
1087
|
+
const standing = submissionStanding(db, page.artifactId, ownerOf(db, page.viewerId));
|
|
1088
|
+
const submitters = new Map<string, string | undefined>();
|
|
1089
|
+
const submitterOf = (submissionId: string): string | undefined => {
|
|
1090
|
+
if (!submitters.has(submissionId)) {
|
|
1091
|
+
submitters.set(
|
|
1092
|
+
submissionId,
|
|
1093
|
+
db.get<{ viewer_id: string }>(
|
|
1094
|
+
"SELECT viewer_id FROM submission WHERE id = ?",
|
|
1095
|
+
submissionId,
|
|
1096
|
+
)?.viewer_id,
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
return submitters.get(submissionId);
|
|
1100
|
+
};
|
|
939
1101
|
for (;;) {
|
|
940
1102
|
const read = readEvents(db, {
|
|
941
1103
|
filter: { artifacts: [page.artifactId] },
|
|
@@ -946,6 +1108,15 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
946
1108
|
if (events.length === limit) return { events, cursor: String(cursor) };
|
|
947
1109
|
cursor = Number(event.cursor);
|
|
948
1110
|
if (options.sentOnly && DELIVERY_EVENTS.has(event.type)) continue;
|
|
1111
|
+
if (event.type.startsWith("submission.")) {
|
|
1112
|
+
const shown = submissionShown(event, page.viewerId, standing, submitterOf);
|
|
1113
|
+
if (shown === "hidden") continue;
|
|
1114
|
+
const seen = eventForPage(event, page.viewerId);
|
|
1115
|
+
events.push(
|
|
1116
|
+
shown === "anonymous" ? { ...seen, actor: { kind: seen.actor.kind } } : seen,
|
|
1117
|
+
);
|
|
1118
|
+
continue;
|
|
1119
|
+
}
|
|
949
1120
|
if (visibleTo(event, page, runOf)) events.push(eventForPage(event, page.viewerId));
|
|
950
1121
|
}
|
|
951
1122
|
cursor = Math.max(cursor, Number(read.cursor));
|
|
@@ -1002,6 +1173,33 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
1002
1173
|
};
|
|
1003
1174
|
});
|
|
1004
1175
|
}),
|
|
1176
|
+
handler(resultsListMethod, (params) => {
|
|
1177
|
+
const artifactId = options.artifacts.resolve(params.artifact);
|
|
1178
|
+
const after = params.after === undefined ? 0 : Number(params.after);
|
|
1179
|
+
const limit = params.limit ?? RESULTS_LIST_MAX;
|
|
1180
|
+
return ledger.read((db) => {
|
|
1181
|
+
const rows = db.all<SubmissionRow>(
|
|
1182
|
+
"SELECT * FROM submission WHERE artifact_id = ? AND position > ? ORDER BY position LIMIT ?",
|
|
1183
|
+
artifactId,
|
|
1184
|
+
after,
|
|
1185
|
+
limit + 1,
|
|
1186
|
+
);
|
|
1187
|
+
const page = rows.slice(0, limit);
|
|
1188
|
+
return {
|
|
1189
|
+
results: page.map((row) => {
|
|
1190
|
+
const results = buildResults(db, row);
|
|
1191
|
+
return params.format === "md"
|
|
1192
|
+
? {
|
|
1193
|
+
submissionId: row.id,
|
|
1194
|
+
markdown: resultsMarkdown(results, JSON.parse(row.snapshot_json) as Snapshot),
|
|
1195
|
+
}
|
|
1196
|
+
: results;
|
|
1197
|
+
}),
|
|
1198
|
+
cursor: String(page.at(-1)?.position ?? after),
|
|
1199
|
+
more: rows.length > limit,
|
|
1200
|
+
};
|
|
1201
|
+
});
|
|
1202
|
+
}),
|
|
1005
1203
|
handler(waitMethod, (params, session) =>
|
|
1006
1204
|
waitFor({
|
|
1007
1205
|
ledger,
|
|
@@ -1230,5 +1428,52 @@ export function createInteraction(options: InteractionOptions): Interaction {
|
|
|
1230
1428
|
return () => tallyListeners.delete(listener);
|
|
1231
1429
|
},
|
|
1232
1430
|
subscriptionCount: () => subscriptions.size,
|
|
1431
|
+
|
|
1432
|
+
addRespondents(db, input) {
|
|
1433
|
+
const added = addRespondents(db, { ...input, now: new Date().toISOString() });
|
|
1434
|
+
queueMicrotask(() => touched(input.artifactId));
|
|
1435
|
+
return added;
|
|
1436
|
+
},
|
|
1437
|
+
removeRespondents(db, input) {
|
|
1438
|
+
const removed = removeRespondents(db, { ...input, now: new Date().toISOString() });
|
|
1439
|
+
queueMicrotask(() => touched(input.artifactId));
|
|
1440
|
+
return removed;
|
|
1441
|
+
},
|
|
1442
|
+
roster: (artifactId, live) => ledger.read((db) => readRoster(db, artifactId, live)),
|
|
1443
|
+
rosterForPage(page) {
|
|
1444
|
+
return ledger.read((db) =>
|
|
1445
|
+
rosterForPage(db, {
|
|
1446
|
+
artifactId: page.artifactId,
|
|
1447
|
+
viewerId: page.viewerId,
|
|
1448
|
+
owner: ownerOf(db, page.viewerId),
|
|
1449
|
+
viewerOf: (viewerId) => viewer(db, viewerId),
|
|
1450
|
+
}),
|
|
1451
|
+
);
|
|
1452
|
+
},
|
|
1453
|
+
rostersForPages(artifactId, viewerIds) {
|
|
1454
|
+
return ledger.read((db) =>
|
|
1455
|
+
rosterForPages(db, {
|
|
1456
|
+
artifactId,
|
|
1457
|
+
pages: viewerIds.map((viewerId) => ({ viewerId, owner: ownerOf(db, viewerId) })),
|
|
1458
|
+
viewerOf: (viewerId) => viewer(db, viewerId),
|
|
1459
|
+
}),
|
|
1460
|
+
);
|
|
1461
|
+
},
|
|
1462
|
+
visibility: (artifactId) => ledger.read((db) => teamVisibility(db, artifactId)),
|
|
1463
|
+
isOwner: (viewerId) => ledger.read((db) => ownerOf(db, viewerId)),
|
|
1464
|
+
peer(artifactId, viewerId) {
|
|
1465
|
+
const record = ledger.read((db) => viewer(db, viewerId));
|
|
1466
|
+
return {
|
|
1467
|
+
key: peerKey(artifactId, viewerId),
|
|
1468
|
+
id: record.id,
|
|
1469
|
+
kind: record.kind,
|
|
1470
|
+
...(record.name !== undefined ? { name: record.name } : {}),
|
|
1471
|
+
...(record.verified !== undefined ? { verified: record.verified } : {}),
|
|
1472
|
+
};
|
|
1473
|
+
},
|
|
1474
|
+
onTeam(listener) {
|
|
1475
|
+
teamListeners.add(listener);
|
|
1476
|
+
return () => teamListeners.delete(listener);
|
|
1477
|
+
},
|
|
1233
1478
|
};
|
|
1234
1479
|
}
|