@agentshouse/app-bridge 0.1.0-c8d8dc6285bbd → 0.1.0-c8dd3de04bf64

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 (95) hide show
  1. package/README.md +7 -7
  2. package/dist/index.d.ts +910 -19
  3. package/dist/mdmodel/definition.d.ts +1 -1
  4. package/dist/mdmodel/document.d.ts +2 -1
  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 -7
  8. package/dist/mdmodel/kinds.d.ts +17 -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 +5 -0
  15. package/dist/mdmodel/types.d.ts +11 -0
  16. package/dist/mdmodel/validate.d.ts +7 -5
  17. package/dist/mdruntime/actions.d.ts +19 -0
  18. package/dist/mdruntime/adapter.d.ts +107 -71
  19. package/dist/mdruntime/attached-model.d.ts +7 -0
  20. package/dist/mdruntime/bootstrap.d.ts +43 -0
  21. package/dist/mdruntime/cell.d.ts +5 -0
  22. package/dist/mdruntime/chain.d.ts +2 -1
  23. package/dist/mdruntime/change.d.ts +1 -0
  24. package/dist/mdruntime/client.d.ts +28 -11
  25. package/dist/mdruntime/collection.d.ts +7 -4
  26. package/dist/mdruntime/compile.d.ts +6 -6
  27. package/dist/mdruntime/conversation-live.d.ts +135 -0
  28. package/dist/mdruntime/conversation-row.d.ts +32 -0
  29. package/dist/mdruntime/conversation.d.ts +41 -45
  30. package/dist/mdruntime/durability.d.ts +15 -1
  31. package/dist/mdruntime/figures.d.ts +48 -0
  32. package/dist/mdruntime/holdings.d.ts +28 -0
  33. package/dist/mdruntime/identity.d.ts +0 -1
  34. package/dist/mdruntime/install.d.ts +55 -0
  35. package/dist/mdruntime/job.d.ts +32 -0
  36. package/dist/mdruntime/listing.d.ts +52 -0
  37. package/dist/mdruntime/live.d.ts +22 -0
  38. package/dist/mdruntime/log.d.ts +5 -0
  39. package/dist/mdruntime/media.d.ts +7 -0
  40. package/dist/mdruntime/messages.d.ts +27 -3
  41. package/dist/mdruntime/model.d.ts +8 -10
  42. package/dist/mdruntime/observation.d.ts +3 -2
  43. package/dist/mdruntime/outcome.d.ts +17 -6
  44. package/dist/mdruntime/overlay.d.ts +1 -0
  45. package/dist/mdruntime/preparation.d.ts +19 -0
  46. package/dist/mdruntime/query.d.ts +18 -208
  47. package/dist/mdruntime/reach.d.ts +20 -11
  48. package/dist/mdruntime/readiness.d.ts +3 -18
  49. package/dist/mdruntime/reads.d.ts +36 -0
  50. package/dist/mdruntime/recovery.d.ts +1 -0
  51. package/dist/mdruntime/refresh.d.ts +26 -0
  52. package/dist/mdruntime/replica.d.ts +11 -12
  53. package/dist/mdruntime/room-draft.d.ts +21 -7
  54. package/dist/mdruntime/room-drafts.d.ts +23 -0
  55. package/dist/mdruntime/runtime.d.ts +42 -0
  56. package/dist/mdruntime/save.d.ts +7 -1
  57. package/dist/mdruntime/saves.d.ts +69 -0
  58. package/dist/mdruntime/search.d.ts +12 -63
  59. package/dist/mdruntime/seed.d.ts +11 -2
  60. package/dist/mdruntime/socket/admission.d.ts +6 -0
  61. package/dist/mdruntime/socket/answers.d.ts +5 -0
  62. package/dist/mdruntime/socket/lanes.d.ts +19 -0
  63. package/dist/mdruntime/socket/rooms.d.ts +43 -0
  64. package/dist/mdruntime/socket/session.d.ts +37 -0
  65. package/dist/mdruntime/socket.d.ts +69 -0
  66. package/dist/mdruntime/source.d.ts +60 -0
  67. package/dist/mdruntime/status.d.ts +4 -5
  68. package/dist/mdruntime/store/fences.d.ts +15 -0
  69. package/dist/mdruntime/store/installs.d.ts +29 -0
  70. package/dist/mdruntime/store/readiness.d.ts +9 -0
  71. package/dist/mdruntime/store/records.d.ts +211 -0
  72. package/dist/mdruntime/store/room-held.d.ts +7 -0
  73. package/dist/mdruntime/store/space.d.ts +10 -0
  74. package/dist/mdruntime/store/watchers.d.ts +16 -0
  75. package/dist/mdruntime/store/writes.d.ts +23 -0
  76. package/dist/mdruntime/store.d.ts +105 -158
  77. package/dist/mdruntime/stored.d.ts +66 -55
  78. package/dist/mdruntime/surface.d.ts +87 -0
  79. package/dist/mdruntime/tables.d.ts +131 -69
  80. package/dist/mdruntime/tallies.d.ts +17 -0
  81. package/dist/mdruntime/transfer.d.ts +0 -5
  82. package/dist/mdruntime/turn.d.ts +8 -0
  83. package/dist/mdruntime/wire.d.ts +25 -9
  84. package/dist/test-host.d.ts +1 -4
  85. package/dist/test-host.js +2 -28
  86. package/docs/families.md +49 -53
  87. package/package.json +1 -1
  88. package/dist/calls.d.ts +0 -1007
  89. package/dist/calls.js +0 -1
  90. package/dist/mdmodel/condition.d.ts +0 -160
  91. package/dist/mdmodel/profile.d.ts +0 -5
  92. package/dist/mdruntime/connection.d.ts +0 -151
  93. package/dist/mdruntime/file.d.ts +0 -11
  94. package/dist/mdruntime/fulltext.d.ts +0 -26
  95. package/dist/mdruntime/shared.d.ts +0 -15
@@ -0,0 +1,135 @@
1
+ import type { AcceptedMessage, ConversationAction, ConversationHistoryRequest, ConversationStream, ListedAgent, ListedConversation, ProcessCommand, RunningSubagent, SessionOption } from './adapter.js';
2
+ import { type Cell } from './cell.js';
3
+ import type { ChangeSet } from './change-set.js';
4
+ import type { Asked, ConversationAgent, ConversationEntry, ConversationView, RunningTurn } from './conversation.js';
5
+ import type { JobMarker } from './job.js';
6
+ import type { CallResult } from './outcome.js';
7
+ import type { Recovery } from './recovery.js';
8
+ import type { ChatDraftRecord, RuntimeStore } from './store.js';
9
+ export type ConversationDependencies = {
10
+ call(name: ConversationAction, input: unknown): Promise<CallResult>;
11
+ history(request: ConversationHistoryRequest): Promise<CallResult>;
12
+ durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
13
+ local(): Promise<RuntimeStore>;
14
+ again(): void;
15
+ settled(): void;
16
+ stream(): ConversationStream | undefined;
17
+ publish(set: ChangeSet): void;
18
+ online(): boolean;
19
+ full(): boolean;
20
+ closed(): boolean;
21
+ unanswered(): void;
22
+ readonly recovery: Recovery;
23
+ };
24
+ export type Live = {
25
+ turn: RunningTurn | null;
26
+ questions: readonly unknown[];
27
+ process: {
28
+ running: boolean;
29
+ } | null;
30
+ commands: readonly ProcessCommand[];
31
+ options: readonly SessionOption[];
32
+ starting: string | null;
33
+ subagents: readonly RunningSubagent[];
34
+ link: {
35
+ connected: boolean;
36
+ } | null;
37
+ deliveryUnknown: readonly string[];
38
+ };
39
+ export declare const QUIET: Live;
40
+ export type Fact = Exclude<keyof Live, 'turn'>;
41
+ export declare const FACTS: readonly Fact[];
42
+ type Watcher = {
43
+ readonly notify: (view: ConversationView) => void;
44
+ };
45
+ type HeldWindow = {
46
+ readonly window: readonly AcceptedMessage[] | null;
47
+ readonly draft: ChatDraftRecord | null;
48
+ readonly ended: string | null;
49
+ readonly marked: readonly JobMarker[];
50
+ readonly more: boolean;
51
+ readonly total: number | null;
52
+ };
53
+ export type SharedView = {
54
+ readonly conversation: string;
55
+ readonly asked: Asked;
56
+ readonly held: Cell<HeldWindow>;
57
+ ready(): readonly Watcher[];
58
+ join(watcher: Watcher): void;
59
+ admit(watcher: Watcher): boolean;
60
+ leave(watcher: Watcher): boolean;
61
+ empty(): boolean;
62
+ };
63
+ type Listing<T> = (value: T) => void;
64
+ export type Audience<T> = {
65
+ waiting(): boolean;
66
+ told(): boolean;
67
+ join(watcher: Listing<T>): void;
68
+ leave(watcher: Listing<T>): void;
69
+ tell(value: T): void;
70
+ welcome(value: T): void;
71
+ clear(): void;
72
+ };
73
+ type HeldFacts = {
74
+ readonly listKnown: boolean;
75
+ readonly listOwed: boolean;
76
+ readonly listTelling: boolean;
77
+ readonly agentsShown: string | null;
78
+ readonly listedAgents: readonly ListedAgent[] | null;
79
+ readonly agentsReading: boolean;
80
+ readonly replicated: ReadonlySet<string>;
81
+ readonly handedReplicated: string | undefined;
82
+ };
83
+ export type Dispatch = Cell<{
84
+ readonly answered: boolean;
85
+ }>;
86
+ export type LiveConversations = {
87
+ readonly deps: ConversationDependencies;
88
+ readonly held: Cell<HeldFacts>;
89
+ readonly closing: AbortSignal;
90
+ readonly listeners: Audience<readonly ConversationEntry[]>;
91
+ readonly agentListeners: Audience<readonly ConversationAgent[]>;
92
+ views(): Iterable<SharedView>;
93
+ viewJoined(key: string, conversation: string, asked: Asked, notify: (view: ConversationView) => void): {
94
+ readonly view: SharedView;
95
+ readonly watcher: Watcher;
96
+ };
97
+ viewLeft(key: string, view: SharedView, watcher: Watcher): void;
98
+ liveOf(conversation: string): Live;
99
+ liveHeld(conversation: string): Live | undefined;
100
+ holdLive(conversation: string, next: Live | null): void;
101
+ factsOwed(conversation: string): void;
102
+ factsHeard(conversation: string, facts: readonly Fact[]): void;
103
+ factsTaken(): readonly (readonly [string, ReadonlySet<Fact>])[];
104
+ behind(conversation: string): boolean;
105
+ behindAll(): readonly string[];
106
+ fellBehind(conversation: string): void;
107
+ caughtUpTo(conversation: string): void;
108
+ gapOpened(conversation: string): void;
109
+ generation(conversation: string): number;
110
+ heardAt(conversation: string, position: string): void;
111
+ newestHeard(conversation: string): string | undefined;
112
+ catching(conversation: string): Promise<void> | undefined;
113
+ catchingUntil(conversation: string, ended: Promise<void>): void;
114
+ creating(conversation: string): void;
115
+ created(conversation: string): void;
116
+ isCreating(conversation: string): boolean;
117
+ relisting(): boolean;
118
+ relistBegun(): void;
119
+ relistHeard(entries: readonly ListedConversation[]): void;
120
+ relistDropped(conversation: string): void;
121
+ relistTaken(): ReadonlyMap<string, ListedConversation> | null;
122
+ sendingBegan(operation: string): Dispatch;
123
+ sendingEnded(operation: string, dispatch: Dispatch): void;
124
+ sending(operation: string): boolean;
125
+ rowSoon(tell: () => void): void;
126
+ inOrder(work: () => Promise<void>): void;
127
+ forget(conversation: string): void;
128
+ current(): boolean;
129
+ known(): boolean;
130
+ reopened(): void;
131
+ lost(): void;
132
+ close(): void;
133
+ };
134
+ export declare function createLiveConversations(deps: ConversationDependencies): LiveConversations;
135
+ export {};
@@ -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,17 +1,19 @@
1
- import type { ConversationAction, ConversationAgents, ConversationEvent, ConversationMessage, ConversationStream, ProcessCommand, SessionOption, TurnContext } from './adapter.js';
1
+ import type { ConversationEvent, ConversationMessage, ProcessCommand, RunningSubagent, SessionOption, TurnContext } from './adapter.js';
2
2
  import { type ChangeSet } from './change-set.js';
3
- import { type ChosenFile } from './file.js';
3
+ import { type LiveConversations } from './conversation-live.js';
4
+ import { type ConversationHeld } from './conversation-row.js';
5
+ import type { OpenJob } from './job.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;
@@ -20,6 +22,9 @@ export type ConversationEntry = {
20
22
  waiting: boolean;
21
23
  state: ConversationState;
22
24
  started: string | null;
25
+ line: string | null;
26
+ question: string | null;
27
+ asked: string | null;
23
28
  };
24
29
  export type ConversationAgent = {
25
30
  identity: string;
@@ -39,6 +44,9 @@ export type ConversationOptions = {
39
44
  after?: string;
40
45
  total?: true;
41
46
  };
47
+ export type ConversationRead = ConversationOptions & {
48
+ text?: string;
49
+ };
42
50
  export type ConversationView = {
43
51
  conversation: string;
44
52
  messages: readonly ConversationMessage[];
@@ -49,9 +57,11 @@ export type ConversationView = {
49
57
  process: {
50
58
  running: boolean;
51
59
  } | null;
60
+ processEnded: string | null;
52
61
  commands: readonly ProcessCommand[];
53
62
  options: readonly SessionOption[];
54
63
  starting: string | null;
64
+ subagents: readonly RunningSubagent[];
55
65
  link: {
56
66
  connected: boolean;
57
67
  } | null;
@@ -59,60 +69,46 @@ export type ConversationView = {
59
69
  chatDraft: (ChatDraft & {
60
70
  readonly revision: string;
61
71
  }) | null;
72
+ jobs: readonly OpenJob[];
62
73
  };
63
74
  export type ConversationSurface = {
64
75
  list(): Promise<readonly ConversationEntry[]>;
65
- read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
76
+ read(conversation: string, options?: ConversationRead): Promise<ConversationView>;
66
77
  create(input: unknown): Promise<CallResult>;
67
78
  send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
68
- attach(room: string, file: ChosenFile): Promise<CallResult | Offline>;
69
- answer(conversation: string, answer: unknown): Promise<CallResult>;
79
+ answer(conversation: string, answer: ConversationAnswer): Promise<CallResult>;
70
80
  interrupt(conversation: string): Promise<CallResult>;
71
81
  kill(conversation: string): Promise<CallResult>;
72
- cancel(conversation: string, turn: string): Promise<CallResult>;
73
82
  delete(conversation: string): Promise<CallResult>;
74
83
  };
84
+ export type ConversationAnswer = {
85
+ interaction_id: string;
86
+ response: unknown;
87
+ };
75
88
  export type ChatDraftSurface = {
76
89
  write(conversation: string, draft: ChatDraft, revision?: string): Promise<void>;
77
90
  prepend(conversation: string, draft: ChatDraft): Promise<void>;
78
91
  discard(conversation: string): Promise<void>;
79
92
  };
80
- export type ConversationDependencies = {
81
- agents(): ConversationAgents | undefined;
82
- documents(agents: ConversationAgents, after: string | undefined): Promise<DocumentResult | PendingResult>;
83
- call(name: ConversationAction, input: unknown): Promise<CallResult>;
84
- durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
85
- stream(): ConversationStream | undefined;
86
- publish(set: ChangeSet): void;
87
- online(): boolean;
88
- full(): boolean;
89
- closed(): boolean;
90
- unanswered(): void;
91
- expired(operation: string): boolean;
92
- };
93
- export type ConversationStore = {
94
- surface: ConversationSurface;
95
- chatDraft: ChatDraftSurface;
96
- hydrate(held: readonly HeldConversation[], drafts: readonly ChatDraftRecord[]): void;
97
- reconcile(): Promise<void>;
98
- catchUp(progress: CycleProgress): Promise<void>;
99
- resend(progress: CycleProgress): Promise<void>;
100
- current(): boolean;
101
- known(): boolean;
102
- reconnected(): void;
103
- reopened(): void;
104
- lost(): void;
105
- watch(conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
106
- watchList(deliver: (entries: readonly ConversationEntry[]) => void): () => void;
107
- watchAgents(deliver: (agents: readonly ConversationAgent[]) => void): () => void;
108
- changed(set: ChangeSet): void;
109
- receive(event: ConversationEvent): boolean;
110
- searchable(): readonly string[];
111
- acquired(conversation: string): boolean;
112
- close(): void;
113
- };
114
93
  export declare function unheldView(conversation: string): ConversationView;
115
94
  export declare const SESSION_STARTED = "Session started";
116
95
  export declare const HISTORY_CONVERSATIONS = 64;
117
96
  export declare function newChat(agent: string): string;
118
- export declare function createConversationStore(deps: ConversationDependencies): ConversationStore;
97
+ export type Asked = {
98
+ limit: number;
99
+ after: string | undefined;
100
+ before: readonly [string, string] | null;
101
+ total: boolean;
102
+ };
103
+ export declare function conversationsLearned(alive: LiveConversations): void;
104
+ export declare function conversationSurface(alive: LiveConversations): ConversationSurface;
105
+ export declare function chatDraftSurface(alive: LiveConversations): ChatDraftSurface;
106
+ export declare function conversationsOpened(alive: LiveConversations, local: RuntimeStore): Promise<void>;
107
+ export declare function reconcileConversations(alive: LiveConversations): Promise<void>;
108
+ export declare function catchUpConversations(alive: LiveConversations, progress: CycleProgress): Promise<void>;
109
+ export declare function resendConversations(alive: LiveConversations, progress: CycleProgress): Promise<void>;
110
+ export declare function watchConversation(alive: LiveConversations, conversation: string, options: ConversationOptions, deliver: (view: ConversationView) => void): () => void;
111
+ export declare function watchConversationList(alive: LiveConversations, deliver: (entries: readonly ConversationEntry[]) => void): () => void;
112
+ export declare function watchConversationAgents(alive: LiveConversations, deliver: (agents: readonly ConversationAgent[]) => void): () => void;
113
+ export declare function conversationsChanged(alive: LiveConversations, set: ChangeSet): void;
114
+ export declare function receiveConversationEvent(alive: LiveConversations, event: ConversationEvent): void;
@@ -1,11 +1,25 @@
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
+ };
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[];
14
+ };
2
15
  export type RuntimeShell = {
3
16
  persistence: Persistence;
4
17
  generation: string | null;
5
- onScreen: boolean;
6
18
  keepGeneration(value: string): void | Promise<void>;
7
19
  dropGeneration(): void | Promise<void>;
8
20
  cleanUp?(): Promise<number>;
21
+ measure?(measured: (app: string, code: AppCode | null) => void): Promise<HeldCode>;
22
+ reset(): Promise<void>;
9
23
  };
10
24
  export declare function refusedForSpace(error: unknown): boolean;
11
25
  export declare function detectStorageLoss(stored: string | null, reported: string | null): string | null;
@@ -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;
@@ -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,55 @@
1
+ import type { AdapterFailure, Authorization, DiscoveredRoom, NotReady, RetryableRefusal } from './adapter.js';
2
+ import { type Reads } from './bootstrap.js';
3
+ import type { Installation, RoomCoverage } from './readiness.js';
4
+ import { advancement, type Refresher } from './refresh.js';
5
+ import type { ReplicaRecord } from './replica.js';
6
+ import type { Runtime } from './runtime.js';
7
+ import type { Live } from './socket.js';
8
+ import { type CoveredRoom, type InstallHold, type RuntimeStore, type Store } from './store.js';
9
+ import { type Unconfirmed } from './transfer.js';
10
+ type Standing = {
11
+ readonly key: number | null;
12
+ readonly confirmed: number;
13
+ };
14
+ export type Unheld = {
15
+ readonly staged: boolean;
16
+ };
17
+ export type Withheld = AdapterFailure | RetryableRefusal | NotReady | Unconfirmed;
18
+ type Landing = {
19
+ readonly kind: 'refreshed';
20
+ readonly from: Standing;
21
+ readonly remodelled: boolean;
22
+ } | {
23
+ readonly kind: 'bootstrapped';
24
+ readonly refreshed: boolean;
25
+ readonly from: Standing;
26
+ };
27
+ type Refreshed = {
28
+ kind: 'advanced';
29
+ record: ReplicaRecord;
30
+ from: Standing;
31
+ remodelled: boolean;
32
+ } | Exclude<Awaited<ReturnType<typeof advancement>>, {
33
+ kind: 'advanced';
34
+ }>;
35
+ export declare const ERASE_BATCH = 512;
36
+ export declare function installationOf(store: Store, coverage: readonly RoomCoverage[], held: ReadonlyMap<string, CoveredRoom>): Installation;
37
+ export declare function roomInFlight(store: Store, locator: string): boolean;
38
+ export declare function sweep({ store, socket, journal }: Runtime): void;
39
+ export declare function forgetInstall(store: Store, locator: string): void;
40
+ export declare function caughtUpTo(runtime: Runtime, locator: string): void;
41
+ export declare function catching(store: Store, locator: string): void;
42
+ export declare function confirmedAgain(store: Store, locator: string): void;
43
+ export declare function standingAt(store: Store, locator: string, held: Pick<ReplicaRecord, 'key'> | undefined): Standing;
44
+ export declare function showing(system: Runtime, locator: string, roomVersion: string, held: string | undefined): void;
45
+ export declare function olderThan(system: Runtime, locator: string, roomVersion: string, held: string | undefined): boolean;
46
+ export declare function replaced(store: Store, locators: readonly string[]): void;
47
+ export declare function reachedBy({ store, socket }: Runtime, locator: string, roomVersion: string): Promise<boolean>;
48
+ export declare function behind({ store, socket }: Runtime, room: DiscoveredRoom): Promise<boolean>;
49
+ export declare function writtenAfter({ store, socket }: Runtime, locator: string, roomVersion: string, path: string): Promise<boolean>;
50
+ export declare function pullRefresh(runtime: Runtime, authorized: Authorization, record: ReplicaRecord, liveness: Live, hold: InstallHold, refresh: Refresher): Promise<Refreshed>;
51
+ export declare function pullBootstrap(runtime: Runtime, authorized: Authorization, room: DiscoveredRoom, local: RuntimeStore, liveness: Live, prior: ReplicaRecord | undefined, from?: Reads, unheld?: Unheld): Promise<import("./bootstrap.js").Bootstrapped | NotReady | import("./adapter.js").RevokedAuthorization | import("./adapter.js").RoomNotReadable | Unconfirmed | {
52
+ readonly kind: 'transport-uncertainty';
53
+ } | RetryableRefusal | import("./adapter.js").ScopedRefusal>;
54
+ export declare function publish(runtime: Runtime, local: RuntimeStore, room: DiscoveredRoom, reached: ReplicaRecord, landing: Landing, live: Live): Promise<boolean>;
55
+ export {};
@@ -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 {};
@@ -0,0 +1,52 @@
1
+ import type { HeldRooms } from '../mdmodel/index.js';
2
+ import type { DiscoveredRoom, HeldRoom, OperationScopes, ProviderRefusal, ReplicaAdmission } 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 { RoomDeclaration } from './socket.js';
9
+ import type { Stored } from './store.js';
10
+ export type AppTypedSelection = {
11
+ roots: readonly string[];
12
+ model: TypesResult;
13
+ };
14
+ export type AppRoom = {
15
+ name: string;
16
+ locator: string;
17
+ handle: string;
18
+ operations: OperationScopes;
19
+ replica: ReplicaAdmission;
20
+ model: TypesResult;
21
+ typedSelection: AppTypedSelection | null;
22
+ providerOwnedPaths: 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 }: Runtime, locator: string, stored: Stored | undefined): ModelState;
35
+ export declare function compositionFor(runtime: Runtime, record: ReplicaRecord): Composition;
36
+ export declare function declarationOf({ socket }: Runtime, locator: string, stored: Stored | undefined): {
37
+ readonly room: RoomDeclaration;
38
+ readonly available: boolean;
39
+ } | undefined;
40
+ export declare function listedLocators({ store, socket }: 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(runtime: Runtime, listing: Listing): readonly AppRoom[];
44
+ export declare function roomFacts(runtime: Runtime, reach?: PortReach | null): Promise<HeldRooms>;
45
+ export declare function list({ store, socket }: Runtime, room: RoomDeclaration, synchronizationAvailable: boolean): void;
46
+ export declare function listHeld({ store, socket }: Runtime, locator: string): void;
47
+ export declare function admitted({ socket }: Runtime, room: RoomDeclaration): boolean;
48
+ export declare function readable(runtime: Runtime, room: DiscoveredRoom): void;
49
+ export declare function usable(runtime: Runtime, room: DiscoveredRoom): void;
50
+ export declare function heldRooms({ store }: Runtime, listed: readonly DiscoveredRoom[]): Promise<HeldRoom[]>;
51
+ export declare function name(runtime: Runtime, locator: string): Promise<void>;
52
+ 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 {};
@@ -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 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";
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;