@agentshouse/mdruntime 0.1.0-cfcbb238a5fa0 → 0.1.0-cfe148b32e3d8
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.
- package/AGENTS.md +229 -211
- package/README.md +9 -8
- package/dist/adapter.d.ts +69 -35
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +4 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +13 -3
- package/dist/binary.d.ts +0 -5
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +1 -1
- package/dist/bootstrap.d.ts +24 -6
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +167 -82
- package/dist/chain.d.ts +11 -0
- package/dist/chain.d.ts.map +1 -0
- package/dist/chain.js +64 -0
- package/dist/change-set.d.ts +9 -16
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +11 -89
- package/dist/change.d.ts +31 -1
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +10 -1
- package/dist/chat/earlier.d.ts +10 -0
- package/dist/chat/earlier.d.ts.map +1 -0
- package/dist/chat/earlier.js +54 -0
- package/dist/chat/house.d.ts +25 -0
- package/dist/chat/house.d.ts.map +1 -0
- package/dist/chat/house.js +38 -0
- package/dist/chat/input.d.ts +3 -1
- package/dist/chat/input.d.ts.map +1 -1
- package/dist/chat/input.js +11 -18
- package/dist/chat/list.d.ts +2 -1
- package/dist/chat/list.d.ts.map +1 -1
- package/dist/chat/list.js +45 -5
- package/dist/chat/markdown.d.ts +2 -2
- package/dist/chat/markdown.d.ts.map +1 -1
- package/dist/chat/markdown.js +80 -39
- package/dist/chat/message.d.ts +1 -0
- package/dist/chat/message.d.ts.map +1 -1
- package/dist/chat/message.js +73 -11
- package/dist/chat/messages.d.ts +14 -1
- package/dist/chat/messages.d.ts.map +1 -1
- package/dist/chat/messages.js +79 -24
- package/dist/chat/name.d.ts +1 -0
- package/dist/chat/name.d.ts.map +1 -1
- package/dist/chat/name.js +1 -1
- package/dist/chat/opened.d.ts +1 -0
- package/dist/chat/opened.d.ts.map +1 -1
- package/dist/chat/opened.js +2 -0
- package/dist/chat/overlay.d.ts +1 -0
- package/dist/chat/overlay.d.ts.map +1 -1
- package/dist/chat/overlay.js +11 -5
- package/dist/chat/parts.d.ts +1 -0
- package/dist/chat/parts.d.ts.map +1 -1
- package/dist/chat/parts.js +3 -2
- package/dist/chat/pieces.d.ts +62 -0
- package/dist/chat/pieces.d.ts.map +1 -0
- package/dist/chat/pieces.js +1110 -0
- package/dist/chat/provider.d.ts +8 -1
- package/dist/chat/provider.d.ts.map +1 -1
- package/dist/chat/provider.js +98 -92
- package/dist/chat/question.d.ts +1 -1
- package/dist/chat/question.d.ts.map +1 -1
- package/dist/chat/question.js +7 -18
- package/dist/chat/ready.d.ts +5 -2
- package/dist/chat/ready.d.ts.map +1 -1
- package/dist/chat/ready.js +7 -5
- package/dist/chat/room-file.d.ts +8 -0
- package/dist/chat/room-file.d.ts.map +1 -0
- package/dist/chat/room-file.js +72 -0
- package/dist/chat/steady.d.ts +3 -0
- package/dist/chat/steady.d.ts.map +1 -0
- package/dist/chat/steady.js +26 -0
- package/dist/chat/style.d.ts.map +1 -1
- package/dist/chat/style.js +6 -1
- package/dist/chat.d.ts +3 -2
- package/dist/chat.d.ts.map +1 -1
- package/dist/chat.js +2 -2
- package/dist/client.d.ts +11 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +35 -5
- package/dist/collection.d.ts +6 -19
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +30 -287
- package/dist/compile.d.ts +16 -0
- package/dist/compile.d.ts.map +1 -0
- package/dist/compile.js +721 -0
- package/dist/connection.d.ts +19 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +2392 -848
- package/dist/conversation.d.ts +14 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +198 -89
- package/dist/digest.d.ts +7 -0
- package/dist/digest.d.ts.map +1 -0
- package/dist/digest.js +113 -0
- package/dist/durability.d.ts +3 -1
- package/dist/durability.d.ts.map +1 -1
- package/dist/entry.d.ts +3 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +18 -23
- package/dist/file.d.ts +2 -10
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -120
- package/dist/fulltext.d.ts +27 -0
- package/dist/fulltext.d.ts.map +1 -0
- package/dist/fulltext.js +368 -0
- package/dist/host.d.ts +1 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +21 -8
- package/dist/identity.d.ts +0 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +0 -3
- package/dist/index.d.ts +11 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/live.d.ts +22 -0
- package/dist/live.d.ts.map +1 -0
- package/dist/live.js +123 -0
- package/dist/memory.d.ts +3 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +30 -20
- package/dist/messages.d.ts +28 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +90 -0
- package/dist/name.d.ts +4 -0
- package/dist/name.d.ts.map +1 -0
- package/dist/name.js +122 -0
- package/dist/observation.d.ts +14 -0
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +93 -3
- package/dist/opened.d.ts +22 -0
- package/dist/opened.d.ts.map +1 -0
- package/dist/opened.js +107 -0
- package/dist/outcome.d.ts +34 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +25 -0
- package/dist/overlay.d.ts +2 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +87 -172
- package/dist/query.d.ts +26 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +41 -6
- package/dist/reach.d.ts +5 -3
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +158 -57
- package/dist/react.d.ts +1 -2
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +2 -14
- package/dist/readiness.d.ts +18 -3
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +4 -2
- package/dist/recovery.d.ts +2 -2
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +8 -7
- package/dist/refresh.d.ts +11 -13
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +78 -51
- package/dist/replica.d.ts +57 -33
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +295 -186
- package/dist/room-draft.d.ts +3 -1
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +29 -22
- package/dist/rows.d.ts +29 -30
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +113 -64
- package/dist/save.d.ts +51 -14
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +518 -180
- package/dist/search.d.ts +23 -42
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +28 -182
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +18 -4
- package/dist/shared.d.ts +8 -3
- package/dist/shared.d.ts.map +1 -1
- package/dist/shared.js +129 -66
- package/dist/store.d.ts +97 -88
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +335 -659
- package/dist/stored.d.ts +145 -0
- package/dist/stored.d.ts.map +1 -0
- package/dist/stored.js +567 -0
- package/dist/tables.d.ts +342 -0
- package/dist/tables.d.ts.map +1 -0
- package/dist/tables.js +576 -0
- package/dist/turn.d.ts +5 -3
- package/dist/turn.d.ts.map +1 -1
- package/dist/turn.js +51 -21
- package/dist/validation.d.ts +30 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +162 -0
- package/dist/windows.d.ts +22 -0
- package/dist/windows.d.ts.map +1 -0
- package/dist/windows.js +89 -0
- package/dist/wire.d.ts +29 -1
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +8 -1
- package/dist/words.d.ts +19 -0
- package/dist/words.d.ts.map +1 -0
- package/dist/words.js +150 -0
- package/package.json +10 -4
- package/dist/acquisition.d.ts +0 -14
- package/dist/acquisition.d.ts.map +0 -1
- package/dist/acquisition.js +0 -24
- package/dist/read-side.d.ts +0 -25
- package/dist/read-side.d.ts.map +0 -1
- package/dist/read-side.js +0 -642
package/dist/conversation.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { ConversationAction, ConversationAgents, ConversationEvent, ConversationMessage, ConversationStream, ProcessCommand, SessionOption, TurnContext } from './adapter.js';
|
|
2
2
|
import { type ChangeSet } from './change-set.js';
|
|
3
|
-
import { type
|
|
3
|
+
import { type ChosenFile } from './file.js';
|
|
4
4
|
import type { Open } from './open.js';
|
|
5
5
|
import { type CallResult, type Offline } from './outcome.js';
|
|
6
6
|
import type { DocumentResult, PendingResult } from './query.js';
|
|
@@ -17,6 +17,7 @@ export type ConversationEntry = {
|
|
|
17
17
|
created: string;
|
|
18
18
|
finished: string | null;
|
|
19
19
|
outcome: string | null;
|
|
20
|
+
waiting: boolean;
|
|
20
21
|
state: ConversationState;
|
|
21
22
|
started: string | null;
|
|
22
23
|
};
|
|
@@ -32,14 +33,17 @@ export type RunningTurn = {
|
|
|
32
33
|
};
|
|
33
34
|
export type ChatDraft = {
|
|
34
35
|
text: string;
|
|
35
|
-
files: readonly ChatDraftFile[];
|
|
36
36
|
};
|
|
37
37
|
export type ConversationOptions = {
|
|
38
38
|
limit?: number;
|
|
39
|
+
after?: string;
|
|
40
|
+
total?: true;
|
|
39
41
|
};
|
|
40
42
|
export type ConversationView = {
|
|
41
43
|
conversation: string;
|
|
42
44
|
messages: readonly ConversationMessage[];
|
|
45
|
+
next?: string;
|
|
46
|
+
total?: number;
|
|
43
47
|
turn: RunningTurn | null;
|
|
44
48
|
questions: readonly unknown[];
|
|
45
49
|
process: {
|
|
@@ -47,6 +51,11 @@ export type ConversationView = {
|
|
|
47
51
|
} | null;
|
|
48
52
|
commands: readonly ProcessCommand[];
|
|
49
53
|
options: readonly SessionOption[];
|
|
54
|
+
starting: string | null;
|
|
55
|
+
link: {
|
|
56
|
+
connected: boolean;
|
|
57
|
+
} | null;
|
|
58
|
+
deliveryUnknown: readonly string[];
|
|
50
59
|
chatDraft: (ChatDraft & {
|
|
51
60
|
readonly revision: string;
|
|
52
61
|
}) | null;
|
|
@@ -56,6 +65,7 @@ export type ConversationSurface = {
|
|
|
56
65
|
read(conversation: string, options?: ConversationOptions): Promise<ConversationView>;
|
|
57
66
|
create(input: unknown): Promise<CallResult>;
|
|
58
67
|
send(conversation: string, operation?: string, draft?: ChatDraft): Promise<CallResult | Offline>;
|
|
68
|
+
attach(room: string, file: ChosenFile): Promise<CallResult | Offline>;
|
|
59
69
|
answer(conversation: string, answer: unknown): Promise<CallResult>;
|
|
60
70
|
interrupt(conversation: string): Promise<CallResult>;
|
|
61
71
|
kill(conversation: string): Promise<CallResult>;
|
|
@@ -64,11 +74,12 @@ export type ConversationSurface = {
|
|
|
64
74
|
};
|
|
65
75
|
export type ChatDraftSurface = {
|
|
66
76
|
write(conversation: string, draft: ChatDraft, revision?: string): Promise<void>;
|
|
77
|
+
prepend(conversation: string, draft: ChatDraft): Promise<void>;
|
|
67
78
|
discard(conversation: string): Promise<void>;
|
|
68
79
|
};
|
|
69
80
|
export type ConversationDependencies = {
|
|
70
81
|
agents(): ConversationAgents | undefined;
|
|
71
|
-
documents(agents: ConversationAgents): Promise<DocumentResult | PendingResult>;
|
|
82
|
+
documents(agents: ConversationAgents, after: string | undefined): Promise<DocumentResult | PendingResult>;
|
|
72
83
|
call(name: ConversationAction, input: unknown): Promise<CallResult>;
|
|
73
84
|
durably<T>(work: (local: RuntimeStore) => Promise<T>): Promise<T>;
|
|
74
85
|
stream(): ConversationStream | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversation.d.ts","sourceRoot":"","sources":["../src/conversation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,EAEjB,mBAAmB,EACnB,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OAAO,CAAC;IACnB,KAAK,IAAI,OAAO,CAAC;IACjB,WAAW,IAAI,IAAI,CAAC;IACpB,QAAQ,IAAI,IAAI,CAAC;IACjB,IAAI,IAAI,IAAI,CAAC;IACb,KAAK,CACH,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,mBAAmB,EAC5B,OAAO,EAAE,CAAC,IAAI,EAAE,gBAAgB,KAAK,IAAI,GACxC,MAAM,IAAI,CAAC;IACd,SAAS,CAAC,OAAO,EAAE,CAAC,OAAO,EAAE,SAAS,iBAAiB,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAChF,WAAW,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE,SAAS,iBAAiB,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IACjF,OAAO,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI,CAAC;IAC9B,OAAO,CAAC,KAAK,EAAE,iBAAiB,GAAG,OAAO,CAAC;IAC3C,UAAU,IAAI,SAAS,MAAM,EAAE,CAAC;IAChC,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC;IACxC,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAyCF,wBAAgB,UAAU,CAAC,YAAY,EAAE,MAAM,GAAG,gBAAgB,CAcjE;AAED,eAAO,MAAM,eAAe,oBAAoB,CAAC;AAIjD,wBAAgB,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE7C;AA6PD,wBAAgB,uBAAuB,CAAC,IAAI,EAAE,wBAAwB,GAAG,iBAAiB,CAk3BzF"}
|
package/dist/conversation.js
CHANGED
|
@@ -3,13 +3,26 @@ import { runtimeError } from './failure.js';
|
|
|
3
3
|
import { declaredFile } from './file.js';
|
|
4
4
|
import { changeBatchIdentity, chatDraftRevision } from './identity.js';
|
|
5
5
|
import { OFFLINE } from './outcome.js';
|
|
6
|
+
import { capped, cursorOf, decodedCursor, FROM_START, messageOrder, precedes } from './windows.js';
|
|
6
7
|
const QUIET = {
|
|
7
8
|
turn: null,
|
|
8
9
|
questions: [],
|
|
9
10
|
process: null,
|
|
10
11
|
commands: [],
|
|
11
12
|
options: [],
|
|
13
|
+
starting: null,
|
|
14
|
+
link: null,
|
|
15
|
+
deliveryUnknown: [],
|
|
12
16
|
};
|
|
17
|
+
const FACTS = [
|
|
18
|
+
'questions',
|
|
19
|
+
'process',
|
|
20
|
+
'commands',
|
|
21
|
+
'options',
|
|
22
|
+
'starting',
|
|
23
|
+
'link',
|
|
24
|
+
'deliveryUnknown',
|
|
25
|
+
];
|
|
13
26
|
export function unheldView(conversation) {
|
|
14
27
|
return {
|
|
15
28
|
conversation,
|
|
@@ -19,6 +32,9 @@ export function unheldView(conversation) {
|
|
|
19
32
|
process: null,
|
|
20
33
|
commands: [],
|
|
21
34
|
options: [],
|
|
35
|
+
starting: null,
|
|
36
|
+
link: null,
|
|
37
|
+
deliveryUnknown: [],
|
|
22
38
|
chatDraft: null,
|
|
23
39
|
};
|
|
24
40
|
}
|
|
@@ -30,8 +46,10 @@ export function newChat(agent) {
|
|
|
30
46
|
function creationOf(input) {
|
|
31
47
|
if (typeof input !== 'object' || input === null)
|
|
32
48
|
return null;
|
|
33
|
-
const { agent_id: agent, operation_id: operation } = input;
|
|
34
|
-
return typeof agent === 'string' && typeof operation === 'string'
|
|
49
|
+
const { agent_id: agent, operation_id: operation, replaces, } = input;
|
|
50
|
+
return typeof agent === 'string' && typeof operation === 'string' && replaces === undefined
|
|
51
|
+
? { agent, operation }
|
|
52
|
+
: null;
|
|
35
53
|
}
|
|
36
54
|
function startedTurn(turn, operation) {
|
|
37
55
|
if (operation.op === 'begin')
|
|
@@ -82,19 +100,25 @@ function appliedTurn(held, operation) {
|
|
|
82
100
|
parts: held.parts.map((kept, at) => (at === operation.index ? changed : kept)),
|
|
83
101
|
};
|
|
84
102
|
}
|
|
85
|
-
function ordered(left, right) {
|
|
86
|
-
if (left.position !== right.position)
|
|
87
|
-
return left.position < right.position ? -1 : 1;
|
|
88
|
-
if (left.identity !== right.identity)
|
|
89
|
-
return left.identity < right.identity ? -1 : 1;
|
|
90
|
-
return 0;
|
|
91
|
-
}
|
|
92
103
|
function windowOf(held, arriving, limit) {
|
|
93
104
|
const byIdentity = new Map(held.map((message) => [message.identity, message]));
|
|
94
105
|
for (const message of arriving)
|
|
95
106
|
byIdentity.set(message.identity, message);
|
|
96
|
-
const next = [...byIdentity.values()].sort(
|
|
97
|
-
|
|
107
|
+
const next = [...byIdentity.values()].sort(messageOrder);
|
|
108
|
+
const start = Math.max(0, next.length - limit);
|
|
109
|
+
return { messages: next.slice(start), dropped: start > 0 };
|
|
110
|
+
}
|
|
111
|
+
function frameOf(asked, messages, more, total) {
|
|
112
|
+
const oldest = messages[0];
|
|
113
|
+
const next = !more
|
|
114
|
+
? undefined
|
|
115
|
+
: oldest === undefined
|
|
116
|
+
? (asked.after ?? FROM_START)
|
|
117
|
+
: cursorOf([oldest.position, oldest.identity]);
|
|
118
|
+
return {
|
|
119
|
+
...(next === undefined ? {} : { next }),
|
|
120
|
+
...(total === null ? {} : { total }),
|
|
121
|
+
};
|
|
98
122
|
}
|
|
99
123
|
function newestOf(arriving, from) {
|
|
100
124
|
return arriving.reduce((top, message) => (top === null || message.position > top ? message.position : top), from);
|
|
@@ -165,18 +189,28 @@ function answered(result, field) {
|
|
|
165
189
|
const value = answer[field];
|
|
166
190
|
return typeof value === 'string' ? value : null;
|
|
167
191
|
}
|
|
168
|
-
function
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
192
|
+
function beforeOf(after) {
|
|
193
|
+
if (after === undefined)
|
|
194
|
+
return null;
|
|
195
|
+
const decoded = typeof after === 'string' ? decodedCursor(after) : null;
|
|
196
|
+
if (decoded?.length === 0)
|
|
197
|
+
return null;
|
|
198
|
+
const [position, identity] = decoded ?? [];
|
|
199
|
+
if (decoded?.length !== 2 || typeof position !== 'string' || typeof identity !== 'string') {
|
|
200
|
+
throw runtimeError('invalid-after', `conversation after must be the next an earlier view returned, got ${String(after)}`);
|
|
201
|
+
}
|
|
202
|
+
return [position, identity];
|
|
203
|
+
}
|
|
204
|
+
function askedOf(options) {
|
|
205
|
+
const { limit, after, total } = options;
|
|
206
|
+
if (limit !== undefined && (!Number.isInteger(limit) || limit < 0)) {
|
|
173
207
|
throw runtimeError('invalid-limit', `conversation limit must be a non-negative integer, got ${String(limit)}`);
|
|
174
208
|
}
|
|
175
|
-
return limit;
|
|
209
|
+
return { limit: capped(limit), after, before: beforeOf(after), total: total === true };
|
|
176
210
|
}
|
|
177
211
|
const EXPIRED = { kind: 'rejected', code: 'expired', fields: {}, retryable: false };
|
|
178
212
|
function unwritten(draft) {
|
|
179
|
-
return draft.text === ''
|
|
213
|
+
return draft.text === '';
|
|
180
214
|
}
|
|
181
215
|
function pending(draft) {
|
|
182
216
|
return {
|
|
@@ -191,11 +225,13 @@ function withSubmitted(draft, submitted) {
|
|
|
191
225
|
const { submitted: _held, ...unsent } = draft;
|
|
192
226
|
return submitted.length === 0 ? unsent : { ...unsent, submitted };
|
|
193
227
|
}
|
|
228
|
+
function prepended(draft, said) {
|
|
229
|
+
return { text: [said.text, draft.text].filter((one) => one !== '').join('\n') };
|
|
230
|
+
}
|
|
194
231
|
function returned(draft, submission, others) {
|
|
195
232
|
return withSubmitted({
|
|
196
233
|
conversation: draft.conversation,
|
|
197
|
-
|
|
198
|
-
files: [...submission.files, ...draft.files],
|
|
234
|
+
...prepended(draft, submission),
|
|
199
235
|
revision: chatDraftRevision(),
|
|
200
236
|
}, others);
|
|
201
237
|
}
|
|
@@ -209,6 +245,7 @@ export function createConversationStore(deps) {
|
|
|
209
245
|
const catching = new Map();
|
|
210
246
|
const gaps = new Map();
|
|
211
247
|
const lives = new Map();
|
|
248
|
+
const unsent = new Map();
|
|
212
249
|
const views = new Map();
|
|
213
250
|
const listing = new Map();
|
|
214
251
|
const creations = new Set();
|
|
@@ -223,7 +260,7 @@ export function createConversationStore(deps) {
|
|
|
223
260
|
function liveOf(conversation) {
|
|
224
261
|
return lives.get(conversation) ?? QUIET;
|
|
225
262
|
}
|
|
226
|
-
function viewOf(conversation, held) {
|
|
263
|
+
function viewOf(conversation, held, frame) {
|
|
227
264
|
const draft = drafts.get(conversation);
|
|
228
265
|
const facts = liveOf(conversation);
|
|
229
266
|
return {
|
|
@@ -234,14 +271,18 @@ export function createConversationStore(deps) {
|
|
|
234
271
|
text,
|
|
235
272
|
message,
|
|
236
273
|
})),
|
|
274
|
+
...frame,
|
|
237
275
|
turn: structuredClone(facts.turn),
|
|
238
276
|
questions: structuredClone(facts.questions),
|
|
239
277
|
process: facts.process === null ? null : { ...facts.process },
|
|
240
278
|
commands: structuredClone(facts.commands),
|
|
241
279
|
options: structuredClone(facts.options),
|
|
280
|
+
starting: facts.starting,
|
|
281
|
+
link: facts.link === null ? null : { ...facts.link },
|
|
282
|
+
deliveryUnknown: [...facts.deliveryUnknown],
|
|
242
283
|
chatDraft: draft === undefined || unwritten(draft)
|
|
243
284
|
? null
|
|
244
|
-
: { text: draft.text,
|
|
285
|
+
: { text: draft.text, revision: draft.revision },
|
|
245
286
|
};
|
|
246
287
|
}
|
|
247
288
|
function emit(conversation) {
|
|
@@ -253,21 +294,36 @@ export function createConversationStore(deps) {
|
|
|
253
294
|
const ready = [...view.watchers].filter((watcher) => watcher.ready);
|
|
254
295
|
if (ready.length === 0)
|
|
255
296
|
continue;
|
|
256
|
-
const value = viewOf(conversation, view.window);
|
|
297
|
+
const value = viewOf(conversation, view.window, sharedFrame(view, view.window));
|
|
257
298
|
for (const watcher of ready)
|
|
258
299
|
watcher.notify(value);
|
|
259
300
|
}
|
|
260
301
|
}
|
|
261
|
-
function
|
|
302
|
+
function sharedFrame(view, window) {
|
|
303
|
+
return frameOf(view.asked, window, view.more, view.total);
|
|
304
|
+
}
|
|
305
|
+
async function slide(local, conversation, arriving) {
|
|
306
|
+
let count;
|
|
262
307
|
for (const view of views.values()) {
|
|
263
308
|
if (view.conversation !== conversation || view.window === null)
|
|
264
309
|
continue;
|
|
265
|
-
|
|
310
|
+
if (arriving === null) {
|
|
311
|
+
view.window = [];
|
|
312
|
+
view.more = false;
|
|
313
|
+
if (view.total !== null)
|
|
314
|
+
view.total = 0;
|
|
315
|
+
continue;
|
|
316
|
+
}
|
|
317
|
+
const joining = arriving.filter((message) => precedes(message, view.asked.before));
|
|
318
|
+
const next = windowOf(view.window, joining, view.asked.limit);
|
|
319
|
+
view.window = next.messages;
|
|
320
|
+
view.more ||= next.dropped;
|
|
321
|
+
if (view.total !== null && arriving.length > 0) {
|
|
322
|
+
count ??= await local.messageCount(conversation);
|
|
323
|
+
view.total = count;
|
|
324
|
+
}
|
|
266
325
|
}
|
|
267
326
|
}
|
|
268
|
-
function changesOf(conversation, arriving) {
|
|
269
|
-
return arriving.map(({ identity, text }) => ({ conversation, identity, text }));
|
|
270
|
-
}
|
|
271
327
|
function stateOf(conversation) {
|
|
272
328
|
const facts = liveOf(conversation);
|
|
273
329
|
if (facts.questions.length > 0)
|
|
@@ -282,6 +338,7 @@ export function createConversationStore(deps) {
|
|
|
282
338
|
created: entry.created,
|
|
283
339
|
finished: entry.finished,
|
|
284
340
|
outcome: entry.outcome,
|
|
341
|
+
waiting: entry.waiting,
|
|
285
342
|
state: stateOf(entry.conversation),
|
|
286
343
|
started: lives.get(entry.conversation)?.turn?.started ?? null,
|
|
287
344
|
}));
|
|
@@ -324,23 +381,30 @@ export function createConversationStore(deps) {
|
|
|
324
381
|
const declaration = deps.agents();
|
|
325
382
|
if (declaration === undefined)
|
|
326
383
|
return;
|
|
327
|
-
const held = await deps.documents(declaration);
|
|
328
|
-
if ('pending' in held)
|
|
329
|
-
return;
|
|
330
|
-
const { documents } = held;
|
|
331
384
|
const names = new Map();
|
|
332
385
|
const retired = new Set();
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
386
|
+
let covered = null;
|
|
387
|
+
for (let after;;) {
|
|
388
|
+
const read = await deps.documents(declaration, after);
|
|
389
|
+
if ('pending' in read)
|
|
390
|
+
return;
|
|
391
|
+
const coverage = JSON.stringify(read.coverage);
|
|
392
|
+
if (covered !== null && coverage !== covered)
|
|
393
|
+
return readAgents();
|
|
394
|
+
covered = coverage;
|
|
395
|
+
for (const document of read.documents) {
|
|
396
|
+
const identity = document.fields?.[declaration.identity];
|
|
397
|
+
const name = document.fields?.[declaration.name];
|
|
398
|
+
if (typeof identity !== 'string' || typeof name !== 'string')
|
|
399
|
+
continue;
|
|
400
|
+
names.set(identity, name);
|
|
401
|
+
const ended = declaration.retired === undefined ? null : document.fields?.[declaration.retired];
|
|
402
|
+
if (ended !== undefined && ended !== null)
|
|
403
|
+
retired.add(identity);
|
|
404
|
+
}
|
|
405
|
+
if (read.next === undefined)
|
|
406
|
+
break;
|
|
407
|
+
after = read.next;
|
|
344
408
|
}
|
|
345
409
|
const named = JSON.stringify([...names]) !== JSON.stringify([...agentNames]);
|
|
346
410
|
if (!named && JSON.stringify([...retired]) === JSON.stringify([...retiredAgents]))
|
|
@@ -364,9 +428,34 @@ export function createConversationStore(deps) {
|
|
|
364
428
|
return agentsRead;
|
|
365
429
|
}
|
|
366
430
|
function live(conversation, change) {
|
|
431
|
+
const owed = unsent.get(conversation);
|
|
432
|
+
for (const fact of FACTS.filter((one) => one in change))
|
|
433
|
+
owed?.delete(fact);
|
|
367
434
|
setLive(conversation, { ...liveOf(conversation), ...change });
|
|
368
435
|
emit(conversation);
|
|
369
436
|
}
|
|
437
|
+
function openingEnded() {
|
|
438
|
+
const owed = [...unsent];
|
|
439
|
+
unsent.clear();
|
|
440
|
+
for (const [conversation, facts] of owed) {
|
|
441
|
+
const held = lives.get(conversation);
|
|
442
|
+
if (held === undefined || facts.size === 0)
|
|
443
|
+
continue;
|
|
444
|
+
setLive(conversation, {
|
|
445
|
+
turn: held.turn,
|
|
446
|
+
questions: facts.has('questions') ? QUIET.questions : held.questions,
|
|
447
|
+
process: facts.has('process') ? QUIET.process : held.process,
|
|
448
|
+
commands: facts.has('commands') ? QUIET.commands : held.commands,
|
|
449
|
+
options: facts.has('options') ? QUIET.options : held.options,
|
|
450
|
+
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
451
|
+
link: facts.has('link') ? QUIET.link : held.link,
|
|
452
|
+
deliveryUnknown: facts.has('deliveryUnknown')
|
|
453
|
+
? QUIET.deliveryUnknown
|
|
454
|
+
: held.deliveryUnknown,
|
|
455
|
+
});
|
|
456
|
+
emit(conversation);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
370
459
|
function relayed(conversation, turn, operation) {
|
|
371
460
|
const held = liveOf(conversation).turn;
|
|
372
461
|
const next = held?.turn === turn ? appliedTurn(held, operation) : startedTurn(turn, operation);
|
|
@@ -393,12 +482,6 @@ export function createConversationStore(deps) {
|
|
|
393
482
|
}
|
|
394
483
|
async function remove(leaving) {
|
|
395
484
|
await deps.durably(async (local) => {
|
|
396
|
-
const removed = [];
|
|
397
|
-
for (const conversation of leaving) {
|
|
398
|
-
for (const identity of await local.messageIdentities(conversation)) {
|
|
399
|
-
removed.push({ conversation, identity, text: null });
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
485
|
await local.dropConversations(leaving);
|
|
403
486
|
const changed = [];
|
|
404
487
|
for (const conversation of leaving) {
|
|
@@ -410,11 +493,12 @@ export function createConversationStore(deps) {
|
|
|
410
493
|
partials.delete(conversation);
|
|
411
494
|
drafts.delete(conversation);
|
|
412
495
|
behind.delete(conversation);
|
|
496
|
+
unsent.delete(conversation);
|
|
413
497
|
setLive(conversation, null);
|
|
414
|
-
slide(conversation, null);
|
|
498
|
+
await slide(local, conversation, null);
|
|
415
499
|
}
|
|
416
500
|
if (changed.length > 0)
|
|
417
|
-
deps.publish(conversationChangeSet(
|
|
501
|
+
deps.publish(conversationChangeSet(changed));
|
|
418
502
|
});
|
|
419
503
|
}
|
|
420
504
|
function gap(conversation) {
|
|
@@ -439,8 +523,8 @@ export function createConversationStore(deps) {
|
|
|
439
523
|
if (advances)
|
|
440
524
|
reads.set(conversation, message.position);
|
|
441
525
|
sealTurns(conversation, new Set([message.turn]));
|
|
442
|
-
slide(conversation, [message]);
|
|
443
|
-
deps.publish(conversationChangeSet(
|
|
526
|
+
await slide(local, conversation, [message]);
|
|
527
|
+
deps.publish(conversationChangeSet([conversation]));
|
|
444
528
|
});
|
|
445
529
|
}
|
|
446
530
|
async function readHistories(conversations, ended) {
|
|
@@ -514,9 +598,9 @@ export function createConversationStore(deps) {
|
|
|
514
598
|
sealTurns(conversation, new Set(arriving.map((message) => message.turn)));
|
|
515
599
|
if (whole && (gaps.get(conversation) ?? 0) === generation)
|
|
516
600
|
behind.delete(conversation);
|
|
517
|
-
slide(conversation, arriving);
|
|
601
|
+
await slide(local, conversation, arriving);
|
|
518
602
|
if (arriving.length > 0 || sealing || whole) {
|
|
519
|
-
deps.publish(conversationChangeSet(
|
|
603
|
+
deps.publish(conversationChangeSet([conversation]));
|
|
520
604
|
}
|
|
521
605
|
});
|
|
522
606
|
}
|
|
@@ -525,11 +609,8 @@ export function createConversationStore(deps) {
|
|
|
525
609
|
if (event.kind === 'gap') {
|
|
526
610
|
if (replicated.has(conversation))
|
|
527
611
|
gap(conversation);
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
return;
|
|
531
|
-
setLive(conversation, { ...QUIET, turn: held.turn });
|
|
532
|
-
emit(conversation);
|
|
612
|
+
if (lives.has(conversation))
|
|
613
|
+
unsent.set(conversation, new Set(FACTS));
|
|
533
614
|
return;
|
|
534
615
|
}
|
|
535
616
|
if (event.kind === 'turn') {
|
|
@@ -552,6 +633,18 @@ export function createConversationStore(deps) {
|
|
|
552
633
|
live(conversation, { options: structuredClone(event.options) });
|
|
553
634
|
return;
|
|
554
635
|
}
|
|
636
|
+
if (event.kind === 'starting') {
|
|
637
|
+
live(conversation, { starting: event.step });
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
if (event.kind === 'link') {
|
|
641
|
+
live(conversation, { link: { connected: event.connected } });
|
|
642
|
+
return;
|
|
643
|
+
}
|
|
644
|
+
if (event.kind === 'deliveries') {
|
|
645
|
+
live(conversation, { deliveryUnknown: [...event.unknown] });
|
|
646
|
+
return;
|
|
647
|
+
}
|
|
555
648
|
const arriving = acceptedMessage(event.message);
|
|
556
649
|
if (arriving === null)
|
|
557
650
|
return;
|
|
@@ -591,7 +684,6 @@ export function createConversationStore(deps) {
|
|
|
591
684
|
const blank = {
|
|
592
685
|
conversation: from,
|
|
593
686
|
text: '',
|
|
594
|
-
files: [],
|
|
595
687
|
revision: chatDraftRevision(),
|
|
596
688
|
};
|
|
597
689
|
const { moves: _answered, ...unsent } = held ?? blank;
|
|
@@ -601,7 +693,7 @@ export function createConversationStore(deps) {
|
|
|
601
693
|
drafts.set(from, left);
|
|
602
694
|
for (const one of taken)
|
|
603
695
|
drafts.set(to, one);
|
|
604
|
-
deps.publish(conversationChangeSet([
|
|
696
|
+
deps.publish(conversationChangeSet([from, to]));
|
|
605
697
|
});
|
|
606
698
|
}
|
|
607
699
|
function withDraft(conversation, next) {
|
|
@@ -610,7 +702,7 @@ export function createConversationStore(deps) {
|
|
|
610
702
|
if (following === undefined)
|
|
611
703
|
return;
|
|
612
704
|
await kept(local, conversation, following);
|
|
613
|
-
deps.publish(conversationChangeSet([
|
|
705
|
+
deps.publish(conversationChangeSet([conversation]));
|
|
614
706
|
});
|
|
615
707
|
}
|
|
616
708
|
async function submitted(conversation, operation, draft) {
|
|
@@ -622,17 +714,12 @@ export function createConversationStore(deps) {
|
|
|
622
714
|
if (submission !== undefined)
|
|
623
715
|
return undefined;
|
|
624
716
|
const said = draft ?? current;
|
|
625
|
-
submission = {
|
|
626
|
-
operation,
|
|
627
|
-
text: said?.text ?? '',
|
|
628
|
-
files: [...(said?.files ?? [])],
|
|
629
|
-
turn: null,
|
|
630
|
-
};
|
|
717
|
+
submission = { operation, text: said?.text ?? '', turn: null };
|
|
631
718
|
return {
|
|
632
719
|
conversation,
|
|
633
720
|
...(draft === undefined || current === undefined
|
|
634
|
-
? { text: '',
|
|
635
|
-
: { text: current.text,
|
|
721
|
+
? { text: '', revision: chatDraftRevision() }
|
|
722
|
+
: { text: current.text, revision: current.revision }),
|
|
636
723
|
submitted: [...(current?.submitted ?? []), submission],
|
|
637
724
|
};
|
|
638
725
|
});
|
|
@@ -650,10 +737,8 @@ export function createConversationStore(deps) {
|
|
|
650
737
|
const dispatch = {};
|
|
651
738
|
sending.set(submission.operation, dispatch);
|
|
652
739
|
try {
|
|
653
|
-
const files = await Promise.all(submission.files.map(async (file) => ({ ...(await declaredFile(file)), blob: file.blob })));
|
|
654
740
|
const result = await invoke('conversation.send', conversation, {
|
|
655
741
|
text: submission.text,
|
|
656
|
-
files,
|
|
657
742
|
operation_id: submission.operation,
|
|
658
743
|
});
|
|
659
744
|
if (result.kind === 'revoked-authorization')
|
|
@@ -691,8 +776,12 @@ export function createConversationStore(deps) {
|
|
|
691
776
|
return entries();
|
|
692
777
|
},
|
|
693
778
|
async read(conversation, options = {}) {
|
|
694
|
-
const
|
|
695
|
-
return deps.durably(async (local) =>
|
|
779
|
+
const asked = askedOf(options);
|
|
780
|
+
return deps.durably(async (local) => {
|
|
781
|
+
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
782
|
+
const total = asked.total ? await local.messageCount(conversation) : null;
|
|
783
|
+
return structuredClone(viewOf(conversation, messages, frameOf(asked, messages, more, total)));
|
|
784
|
+
});
|
|
696
785
|
},
|
|
697
786
|
async create(input) {
|
|
698
787
|
const result = await deps.call('conversation.create', input);
|
|
@@ -717,10 +806,19 @@ export function createConversationStore(deps) {
|
|
|
717
806
|
if (draft !== undefined) {
|
|
718
807
|
await withDraft(conversation, (current) => current?.submitted?.some((one) => one.operation === operation) === true
|
|
719
808
|
? undefined
|
|
720
|
-
: returned(current ?? { conversation, text: '',
|
|
809
|
+
: returned(current ?? { conversation, text: '', revision: '' }, { operation, ...draft, turn: null }, current?.submitted ?? []));
|
|
721
810
|
}
|
|
722
811
|
return OFFLINE;
|
|
723
812
|
},
|
|
813
|
+
async attach(room, file) {
|
|
814
|
+
if (!deps.online())
|
|
815
|
+
return OFFLINE;
|
|
816
|
+
return deps.call('conversation.attach', {
|
|
817
|
+
room,
|
|
818
|
+
...(await declaredFile(file)),
|
|
819
|
+
blob: file.blob,
|
|
820
|
+
});
|
|
821
|
+
},
|
|
724
822
|
answer(conversation, answer) {
|
|
725
823
|
return invoke('conversation.answer', conversation, { answer });
|
|
726
824
|
},
|
|
@@ -751,21 +849,22 @@ export function createConversationStore(deps) {
|
|
|
751
849
|
return withDraft(conversation, (current) => ({
|
|
752
850
|
conversation,
|
|
753
851
|
text: draft.text,
|
|
754
|
-
files: [...draft.files],
|
|
755
852
|
revision,
|
|
756
853
|
...(current === undefined ? {} : pending(current)),
|
|
757
854
|
}));
|
|
758
855
|
},
|
|
856
|
+
prepend(conversation, draft) {
|
|
857
|
+
return withDraft(conversation, (current) => ({
|
|
858
|
+
conversation,
|
|
859
|
+
...(current === undefined ? { text: draft.text } : prepended(current, draft)),
|
|
860
|
+
revision: chatDraftRevision(),
|
|
861
|
+
...(current === undefined ? {} : pending(current)),
|
|
862
|
+
}));
|
|
863
|
+
},
|
|
759
864
|
discard(conversation) {
|
|
760
865
|
return withDraft(conversation, (current) => current === undefined
|
|
761
866
|
? undefined
|
|
762
|
-
: {
|
|
763
|
-
conversation,
|
|
764
|
-
text: '',
|
|
765
|
-
files: [],
|
|
766
|
-
revision: chatDraftRevision(),
|
|
767
|
-
...pending(current),
|
|
768
|
-
});
|
|
867
|
+
: { conversation, text: '', revision: chatDraftRevision(), ...pending(current) });
|
|
769
868
|
},
|
|
770
869
|
};
|
|
771
870
|
return {
|
|
@@ -864,26 +963,34 @@ export function createConversationStore(deps) {
|
|
|
864
963
|
catching.clear();
|
|
865
964
|
},
|
|
866
965
|
watch(conversation, options, deliver) {
|
|
867
|
-
const
|
|
868
|
-
const key = JSON.stringify([conversation, limit ?? null]);
|
|
966
|
+
const asked = askedOf(options);
|
|
967
|
+
const key = JSON.stringify([conversation, asked.limit, asked.after ?? null, asked.total]);
|
|
869
968
|
const view = views.get(key) ?? {
|
|
870
969
|
conversation,
|
|
871
|
-
|
|
970
|
+
asked,
|
|
872
971
|
watchers: new Set(),
|
|
873
972
|
window: null,
|
|
973
|
+
more: false,
|
|
974
|
+
total: null,
|
|
874
975
|
};
|
|
875
976
|
views.set(key, view);
|
|
876
977
|
const watcher = { notify: deliver, ready: false };
|
|
877
978
|
view.watchers.add(watcher);
|
|
878
979
|
void deps
|
|
879
980
|
.durably(async (local) => {
|
|
880
|
-
view.window
|
|
981
|
+
if (view.window !== null)
|
|
982
|
+
return;
|
|
983
|
+
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
984
|
+
view.window = messages;
|
|
985
|
+
view.more = more;
|
|
986
|
+
view.total = asked.total ? await local.messageCount(conversation) : null;
|
|
881
987
|
})
|
|
882
988
|
.then(() => {
|
|
883
989
|
if (deps.closed() || !view.watchers.has(watcher))
|
|
884
990
|
return;
|
|
885
991
|
watcher.ready = true;
|
|
886
|
-
|
|
992
|
+
const window = view.window ?? [];
|
|
993
|
+
watcher.notify(viewOf(conversation, window, sharedFrame(view, window)));
|
|
887
994
|
})
|
|
888
995
|
.catch(() => { });
|
|
889
996
|
return () => {
|
|
@@ -935,6 +1042,7 @@ export function createConversationStore(deps) {
|
|
|
935
1042
|
creations.delete(entry.conversation);
|
|
936
1043
|
}
|
|
937
1044
|
listKnown = true;
|
|
1045
|
+
openingEnded();
|
|
938
1046
|
}
|
|
939
1047
|
else if (event.kind === 'listed') {
|
|
940
1048
|
listing.set(event.entry.conversation, { ...event.entry });
|
|
@@ -961,6 +1069,7 @@ export function createConversationStore(deps) {
|
|
|
961
1069
|
close() {
|
|
962
1070
|
views.clear();
|
|
963
1071
|
lives.clear();
|
|
1072
|
+
unsent.clear();
|
|
964
1073
|
listWatchers.clear();
|
|
965
1074
|
agentWatchers.clear();
|
|
966
1075
|
},
|
package/dist/digest.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AA0EA,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,IAAI,CAAC;IAChC,GAAG,IAAI,MAAM,CAAC;CACf,CAAC;AAEF,wBAAgB,MAAM,IAAI,MAAM,CAoC/B;AAED,wBAAsB,MAAM,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAMxD"}
|