@agentshouse/app-bridge 0.1.0-ca559eade7c19 → 0.1.0-ca61ac777c0b7

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 (108) hide show
  1. package/README.md +11 -11
  2. package/dist/index.d.ts +1033 -20
  3. package/dist/mdmodel/definition.d.ts +18 -1
  4. package/dist/mdmodel/document.d.ts +10 -6
  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 +25 -11
  8. package/dist/mdmodel/kinds.d.ts +17 -0
  9. package/dist/mdmodel/markdown.d.ts +50 -0
  10. package/dist/mdmodel/paths.d.ts +9 -1
  11. package/dist/mdmodel/pattern.d.ts +9 -0
  12. package/dist/mdmodel/project.d.ts +1 -0
  13. package/dist/mdmodel/query/language.d.ts +253 -0
  14. package/dist/mdmodel/query/match.d.ts +13 -0
  15. package/dist/mdmodel/query/rows.d.ts +31 -0
  16. package/dist/mdmodel/query/sql.d.ts +38 -0
  17. package/dist/mdmodel/reserved.d.ts +5 -0
  18. package/dist/mdmodel/types.d.ts +46 -5
  19. package/dist/mdmodel/validate.d.ts +31 -4
  20. package/dist/mdruntime/actions.d.ts +19 -0
  21. package/dist/mdruntime/adapter.d.ts +161 -116
  22. package/dist/mdruntime/attached-model.d.ts +7 -0
  23. package/dist/mdruntime/binary.d.ts +0 -5
  24. package/dist/mdruntime/bootstrap.d.ts +43 -0
  25. package/dist/mdruntime/cell.d.ts +5 -0
  26. package/dist/mdruntime/chain.d.ts +11 -0
  27. package/dist/mdruntime/change-set.d.ts +13 -16
  28. package/dist/mdruntime/change.d.ts +32 -1
  29. package/dist/mdruntime/client.d.ts +36 -11
  30. package/dist/mdruntime/collection.d.ts +29 -21
  31. package/dist/mdruntime/compile.d.ts +15 -0
  32. package/dist/mdruntime/conversation-live.d.ts +135 -0
  33. package/dist/mdruntime/conversation-row.d.ts +32 -0
  34. package/dist/mdruntime/conversation.d.ts +54 -46
  35. package/dist/mdruntime/declaration.d.ts +9 -0
  36. package/dist/mdruntime/durability.d.ts +16 -4
  37. package/dist/mdruntime/failure.d.ts +1 -0
  38. package/dist/mdruntime/figures.d.ts +48 -0
  39. package/dist/mdruntime/holdings.d.ts +28 -0
  40. package/dist/mdruntime/identity.d.ts +5 -0
  41. package/dist/mdruntime/listing.d.ts +47 -0
  42. package/dist/mdruntime/live.d.ts +22 -0
  43. package/dist/mdruntime/log.d.ts +5 -0
  44. package/dist/mdruntime/media.d.ts +7 -0
  45. package/dist/mdruntime/messages.d.ts +48 -0
  46. package/dist/mdruntime/model.d.ts +8 -11
  47. package/dist/mdruntime/observation.d.ts +17 -2
  48. package/dist/mdruntime/opened.d.ts +21 -0
  49. package/dist/mdruntime/outcome.d.ts +49 -8
  50. package/dist/mdruntime/overlay.d.ts +4 -5
  51. package/dist/mdruntime/preparation.d.ts +19 -0
  52. package/dist/mdruntime/presence.d.ts +51 -0
  53. package/dist/mdruntime/query.d.ts +25 -191
  54. package/dist/mdruntime/reach.d.ts +20 -9
  55. package/dist/mdruntime/readiness.d.ts +13 -17
  56. package/dist/mdruntime/reads.d.ts +36 -0
  57. package/dist/mdruntime/recovery.d.ts +3 -2
  58. package/dist/mdruntime/refresh.d.ts +26 -0
  59. package/dist/mdruntime/replica.d.ts +50 -33
  60. package/dist/mdruntime/room-draft.d.ts +28 -11
  61. package/dist/mdruntime/room-drafts.d.ts +23 -0
  62. package/dist/mdruntime/runtime.d.ts +33 -0
  63. package/dist/mdruntime/save.d.ts +42 -48
  64. package/dist/mdruntime/saves.d.ts +31 -0
  65. package/dist/mdruntime/search.d.ts +12 -82
  66. package/dist/mdruntime/seed.d.ts +11 -2
  67. package/dist/mdruntime/socket/admission.d.ts +6 -0
  68. package/dist/mdruntime/socket/answers.d.ts +5 -0
  69. package/dist/mdruntime/socket/lanes.d.ts +19 -0
  70. package/dist/mdruntime/socket/session.d.ts +37 -0
  71. package/dist/mdruntime/socket.d.ts +66 -0
  72. package/dist/mdruntime/source.d.ts +60 -0
  73. package/dist/mdruntime/status.d.ts +4 -5
  74. package/dist/mdruntime/store/installs.d.ts +29 -0
  75. package/dist/mdruntime/store/readiness.d.ts +9 -0
  76. package/dist/mdruntime/store/records.d.ts +209 -0
  77. package/dist/mdruntime/store/room-held.d.ts +7 -0
  78. package/dist/mdruntime/store/space.d.ts +10 -0
  79. package/dist/mdruntime/store/watchers.d.ts +16 -0
  80. package/dist/mdruntime/store/writes.d.ts +23 -0
  81. package/dist/mdruntime/store.d.ts +109 -150
  82. package/dist/mdruntime/stored.d.ts +155 -0
  83. package/dist/mdruntime/surface.d.ts +87 -0
  84. package/dist/mdruntime/tables.d.ts +411 -0
  85. package/dist/mdruntime/tallies.d.ts +17 -0
  86. package/dist/mdruntime/transfer.d.ts +0 -5
  87. package/dist/mdruntime/wire.d.ts +54 -10
  88. package/dist/session-content/bounds.d.ts +7 -0
  89. package/dist/session-content/check.d.ts +18 -0
  90. package/dist/session-content/index.d.ts +7 -0
  91. package/dist/session-content/parts.d.ts +102 -0
  92. package/dist/session-content/state.d.ts +61 -0
  93. package/dist/session-content/turn.d.ts +328 -0
  94. package/dist/test-host.d.ts +7 -4
  95. package/dist/test-host.js +19 -29
  96. package/docs/families.md +69 -56
  97. package/package.json +8 -3
  98. package/dist/calls.d.ts +0 -118
  99. package/dist/calls.js +0 -1
  100. package/dist/mdmodel/blocks.d.ts +0 -10
  101. package/dist/mdmodel/condition.d.ts +0 -149
  102. package/dist/mdmodel/profile.d.ts +0 -5
  103. package/dist/mdruntime/acquisition.d.ts +0 -13
  104. package/dist/mdruntime/connection.d.ts +0 -141
  105. package/dist/mdruntime/file.d.ts +0 -19
  106. package/dist/mdruntime/rows.d.ts +0 -37
  107. package/dist/mdruntime/shared.d.ts +0 -10
  108. package/dist/mdruntime/turn.d.ts +0 -6
@@ -1,24 +1,30 @@
1
- import type { ConversationAction, ConversationAgents, ConversationEvent, ConversationMessage, ConversationStream, ProcessCommand, SessionOption, TurnContext } from './adapter.js';
1
+ import { type Part, type SessionState } from '../session-content/index.js';
2
+ import type { ConversationEvent, ConversationMessage, ProcessCommand, SessionOption } from './adapter.js';
2
3
  import { type ChangeSet } from './change-set.js';
3
- import { type ChatDraftFile } from './file.js';
4
+ import { type LiveConversations } from './conversation-live.js';
5
+ import { type ConversationHeld } from './conversation-row.js';
4
6
  import type { Open } from './open.js';
5
7
  import { type CallResult, type Offline } from './outcome.js';
6
- import type { DocumentResult, PendingResult } from './query.js';
7
8
  import type { CycleProgress } from './status.js';
8
- import type { ChatDraftRecord, HeldConversation, RuntimeStore } from './store.js';
9
+ import type { RuntimeStore } from './store.js';
9
10
  export type ConversationState = Open<'working' | 'asking' | 'idle'>;
10
- export type ConversationEntry = {
11
+ export type ConversationEntry = ConversationHeld & {
11
12
  conversation: string;
12
13
  agent: {
13
14
  identity: string;
14
- name: string | null;
15
+ name: string;
16
+ retired: boolean;
15
17
  };
16
18
  name: string;
17
19
  created: string;
18
20
  finished: string | null;
19
21
  outcome: string | null;
22
+ waiting: boolean;
20
23
  state: ConversationState;
21
24
  started: string | null;
25
+ line: string | null;
26
+ question: string | null;
27
+ asked: string | null;
22
28
  };
23
29
  export type ConversationAgent = {
24
30
  identity: string;
@@ -27,79 +33,81 @@ export type ConversationAgent = {
27
33
  export type RunningTurn = {
28
34
  turn: string;
29
35
  started: string | null;
30
- parts: readonly unknown[];
31
- context: TurnContext | null;
36
+ parts: readonly Part[];
32
37
  };
33
38
  export type ChatDraft = {
34
39
  text: string;
35
- files: readonly ChatDraftFile[];
36
40
  };
37
41
  export type ConversationOptions = {
38
42
  limit?: number;
43
+ after?: string;
44
+ total?: true;
45
+ };
46
+ export type ConversationRead = ConversationOptions & {
47
+ text?: string;
39
48
  };
40
49
  export type ConversationView = {
41
50
  conversation: string;
42
51
  messages: readonly ConversationMessage[];
52
+ next?: string;
53
+ total?: number;
43
54
  turn: RunningTurn | null;
44
55
  questions: readonly unknown[];
45
56
  process: {
46
57
  running: boolean;
47
58
  } | null;
59
+ processEnded: string | null;
48
60
  commands: readonly ProcessCommand[];
49
61
  options: readonly SessionOption[];
62
+ starting: string | null;
63
+ state: SessionState | null;
64
+ link: {
65
+ connected: boolean;
66
+ } | null;
67
+ deliveryWaiting: readonly string[];
68
+ deliveryUnknown: readonly string[];
50
69
  chatDraft: (ChatDraft & {
51
70
  readonly revision: string;
52
71
  }) | null;
53
72
  };
54
73
  export type ConversationSurface = {
55
74
  list(): Promise<readonly ConversationEntry[]>;
56
- read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
75
+ read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
57
76
  create(input: unknown): Promise<CallResult>;
58
77
  send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
59
- answer(conversation: string, answer: unknown): Promise<CallResult>;
78
+ answer(conversation: string, answer: ConversationAnswer): Promise<CallResult>;
60
79
  interrupt(conversation: string): Promise<CallResult>;
61
80
  kill(conversation: string): Promise<CallResult>;
62
- cancel(conversation: string, turn: string): Promise<CallResult>;
63
81
  delete(conversation: string): Promise<CallResult>;
64
82
  };
83
+ export type ConversationAnswer = {
84
+ interaction_id: string;
85
+ response: unknown;
86
+ };
65
87
  export type ChatDraftSurface = {
66
88
  write(conversation: string, draft: ChatDraft, revision?: string): Promise<void>;
89
+ prepend(conversation: string, draft: ChatDraft): Promise<void>;
67
90
  discard(conversation: string): Promise<void>;
68
91
  };
69
- export type ConversationDependencies = {
70
- agents(): ConversationAgents | undefined;
71
- documents(agents: ConversationAgents): Promise<DocumentResult | PendingResult>;
72
- call(name: ConversationAction, input: unknown): Promise<CallResult>;
73
- durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
74
- stream(): ConversationStream | undefined;
75
- publish(set: ChangeSet): void;
76
- online(): boolean;
77
- closed(): boolean;
78
- unanswered(): void;
79
- expired(operation: string): boolean;
80
- };
81
- export type ConversationStore = {
82
- surface: ConversationSurface;
83
- chatDraft: ChatDraftSurface;
84
- hydrate(held: readonly HeldConversation[], drafts: readonly ChatDraftRecord[]): void;
85
- reconcile(): Promise<void>;
86
- catchUp(progress: CycleProgress): Promise<void>;
87
- resend(progress: CycleProgress): Promise<void>;
88
- current(): boolean;
89
- known(): boolean;
90
- reconnected(): void;
91
- reopened(): void;
92
- lost(): void;
93
- watch(conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
94
- watchList(deliver: (entries: readonly ConversationEntry[]) => void): () => void;
95
- watchAgents(deliver: (agents: readonly ConversationAgent[]) => void): () => void;
96
- changed(set: ChangeSet): void;
97
- receive(event: ConversationEvent): boolean;
98
- searchable(): readonly string[];
99
- acquired(conversation: string): boolean;
100
- close(): void;
101
- };
102
92
  export declare function unheldView(conversation: string): ConversationView;
103
93
  export declare const SESSION_STARTED = "Session started";
94
+ export declare const HISTORY_CONVERSATIONS = 64;
104
95
  export declare function newChat(agent: string): string;
105
- export declare function createConversationStore(deps: ConversationDependencies): ConversationStore;
96
+ export type Asked = {
97
+ limit: number;
98
+ after: string | undefined;
99
+ before: readonly [string, string] | null;
100
+ total: boolean;
101
+ };
102
+ export declare function conversationsLearned(alive: LiveConversations): void;
103
+ export declare function conversationSurface(alive: LiveConversations): ConversationSurface;
104
+ export declare function chatDraftSurface(alive: LiveConversations): ChatDraftSurface;
105
+ export declare function conversationsOpened(alive: LiveConversations, local: RuntimeStore): Promise<void>;
106
+ export declare function reconcileConversations(alive: LiveConversations): Promise<void>;
107
+ export declare function catchUpConversations(alive: LiveConversations, progress: CycleProgress): Promise<void>;
108
+ export declare function resendConversations(alive: LiveConversations, progress: CycleProgress): Promise<void>;
109
+ export declare function watchConversation(alive: LiveConversations, conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
110
+ export declare function watchConversationList(alive: LiveConversations, deliver: (entries: readonly ConversationEntry[]) => void): () => void;
111
+ export declare function watchConversationAgents(alive: LiveConversations, deliver: (agents: readonly ConversationAgent[]) => void): () => void;
112
+ export declare function conversationsChanged(alive: LiveConversations, set: ChangeSet): void;
113
+ export declare function receiveConversationEvent(alive: LiveConversations, event: ConversationEvent): void;
@@ -0,0 +1,9 @@
1
+ import type { DiscoveredRoom, OperationScopes, PathRule, RoomDeclaration } from './adapter.js';
2
+ export type WriteRefusal = {
3
+ readonly code: 'room-root' | 'provider-owned-path' | 'invalid-path' | `${keyof OperationScopes}-grant`;
4
+ readonly path: string;
5
+ };
6
+ export type WriteRule = (path: string, needs: readonly (keyof OperationScopes)[]) => WriteRefusal | null;
7
+ export declare function declared({ locator: _locator, roomVersion: _roomVersion, ...declaration }: DiscoveredRoom): RoomDeclaration;
8
+ export declare function sameDeclaration(left: RoomDeclaration, right: RoomDeclaration): boolean;
9
+ export declare function writeRule({ operations, providerOwnedPaths, authoredPaths, }: Pick<RoomDeclaration, 'operations' | 'providerOwnedPaths' | 'authoredPaths'>, pathRule: PathRule, local: boolean): WriteRule;
@@ -1,14 +1,26 @@
1
1
  import type { Persistence } from './readiness.js';
2
- export type StorageEstimate = {
3
- readonly usage: number;
4
- readonly quota: number;
2
+ export type UnsentKind = 'pending-change' | 'call' | 'room-draft' | 'chat-draft';
3
+ export type UnsentWork = {
4
+ readonly kind: UnsentKind;
5
+ readonly count: number;
6
+ };
7
+ export type AppCode = {
8
+ readonly running: number;
9
+ readonly older: number;
10
+ };
11
+ export type HeldCode = {
12
+ readonly house: number | null;
13
+ readonly apps: readonly string[];
5
14
  };
6
15
  export type RuntimeShell = {
7
16
  persistence: Persistence;
8
17
  generation: string | null;
9
18
  keepGeneration(value: string): void | Promise<void>;
10
19
  dropGeneration(): void | Promise<void>;
11
- estimate?(): Promise<StorageEstimate | null>;
20
+ cleanUp?(): Promise<number>;
21
+ measure?(measured: (app: string, code: AppCode | null) => void): Promise<HeldCode>;
22
+ reset(): Promise<void>;
12
23
  };
24
+ export declare function refusedForSpace(error: unknown): boolean;
13
25
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
14
26
  export declare function nextGeneration(stored: string | null, reported: string | null): string;
@@ -9,4 +9,5 @@ export type Described = {
9
9
  };
10
10
  export declare function runtimeError(code: string, message?: string, retryable?: boolean): RuntimeError;
11
11
  export declare function failed(error: unknown): RuntimeError;
12
+ export declare function uncaught(error: unknown): void;
12
13
  export declare function described(error: unknown): Described;
@@ -0,0 +1,48 @@
1
+ import type { ChangeSet } from './change-set.js';
2
+ import type { GroupTotal, PendingResult } from './query.js';
3
+ import type { Deliver, Fail } from './reach.js';
4
+ import type { ConversationTally, RoomTally } from './tallies.js';
5
+ import type { QueryRoom } from './tables.js';
6
+ export declare const HOUSE_DIRECTORY = "house";
7
+ export declare const ROOM_TOTALS: {
8
+ readonly outside: readonly ["house"];
9
+ readonly groupBy: readonly ["room"];
10
+ readonly select: {
11
+ readonly size: true;
12
+ };
13
+ };
14
+ export declare const FIGURES_DAY_MS = 86400000;
15
+ export type DayFigures = {
16
+ readonly created: number;
17
+ readonly changed: number;
18
+ readonly chats: number;
19
+ readonly messages: number;
20
+ };
21
+ export type RoomFigures = {
22
+ readonly room: string;
23
+ readonly day: DayFigures;
24
+ readonly total: {
25
+ readonly documents: GroupTotal;
26
+ readonly files: GroupTotal;
27
+ };
28
+ };
29
+ export type Figures = {
30
+ readonly rooms: readonly RoomFigures[];
31
+ readonly agentMessages: number;
32
+ };
33
+ export type FiguresResult = Figures | PendingResult;
34
+ export type FiguresCover = PendingResult | {
35
+ readonly rooms: readonly QueryRoom[];
36
+ };
37
+ export type FiguresSources = {
38
+ cover(): Promise<FiguresCover>;
39
+ rooms(rooms: readonly QueryRoom[], since: string): Promise<readonly RoomTally[]>;
40
+ conversations(conversations: readonly string[] | null, since: string): Promise<readonly ConversationTally[]>;
41
+ };
42
+ export type FiguresRead = {
43
+ watch(deliver: Deliver, fail: Fail): () => void;
44
+ touched(set: ChangeSet): void;
45
+ recover(): void;
46
+ close(): void;
47
+ };
48
+ export declare function createFigures(sources: FiguresSources): FiguresRead;
@@ -0,0 +1,28 @@
1
+ import type { AppCode } from './durability.js';
2
+ import type { GroupTotal, PendingResult } from './query.js';
3
+ import type { Deliver, Fail } from './reach.js';
4
+ import type { Runtime } from './runtime.js';
5
+ import type { OpenedRoom } from './tables.js';
6
+ export type RoomDocuments = {
7
+ readonly room: string;
8
+ readonly documents: GroupTotal;
9
+ };
10
+ export type HeldApp = ({
11
+ readonly app: string;
12
+ readonly state: 'measured';
13
+ } & AppCode) | {
14
+ readonly app: string;
15
+ readonly state: 'asking' | 'unknown';
16
+ };
17
+ export type Holdings = {
18
+ readonly rooms: readonly RoomDocuments[] | PendingResult;
19
+ readonly opened: GroupTotal & {
20
+ readonly rooms: readonly OpenedRoom[];
21
+ };
22
+ readonly apps: readonly HeldApp[];
23
+ readonly house: number | null;
24
+ readonly total: number | null;
25
+ readonly cleanUp: number | null;
26
+ };
27
+ export declare const CLEANED_TOPIC = "cleaned";
28
+ export declare function watchHoldings({ store, figures, shell }: Runtime, deliver: Deliver, fail: Fail): () => void;
@@ -0,0 +1,5 @@
1
+ export declare function changeBatchIdentity(at?: number): string;
2
+ export declare function roomDraftRevision(): string;
3
+ export declare function chatDraftRevision(): string;
4
+ export declare function transferIdentity(): string;
5
+ export declare function binaryLocalId(): string;
@@ -0,0 +1,47 @@
1
+ import type { HeldRooms } from '../mdmodel/index.js';
2
+ import type { DiscoveredRoom, HeldRoom, OperationScopes, ProviderRefusal, ReplicaAdmission, RoomDeclaration } from './adapter.js';
3
+ import type { Composition } from './collection.js';
4
+ import { type ModelState, type TypesResult } from './model.js';
5
+ import { type PortReach } from './reach.js';
6
+ import type { ReplicaRecord } from './replica.js';
7
+ import type { Runtime } from './runtime.js';
8
+ import type { Stored } from './store.js';
9
+ export type AppTypedSelection = {
10
+ roots: readonly string[];
11
+ model: TypesResult;
12
+ };
13
+ export type AppRoom = {
14
+ name: string;
15
+ locator: string;
16
+ handle: string;
17
+ operations: OperationScopes;
18
+ replica: ReplicaAdmission;
19
+ model: TypesResult;
20
+ typedSelection: AppTypedSelection | null;
21
+ providerOwnedPaths: readonly string[];
22
+ authoredPaths: readonly string[];
23
+ roomVersion: string | null;
24
+ documents: number;
25
+ synchronizationAvailable: boolean;
26
+ refusal: ProviderRefusal | null;
27
+ locked: boolean;
28
+ };
29
+ type ListedRoom = Omit<AppRoom, 'documents' | 'locked'>;
30
+ type ListedEntry = ListedRoom & {
31
+ readonly documents: number;
32
+ };
33
+ export type Listing = ReadonlyMap<string, ListedEntry>;
34
+ export declare function modelIn({ socket, presence }: Runtime, locator: string, stored: Stored | undefined): ModelState;
35
+ export declare function compositionFor(runtime: Runtime, record: ReplicaRecord): Composition;
36
+ export declare function declarationOf({ presence }: Runtime, locator: string, stored: Stored | undefined): {
37
+ readonly room: RoomDeclaration;
38
+ readonly available: boolean;
39
+ } | undefined;
40
+ export declare function listedLocators({ presence }: Runtime, held: ReadonlyMap<string, unknown>): string[];
41
+ export declare function patchedListing(runtime: Runtime, changed: ReadonlySet<string>): Promise<Listing | null>;
42
+ export declare function listingNow(runtime: Runtime): Promise<Listing>;
43
+ export declare function shownRooms({ presence }: Runtime, listing: Listing): readonly AppRoom[];
44
+ export declare function roomFacts(runtime: Runtime, reach?: PortReach | null): Promise<HeldRooms>;
45
+ export declare function heldRooms({ store }: Runtime, listed: readonly DiscoveredRoom[]): Promise<HeldRoom[]>;
46
+ export declare function name(runtime: Runtime, locator: string): Promise<void>;
47
+ export {};
@@ -0,0 +1,22 @@
1
+ import type { ChangeSet } from './change-set.js';
2
+ import { type KeyedResult, type QueryMessage } from './observation.js';
3
+ import type { PendingResult, Plan, QueryCoverage } from './query.js';
4
+ import type { Fail } from './reach.js';
5
+ import type { QueryRoom } from './tables.js';
6
+ export type Cover = {
7
+ coverage: QueryCoverage;
8
+ rooms: readonly QueryRoom[];
9
+ } | PendingResult;
10
+ export type Ran = KeyedResult & {
11
+ readonly current: () => boolean;
12
+ };
13
+ export type Run = (plan: Plan, cover: () => Promise<Cover>) => Promise<Ran>;
14
+ type Listener = (message: QueryMessage) => void;
15
+ export type LiveQueries<H> = {
16
+ touched(set: ChangeSet): void;
17
+ recover(): void;
18
+ watch(plan: Plan, identity: string, cover: (held: H) => Cover, deliver: Listener, failed: Fail): () => void;
19
+ close(): void;
20
+ };
21
+ export declare function createLiveQueries<H>(run: Run, holding: () => Promise<H>): LiveQueries<H>;
22
+ export {};
@@ -0,0 +1,5 @@
1
+ export declare function createLog(): {
2
+ record(event: string): void;
3
+ export(): string;
4
+ };
5
+ export type Log = ReturnType<typeof createLog>;
@@ -0,0 +1,7 @@
1
+ import type { MdRuntimeClient } from './client.js';
2
+ import { type ShownAnswer } from './outcome.js';
3
+ export declare const ROOM_MEDIA = "room-media";
4
+ type Show = (room: string, path: string, revision?: string) => Promise<ShownAnswer>;
5
+ export declare function shownBy(show: Show, client: MdRuntimeClient): MdRuntimeClient;
6
+ export declare function defineRoomMedia(client: Promise<MdRuntimeClient> | MdRuntimeClient): void;
7
+ export {};
@@ -0,0 +1,48 @@
1
+ import type { AcceptedMessage } from './adapter.js';
2
+ import type { Connection } from './tables.js';
3
+ export declare const MESSAGE_TABLES: readonly string[];
4
+ 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 asking.text 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";
5
+ export type HeldConversation = {
6
+ readonly conversation: string;
7
+ readonly read: string | null | undefined;
8
+ readonly partial: boolean;
9
+ };
10
+ export type MessageWindow = {
11
+ readonly messages: AcceptedMessage[];
12
+ readonly more: boolean;
13
+ };
14
+ export type HeldSource = {
15
+ readonly source: unknown;
16
+ readonly sender: string | null;
17
+ };
18
+ export type HeldRow = {
19
+ readonly conversation: string;
20
+ readonly said: {
21
+ readonly text: string;
22
+ readonly role: string | null;
23
+ readonly at: string | null;
24
+ } | null;
25
+ readonly failure: string | null;
26
+ readonly opened: HeldSource | null;
27
+ readonly asking: (HeldSource & {
28
+ readonly identity: string;
29
+ readonly text: string;
30
+ readonly at: string | null;
31
+ }) | null;
32
+ };
33
+ export type ConversationWrite = {
34
+ readonly conversation: string;
35
+ readonly messages: readonly AcceptedMessage[];
36
+ readonly read?: {
37
+ readonly at: string | null;
38
+ readonly partial: boolean;
39
+ };
40
+ };
41
+ export declare function heldConversations(connection: Connection, conversations: readonly string[] | null): HeldConversation[];
42
+ export declare function keptMessages(connection: Connection, { conversation, messages, read }: ConversationWrite): null;
43
+ export declare function messageWindow(connection: Connection, conversation: string, limit: number, before: readonly [string, string] | null, phrase: string | null): MessageWindow;
44
+ export declare function messageCount(connection: Connection, conversation: string, phrase: string | null): number;
45
+ export declare function conversationRows(connection: Connection, conversations: readonly string[]): HeldRow[];
46
+ export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
47
+ export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
48
+ 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,20 +20,21 @@ 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;
28
26
  verifiedWith: ModelIdentity;
29
27
  types: VerifiedModel['types'];
30
28
  };
29
+ export type StoredModel = Extract<ModelState, {
30
+ status: 'unavailable';
31
+ }> | Omit<Extract<ModelState, {
32
+ status: 'current' | 'cached';
33
+ }>, 'types'>;
31
34
  export type TypesResult = {
32
35
  status: Open<'unavailable'>;
33
36
  reason: ModelUnavailableReason;
34
37
  types: null;
35
- schema?: string | null;
36
- revision?: string | null;
37
38
  } | {
38
39
  status: Open<'current' | 'cached'>;
39
40
  identity: string;
@@ -49,9 +50,5 @@ export type ValidationReceipt = {
49
50
  source: Open<'current' | 'cached'>;
50
51
  };
51
52
  export declare const NO_MODEL: ModelState;
52
- export declare function definitionOf(state: ModelState, type: string | undefined): Definition | undefined;
53
53
  export declare function modelTypes(state: ModelState): TypesResult;
54
- export declare function cached(state: ModelState): ModelState;
55
- export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
56
- export declare function sameTyping(left: ModelState, right: ModelState): boolean;
57
- export declare function referenceField(facts: ValueFacts | undefined): boolean;
54
+ export declare function storedModel(state: ModelState): StoredModel;
@@ -14,6 +14,8 @@ export type QueryChange = {
14
14
  removed: readonly RowKey[];
15
15
  order: readonly RowKey[] | null;
16
16
  coverage?: QueryCoverage;
17
+ next?: string | null;
18
+ total?: number;
17
19
  };
18
20
  export type QueryMessage = KeyedResult | QueryChange;
19
21
  export type Observed = {
@@ -25,5 +27,18 @@ export declare function rowsOf(result: QueryResult): readonly (QueryDocument | Q
25
27
  export declare function whole(message: QueryMessage): message is KeyedResult;
26
28
  export declare function applied(keyed: KeyedResult, message: QueryMessage): KeyedResult;
27
29
  export declare function observed(first: unknown, stop: () => void, keyed: boolean): Observed;
28
- export declare function opened(watch: (deliver: (message: unknown) => void) => () => void, keyed: boolean): Promise<Observation<unknown>>;
29
- 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
+ export type Digest = {
33
+ readonly pending: string;
34
+ } | {
35
+ readonly keys: readonly RowKey[];
36
+ readonly rows: ReadonlyMap<RowKey, number>;
37
+ readonly coverage: string;
38
+ readonly next: string | undefined;
39
+ readonly total: number | undefined;
40
+ };
41
+ export declare function hashed(text: string): number;
42
+ export declare function digestOf({ result, keys }: KeyedResult): Digest;
43
+ export declare function digestApplied(digest: Digest, message: QueryMessage): Digest;
44
+ export declare function changeOf(previous: Digest, next: KeyedResult): QueryMessage | null;
@@ -0,0 +1,21 @@
1
+ import type { BinaryResult } from './adapter.js';
2
+ import { type RuntimeDatabase } from './tables.js';
3
+ export type OpenedName = {
4
+ readonly locator: string;
5
+ readonly path: string;
6
+ readonly revision: string;
7
+ };
8
+ export type KeptBinary = {
9
+ readonly kind: 'binary';
10
+ readonly file: string;
11
+ readonly byteLength: number;
12
+ readonly mediaType: string;
13
+ };
14
+ export type KeptResult = KeptBinary | Exclude<BinaryResult, {
15
+ kind: 'binary';
16
+ }>;
17
+ export type OpenedFiles = {
18
+ find(name: OpenedName): Promise<KeptBinary | null>;
19
+ fetch(name: OpenedName, read: () => Promise<BinaryResult>): Promise<KeptResult>;
20
+ };
21
+ export declare function openedFiles(database: RuntimeDatabase, lost: (locator: string) => boolean): OpenedFiles;
@@ -1,29 +1,73 @@
1
- import type { ActionResult, AdapterFailure, BinaryResult, HistoryResult, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
1
+ import type { ActionResult, AdapterFailure, AttachResult, BinaryLinkResult, HistoryResult, HistoryRevision, ProviderRefusal, RoomVersionAt, ScopedRefusal } from './adapter.js';
2
2
  import type { ChangeBatch } from './change.js';
3
+ import type { KeptBinary, KeptResult } from './opened.js';
3
4
  type Refused<Kind extends string> = ProviderRefusal & {
4
5
  kind: Kind;
5
6
  };
6
7
  export type Failure = Refused<'transport-uncertainty'> | Refused<'revoked-authorization'> | (Refused<'room-not-readable'> & {
7
8
  locator: string;
9
+ }) | (Refused<'room-locked'> & {
10
+ locator: string;
8
11
  }) | ScopedRefusal;
9
12
  export type CallResult = {
10
13
  kind: 'action';
11
14
  result: unknown;
12
15
  at?: RoomVersionAt;
13
- } | Refused<'rejected'> | Refused<'undeclared'> | Failure;
16
+ } | (Refused<'rejected'> & {
17
+ reset?: string;
18
+ }) | Refused<'undeclared'> | Failure;
14
19
  export type HistoryAnswer = Exclude<HistoryResult, {
15
20
  kind: Failure['kind'];
16
21
  }> | Failure;
22
+ type BinaryRefusal = Refused<'rejected'> | Refused<'absent'> | Failure;
17
23
  export type BinaryAnswer = {
18
24
  kind: 'binary';
19
- blob: Blob;
25
+ stream: ReadableStream<Uint8Array>;
26
+ byteLength: number;
27
+ mediaType: string;
28
+ } | BinaryRefusal;
29
+ export type HeldBinaryAnswer = KeptBinary | BinaryRefusal;
30
+ export type BinaryLinkAnswer = {
31
+ kind: 'link';
32
+ url: string;
33
+ name: string;
34
+ mediaType: string;
20
35
  } | Refused<'rejected'> | Refused<'absent'> | Failure;
21
- export declare function absentBinary(path: string): BinaryAnswer;
22
- export declare function binaryAnswer(result: BinaryResult): BinaryAnswer;
36
+ export type HeldShownAnswer = KeptBinary | BinaryLinkAnswer;
37
+ export type ShownAnswer = BinaryAnswer | BinaryLinkAnswer;
38
+ export type AttachAnswer = {
39
+ kind: 'attached';
40
+ path: string;
41
+ } | Offline | Refused<'rejected'> | Failure;
42
+ export type DownloadAnswer = {
43
+ kind: 'started';
44
+ } | Refused<'rejected'> | Refused<'absent'> | Refused<'blocked'> | Failure;
45
+ export type Resolution = {
46
+ readonly kind: 'document';
47
+ readonly room: string;
48
+ readonly path: string;
49
+ } | {
50
+ readonly kind: 'deleted';
51
+ readonly room: string;
52
+ readonly path: string;
53
+ readonly revision: HistoryRevision;
54
+ } | Refused<'unreadable'> | Refused<'absent'> | Failure;
55
+ export declare const UNREADABLE: Refused<'unreadable'>;
56
+ export declare const LOCKED_UNREADABLE: Refused<'unreadable'>;
57
+ export declare const ABSENT_TARGET: Refused<'absent'>;
58
+ export declare function absentBinary(path: string): Refused<'absent'>;
59
+ export declare function binaryAnswer(result: KeptResult): HeldBinaryAnswer;
60
+ export declare function binaryLinkAnswer(result: BinaryLinkResult, held?: string): BinaryLinkAnswer;
61
+ export declare function attachAnswer(result: AttachResult): AttachAnswer;
62
+ export declare const ROOM_LOCKED = "room-locked";
63
+ export declare function lockedRoom(locator: string): Refused<'room-locked'> & {
64
+ locator: string;
65
+ };
23
66
  export type Offline = {
24
67
  readonly kind: 'offline';
25
68
  };
26
69
  export declare const OFFLINE: Offline;
70
+ export declare function answeredResult(value: unknown): boolean;
27
71
  export declare const UNCERTAIN: Failure;
28
72
  export declare function undeclared(name: string): CallResult;
29
73
  export declare function failure(result: AdapterFailure): Failure;
@@ -39,8 +83,5 @@ export type QueueEntry = {
39
83
  readonly batch: ChangeBatch;
40
84
  } & (Submission | {
41
85
  readonly state: 'local';
42
- } | {
43
- readonly state: 'accepted';
44
- readonly roomVersion: string;
45
86
  });
46
87
  export {};
@@ -1,8 +1,10 @@
1
1
  import type { BinaryFile, HeadChange } from './adapter.js';
2
+ import { type Composition } from './collection.js';
2
3
  import type { ChangeBatch } from './change.js';
3
4
  export type Heads = {
4
5
  revisions: Readonly<Record<string, string>>;
5
6
  fileIds: Readonly<Record<string, string>>;
7
+ created: Readonly<Record<string, string>>;
6
8
  changes: Readonly<Record<string, HeadChange>>;
7
9
  };
8
10
  export type HeldBinary = ({
@@ -18,10 +20,7 @@ export type Layer = Heads & {
18
20
  documents: Readonly<Record<string, string>>;
19
21
  binaries: Readonly<Record<string, HeldBinary>>;
20
22
  };
21
- export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Record<string, HeldBinary>;
23
+ export declare function acceptedBinaries(files: Readonly<Record<string, BinaryFile>>): Generator<readonly [string, HeldBinary]>;
22
24
  export declare function sameBinary(left: HeldBinary | undefined, right: HeldBinary | undefined): boolean;
23
25
  export declare function sameChange(left: HeadChange | undefined, right: HeadChange | undefined): boolean;
24
- export declare function overlay(base: Layer, queue: readonly ChangeBatch[], unapplied?: () => void): Layer;
25
- export declare function sameLayerText(left: Layer, right: Layer): boolean;
26
- export declare function changedPaths(left: Layer, right: Layer): ReadonlySet<string>;
27
- export declare function overlayChanged(base: Layer, queue: readonly ChangeBatch[], previousBase: Layer, previousQueue: readonly ChangeBatch[], previousVisible: Layer): Layer;
26
+ export declare function overlaying(base: Layer, queue: readonly ChangeBatch[], composition: Composition, unapplied?: () => void): Generator<number, Layer, void>;