@agentshouse/app-bridge 0.1.0-caae3da69c1c2 → 0.1.0-cac2ee656ded8

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 (113) hide show
  1. package/README.md +9 -9
  2. package/dist/index.d.ts +571 -18
  3. package/dist/mdmodel/body.d.ts +84 -0
  4. package/dist/mdmodel/built-in.d.ts +3 -0
  5. package/dist/mdmodel/crockford.d.ts +3 -0
  6. package/dist/mdmodel/definition.d.ts +21 -10
  7. package/dist/mdmodel/document.d.ts +15 -8
  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 +1 -1
  11. package/dist/mdmodel/house-model.d.ts +826 -0
  12. package/dist/mdmodel/house-references.d.ts +3 -0
  13. package/dist/mdmodel/index.d.ts +35 -13
  14. package/dist/mdmodel/kinds.d.ts +17 -0
  15. package/dist/mdmodel/markdown.d.ts +74 -0
  16. package/dist/mdmodel/paths.d.ts +10 -1
  17. package/dist/mdmodel/pattern.d.ts +9 -0
  18. package/dist/mdmodel/query/language.d.ts +253 -0
  19. package/dist/mdmodel/query/match.d.ts +13 -0
  20. package/dist/mdmodel/query/rows.d.ts +31 -0
  21. package/dist/mdmodel/query/sql.d.ts +38 -0
  22. package/dist/mdmodel/reserved.d.ts +5 -0
  23. package/dist/mdmodel/room-types.d.ts +6 -0
  24. package/dist/mdmodel/types.d.ts +29 -10
  25. package/dist/mdmodel/validate.d.ts +31 -6
  26. package/dist/mdruntime/actions.d.ts +25 -0
  27. package/dist/mdruntime/adapter.d.ts +159 -122
  28. package/dist/mdruntime/attached-model.d.ts +6 -0
  29. package/dist/mdruntime/binary.d.ts +0 -5
  30. package/dist/mdruntime/bootstrap.d.ts +43 -0
  31. package/dist/mdruntime/cell.d.ts +5 -0
  32. package/dist/mdruntime/chain.d.ts +11 -0
  33. package/dist/mdruntime/change-set.d.ts +10 -16
  34. package/dist/mdruntime/change.d.ts +32 -1
  35. package/dist/mdruntime/client.d.ts +37 -26
  36. package/dist/mdruntime/collection.d.ts +29 -22
  37. package/dist/mdruntime/compile.d.ts +17 -0
  38. package/dist/mdruntime/conversation-live.d.ts +146 -0
  39. package/dist/mdruntime/conversation-row.d.ts +32 -0
  40. package/dist/mdruntime/conversation.d.ts +68 -49
  41. package/dist/mdruntime/declaration.d.ts +9 -0
  42. package/dist/mdruntime/durability.d.ts +20 -4
  43. package/dist/mdruntime/failure.d.ts +3 -0
  44. package/dist/mdruntime/figures.d.ts +48 -0
  45. package/dist/mdruntime/holdings.d.ts +28 -0
  46. package/dist/mdruntime/identity.d.ts +5 -0
  47. package/dist/mdruntime/listing.d.ts +47 -0
  48. package/dist/mdruntime/live.d.ts +22 -0
  49. package/dist/mdruntime/media.d.ts +7 -0
  50. package/dist/mdruntime/messages.d.ts +55 -0
  51. package/dist/mdruntime/model.d.ts +8 -11
  52. package/dist/mdruntime/observation.d.ts +17 -3
  53. package/dist/mdruntime/opened.d.ts +21 -0
  54. package/dist/mdruntime/outcome.d.ts +47 -9
  55. package/dist/mdruntime/overlay.d.ts +7 -5
  56. package/dist/mdruntime/preparation.d.ts +19 -0
  57. package/dist/mdruntime/presence.d.ts +51 -0
  58. package/dist/mdruntime/query.d.ts +21 -207
  59. package/dist/mdruntime/reach.d.ts +20 -9
  60. package/dist/mdruntime/readiness.d.ts +14 -18
  61. package/dist/mdruntime/reads.d.ts +38 -0
  62. package/dist/mdruntime/recovery.d.ts +5 -2
  63. package/dist/mdruntime/refresh.d.ts +26 -0
  64. package/dist/mdruntime/replica.d.ts +50 -39
  65. package/dist/mdruntime/retried.d.ts +29 -0
  66. package/dist/mdruntime/room-draft.d.ts +28 -11
  67. package/dist/mdruntime/room-drafts.d.ts +23 -0
  68. package/dist/mdruntime/runtime.d.ts +33 -0
  69. package/dist/mdruntime/save.d.ts +43 -50
  70. package/dist/mdruntime/saves.d.ts +31 -0
  71. package/dist/mdruntime/search.d.ts +12 -95
  72. package/dist/mdruntime/seed.d.ts +11 -2
  73. package/dist/mdruntime/socket/admission.d.ts +6 -0
  74. package/dist/mdruntime/socket/answers.d.ts +5 -0
  75. package/dist/mdruntime/socket/lanes.d.ts +27 -0
  76. package/dist/mdruntime/socket/session.d.ts +37 -0
  77. package/dist/mdruntime/socket.d.ts +66 -0
  78. package/dist/mdruntime/source.d.ts +53 -0
  79. package/dist/mdruntime/status.d.ts +4 -5
  80. package/dist/mdruntime/store/installs.d.ts +29 -0
  81. package/dist/mdruntime/store/readiness.d.ts +9 -0
  82. package/dist/mdruntime/store/records.d.ts +214 -0
  83. package/dist/mdruntime/store/room-held.d.ts +7 -0
  84. package/dist/mdruntime/store/space.d.ts +10 -0
  85. package/dist/mdruntime/store/watchers.d.ts +16 -0
  86. package/dist/mdruntime/store/writes.d.ts +23 -0
  87. package/dist/mdruntime/store.d.ts +111 -166
  88. package/dist/mdruntime/stored.d.ts +156 -0
  89. package/dist/mdruntime/surface.d.ts +88 -0
  90. package/dist/mdruntime/tables.d.ts +414 -0
  91. package/dist/mdruntime/tallies.d.ts +17 -0
  92. package/dist/mdruntime/transfer.d.ts +0 -5
  93. package/dist/mdruntime/wire.d.ts +82 -9
  94. package/dist/session-content/bounds.d.ts +7 -0
  95. package/dist/session-content/check.d.ts +18 -0
  96. package/dist/session-content/index.d.ts +7 -0
  97. package/dist/session-content/parts.d.ts +103 -0
  98. package/dist/session-content/state.d.ts +61 -0
  99. package/dist/session-content/turn.d.ts +328 -0
  100. package/dist/test-host.d.ts +7 -4
  101. package/dist/test-host.js +18 -28
  102. package/docs/families.md +65 -57
  103. package/package.json +8 -3
  104. package/dist/calls.d.ts +0 -957
  105. package/dist/calls.js +0 -1
  106. package/dist/mdmodel/blocks.d.ts +0 -10
  107. package/dist/mdmodel/condition.d.ts +0 -147
  108. package/dist/mdmodel/profile.d.ts +0 -5
  109. package/dist/mdruntime/connection.d.ts +0 -146
  110. package/dist/mdruntime/file.d.ts +0 -19
  111. package/dist/mdruntime/rows.d.ts +0 -38
  112. package/dist/mdruntime/shared.d.ts +0 -14
  113. package/dist/mdruntime/turn.d.ts +0 -8
@@ -1,92 +1,7 @@
1
- import { type Definition } from '../mdmodel/index.js';
1
+ import { type HeldRooms, type QueryPlan } from '../mdmodel/index.js';
2
2
  import type { HeadChange } from './adapter.js';
3
3
  import type { BinaryFileRecord } from './binary.js';
4
4
  import type { Open } from './open.js';
5
- export type Value = string | number | boolean | null;
6
- export type Predicate = Value | {
7
- $eq: Value;
8
- } | {
9
- $ne: Value;
10
- } | {
11
- $in: readonly Value[];
12
- } | {
13
- $nin: readonly Value[];
14
- } | {
15
- $gt?: Value;
16
- $gte?: Value;
17
- $lt?: Value;
18
- $lte?: Value;
19
- } | {
20
- $all: readonly Value[];
21
- } | {
22
- $size: number;
23
- } | {
24
- $exists: boolean;
25
- };
26
- export type Where = {
27
- $and?: readonly Where[];
28
- $or?: readonly Where[];
29
- [field: string]: Predicate | readonly Where[] | undefined;
30
- };
31
- export type Related = {
32
- types?: readonly string[];
33
- where?: Where;
34
- pathPrefix?: string;
35
- };
36
- export type Filter = {
37
- rooms?: readonly string[];
38
- types?: readonly string[];
39
- where?: Where;
40
- pathPrefix?: string;
41
- folder?: string;
42
- paths?: readonly string[];
43
- hop?: Related & {
44
- field: string;
45
- };
46
- backlinks?: Related & {
47
- field?: string;
48
- };
49
- };
50
- export type Key = 'room' | 'path' | 'type' | 'folder' | {
51
- field: string;
52
- };
53
- export type Select = 'all' | {
54
- fields?: 'all' | readonly string[];
55
- sections?: 'all' | readonly string[];
56
- preamble?: true;
57
- markdown?: true;
58
- backlinks?: true;
59
- change?: true;
60
- fileId?: true;
61
- };
62
- export type OrderOptions = {
63
- nulls?: 'first' | 'last';
64
- stringSort?: 'lexical' | 'locale';
65
- locale?: string;
66
- localeOptions?: Readonly<Record<string, unknown>>;
67
- };
68
- export type Direction = 'asc' | 'desc';
69
- export type DocumentQuery = Filter & {
70
- select: Select;
71
- orderBy?: readonly ({
72
- by: Key;
73
- direction?: Direction;
74
- } & OrderOptions)[];
75
- limit?: number;
76
- after?: string;
77
- total?: true;
78
- };
79
- export type GroupQuery = Filter & {
80
- groupBy: readonly Exclude<Key, 'path'>[];
81
- orderBy?: readonly {
82
- by: 'count' | Exclude<Key, 'path'>;
83
- direction?: Direction;
84
- }[];
85
- limit?: number;
86
- after?: string;
87
- total?: true;
88
- };
89
- export type LocalQuery = DocumentQuery | GroupQuery;
90
5
  export type Backlink = {
91
6
  path: string;
92
7
  type: string;
@@ -103,11 +18,22 @@ export type QueryDocument = {
103
18
  backlinks?: readonly Backlink[];
104
19
  change?: HeadChange | null;
105
20
  fileId?: string | null;
21
+ revision?: string | null;
106
22
  binaryFile?: BinaryFileRecord;
23
+ size?: number | null;
24
+ created?: string | null;
25
+ };
26
+ export type GroupTotal = {
27
+ count: number;
28
+ size: number;
107
29
  };
108
30
  export type QueryGroup = {
109
31
  key: readonly unknown[];
110
32
  count: number;
33
+ documents?: GroupTotal;
34
+ files?: GroupTotal;
35
+ updated?: string | null;
36
+ greatest?: unknown;
111
37
  };
112
38
  export type CoveredRoom = {
113
39
  room: string;
@@ -116,10 +42,9 @@ export type CoveredRoom = {
116
42
  };
117
43
  export type QueryCoverage = {
118
44
  rooms: readonly CoveredRoom[];
119
- indexes: readonly string[];
120
45
  overlay: readonly string[];
121
46
  };
122
- export type Awaits = Open<'acquisition' | 'preparation' | 'index'>;
47
+ export type Awaits = Open<'acquisition' | 'preparation' | 'unlock'>;
123
48
  export type PendingRoom = {
124
49
  room: string;
125
50
  awaits: Awaits;
@@ -145,129 +70,18 @@ export type GroupResult = GroupRows & {
145
70
  coverage: QueryCoverage;
146
71
  };
147
72
  export type QueryResult = DocumentResult | GroupResult | PendingResult;
148
- export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
149
- export type RoomFacts = {
150
- locator: string;
151
- available: boolean;
152
- types: readonly Definition[];
153
- };
154
- export type HeldRooms = {
155
- listed: boolean;
156
- rooms: readonly RoomFacts[];
157
- };
158
- export type Test = {
159
- op: 'eq';
160
- value: Value;
161
- } | {
162
- op: 'ne';
163
- value: Value;
164
- } | {
165
- op: 'in';
166
- values: readonly Value[];
167
- } | {
168
- op: 'nin';
169
- values: readonly Value[];
170
- } | {
171
- op: 'range';
172
- bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
173
- } | {
174
- op: 'all';
175
- values: readonly Value[];
176
- } | {
177
- op: 'size';
178
- size: number;
179
- } | {
180
- op: 'exists';
181
- exists: boolean;
182
- };
183
- export type Condition = {
184
- every: readonly Condition[];
185
- } | {
186
- some: readonly Condition[];
187
- } | {
188
- field: string;
189
- test: Test;
190
- };
191
- export type Scope = {
192
- types: readonly string[] | null;
193
- where: Condition | null;
194
- pathPrefix: string | null;
195
- };
196
- export type KeyPlan = {
197
- of: 'room';
198
- } | {
199
- of: 'path';
200
- } | {
201
- of: 'type';
202
- } | {
203
- of: 'folder';
204
- } | {
205
- of: 'field';
206
- field: string;
207
- };
208
- export type DocumentShape = {
209
- kind: 'documents';
210
- fields: 'all' | readonly string[] | null;
211
- sections: 'all' | readonly string[] | null;
212
- preamble: boolean;
213
- markdown: boolean;
214
- backlinks: boolean;
215
- change: boolean;
216
- fileId: boolean;
217
- orderBy: readonly {
218
- key: KeyPlan;
219
- options: OrderOptions & {
220
- direction: Direction;
221
- };
222
- }[];
223
- };
224
- export type GroupShape = {
225
- kind: 'groups';
226
- groupBy: readonly KeyPlan[];
227
- orderBy: readonly {
228
- by: 'count' | number;
229
- direction: Direction;
230
- }[];
73
+ export type PlanArea = {
74
+ room: string;
75
+ path: string;
76
+ open: readonly string[];
231
77
  };
232
78
  export type PlanReach = {
233
79
  rooms: readonly string[];
234
80
  documents: readonly string[];
81
+ areas: readonly PlanArea[];
235
82
  };
236
- export type Continuation = {
237
- text: string;
238
- values: readonly unknown[] | null;
239
- };
240
- export type Plan = {
241
- key: string;
242
- rooms: readonly string[] | null;
83
+ export type Plan = QueryPlan & {
243
84
  reach: PlanReach | null;
244
- root: Scope;
245
- folder: string | null;
246
- paths: readonly string[] | null;
247
- hop: (Scope & {
248
- field: string;
249
- }) | null;
250
- backlinks: (Scope & {
251
- field: string | null;
252
- }) | null;
253
- shape: DocumentShape | GroupShape;
254
- limit: number | null;
255
- after: Continuation | null;
256
- total: boolean;
85
+ locked: readonly string[];
257
86
  };
258
- export declare class QueryError extends Error {
259
- readonly code: QueryErrorCode;
260
- readonly retryable = false;
261
- constructor(code: QueryErrorCode, at: string, problem: string);
262
- }
263
- type Entries = Readonly<Record<string, unknown>>;
264
- export declare function invalid(at: string, problem: string): never;
265
- export declare function plain(value: unknown): value is Entries;
266
- export declare function known(value: Entries, allowed: readonly string[], at: string): void;
267
- export declare function flag(input: unknown, at: string): boolean;
268
- export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
269
- export declare function limitOf(input: unknown): number | null;
270
- export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
271
- export declare function queryKey(query: unknown): string;
272
- export declare function identityOf(plan: Plan): string;
273
- export {};
87
+ export declare function planWithin(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
@@ -1,34 +1,45 @@
1
- import type { ReferrerScope } from './adapter.js';
2
- import type { MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
1
+ import type { AppRoom } from './listing.js';
2
+ import type { ReadinessPort } from './preparation.js';
3
+ import type { MdRuntime, RuntimeTopic } from './surface.js';
3
4
  import type { Plan, PlanReach, QueryResult } from './query.js';
4
5
  import type { Readiness } from './readiness.js';
5
- import { type SearchResult } from './search.js';
6
+ import type { SearchResult } from './search.js';
6
7
  export type ReachedDocument = {
7
8
  readonly room: string;
8
9
  readonly path: string;
9
10
  };
11
+ export type ReachedArea = {
12
+ readonly room: string;
13
+ readonly path: string;
14
+ readonly open: readonly string[];
15
+ };
10
16
  export type PortReach = {
11
17
  readonly rooms: readonly string[];
12
18
  readonly documents: readonly ReachedDocument[];
19
+ readonly areas?: readonly ReachedArea[];
13
20
  readonly conversations: boolean;
14
21
  };
15
22
  export type Deliver = (message: unknown) => void;
16
- export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
23
+ export type Fail = (error: unknown) => void;
24
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
17
25
  export type RuntimeView = {
18
26
  md: MdRuntime;
19
27
  watch: Watch;
20
28
  };
21
29
  export type NarrowedView = RuntimeView & {
22
30
  narrow(reach: PortReach | null): void;
23
- facts(port: ReadinessPort): void;
24
31
  };
25
32
  export type Reachable = RuntimeView & {
26
- plan(input: unknown, reach: PortReach | null): Plan;
33
+ plan(input: unknown, reach: PortReach | null): Promise<Plan>;
27
34
  query(plan: Plan): Promise<QueryResult>;
28
- watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
35
+ watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
29
36
  search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
30
37
  watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
31
- referrerScope(referrer: unknown): ReferrerScope | null;
38
+ locked(room: string): Promise<boolean>;
39
+ lockedRooms(): Promise<readonly string[]>;
40
+ watchLocks(notify: () => void): () => void;
41
+ located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
42
+ room(locator: string): Promise<AppRoom | undefined>;
32
43
  };
33
44
  export declare function holds(reach: PortReach | null, room: string): boolean;
34
45
  export declare function governs(reach: PortReach | null, room: {
@@ -41,4 +52,4 @@ export declare function governs(reach: PortReach | null, room: {
41
52
  readonly selection: boolean;
42
53
  };
43
54
  export declare function planReach(reach: PortReach | null): PlanReach | null;
44
- export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
55
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
@@ -1,35 +1,32 @@
1
1
  import type { Open } from './open.js';
2
2
  export type CodeAvailability = Open<'stored' | 'absent'>;
3
- export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'indexing' | 'refused' | 'unadmitted'>;
3
+ export type RoomPreparation = Open<'complete' | 'acquiring' | 'preparing' | 'unadmitted'>;
4
4
  export type RoomCoverage = {
5
5
  readonly room: string;
6
6
  readonly state: RoomPreparation;
7
7
  };
8
- export type ConversationCoverage = Open<'complete' | 'acquiring' | 'indexing' | 'undeclared'>;
9
- export type SearchObligation = Open<'required' | 'unused'>;
8
+ export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
10
9
  export type TargetCoverage = {
11
10
  readonly complete: boolean;
12
11
  readonly listed: boolean;
13
12
  readonly rooms: readonly RoomCoverage[];
14
13
  readonly conversations: ConversationCoverage;
15
- readonly search: SearchObligation;
16
14
  };
17
- export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
15
+ export type Persistence = Open<'granted' | 'denied' | 'unavailable' | 'memory'>;
18
16
  export type Durability = Open<'persistent' | 'best-effort'>;
19
17
  export type ConnectionAvailability = Open<'connected' | 'connecting' | 'unreachable'>;
20
18
  export type HouseOutcome = Open<'open' | 'write-halted' | 'refused'>;
21
- export type CapacityCause = {
22
- readonly cause: Open<'insufficient-space' | 'quota-exceeded'>;
23
- readonly needed: number | null;
24
- readonly available: number | null;
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;
25
24
  };
26
- export type RefusedRoom = {
27
- readonly room: string;
28
- readonly file: string;
29
- readonly rule: string;
30
- readonly location: string | null;
25
+ export type Installation = {
26
+ readonly step: InstallationStep | null;
27
+ readonly bytes: InstallationAmount;
31
28
  };
32
- export type ReadinessStatus = Open<'preparing' | 'paused' | 'refused' | 'ready' | 'lost'>;
29
+ export type ReadinessStatus = Open<'preparing' | 'paused' | 'ready' | 'lost'>;
33
30
  export type Readiness = {
34
31
  readonly status: ReadinessStatus;
35
32
  readonly ready: boolean;
@@ -40,13 +37,12 @@ export type Readiness = {
40
37
  readonly persistence: Persistence;
41
38
  readonly connection: ConnectionAvailability;
42
39
  readonly house: HouseOutcome;
43
- readonly capacity: CapacityCause | null;
44
- readonly refused: readonly RefusedRoom[];
40
+ readonly space: Space | null;
41
+ readonly installation: Installation;
45
42
  readonly lost: boolean;
46
43
  };
47
44
  export type ReadinessFacts = Omit<Readiness, 'status' | 'ready' | 'usable' | 'durability' | 'coverage'> & {
48
45
  readonly coverage: Omit<TargetCoverage, 'complete'>;
49
46
  readonly established: boolean;
50
47
  };
51
- export declare const SETTLED_ROOMS: ReadonlySet<string>;
52
48
  export declare function readinessOf(facts: ReadinessFacts): Readiness;
@@ -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(): 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;
@@ -8,7 +8,7 @@ export type AttemptOptions = {
8
8
  };
9
9
  export type RecoveryOptions = {
10
10
  readonly firstMs?: number;
11
- readonly ceilingMs?: number;
11
+ readonly maxMs?: number;
12
12
  readonly attempts?: number;
13
13
  readonly inFlight?: number;
14
14
  };
@@ -16,9 +16,12 @@ export type Recovery = {
16
16
  attempt(intent: string, run: Attempt, options?: AttemptOptions): Promise<boolean>;
17
17
  pending(intent: string): boolean;
18
18
  resume(): void;
19
+ again(): void;
20
+ waits(wake: () => void): () => void;
19
21
  cancel(intent: string): void;
20
22
  scope(inFlight?: number): Recovery;
21
23
  retire(): Promise<void>;
22
24
  };
23
- export declare function retryDelay(tries: number, firstMs?: number, ceilingMs?: number): number;
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>;
24
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 {};
@@ -1,51 +1,62 @@
1
- import { type ChangeBatch } from './change.js';
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';
2
4
  import { type Collection, type Composition } from './collection.js';
5
+ import { type ModelState } from './model.js';
3
6
  import { type Layer } from './overlay.js';
4
- import type { MutationResult } from './adapter.js';
5
- import type { ReplicaRecord } from './store.js';
6
- import type { Refused } from './transfer.js';
7
- import { type Later } from './turn.js';
8
- export type ConfirmedLayer = {
9
- record: ReplicaRecord;
10
- collection: Collection;
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>;
11
21
  };
12
22
  export type VisibleLayer = Layer & {
13
- collection: Collection;
23
+ readonly collection: Collection;
14
24
  };
15
- export type Staged = {
16
- kind: 'staged';
17
- confirmed: ConfirmedLayer;
18
- } | Refused;
19
- export type Replica = {
20
- confirmed: ConfirmedLayer;
21
- queue: readonly ChangeBatch[];
22
- visible: VisibleLayer;
23
- replay: readonly ReplayStep[];
25
+ export type Slice = Layer & {
26
+ readonly written: Readonly<Record<string, string>>;
27
+ readonly facts: Readonly<Record<string, SavedFacts>>;
28
+ readonly held: ReadonlySet<string>;
24
29
  };
25
- type ReplayStep = {
26
- id: string;
27
- before: Layer;
28
- after: Layer;
29
- effective: ChangeBatch;
30
- collection?: Collection;
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>;
31
43
  };
32
- export declare function compositionOf(record: ReplicaRecord): Composition;
33
- export declare function confirmedOf(record: ReplicaRecord, previous?: ConfirmedLayer): ConfirmedLayer;
34
- export declare function sameMembership(record: ReplicaRecord, other: ReplicaRecord): boolean;
35
- export declare function readStaged(staged: ReplicaRecord, previous?: ConfirmedLayer): Later<Staged>;
36
- export declare function readReclassified(record: ReplicaRecord, previous: ConfirmedLayer): Later<Staged | {
37
- kind: 'deferred';
38
- }>;
39
- type Accepted = Extract<MutationResult, {
40
- kind: 'accepted';
41
- }>;
42
- export declare function applyReturned(confirmed: ConfirmedLayer, submitted: ChangeBatch, accepted: Accepted, roomVersion: string, writtenAt: string): Later<Staged>;
43
- export declare function replicating(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], previous?: Replica): Generator<number, Replica, void>;
44
- export declare function replicaOf(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], previous?: Replica): Replica;
45
- export declare function landed(batch: ChangeBatch, confirmed: ConfirmedLayer, current?: Readonly<Record<string, string>>): boolean;
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;
46
48
  export type Standing = {
47
49
  readonly withdrawn: readonly ChangeBatch[];
48
50
  readonly kept: readonly ChangeBatch[];
49
51
  };
50
- export declare function standing(confirmed: ConfirmedLayer, queue: readonly ChangeBatch[], withdrawable: (batch: ChangeBatch) => boolean, local: boolean): Generator<number, Standing, void>;
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>;
51
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>;