@agentshouse/mdruntime 0.1.0-c112fd663ab59 → 0.1.0-c11a2e8d6df41
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/README.md +21 -19
- package/dist/acceptance.d.ts +0 -3
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +72 -158
- package/dist/act-lanes.d.ts +30 -0
- package/dist/act-lanes.d.ts.map +1 -0
- package/dist/act-lanes.js +225 -0
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +174 -75
- package/dist/adapter.d.ts +145 -68
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +2 -7
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +347 -0
- package/dist/binary.d.ts +6 -2
- package/dist/binary.d.ts.map +1 -1
- package/dist/binary.js +10 -3
- package/dist/bootstrap.d.ts +1 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +6 -19
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- package/dist/change-set.d.ts +4 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +6 -0
- package/dist/change.d.ts +6 -2
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +3 -0
- package/dist/chat-types.d.ts +0 -2
- package/dist/chat-types.d.ts.map +1 -1
- package/dist/chat-types.js +2 -4
- package/dist/client.d.ts +22 -23
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +51 -66
- package/dist/collection.d.ts +27 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +34 -10
- package/dist/column.d.ts +5 -0
- package/dist/column.d.ts.map +1 -0
- package/dist/column.js +9 -0
- package/dist/compile.d.ts +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +87 -43
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +36 -27
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +28 -15
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +25 -14
- package/dist/conversation-row.d.ts +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +46 -16
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +334 -239
- package/dist/declaration.d.ts +10 -0
- package/dist/declaration.d.ts.map +1 -0
- package/dist/declaration.js +24 -0
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +47 -47
- package/dist/download.d.ts +6 -0
- package/dist/download.d.ts.map +1 -0
- package/dist/download.js +42 -0
- package/dist/durability.d.ts +5 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +16 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +75 -30
- package/dist/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- package/dist/failure.d.ts +2 -0
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +6 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +4 -2
- package/dist/file.d.ts +1 -1
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +3 -2
- package/dist/host.d.ts +24 -4
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +108 -32
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +82 -0
- package/dist/index.d.ts +23 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -8
- package/dist/install.d.ts +10 -6
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +89 -108
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +74 -54
- package/dist/listing.d.ts +29 -22
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +71 -79
- package/dist/live.d.ts +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts +2 -4
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +10 -38
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +11 -23
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +167 -33
- package/dist/memory.d.ts +10 -4
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +98 -37
- package/dist/messages.d.ts +17 -6
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +34 -27
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +4 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -5
- package/dist/models.d.ts +4 -8
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +94 -138
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +1 -1
- package/dist/opened.d.ts.map +1 -1
- package/dist/opened.js +2 -2
- package/dist/opening.d.ts.map +1 -1
- package/dist/opening.js +21 -12
- package/dist/outcome.d.ts +24 -4
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +33 -3
- package/dist/overlay.d.ts +9 -5
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +37 -24
- package/dist/page-metadata.d.ts +8 -0
- package/dist/page-metadata.d.ts.map +1 -0
- package/dist/page-metadata.js +19 -0
- package/dist/parts.d.ts +5 -59
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +32 -122
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +207 -96
- package/dist/presence.d.ts +58 -0
- package/dist/presence.d.ts.map +1 -0
- package/dist/presence.js +231 -0
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +136 -78
- package/dist/query.d.ts +2 -2
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +40 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +480 -0
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +182 -38
- package/dist/react.d.ts +11 -5
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +28 -5
- package/dist/readiness.d.ts +20 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +17 -10
- package/dist/reads.d.ts +4 -2
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +9 -4
- package/dist/recovery.d.ts +4 -1
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +31 -8
- package/dist/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +6 -6
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +2 -4
- package/dist/replica.d.ts +5 -11
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +16 -18
- package/dist/retried.d.ts +30 -0
- package/dist/retried.d.ts.map +1 -0
- package/dist/retried.js +72 -0
- package/dist/room-draft.d.ts +30 -5
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +275 -65
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +11 -6
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +45 -0
- package/dist/rows.d.ts +11 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +27 -14
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +13 -19
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +43 -90
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +314 -223
- package/dist/saves.d.ts +6 -42
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +176 -718
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +4 -4
- package/dist/shown.d.ts +9 -5
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +93 -57
- package/dist/socket/lanes.d.ts +12 -4
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +34 -8
- package/dist/socket/session.d.ts +4 -1
- package/dist/socket/session.d.ts.map +1 -1
- package/dist/socket/session.js +3 -0
- package/dist/socket.d.ts +4 -6
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -14
- package/dist/source.d.ts +7 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +24 -7
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +67 -24
- package/dist/store/rooms-shown.d.ts +8 -0
- package/dist/store/rooms-shown.d.ts.map +1 -0
- package/dist/store/rooms-shown.js +13 -0
- package/dist/store.d.ts +25 -15
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +50 -18
- package/dist/stored.d.ts +39 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +217 -59
- package/dist/surface.d.ts +14 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +65 -34
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +127 -102
- package/dist/tables.d.ts +28 -56
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +95 -329
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +1 -2
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +51 -11
- package/dist/wire.d.ts +71 -12
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +30 -14
- package/package.json +4 -3
- package/dist/attempt.d.ts +0 -16
- package/dist/attempt.d.ts.map +0 -1
- package/dist/attempt.js +0 -70
- package/dist/job.d.ts +0 -33
- package/dist/job.d.ts.map +0 -1
- package/dist/job.js +0 -54
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
- package/dist/socket/rooms.d.ts +0 -44
- package/dist/socket/rooms.d.ts.map +0 -1
- package/dist/socket/rooms.js +0 -90
- package/dist/store/fences.d.ts +0 -16
- package/dist/store/fences.d.ts.map +0 -1
- package/dist/store/fences.js +0 -26
package/dist/conversation.js
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
1
|
import { cursorOf, decodedCursor } from '@agentshouse/mdmodel';
|
|
2
|
+
import { applied, isTurn, standingState, } from '@agentshouse/session-content';
|
|
2
3
|
import { conversationChangeSet } from './change-set.js';
|
|
3
4
|
import { FACTS, QUIET, } from './conversation-live.js';
|
|
4
5
|
import { heldFacts } from './conversation-row.js';
|
|
5
6
|
import { runtimeError, uncaught } from './failure.js';
|
|
6
7
|
import { refusedForSpace } from './durability.js';
|
|
7
8
|
import { changeBatchIdentity, chatDraftRevision } from './identity.js';
|
|
8
|
-
import { OFFLINE } from './outcome.js';
|
|
9
|
-
import {
|
|
9
|
+
import { OFFLINE, } from './outcome.js';
|
|
10
|
+
import { runningLine } from './parts.js';
|
|
11
|
+
import { record, text } from './read.js';
|
|
10
12
|
import { openQuestion, questionAsked } from './questions.js';
|
|
11
13
|
import { untilAnswered } from './recovery.js';
|
|
14
|
+
import { retrying } from './retried.js';
|
|
12
15
|
import { capped, FROM_START, messageOrder, precedes } from './windows.js';
|
|
13
16
|
export function unheldView(conversation) {
|
|
14
17
|
return {
|
|
@@ -21,15 +24,18 @@ export function unheldView(conversation) {
|
|
|
21
24
|
commands: [],
|
|
22
25
|
options: [],
|
|
23
26
|
starting: null,
|
|
24
|
-
|
|
25
|
-
|
|
27
|
+
state: null,
|
|
28
|
+
deliveryWaiting: [],
|
|
26
29
|
deliveryUnknown: [],
|
|
27
30
|
chatDraft: null,
|
|
28
|
-
|
|
31
|
+
dismissedSuggestion: null,
|
|
32
|
+
pins: [],
|
|
29
33
|
};
|
|
30
34
|
}
|
|
31
35
|
export const SESSION_STARTED = 'Session started';
|
|
32
36
|
const NEW_CHAT = 'new:';
|
|
37
|
+
const LISTING = 'listing';
|
|
38
|
+
export const CATCHING_UP = 'catching-up';
|
|
33
39
|
export const HISTORY_CONVERSATIONS = 64;
|
|
34
40
|
export function newChat(agent) {
|
|
35
41
|
return `${NEW_CHAT}${agent}`;
|
|
@@ -42,52 +48,15 @@ function creationOf(input) {
|
|
|
42
48
|
}
|
|
43
49
|
function startedTurn(turn, operation) {
|
|
44
50
|
if (operation.op === 'begin')
|
|
45
|
-
return { turn, started: operation.at, parts: []
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
turn,
|
|
49
|
-
started: null,
|
|
50
|
-
parts: [],
|
|
51
|
-
context: { used: operation.used, window: operation.window },
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
return operation.op === 'start' && operation.index === 0
|
|
55
|
-
? { turn, started: null, parts: [structuredClone(operation.part)], context: null }
|
|
56
|
-
: null;
|
|
57
|
-
}
|
|
58
|
-
function changedFields(part, operation) {
|
|
59
|
-
if (operation.op === 'append') {
|
|
60
|
-
return { text: `${String(part.text ?? '')}${operation.text}` };
|
|
61
|
-
}
|
|
62
|
-
if (operation.op === 'status') {
|
|
63
|
-
return { status: operation.status, result: structuredClone(operation.result) };
|
|
64
|
-
}
|
|
65
|
-
if (operation.op === 'count')
|
|
66
|
-
return { count: operation.count };
|
|
67
|
-
return { entries: structuredClone(operation.entries) };
|
|
51
|
+
return { turn, started: operation.at, parts: [] };
|
|
52
|
+
const parts = applied([], operation);
|
|
53
|
+
return parts === null ? null : { turn, started: null, parts };
|
|
68
54
|
}
|
|
69
55
|
function appliedTurn(held, operation) {
|
|
70
56
|
if (operation.op === 'begin')
|
|
71
57
|
return { ...held, started: operation.at };
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
75
|
-
if (operation.op === 'start') {
|
|
76
|
-
if (operation.index !== 0 && operation.index !== held.parts.length)
|
|
77
|
-
return null;
|
|
78
|
-
return {
|
|
79
|
-
...held,
|
|
80
|
-
parts: [...held.parts.slice(0, operation.index), structuredClone(operation.part)],
|
|
81
|
-
};
|
|
82
|
-
}
|
|
83
|
-
const part = held.parts[operation.index];
|
|
84
|
-
if (typeof part !== 'object' || part === null)
|
|
85
|
-
return null;
|
|
86
|
-
const changed = { ...part, ...changedFields(part, operation) };
|
|
87
|
-
return {
|
|
88
|
-
...held,
|
|
89
|
-
parts: held.parts.map((kept, at) => (at === operation.index ? changed : kept)),
|
|
90
|
-
};
|
|
58
|
+
const parts = applied(held.parts, operation);
|
|
59
|
+
return parts === null ? null : { ...held, parts };
|
|
91
60
|
}
|
|
92
61
|
function windowOf(held, arriving, limit) {
|
|
93
62
|
const byIdentity = new Map(held.map((message) => [message.identity, message]));
|
|
@@ -110,7 +79,7 @@ function frameOf(asked, messages, more, total) {
|
|
|
110
79
|
};
|
|
111
80
|
}
|
|
112
81
|
function newestOf(arriving, from) {
|
|
113
|
-
return arriving.reduce((top, message) => (top === null || message.
|
|
82
|
+
return arriving.reduce((top, message) => (top === null || message.change > top ? message.change : top), from);
|
|
114
83
|
}
|
|
115
84
|
function acceptedMessage(value) {
|
|
116
85
|
if (typeof value !== 'object' || value === null)
|
|
@@ -119,6 +88,7 @@ function acceptedMessage(value) {
|
|
|
119
88
|
if (typeof record.identity !== 'string' ||
|
|
120
89
|
typeof record.turn !== 'string' ||
|
|
121
90
|
typeof record.position !== 'string' ||
|
|
91
|
+
typeof record.change !== 'string' ||
|
|
122
92
|
typeof record.text !== 'string') {
|
|
123
93
|
return null;
|
|
124
94
|
}
|
|
@@ -126,6 +96,7 @@ function acceptedMessage(value) {
|
|
|
126
96
|
identity: record.identity,
|
|
127
97
|
turn: record.turn,
|
|
128
98
|
position: record.position,
|
|
99
|
+
change: record.change,
|
|
129
100
|
text: record.text,
|
|
130
101
|
message: structuredClone(record.message),
|
|
131
102
|
};
|
|
@@ -227,17 +198,17 @@ function withSubmitted(draft, submitted) {
|
|
|
227
198
|
const { submitted: _held, ...unsent } = draft;
|
|
228
199
|
return submitted.length === 0 ? unsent : { ...unsent, submitted };
|
|
229
200
|
}
|
|
230
|
-
function
|
|
231
|
-
return
|
|
201
|
+
export function joinedDraft(first, second) {
|
|
202
|
+
return [first, second].filter((one) => one !== '').join('\n');
|
|
232
203
|
}
|
|
233
204
|
function returned(draft, submission, others) {
|
|
234
205
|
return withSubmitted({
|
|
235
206
|
conversation: draft.conversation,
|
|
236
|
-
|
|
207
|
+
text: joinedDraft(submission.text, draft.text),
|
|
237
208
|
revision: chatDraftRevision(),
|
|
238
209
|
}, others);
|
|
239
210
|
}
|
|
240
|
-
function viewOf(alive, conversation, held, frame, draft, ended,
|
|
211
|
+
function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
|
|
241
212
|
const facts = alive.liveOf(conversation);
|
|
242
213
|
return {
|
|
243
214
|
conversation,
|
|
@@ -255,26 +226,45 @@ function viewOf(alive, conversation, held, frame, draft, ended, marked) {
|
|
|
255
226
|
commands: structuredClone(facts.commands),
|
|
256
227
|
options: structuredClone(facts.options),
|
|
257
228
|
starting: facts.starting,
|
|
258
|
-
|
|
259
|
-
|
|
229
|
+
state: sessionOf(facts, held, ended),
|
|
230
|
+
deliveryWaiting: [...facts.deliveryWaiting],
|
|
260
231
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
261
232
|
chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
: jobsOf(marked.filter(({ at }) => ended === null || at > ended), facts.turn),
|
|
233
|
+
dismissedSuggestion: dismissed,
|
|
234
|
+
pins: [...pins],
|
|
265
235
|
};
|
|
266
236
|
}
|
|
237
|
+
function standing(facts, saved, ended) {
|
|
238
|
+
if (facts.state !== null)
|
|
239
|
+
return structuredClone(facts.state);
|
|
240
|
+
if (saved === null)
|
|
241
|
+
return null;
|
|
242
|
+
const down = facts.process?.running === false;
|
|
243
|
+
return structuredClone(standingState(saved.state, saved.at, down ? saved.at : ended));
|
|
244
|
+
}
|
|
245
|
+
function sessionOf(facts, held, ended) {
|
|
246
|
+
const saved = [...held]
|
|
247
|
+
.reverse()
|
|
248
|
+
.map(({ message }) => record(message))
|
|
249
|
+
.find(({ content }) => isTurn(content));
|
|
250
|
+
const at = saved === undefined ? null : text(saved, 'accepted_at');
|
|
251
|
+
return standing(facts, saved === undefined || !isTurn(saved.content) || at === null
|
|
252
|
+
? null
|
|
253
|
+
: { state: saved.content.state, at }, ended);
|
|
254
|
+
}
|
|
267
255
|
function emit(alive, conversation) {
|
|
268
256
|
if (alive.deps.closed())
|
|
269
257
|
return;
|
|
270
258
|
for (const view of alive.views()) {
|
|
271
|
-
const
|
|
259
|
+
const held = view.held.now();
|
|
260
|
+
const { window } = held;
|
|
272
261
|
if (view.conversation !== conversation || window === null)
|
|
273
262
|
continue;
|
|
274
263
|
const ready = view.ready();
|
|
275
264
|
if (ready.length === 0)
|
|
276
265
|
continue;
|
|
277
|
-
const
|
|
266
|
+
const frame = sharedFrame(view, window);
|
|
267
|
+
const value = viewOf(alive, conversation, window, frame, held);
|
|
278
268
|
for (const watcher of ready)
|
|
279
269
|
watcher.notify(value);
|
|
280
270
|
}
|
|
@@ -285,23 +275,18 @@ function sharedFrame(view, window) {
|
|
|
285
275
|
}
|
|
286
276
|
async function slide(alive, local, conversation, arriving) {
|
|
287
277
|
let count;
|
|
288
|
-
let marked;
|
|
289
278
|
for (const view of alive.views()) {
|
|
290
279
|
const { held } = view;
|
|
291
280
|
const { window, total } = held.now();
|
|
292
281
|
if (view.conversation !== conversation || window === null)
|
|
293
282
|
continue;
|
|
294
283
|
if (arriving === null) {
|
|
295
|
-
held.set({ window: [],
|
|
284
|
+
held.set({ window: [], more: false, total: total === null ? null : 0 });
|
|
296
285
|
continue;
|
|
297
286
|
}
|
|
298
287
|
const joining = arriving.filter((message) => precedes(message, view.asked.before));
|
|
299
288
|
const next = windowOf(window, joining, view.asked.limit);
|
|
300
289
|
held.set({ window: next.messages, more: held.now().more || next.dropped });
|
|
301
|
-
if (arriving.length > 0) {
|
|
302
|
-
marked ??= await local.jobMarkers(conversation);
|
|
303
|
-
held.set({ marked });
|
|
304
|
-
}
|
|
305
290
|
if (held.now().total !== null && arriving.length > 0) {
|
|
306
291
|
count ??= await local.messageCount(conversation);
|
|
307
292
|
held.set({ total: count });
|
|
@@ -315,76 +300,106 @@ function stateOf(alive, conversation) {
|
|
|
315
300
|
return facts.turn === null ? 'idle' : 'working';
|
|
316
301
|
}
|
|
317
302
|
function rowOf(alive, conversation) {
|
|
318
|
-
const { turn, questions } = alive.liveOf(conversation);
|
|
303
|
+
const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
|
|
319
304
|
return {
|
|
320
305
|
state: stateOf(alive, conversation),
|
|
321
306
|
started: turn?.started ?? null,
|
|
322
307
|
line: turn === null ? null : runningLine(turn.parts),
|
|
323
308
|
question: openQuestion(questions),
|
|
324
309
|
asked: questionAsked(questions),
|
|
310
|
+
deliveryWaiting: [...deliveryWaiting],
|
|
325
311
|
};
|
|
326
312
|
}
|
|
327
313
|
async function entries(alive) {
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
314
|
+
const listing = await heldListing(alive);
|
|
315
|
+
if (listing === null)
|
|
316
|
+
return null;
|
|
317
|
+
const list = listing.conversations;
|
|
318
|
+
const agents = new Map(listing.agents.map((agent) => [agent.id, agent]));
|
|
319
|
+
if (list.some((entry) => !agents.has(entry.agent)))
|
|
330
320
|
return null;
|
|
331
321
|
const held = list.length === 0
|
|
332
322
|
? []
|
|
333
323
|
: await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
|
|
334
324
|
const rows = new Map(held.map((one) => [one.conversation, one]));
|
|
335
|
-
return list.map((entry) =>
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
325
|
+
return list.map((entry) => {
|
|
326
|
+
const agent = agents.get(entry.agent);
|
|
327
|
+
return {
|
|
328
|
+
conversation: entry.conversation,
|
|
329
|
+
agent: { identity: agent.id, name: agent.name, retired: agent.retired_at !== null },
|
|
330
|
+
name: entry.name,
|
|
331
|
+
created: entry.created,
|
|
332
|
+
outcome: entry.outcome,
|
|
333
|
+
waiting: entry.waiting,
|
|
334
|
+
subject: entry.subject,
|
|
335
|
+
room: entry.room,
|
|
336
|
+
model: entry.model,
|
|
337
|
+
effort: entry.effort,
|
|
338
|
+
...rowOf(alive, entry.conversation),
|
|
339
|
+
...heldFacts(rows.get(entry.conversation), entry),
|
|
340
|
+
jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
|
|
341
|
+
};
|
|
342
|
+
});
|
|
346
343
|
}
|
|
347
|
-
async function
|
|
348
|
-
const
|
|
349
|
-
if (
|
|
350
|
-
return
|
|
351
|
-
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
344
|
+
async function heldListing(alive) {
|
|
345
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
346
|
+
if (conversationList !== null && agentList !== null)
|
|
347
|
+
return { conversations: conversationList, agents: agentList };
|
|
348
|
+
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
349
|
+
? null
|
|
350
|
+
: { conversations: [], agents: [] };
|
|
352
351
|
}
|
|
353
352
|
async function endedIn(alive, conversation) {
|
|
354
|
-
const
|
|
355
|
-
return
|
|
353
|
+
const listing = await heldListing(alive);
|
|
354
|
+
return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
|
|
355
|
+
null);
|
|
356
|
+
}
|
|
357
|
+
function upserted(kept, set, key) {
|
|
358
|
+
const held = new Map(kept.map((one) => [key(one), one]));
|
|
359
|
+
for (const one of set)
|
|
360
|
+
held.set(key(one), { ...one });
|
|
361
|
+
return held;
|
|
356
362
|
}
|
|
357
363
|
function listChanged(alive, change) {
|
|
358
364
|
void alive.deps
|
|
359
365
|
.durably(async (local) => {
|
|
360
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
366
|
+
const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
|
|
367
|
+
if (readUntil === null)
|
|
368
|
+
await local.fact('readUntil', new Date().toISOString());
|
|
369
|
+
const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
|
|
370
|
+
for (const entry of change.set)
|
|
365
371
|
alive.created(entry.conversation);
|
|
366
|
-
}
|
|
367
372
|
if (change.gone !== null)
|
|
368
373
|
held.delete(change.gone);
|
|
369
374
|
const list = [...held.values()];
|
|
375
|
+
const agents = [
|
|
376
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
377
|
+
];
|
|
370
378
|
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
371
379
|
await local.fact('conversationList', list);
|
|
372
380
|
}
|
|
381
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
382
|
+
await local.fact('agentList', agents);
|
|
383
|
+
}
|
|
373
384
|
if (change.cursor !== undefined) {
|
|
374
385
|
if (change.cursor !== conversationCursor) {
|
|
375
386
|
await local.fact('conversationCursor', change.cursor);
|
|
376
387
|
}
|
|
377
388
|
alive.deps.stream()?.hold(change.cursor);
|
|
378
389
|
}
|
|
379
|
-
return list;
|
|
390
|
+
return { conversations: list, agents };
|
|
380
391
|
})
|
|
381
|
-
.catch(async () =>
|
|
382
|
-
.
|
|
392
|
+
.catch(async () => {
|
|
393
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
394
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
395
|
+
})
|
|
396
|
+
.then((listing) => {
|
|
383
397
|
if (alive.deps.closed() || change.paged === true)
|
|
384
398
|
return;
|
|
399
|
+
const list = listing.conversations;
|
|
385
400
|
endedAnew(alive, list);
|
|
386
401
|
if (change.cursor !== undefined) {
|
|
387
|
-
alive.held.set({ listKnown: true });
|
|
402
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
388
403
|
settleBehind(alive, list);
|
|
389
404
|
openingEnded(alive);
|
|
390
405
|
alive.deps.settled();
|
|
@@ -392,11 +407,12 @@ function listChanged(alive, change) {
|
|
|
392
407
|
emitList(alive);
|
|
393
408
|
if (!alive.known())
|
|
394
409
|
return;
|
|
395
|
-
retiredDrafts(alive,
|
|
396
|
-
const { replicated } = alive.held.now();
|
|
397
|
-
if (change.cursor === undefined
|
|
398
|
-
|
|
399
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
410
|
+
retiredDrafts(alive, listing);
|
|
411
|
+
const { replicated, openingRead } = alive.held.now();
|
|
412
|
+
if (change.cursor === undefined
|
|
413
|
+
? list.length !== replicated.size ||
|
|
414
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
415
|
+
: openingRead) {
|
|
400
416
|
alive.deps.again();
|
|
401
417
|
}
|
|
402
418
|
}, uncaught);
|
|
@@ -412,23 +428,23 @@ function endedAnew(alive, list) {
|
|
|
412
428
|
emit(alive, view.conversation);
|
|
413
429
|
}
|
|
414
430
|
}
|
|
415
|
-
function
|
|
416
|
-
const reading =
|
|
431
|
+
function shownListing(alive, work) {
|
|
432
|
+
const reading = heldListing(alive);
|
|
417
433
|
alive.inOrder(async () => {
|
|
418
|
-
const
|
|
434
|
+
const listing = await reading.catch((error) => {
|
|
419
435
|
uncaught(error);
|
|
420
436
|
return null;
|
|
421
437
|
});
|
|
422
|
-
if (
|
|
438
|
+
if (listing === null || alive.deps.closed())
|
|
423
439
|
return;
|
|
424
|
-
work(
|
|
440
|
+
work(listing);
|
|
425
441
|
});
|
|
426
442
|
}
|
|
427
443
|
async function told(alive) {
|
|
428
444
|
try {
|
|
429
445
|
while (alive.held.now().listOwed && !alive.deps.closed()) {
|
|
430
446
|
alive.held.set({ listOwed: false });
|
|
431
|
-
const value = await untilAnswered(() => entries(alive), alive.closing);
|
|
447
|
+
const value = await untilAnswered(retrying(alive.deps.retries, 'conversations', LISTING, () => entries(alive)), alive.closing, () => true, alive.deps.recovery);
|
|
432
448
|
if (alive.deps.closed())
|
|
433
449
|
return;
|
|
434
450
|
if (value === null)
|
|
@@ -466,75 +482,73 @@ export function conversationsLearned(alive) {
|
|
|
466
482
|
return;
|
|
467
483
|
if (alive.listeners.waiting())
|
|
468
484
|
tellList(alive);
|
|
469
|
-
if (!alive.agentListeners.waiting())
|
|
485
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
470
486
|
return;
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
487
|
+
shownListing(alive, (listing) => {
|
|
488
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
489
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
function agentsOf(listing) {
|
|
493
|
+
return listing.agents
|
|
494
|
+
.filter((agent) => agent.retired_at === null)
|
|
495
|
+
.map((agent) => ({
|
|
496
|
+
identity: agent.id,
|
|
497
|
+
name: agent.name,
|
|
498
|
+
cli: agent.cli,
|
|
499
|
+
model: agent.model,
|
|
500
|
+
effort: agent.effort,
|
|
501
|
+
environment: {
|
|
502
|
+
identity: agent.environment,
|
|
503
|
+
name: agent.environment_name,
|
|
504
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
505
|
+
},
|
|
506
|
+
}))
|
|
483
507
|
.sort((left, right) => left.name === right.name
|
|
484
508
|
? left.identity.localeCompare(right.identity)
|
|
485
509
|
: left.name.localeCompare(right.name));
|
|
486
510
|
}
|
|
487
|
-
function readAgents(alive) {
|
|
488
|
-
const stream = alive.deps.stream();
|
|
489
|
-
if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
|
|
490
|
-
return;
|
|
491
|
-
const { agents: read } = stream;
|
|
492
|
-
const { agentListeners } = alive;
|
|
493
|
-
alive.held.set({ agentsReading: true });
|
|
494
|
-
void alive.deps.recovery
|
|
495
|
-
.attempt('agents', async () => {
|
|
496
|
-
if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
|
|
497
|
-
return 'done';
|
|
498
|
-
}
|
|
499
|
-
const listed = await read();
|
|
500
|
-
if (listed === null)
|
|
501
|
-
return 'done';
|
|
502
|
-
alive.held.set({ listedAgents: listed });
|
|
503
|
-
emitAgents(alive);
|
|
504
|
-
return 'done';
|
|
505
|
-
})
|
|
506
|
-
.finally(() => {
|
|
507
|
-
alive.held.set({ agentsReading: false });
|
|
508
|
-
});
|
|
509
|
-
}
|
|
510
511
|
function emitAgents(alive) {
|
|
511
|
-
|
|
512
|
+
const { agentListeners, listedListeners } = alive;
|
|
513
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
512
514
|
return;
|
|
513
|
-
|
|
514
|
-
const value =
|
|
515
|
+
shownListing(alive, (listing) => {
|
|
516
|
+
const value = agentsOf(listing);
|
|
515
517
|
const shown = JSON.stringify(value);
|
|
516
|
-
if (shown
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
518
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
519
|
+
alive.held.set({ agentsShown: shown });
|
|
520
|
+
agentListeners.tell(value);
|
|
521
|
+
}
|
|
522
|
+
const listed = JSON.stringify(listing.agents);
|
|
523
|
+
if (listed !== alive.held.now().listedShown) {
|
|
524
|
+
alive.held.set({ listedShown: listed });
|
|
525
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
526
|
+
}
|
|
520
527
|
});
|
|
521
528
|
}
|
|
529
|
+
function ran({ state, process }) {
|
|
530
|
+
return JSON.stringify([state?.running ?? null, process?.running ?? null]);
|
|
531
|
+
}
|
|
522
532
|
function setLive(alive, conversation, next) {
|
|
533
|
+
const was = ran(alive.liveOf(conversation));
|
|
523
534
|
const before = rowOf(alive, conversation);
|
|
524
535
|
alive.holdLive(conversation, next);
|
|
525
536
|
const after = rowOf(alive, conversation);
|
|
526
|
-
if (after.state !== before.state ||
|
|
537
|
+
if (after.state !== before.state ||
|
|
538
|
+
after.started !== before.started ||
|
|
539
|
+
ran(alive.liveOf(conversation)) !== was ||
|
|
540
|
+
after.deliveryWaiting.join() !== before.deliveryWaiting.join())
|
|
527
541
|
emitList(alive);
|
|
528
542
|
else if (after.line !== before.line ||
|
|
529
543
|
after.question !== before.question ||
|
|
530
544
|
after.asked !== before.asked)
|
|
531
545
|
tellSoon(alive);
|
|
532
546
|
}
|
|
533
|
-
function retiredChat(conversation,
|
|
547
|
+
function retiredChat(conversation, listing) {
|
|
534
548
|
if (!conversation.startsWith(NEW_CHAT))
|
|
535
549
|
return false;
|
|
536
550
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
537
|
-
return
|
|
551
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
538
552
|
}
|
|
539
553
|
function live(alive, conversation, change) {
|
|
540
554
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -553,8 +567,8 @@ function openingEnded(alive) {
|
|
|
553
567
|
commands: facts.has('commands') ? QUIET.commands : held.commands,
|
|
554
568
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
555
569
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
556
|
-
|
|
557
|
-
|
|
570
|
+
state: facts.has('state') ? QUIET.state : held.state,
|
|
571
|
+
deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
|
|
558
572
|
deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
|
|
559
573
|
});
|
|
560
574
|
emit(alive, conversation);
|
|
@@ -586,19 +600,13 @@ function handReplicated(alive) {
|
|
|
586
600
|
}
|
|
587
601
|
async function remove(alive, leaving) {
|
|
588
602
|
await alive.deps.durably(async (local) => {
|
|
589
|
-
const kept = new Set(
|
|
590
|
-
...(await local.conversations(leaving)).map(({ conversation }) => conversation),
|
|
591
|
-
...(await local.chatDrafts())
|
|
592
|
-
.filter(({ conversation }) => leaving.includes(conversation))
|
|
593
|
-
.map(({ conversation }) => conversation),
|
|
594
|
-
]);
|
|
595
|
-
await local.dropConversations(leaving);
|
|
603
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
596
604
|
const changed = [];
|
|
597
605
|
for (const conversation of leaving) {
|
|
598
606
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
599
607
|
changed.push(conversation);
|
|
600
608
|
}
|
|
601
|
-
|
|
609
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
602
610
|
alive.forget(conversation);
|
|
603
611
|
setLive(alive, conversation, null);
|
|
604
612
|
await slide(alive, local, conversation, null);
|
|
@@ -627,7 +635,7 @@ async function readsOf(local, conversations) {
|
|
|
627
635
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
628
636
|
}
|
|
629
637
|
function retiredDrafts(alive, list) {
|
|
630
|
-
if (!list.some((
|
|
638
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
631
639
|
return;
|
|
632
640
|
void alive.deps
|
|
633
641
|
.local()
|
|
@@ -670,14 +678,12 @@ function keep(alive, conversation, message) {
|
|
|
670
678
|
if (!alive.held.now().replicated.has(conversation))
|
|
671
679
|
return;
|
|
672
680
|
const read = (await readsOf(local, [conversation])).get(conversation)?.read;
|
|
673
|
-
const advances = read !== undefined &&
|
|
674
|
-
!alive.behind(conversation) &&
|
|
675
|
-
(read === null || message.position > read);
|
|
681
|
+
const advances = read !== undefined && !alive.behind(conversation) && (read === null || message.change > read);
|
|
676
682
|
await sealed(alive, local, conversation, new Set([message.turn]));
|
|
677
683
|
await local.keepMessages({
|
|
678
684
|
conversation,
|
|
679
685
|
messages: [message],
|
|
680
|
-
...(advances ? { read: { at: message.
|
|
686
|
+
...(advances ? { read: { at: message.change, partial: false } } : {}),
|
|
681
687
|
});
|
|
682
688
|
sealTurns(alive, conversation, new Set([message.turn]));
|
|
683
689
|
await slide(alive, local, conversation, [message]);
|
|
@@ -789,22 +795,21 @@ function heard(alive, event) {
|
|
|
789
795
|
live(alive, conversation, { starting: event.step });
|
|
790
796
|
return;
|
|
791
797
|
}
|
|
792
|
-
if (event.kind === '
|
|
793
|
-
live(alive, conversation, {
|
|
794
|
-
return;
|
|
795
|
-
}
|
|
796
|
-
if (event.kind === 'link') {
|
|
797
|
-
live(alive, conversation, { link: { connected: event.connected } });
|
|
798
|
+
if (event.kind === 'state') {
|
|
799
|
+
live(alive, conversation, { state: structuredClone(event.state) });
|
|
798
800
|
return;
|
|
799
801
|
}
|
|
800
802
|
if (event.kind === 'deliveries') {
|
|
801
|
-
live(alive, conversation, {
|
|
803
|
+
live(alive, conversation, {
|
|
804
|
+
deliveryWaiting: [...event.waiting],
|
|
805
|
+
deliveryUnknown: [...event.unknown],
|
|
806
|
+
});
|
|
802
807
|
return;
|
|
803
808
|
}
|
|
804
809
|
const arriving = acceptedMessage(event.message);
|
|
805
810
|
if (arriving === null)
|
|
806
811
|
return;
|
|
807
|
-
alive.heardAt(conversation, arriving.
|
|
812
|
+
alive.heardAt(conversation, arriving.change);
|
|
808
813
|
if (alive.held.now().replicated.has(conversation)) {
|
|
809
814
|
if (alive.deps.full()) {
|
|
810
815
|
alive.gapOpened(conversation);
|
|
@@ -822,19 +827,27 @@ function heard(alive, event) {
|
|
|
822
827
|
emit(alive, conversation);
|
|
823
828
|
}
|
|
824
829
|
async function kept(alive, local, conversation, following) {
|
|
825
|
-
const
|
|
826
|
-
if (
|
|
830
|
+
const draft = following === null || empty(following) ? null : following;
|
|
831
|
+
if (draft === null)
|
|
827
832
|
await local.dropChatDraft(conversation);
|
|
828
833
|
else
|
|
829
|
-
await local.keepChatDrafts([
|
|
830
|
-
|
|
834
|
+
await local.keepChatDrafts([draft]);
|
|
835
|
+
heldInViews(alive, conversation, { draft });
|
|
831
836
|
}
|
|
832
|
-
function
|
|
837
|
+
function heldInViews(alive, conversation, held) {
|
|
833
838
|
for (const view of alive.views()) {
|
|
834
839
|
if (view.conversation === conversation)
|
|
835
|
-
view.held.set(
|
|
840
|
+
view.held.set(held);
|
|
836
841
|
}
|
|
837
842
|
}
|
|
843
|
+
async function factOf(local, name) {
|
|
844
|
+
return Object.fromEntries((await local.conversationFacts())
|
|
845
|
+
.filter((fact) => fact.name === name)
|
|
846
|
+
.map(({ conversation, value }) => [conversation, value]));
|
|
847
|
+
}
|
|
848
|
+
async function dismissedIn(local, conversation) {
|
|
849
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
850
|
+
}
|
|
838
851
|
async function draftAt(local, conversation) {
|
|
839
852
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
840
853
|
}
|
|
@@ -865,9 +878,9 @@ function moved(alive, agent, operation, to) {
|
|
|
865
878
|
: [{ ...unsent, conversation: to }];
|
|
866
879
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
867
880
|
await local.keepChatDrafts([left, ...taken]);
|
|
868
|
-
|
|
881
|
+
heldInViews(alive, from, { draft: left });
|
|
869
882
|
for (const one of taken)
|
|
870
|
-
|
|
883
|
+
heldInViews(alive, to, { draft: one });
|
|
871
884
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
872
885
|
});
|
|
873
886
|
}
|
|
@@ -898,13 +911,10 @@ async function submitted(alive, conversation, operation, draft) {
|
|
|
898
911
|
});
|
|
899
912
|
return submission;
|
|
900
913
|
}
|
|
901
|
-
async function dispatched(alive, conversation, submission) {
|
|
914
|
+
async function dispatched(alive, conversation, submission, resent = false) {
|
|
902
915
|
const dispatch = alive.sendingBegan(submission.operation);
|
|
903
916
|
try {
|
|
904
|
-
const result = await invoke(alive, 'conversations/send', conversation, {
|
|
905
|
-
operation_id: submission.operation,
|
|
906
|
-
text: submission.text,
|
|
907
|
-
});
|
|
917
|
+
const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
|
|
908
918
|
dispatch.set({ answered: result.kind !== 'transport-uncertainty' });
|
|
909
919
|
if (result.kind === 'revoked-authorization')
|
|
910
920
|
return result;
|
|
@@ -912,6 +922,7 @@ async function dispatched(alive, conversation, submission) {
|
|
|
912
922
|
alive.deps.unanswered();
|
|
913
923
|
return result;
|
|
914
924
|
}
|
|
925
|
+
alive.deps.heard(submission.operation, resent);
|
|
915
926
|
const turn = answered(result, 'message_id');
|
|
916
927
|
await withDraft(alive, conversation, async (current, local) => {
|
|
917
928
|
const held = current?.submitted?.find((one) => one.operation === submission.operation);
|
|
@@ -931,11 +942,12 @@ async function dispatched(alive, conversation, submission) {
|
|
|
931
942
|
alive.sendingEnded(submission.operation, dispatch);
|
|
932
943
|
}
|
|
933
944
|
}
|
|
934
|
-
function invoke(alive, name, conversation, extra = {
|
|
935
|
-
return alive.deps.call(name, { conversation_id: conversation, ...extra });
|
|
945
|
+
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
946
|
+
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
936
947
|
}
|
|
937
|
-
export function conversationSurface(alive) {
|
|
948
|
+
export function conversationSurface(alive, files) {
|
|
938
949
|
return {
|
|
950
|
+
...files,
|
|
939
951
|
list() {
|
|
940
952
|
return new Promise((settle) => {
|
|
941
953
|
const answer = (listed) => {
|
|
@@ -953,8 +965,12 @@ export function conversationSurface(alive) {
|
|
|
953
965
|
return alive.deps.durably(async (local) => {
|
|
954
966
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
955
967
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
956
|
-
|
|
957
|
-
|
|
968
|
+
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
|
|
969
|
+
draft: (await local.chatDraft(conversation)) ?? null,
|
|
970
|
+
ended: await endedIn(alive, conversation),
|
|
971
|
+
dismissed: await dismissedIn(local, conversation),
|
|
972
|
+
pins: (await local.facts()).chatPins,
|
|
973
|
+
}));
|
|
958
974
|
});
|
|
959
975
|
},
|
|
960
976
|
async create(input) {
|
|
@@ -962,7 +978,7 @@ export function conversationSurface(alive) {
|
|
|
962
978
|
const conversation = answered(result, 'conversation_id');
|
|
963
979
|
if (conversation === null)
|
|
964
980
|
return result;
|
|
965
|
-
const listed = (await
|
|
981
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
966
982
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
967
983
|
alive.creating(conversation);
|
|
968
984
|
}
|
|
@@ -991,40 +1007,90 @@ export function conversationSurface(alive) {
|
|
|
991
1007
|
}
|
|
992
1008
|
return OFFLINE;
|
|
993
1009
|
},
|
|
994
|
-
answer(conversation, answer) {
|
|
995
|
-
return invoke(alive, 'conversations/interaction/answer', conversation,
|
|
996
|
-
|
|
997
|
-
|
|
1010
|
+
answer(conversation, answer, operation) {
|
|
1011
|
+
return invoke(alive, 'conversations/interaction/answer', conversation, operation, answer);
|
|
1012
|
+
},
|
|
1013
|
+
interrupt(conversation, operation) {
|
|
1014
|
+
return invoke(alive, 'conversations/interrupt', conversation, operation);
|
|
1015
|
+
},
|
|
1016
|
+
kill(conversation, operation) {
|
|
1017
|
+
return invoke(alive, 'conversations/kill', conversation, operation);
|
|
1018
|
+
},
|
|
1019
|
+
delete(conversation, operation) {
|
|
1020
|
+
return invoke(alive, 'conversations/delete', conversation, operation);
|
|
1021
|
+
},
|
|
1022
|
+
takeOut(conversation, message, operation) {
|
|
1023
|
+
return invoke(alive, 'conversations/take-out', conversation, operation, {
|
|
1024
|
+
message_id: message,
|
|
1025
|
+
});
|
|
1026
|
+
},
|
|
1027
|
+
decide({ request, room, message }, decision, operation) {
|
|
1028
|
+
return alive.deps.call('agent-functions/decide', {
|
|
1029
|
+
room_ref: room,
|
|
1030
|
+
request,
|
|
1031
|
+
...(message === undefined ? {} : { message }),
|
|
1032
|
+
decision,
|
|
1033
|
+
operation_id: operation,
|
|
998
1034
|
});
|
|
999
1035
|
},
|
|
1000
|
-
|
|
1001
|
-
return invoke(alive, 'conversations/
|
|
1036
|
+
rename(conversation, name, operation) {
|
|
1037
|
+
return invoke(alive, 'conversations/rename', conversation, operation, { name });
|
|
1002
1038
|
},
|
|
1003
|
-
|
|
1004
|
-
return invoke(alive, 'conversations/
|
|
1039
|
+
set(conversation, settings, operation) {
|
|
1040
|
+
return invoke(alive, 'conversations/set', conversation, operation, settings);
|
|
1005
1041
|
},
|
|
1006
|
-
|
|
1007
|
-
return invoke(alive, 'conversations/
|
|
1042
|
+
retry(conversation, message, operation) {
|
|
1043
|
+
return invoke(alive, 'conversations/retry', conversation, operation, {
|
|
1044
|
+
message_id: message,
|
|
1045
|
+
});
|
|
1046
|
+
},
|
|
1047
|
+
async pin(figures) {
|
|
1048
|
+
const pins = [...figures];
|
|
1049
|
+
await alive.deps.durably((local) => local.fact('chatPins', pins));
|
|
1050
|
+
const views = [...alive.views()];
|
|
1051
|
+
for (const view of views)
|
|
1052
|
+
view.held.set({ pins });
|
|
1053
|
+
for (const conversation of new Set(views.map((view) => view.conversation))) {
|
|
1054
|
+
emit(alive, conversation);
|
|
1055
|
+
}
|
|
1056
|
+
},
|
|
1057
|
+
async openTurn(conversation, turn) {
|
|
1058
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1059
|
+
tellList(alive);
|
|
1060
|
+
},
|
|
1061
|
+
dismissSuggestion(conversation, suggestion) {
|
|
1062
|
+
return alive.deps.durably(async (local) => {
|
|
1063
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1064
|
+
return;
|
|
1065
|
+
await local.keepConversationFact({
|
|
1066
|
+
conversation,
|
|
1067
|
+
name: 'dismissedSuggestion',
|
|
1068
|
+
value: suggestion,
|
|
1069
|
+
});
|
|
1070
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1071
|
+
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1072
|
+
});
|
|
1008
1073
|
},
|
|
1009
1074
|
};
|
|
1010
1075
|
}
|
|
1076
|
+
function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
|
|
1077
|
+
return withDraft(alive, conversation, (current) => ({
|
|
1078
|
+
conversation,
|
|
1079
|
+
text: text(current?.text ?? ''),
|
|
1080
|
+
revision,
|
|
1081
|
+
...(current === undefined ? {} : pending(current)),
|
|
1082
|
+
}));
|
|
1083
|
+
}
|
|
1011
1084
|
export function chatDraftSurface(alive) {
|
|
1012
1085
|
return {
|
|
1013
|
-
write(conversation, draft, revision
|
|
1014
|
-
return
|
|
1015
|
-
conversation,
|
|
1016
|
-
text: draft.text,
|
|
1017
|
-
revision,
|
|
1018
|
-
...(current === undefined ? {} : pending(current)),
|
|
1019
|
-
}));
|
|
1086
|
+
write(conversation, draft, revision) {
|
|
1087
|
+
return rewritten(alive, conversation, () => draft.text, revision);
|
|
1020
1088
|
},
|
|
1021
1089
|
prepend(conversation, draft) {
|
|
1022
|
-
return
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
...(current === undefined ? {} : pending(current)),
|
|
1027
|
-
}));
|
|
1090
|
+
return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
|
|
1091
|
+
},
|
|
1092
|
+
append(conversation, draft) {
|
|
1093
|
+
return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
|
|
1028
1094
|
},
|
|
1029
1095
|
discard(conversation) {
|
|
1030
1096
|
return withDraft(alive, conversation, (current) => current === undefined
|
|
@@ -1034,31 +1100,37 @@ export function chatDraftSurface(alive) {
|
|
|
1034
1100
|
};
|
|
1035
1101
|
}
|
|
1036
1102
|
export async function conversationsOpened(alive, local) {
|
|
1037
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1038
|
-
if (conversationList === null ||
|
|
1103
|
+
const { conversationList, agentList, conversationCursor } = await local.facts();
|
|
1104
|
+
if (conversationList === null || agentList === null)
|
|
1105
|
+
return;
|
|
1106
|
+
alive.held.set({ listHeld: true });
|
|
1107
|
+
if (alive.known())
|
|
1039
1108
|
return;
|
|
1040
1109
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1041
1110
|
conversationsLearned(alive);
|
|
1042
1111
|
}
|
|
1112
|
+
export function reconcileOpening(alive) {
|
|
1113
|
+
alive.held.set({ openingRead: true });
|
|
1114
|
+
return reconcileConversations(alive);
|
|
1115
|
+
}
|
|
1043
1116
|
export async function reconcileConversations(alive) {
|
|
1044
1117
|
if (!alive.known())
|
|
1045
1118
|
return;
|
|
1046
1119
|
const local = await alive.deps.local();
|
|
1047
|
-
const [held,
|
|
1120
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1048
1121
|
local.conversations(),
|
|
1049
|
-
local.
|
|
1122
|
+
local.storedConversations(),
|
|
1050
1123
|
local.facts(),
|
|
1051
1124
|
]);
|
|
1052
1125
|
const list = conversationList ?? [];
|
|
1126
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1053
1127
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1054
1128
|
const named = new Set(entries.keys());
|
|
1055
1129
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1056
1130
|
const { replicated } = alive.held.now();
|
|
1057
|
-
const leaving = [
|
|
1058
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1059
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1131
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1060
1132
|
!alive.isCreating(conversation) &&
|
|
1061
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1133
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1062
1134
|
for (const conversation of named) {
|
|
1063
1135
|
if (!replicated.has(conversation) &&
|
|
1064
1136
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1093,6 +1165,17 @@ export async function catchUpConversations(alive, progress) {
|
|
|
1093
1165
|
if (!alive.current())
|
|
1094
1166
|
progress.complete = false;
|
|
1095
1167
|
}
|
|
1168
|
+
export async function holdsSubmission(alive, operation) {
|
|
1169
|
+
if (alive.sending(operation))
|
|
1170
|
+
return true;
|
|
1171
|
+
const local = await alive.deps.local();
|
|
1172
|
+
for (const { conversation } of await local.chatDrafts()) {
|
|
1173
|
+
const held = (await local.chatDraft(conversation))?.submitted;
|
|
1174
|
+
if (held?.some((one) => one.operation === operation && one.turn === null) === true)
|
|
1175
|
+
return true;
|
|
1176
|
+
}
|
|
1177
|
+
return false;
|
|
1178
|
+
}
|
|
1096
1179
|
export async function resendConversations(alive, progress) {
|
|
1097
1180
|
const local = await alive.deps.local();
|
|
1098
1181
|
const tried = new Set();
|
|
@@ -1104,7 +1187,7 @@ export async function resendConversations(alive, progress) {
|
|
|
1104
1187
|
if (alive.deps.closed())
|
|
1105
1188
|
return;
|
|
1106
1189
|
tried.add(submission.operation);
|
|
1107
|
-
const result = await dispatched(alive, conversation, submission);
|
|
1190
|
+
const result = await dispatched(alive, conversation, submission, true);
|
|
1108
1191
|
if (result.kind === 'revoked-authorization')
|
|
1109
1192
|
return;
|
|
1110
1193
|
if (result.kind === 'transport-uncertainty') {
|
|
@@ -1124,23 +1207,25 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1124
1207
|
const { view, watcher } = alive.viewJoined(key, conversation, asked, deliver);
|
|
1125
1208
|
const { held } = view;
|
|
1126
1209
|
const reading = new AbortController();
|
|
1127
|
-
void untilAnswered(() => alive.deps.durably(async (local) => {
|
|
1210
|
+
void untilAnswered(retrying(alive.deps.retries, 'reading', `window ${key}`, () => alive.deps.durably(async (local) => {
|
|
1128
1211
|
if (held.now().window !== null)
|
|
1129
1212
|
return;
|
|
1130
1213
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
1131
1214
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1132
1215
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1216
|
+
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1217
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1133
1218
|
held.set({ window: messages });
|
|
1134
|
-
held.set({ marked: await local.jobMarkers(conversation) });
|
|
1135
1219
|
held.set({ more });
|
|
1136
1220
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
1137
|
-
}), reading.signal)
|
|
1221
|
+
})), reading.signal)
|
|
1138
1222
|
.then(() => {
|
|
1139
1223
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1140
1224
|
return;
|
|
1141
|
-
const
|
|
1142
|
-
const shown = window ?? [];
|
|
1143
|
-
|
|
1225
|
+
const now = held.now();
|
|
1226
|
+
const shown = now.window ?? [];
|
|
1227
|
+
const frame = sharedFrame(view, shown);
|
|
1228
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1144
1229
|
})
|
|
1145
1230
|
.catch(() => { });
|
|
1146
1231
|
return () => {
|
|
@@ -1156,9 +1241,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1156
1241
|
export function watchConversationAgents(alive, deliver) {
|
|
1157
1242
|
alive.agentListeners.join(deliver);
|
|
1158
1243
|
conversationsLearned(alive);
|
|
1159
|
-
readAgents(alive);
|
|
1160
1244
|
return () => alive.agentListeners.leave(deliver);
|
|
1161
1245
|
}
|
|
1246
|
+
export function watchListedAgents(alive, deliver) {
|
|
1247
|
+
alive.listedListeners.join(deliver);
|
|
1248
|
+
conversationsLearned(alive);
|
|
1249
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1250
|
+
}
|
|
1162
1251
|
export function conversationsChanged(alive, set) {
|
|
1163
1252
|
for (const conversation of set.conversations)
|
|
1164
1253
|
emit(alive, conversation);
|
|
@@ -1170,26 +1259,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1170
1259
|
if (event.whole)
|
|
1171
1260
|
alive.relistBegun();
|
|
1172
1261
|
if (alive.relisting())
|
|
1173
|
-
alive.relistHeard(event.entries);
|
|
1262
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1174
1263
|
if (event.more && alive.relisting())
|
|
1175
1264
|
return;
|
|
1176
1265
|
const whole = alive.relistTaken();
|
|
1177
1266
|
listChanged(alive, {
|
|
1178
1267
|
replacing: whole !== null,
|
|
1179
|
-
set: whole === null ? event.entries : [...whole.values()],
|
|
1268
|
+
set: whole === null ? event.entries : [...whole.conversations.values()],
|
|
1269
|
+
agents: whole === null ? event.agents : [...whole.agents.values()],
|
|
1180
1270
|
gone: null,
|
|
1181
1271
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1182
1272
|
});
|
|
1183
1273
|
return;
|
|
1184
1274
|
}
|
|
1185
1275
|
if (event.kind === 'listed') {
|
|
1186
|
-
alive.relistHeard([event.entry]);
|
|
1187
|
-
listChanged(alive, { replacing: false, set: [event.entry], gone: null });
|
|
1276
|
+
alive.relistHeard([event.entry], []);
|
|
1277
|
+
listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
|
|
1278
|
+
return;
|
|
1279
|
+
}
|
|
1280
|
+
if (event.kind === 'agent') {
|
|
1281
|
+
alive.relistHeard([], [event.agent]);
|
|
1282
|
+
listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
|
|
1188
1283
|
return;
|
|
1189
1284
|
}
|
|
1190
1285
|
if (event.kind === 'unlisted') {
|
|
1191
1286
|
alive.relistDropped(event.conversation);
|
|
1192
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1287
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1193
1288
|
return;
|
|
1194
1289
|
}
|
|
1195
1290
|
heard(alive, event);
|