@agentshouse/app-bridge 0.1.0-cd2d3edbf9805 → 0.1.0-cd2df7704a056

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 (43) hide show
  1. package/README.md +6 -6
  2. package/dist/index.d.ts +826 -2
  3. package/dist/mdmodel/definition.d.ts +1 -1
  4. package/dist/mdmodel/event.d.ts +77 -0
  5. package/dist/mdmodel/facts.d.ts +14 -0
  6. package/dist/mdmodel/index.d.ts +17 -5
  7. package/dist/mdmodel/kinds.d.ts +18 -0
  8. package/dist/mdmodel/query/language.d.ts +222 -0
  9. package/dist/mdmodel/query/match.d.ts +13 -0
  10. package/dist/mdmodel/query/rows.d.ts +31 -0
  11. package/dist/mdmodel/query/sql.d.ts +38 -0
  12. package/dist/mdmodel/reserved.d.ts +4 -0
  13. package/dist/mdmodel/types.d.ts +7 -0
  14. package/dist/mdmodel/validate.d.ts +4 -3
  15. package/dist/mdruntime/adapter.d.ts +39 -10
  16. package/dist/mdruntime/chain.d.ts +2 -1
  17. package/dist/mdruntime/client.d.ts +9 -5
  18. package/dist/mdruntime/collection.d.ts +2 -1
  19. package/dist/mdruntime/compile.d.ts +1 -6
  20. package/dist/mdruntime/connection.d.ts +8 -6
  21. package/dist/mdruntime/conversation.d.ts +14 -8
  22. package/dist/mdruntime/durability.d.ts +6 -0
  23. package/dist/mdruntime/identity.d.ts +0 -1
  24. package/dist/mdruntime/messages.d.ts +2 -2
  25. package/dist/mdruntime/model.d.ts +2 -7
  26. package/dist/mdruntime/observation.d.ts +2 -2
  27. package/dist/mdruntime/query.d.ts +3 -208
  28. package/dist/mdruntime/reach.d.ts +6 -6
  29. package/dist/mdruntime/readiness.d.ts +0 -2
  30. package/dist/mdruntime/replica.d.ts +8 -5
  31. package/dist/mdruntime/room-draft.d.ts +4 -3
  32. package/dist/mdruntime/search.d.ts +12 -63
  33. package/dist/mdruntime/store.d.ts +5 -7
  34. package/dist/mdruntime/stored.d.ts +3 -4
  35. package/dist/mdruntime/tables.d.ts +8 -6
  36. package/dist/mdruntime/wire.d.ts +9 -4
  37. package/dist/test-host.js +1 -0
  38. package/docs/families.md +15 -2
  39. package/package.json +1 -1
  40. package/dist/calls.d.ts +0 -747
  41. package/dist/calls.js +0 -1
  42. package/dist/mdmodel/condition.d.ts +0 -167
  43. package/dist/mdruntime/fulltext.d.ts +0 -26
@@ -1,9 +1,11 @@
1
+ import type { DocumentQuery, GroupQuery } from '../mdmodel/index.js';
1
2
  import type { AppRoom, ConnectionRefusal, HistoryQuery, RoomSchemas, SavedParts, SavedRoomDraft, SaveResult } from './connection.js';
2
3
  import type { Member, ServiceMode } from './adapter.js';
3
- import type { ChatDraft, ConversationAgent, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
4
+ import type { UnsentWork } from './durability.js';
5
+ import type { ChatDraft, ConversationAgent, ConversationAnswer, ConversationEntry, ConversationOptions, ConversationRead, ConversationView } from './conversation.js';
4
6
  import { type Observation } from './observation.js';
5
7
  import type { AttachAnswer, BinaryAnswer, CallResult, DownloadAnswer, HistoryAnswer, Offline, QueueEntry, Resolution } from './outcome.js';
6
- import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
8
+ import type { DocumentResult, GroupResult, PendingResult } from './query.js';
7
9
  import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
8
10
  import type { SearchRequest, SearchResult } from './search.js';
9
11
  import type { Readiness } from './readiness.js';
@@ -32,13 +34,12 @@ export type MdRuntimeClient = {
32
34
  };
33
35
  conversation: {
34
36
  list(): Promise<readonly ConversationEntry[]>;
35
- read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
37
+ read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
36
38
  create(input: unknown): Promise<CallResult>;
37
39
  send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
38
- answer(conversation: string, answer: unknown): Promise<CallResult>;
40
+ answer(conversation: string, answer: ConversationAnswer): Promise<CallResult>;
39
41
  interrupt(conversation: string): Promise<CallResult>;
40
42
  kill(conversation: string): Promise<CallResult>;
41
- cancel(conversation: string, turn: string): Promise<CallResult>;
42
43
  delete(conversation: string): Promise<CallResult>;
43
44
  };
44
45
  chatDraft: {
@@ -59,6 +60,8 @@ export type MdRuntimeClient = {
59
60
  persistence(): Promise<boolean>;
60
61
  retry(): Promise<void>;
61
62
  cleanUp(): Promise<number>;
63
+ unsent(): Promise<readonly UnsentWork[]>;
64
+ reset(): Promise<void>;
62
65
  observe: {
63
66
  (topic: 'deployment-facts'): Promise<Observation<unknown>>;
64
67
  (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
@@ -68,6 +71,7 @@ export type MdRuntimeClient = {
68
71
  (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
69
72
  (topic: 'service-mode'): Promise<Observation<ServiceMode>>;
70
73
  (topic: 'member'): Promise<Observation<Member | null>>;
74
+ (topic: 'authority-changes'): Promise<Observation<number>>;
71
75
  (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
72
76
  (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
73
77
  (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
@@ -1,4 +1,4 @@
1
- import { type Document } from '../mdmodel/index.js';
1
+ import { type Document, type TypedPath } from '../mdmodel/index.js';
2
2
  import type { ModelState } from './model.js';
3
3
  import type { MdModelIdentity } from './adapter.js';
4
4
  export declare const MD_MODEL: MdModelIdentity;
@@ -13,6 +13,7 @@ export type Composition = {
13
13
  roots: readonly string[];
14
14
  model: ModelState;
15
15
  } | null;
16
+ typedPaths: readonly TypedPath[];
16
17
  };
17
18
  export type Composed = {
18
19
  readonly composition: Composition;
@@ -1,15 +1,10 @@
1
1
  import type { Plan, QueryRows } from './query.js';
2
- import type { Connection, Value } from './tables.js';
2
+ import type { Connection } from './tables.js';
3
3
  export type QueryRoom = {
4
4
  readonly locator: string;
5
5
  readonly key: number;
6
6
  };
7
- export type Fragment = {
8
- readonly sql: string;
9
- readonly bind: readonly Value[];
10
- };
11
7
  export type QueryAnswer = QueryRows & {
12
8
  readonly more?: string;
13
9
  };
14
- export declare function selected(connection: Connection, plan: Plan, rooms: readonly QueryRoom[]): Fragment;
15
10
  export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
@@ -1,6 +1,7 @@
1
+ import { type DocumentQuery, type GroupQuery } from '../mdmodel/index.js';
1
2
  import { type TypesResult } from './model.js';
2
3
  import { type Observation } from './observation.js';
3
- import { type DocumentQuery, type DocumentResult, type GroupQuery, type GroupResult, type PendingResult } from './query.js';
4
+ import { type DocumentResult, type GroupResult, type PendingResult } from './query.js';
4
5
  import { type EntrySeed } from './seed.js';
5
6
  import { type SearchRequest, type SearchResult } from './search.js';
6
7
  import { type Adapter, type Authorization, type Member, type ProviderRefusal, type ServiceMode } from './adapter.js';
@@ -12,8 +13,8 @@ import { type Recovery } from './recovery.js';
12
13
  import { type SaveRefusal } from './save.js';
13
14
  import { type RoomDraft, type RoomDraftParts, type RoomDraftWrite } from './room-draft.js';
14
15
  import { type SyncStatus } from './status.js';
15
- import { type RuntimeShell } from './durability.js';
16
- import { type CodeAvailability, type Persistence, type Readiness, type SearchObligation, type Space } from './readiness.js';
16
+ import { type RuntimeShell, type UnsentWork } from './durability.js';
17
+ import { type CodeAvailability, type Persistence, type Readiness } from './readiness.js';
17
18
  import type { RuntimeDatabase } from './tables.js';
18
19
  import { type NarrowedView, type PortReach, type RuntimeView } from './reach.js';
19
20
  export type AppTypedSelection = {
@@ -116,6 +117,8 @@ export type MdRuntime = {
116
117
  persistence(): boolean;
117
118
  retry(): Promise<void>;
118
119
  cleanUp(): Promise<number>;
120
+ unsent(): Promise<readonly UnsentWork[]>;
121
+ reset(): Promise<void>;
119
122
  observe: {
120
123
  (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
121
124
  (topic: 'readiness'): Promise<Observation<Readiness>>;
@@ -124,6 +127,7 @@ export type MdRuntime = {
124
127
  (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
125
128
  (topic: 'service-mode'): Promise<Observation<ServiceMode>>;
126
129
  (topic: 'member'): Promise<Observation<Member | null>>;
130
+ (topic: 'authority-changes'): Promise<Observation<number>>;
127
131
  (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
128
132
  (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
129
133
  (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
@@ -135,12 +139,10 @@ export type MdRuntime = {
135
139
  };
136
140
  reauthorize(): Promise<void>;
137
141
  };
138
- export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
142
+ export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'authority-changes' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
139
143
  export type ReadinessPort = {
140
144
  readonly target: string;
141
145
  readonly code: CodeAvailability;
142
- readonly space: Space | null;
143
- readonly search: SearchObligation;
144
146
  };
145
147
  export type ComposedRuntime = RuntimeView & {
146
148
  seed(entry: EntrySeed): void;
@@ -1,4 +1,4 @@
1
- import type { ConversationAction, ConversationEvent, ConversationMessage, ConversationStream, ListedConversation, ProcessCommand, SessionOption, TurnContext } from './adapter.js';
1
+ import type { ConversationAction, ConversationEvent, ConversationHistoryRequest, ConversationMessage, ConversationStream, ListedConversation, ProcessCommand, RunningSubagent, SessionOption, TurnContext } from './adapter.js';
2
2
  import { type ChangeSet } from './change-set.js';
3
3
  import type { Open } from './open.js';
4
4
  import { type CallResult, type Offline } from './outcome.js';
@@ -37,6 +37,9 @@ export type ConversationOptions = {
37
37
  after?: string;
38
38
  total?: true;
39
39
  };
40
+ export type ConversationRead = ConversationOptions & {
41
+ text?: string;
42
+ };
40
43
  export type ConversationView = {
41
44
  conversation: string;
42
45
  messages: readonly ConversationMessage[];
@@ -47,9 +50,11 @@ export type ConversationView = {
47
50
  process: {
48
51
  running: boolean;
49
52
  } | null;
53
+ processEnded: string | null;
50
54
  commands: readonly ProcessCommand[];
51
55
  options: readonly SessionOption[];
52
56
  starting: string | null;
57
+ subagents: readonly RunningSubagent[];
53
58
  link: {
54
59
  connected: boolean;
55
60
  } | null;
@@ -60,15 +65,18 @@ export type ConversationView = {
60
65
  };
61
66
  export type ConversationSurface = {
62
67
  list(): Promise<readonly ConversationEntry[]>;
63
- read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
68
+ read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
64
69
  create(input: unknown): Promise<CallResult>;
65
70
  send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
66
- answer(conversation: string, answer: unknown): Promise<CallResult>;
71
+ answer(conversation: string, answer: ConversationAnswer): Promise<CallResult>;
67
72
  interrupt(conversation: string): Promise<CallResult>;
68
73
  kill(conversation: string): Promise<CallResult>;
69
- cancel(conversation: string, turn: string): Promise<CallResult>;
70
74
  delete(conversation: string): Promise<CallResult>;
71
75
  };
76
+ export type ConversationAnswer = {
77
+ interaction_id: string;
78
+ response: unknown;
79
+ };
72
80
  export type ChatDraftSurface = {
73
81
  write(conversation: string, draft: ChatDraft, revision?: string): Promise<void>;
74
82
  prepend(conversation: string, draft: ChatDraft): Promise<void>;
@@ -76,6 +84,7 @@ export type ChatDraftSurface = {
76
84
  };
77
85
  export type ConversationDependencies = {
78
86
  call(name: ConversationAction, input: unknown): Promise<CallResult>;
87
+ history(request: ConversationHistoryRequest): Promise<CallResult>;
79
88
  durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
80
89
  stream(): ConversationStream | undefined;
81
90
  publish(set: ChangeSet): void;
@@ -83,12 +92,11 @@ export type ConversationDependencies = {
83
92
  full(): boolean;
84
93
  closed(): boolean;
85
94
  unanswered(): void;
86
- expired(operation: string): boolean;
87
95
  };
88
96
  export type ConversationStore = {
89
97
  surface: ConversationSurface;
90
98
  chatDraft: ChatDraftSurface;
91
- hydrate(held: readonly HeldConversation[], drafts: readonly ChatDraftRecord[], list: readonly ListedConversation[] | null): void;
99
+ hydrate(held: readonly HeldConversation[], drafts: readonly ChatDraftRecord[], list: readonly ListedConversation[] | null, cursor: string | null): void;
92
100
  reconcile(): Promise<void>;
93
101
  catchUp(progress: CycleProgress): Promise<void>;
94
102
  resend(progress: CycleProgress): Promise<void>;
@@ -102,8 +110,6 @@ export type ConversationStore = {
102
110
  watchAgents(deliver: (agents: readonly ConversationAgent[]) => void): () => void;
103
111
  changed(set: ChangeSet): void;
104
112
  receive(event: ConversationEvent): boolean;
105
- searchable(): readonly string[];
106
- acquired(conversation: string): boolean;
107
113
  close(): void;
108
114
  };
109
115
  export declare function unheldView(conversation: string): ConversationView;
@@ -1,10 +1,16 @@
1
1
  import type { Persistence } from './readiness.js';
2
+ export type UnsentKind = 'pending-change' | 'call' | 'room-draft' | 'chat-draft';
3
+ export type UnsentWork = {
4
+ readonly kind: UnsentKind;
5
+ readonly count: number;
6
+ };
2
7
  export type RuntimeShell = {
3
8
  persistence: Persistence;
4
9
  generation: string | null;
5
10
  keepGeneration(value: string): void | Promise<void>;
6
11
  dropGeneration(): void | Promise<void>;
7
12
  cleanUp?(): Promise<number>;
13
+ reset(): Promise<void>;
8
14
  };
9
15
  export declare function refusedForSpace(error: unknown): boolean;
10
16
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
@@ -1,5 +1,4 @@
1
1
  export declare function changeBatchIdentity(at?: number): string;
2
- export declare function identityTime(identity: string): number;
3
2
  export declare function roomDraftRevision(): string;
4
3
  export declare function chatDraftRevision(): string;
5
4
  export declare function transferIdentity(): string;
@@ -20,8 +20,8 @@ export type ConversationWrite = {
20
20
  };
21
21
  export declare function heldConversations(connection: Connection): HeldConversation[];
22
22
  export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
23
- export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null): MessageWindow;
24
- export declare function messageCount(connection: Connection, conversation: string): number;
23
+ export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
24
+ export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
25
25
  export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
26
26
  export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
27
27
  export declare function forgottenMessages(connection: Connection): void;
@@ -1,4 +1,4 @@
1
- import type { Definition, ValueFacts, VerifiedModel } from '../mdmodel/index.js';
1
+ import type { Definition, VerifiedModel } from '../mdmodel/index.js';
2
2
  import type { Open } from './open.js';
3
3
  export type ModelIdentity = {
4
4
  identity: string;
@@ -8,7 +8,7 @@ export type ModelSnapshot = ModelIdentity & {
8
8
  schema: string | null;
9
9
  revision: string | null;
10
10
  };
11
- export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired' | 'invalid'>;
11
+ export type ModelUnavailableReason = Open<'not-readable' | 'revoked' | 'not-acquired'>;
12
12
  export type ModelResult = {
13
13
  kind: 'model';
14
14
  snapshot: ModelSnapshot;
@@ -20,8 +20,6 @@ export type MdType = Definition;
20
20
  export type ModelState = {
21
21
  status: 'unavailable';
22
22
  reason: ModelUnavailableReason;
23
- schema?: string | null;
24
- revision?: string | null;
25
23
  } | {
26
24
  status: 'current' | 'cached';
27
25
  snapshot: ModelSnapshot;
@@ -37,8 +35,6 @@ export type TypesResult = {
37
35
  status: Open<'unavailable'>;
38
36
  reason: ModelUnavailableReason;
39
37
  types: null;
40
- schema?: string | null;
41
- revision?: string | null;
42
38
  } | {
43
39
  status: Open<'current' | 'cached'>;
44
40
  identity: string;
@@ -59,4 +55,3 @@ export declare function modelTypes(state: ModelState): TypesResult;
59
55
  export declare function storedModel(state: ModelState): StoredModel;
60
56
  export declare function cached(state: ModelState): ModelState;
61
57
  export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
62
- export declare function referenceField(facts: ValueFacts | undefined): boolean;
@@ -27,8 +27,8 @@ export declare function rowsOf(result: QueryResult): readonly (QueryDocument | Q
27
27
  export declare function whole(message: QueryMessage): message is KeyedResult;
28
28
  export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
29
29
  export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
30
- export declare function opened(watch: (deliver: (message: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
31
- export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
30
+ export declare function opened(watch: (deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
31
+ export declare function observing<Topic extends string>(watch: (topic: Topic, input: readonly unknown[], deliver: (message: unknown) => void, fail: (error: unknown) => void) => () => void): (topic: Topic, ...input: unknown[]) => Promise<Observation<unknown>>;
32
32
  export type Digest = {
33
33
  readonly pending: string;
34
34
  } | {
@@ -1,93 +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
- revision?: true;
62
- };
63
- export type OrderOptions = {
64
- nulls?: 'first' | 'last';
65
- stringSort?: 'lexical' | 'locale';
66
- locale?: string;
67
- localeOptions?: Readonly<Record<string, unknown>>;
68
- };
69
- export type Direction = 'asc' | 'desc';
70
- export type DocumentQuery = Filter & {
71
- select: Select;
72
- orderBy?: readonly ({
73
- by: Key;
74
- direction?: Direction;
75
- } & OrderOptions)[];
76
- limit?: number;
77
- after?: string;
78
- total?: true;
79
- };
80
- export type GroupQuery = Filter & {
81
- groupBy: readonly Exclude<Key, 'path'>[];
82
- orderBy?: readonly {
83
- by: 'count' | Exclude<Key, 'path'>;
84
- direction?: Direction;
85
- }[];
86
- limit?: number;
87
- after?: string;
88
- total?: true;
89
- };
90
- export type LocalQuery = DocumentQuery | GroupQuery;
91
5
  export type Backlink = {
92
6
  path: string;
93
7
  type: string;
@@ -147,91 +61,6 @@ export type GroupResult = GroupRows & {
147
61
  coverage: QueryCoverage;
148
62
  };
149
63
  export type QueryResult = DocumentResult | GroupResult | PendingResult;
150
- export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
151
- export type RoomFacts = {
152
- locator: string;
153
- available: boolean;
154
- types: readonly Definition[];
155
- };
156
- export type HeldRooms = {
157
- listed: boolean;
158
- rooms: readonly RoomFacts[];
159
- };
160
- export type Test = {
161
- op: 'eq';
162
- value: Value;
163
- } | {
164
- op: 'ne';
165
- value: Value;
166
- } | {
167
- op: 'in';
168
- values: readonly Value[];
169
- } | {
170
- op: 'nin';
171
- values: readonly Value[];
172
- } | {
173
- op: 'range';
174
- bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
175
- } | {
176
- op: 'all';
177
- values: readonly Value[];
178
- } | {
179
- op: 'size';
180
- size: number;
181
- } | {
182
- op: 'exists';
183
- exists: boolean;
184
- };
185
- export type Condition = {
186
- every: readonly Condition[];
187
- } | {
188
- some: readonly Condition[];
189
- } | {
190
- field: string;
191
- test: Test;
192
- };
193
- export type Scope = {
194
- types: readonly string[] | null;
195
- where: Condition | null;
196
- pathPrefix: string | null;
197
- };
198
- export type KeyPlan = {
199
- of: 'room';
200
- } | {
201
- of: 'path';
202
- } | {
203
- of: 'type';
204
- } | {
205
- of: 'folder';
206
- } | {
207
- of: 'field';
208
- field: string;
209
- };
210
- export type DocumentShape = {
211
- kind: 'documents';
212
- fields: 'all' | readonly string[] | null;
213
- sections: 'all' | readonly string[] | null;
214
- preamble: boolean;
215
- markdown: boolean;
216
- backlinks: boolean;
217
- change: boolean;
218
- fileId: boolean;
219
- revision: boolean;
220
- orderBy: readonly {
221
- key: KeyPlan;
222
- options: OrderOptions & {
223
- direction: Direction;
224
- };
225
- }[];
226
- };
227
- export type GroupShape = {
228
- kind: 'groups';
229
- groupBy: readonly KeyPlan[];
230
- orderBy: readonly {
231
- by: 'count' | number;
232
- direction: Direction;
233
- }[];
234
- };
235
64
  export type PlanArea = {
236
65
  room: string;
237
66
  path: string;
@@ -242,42 +71,8 @@ export type PlanReach = {
242
71
  documents: readonly string[];
243
72
  areas: readonly PlanArea[];
244
73
  };
245
- export type Continuation = {
246
- text: string;
247
- values: readonly unknown[] | null;
248
- };
249
- export type Plan = {
250
- key: string;
251
- rooms: readonly string[] | null;
74
+ export type Plan = QueryPlan & {
252
75
  reach: PlanReach | null;
253
76
  locked: readonly string[];
254
- root: Scope;
255
- folder: string | null;
256
- paths: readonly string[] | null;
257
- hop: (Scope & {
258
- field: string;
259
- }) | null;
260
- backlinks: (Scope & {
261
- field: string | null;
262
- }) | null;
263
- shape: DocumentShape | GroupShape;
264
- limit: number | null;
265
- after: Continuation | null;
266
- total: boolean;
267
77
  };
268
- export declare class QueryError extends Error {
269
- readonly code: QueryErrorCode;
270
- readonly retryable = false;
271
- constructor(code: QueryErrorCode, at: string, problem: string);
272
- }
273
- type Entries = Readonly<Record<string, unknown>>;
274
- export declare function invalid(at: string, problem: string): never;
275
- export declare function plain(value: unknown): value is Entries;
276
- export declare function known(value: Entries, allowed: readonly string[], at: string): void;
277
- export declare function flag(input: unknown, at: string): boolean;
278
- export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
279
- export declare function limitOf(input: unknown): number | null;
280
- export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
281
- export declare function queryKey(query: unknown): string;
282
- export declare function identityOf(plan: Plan): string;
283
- export {};
78
+ export declare function planWithin(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
@@ -1,7 +1,7 @@
1
1
  import type { AppRoom, MdRuntime, ReadinessPort, RuntimeTopic } from './connection.js';
2
2
  import type { Plan, PlanReach, QueryResult } from './query.js';
3
3
  import type { Readiness } from './readiness.js';
4
- import { type SearchResult } from './search.js';
4
+ import type { SearchResult } from './search.js';
5
5
  export type ReachedDocument = {
6
6
  readonly room: string;
7
7
  readonly path: string;
@@ -18,20 +18,20 @@ export type PortReach = {
18
18
  readonly conversations: boolean;
19
19
  };
20
20
  export type Deliver = (message: unknown) => void;
21
- export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver) => () => void;
21
+ export type Fail = (error: unknown) => void;
22
+ export type Watch = (topic: RuntimeTopic, input: readonly unknown[], deliver: Deliver, fail: Fail) => () => void;
22
23
  export type RuntimeView = {
23
24
  md: MdRuntime;
24
25
  watch: Watch;
25
26
  };
26
27
  export type NarrowedView = RuntimeView & {
27
28
  narrow(reach: PortReach | null): void;
28
- facts(port: ReadinessPort): void;
29
29
  };
30
30
  export type Reachable = RuntimeView & {
31
31
  plan(input: unknown, reach: PortReach | null): Plan;
32
32
  query(plan: Plan): Promise<QueryResult>;
33
- watchPlan(plan: Plan, deliver: (message: unknown) => void): () => void;
34
- search(input: unknown, reach: PortReach | null, locked: readonly string[]): Promise<SearchResult>;
33
+ watchPlan(plan: Plan, deliver: Deliver, fail: Fail): () => void;
34
+ search(input: unknown, reach: PortReach | null): Promise<SearchResult>;
35
35
  watchReadiness(port: ReadinessPort, reach: PortReach | null, deliver: (readiness: Readiness) => void): () => void;
36
36
  locked(room: string): boolean;
37
37
  lockedRooms(): readonly string[];
@@ -50,4 +50,4 @@ export declare function governs(reach: PortReach | null, room: {
50
50
  readonly selection: boolean;
51
51
  };
52
52
  export declare function planReach(reach: PortReach | null): PlanReach | null;
53
- export declare function narrowed(runtime: Reachable, given: PortReach | null, told: ReadinessPort): NarrowedView;
53
+ export declare function narrowed(runtime: Reachable, given: PortReach | null, port: ReadinessPort): NarrowedView;
@@ -6,13 +6,11 @@ export type RoomCoverage = {
6
6
  readonly state: RoomPreparation;
7
7
  };
8
8
  export type ConversationCoverage = Open<'complete' | 'acquiring' | 'undeclared'>;
9
- export type SearchObligation = Open<'required' | 'unused'>;
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
15
  export type Persistence = Open<'granted' | 'denied' | 'unavailable'>;
18
16
  export type Durability = Open<'persistent' | 'best-effort'>;
@@ -1,4 +1,5 @@
1
- import type { BootstrapInventory, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
1
+ import { type TypedPath } from '../mdmodel/index.js';
2
+ import type { BootstrapInventory, SavedFacts, MutationResult, OperationScopes, ReplicaAdmission, TypedSelection } from './adapter.js';
2
3
  import { type ChangeBatch, type Precondition } from './change.js';
3
4
  import { type Collection, type Composition } from './collection.js';
4
5
  import { type ModelState } from './model.js';
@@ -31,14 +32,16 @@ export type VisibleLayer = Layer & {
31
32
  };
32
33
  export type Slice = Layer & {
33
34
  readonly written: Readonly<Record<string, string>>;
35
+ readonly facts: Readonly<Record<string, SavedFacts>>;
34
36
  readonly held: ReadonlySet<string>;
35
37
  };
36
- export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState): Composition;
38
+ export declare function compositionOf(record: Pick<ReplicaRecord, 'model' | 'typedSelection'>, builtIn: ModelState, typedPaths: readonly TypedPath[]): Composition;
37
39
  export declare function storedRecord(record: ReplicaRecord): string;
38
40
  export declare function slicing(entries: readonly HeldEntry[], paths: Iterable<string>): Generator<number, Slice, void>;
41
+ export type LayerEntry = Omit<StoredEntry, 'facts'>;
39
42
  export declare function entryAt(layer: Layer & {
40
43
  readonly written?: Readonly<Record<string, string>>;
41
- }, path: string): StoredEntry | null;
44
+ }, path: string): LayerEntry | null;
42
45
  export declare function slicingWith(slice: Slice, set: readonly StoredEntry[], removed: readonly string[]): Generator<number, Slice, void>;
43
46
  export declare function touchedBy(queue: readonly ChangeBatch[]): Set<string>;
44
47
  export declare function movedBy(queue: readonly ChangeBatch[], locator: string): Set<string>;
@@ -47,7 +50,7 @@ export type Replayed = {
47
50
  readonly touched: ReadonlySet<string>;
48
51
  };
49
52
  export declare function replaying(confirmed: Slice, queue: readonly ChangeBatch[], locator: string, composition: Composition): Generator<number, Replayed, void>;
50
- export declare function overlayOf(visible: Layer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
53
+ export declare function overlayOf(visible: VisibleLayer, touched: Iterable<string>): Generator<number, OverlayEntry[], void>;
51
54
  export declare function holds(layer: Layer, preconditions: readonly Precondition[]): boolean;
52
55
  export declare function landed(batch: ChangeBatch, confirmed: Layer, current?: Readonly<Record<string, string>>): boolean;
53
56
  export type Standing = {
@@ -63,5 +66,5 @@ export type Returned = {
63
66
  readonly removed: readonly string[];
64
67
  };
65
68
  export declare function returnedPaths(submitted: ChangeBatch, accepted: Accepted): Set<string>;
66
- export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string): Generator<number, Returned, void>;
69
+ export declare function returning(confirmed: Slice, submitted: ChangeBatch, accepted: Accepted, writtenAt: string, composition: Composition): Generator<number, Returned, void>;
67
70
  export {};
@@ -90,9 +90,9 @@ type ChangedUnderneath = {
90
90
  readonly file?: string | null;
91
91
  };
92
92
  export type ReturnReason = ProviderRefusal & {
93
- readonly kind: Open<'conflicted' | 'rejected' | 'expired' | 'withdrawn'>;
93
+ readonly kind: Open<'conflicted' | 'rejected' | 'withdrawn'>;
94
94
  };
95
- export declare function returnedBy(kind: 'expired' | 'withdrawn'): ReturnReason;
95
+ export declare function returnedBy(kind: 'withdrawn'): ReturnReason;
96
96
  export type RoomDraft = {
97
97
  readonly room: string;
98
98
  readonly path: string;
@@ -127,13 +127,14 @@ export type SavedDraft = {
127
127
  readonly path: string;
128
128
  readonly parts: HeldParts;
129
129
  };
130
- export declare function readParts(value: unknown): RoomDraftParts;
130
+ export declare function readParts(value: unknown, path: string): RoomDraftParts;
131
131
  export declare function gatheredParts(earlier: unknown, later: unknown): unknown;
132
132
  export declare function held(current: HeldParts | undefined, parts: RoomDraftParts, file?: HeldFile): HeldParts;
133
133
  export declare function underneath(parts: HeldParts, path: string, visible: VisibleLayer | undefined): ChangedUnderneath;
134
134
  export declare function heldFile(blob: Blob, base: string | null): Promise<HeldFile>;
135
135
  export declare function binaryBase(visible: VisibleLayer | undefined, path: string): string | null;
136
136
  export declare function changedParts(path: string, parts: HeldParts, visible: VisibleLayer | undefined): readonly ChangedPart[];
137
+ export declare function lineEnded(text: string): string;
137
138
  export type TextParts = {
138
139
  readonly fields?: Readonly<Record<string, {
139
140
  readonly value: unknown;