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

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 (60) hide show
  1. package/README.md +9 -7
  2. package/dist/calls.d.ts +747 -0
  3. package/dist/calls.js +1 -0
  4. package/dist/index.d.ts +44 -6
  5. package/dist/mdmodel/blocks.d.ts +10 -0
  6. package/dist/mdmodel/condition.d.ts +167 -0
  7. package/dist/mdmodel/definition.d.ts +81 -0
  8. package/dist/mdmodel/divide.d.ts +2 -0
  9. package/dist/mdmodel/document.d.ts +15 -0
  10. package/dist/mdmodel/fields.d.ts +5 -0
  11. package/dist/mdmodel/index.d.ts +20 -0
  12. package/dist/mdmodel/links.d.ts +28 -0
  13. package/dist/mdmodel/paths.d.ts +25 -0
  14. package/dist/mdmodel/profile.d.ts +5 -0
  15. package/dist/mdmodel/project.d.ts +21 -0
  16. package/dist/mdmodel/references.d.ts +3 -0
  17. package/dist/mdmodel/types.d.ts +167 -0
  18. package/dist/mdmodel/validate.d.ts +31 -0
  19. package/dist/mdmodel/version.d.ts +1 -0
  20. package/dist/mdmodel/yaml.d.ts +55 -0
  21. package/dist/mdruntime/adapter.d.ts +517 -0
  22. package/dist/mdruntime/binary.d.ts +17 -0
  23. package/dist/mdruntime/chain.d.ts +10 -0
  24. package/dist/mdruntime/change-set.d.ts +27 -0
  25. package/dist/mdruntime/change.d.ts +118 -0
  26. package/dist/mdruntime/client.d.ts +90 -0
  27. package/dist/mdruntime/collection.d.ts +27 -0
  28. package/dist/mdruntime/compile.d.ts +15 -0
  29. package/dist/mdruntime/connection.d.ts +152 -0
  30. package/dist/mdruntime/conversation.d.ts +113 -0
  31. package/dist/mdruntime/durability.d.ts +11 -0
  32. package/dist/mdruntime/failure.d.ts +12 -0
  33. package/dist/mdruntime/fulltext.d.ts +26 -0
  34. package/dist/mdruntime/identity.d.ts +6 -0
  35. package/dist/mdruntime/media.d.ts +7 -0
  36. package/dist/mdruntime/messages.d.ts +27 -0
  37. package/dist/mdruntime/model.d.ts +62 -0
  38. package/dist/mdruntime/observation.d.ts +44 -0
  39. package/dist/mdruntime/open.d.ts +1 -0
  40. package/dist/mdruntime/opened.d.ts +21 -0
  41. package/dist/mdruntime/outcome.d.ts +84 -0
  42. package/dist/mdruntime/overlay.d.ts +24 -0
  43. package/dist/mdruntime/query.d.ts +283 -0
  44. package/dist/mdruntime/reach.d.ts +53 -0
  45. package/dist/mdruntime/readiness.d.ts +51 -0
  46. package/dist/mdruntime/recovery.d.ts +25 -0
  47. package/dist/mdruntime/replica.d.ts +67 -0
  48. package/dist/mdruntime/room-draft.d.ts +173 -0
  49. package/dist/mdruntime/save.d.ts +102 -0
  50. package/dist/mdruntime/search.d.ts +72 -0
  51. package/dist/mdruntime/seed.d.ts +15 -0
  52. package/dist/mdruntime/status.d.ts +27 -0
  53. package/dist/mdruntime/store.d.ts +153 -0
  54. package/dist/mdruntime/stored.d.ts +129 -0
  55. package/dist/mdruntime/tables.d.ts +324 -0
  56. package/dist/mdruntime/wire.d.ts +238 -0
  57. package/dist/test-host.d.ts +8 -2
  58. package/dist/test-host.js +47 -11
  59. package/docs/families.md +55 -12
  60. package/package.json +8 -6
@@ -0,0 +1,118 @@
1
+ import type { BinaryFile, HeadChange } from './adapter.js';
2
+ export type Change = {
3
+ readonly kind: 'field';
4
+ readonly path: string;
5
+ readonly name: string;
6
+ readonly value: unknown;
7
+ } | {
8
+ readonly kind: 'section';
9
+ readonly path: string;
10
+ readonly name: string;
11
+ readonly value: string;
12
+ } | {
13
+ readonly kind: 'preamble';
14
+ readonly path: string;
15
+ readonly value: string;
16
+ } | {
17
+ readonly kind: 'create';
18
+ readonly path: string;
19
+ readonly fields: Readonly<Record<string, unknown>>;
20
+ readonly sections: Readonly<Record<string, string>>;
21
+ } | {
22
+ readonly kind: 'create';
23
+ readonly path: string;
24
+ readonly content: string;
25
+ } | {
26
+ readonly kind: 'replace';
27
+ readonly path: string;
28
+ readonly content: string;
29
+ } | {
30
+ readonly kind: 'binary';
31
+ readonly path: string;
32
+ readonly localId: string;
33
+ readonly byteLength: number;
34
+ readonly mediaType: string;
35
+ readonly sha256: string;
36
+ } | {
37
+ readonly kind: 'move';
38
+ readonly path: string;
39
+ readonly to: string;
40
+ } | {
41
+ readonly kind: 'remove';
42
+ readonly path: string;
43
+ } | (Arriving & {
44
+ readonly content: string;
45
+ }) | (Arriving & {
46
+ readonly binary: BinaryFile;
47
+ });
48
+ type Arriving = {
49
+ readonly kind: 'arrival';
50
+ readonly path: string;
51
+ readonly revision?: string;
52
+ readonly fileId?: string;
53
+ readonly change?: HeadChange;
54
+ };
55
+ export type RoomMove = {
56
+ readonly source: {
57
+ readonly room: string;
58
+ readonly baseRoomVersion: string;
59
+ };
60
+ readonly destination: {
61
+ readonly room: string;
62
+ readonly baseRoomVersion: string;
63
+ readonly handle: string;
64
+ };
65
+ readonly moves: readonly {
66
+ readonly path: string;
67
+ readonly to: string;
68
+ }[];
69
+ };
70
+ export type Precondition = {
71
+ readonly kind: 'field';
72
+ readonly path: string;
73
+ readonly name: string;
74
+ readonly value: unknown;
75
+ } | {
76
+ readonly kind: 'section';
77
+ readonly path: string;
78
+ readonly name: string;
79
+ readonly value: string;
80
+ } | {
81
+ readonly kind: 'preamble';
82
+ readonly path: string;
83
+ readonly value: string;
84
+ } | {
85
+ readonly kind: 'revision';
86
+ readonly path: string;
87
+ readonly revision: string;
88
+ } | {
89
+ readonly kind: 'content';
90
+ readonly path: string;
91
+ readonly content: string;
92
+ } | {
93
+ readonly kind: 'present';
94
+ readonly path: string;
95
+ } | {
96
+ readonly kind: 'absent';
97
+ readonly path: string;
98
+ };
99
+ export type WrittenBy = {
100
+ readonly app: string;
101
+ readonly release: string;
102
+ };
103
+ export type ChangeBatch = {
104
+ validation?: import('./model.js').ValidationReceipt;
105
+ readonly id: string;
106
+ readonly baseRoomVersion: string;
107
+ readonly changes: readonly Change[];
108
+ readonly preconditions: readonly Precondition[];
109
+ readonly writtenBy?: WrittenBy;
110
+ readonly between?: RoomMove;
111
+ };
112
+ export declare function immutable(batch: ChangeBatch): ChangeBatch;
113
+ export declare function partnerOf(batch: ChangeBatch, locator: string): string | null;
114
+ export declare function leaving(batch: ChangeBatch, locator: string): boolean;
115
+ export declare function landing(changes: readonly Change[], index: number, path: string): string | null;
116
+ export declare function departure(changes: readonly Change[], index: number): string;
117
+ export declare function queuedFile(batch: ChangeBatch, path: string, localId: string): number;
118
+ export {};
@@ -0,0 +1,90 @@
1
+ import type { AppRoom, ConnectionRefusal, HistoryQuery, RoomSchemas, SavedParts, SavedRoomDraft, SaveResult } from './connection.js';
2
+ import type { Member, ServiceMode } from './adapter.js';
3
+ import type { ChatDraft, ConversationAgent, ConversationEntry, ConversationOptions, ConversationView } from './conversation.js';
4
+ import { type Observation } from './observation.js';
5
+ import type { AttachAnswer, BinaryAnswer, CallResult, DownloadAnswer, HistoryAnswer, Offline, QueueEntry, Resolution } from './outcome.js';
6
+ import type { DocumentQuery, DocumentResult, GroupQuery, GroupResult, PendingResult } from './query.js';
7
+ import type { RoomDraft, RoomDraftParts, RoomDraftWrite } from './room-draft.js';
8
+ import type { SearchRequest, SearchResult } from './search.js';
9
+ import type { Readiness } from './readiness.js';
10
+ import type { SyncStatus } from './status.js';
11
+ import { type RuntimePort } from './wire.js';
12
+ export type MdRuntimeClient = {
13
+ rooms(): Promise<readonly AppRoom[]>;
14
+ query: {
15
+ (query: DocumentQuery): Promise<DocumentResult | PendingResult>;
16
+ (query: GroupQuery): Promise<GroupResult | PendingResult>;
17
+ };
18
+ search(request: SearchRequest): Promise<SearchResult>;
19
+ types(locator: string): Promise<RoomSchemas>;
20
+ roomDraft: {
21
+ list(): Promise<readonly RoomDraft[]>;
22
+ read(room: string, path: string): Promise<RoomDraft | null>;
23
+ write(room: string, path: string, revision: string | null, parts: RoomDraftParts, next?: string): Promise<RoomDraftWrite>;
24
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
25
+ };
26
+ save(room: string, roomDrafts: readonly SavedRoomDraft[]): Promise<SaveResult>;
27
+ saveParts(room: string, parts: readonly SavedParts[]): Promise<SaveResult>;
28
+ presentation: {
29
+ read(): Promise<unknown>;
30
+ write(value: unknown): Promise<void>;
31
+ edit(members: Readonly<Record<string, unknown>>): Promise<void>;
32
+ };
33
+ conversation: {
34
+ list(): Promise<readonly ConversationEntry[]>;
35
+ read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
36
+ create(input: unknown): Promise<CallResult>;
37
+ send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
38
+ answer(conversation: string, answer: unknown): Promise<CallResult>;
39
+ interrupt(conversation: string): Promise<CallResult>;
40
+ kill(conversation: string): Promise<CallResult>;
41
+ cancel(conversation: string, turn: string): Promise<CallResult>;
42
+ delete(conversation: string): Promise<CallResult>;
43
+ };
44
+ chatDraft: {
45
+ write(conversation: string, draft: ChatDraft, revision?: string): Promise<void>;
46
+ prepend(conversation: string, draft: ChatDraft): Promise<void>;
47
+ discard(conversation: string): Promise<void>;
48
+ };
49
+ history(locator: string, path: string, query?: HistoryQuery): Promise<HistoryAnswer>;
50
+ resolve(room: string, path: string, destination: string): Promise<Resolution>;
51
+ binaryFile: {
52
+ read(room: string, path: string, revision?: string): Promise<BinaryAnswer>;
53
+ attach(room: string, file: File): Promise<AttachAnswer>;
54
+ download(room: string, path: string, revision?: string): Promise<DownloadAnswer>;
55
+ };
56
+ call(name: string, input: unknown): Promise<CallResult>;
57
+ reached(locator: string, roomVersion: string, path?: string): Promise<boolean>;
58
+ log(): Promise<string>;
59
+ persistence(): Promise<boolean>;
60
+ retry(): Promise<void>;
61
+ cleanUp(): Promise<number>;
62
+ observe: {
63
+ (topic: 'deployment-facts'): Promise<Observation<unknown>>;
64
+ (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
65
+ (topic: 'readiness'): Promise<Observation<Readiness>>;
66
+ (topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
67
+ (topic: 'storage-loss'): Promise<Observation<string | null>>;
68
+ (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
69
+ (topic: 'service-mode'): Promise<Observation<ServiceMode>>;
70
+ (topic: 'member'): Promise<Observation<Member | null>>;
71
+ (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
72
+ (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
73
+ (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
74
+ (topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
75
+ (topic: 'presentation'): Promise<Observation<unknown>>;
76
+ (topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
77
+ (topic: 'conversations'): Promise<Observation<readonly ConversationEntry[]>>;
78
+ (topic: 'agents'): Promise<Observation<readonly ConversationAgent[]>>;
79
+ };
80
+ reauthorize(): Promise<void>;
81
+ settled(): Promise<void>;
82
+ };
83
+ export declare function connectMdRuntime(port: RuntimePort): MdRuntimeClient;
84
+ export declare function inTurn(client: MdRuntimeClient, work: () => Promise<void>): Promise<void>;
85
+ export { chainedWindows, type WindowAnswer, type WindowChain } from './chain.js';
86
+ export { roomDraftRevision } from './identity.js';
87
+ export { defineRoomMedia, ROOM_MEDIA } from './media.js';
88
+ export type { Observation } from './observation.js';
89
+ export type { Open } from './open.js';
90
+ export { unanswered, type RuntimePort, type WireMember } from './wire.js';
@@ -0,0 +1,27 @@
1
+ import { type Document } from '../mdmodel/index.js';
2
+ import type { ModelState } from './model.js';
3
+ import type { MdModelIdentity } from './adapter.js';
4
+ export declare const MD_MODEL: MdModelIdentity;
5
+ export type Collection = {
6
+ text: Readonly<Record<string, string>>;
7
+ composition: Composition;
8
+ document(path: string): Document | undefined;
9
+ };
10
+ export type Composition = {
11
+ model: ModelState;
12
+ selection: {
13
+ roots: readonly string[];
14
+ model: ModelState;
15
+ } | null;
16
+ };
17
+ export type Composed = {
18
+ readonly composition: Composition;
19
+ readonly fingerprint: string;
20
+ };
21
+ export declare function composedOf(composition: Composition): Composed;
22
+ export declare function selected(composition: Composition, path: string): boolean;
23
+ export declare function governing(composition: Composition, path: string): ModelState;
24
+ export declare function collectionOf(text: Readonly<Record<string, string>>, composition: Composition): Collection;
25
+ export declare function documentsOf(collection: Collection): Generator<number, Iterable<readonly [string, Document]>, void>;
26
+ export declare function validRoot(root: unknown): root is string;
27
+ export declare function available(composition: Composition): boolean;
@@ -0,0 +1,15 @@
1
+ import type { Plan, QueryRows } from './query.js';
2
+ import type { Connection, Value } from './tables.js';
3
+ export type QueryRoom = {
4
+ readonly locator: string;
5
+ readonly key: number;
6
+ };
7
+ export type Fragment = {
8
+ readonly sql: string;
9
+ readonly bind: readonly Value[];
10
+ };
11
+ export type QueryAnswer = QueryRows & {
12
+ readonly more?: string;
13
+ };
14
+ export declare function selected(connection: Connection, plan: Plan, rooms: readonly QueryRoom[]): Fragment;
15
+ export declare function answerQuery(connection: Connection, plan: Plan, rooms: readonly QueryRoom[], budget?: number | null): QueryAnswer;
@@ -0,0 +1,152 @@
1
+ import { type TypesResult } from './model.js';
2
+ import { type Observation } from './observation.js';
3
+ import { type DocumentQuery, type DocumentResult, type GroupQuery, type GroupResult, type PendingResult } from './query.js';
4
+ import { type EntrySeed } from './seed.js';
5
+ import { type SearchRequest, type SearchResult } from './search.js';
6
+ import { type Adapter, type Authorization, type Member, type ProviderRefusal, type ServiceMode } from './adapter.js';
7
+ import { type ChatDraftSurface, type ConversationAgent, type ConversationEntry, type ConversationOptions, type ConversationSurface, type ConversationView } from './conversation.js';
8
+ import { type WrittenBy } from './change.js';
9
+ import type { Open } from './open.js';
10
+ import { type AttachAnswer, type BinaryLinkAnswer, type CallResult, type HeldBinaryAnswer, type HeldShownAnswer, type HistoryAnswer, type QueueEntry, type Resolution } from './outcome.js';
11
+ import { type Recovery } from './recovery.js';
12
+ import { type SaveRefusal } from './save.js';
13
+ import { type RoomDraft, type RoomDraftParts, type RoomDraftWrite } from './room-draft.js';
14
+ 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';
17
+ import type { RuntimeDatabase } from './tables.js';
18
+ import { type NarrowedView, type PortReach, type RuntimeView } from './reach.js';
19
+ export type AppTypedSelection = {
20
+ roots: readonly string[];
21
+ model: TypesResult;
22
+ };
23
+ export type AppRoom = {
24
+ name: string;
25
+ locator: string;
26
+ handle: string;
27
+ operations: import('./adapter.js').OperationScopes;
28
+ replica: import('./adapter.js').ReplicaAdmission;
29
+ model: TypesResult;
30
+ typedSelection: AppTypedSelection | null;
31
+ providerOwnedPaths: readonly string[];
32
+ roomVersion: string | null;
33
+ documents: number;
34
+ synchronizationAvailable: boolean;
35
+ refusal: ProviderRefusal | null;
36
+ locked: boolean;
37
+ };
38
+ export type RoomSchemas = {
39
+ collection: TypesResult;
40
+ typedSelection: TypesResult | null;
41
+ };
42
+ type RefusalReason = 'missing-required-guarantee' | 'revoked-authorization';
43
+ export type ConnectionRefusalCode = Open<RefusalReason>;
44
+ export type ConnectionRefusal = {
45
+ code: ConnectionRefusalCode;
46
+ retryable: boolean;
47
+ reauthorizationOffered: boolean;
48
+ refusal: ProviderRefusal | null;
49
+ };
50
+ export type MdRuntimeOptions = {
51
+ adapter: Adapter;
52
+ shell: RuntimeShell;
53
+ database: RuntimeDatabase;
54
+ authorization?: Authorization;
55
+ signal?: AbortSignal;
56
+ recovery?: Recovery;
57
+ usableWhenHeld?: readonly string[];
58
+ };
59
+ export type SaveResult = {
60
+ outcome: 'saved';
61
+ identifier: string;
62
+ } | ({
63
+ outcome: 'refused';
64
+ } & SaveRefusal);
65
+ export type SavedRoomDraft = {
66
+ readonly path: string;
67
+ readonly revision: string;
68
+ };
69
+ export type SavedParts = {
70
+ readonly path: string;
71
+ readonly parts: RoomDraftParts;
72
+ };
73
+ export type RoomDraftSurface = {
74
+ list(): Promise<readonly RoomDraft[]>;
75
+ read(room: string, path: string): Promise<RoomDraft | null>;
76
+ write(room: string, path: string, revision: string | null, parts: unknown, next?: string): Promise<RoomDraftWrite>;
77
+ discard(room: string, path: string, revision: string): Promise<RoomDraftWrite>;
78
+ };
79
+ export type PresentationSurface = {
80
+ read(app: string): Promise<unknown>;
81
+ write(app: string, value: unknown): Promise<void>;
82
+ edit(app: string, members: Readonly<Record<string, unknown>>): Promise<void>;
83
+ };
84
+ export type BinaryFileSurface = {
85
+ read(room: string, path: string, revision?: string): Promise<HeldBinaryAnswer>;
86
+ link(room: string, path: string, revision?: string): Promise<BinaryLinkAnswer>;
87
+ show(room: string, path: string, revision?: string): Promise<HeldShownAnswer>;
88
+ attach(room: string, file: File): Promise<AttachAnswer>;
89
+ part(file: string, part: number): Promise<Uint8Array | null>;
90
+ };
91
+ export type HistoryQuery = {
92
+ revision?: string;
93
+ pageToken?: string;
94
+ };
95
+ export type MdRuntime = {
96
+ loaded(): Promise<void>;
97
+ rooms(): Promise<readonly AppRoom[]>;
98
+ query: {
99
+ (query: DocumentQuery): Promise<DocumentResult | PendingResult>;
100
+ (query: GroupQuery): Promise<GroupResult | PendingResult>;
101
+ };
102
+ search(request: SearchRequest): Promise<SearchResult>;
103
+ types(locator: string): RoomSchemas;
104
+ roomDraft: RoomDraftSurface;
105
+ conversation: ConversationSurface;
106
+ chatDraft: ChatDraftSurface;
107
+ presentation: PresentationSurface;
108
+ save(room: string, roomDrafts: readonly SavedRoomDraft[], writtenBy?: WrittenBy): Promise<SaveResult>;
109
+ saveParts(room: string, parts: readonly SavedParts[], writtenBy?: WrittenBy): Promise<SaveResult>;
110
+ history(locator: string, path: string, query?: HistoryQuery): Promise<HistoryAnswer>;
111
+ resolve(room: string, path: string, destination: string): Promise<Resolution>;
112
+ binaryFile: BinaryFileSurface;
113
+ call(name: string, input: unknown): Promise<CallResult>;
114
+ reached(locator: string, roomVersion: string, path?: string): Promise<boolean>;
115
+ log(): string;
116
+ persistence(): boolean;
117
+ retry(): Promise<void>;
118
+ cleanUp(): Promise<number>;
119
+ observe: {
120
+ (topic: 'rooms'): Promise<Observation<readonly AppRoom[]>>;
121
+ (topic: 'readiness'): Promise<Observation<Readiness>>;
122
+ (topic: 'connection-refusal'): Promise<Observation<ConnectionRefusal | null>>;
123
+ (topic: 'storage-loss'): Promise<Observation<string | null>>;
124
+ (topic: 'sync-status'): Promise<Observation<SyncStatus>>;
125
+ (topic: 'service-mode'): Promise<Observation<ServiceMode>>;
126
+ (topic: 'member'): Promise<Observation<Member | null>>;
127
+ (topic: 'query', query: DocumentQuery): Promise<Observation<DocumentResult | PendingResult>>;
128
+ (topic: 'query', query: GroupQuery): Promise<Observation<GroupResult | PendingResult>>;
129
+ (topic: 'queue', locator: string): Promise<Observation<readonly QueueEntry[]>>;
130
+ (topic: 'room-drafts'): Promise<Observation<readonly RoomDraft[]>>;
131
+ (topic: 'presentation', app: string): Promise<Observation<unknown>>;
132
+ (topic: 'conversation', conversation: string, options: ConversationOptions): Promise<Observation<ConversationView>>;
133
+ (topic: 'conversations'): Promise<Observation<readonly ConversationEntry[]>>;
134
+ (topic: 'agents'): Promise<Observation<readonly ConversationAgent[]>>;
135
+ };
136
+ reauthorize(): Promise<void>;
137
+ };
138
+ export type RuntimeTopic = 'rooms' | 'readiness' | 'connection-refusal' | 'storage-loss' | 'sync-status' | 'service-mode' | 'member' | 'query' | 'queue' | 'room-drafts' | 'presentation' | 'conversation' | 'conversations' | 'agents';
139
+ export type ReadinessPort = {
140
+ readonly target: string;
141
+ readonly code: CodeAvailability;
142
+ readonly space: Space | null;
143
+ readonly search: SearchObligation;
144
+ };
145
+ export type ComposedRuntime = RuntimeView & {
146
+ seed(entry: EntrySeed): void;
147
+ stop(): Promise<void>;
148
+ persisted(answer: Persistence): void;
149
+ within(reach: PortReach | null, port: ReadinessPort): NarrowedView;
150
+ };
151
+ export declare function composeRuntime(options: MdRuntimeOptions): ComposedRuntime;
152
+ export {};
@@ -0,0 +1,113 @@
1
+ import type { ConversationAction, ConversationEvent, ConversationMessage, ConversationStream, ListedConversation, ProcessCommand, SessionOption, TurnContext } from './adapter.js';
2
+ import { type ChangeSet } from './change-set.js';
3
+ import type { Open } from './open.js';
4
+ import { type CallResult, type Offline } from './outcome.js';
5
+ import type { CycleProgress } from './status.js';
6
+ import type { ChatDraftRecord, HeldConversation, RuntimeStore } from './store.js';
7
+ export type ConversationState = Open<'working' | 'asking' | 'idle'>;
8
+ export type ConversationEntry = {
9
+ conversation: string;
10
+ agent: {
11
+ identity: string;
12
+ name: string;
13
+ };
14
+ name: string;
15
+ created: string;
16
+ finished: string | null;
17
+ outcome: string | null;
18
+ waiting: boolean;
19
+ state: ConversationState;
20
+ started: string | null;
21
+ };
22
+ export type ConversationAgent = {
23
+ identity: string;
24
+ name: string;
25
+ };
26
+ export type RunningTurn = {
27
+ turn: string;
28
+ started: string | null;
29
+ parts: readonly unknown[];
30
+ context: TurnContext | null;
31
+ };
32
+ export type ChatDraft = {
33
+ text: string;
34
+ };
35
+ export type ConversationOptions = {
36
+ limit?: number;
37
+ after?: string;
38
+ total?: true;
39
+ };
40
+ export type ConversationView = {
41
+ conversation: string;
42
+ messages: readonly ConversationMessage[];
43
+ next?: string;
44
+ total?: number;
45
+ turn: RunningTurn | null;
46
+ questions: readonly unknown[];
47
+ process: {
48
+ running: boolean;
49
+ } | null;
50
+ commands: readonly ProcessCommand[];
51
+ options: readonly SessionOption[];
52
+ starting: string | null;
53
+ link: {
54
+ connected: boolean;
55
+ } | null;
56
+ deliveryUnknown: readonly string[];
57
+ chatDraft: (ChatDraft & {
58
+ readonly revision: string;
59
+ }) | null;
60
+ };
61
+ export type ConversationSurface = {
62
+ list(): Promise<readonly ConversationEntry[]>;
63
+ read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
64
+ create(input: unknown): Promise<CallResult>;
65
+ send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
66
+ answer(conversation: string, answer: unknown): Promise<CallResult>;
67
+ interrupt(conversation: string): Promise<CallResult>;
68
+ kill(conversation: string): Promise<CallResult>;
69
+ cancel(conversation: string, turn: string): Promise<CallResult>;
70
+ delete(conversation: string): Promise<CallResult>;
71
+ };
72
+ export type ChatDraftSurface = {
73
+ write(conversation: string, draft: ChatDraft, revision?: string): Promise<void>;
74
+ prepend(conversation: string, draft: ChatDraft): Promise<void>;
75
+ discard(conversation: string): Promise<void>;
76
+ };
77
+ export type ConversationDependencies = {
78
+ call(name: ConversationAction, input: unknown): Promise<CallResult>;
79
+ durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
80
+ stream(): ConversationStream | undefined;
81
+ publish(set: ChangeSet): void;
82
+ online(): boolean;
83
+ full(): boolean;
84
+ closed(): boolean;
85
+ unanswered(): void;
86
+ expired(operation: string): boolean;
87
+ };
88
+ export type ConversationStore = {
89
+ surface: ConversationSurface;
90
+ chatDraft: ChatDraftSurface;
91
+ hydrate(held: readonly HeldConversation[], drafts: readonly ChatDraftRecord[], list: readonly ListedConversation[] | null): void;
92
+ reconcile(): Promise<void>;
93
+ catchUp(progress: CycleProgress): Promise<void>;
94
+ resend(progress: CycleProgress): Promise<void>;
95
+ current(): boolean;
96
+ known(): boolean;
97
+ learned(): void;
98
+ reopened(): void;
99
+ lost(): void;
100
+ watch(conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
101
+ watchList(deliver: (entries: readonly ConversationEntry[]) => void): () => void;
102
+ watchAgents(deliver: (agents: readonly ConversationAgent[]) => void): () => void;
103
+ changed(set: ChangeSet): void;
104
+ receive(event: ConversationEvent): boolean;
105
+ searchable(): readonly string[];
106
+ acquired(conversation: string): boolean;
107
+ close(): void;
108
+ };
109
+ export declare function unheldView(conversation: string): ConversationView;
110
+ export declare const SESSION_STARTED = "Session started";
111
+ export declare const HISTORY_CONVERSATIONS = 64;
112
+ export declare function newChat(agent: string): string;
113
+ export declare function createConversationStore(deps: ConversationDependencies): ConversationStore;
@@ -0,0 +1,11 @@
1
+ import type { Persistence } from './readiness.js';
2
+ export type RuntimeShell = {
3
+ persistence: Persistence;
4
+ generation: string | null;
5
+ keepGeneration(value: string): void | Promise<void>;
6
+ dropGeneration(): void | Promise<void>;
7
+ cleanUp?(): Promise<number>;
8
+ };
9
+ export declare function refusedForSpace(error: unknown): boolean;
10
+ export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
11
+ export declare function nextGeneration(stored: string | null, reported: string | null): string;
@@ -0,0 +1,12 @@
1
+ export type RuntimeError = Error & {
2
+ readonly code: string;
3
+ readonly retryable: boolean;
4
+ };
5
+ export type Described = {
6
+ message: string;
7
+ code: string;
8
+ retryable: boolean;
9
+ };
10
+ export declare function runtimeError(code: string, message?: string, retryable?: boolean): RuntimeError;
11
+ export declare function failed(error: unknown): RuntimeError;
12
+ export declare function described(error: unknown): Described;
@@ -0,0 +1,26 @@
1
+ import { type QueryRoom } from './compile.js';
2
+ import type { Plan } from './query.js';
3
+ import type { HitCursor, SearchWindow } from './search.js';
4
+ import type { Connection } from './tables.js';
5
+ export declare const SEARCH_TABLES: readonly string[];
6
+ export type SearchAsk = {
7
+ readonly text: string;
8
+ readonly limit: number;
9
+ readonly after: readonly [HitCursor, HitCursor] | null;
10
+ readonly total: boolean;
11
+ readonly documents: {
12
+ readonly plan: Plan;
13
+ readonly rooms: readonly QueryRoom[];
14
+ readonly beneath: readonly {
15
+ readonly key: number;
16
+ readonly roots: readonly string[];
17
+ }[];
18
+ } | null;
19
+ readonly conversations: readonly string[];
20
+ };
21
+ export declare function indexDocument(connection: Connection, id: number, path: string, content: string): void;
22
+ export declare function indexMessage(connection: Connection, id: number, text: string): void;
23
+ export declare function unindexDocuments(connection: Connection, ids: Iterable<number>): void;
24
+ export declare function unindexMessages(connection: Connection, ids: Iterable<number>): void;
25
+ export declare function unindexAll(connection: Connection): void;
26
+ export declare function searched(connection: Connection, ask: SearchAsk): SearchWindow;
@@ -0,0 +1,6 @@
1
+ export declare function changeBatchIdentity(at?: number): string;
2
+ export declare function identityTime(identity: string): number;
3
+ export declare function roomDraftRevision(): string;
4
+ export declare function chatDraftRevision(): string;
5
+ export declare function transferIdentity(): string;
6
+ export declare function binaryLocalId(): string;
@@ -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, registry?: CustomElementRegistry): void;
7
+ export {};
@@ -0,0 +1,27 @@
1
+ import type { AcceptedMessage } from './adapter.js';
2
+ import type { Connection } from './tables.js';
3
+ export declare const MESSAGE_TABLES: readonly string[];
4
+ export type HeldConversation = {
5
+ readonly conversation: string;
6
+ readonly read: string | null | undefined;
7
+ readonly partial: boolean;
8
+ };
9
+ export type MessageWindow = {
10
+ readonly messages: AcceptedMessage[];
11
+ readonly more: boolean;
12
+ };
13
+ export type ConversationWrite = {
14
+ readonly conversation: string;
15
+ readonly messages: readonly AcceptedMessage[];
16
+ readonly read?: {
17
+ readonly at: string | null;
18
+ readonly partial: boolean;
19
+ };
20
+ };
21
+ export declare function heldConversations(connection: Connection): HeldConversation[];
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;
25
+ export declare function turnArrived(connection: Connection, conversation: string, turn: string): boolean;
26
+ export declare function droppedMessages(connection: Connection, conversations: readonly string[]): void;
27
+ export declare function forgottenMessages(connection: Connection): void;