@agentshouse/app-bridge 0.1.0-c895bda3a3f6a → 0.1.0-c8a7dd564e490

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 (49) hide show
  1. package/README.md +6 -6
  2. package/dist/index.d.ts +91 -59
  3. package/dist/mdmodel/definition.d.ts +1 -1
  4. package/dist/mdmodel/document.d.ts +1 -2
  5. package/dist/mdmodel/event.d.ts +77 -0
  6. package/dist/mdmodel/facts.d.ts +14 -0
  7. package/dist/mdmodel/index.d.ts +19 -6
  8. package/dist/mdmodel/kinds.d.ts +18 -0
  9. package/dist/mdmodel/pattern.d.ts +9 -0
  10. package/dist/mdmodel/query/language.d.ts +253 -0
  11. package/dist/mdmodel/query/match.d.ts +13 -0
  12. package/dist/mdmodel/query/rows.d.ts +31 -0
  13. package/dist/mdmodel/query/sql.d.ts +38 -0
  14. package/dist/mdmodel/reserved.d.ts +4 -0
  15. package/dist/mdmodel/types.d.ts +7 -5
  16. package/dist/mdmodel/validate.d.ts +7 -5
  17. package/dist/mdruntime/adapter.d.ts +37 -25
  18. package/dist/mdruntime/chain.d.ts +2 -1
  19. package/dist/mdruntime/change.d.ts +1 -0
  20. package/dist/mdruntime/client.d.ts +7 -3
  21. package/dist/mdruntime/collection.d.ts +2 -1
  22. package/dist/mdruntime/compile.d.ts +2 -7
  23. package/dist/mdruntime/connection.d.ts +7 -6
  24. package/dist/mdruntime/conversation-row.d.ts +32 -0
  25. package/dist/mdruntime/conversation.d.ts +18 -9
  26. package/dist/mdruntime/durability.d.ts +6 -0
  27. package/dist/mdruntime/identity.d.ts +0 -1
  28. package/dist/mdruntime/job.d.ts +32 -0
  29. package/dist/mdruntime/messages.d.ts +27 -3
  30. package/dist/mdruntime/model.d.ts +2 -9
  31. package/dist/mdruntime/observation.d.ts +2 -2
  32. package/dist/mdruntime/overlay.d.ts +1 -0
  33. package/dist/mdruntime/query.d.ts +13 -210
  34. package/dist/mdruntime/reach.d.ts +11 -11
  35. package/dist/mdruntime/readiness.d.ts +0 -2
  36. package/dist/mdruntime/replica.d.ts +8 -5
  37. package/dist/mdruntime/room-draft.d.ts +3 -2
  38. package/dist/mdruntime/search.d.ts +12 -63
  39. package/dist/mdruntime/source.d.ts +60 -0
  40. package/dist/mdruntime/status.d.ts +0 -2
  41. package/dist/mdruntime/store.d.ts +88 -41
  42. package/dist/mdruntime/stored.d.ts +58 -65
  43. package/dist/mdruntime/tables.d.ts +88 -51
  44. package/dist/mdruntime/wire.d.ts +8 -0
  45. package/dist/test-host.js +1 -1
  46. package/docs/families.md +17 -6
  47. package/package.json +1 -1
  48. package/dist/mdmodel/condition.d.ts +0 -180
  49. package/dist/mdruntime/fulltext.d.ts +0 -26
@@ -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 = {
@@ -100,7 +101,7 @@ export type MdRuntime = {
100
101
  (query: GroupQuery): Promise<GroupResult | PendingResult>;
101
102
  };
102
103
  search(request: SearchRequest): Promise<SearchResult>;
103
- types(locator: string): RoomSchemas;
104
+ types(locator: string): Promise<RoomSchemas>;
104
105
  roomDraft: RoomDraftSurface;
105
106
  conversation: ConversationSurface;
106
107
  chatDraft: ChatDraftSurface;
@@ -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>>;
@@ -140,8 +143,6 @@ export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'stora
140
143
  export type ReadinessPort = {
141
144
  readonly target: string;
142
145
  readonly code: CodeAvailability;
143
- readonly space: Space | null;
144
- readonly search: SearchObligation;
145
146
  };
146
147
  export type ComposedRuntime = RuntimeView & {
147
148
  seed(entry: EntrySeed): void;
@@ -0,0 +1,32 @@
1
+ import type { HeldRow } from './messages.js';
2
+ import { type HouseSource } from './source.js';
3
+ export type ConversationLast = {
4
+ readonly text: string;
5
+ readonly by: 'owner' | 'agent' | 'house';
6
+ readonly at: string;
7
+ };
8
+ export type ConversationStart = Extract<HouseSource, {
9
+ readonly kind: 'request' | 'trigger';
10
+ }>;
11
+ export type ConversationAsk = {
12
+ readonly who: string;
13
+ readonly agent: string | null;
14
+ readonly room: {
15
+ readonly ref: string;
16
+ readonly name: string;
17
+ };
18
+ readonly prompt: string;
19
+ readonly at: string;
20
+ readonly request: string;
21
+ readonly message?: string;
22
+ };
23
+ export type ConversationHeld = {
24
+ readonly last: ConversationLast | null;
25
+ readonly failure: string | null;
26
+ readonly startedBy: ConversationStart | null;
27
+ readonly asks: ConversationAsk | null;
28
+ };
29
+ export declare function heldFacts(held: HeldRow | undefined, listed: {
30
+ readonly outcome: string | null;
31
+ readonly waiting: boolean;
32
+ }): ConversationHeld;
@@ -1,11 +1,13 @@
1
- import type { ConversationAction, ConversationEvent, ConversationHistoryRequest, ConversationMessage, ConversationStream, ListedConversation, ProcessCommand, RunningSubagent, SessionOption, TurnContext } from './adapter.js';
1
+ import type { ConversationAction, ConversationEvent, ConversationHistoryRequest, ConversationMessage, ConversationStream, ProcessCommand, RunningSubagent, SessionOption, TurnContext } from './adapter.js';
2
2
  import { type ChangeSet } from './change-set.js';
3
+ import { type ConversationHeld } from './conversation-row.js';
4
+ import type { OpenJob } from './job.js';
3
5
  import type { Open } from './open.js';
4
6
  import { type CallResult, type Offline } from './outcome.js';
5
7
  import type { CycleProgress } from './status.js';
6
- import type { ChatDraftRecord, HeldConversation, RuntimeStore } from './store.js';
8
+ import type { RuntimeStore } from './store.js';
7
9
  export type ConversationState = Open<'working' | 'asking' | 'idle'>;
8
- export type ConversationEntry = {
10
+ export type ConversationEntry = ConversationHeld & {
9
11
  conversation: string;
10
12
  agent: {
11
13
  identity: string;
@@ -18,6 +20,8 @@ export type ConversationEntry = {
18
20
  waiting: boolean;
19
21
  state: ConversationState;
20
22
  started: string | null;
23
+ line: string | null;
24
+ question: string | null;
21
25
  };
22
26
  export type ConversationAgent = {
23
27
  identity: string;
@@ -37,6 +41,9 @@ export type ConversationOptions = {
37
41
  after?: string;
38
42
  total?: true;
39
43
  };
44
+ export type ConversationRead = ConversationOptions & {
45
+ text?: string;
46
+ };
40
47
  export type ConversationView = {
41
48
  conversation: string;
42
49
  messages: readonly ConversationMessage[];
@@ -47,6 +54,7 @@ export type ConversationView = {
47
54
  process: {
48
55
  running: boolean;
49
56
  } | null;
57
+ processEnded: string | null;
50
58
  commands: readonly ProcessCommand[];
51
59
  options: readonly SessionOption[];
52
60
  starting: string | null;
@@ -58,10 +66,11 @@ export type ConversationView = {
58
66
  chatDraft: (ChatDraft & {
59
67
  readonly revision: string;
60
68
  }) | null;
69
+ jobs: readonly OpenJob[];
61
70
  };
62
71
  export type ConversationSurface = {
63
72
  list(): Promise<readonly ConversationEntry[]>;
64
- read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
73
+ read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
65
74
  create(input: unknown): Promise<CallResult>;
66
75
  send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
67
76
  answer(conversation: string, answer: ConversationAnswer): Promise<CallResult>;
@@ -82,18 +91,20 @@ export type ConversationDependencies = {
82
91
  call(name: ConversationAction, input: unknown): Promise<CallResult>;
83
92
  history(request: ConversationHistoryRequest): Promise<CallResult>;
84
93
  durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
94
+ local(): Promise<RuntimeStore>;
95
+ again(): void;
96
+ settled(): void;
85
97
  stream(): ConversationStream | undefined;
86
98
  publish(set: ChangeSet): void;
87
99
  online(): boolean;
88
100
  full(): boolean;
89
101
  closed(): boolean;
90
102
  unanswered(): void;
91
- expired(operation: string): boolean;
92
103
  };
93
104
  export type ConversationStore = {
94
105
  surface: ConversationSurface;
95
106
  chatDraft: ChatDraftSurface;
96
- hydrate(held: readonly HeldConversation[], drafts: readonly ChatDraftRecord[], list: readonly ListedConversation[] | null, cursor: string | null): void;
107
+ opened(local: RuntimeStore): Promise<void>;
97
108
  reconcile(): Promise<void>;
98
109
  catchUp(progress: CycleProgress): Promise<void>;
99
110
  resend(progress: CycleProgress): Promise<void>;
@@ -106,9 +117,7 @@ export type ConversationStore = {
106
117
  watchList(deliver: (entries: readonly ConversationEntry[]) => void): () => void;
107
118
  watchAgents(deliver: (agents: readonly ConversationAgent[]) => void): () => void;
108
119
  changed(set: ChangeSet): void;
109
- receive(event: ConversationEvent): boolean;
110
- searchable(): readonly string[];
111
- acquired(conversation: string): boolean;
120
+ receive(event: ConversationEvent): void;
112
121
  close(): void;
113
122
  };
114
123
  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;
@@ -0,0 +1,32 @@
1
+ type Job = {
2
+ readonly label: string;
3
+ readonly kind: 'started' | 'scheduled' | 'ended';
4
+ readonly state: string;
5
+ readonly next: string | null;
6
+ };
7
+ export type RunningJob = {
8
+ readonly name: string;
9
+ readonly running_since: string;
10
+ };
11
+ export type JobMarker = {
12
+ readonly said: string;
13
+ readonly at: string;
14
+ };
15
+ export type OpenJob<At = string | null> = {
16
+ readonly name: string;
17
+ readonly started: At;
18
+ };
19
+ export declare function jobOf(said: string): Job;
20
+ export declare function closeLast(open: {
21
+ readonly key: string;
22
+ }[], key: string): void;
23
+ export declare function markerMoved<Kept extends {
24
+ readonly key: string;
25
+ }>(open: Kept[], said: string, opened: (job: Job, key: string) => Kept | null): void;
26
+ export declare function openJobs<At>(markers: readonly {
27
+ readonly said: string;
28
+ readonly at: At;
29
+ }[]): readonly OpenJob<At>[];
30
+ export declare function jobsRunning(jobs: readonly RunningJob[], now: number): string[];
31
+ export declare function sessionEnded(jobs: readonly RunningJob[], now: number): string;
32
+ export {};
@@ -1,6 +1,9 @@
1
1
  import type { AcceptedMessage } from './adapter.js';
2
+ import type { JobMarker } from './job.js';
2
3
  import type { Connection } from './tables.js';
3
4
  export declare const MESSAGE_TABLES: readonly string[];
5
+ export declare const ROWS = "WITH chosen AS (\n SELECT listed.value AS conversation,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'assistant' ORDER BY position DESC, identity DESC LIMIT 1) AS answer,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND text <> '' ORDER BY position DESC, identity DESC LIMIT 1) AS said,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' ORDER BY position, identity LIMIT 1) AS opened,\n (SELECT id FROM conversation_messages WHERE conversation = listed.value AND json_extract(message, '$.role') = 'house' AND json_extract(message, '$.waiting') = 1 ORDER BY position, identity LIMIT 1) AS asking\n FROM json_each(?) AS listed\n )\n SELECT chosen.conversation AS conversation,\n substr(said.text, 1, 512) AS said_text,\n json_extract(said.message, '$.role') AS said_role,\n json_extract(said.message, '$.accepted_at') AS said_at,\n substr(json_extract(answer.message, '$.failure'), 1, 512) AS failure,\n json_extract(opened.message, '$.source') AS opened_source,\n json_extract(opened.message, '$.sender') AS opened_sender,\n asking.identity AS asking_identity,\n substr(asking.text, 1, 512) AS asking_text,\n json_extract(asking.message, '$.accepted_at') AS asking_at,\n json_extract(asking.message, '$.source') AS asking_source,\n json_extract(asking.message, '$.sender') AS asking_sender\n FROM chosen\n LEFT JOIN conversation_messages said ON said.id = chosen.said\n LEFT JOIN conversation_messages answer ON answer.id = chosen.answer\n LEFT JOIN conversation_messages opened ON opened.id = chosen.opened\n LEFT JOIN conversation_messages asking ON asking.id = chosen.asking";
6
+ export declare const JOB_MARKERS = "SELECT json_extract(part.value, '$.text') AS said,\n json_extract(message, '$.accepted_at') AS at\n FROM conversation_messages, json_each(message, '$.parts') AS part\n WHERE conversation = ? AND instr(message, '\"marker\":\"job\"') > 0\n AND json_extract(part.value, '$.type') = 'marker'\n AND json_extract(part.value, '$.marker') = 'job'\n ORDER BY position, identity, part.key";
4
7
  export type HeldConversation = {
5
8
  readonly conversation: string;
6
9
  readonly read: string | null | undefined;
@@ -10,6 +13,25 @@ export type MessageWindow = {
10
13
  readonly messages: AcceptedMessage[];
11
14
  readonly more: boolean;
12
15
  };
16
+ export type HeldSource = {
17
+ readonly source: unknown;
18
+ readonly sender: string | null;
19
+ };
20
+ export type HeldRow = {
21
+ readonly conversation: string;
22
+ readonly said: {
23
+ readonly text: string;
24
+ readonly role: string | null;
25
+ readonly at: string | null;
26
+ } | null;
27
+ readonly failure: string | null;
28
+ readonly opened: HeldSource | null;
29
+ readonly asking: (HeldSource & {
30
+ readonly identity: string;
31
+ readonly text: string;
32
+ readonly at: string | null;
33
+ }) | null;
34
+ };
13
35
  export type ConversationWrite = {
14
36
  readonly conversation: string;
15
37
  readonly messages: readonly AcceptedMessage[];
@@ -18,10 +40,12 @@ export type ConversationWrite = {
18
40
  readonly partial: boolean;
19
41
  };
20
42
  };
21
- export declare function heldConversations(connection: Connection): HeldConversation[];
43
+ export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
22
44
  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;
45
+ export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
46
+ export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
47
+ export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
48
+ export declare function jobMarkers(connection: Connection, conversation: string): JobMarker[];
25
49
  export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
26
50
  export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
27
51
  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;
@@ -57,6 +53,3 @@ export declare const NO_MODEL: ModelState;
57
53
  export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
58
54
  export declare function modelTypes(state: ModelState): TypesResult;
59
55
  export declare function storedModel(state: ModelState): StoredModel;
60
- export declare function cached(state: ModelState): ModelState;
61
- 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
  } | {
@@ -3,6 +3,7 @@ import type { ChangeBatch } from './change.js';
3
3
  export type Heads = {
4
4
  revisions: Readonly<Record<string, string>>;
5
5
  fileIds: Readonly<Record<string, string>>;
6
+ created: Readonly<Record<string, string>>;
6
7
  changes: Readonly<Record<string, HeadChange>>;
7
8
  };
8
9
  export type HeldBinary = ({
@@ -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;
@@ -101,16 +15,25 @@ export type QueryDocument = {
101
15
  sections?: Readonly<Record<string, string>>;
102
16
  preamble?: string;
103
17
  markdown?: string;
104
- textHeld?: false;
105
18
  backlinks?: readonly Backlink[];
106
19
  change?: HeadChange | null;
107
20
  fileId?: string | null;
108
21
  revision?: string | null;
109
22
  binaryFile?: BinaryFileRecord;
23
+ size?: number | null;
24
+ created?: string | null;
25
+ };
26
+ export type GroupTotal = {
27
+ count: number;
28
+ size: number;
110
29
  };
111
30
  export type QueryGroup = {
112
31
  key: readonly unknown[];
113
32
  count: number;
33
+ documents?: GroupTotal;
34
+ files?: GroupTotal;
35
+ updated?: string | null;
36
+ greatest?: unknown;
114
37
  };
115
38
  export type CoveredRoom = {
116
39
  room: string;
@@ -148,92 +71,6 @@ export type GroupResult = GroupRows & {
148
71
  coverage: QueryCoverage;
149
72
  };
150
73
  export type QueryResult = DocumentResult | GroupResult | PendingResult;
151
- export type QueryErrorCode = 'invalid-query' | 'unknown-type' | 'unknown-field' | 'wrong-kind';
152
- export type RoomFacts = {
153
- locator: string;
154
- available: boolean;
155
- types: readonly Definition[];
156
- };
157
- export type HeldRooms = {
158
- listed: boolean;
159
- rooms: readonly RoomFacts[];
160
- };
161
- export type Test = {
162
- op: 'eq';
163
- value: Value;
164
- } | {
165
- op: 'ne';
166
- value: Value;
167
- } | {
168
- op: 'in';
169
- values: readonly Value[];
170
- } | {
171
- op: 'nin';
172
- values: readonly Value[];
173
- } | {
174
- op: 'range';
175
- bounds: readonly (readonly ['gt' | 'gte' | 'lt' | 'lte', Value])[];
176
- } | {
177
- op: 'all';
178
- values: readonly Value[];
179
- } | {
180
- op: 'size';
181
- size: number;
182
- } | {
183
- op: 'exists';
184
- exists: boolean;
185
- };
186
- export type Condition = {
187
- every: readonly Condition[];
188
- } | {
189
- some: readonly Condition[];
190
- } | {
191
- field: string;
192
- test: Test;
193
- };
194
- export type Scope = {
195
- types: readonly string[] | null;
196
- where: Condition | null;
197
- pathPrefix: string | null;
198
- };
199
- export type KeyPlan = {
200
- of: 'room';
201
- } | {
202
- of: 'path';
203
- } | {
204
- of: 'type';
205
- } | {
206
- of: 'folder';
207
- } | {
208
- of: 'field';
209
- field: string;
210
- };
211
- export type DocumentShape = {
212
- kind: 'documents';
213
- fields: 'all' | readonly string[] | null;
214
- sections: 'all' | readonly string[] | null;
215
- preamble: boolean;
216
- markdown: boolean;
217
- backlinks: boolean;
218
- change: boolean;
219
- fileId: boolean;
220
- revision: boolean;
221
- orderBy: readonly {
222
- key: KeyPlan;
223
- options: OrderOptions & {
224
- direction: Direction;
225
- };
226
- }[];
227
- };
228
- export declare function bodied(shape: DocumentShape): boolean;
229
- export type GroupShape = {
230
- kind: 'groups';
231
- groupBy: readonly KeyPlan[];
232
- orderBy: readonly {
233
- by: 'count' | number;
234
- direction: Direction;
235
- }[];
236
- };
237
74
  export type PlanArea = {
238
75
  room: string;
239
76
  path: string;
@@ -244,42 +81,8 @@ export type PlanReach = {
244
81
  documents: readonly string[];
245
82
  areas: readonly PlanArea[];
246
83
  };
247
- export type Continuation = {
248
- text: string;
249
- values: readonly unknown[] | null;
250
- };
251
- export type Plan = {
252
- key: string;
253
- rooms: readonly string[] | null;
84
+ export type Plan = QueryPlan & {
254
85
  reach: PlanReach | null;
255
86
  locked: readonly string[];
256
- root: Scope;
257
- folder: string | null;
258
- paths: readonly string[] | null;
259
- hop: (Scope & {
260
- field: string;
261
- }) | null;
262
- backlinks: (Scope & {
263
- field: string | null;
264
- }) | null;
265
- shape: DocumentShape | GroupShape;
266
- limit: number | null;
267
- after: Continuation | null;
268
- total: boolean;
269
87
  };
270
- export declare class QueryError extends Error {
271
- readonly code: QueryErrorCode;
272
- readonly retryable = false;
273
- constructor(code: QueryErrorCode, at: string, problem: string);
274
- }
275
- type Entries = Readonly<Record<string, unknown>>;
276
- export declare function invalid(at: string, problem: string): never;
277
- export declare function plain(value: unknown): value is Entries;
278
- export declare function known(value: Entries, allowed: readonly string[], at: string): void;
279
- export declare function flag(input: unknown, at: string): boolean;
280
- export declare function planOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
281
- export declare function limitOf(input: unknown): number | null;
282
- export declare function filterOf(input: unknown, facts: HeldRooms, reach?: PlanReach | null): Plan;
283
- export declare function queryKey(query: unknown): string;
284
- export declare function identityOf(plan: Plan): string;
285
- export {};
88
+ 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,26 +18,26 @@ 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
- plan(input: unknown, reach: PortReach | null): Plan;
31
+ plan(input: unknown, reach: PortReach | null): Promise<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
- locked(room: string): boolean;
37
- lockedRooms(): readonly string[];
36
+ locked(room: string): Promise<boolean>;
37
+ lockedRooms(): Promise<readonly string[]>;
38
38
  watchLocks(notify: () => void): () => void;
39
- located(room: string, path: string, destination: string): ReachedDocument | null;
40
- room(locator: string): AppRoom | undefined;
39
+ located(room: string, path: string, destination: string): Promise<ReachedDocument | null>;
40
+ room(locator: string): Promise<AppRoom | undefined>;
41
41
  };
42
42
  export declare function holds(reach: PortReach | null, room: string): boolean;
43
43
  export declare function governs(reach: PortReach | null, room: {
@@ -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'>;