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