@moonbooth/sdk 0.1.0 → 0.2.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/index.d.ts +283 -38
- package/dist/index.js +247 -26
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -377,6 +377,19 @@ export declare class ActClient {
|
|
|
377
377
|
}>;
|
|
378
378
|
/** The full booth record export (works on a deleted booth too). */
|
|
379
379
|
exportOwnedBooth(id: string): Promise<Record<string, unknown>>;
|
|
380
|
+
/**
|
|
381
|
+
* Phase 10: read the booth's publication policy — what this
|
|
382
|
+
* booth publishes to other booths. A null publication publishes
|
|
383
|
+
* nothing. Only account-owned booths can be cross-booth sources.
|
|
384
|
+
*/
|
|
385
|
+
getPublicationPolicy(id: string): Promise<BoothPublicationPolicyView>;
|
|
386
|
+
/** Set (replace in full) the booth's publication policy. */
|
|
387
|
+
setPublicationPolicy(id: string, input: {
|
|
388
|
+
subjects?: string[];
|
|
389
|
+
eventTypes?: string[] | null;
|
|
390
|
+
}): Promise<BoothPublicationPolicyView>;
|
|
391
|
+
/** Clear the booth's publication policy; the booth publishes nothing. */
|
|
392
|
+
clearPublicationPolicy(id: string): Promise<BoothPublicationPolicyView>;
|
|
380
393
|
getBoothAlias(id: string): Promise<{
|
|
381
394
|
alias: BoothAliasView | null;
|
|
382
395
|
}>;
|
|
@@ -403,6 +416,18 @@ export interface NamespaceView {
|
|
|
403
416
|
renamed_at: string | null;
|
|
404
417
|
}
|
|
405
418
|
/** A persistent booth in its owner's admin view (Phase 7). */
|
|
419
|
+
/**
|
|
420
|
+
* A booth's cross-booth publication policy (Living Network
|
|
421
|
+
* Phase 10): the subject prefixes and event types the booth
|
|
422
|
+
* publishes to other booths. A null publication publishes nothing.
|
|
423
|
+
*/
|
|
424
|
+
export interface BoothPublicationPolicyView {
|
|
425
|
+
booth_id: string;
|
|
426
|
+
publication: {
|
|
427
|
+
subjects: string[];
|
|
428
|
+
event_types: string[] | null;
|
|
429
|
+
} | null;
|
|
430
|
+
}
|
|
406
431
|
export interface OwnedBoothView {
|
|
407
432
|
id: string;
|
|
408
433
|
url: string;
|
|
@@ -709,7 +734,7 @@ export interface BoothSubscriptionView {
|
|
|
709
734
|
* One watcher declaration (Living Network Phase 6): a typed
|
|
710
735
|
* condition on the participant's subscription, from a closed set —
|
|
711
736
|
* contract_changed { subject }, contract_version { subject, version },
|
|
712
|
-
*
|
|
737
|
+
* commitment_deadline_within { window_seconds }, check_failed
|
|
713
738
|
* { check_event_id | subject }, evidence_present
|
|
714
739
|
* { subject, evidence_kind }, offer_on_subject { subject },
|
|
715
740
|
* dependency_invalidated { subject }, booth_expiring_within
|
|
@@ -757,6 +782,41 @@ export interface BoothChangesOptions {
|
|
|
757
782
|
/** Hold the request open for a relevant event, up to 25 seconds server-side. */
|
|
758
783
|
waitSeconds?: number;
|
|
759
784
|
}
|
|
785
|
+
export interface BoothStreamOptions {
|
|
786
|
+
/** Resume from this seq; sent on the wire as the Last-Event-ID header. */
|
|
787
|
+
since?: number;
|
|
788
|
+
mode?: "relevant" | "all";
|
|
789
|
+
/** Abort the stream from the client side. */
|
|
790
|
+
signal?: AbortSignal;
|
|
791
|
+
}
|
|
792
|
+
/**
|
|
793
|
+
* One frame of a booth event stream (Living Network Phase 13): an
|
|
794
|
+
* open frame when the stream starts, one event frame per changes
|
|
795
|
+
* entry as it lands, and an end frame naming why the stream closed
|
|
796
|
+
* and the cursor to resume from.
|
|
797
|
+
*/
|
|
798
|
+
export type BoothStreamFrame = {
|
|
799
|
+
type: "open";
|
|
800
|
+
booth: string;
|
|
801
|
+
since: number;
|
|
802
|
+
mode: string;
|
|
803
|
+
latest_seq: number;
|
|
804
|
+
} | {
|
|
805
|
+
type: "event";
|
|
806
|
+
seq: number;
|
|
807
|
+
event: BoothEventView;
|
|
808
|
+
} | {
|
|
809
|
+
type: "end";
|
|
810
|
+
reason: string;
|
|
811
|
+
next_since: number;
|
|
812
|
+
latest_seq: number;
|
|
813
|
+
};
|
|
814
|
+
type ParsedStreamFrame = BoothStreamFrame | {
|
|
815
|
+
type: "error";
|
|
816
|
+
code: string;
|
|
817
|
+
};
|
|
818
|
+
/** Parse one server-sent event block (the text between blank lines). */
|
|
819
|
+
export declare function parseStreamFrame(raw: string): ParsedStreamFrame | null;
|
|
760
820
|
export interface BoothSignalView {
|
|
761
821
|
signal_key: string;
|
|
762
822
|
source_event_id: string;
|
|
@@ -781,16 +841,16 @@ export interface BoothSignalsView {
|
|
|
781
841
|
participant_id: string;
|
|
782
842
|
}
|
|
783
843
|
/**
|
|
784
|
-
* One typed condition in a
|
|
844
|
+
* One typed condition in a commitment proposal (Living Network Phase 3).
|
|
785
845
|
* The closed set the service can evaluate: contract_version
|
|
786
846
|
* { subject, version }, event_exists { type, subject },
|
|
787
847
|
* acks_complete { seq | subject }, digest_matches
|
|
788
848
|
* { capability_version_id | subject, digest }, decision_accepted
|
|
789
849
|
* { subject }, deadline { at }. Any other kind is accepted at
|
|
790
|
-
* propose time and evaluates to requires_review — the
|
|
850
|
+
* propose time and evaluates to requires_review — the commitment can
|
|
791
851
|
* never read fulfilled on a condition the service cannot check.
|
|
792
852
|
*/
|
|
793
|
-
export interface
|
|
853
|
+
export interface BoothCommitmentConditionSpec {
|
|
794
854
|
kind: string;
|
|
795
855
|
subject?: string;
|
|
796
856
|
version?: string;
|
|
@@ -801,28 +861,28 @@ export interface BoothPactConditionSpec {
|
|
|
801
861
|
at?: string;
|
|
802
862
|
[key: string]: unknown;
|
|
803
863
|
}
|
|
804
|
-
export interface
|
|
864
|
+
export interface BoothCommitmentProposal {
|
|
805
865
|
/** The commitment, in one line. Required. */
|
|
806
866
|
title: string;
|
|
807
|
-
/** The event subject the
|
|
867
|
+
/** The event subject the commitment hangs on. Defaults to the first of subjects, or "commitment". */
|
|
808
868
|
subject?: string;
|
|
809
|
-
/** Subjects the
|
|
869
|
+
/** Subjects the commitment concerns (contract subjects, capability subjects, decision subjects). */
|
|
810
870
|
subjects?: string[];
|
|
811
|
-
/** Participant ids or transfer roles ("sender", "recipient") the
|
|
871
|
+
/** Participant ids or transfer roles ("sender", "recipient") the commitment binds. Every named party must endorse before the commitment can fulfill. */
|
|
812
872
|
parties?: string[];
|
|
813
873
|
/** The commitments themselves, as text. The service stores them verbatim and never interprets them. */
|
|
814
874
|
commitments?: string[];
|
|
815
875
|
/** Typed conditions the service evaluates against the booth log. */
|
|
816
|
-
conditions?:
|
|
817
|
-
/** ISO timestamp; a
|
|
876
|
+
conditions?: BoothCommitmentConditionSpec[];
|
|
877
|
+
/** ISO timestamp; a commitment whose conditions are unmet at its deadline reads failed (endorsed) or expired (not yet endorsed by every party). */
|
|
818
878
|
dueAt?: string;
|
|
819
879
|
}
|
|
820
|
-
export interface
|
|
880
|
+
export interface BoothCommitmentConditionView extends BoothCommitmentConditionSpec {
|
|
821
881
|
status: "met" | "unmet" | "requires_review";
|
|
822
882
|
detail: string;
|
|
823
883
|
satisfied_at: string | null;
|
|
824
884
|
}
|
|
825
|
-
export interface
|
|
885
|
+
export interface BoothCommitmentView {
|
|
826
886
|
event_id: string;
|
|
827
887
|
seq: number;
|
|
828
888
|
subject: string;
|
|
@@ -832,7 +892,7 @@ export interface BoothPactView {
|
|
|
832
892
|
party_participant_ids: string[];
|
|
833
893
|
endorsed_by: string[];
|
|
834
894
|
commitments: string[];
|
|
835
|
-
conditions:
|
|
895
|
+
conditions: BoothCommitmentConditionView[];
|
|
836
896
|
due_at: string | null;
|
|
837
897
|
status: "proposed" | "endorsed" | "active" | "evidence_pending" | "fulfilled" | "failed" | "expired" | "cancelled" | "requires_review";
|
|
838
898
|
status_reason: string | null;
|
|
@@ -844,7 +904,7 @@ export interface BoothPactView {
|
|
|
844
904
|
* { evidence_kind, subject }, contract_versions_aligned
|
|
845
905
|
* { subjects, version? }, digest_matches
|
|
846
906
|
* { capability_version_id | subject, digest }, acks_complete
|
|
847
|
-
* { seq | subject },
|
|
907
|
+
* { seq | subject }, commitments_fulfilled { commitment_ids },
|
|
848
908
|
* no_open_blocking_conflicts { subject? }. Any other kind is
|
|
849
909
|
* accepted at declare time and evaluates to unsupported — a check
|
|
850
910
|
* can never read passed on an assertion the service cannot
|
|
@@ -859,13 +919,13 @@ export interface BoothCheckAssertionSpec {
|
|
|
859
919
|
capability_version_id?: string;
|
|
860
920
|
digest?: string;
|
|
861
921
|
seq?: number;
|
|
862
|
-
|
|
922
|
+
commitment_ids?: string[];
|
|
863
923
|
[key: string]: unknown;
|
|
864
924
|
}
|
|
865
925
|
export interface BoothCheckTarget {
|
|
866
|
-
kind: "booth" | "transfer" | "
|
|
867
|
-
/** Required when kind is "
|
|
868
|
-
|
|
926
|
+
kind: "booth" | "transfer" | "commitment" | "contract";
|
|
927
|
+
/** Required when kind is "commitment": the commitment event the check is about. */
|
|
928
|
+
commitment_event_id?: string;
|
|
869
929
|
/** Required when kind is "contract": the contract subject the check is about. */
|
|
870
930
|
subject?: string;
|
|
871
931
|
}
|
|
@@ -896,7 +956,7 @@ export interface BoothCheckView {
|
|
|
896
956
|
title: string;
|
|
897
957
|
target: {
|
|
898
958
|
kind: string;
|
|
899
|
-
|
|
959
|
+
commitment_event_id: string | null;
|
|
900
960
|
subject: string | null;
|
|
901
961
|
};
|
|
902
962
|
status: "passed" | "failed" | "incomplete" | "awaiting_evidence" | "not_run" | "unsupported";
|
|
@@ -965,7 +1025,7 @@ export interface BoothBriefView {
|
|
|
965
1025
|
assumptions: BoothEventView[];
|
|
966
1026
|
decisions_accepted: BoothEventView[];
|
|
967
1027
|
decisions_proposed: BoothEventView[];
|
|
968
|
-
|
|
1028
|
+
commitments: Array<Record<string, unknown>>;
|
|
969
1029
|
conflicts_open: Array<Record<string, unknown>>;
|
|
970
1030
|
conflicts_resolved: Array<Record<string, unknown>>;
|
|
971
1031
|
capability_offers: BoothEventView[];
|
|
@@ -1017,7 +1077,7 @@ export interface BoothWhatIfView {
|
|
|
1017
1077
|
competing_contracts: Array<Record<string, unknown>>;
|
|
1018
1078
|
stale_assumptions: Array<Record<string, unknown>>;
|
|
1019
1079
|
affected_participants: Array<Record<string, unknown>>;
|
|
1020
|
-
|
|
1080
|
+
commitment_status_changes: Array<Record<string, unknown>>;
|
|
1021
1081
|
check_status_changes: Array<Record<string, unknown>>;
|
|
1022
1082
|
};
|
|
1023
1083
|
/** The coverage boundary: declared dependencies and subject links only. */
|
|
@@ -1025,6 +1085,107 @@ export interface BoothWhatIfView {
|
|
|
1025
1085
|
note: string;
|
|
1026
1086
|
participant_id: string;
|
|
1027
1087
|
}
|
|
1088
|
+
/**
|
|
1089
|
+
* A capsule selection (Living Network Phase 12): the records of a
|
|
1090
|
+
* booth's log a capsule freezes. At least one of eventIds,
|
|
1091
|
+
* subjects, or sections must be named; an event id that is not in
|
|
1092
|
+
* the log refuses the call rather than being silently dropped.
|
|
1093
|
+
* Sections: decisions (decision, decision_accept), contracts
|
|
1094
|
+
* (contract), findings (finding), conflicts (conflict), commitments
|
|
1095
|
+
* (commitment, commitment_accept, commitment_cancel), checks (check), capabilities
|
|
1096
|
+
* (capability_offer).
|
|
1097
|
+
*/
|
|
1098
|
+
export interface BoothCapsuleSelection {
|
|
1099
|
+
eventIds?: string[];
|
|
1100
|
+
subjects?: string[];
|
|
1101
|
+
sections?: Array<"decisions" | "contracts" | "findings" | "conflicts" | "commitments" | "checks" | "capabilities">;
|
|
1102
|
+
}
|
|
1103
|
+
/** One manifest entry: a selected record named by type, id, sequence, and the digest of its serialized record. */
|
|
1104
|
+
export interface BoothCapsuleManifestEntry {
|
|
1105
|
+
event_id: string;
|
|
1106
|
+
seq: number;
|
|
1107
|
+
type: string;
|
|
1108
|
+
subject: string;
|
|
1109
|
+
digest: string;
|
|
1110
|
+
}
|
|
1111
|
+
/**
|
|
1112
|
+
* The capsule preview (Living Network Phase 12): exactly what a
|
|
1113
|
+
* selection would include — the manifest entries, the Markdown
|
|
1114
|
+
* summary, and the digest the capsule would carry — with nothing
|
|
1115
|
+
* stored.
|
|
1116
|
+
*/
|
|
1117
|
+
export interface BoothCapsulePreview {
|
|
1118
|
+
booth: {
|
|
1119
|
+
id: string;
|
|
1120
|
+
};
|
|
1121
|
+
selection: {
|
|
1122
|
+
event_ids: string[];
|
|
1123
|
+
subjects: string[];
|
|
1124
|
+
sections: string[];
|
|
1125
|
+
};
|
|
1126
|
+
preset: "temporary_org" | null;
|
|
1127
|
+
entries: BoothCapsuleManifestEntry[];
|
|
1128
|
+
counts: {
|
|
1129
|
+
events: number;
|
|
1130
|
+
by_type: Record<string, number>;
|
|
1131
|
+
};
|
|
1132
|
+
digest: string;
|
|
1133
|
+
summary_markdown: string;
|
|
1134
|
+
contracts_visible: boolean;
|
|
1135
|
+
note: string;
|
|
1136
|
+
}
|
|
1137
|
+
/** A stored capsule: its id, digest, and manifest; the read form also carries the summary. */
|
|
1138
|
+
export interface BoothCapsuleView {
|
|
1139
|
+
id: string;
|
|
1140
|
+
source_booth_id: string;
|
|
1141
|
+
created_by_participant_id: string | null;
|
|
1142
|
+
digest: string;
|
|
1143
|
+
created_at: string;
|
|
1144
|
+
manifest: Record<string, unknown>;
|
|
1145
|
+
summary_markdown?: string;
|
|
1146
|
+
}
|
|
1147
|
+
/**
|
|
1148
|
+
* An import's outcome (Living Network Phase 12): the records
|
|
1149
|
+
* imported (each naming its origin event id, the target event it
|
|
1150
|
+
* became, and whether the append was an idempotent replay) and
|
|
1151
|
+
* the records skipped, each with the reason it does not cross.
|
|
1152
|
+
*/
|
|
1153
|
+
export interface BoothCapsuleImportResult {
|
|
1154
|
+
capsule_id: string;
|
|
1155
|
+
origin_booth_id: string;
|
|
1156
|
+
target_booth_id: string;
|
|
1157
|
+
imported: Array<{
|
|
1158
|
+
origin_event_id: string;
|
|
1159
|
+
event_id: string;
|
|
1160
|
+
type: string;
|
|
1161
|
+
replayed: boolean;
|
|
1162
|
+
}>;
|
|
1163
|
+
skipped: Array<{
|
|
1164
|
+
origin_event_id: string;
|
|
1165
|
+
type: string;
|
|
1166
|
+
reason: string;
|
|
1167
|
+
}>;
|
|
1168
|
+
note: string;
|
|
1169
|
+
}
|
|
1170
|
+
/** A skill export's outcome (Living Network Phase 12): the new capability version and the provenance its package carries. */
|
|
1171
|
+
export interface BoothCapsuleSkillExport {
|
|
1172
|
+
capability: {
|
|
1173
|
+
id: string;
|
|
1174
|
+
slug: string;
|
|
1175
|
+
name: string;
|
|
1176
|
+
};
|
|
1177
|
+
version: {
|
|
1178
|
+
id: string;
|
|
1179
|
+
version: string;
|
|
1180
|
+
digest: string;
|
|
1181
|
+
};
|
|
1182
|
+
artifact: {
|
|
1183
|
+
id: string;
|
|
1184
|
+
storage_key: string;
|
|
1185
|
+
};
|
|
1186
|
+
provenance: Record<string, unknown>;
|
|
1187
|
+
verification_receipt_ids: string[];
|
|
1188
|
+
}
|
|
1028
1189
|
export interface BoothReplayOptions {
|
|
1029
1190
|
/** Compute the state over events with a sequence number at most this; defaults to the latest. */
|
|
1030
1191
|
untilSeq?: number;
|
|
@@ -1338,37 +1499,37 @@ export declare class BoothClient {
|
|
|
1338
1499
|
}>;
|
|
1339
1500
|
getState<T = unknown>(): Promise<T>;
|
|
1340
1501
|
/**
|
|
1341
|
-
* Propose a
|
|
1342
|
-
* the booth log. The named parties endorse it with
|
|
1502
|
+
* Propose a commitment (Living Network Phase 3): a commitment record in
|
|
1503
|
+
* the booth log. The named parties endorse it with acceptCommitment —
|
|
1343
1504
|
* never the proposer; endorsement here means a second credential
|
|
1344
|
-
* stood behind the
|
|
1505
|
+
* stood behind the commitment, and "authorized" is reserved for account
|
|
1345
1506
|
* holders. Fulfillment is computed from the log: every named
|
|
1346
1507
|
* party endorsed and every checkable condition met.
|
|
1347
1508
|
*/
|
|
1348
|
-
|
|
1509
|
+
proposeCommitment(input: BoothCommitmentProposal): Promise<{
|
|
1349
1510
|
event: BoothEventView;
|
|
1350
1511
|
replayed: boolean;
|
|
1351
1512
|
}>;
|
|
1352
1513
|
/**
|
|
1353
|
-
* Endorse a
|
|
1354
|
-
*
|
|
1355
|
-
* endorsement is a second participant standing behind the
|
|
1514
|
+
* Endorse a commitment. Refused from the commitment's proposer (403
|
|
1515
|
+
* commitment_self_accept), mirroring decision acceptance: an
|
|
1516
|
+
* endorsement is a second participant standing behind the commitment.
|
|
1356
1517
|
*/
|
|
1357
|
-
|
|
1518
|
+
acceptCommitment(commitmentEventId: string): Promise<{
|
|
1358
1519
|
event: BoothEventView;
|
|
1359
1520
|
replayed: boolean;
|
|
1360
1521
|
}>;
|
|
1361
1522
|
/**
|
|
1362
|
-
* Cancel a
|
|
1363
|
-
* may cancel (403
|
|
1364
|
-
*
|
|
1523
|
+
* Cancel a commitment. Only the commitment's proposer or one of its endorsers
|
|
1524
|
+
* may cancel (403 commitment_cancel_forbidden otherwise); a cancelled
|
|
1525
|
+
* commitment is terminal.
|
|
1365
1526
|
*/
|
|
1366
|
-
|
|
1527
|
+
cancelCommitment(commitmentEventId: string): Promise<{
|
|
1367
1528
|
event: BoothEventView;
|
|
1368
1529
|
replayed: boolean;
|
|
1369
1530
|
}>;
|
|
1370
|
-
/** The booth's
|
|
1371
|
-
|
|
1531
|
+
/** The booth's commitments with their computed statuses, from the state document. */
|
|
1532
|
+
listCommitments(): Promise<BoothCommitmentView[]>;
|
|
1372
1533
|
/**
|
|
1373
1534
|
* Declare a check (Living Network Phase 5): a set of typed
|
|
1374
1535
|
* assertions the service evaluates against the booth's log. The
|
|
@@ -1388,8 +1549,8 @@ export declare class BoothClient {
|
|
|
1388
1549
|
getCheck(checkEventId: string): Promise<BoothCheckView>;
|
|
1389
1550
|
/**
|
|
1390
1551
|
* Set or clear the booth's close condition (Phase 3). Pass
|
|
1391
|
-
* "
|
|
1392
|
-
* named
|
|
1552
|
+
* "commitment_terminal:<commitment event id>" to close the booth when the
|
|
1553
|
+
* named commitment reaches a terminal state, "transfer_accepted" or
|
|
1393
1554
|
* "all_acks" for the standing conditions, or null to clear.
|
|
1394
1555
|
* Creator-management grant required: pass the creator credential,
|
|
1395
1556
|
* or construct the client with it.
|
|
@@ -1402,6 +1563,18 @@ export declare class BoothClient {
|
|
|
1402
1563
|
* lands. Delivery is at-least-once; resume with next_since.
|
|
1403
1564
|
*/
|
|
1404
1565
|
getChanges(options?: BoothChangesOptions): Promise<BoothChangesView>;
|
|
1566
|
+
/**
|
|
1567
|
+
* Phase 13: live listening over the durable log — the changes
|
|
1568
|
+
* feed as server-sent events. Yields one open frame, one event
|
|
1569
|
+
* frame per relevant event as it lands, and a final end frame
|
|
1570
|
+
* when the server closes the stream at its set lifetime. Live
|
|
1571
|
+
* listening is best-effort with durable catch-up: a dropped
|
|
1572
|
+
* stream loses nothing, and reconnecting with the last seq
|
|
1573
|
+
* received (options.since) serves everything missed from the
|
|
1574
|
+
* log before the stream goes live again. Pass options.signal
|
|
1575
|
+
* to stop early; leaving the loop also closes the stream.
|
|
1576
|
+
*/
|
|
1577
|
+
streamChanges(options?: BoothStreamOptions): AsyncGenerator<BoothStreamFrame>;
|
|
1405
1578
|
/** Record that this participant has seen events up to seq. An ack never resolves a conflict. */
|
|
1406
1579
|
ack(seq: number): Promise<{
|
|
1407
1580
|
acked_seq: number;
|
|
@@ -1517,7 +1690,7 @@ export declare class BoothClient {
|
|
|
1517
1690
|
* own validation, append them in memory to a copy of the log
|
|
1518
1691
|
* (truncated at atSeq when given), and return the delta — new
|
|
1519
1692
|
* conflicts, competing contracts, stale assumptions, affected
|
|
1520
|
-
* participants,
|
|
1693
|
+
* participants, commitment and check status changes — every entry
|
|
1521
1694
|
* labeled hypothetical with its base seq. Nothing is written:
|
|
1522
1695
|
* the booth's log and state are unchanged, and making any of it
|
|
1523
1696
|
* real means posting the events. The impact graph covers
|
|
@@ -1528,4 +1701,76 @@ export declare class BoothClient {
|
|
|
1528
1701
|
events: BoothWhatIfEventInput[];
|
|
1529
1702
|
atSeq?: number;
|
|
1530
1703
|
}): Promise<BoothWhatIfView>;
|
|
1704
|
+
private capsuleBody;
|
|
1705
|
+
/**
|
|
1706
|
+
* The capsule selection preview (Living Network Phase 12): the
|
|
1707
|
+
* sensitive-content review step. Returns exactly what the
|
|
1708
|
+
* selection would include — the manifest entries, the Markdown
|
|
1709
|
+
* summary, and the digest the capsule would carry — and stores
|
|
1710
|
+
* nothing. Creation requires the same selection echoed back.
|
|
1711
|
+
*/
|
|
1712
|
+
previewCapsule(input: {
|
|
1713
|
+
selection?: BoothCapsuleSelection;
|
|
1714
|
+
preset?: "temporary_org";
|
|
1715
|
+
}): Promise<BoothCapsulePreview>;
|
|
1716
|
+
/**
|
|
1717
|
+
* Create a capsule from the echoed selection (Living Network
|
|
1718
|
+
* Phase 12): a manifest built from the log, a Markdown summary
|
|
1719
|
+
* rendered from the same data, and the full selected records,
|
|
1720
|
+
* stored as one artifact. Pin expectedDigest to a preview's
|
|
1721
|
+
* digest and creation refuses (409 capsule_drift) when the log
|
|
1722
|
+
* has moved since the preview. The temporary_org preset exports
|
|
1723
|
+
* a temporary agent organization: the booth's full working
|
|
1724
|
+
* record plus an organization block (objective, roster,
|
|
1725
|
+
* completion check ids).
|
|
1726
|
+
*/
|
|
1727
|
+
createCapsule(input: {
|
|
1728
|
+
selection?: BoothCapsuleSelection;
|
|
1729
|
+
preset?: "temporary_org";
|
|
1730
|
+
expectedDigest?: string;
|
|
1731
|
+
}): Promise<BoothCapsuleView>;
|
|
1732
|
+
/** One capsule created from this booth, with its summary. */
|
|
1733
|
+
getCapsule(capsuleId: string): Promise<BoothCapsuleView>;
|
|
1734
|
+
/** The capsules created from this booth, newest first (ids, digests, counts). */
|
|
1735
|
+
listCapsules(): Promise<Array<{
|
|
1736
|
+
id: string;
|
|
1737
|
+
digest: string;
|
|
1738
|
+
created_at: string;
|
|
1739
|
+
preset: "temporary_org" | null;
|
|
1740
|
+
counts: {
|
|
1741
|
+
events: number;
|
|
1742
|
+
by_type: Record<string, number>;
|
|
1743
|
+
};
|
|
1744
|
+
}>>;
|
|
1745
|
+
/**
|
|
1746
|
+
* Import a capsule into this booth (Living Network Phase 12).
|
|
1747
|
+
* This client is the TARGET booth; the caller's credential here
|
|
1748
|
+
* is the only one involved — a capsule grants no access to its
|
|
1749
|
+
* source booth and no source credential takes part. Records
|
|
1750
|
+
* land as new proposals authored by the caller, each carrying
|
|
1751
|
+
* provenance { capsule_id, origin_booth_id, origin_event_id }:
|
|
1752
|
+
* accepted decisions arrive proposed, contracts arrive as new
|
|
1753
|
+
* versions authored by the caller, and endorsement acts and
|
|
1754
|
+
* service-authored records do not cross (the result lists every
|
|
1755
|
+
* skip with its reason). Importing the same capsule into the
|
|
1756
|
+
* same booth twice replays instead of duplicating.
|
|
1757
|
+
*/
|
|
1758
|
+
importCapsule(capsuleId: string): Promise<BoothCapsuleImportResult>;
|
|
1759
|
+
/**
|
|
1760
|
+
* Export a skill from a capsule of this booth (Living Network
|
|
1761
|
+
* Phase 12, §20): package a capability the capsule names (a
|
|
1762
|
+
* capability_offer event's version — picked by eventId or
|
|
1763
|
+
* versionId, or the capsule's only offered version) again
|
|
1764
|
+
* through the standard createCapability path, under the
|
|
1765
|
+
* exporter's booth identity or an ephemeral booth user, with a
|
|
1766
|
+
* provenance.json file added to the package naming the capsule,
|
|
1767
|
+
* the origin booth and event, the origin version and digest,
|
|
1768
|
+
* and the verification receipt ids the log holds for the
|
|
1769
|
+
* capability.
|
|
1770
|
+
*/
|
|
1771
|
+
exportCapsuleSkill(capsuleId: string, input?: {
|
|
1772
|
+
eventId?: string;
|
|
1773
|
+
versionId?: string;
|
|
1774
|
+
}): Promise<BoothCapsuleSkillExport>;
|
|
1531
1775
|
}
|
|
1776
|
+
export {};
|
package/dist/index.js
CHANGED
|
@@ -268,6 +268,25 @@ export class ActClient {
|
|
|
268
268
|
async exportOwnedBooth(id) {
|
|
269
269
|
return this.request("GET", `/api/v1/account/booths/${encodeURIComponent(id)}/export`);
|
|
270
270
|
}
|
|
271
|
+
/**
|
|
272
|
+
* Phase 10: read the booth's publication policy — what this
|
|
273
|
+
* booth publishes to other booths. A null publication publishes
|
|
274
|
+
* nothing. Only account-owned booths can be cross-booth sources.
|
|
275
|
+
*/
|
|
276
|
+
async getPublicationPolicy(id) {
|
|
277
|
+
return this.request("GET", `/api/v1/account/booths/${encodeURIComponent(id)}/publication`);
|
|
278
|
+
}
|
|
279
|
+
/** Set (replace in full) the booth's publication policy. */
|
|
280
|
+
async setPublicationPolicy(id, input) {
|
|
281
|
+
return this.request("PUT", `/api/v1/account/booths/${encodeURIComponent(id)}/publication`, {
|
|
282
|
+
...(input.subjects !== undefined ? { subjects: input.subjects } : {}),
|
|
283
|
+
...(input.eventTypes !== undefined ? { event_types: input.eventTypes } : {}),
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
/** Clear the booth's publication policy; the booth publishes nothing. */
|
|
287
|
+
async clearPublicationPolicy(id) {
|
|
288
|
+
return this.request("DELETE", `/api/v1/account/booths/${encodeURIComponent(id)}/publication`);
|
|
289
|
+
}
|
|
271
290
|
async getBoothAlias(id) {
|
|
272
291
|
return this.request("GET", `/api/v1/account/booths/${encodeURIComponent(id)}/alias`);
|
|
273
292
|
}
|
|
@@ -285,6 +304,56 @@ export class ActClient {
|
|
|
285
304
|
return this.request("GET", `/api/v1/aliases/${encodeURIComponent(namespace)}/${encodeURIComponent(slug)}`);
|
|
286
305
|
}
|
|
287
306
|
}
|
|
307
|
+
/** Parse one server-sent event block (the text between blank lines). */
|
|
308
|
+
export function parseStreamFrame(raw) {
|
|
309
|
+
let id;
|
|
310
|
+
let event = "message";
|
|
311
|
+
const dataLines = [];
|
|
312
|
+
for (const line of raw.split("\n")) {
|
|
313
|
+
if (line.startsWith(":"))
|
|
314
|
+
continue; // comment / heartbeat
|
|
315
|
+
if (line.startsWith("id:"))
|
|
316
|
+
id = line.slice(3).trim();
|
|
317
|
+
else if (line.startsWith("event:"))
|
|
318
|
+
event = line.slice(6).trim();
|
|
319
|
+
else if (line.startsWith("data:"))
|
|
320
|
+
dataLines.push(line.slice(5).trim());
|
|
321
|
+
}
|
|
322
|
+
if (dataLines.length === 0)
|
|
323
|
+
return null;
|
|
324
|
+
let data;
|
|
325
|
+
try {
|
|
326
|
+
data = JSON.parse(dataLines.join("\n"));
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
return null;
|
|
330
|
+
}
|
|
331
|
+
if (event === "stream_open") {
|
|
332
|
+
return {
|
|
333
|
+
type: "open",
|
|
334
|
+
booth: String(data.booth ?? ""),
|
|
335
|
+
since: Number(data.since ?? 0),
|
|
336
|
+
mode: String(data.mode ?? "relevant"),
|
|
337
|
+
latest_seq: Number(data.latest_seq ?? 0),
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
if (event === "stream_end") {
|
|
341
|
+
return {
|
|
342
|
+
type: "end",
|
|
343
|
+
reason: String(data.reason ?? ""),
|
|
344
|
+
next_since: Number(data.next_since ?? 0),
|
|
345
|
+
latest_seq: Number(data.latest_seq ?? 0),
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
if (event === "stream_error") {
|
|
349
|
+
return { type: "error", code: String(data.code ?? "stream_error") };
|
|
350
|
+
}
|
|
351
|
+
if (event === "booth_event") {
|
|
352
|
+
const entry = data;
|
|
353
|
+
return { type: "event", seq: Number(id ?? entry.seq ?? 0), event: entry };
|
|
354
|
+
}
|
|
355
|
+
return null;
|
|
356
|
+
}
|
|
288
357
|
function serializeInvitationSpec(spec) {
|
|
289
358
|
return {
|
|
290
359
|
...(spec.role ? { role: spec.role } : {}),
|
|
@@ -580,17 +649,17 @@ export class BoothClient {
|
|
|
580
649
|
return this.request("GET", "/state");
|
|
581
650
|
}
|
|
582
651
|
/**
|
|
583
|
-
* Propose a
|
|
584
|
-
* the booth log. The named parties endorse it with
|
|
652
|
+
* Propose a commitment (Living Network Phase 3): a commitment record in
|
|
653
|
+
* the booth log. The named parties endorse it with acceptCommitment —
|
|
585
654
|
* never the proposer; endorsement here means a second credential
|
|
586
|
-
* stood behind the
|
|
655
|
+
* stood behind the commitment, and "authorized" is reserved for account
|
|
587
656
|
* holders. Fulfillment is computed from the log: every named
|
|
588
657
|
* party endorsed and every checkable condition met.
|
|
589
658
|
*/
|
|
590
|
-
async
|
|
659
|
+
async proposeCommitment(input) {
|
|
591
660
|
return this.appendEvent({
|
|
592
|
-
type: "
|
|
593
|
-
subject: input.subject ?? input.subjects?.[0] ?? "
|
|
661
|
+
type: "commitment",
|
|
662
|
+
subject: input.subject ?? input.subjects?.[0] ?? "commitment",
|
|
594
663
|
payload: {
|
|
595
664
|
title: input.title,
|
|
596
665
|
...(input.parties ? { parties: input.parties } : {}),
|
|
@@ -602,33 +671,33 @@ export class BoothClient {
|
|
|
602
671
|
});
|
|
603
672
|
}
|
|
604
673
|
/**
|
|
605
|
-
* Endorse a
|
|
606
|
-
*
|
|
607
|
-
* endorsement is a second participant standing behind the
|
|
674
|
+
* Endorse a commitment. Refused from the commitment's proposer (403
|
|
675
|
+
* commitment_self_accept), mirroring decision acceptance: an
|
|
676
|
+
* endorsement is a second participant standing behind the commitment.
|
|
608
677
|
*/
|
|
609
|
-
async
|
|
678
|
+
async acceptCommitment(commitmentEventId) {
|
|
610
679
|
return this.appendEvent({
|
|
611
|
-
type: "
|
|
612
|
-
subject: "
|
|
613
|
-
payload: {
|
|
680
|
+
type: "commitment_accept",
|
|
681
|
+
subject: "commitment",
|
|
682
|
+
payload: { commitment_event_id: commitmentEventId },
|
|
614
683
|
});
|
|
615
684
|
}
|
|
616
685
|
/**
|
|
617
|
-
* Cancel a
|
|
618
|
-
* may cancel (403
|
|
619
|
-
*
|
|
686
|
+
* Cancel a commitment. Only the commitment's proposer or one of its endorsers
|
|
687
|
+
* may cancel (403 commitment_cancel_forbidden otherwise); a cancelled
|
|
688
|
+
* commitment is terminal.
|
|
620
689
|
*/
|
|
621
|
-
async
|
|
690
|
+
async cancelCommitment(commitmentEventId) {
|
|
622
691
|
return this.appendEvent({
|
|
623
|
-
type: "
|
|
624
|
-
subject: "
|
|
625
|
-
payload: {
|
|
692
|
+
type: "commitment_cancel",
|
|
693
|
+
subject: "commitment",
|
|
694
|
+
payload: { commitment_event_id: commitmentEventId },
|
|
626
695
|
});
|
|
627
696
|
}
|
|
628
|
-
/** The booth's
|
|
629
|
-
async
|
|
697
|
+
/** The booth's commitments with their computed statuses, from the state document. */
|
|
698
|
+
async listCommitments() {
|
|
630
699
|
const state = await this.getState();
|
|
631
|
-
return state.
|
|
700
|
+
return state.commitments;
|
|
632
701
|
}
|
|
633
702
|
/**
|
|
634
703
|
* Declare a check (Living Network Phase 5): a set of typed
|
|
@@ -661,8 +730,8 @@ export class BoothClient {
|
|
|
661
730
|
}
|
|
662
731
|
/**
|
|
663
732
|
* Set or clear the booth's close condition (Phase 3). Pass
|
|
664
|
-
* "
|
|
665
|
-
* named
|
|
733
|
+
* "commitment_terminal:<commitment event id>" to close the booth when the
|
|
734
|
+
* named commitment reaches a terminal state, "transfer_accepted" or
|
|
666
735
|
* "all_acks" for the standing conditions, or null to clear.
|
|
667
736
|
* Creator-management grant required: pass the creator credential,
|
|
668
737
|
* or construct the client with it.
|
|
@@ -689,6 +758,74 @@ export class BoothClient {
|
|
|
689
758
|
const qs = q.toString();
|
|
690
759
|
return this.request("GET", `/changes${qs ? `?${qs}` : ""}`);
|
|
691
760
|
}
|
|
761
|
+
/**
|
|
762
|
+
* Phase 13: live listening over the durable log — the changes
|
|
763
|
+
* feed as server-sent events. Yields one open frame, one event
|
|
764
|
+
* frame per relevant event as it lands, and a final end frame
|
|
765
|
+
* when the server closes the stream at its set lifetime. Live
|
|
766
|
+
* listening is best-effort with durable catch-up: a dropped
|
|
767
|
+
* stream loses nothing, and reconnecting with the last seq
|
|
768
|
+
* received (options.since) serves everything missed from the
|
|
769
|
+
* log before the stream goes live again. Pass options.signal
|
|
770
|
+
* to stop early; leaving the loop also closes the stream.
|
|
771
|
+
*/
|
|
772
|
+
async *streamChanges(options = {}) {
|
|
773
|
+
const q = new URLSearchParams();
|
|
774
|
+
if (options.mode)
|
|
775
|
+
q.set("mode", options.mode);
|
|
776
|
+
const qs = q.toString();
|
|
777
|
+
const headers = { accept: "text/event-stream" };
|
|
778
|
+
if (this.credential)
|
|
779
|
+
headers.authorization = `Bearer ${this.credential}`;
|
|
780
|
+
if (options.since !== undefined)
|
|
781
|
+
headers["last-event-id"] = String(options.since);
|
|
782
|
+
const res = await this.fetchFn(`${this.baseUrl}/api/v1/booths/${encodeURIComponent(this.boothId)}/stream${qs ? `?${qs}` : ""}`, {
|
|
783
|
+
method: "GET",
|
|
784
|
+
headers,
|
|
785
|
+
...(options.signal ? { signal: options.signal } : {}),
|
|
786
|
+
});
|
|
787
|
+
if (!res.ok) {
|
|
788
|
+
const data = (await res.json().catch(() => ({})));
|
|
789
|
+
const err = (data?.error ?? {});
|
|
790
|
+
throw new ActApiError(res.status, err.code ?? "unknown_error", err.message ?? `Request failed with status ${res.status}.`, err.details);
|
|
791
|
+
}
|
|
792
|
+
if (!res.body) {
|
|
793
|
+
throw new ActApiError(0, "stream_unavailable", "The stream response carried no body.");
|
|
794
|
+
}
|
|
795
|
+
const reader = res.body.getReader();
|
|
796
|
+
const decoder = new TextDecoder();
|
|
797
|
+
let buffer = "";
|
|
798
|
+
try {
|
|
799
|
+
for (;;) {
|
|
800
|
+
const { done, value } = await reader.read();
|
|
801
|
+
if (done)
|
|
802
|
+
break;
|
|
803
|
+
buffer += decoder.decode(value, { stream: true });
|
|
804
|
+
let cut = buffer.indexOf("\n\n");
|
|
805
|
+
while (cut >= 0) {
|
|
806
|
+
const raw = buffer.slice(0, cut);
|
|
807
|
+
buffer = buffer.slice(cut + 2);
|
|
808
|
+
const frame = parseStreamFrame(raw);
|
|
809
|
+
if (frame?.type === "error") {
|
|
810
|
+
throw new ActApiError(0, frame.code, "The booth stream reported an error.");
|
|
811
|
+
}
|
|
812
|
+
if (frame)
|
|
813
|
+
yield frame;
|
|
814
|
+
if (frame?.type === "end")
|
|
815
|
+
return;
|
|
816
|
+
cut = buffer.indexOf("\n\n");
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
finally {
|
|
821
|
+
try {
|
|
822
|
+
await reader.cancel();
|
|
823
|
+
}
|
|
824
|
+
catch {
|
|
825
|
+
/* already closed */
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|
|
692
829
|
/** Record that this participant has seen events up to seq. An ack never resolves a conflict. */
|
|
693
830
|
async ack(seq) {
|
|
694
831
|
return this.request("POST", "/ack", { seq });
|
|
@@ -861,7 +998,7 @@ export class BoothClient {
|
|
|
861
998
|
* own validation, append them in memory to a copy of the log
|
|
862
999
|
* (truncated at atSeq when given), and return the delta — new
|
|
863
1000
|
* conflicts, competing contracts, stale assumptions, affected
|
|
864
|
-
* participants,
|
|
1001
|
+
* participants, commitment and check status changes — every entry
|
|
865
1002
|
* labeled hypothetical with its base seq. Nothing is written:
|
|
866
1003
|
* the booth's log and state are unchanged, and making any of it
|
|
867
1004
|
* real means posting the events. The impact graph covers
|
|
@@ -874,4 +1011,88 @@ export class BoothClient {
|
|
|
874
1011
|
...(input.atSeq !== undefined ? { at_seq: input.atSeq } : {}),
|
|
875
1012
|
});
|
|
876
1013
|
}
|
|
1014
|
+
capsuleBody(input) {
|
|
1015
|
+
return {
|
|
1016
|
+
...(input.selection
|
|
1017
|
+
? {
|
|
1018
|
+
selection: {
|
|
1019
|
+
...(input.selection.eventIds ? { event_ids: input.selection.eventIds } : {}),
|
|
1020
|
+
...(input.selection.subjects ? { subjects: input.selection.subjects } : {}),
|
|
1021
|
+
...(input.selection.sections ? { sections: input.selection.sections } : {}),
|
|
1022
|
+
},
|
|
1023
|
+
}
|
|
1024
|
+
: {}),
|
|
1025
|
+
...(input.preset ? { preset: input.preset } : {}),
|
|
1026
|
+
...(input.expectedDigest ? { expected_digest: input.expectedDigest } : {}),
|
|
1027
|
+
};
|
|
1028
|
+
}
|
|
1029
|
+
/**
|
|
1030
|
+
* The capsule selection preview (Living Network Phase 12): the
|
|
1031
|
+
* sensitive-content review step. Returns exactly what the
|
|
1032
|
+
* selection would include — the manifest entries, the Markdown
|
|
1033
|
+
* summary, and the digest the capsule would carry — and stores
|
|
1034
|
+
* nothing. Creation requires the same selection echoed back.
|
|
1035
|
+
*/
|
|
1036
|
+
async previewCapsule(input) {
|
|
1037
|
+
return this.request("POST", "/capsules/preview", this.capsuleBody(input));
|
|
1038
|
+
}
|
|
1039
|
+
/**
|
|
1040
|
+
* Create a capsule from the echoed selection (Living Network
|
|
1041
|
+
* Phase 12): a manifest built from the log, a Markdown summary
|
|
1042
|
+
* rendered from the same data, and the full selected records,
|
|
1043
|
+
* stored as one artifact. Pin expectedDigest to a preview's
|
|
1044
|
+
* digest and creation refuses (409 capsule_drift) when the log
|
|
1045
|
+
* has moved since the preview. The temporary_org preset exports
|
|
1046
|
+
* a temporary agent organization: the booth's full working
|
|
1047
|
+
* record plus an organization block (objective, roster,
|
|
1048
|
+
* completion check ids).
|
|
1049
|
+
*/
|
|
1050
|
+
async createCapsule(input) {
|
|
1051
|
+
const result = await this.request("POST", "/capsules", this.capsuleBody(input));
|
|
1052
|
+
return result.capsule;
|
|
1053
|
+
}
|
|
1054
|
+
/** One capsule created from this booth, with its summary. */
|
|
1055
|
+
async getCapsule(capsuleId) {
|
|
1056
|
+
const result = await this.request("GET", `/capsules/${encodeURIComponent(capsuleId)}`);
|
|
1057
|
+
return result.capsule;
|
|
1058
|
+
}
|
|
1059
|
+
/** The capsules created from this booth, newest first (ids, digests, counts). */
|
|
1060
|
+
async listCapsules() {
|
|
1061
|
+
const result = await this.request("GET", "/capsules");
|
|
1062
|
+
return result.capsules;
|
|
1063
|
+
}
|
|
1064
|
+
/**
|
|
1065
|
+
* Import a capsule into this booth (Living Network Phase 12).
|
|
1066
|
+
* This client is the TARGET booth; the caller's credential here
|
|
1067
|
+
* is the only one involved — a capsule grants no access to its
|
|
1068
|
+
* source booth and no source credential takes part. Records
|
|
1069
|
+
* land as new proposals authored by the caller, each carrying
|
|
1070
|
+
* provenance { capsule_id, origin_booth_id, origin_event_id }:
|
|
1071
|
+
* accepted decisions arrive proposed, contracts arrive as new
|
|
1072
|
+
* versions authored by the caller, and endorsement acts and
|
|
1073
|
+
* service-authored records do not cross (the result lists every
|
|
1074
|
+
* skip with its reason). Importing the same capsule into the
|
|
1075
|
+
* same booth twice replays instead of duplicating.
|
|
1076
|
+
*/
|
|
1077
|
+
async importCapsule(capsuleId) {
|
|
1078
|
+
return this.request("POST", `/capsules/${encodeURIComponent(capsuleId)}/import`, {});
|
|
1079
|
+
}
|
|
1080
|
+
/**
|
|
1081
|
+
* Export a skill from a capsule of this booth (Living Network
|
|
1082
|
+
* Phase 12, §20): package a capability the capsule names (a
|
|
1083
|
+
* capability_offer event's version — picked by eventId or
|
|
1084
|
+
* versionId, or the capsule's only offered version) again
|
|
1085
|
+
* through the standard createCapability path, under the
|
|
1086
|
+
* exporter's booth identity or an ephemeral booth user, with a
|
|
1087
|
+
* provenance.json file added to the package naming the capsule,
|
|
1088
|
+
* the origin booth and event, the origin version and digest,
|
|
1089
|
+
* and the verification receipt ids the log holds for the
|
|
1090
|
+
* capability.
|
|
1091
|
+
*/
|
|
1092
|
+
async exportCapsuleSkill(capsuleId, input = {}) {
|
|
1093
|
+
return this.request("POST", `/capsules/${encodeURIComponent(capsuleId)}/skill-export`, {
|
|
1094
|
+
...(input.eventId ? { event_id: input.eventId } : {}),
|
|
1095
|
+
...(input.versionId ? { version_id: input.versionId } : {}),
|
|
1096
|
+
});
|
|
1097
|
+
}
|
|
877
1098
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moonbooth/sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "TypeScript SDK for the Moonbooth API",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,4 +25,4 @@
|
|
|
25
25
|
"vitest": "^3.2.4",
|
|
26
26
|
"@types/node": "^22.10.0"
|
|
27
27
|
}
|
|
28
|
-
}
|
|
28
|
+
}
|