@agentshouse/app-bridge 0.1.0-c58a055eeaa71 → 0.1.0-c59dd0a694516

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.
Files changed (114) hide show
  1. package/README.md +11 -9
  2. package/dist/index.d.ts +620 -14
  3. package/dist/mdmodel/body.d.ts +84 -0
  4. package/dist/mdmodel/built-in.d.ts +3 -0
  5. package/dist/mdmodel/definition.d.ts +90 -0
  6. package/dist/mdmodel/divide.d.ts +2 -0
  7. package/dist/mdmodel/document.d.ts +21 -0
  8. package/dist/mdmodel/event.d.ts +76 -0
  9. package/dist/mdmodel/facts.d.ts +14 -0
  10. package/dist/mdmodel/fields.d.ts +5 -0
  11. package/dist/mdmodel/house-model.d.ts +865 -0
  12. package/dist/mdmodel/house-references/crockford.d.ts +3 -0
  13. package/dist/mdmodel/house-references/patterns.d.ts +8 -0
  14. package/dist/mdmodel/index.d.ts +43 -0
  15. package/dist/mdmodel/kinds.d.ts +17 -0
  16. package/dist/mdmodel/markdown.d.ts +74 -0
  17. package/dist/mdmodel/media-type.d.ts +71 -0
  18. package/dist/mdmodel/not-ready.d.ts +1 -0
  19. package/dist/mdmodel/paths.d.ts +39 -0
  20. package/dist/mdmodel/pattern.d.ts +9 -0
  21. package/dist/mdmodel/project.d.ts +21 -0
  22. package/dist/mdmodel/query/language.d.ts +253 -0
  23. package/dist/mdmodel/query/match.d.ts +13 -0
  24. package/dist/mdmodel/query/rows.d.ts +31 -0
  25. package/dist/mdmodel/query/sql.d.ts +38 -0
  26. package/dist/mdmodel/references.d.ts +3 -0
  27. package/dist/mdmodel/reserved.d.ts +5 -0
  28. package/dist/mdmodel/room-types.d.ts +6 -0
  29. package/dist/mdmodel/types.d.ts +172 -0
  30. package/dist/mdmodel/validate.d.ts +37 -0
  31. package/dist/mdmodel/version.d.ts +1 -0
  32. package/dist/mdmodel/yaml.d.ts +55 -0
  33. package/dist/mdruntime/actions.d.ts +25 -0
  34. package/dist/mdruntime/adapter.d.ts +575 -0
  35. package/dist/mdruntime/attached-model.d.ts +6 -0
  36. package/dist/mdruntime/authored.d.ts +87 -0
  37. package/dist/mdruntime/binary.d.ts +17 -0
  38. package/dist/mdruntime/bootstrap.d.ts +43 -0
  39. package/dist/mdruntime/cell.d.ts +5 -0
  40. package/dist/mdruntime/chain.d.ts +11 -0
  41. package/dist/mdruntime/change-set.d.ts +31 -0
  42. package/dist/mdruntime/change.d.ts +123 -0
  43. package/dist/mdruntime/client.d.ts +98 -0
  44. package/dist/mdruntime/collection.d.ts +49 -0
  45. package/dist/mdruntime/compile.d.ts +17 -0
  46. package/dist/mdruntime/conversation-live.d.ts +149 -0
  47. package/dist/mdruntime/conversation-row.d.ts +39 -0
  48. package/dist/mdruntime/conversation.d.ts +136 -0
  49. package/dist/mdruntime/declaration.d.ts +9 -0
  50. package/dist/mdruntime/durability.d.ts +30 -0
  51. package/dist/mdruntime/failure.d.ts +15 -0
  52. package/dist/mdruntime/figures.d.ts +48 -0
  53. package/dist/mdruntime/holdings.d.ts +28 -0
  54. package/dist/mdruntime/identity.d.ts +5 -0
  55. package/dist/mdruntime/install.d.ts +59 -0
  56. package/dist/mdruntime/listing.d.ts +51 -0
  57. package/dist/mdruntime/live.d.ts +24 -0
  58. package/dist/mdruntime/media.d.ts +12 -0
  59. package/dist/mdruntime/messages.d.ts +57 -0
  60. package/dist/mdruntime/model.d.ts +54 -0
  61. package/dist/mdruntime/observation.d.ts +59 -0
  62. package/dist/mdruntime/open.d.ts +1 -0
  63. package/dist/mdruntime/opened.d.ts +21 -0
  64. package/dist/mdruntime/outcome.d.ts +94 -0
  65. package/dist/mdruntime/overlay.d.ts +29 -0
  66. package/dist/mdruntime/preparation.d.ts +40 -0
  67. package/dist/mdruntime/presence.d.ts +57 -0
  68. package/dist/mdruntime/query.d.ts +87 -0
  69. package/dist/mdruntime/reach.d.ts +54 -0
  70. package/dist/mdruntime/readiness.d.ts +54 -0
  71. package/dist/mdruntime/reads.d.ts +38 -0
  72. package/dist/mdruntime/recovery.d.ts +27 -0
  73. package/dist/mdruntime/refresh.d.ts +26 -0
  74. package/dist/mdruntime/replica.d.ts +62 -0
  75. package/dist/mdruntime/retried.d.ts +29 -0
  76. package/dist/mdruntime/room-draft.d.ts +197 -0
  77. package/dist/mdruntime/room-drafts.d.ts +23 -0
  78. package/dist/mdruntime/runtime.d.ts +33 -0
  79. package/dist/mdruntime/save.d.ts +58 -0
  80. package/dist/mdruntime/saves.d.ts +31 -0
  81. package/dist/mdruntime/search.d.ts +21 -0
  82. package/dist/mdruntime/seed.d.ts +24 -0
  83. package/dist/mdruntime/socket/admission.d.ts +6 -0
  84. package/dist/mdruntime/socket/answers.d.ts +5 -0
  85. package/dist/mdruntime/socket/lanes.d.ts +27 -0
  86. package/dist/mdruntime/socket/session.d.ts +37 -0
  87. package/dist/mdruntime/socket.d.ts +66 -0
  88. package/dist/mdruntime/source.d.ts +58 -0
  89. package/dist/mdruntime/status.d.ts +25 -0
  90. package/dist/mdruntime/store/installs.d.ts +29 -0
  91. package/dist/mdruntime/store/readiness.d.ts +10 -0
  92. package/dist/mdruntime/store/records.d.ts +222 -0
  93. package/dist/mdruntime/store/room-held.d.ts +7 -0
  94. package/dist/mdruntime/store/rooms-shown.d.ts +7 -0
  95. package/dist/mdruntime/store/space.d.ts +10 -0
  96. package/dist/mdruntime/store/watchers.d.ts +16 -0
  97. package/dist/mdruntime/store/writes.d.ts +23 -0
  98. package/dist/mdruntime/store.d.ts +125 -0
  99. package/dist/mdruntime/stored.d.ts +166 -0
  100. package/dist/mdruntime/surface.d.ts +89 -0
  101. package/dist/mdruntime/tables.d.ts +375 -0
  102. package/dist/mdruntime/tallies.d.ts +17 -0
  103. package/dist/mdruntime/transfer.d.ts +4 -0
  104. package/dist/mdruntime/wire.d.ts +288 -0
  105. package/dist/session-content/bounds.d.ts +7 -0
  106. package/dist/session-content/check.d.ts +18 -0
  107. package/dist/session-content/index.d.ts +7 -0
  108. package/dist/session-content/parts.d.ts +103 -0
  109. package/dist/session-content/state.d.ts +61 -0
  110. package/dist/session-content/turn.d.ts +328 -0
  111. package/dist/test-host.d.ts +15 -5
  112. package/dist/test-host.js +74 -23
  113. package/docs/families.md +93 -22
  114. package/package.json +8 -6
@@ -0,0 +1,94 @@
1
+ import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
2
+ import type { ChangeBatch } from './change.js';
3
+ import type { Attempt, Retries } from './retried.js';
4
+ import type { KeptBinary, KeptResult } from './opened.js';
5
+ type Refused<Kind extends string> = ProviderRefusal & {
6
+ kind: Kind;
7
+ };
8
+ export type Failure = Refused<'transport-uncertainty'> | Refused<'revoked-authorization'> | (Refused<'room-not-readable'> & {
9
+ locator: string;
10
+ }) | (Refused<'room-locked'> & {
11
+ locator: string;
12
+ }) | ScopedRefusal;
13
+ export type CallResult = {
14
+ kind: 'action';
15
+ result: unknown;
16
+ at?: RoomVersionAt;
17
+ } | (Refused<'rejected'> & {
18
+ reset?: string;
19
+ }) | Refused<'undeclared'> | Failure;
20
+ export type HistoryAnswer = Exclude<HistoryResult, {
21
+ kind: Failure['kind'];
22
+ }> | Failure;
23
+ type BinaryRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
24
+ export type BinaryAnswer = {
25
+ kind: 'binary';
26
+ stream: ReadableStream<Uint8Array>;
27
+ byteLength: number;
28
+ mediaType: string;
29
+ } | BinaryRefusal;
30
+ export type HeldBinaryAnswer = KeptBinary | BinaryRefusal;
31
+ export type BinaryLinkAnswer = {
32
+ kind: 'link';
33
+ url: string;
34
+ name: string;
35
+ mediaType: string;
36
+ } | Refused<'rejected'> | Refused<'absent'> | Failure;
37
+ export type HeldShownAnswer = KeptBinary | BinaryLinkAnswer;
38
+ export type ShownAnswer = BinaryAnswer | BinaryLinkAnswer;
39
+ export type AttachAnswer = {
40
+ kind: 'attached';
41
+ path: string;
42
+ } | Offline | Refused<'rejected'> | Failure;
43
+ export type DownloadAnswer = {
44
+ kind: 'started';
45
+ } | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
46
+ export type Resolution = {
47
+ readonly kind: 'document';
48
+ readonly room: string;
49
+ readonly path: string;
50
+ } | {
51
+ readonly kind: 'deleted';
52
+ readonly room: string;
53
+ readonly path: string;
54
+ readonly revision: HistoryRevision;
55
+ } | Refused<'unreadable'> | Refused<'absent'> | Failure;
56
+ export declare const UNREADABLE: Refused<'unreadable'>;
57
+ export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
58
+ export declare const ABSENT_TARGET: Refused<'absent'>;
59
+ export declare function absentBinary(path: string): Refused<'absent'>;
60
+ export declare function declaredType(blob: Blob): string;
61
+ export declare function blobOf(binary: Extract<BinaryAnswer, {
62
+ kind: 'binary';
63
+ }>): Promise<Blob>;
64
+ export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
65
+ export declare function binaryLinkAnswer(result: BinaryLinkResult, held?: string): BinaryLinkAnswer;
66
+ export declare function attachAnswer(result: AttachResult): AttachAnswer;
67
+ export declare const ROOM_LOCKED = "room-locked";
68
+ export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
69
+ locator: string;
70
+ };
71
+ export type Offline = {
72
+ readonly kind: 'offline';
73
+ };
74
+ export declare const OFFLINE: Offline;
75
+ export declare function answeredResult(value: unknown): boolean;
76
+ export declare const UNCERTAIN: Failure;
77
+ export declare function undeclared(name: string): CallResult;
78
+ export declare function failure(result: AdapterFailure): Failure;
79
+ export declare function calledResult(result: ActionResult): CallResult;
80
+ export declare function historyAnswer(result: HistoryResult): HistoryAnswer;
81
+ export type Submission = {
82
+ readonly state: 'waiting' | 'submitted';
83
+ } | {
84
+ readonly state: 'reset';
85
+ readonly reset: string;
86
+ };
87
+ export type QueueEntry = {
88
+ readonly batch: ChangeBatch;
89
+ } & (Submission | {
90
+ readonly state: 'local';
91
+ });
92
+ export declare const UNANSWERED: ActionResult;
93
+ export declare function handedOutcome(retries: Retries, attempt: Attempt | undefined, result: ActionResult): CallResult;
94
+ export {};
@@ -0,0 +1,29 @@
1
+ import { type ApplyResult } from '../mdmodel/index.js';
2
+ import type { BinaryFile, HeadChange } from './adapter.js';
3
+ import { type Composition } from './collection.js';
4
+ import { type ChangeBatch } from './change.js';
5
+ export type Heads = {
6
+ revisions: Readonly<Record<string, string>>;
7
+ fileIds: Readonly<Record<string, string>>;
8
+ created: Readonly<Record<string, string>>;
9
+ changes: Readonly<Record<string, HeadChange>>;
10
+ };
11
+ export type HeldBinary = ({
12
+ readonly state: 'accepted';
13
+ } & BinaryFile) | {
14
+ readonly state: 'pending';
15
+ readonly localId: string;
16
+ readonly byteLength: number;
17
+ readonly mediaType: string;
18
+ readonly sha256: string;
19
+ };
20
+ export type Layer = Heads & {
21
+ documents: Readonly<Record<string, string>>;
22
+ binaries: Readonly<Record<string, HeldBinary>>;
23
+ };
24
+ export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
25
+ export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
26
+ export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
27
+ export declare function composed(path: string, fields: Readonly<Record<string, unknown>>, sections: Readonly<Record<string, string>>, composition: Composition): ApplyResult;
28
+ export declare function compose(path: string, fields: Readonly<Record<string, unknown>>, sections: Readonly<Record<string, string>>, composition: Composition): string;
29
+ export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], composition: Composition, unapplied?: () => void): Generator<number, Layer, void>;
@@ -0,0 +1,40 @@
1
+ import { type InstallShare } from './install.js';
2
+ import { type ReadinessChange } from './observation.js';
3
+ import { type PortReach } from './reach.js';
4
+ import { type CodeAvailability, type ConnectionAvailability, type Readiness, type RoomCoverage } from './readiness.js';
5
+ import type { Runtime } from './runtime.js';
6
+ export type ReadinessPort = {
7
+ readonly target: string;
8
+ readonly code: CodeAvailability;
9
+ };
10
+ export type ReadinessMessage = Readiness | ReadinessChange;
11
+ export type ReadinessWatch = {
12
+ readonly port: ReadinessPort;
13
+ readonly reach: PortReach | null;
14
+ readonly deliver: (readiness: ReadinessMessage) => void;
15
+ };
16
+ type Share = InstallShare & {
17
+ readonly coverage: RoomCoverage;
18
+ };
19
+ type Totals = {
20
+ installing: number;
21
+ downloading: number;
22
+ acquiring: number;
23
+ unsettled: number;
24
+ done: number;
25
+ total: number;
26
+ };
27
+ export type ReadinessShowing = {
28
+ readonly listing: number;
29
+ readonly roomsListed: boolean;
30
+ readonly named: ReadonlySet<string> | null;
31
+ readonly rooms: Map<string, Share>;
32
+ readonly totals: Totals;
33
+ shown: string;
34
+ };
35
+ export declare function prepare(runtime: Runtime, locators?: readonly string[]): void;
36
+ export declare function connectionNow(runtime: Runtime): Promise<ConnectionAvailability>;
37
+ export declare function deliverOwedReadiness(runtime: Runtime, owed: readonly ReadinessWatch[], touched: ReadonlySet<string> | null): Promise<void>;
38
+ export declare function watchReadiness({ store }: Runtime, port: ReadinessPort, reach: PortReach | null, deliver: (readiness: ReadinessMessage) => void): () => void;
39
+ export declare function filled(runtime: Runtime): void;
40
+ export {};
@@ -0,0 +1,57 @@
1
+ import type { DiscoveredRoom, ProviderRefusal, ScopedRefusal } from './adapter.js';
2
+ import type { ModelState } from './model.js';
3
+ type Repairable = {
4
+ readonly reset: string | undefined;
5
+ };
6
+ type Standing = {
7
+ readonly stale: boolean;
8
+ readonly repairable: Repairable | null;
9
+ readonly repairing: boolean;
10
+ readonly reloadDue: boolean;
11
+ };
12
+ export declare function lockingMode(mode: string | undefined): boolean;
13
+ type Listing = {
14
+ readonly whole: boolean;
15
+ readonly live: boolean;
16
+ };
17
+ export type Presence = {
18
+ list(found: readonly DiscoveredRoom[], how: Listing): readonly DiscoveredRoom[];
19
+ room(locator: string): DiscoveredRoom | undefined;
20
+ rooms(): readonly DiscoveredRoom[];
21
+ available(locator: string, selection?: string): boolean;
22
+ refusal(locator: string): ProviderRefusal | null;
23
+ unheldModel(locator: string): ModelState | null;
24
+ refused(locator: string, refusal: ScopedRefusal | null): void;
25
+ readable(locator: string): boolean;
26
+ modelled(locator: string, model: ModelState | null): void;
27
+ installed(locator: string, bootstrapped: boolean): void;
28
+ locked(locator: string, stored: () => Promise<string | null>): Promise<boolean>;
29
+ lockedAmong(stored: ReadonlyMap<string, {
30
+ readonly offline: string;
31
+ }>, locking: ReadonlySet<string>): readonly string[];
32
+ lockedAs(locator: string, mode: string | undefined): boolean;
33
+ connectionLost(lapsed: () => void): void;
34
+ connectionLive(): void;
35
+ lapse(): void;
36
+ stood(locator: string, stale: boolean, repairable?: Repairable | null): void;
37
+ repairing(locator: string, running: boolean): void;
38
+ reload(locator: string, due: boolean): void;
39
+ standing(locator: string): Standing;
40
+ settled(): boolean;
41
+ repairsOwed(): readonly string[];
42
+ askAgain(locator: string, ask: () => void): void;
43
+ stopAsking(locator?: string): void;
44
+ lose(locator: string, during: number): boolean;
45
+ writing(locator: string): boolean;
46
+ unwritten(locator: string): void;
47
+ lost(locator: string): boolean;
48
+ losing(): boolean;
49
+ listing(): number;
50
+ losses(): number;
51
+ lostSince(locator: string, losses: number): boolean;
52
+ liftable(locator: string, discovery: number): boolean;
53
+ lift(locator: string, discovery: number, unfenced: boolean): void;
54
+ close(): void;
55
+ };
56
+ export declare function createPresence(notReadyWaitMs: (asked: number) => number): Presence;
57
+ export {};
@@ -0,0 +1,87 @@
1
+ import { type HeldRooms, type QueryPlan } from '../mdmodel/index.js';
2
+ import type { HeadChange } from './adapter.js';
3
+ import type { BinaryFileRecord } from './binary.js';
4
+ import type { Open } from './open.js';
5
+ export type Backlink = {
6
+ path: string;
7
+ type: string;
8
+ field: string;
9
+ };
10
+ export type QueryDocument = {
11
+ room: string;
12
+ path: string;
13
+ type?: string;
14
+ fields?: Readonly<Record<string, unknown>>;
15
+ sections?: Readonly<Record<string, string>>;
16
+ preamble?: string;
17
+ markdown?: string;
18
+ backlinks?: readonly Backlink[];
19
+ change?: HeadChange | null;
20
+ fileId?: string | null;
21
+ revision?: string | null;
22
+ binaryFile?: BinaryFileRecord;
23
+ size?: number | null;
24
+ created?: string | null;
25
+ };
26
+ export type GroupTotal = {
27
+ count: number;
28
+ size: number;
29
+ };
30
+ export type QueryGroup = {
31
+ key: readonly unknown[];
32
+ count: number;
33
+ documents?: GroupTotal;
34
+ files?: GroupTotal;
35
+ updated?: string | null;
36
+ greatest?: unknown;
37
+ };
38
+ export type CoveredRoom = {
39
+ room: string;
40
+ generation: string;
41
+ current: boolean;
42
+ };
43
+ export type QueryCoverage = {
44
+ rooms: readonly CoveredRoom[];
45
+ overlay: readonly string[];
46
+ };
47
+ export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
48
+ export type PendingRoom = {
49
+ room: string;
50
+ awaits: Awaits;
51
+ };
52
+ export type PendingResult = {
53
+ pending: readonly PendingRoom[];
54
+ };
55
+ export type DocumentRows = {
56
+ documents: readonly QueryDocument[];
57
+ next?: string;
58
+ total?: number;
59
+ };
60
+ export type GroupRows = {
61
+ groups: readonly QueryGroup[];
62
+ next?: string;
63
+ total?: number;
64
+ };
65
+ export type QueryRows = DocumentRows | GroupRows;
66
+ export type DocumentResult = DocumentRows & {
67
+ coverage: QueryCoverage;
68
+ };
69
+ export type GroupResult = GroupRows & {
70
+ coverage: QueryCoverage;
71
+ };
72
+ export type QueryResult = DocumentResult | GroupResult | PendingResult;
73
+ export type PlanArea = {
74
+ room: string;
75
+ path: string;
76
+ open: readonly string[];
77
+ };
78
+ export type PlanReach = {
79
+ rooms: readonly string[];
80
+ documents: readonly string[];
81
+ areas: readonly PlanArea[];
82
+ };
83
+ export type Plan = QueryPlan & {
84
+ reach: PlanReach | null;
85
+ locked: readonly string[];
86
+ };
87
+ export declare function planWithin(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
@@ -0,0 +1,54 @@
1
+ import type { AppRoom } from './listing.js';
2
+ import type { ReadinessMessage, ReadinessPort } from './preparation.js';
3
+ import type { MdRuntime, RuntimeTopic } from './surface.js';
4
+ import type { Plan, PlanReach, QueryResult } from './query.js';
5
+ import type { SearchResult } from './search.js';
6
+ export type ReachedDocument = {
7
+ readonly room: string;
8
+ readonly path: string;
9
+ };
10
+ export type ReachedArea = {
11
+ readonly room: string;
12
+ readonly path: string;
13
+ readonly open: readonly string[];
14
+ };
15
+ export type PortReach = {
16
+ readonly rooms: readonly string[];
17
+ readonly documents: readonly ReachedDocument[];
18
+ readonly areas?: readonly ReachedArea[];
19
+ readonly conversations: boolean;
20
+ };
21
+ export type Deliver = (message: unknown) => void;
22
+ export type Fail = (error: unknown) => void;
23
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
24
+ export type RuntimeView = {
25
+ md: MdRuntime;
26
+ watch: Watch;
27
+ };
28
+ export type NarrowedView = RuntimeView & {
29
+ narrow(reach: PortReach | null): void;
30
+ };
31
+ export type Reachable = RuntimeView & {
32
+ plan(input: unknown, reach: PortReach | null): Promise<Plan>;
33
+ query(plan: Plan): Promise<QueryResult>;
34
+ watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
35
+ search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
36
+ watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: ReadinessMessage) => void): () => void;
37
+ locked(room: string): Promise<boolean>;
38
+ lockedRooms(): Promise<readonly string[]>;
39
+ watchLocks(notify: () => void): () => void;
40
+ located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
41
+ room(locator: string): Promise<AppRoom | undefined>;
42
+ };
43
+ export declare function holds(reach: PortReach | null, room: string): boolean;
44
+ export declare function governs(reach: PortReach | null, room: {
45
+ readonly locator: string;
46
+ readonly typedSelection: {
47
+ roots: readonly string[];
48
+ } | null;
49
+ }): {
50
+ readonly collection: boolean;
51
+ readonly selection: boolean;
52
+ };
53
+ export declare function planReach(reach: PortReach | null): PlanReach | null;
54
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
@@ -0,0 +1,54 @@
1
+ import type { Open } from './open.js';
2
+ export type CodeAvailability = Open<'stored' | 'absent'>;
3
+ export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'unadmitted'>;
4
+ export type RoomCoverage = {
5
+ readonly room: string;
6
+ readonly state: RoomPreparation;
7
+ };
8
+ export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
9
+ export type TargetCoverage = {
10
+ readonly complete: boolean;
11
+ readonly listed: boolean;
12
+ readonly rooms: readonly RoomCoverage[];
13
+ readonly conversations: ConversationCoverage;
14
+ };
15
+ export type Persistence = Open<'granted' | 'denied' | 'unavailable' | 'memory'>;
16
+ export type Durability = Open<'persistent' | 'best-effort'>;
17
+ export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
18
+ export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
19
+ export type Space = Open<'full'>;
20
+ export type InstallationStep = Open<'downloading' | 'writing' | 'replaying'>;
21
+ export type InstallationAmount = {
22
+ readonly done: number;
23
+ readonly total: number;
24
+ };
25
+ export type Installation = {
26
+ readonly step: InstallationStep | null;
27
+ readonly bytes: InstallationAmount;
28
+ };
29
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
30
+ export type Readiness = {
31
+ readonly status: ReadinessStatus;
32
+ readonly ready: boolean;
33
+ readonly usable: boolean;
34
+ readonly code: CodeAvailability;
35
+ readonly coverage: TargetCoverage;
36
+ readonly durability: Durability;
37
+ readonly persistence: Persistence;
38
+ readonly connection: ConnectionAvailability;
39
+ readonly house: HouseOutcome;
40
+ readonly space: Space | null;
41
+ readonly installation: Installation;
42
+ readonly lost: boolean;
43
+ };
44
+ export type ReadinessShown = Omit<Readiness, 'coverage'> & {
45
+ readonly coverage: Omit<TargetCoverage, 'rooms'>;
46
+ };
47
+ export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
48
+ readonly coverage: Omit<TargetCoverage, 'complete' | 'rooms'> & {
49
+ readonly unsettled: number;
50
+ };
51
+ readonly established: boolean;
52
+ };
53
+ export declare const COMPLETE_ROOMS: ReadonlySet<string>;
54
+ export declare function readinessOf(facts: ReadinessFacts): ReadinessShown;
@@ -0,0 +1,38 @@
1
+ import { type CallResult } from './outcome.js';
2
+ import type { Recovery } from './recovery.js';
3
+ import type { Attempt, Retries } from './retried.js';
4
+ import type { Connection, RuntimeDatabase } from './tables.js';
5
+ export declare const READ_TABLES: readonly string[];
6
+ export type ReadAt = {
7
+ readonly name: string;
8
+ readonly input: string;
9
+ readonly build: string;
10
+ };
11
+ export type ObservedRead = {
12
+ readonly answer: unknown;
13
+ readonly failure: CallResult | null;
14
+ readonly kept: boolean;
15
+ };
16
+ export type ReadAnswers = {
17
+ watch(name: string, input: unknown, deliver: (read: ObservedRead) => void): () => void;
18
+ again(led?: Promise<unknown>): void;
19
+ reopened(): void;
20
+ };
21
+ export type ReadAnswersOptions = {
22
+ readonly database: RuntimeDatabase;
23
+ readonly build: string;
24
+ readonly unkept: readonly string[];
25
+ readonly leading: readonly string[];
26
+ readonly recovery: Recovery;
27
+ readonly retries: Retries;
28
+ call(name: string, input: unknown, attempt: Attempt): Promise<CallResult>;
29
+ online(): boolean;
30
+ streaming(): boolean;
31
+ closed(): boolean;
32
+ full(): boolean;
33
+ filled(): void;
34
+ };
35
+ export declare function storedRead(connection: Connection, { name, input, build }: ReadAt): string | null;
36
+ export declare function keptRead(connection: Connection, { name, input, build }: ReadAt, answer: string): null;
37
+ export declare function readsOfOtherBuildsForgotten(connection: Connection, build: string): null;
38
+ export declare function readAnswers(options: ReadAnswersOptions): ReadAnswers;
@@ -0,0 +1,27 @@
1
+ export type Attempted = 'done' | 'again' | {
2
+ readonly at: number;
3
+ };
4
+ export type Attempt = (signal: AbortSignal) => Promise<Attempted>;
5
+ export type AttemptOptions = {
6
+ readonly at?: number;
7
+ readonly again?: boolean;
8
+ };
9
+ export type RecoveryOptions = {
10
+ readonly firstMs?: number;
11
+ readonly maxMs?: number;
12
+ readonly attempts?: number;
13
+ readonly inFlight?: number;
14
+ };
15
+ export type Recovery = {
16
+ attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
17
+ pending(intent: string): boolean;
18
+ resume(): void;
19
+ again(): void;
20
+ waits(wake: () => void): () => void;
21
+ cancel(intent: string): void;
22
+ scope(inFlight?: number): Recovery;
23
+ retire(): Promise<void>;
24
+ };
25
+ export declare function retryDelay(tries: number, firstMs?: number, maxMs?: number): number;
26
+ export declare function untilAnswered<T>(ask: () => Promise<T>, signal: AbortSignal, answered?: (answer: T) => boolean, owner?: Recovery): Promise<T>;
27
+ export declare function createRecovery(options?: RecoveryOptions): Recovery;
@@ -0,0 +1,26 @@
1
+ import type { AdapterFailure, Authorization, RefreshPage, RefreshRequest, RefreshResult, RetryableRefusal } from './adapter.js';
2
+ import type { Remodel } from './bootstrap.js';
3
+ import type { ReplicaRecord } from './replica.js';
4
+ import type { RefreshedPage } from './store.js';
5
+ import type { HeldEntry, StoredEntry } from './tables.js';
6
+ import { type Unconfirmed } from './transfer.js';
7
+ export type Advancement = {
8
+ kind: 'still-current';
9
+ } | {
10
+ kind: 'advanced';
11
+ record: ReplicaRecord;
12
+ changed: ReadonlySet<string>;
13
+ } | {
14
+ kind: 'beyond-horizon';
15
+ } | RetryableRefusal | Unconfirmed | AdapterFailure;
16
+ export type Refresher = (authorization: Authorization, request: RefreshRequest) => Promise<RefreshResult>;
17
+ export type Refreshing = {
18
+ turn(): void;
19
+ prior(paths: readonly string[]): Promise<ReadonlyMap<string, HeldEntry>>;
20
+ later(paths: readonly string[], roomVersion: string): Promise<ReadonlySet<string>>;
21
+ stage(page: RefreshedPage): Promise<boolean>;
22
+ };
23
+ type PageContent = Pick<RefreshPage, 'documents' | 'facts' | 'revisions' | 'fileIds' | 'created' | 'changes' | 'binaryFiles'>;
24
+ export declare function pageEntries(page: PageContent, removals: readonly string[], roomVersion: string, prior: (paths: readonly string[]) => Promise<ReadonlyMap<string, HeldEntry>>): Promise<StoredEntry[]>;
25
+ export declare function advancement(refresh: Refresher, authorization: Authorization, held: ReplicaRecord, remodel: Remodel, continuing: () => boolean, staging: Refreshing): Promise<Advancement>;
26
+ export {};
@@ -0,0 +1,62 @@
1
+ import { type TypedPath } from '../mdmodel/index.js';
2
+ import type { BootstrapInventory, SavedFacts, MutationResult, RoomDeclaration, TypedSelection } from './adapter.js';
3
+ import { type ChangeBatch, type Precondition } from './change.js';
4
+ import { type Collection, type Composition } from './collection.js';
5
+ import { type ModelState } from './model.js';
6
+ import { type Layer } from './overlay.js';
7
+ import type { HeldEntry, OverlayEntry, StoredEntry } from './tables.js';
8
+ export type ReplicaRecord = {
9
+ readonly locator: string;
10
+ readonly declaration: RoomDeclaration;
11
+ readonly model: ModelState;
12
+ readonly roomVersion: string;
13
+ readonly transfer: string;
14
+ readonly inventory: BootstrapInventory;
15
+ readonly key: number;
16
+ };
17
+ export type HeldReplica = {
18
+ readonly record: ReplicaRecord;
19
+ readonly queue: readonly ChangeBatch[];
20
+ readonly overlaid: ReadonlySet<string>;
21
+ };
22
+ export type VisibleLayer = Layer & {
23
+ readonly collection: Collection;
24
+ };
25
+ export type Slice = Layer & {
26
+ readonly written: Readonly<Record<string, string>>;
27
+ readonly facts: Readonly<Record<string, SavedFacts>>;
28
+ readonly held: ReadonlySet<string>;
29
+ };
30
+ export declare function compositionOf(model: ModelState, typedSelection: TypedSelection | null, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
31
+ export declare function storedRecord(record: ReplicaRecord): string;
32
+ export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
33
+ export type LayerEntry = Omit<StoredEntry, 'facts'>;
34
+ export declare function entryAt(layer: Layer & {
35
+ readonly written?: Readonly<Record<string, string>>;
36
+ }, path: string): LayerEntry | null;
37
+ export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
38
+ export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
39
+ export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
40
+ export type Replayed = {
41
+ readonly visible: VisibleLayer;
42
+ readonly touched: ReadonlySet<string>;
43
+ };
44
+ export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
45
+ export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
46
+ export declare function holds(layer: Layer, preconditions: readonly Precondition[], composition: Composition): boolean;
47
+ export declare function landed(batch: ChangeBatch, confirmed: Layer, composition: Composition, current?: Readonly<Record<string, string>>): boolean;
48
+ export type Standing = {
49
+ readonly withdrawn: readonly ChangeBatch[];
50
+ readonly kept: readonly ChangeBatch[];
51
+ };
52
+ export declare function standing(confirmed: Slice, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean, locator: string, composition: Composition): Generator<number, Standing, void>;
53
+ type Accepted = Extract<MutationResult, {
54
+ kind: 'accepted';
55
+ }>;
56
+ export type Returned = {
57
+ readonly set: readonly StoredEntry[];
58
+ readonly removed: readonly string[];
59
+ };
60
+ export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
61
+ export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
62
+ export {};
@@ -0,0 +1,29 @@
1
+ import { type RuntimeShell } from './durability.js';
2
+ export declare const STEPS: readonly ['database', 'sign_in', 'connection', 'code', 'download', 'conversations', 'sending', 'reading'];
3
+ export type Step = (typeof STEPS)[number];
4
+ export type RetriedFailure = {
5
+ readonly step: Step;
6
+ readonly answered: false;
7
+ } | {
8
+ readonly step: Step;
9
+ readonly answered: true;
10
+ readonly error: unknown;
11
+ };
12
+ export type Uncertain = {
13
+ readonly failure?: unknown;
14
+ };
15
+ export type Attempt = {
16
+ readonly step: Step;
17
+ readonly instance: string;
18
+ };
19
+ export declare class Unanswered extends Error {
20
+ }
21
+ export declare function uncertainError(uncertainty: Uncertain): unknown;
22
+ export type Retries = {
23
+ failed(step: Step, instance: string, error: unknown): void;
24
+ unanswered(step: Step, instance: string): void;
25
+ uncertain(step: Step, instance: string, uncertainty: Uncertain): void;
26
+ succeeded(step: Step, instance: string): void;
27
+ };
28
+ export declare function createRetries(shell: Pick<RuntimeShell, 'retried' | 'succeeded'>): Retries;
29
+ export declare function retrying<T>(retries: Retries, step: Step, instance: string, ask: () => Promise<T>): () => Promise<T>;