@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c80bb5b77602a
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.map +1 -1
- package/dist/acceptance.js +15 -24
- package/dist/act-lanes.d.ts +11 -14
- package/dist/act-lanes.d.ts.map +1 -1
- package/dist/act-lanes.js +53 -5
- package/dist/actions.d.ts +8 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +138 -68
- package/dist/adapter.d.ts +109 -24
- 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/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 +20 -14
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +28 -56
- package/dist/collection.d.ts +5 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +16 -8
- 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 +21 -11
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +21 -16
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +23 -10
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -8
- 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 +22 -11
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +258 -188
- package/dist/declaration.js +1 -1
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +36 -9
- 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 +7 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +76 -30
- package/dist/house-query.d.ts +18 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +54 -0
- package/dist/index.d.ts +17 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/install.d.ts +10 -4
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +45 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +50 -32
- package/dist/listing.d.ts +24 -12
- package/dist/listing.d.ts.map +1 -1
- package/dist/listing.js +50 -21
- 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 +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- 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 +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +63 -19
- package/dist/messages.d.ts +17 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -10
- 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 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +7 -1
- package/dist/models.d.ts.map +1 -1
- package/dist/models.js +5 -8
- 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/opening.d.ts.map +1 -1
- package/dist/opening.js +20 -10
- 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 +7 -4
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +11 -9
- 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 +198 -87
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +2 -2
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +81 -64
- 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 +2 -2
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +73 -48
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +162 -37
- package/dist/react.d.ts +10 -11
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +22 -4
- 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/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 +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +4 -4
- 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 +258 -32
- 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 +2 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +8 -7
- 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 +5 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -124
- package/dist/saves.d.ts +4 -2
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +65 -21
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/shown.d.ts +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- 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 -3
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +4 -9
- 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 +20 -5
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +60 -22
- 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 +17 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +18 -6
- package/dist/stored.d.ts +32 -14
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +185 -49
- package/dist/surface.d.ts +14 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +59 -27
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +76 -40
- package/dist/tables.d.ts +17 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +87 -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 +3 -9
- package/dist/wire.d.ts +38 -15
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +20 -13
- package/package.json +3 -3
- package/dist/log.d.ts +0 -6
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -14
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,14 +25,17 @@ export function unheldView(conversation) {
|
|
|
24
25
|
options: [],
|
|
25
26
|
starting: null,
|
|
26
27
|
state: null,
|
|
27
|
-
link: null,
|
|
28
28
|
deliveryWaiting: [],
|
|
29
29
|
deliveryUnknown: [],
|
|
30
30
|
chatDraft: null,
|
|
31
|
+
dismissedSuggestion: null,
|
|
32
|
+
pins: [],
|
|
31
33
|
};
|
|
32
34
|
}
|
|
33
35
|
export const SESSION_STARTED = 'Session started';
|
|
34
36
|
const NEW_CHAT = 'new:';
|
|
37
|
+
const LISTING = 'listing';
|
|
38
|
+
export const CATCHING_UP = 'catching-up';
|
|
35
39
|
export const HISTORY_CONVERSATIONS = 64;
|
|
36
40
|
export function newChat(agent) {
|
|
37
41
|
return `${NEW_CHAT}${agent}`;
|
|
@@ -194,17 +198,17 @@ function withSubmitted(draft, submitted) {
|
|
|
194
198
|
const { submitted: _held, ...unsent } = draft;
|
|
195
199
|
return submitted.length === 0 ? unsent : { ...unsent, submitted };
|
|
196
200
|
}
|
|
197
|
-
function
|
|
198
|
-
return
|
|
201
|
+
export function joinedDraft(first, second) {
|
|
202
|
+
return [first, second].filter((one) => one !== '').join('\n');
|
|
199
203
|
}
|
|
200
204
|
function returned(draft, submission, others) {
|
|
201
205
|
return withSubmitted({
|
|
202
206
|
conversation: draft.conversation,
|
|
203
|
-
|
|
207
|
+
text: joinedDraft(submission.text, draft.text),
|
|
204
208
|
revision: chatDraftRevision(),
|
|
205
209
|
}, others);
|
|
206
210
|
}
|
|
207
|
-
function viewOf(alive, conversation, held, frame, draft, ended) {
|
|
211
|
+
function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
|
|
208
212
|
const facts = alive.liveOf(conversation);
|
|
209
213
|
return {
|
|
210
214
|
conversation,
|
|
@@ -223,36 +227,44 @@ function viewOf(alive, conversation, held, frame, draft, ended) {
|
|
|
223
227
|
options: structuredClone(facts.options),
|
|
224
228
|
starting: facts.starting,
|
|
225
229
|
state: sessionOf(facts, held, ended),
|
|
226
|
-
link: facts.link === null ? null : { ...facts.link },
|
|
227
230
|
deliveryWaiting: [...facts.deliveryWaiting],
|
|
228
231
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
229
232
|
chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
|
|
233
|
+
dismissedSuggestion: dismissed,
|
|
234
|
+
pins: [...pins],
|
|
230
235
|
};
|
|
231
236
|
}
|
|
232
|
-
function
|
|
237
|
+
function standing(facts, saved, ended) {
|
|
233
238
|
if (facts.state !== null)
|
|
234
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) {
|
|
235
246
|
const saved = [...held]
|
|
236
247
|
.reverse()
|
|
237
248
|
.map(({ message }) => record(message))
|
|
238
249
|
.find(({ content }) => isTurn(content));
|
|
239
250
|
const at = saved === undefined ? null : text(saved, 'accepted_at');
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
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);
|
|
244
254
|
}
|
|
245
255
|
function emit(alive, conversation) {
|
|
246
256
|
if (alive.deps.closed())
|
|
247
257
|
return;
|
|
248
258
|
for (const view of alive.views()) {
|
|
249
|
-
const
|
|
259
|
+
const held = view.held.now();
|
|
260
|
+
const { window } = held;
|
|
250
261
|
if (view.conversation !== conversation || window === null)
|
|
251
262
|
continue;
|
|
252
263
|
const ready = view.ready();
|
|
253
264
|
if (ready.length === 0)
|
|
254
265
|
continue;
|
|
255
|
-
const
|
|
266
|
+
const frame = sharedFrame(view, window);
|
|
267
|
+
const value = viewOf(alive, conversation, window, frame, held);
|
|
256
268
|
for (const watcher of ready)
|
|
257
269
|
watcher.notify(value);
|
|
258
270
|
}
|
|
@@ -288,76 +300,103 @@ function stateOf(alive, conversation) {
|
|
|
288
300
|
return facts.turn === null ? 'idle' : 'working';
|
|
289
301
|
}
|
|
290
302
|
function rowOf(alive, conversation) {
|
|
291
|
-
const { turn, questions } = alive.liveOf(conversation);
|
|
303
|
+
const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
|
|
292
304
|
return {
|
|
293
305
|
state: stateOf(alive, conversation),
|
|
294
306
|
started: turn?.started ?? null,
|
|
295
307
|
line: turn === null ? null : runningLine(turn.parts),
|
|
296
308
|
question: openQuestion(questions),
|
|
297
309
|
asked: questionAsked(questions),
|
|
310
|
+
deliveryWaiting: [...deliveryWaiting],
|
|
298
311
|
};
|
|
299
312
|
}
|
|
300
313
|
async function entries(alive) {
|
|
301
|
-
const
|
|
302
|
-
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)))
|
|
303
320
|
return null;
|
|
304
321
|
const held = list.length === 0
|
|
305
322
|
? []
|
|
306
323
|
: await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
|
|
307
324
|
const rows = new Map(held.map((one) => [one.conversation, one]));
|
|
308
|
-
return list.map((entry) =>
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
+
...rowOf(alive, entry.conversation),
|
|
336
|
+
...heldFacts(rows.get(entry.conversation), entry),
|
|
337
|
+
jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
|
|
338
|
+
};
|
|
339
|
+
});
|
|
319
340
|
}
|
|
320
|
-
async function
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
return
|
|
324
|
-
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
341
|
+
async function heldListing(alive) {
|
|
342
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
343
|
+
if (conversationList !== null && agentList !== null)
|
|
344
|
+
return { conversations: conversationList, agents: agentList };
|
|
345
|
+
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
346
|
+
? null
|
|
347
|
+
: { conversations: [], agents: [] };
|
|
325
348
|
}
|
|
326
349
|
async function endedIn(alive, conversation) {
|
|
327
|
-
const
|
|
328
|
-
return
|
|
350
|
+
const listing = await heldListing(alive);
|
|
351
|
+
return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
|
|
352
|
+
null);
|
|
353
|
+
}
|
|
354
|
+
function upserted(kept, set, key) {
|
|
355
|
+
const held = new Map(kept.map((one) => [key(one), one]));
|
|
356
|
+
for (const one of set)
|
|
357
|
+
held.set(key(one), { ...one });
|
|
358
|
+
return held;
|
|
329
359
|
}
|
|
330
360
|
function listChanged(alive, change) {
|
|
331
361
|
void alive.deps
|
|
332
362
|
.durably(async (local) => {
|
|
333
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
363
|
+
const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
|
|
364
|
+
if (readUntil === null)
|
|
365
|
+
await local.fact('readUntil', new Date().toISOString());
|
|
366
|
+
const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
|
|
367
|
+
for (const entry of change.set)
|
|
338
368
|
alive.created(entry.conversation);
|
|
339
|
-
}
|
|
340
369
|
if (change.gone !== null)
|
|
341
370
|
held.delete(change.gone);
|
|
342
371
|
const list = [...held.values()];
|
|
372
|
+
const agents = [
|
|
373
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
374
|
+
];
|
|
343
375
|
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
344
376
|
await local.fact('conversationList', list);
|
|
345
377
|
}
|
|
378
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
379
|
+
await local.fact('agentList', agents);
|
|
380
|
+
}
|
|
346
381
|
if (change.cursor !== undefined) {
|
|
347
382
|
if (change.cursor !== conversationCursor) {
|
|
348
383
|
await local.fact('conversationCursor', change.cursor);
|
|
349
384
|
}
|
|
350
385
|
alive.deps.stream()?.hold(change.cursor);
|
|
351
386
|
}
|
|
352
|
-
return list;
|
|
387
|
+
return { conversations: list, agents };
|
|
353
388
|
})
|
|
354
|
-
.catch(async () =>
|
|
355
|
-
.
|
|
389
|
+
.catch(async () => {
|
|
390
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
391
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
392
|
+
})
|
|
393
|
+
.then((listing) => {
|
|
356
394
|
if (alive.deps.closed() || change.paged === true)
|
|
357
395
|
return;
|
|
396
|
+
const list = listing.conversations;
|
|
358
397
|
endedAnew(alive, list);
|
|
359
398
|
if (change.cursor !== undefined) {
|
|
360
|
-
alive.held.set({ listKnown: true });
|
|
399
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
361
400
|
settleBehind(alive, list);
|
|
362
401
|
openingEnded(alive);
|
|
363
402
|
alive.deps.settled();
|
|
@@ -365,11 +404,12 @@ function listChanged(alive, change) {
|
|
|
365
404
|
emitList(alive);
|
|
366
405
|
if (!alive.known())
|
|
367
406
|
return;
|
|
368
|
-
retiredDrafts(alive,
|
|
369
|
-
const { replicated } = alive.held.now();
|
|
370
|
-
if (change.cursor === undefined
|
|
371
|
-
|
|
372
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
407
|
+
retiredDrafts(alive, listing);
|
|
408
|
+
const { replicated, openingRead } = alive.held.now();
|
|
409
|
+
if (change.cursor === undefined
|
|
410
|
+
? list.length !== replicated.size ||
|
|
411
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
412
|
+
: openingRead) {
|
|
373
413
|
alive.deps.again();
|
|
374
414
|
}
|
|
375
415
|
}, uncaught);
|
|
@@ -385,23 +425,23 @@ function endedAnew(alive, list) {
|
|
|
385
425
|
emit(alive, view.conversation);
|
|
386
426
|
}
|
|
387
427
|
}
|
|
388
|
-
function
|
|
389
|
-
const reading =
|
|
428
|
+
function shownListing(alive, work) {
|
|
429
|
+
const reading = heldListing(alive);
|
|
390
430
|
alive.inOrder(async () => {
|
|
391
|
-
const
|
|
431
|
+
const listing = await reading.catch((error) => {
|
|
392
432
|
uncaught(error);
|
|
393
433
|
return null;
|
|
394
434
|
});
|
|
395
|
-
if (
|
|
435
|
+
if (listing === null || alive.deps.closed())
|
|
396
436
|
return;
|
|
397
|
-
work(
|
|
437
|
+
work(listing);
|
|
398
438
|
});
|
|
399
439
|
}
|
|
400
440
|
async function told(alive) {
|
|
401
441
|
try {
|
|
402
442
|
while (alive.held.now().listOwed && !alive.deps.closed()) {
|
|
403
443
|
alive.held.set({ listOwed: false });
|
|
404
|
-
const value = await untilAnswered(() => entries(alive), alive.closing);
|
|
444
|
+
const value = await untilAnswered(retrying(alive.deps.retries, 'conversations', LISTING, () => entries(alive)), alive.closing, () => true, alive.deps.recovery);
|
|
405
445
|
if (alive.deps.closed())
|
|
406
446
|
return;
|
|
407
447
|
if (value === null)
|
|
@@ -439,84 +479,73 @@ export function conversationsLearned(alive) {
|
|
|
439
479
|
return;
|
|
440
480
|
if (alive.listeners.waiting())
|
|
441
481
|
tellList(alive);
|
|
442
|
-
if (!alive.agentListeners.waiting())
|
|
482
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
443
483
|
return;
|
|
444
|
-
|
|
484
|
+
shownListing(alive, (listing) => {
|
|
485
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
486
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
487
|
+
});
|
|
445
488
|
}
|
|
446
|
-
function
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
:
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
cli: held.cli,
|
|
462
|
-
environment: structuredClone(held.environment),
|
|
463
|
-
};
|
|
464
|
-
})
|
|
489
|
+
function agentsOf(listing) {
|
|
490
|
+
return listing.agents
|
|
491
|
+
.filter((agent) => agent.retired_at === null)
|
|
492
|
+
.map((agent) => ({
|
|
493
|
+
identity: agent.id,
|
|
494
|
+
name: agent.name,
|
|
495
|
+
cli: agent.cli,
|
|
496
|
+
model: agent.model,
|
|
497
|
+
effort: agent.effort,
|
|
498
|
+
environment: {
|
|
499
|
+
identity: agent.environment,
|
|
500
|
+
name: agent.environment_name,
|
|
501
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
502
|
+
},
|
|
503
|
+
}))
|
|
465
504
|
.sort((left, right) => left.name === right.name
|
|
466
505
|
? left.identity.localeCompare(right.identity)
|
|
467
506
|
: left.name.localeCompare(right.name));
|
|
468
507
|
}
|
|
469
|
-
function readAgents(alive) {
|
|
470
|
-
const stream = alive.deps.stream();
|
|
471
|
-
if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
|
|
472
|
-
return;
|
|
473
|
-
const { agents: read } = stream;
|
|
474
|
-
const { agentListeners } = alive;
|
|
475
|
-
alive.held.set({ agentsReading: true });
|
|
476
|
-
void alive.deps.recovery
|
|
477
|
-
.attempt('agents', async () => {
|
|
478
|
-
if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
|
|
479
|
-
return 'done';
|
|
480
|
-
}
|
|
481
|
-
const listed = await read();
|
|
482
|
-
if (listed === null)
|
|
483
|
-
return 'done';
|
|
484
|
-
alive.held.set({ listedAgents: listed });
|
|
485
|
-
emitAgents(alive);
|
|
486
|
-
return 'done';
|
|
487
|
-
})
|
|
488
|
-
.finally(() => {
|
|
489
|
-
alive.held.set({ agentsReading: false });
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
508
|
function emitAgents(alive) {
|
|
493
|
-
|
|
509
|
+
const { agentListeners, listedListeners } = alive;
|
|
510
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
494
511
|
return;
|
|
495
|
-
|
|
496
|
-
const value =
|
|
512
|
+
shownListing(alive, (listing) => {
|
|
513
|
+
const value = agentsOf(listing);
|
|
497
514
|
const shown = JSON.stringify(value);
|
|
498
|
-
if (shown
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
515
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
516
|
+
alive.held.set({ agentsShown: shown });
|
|
517
|
+
agentListeners.tell(value);
|
|
518
|
+
}
|
|
519
|
+
const listed = JSON.stringify(listing.agents);
|
|
520
|
+
if (listed !== alive.held.now().listedShown) {
|
|
521
|
+
alive.held.set({ listedShown: listed });
|
|
522
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
523
|
+
}
|
|
502
524
|
});
|
|
503
525
|
}
|
|
526
|
+
function ran({ state, process }) {
|
|
527
|
+
return JSON.stringify([state?.running ?? null, process?.running ?? null]);
|
|
528
|
+
}
|
|
504
529
|
function setLive(alive, conversation, next) {
|
|
530
|
+
const was = ran(alive.liveOf(conversation));
|
|
505
531
|
const before = rowOf(alive, conversation);
|
|
506
532
|
alive.holdLive(conversation, next);
|
|
507
533
|
const after = rowOf(alive, conversation);
|
|
508
|
-
if (after.state !== before.state ||
|
|
534
|
+
if (after.state !== before.state ||
|
|
535
|
+
after.started !== before.started ||
|
|
536
|
+
ran(alive.liveOf(conversation)) !== was ||
|
|
537
|
+
after.deliveryWaiting.join() !== before.deliveryWaiting.join())
|
|
509
538
|
emitList(alive);
|
|
510
539
|
else if (after.line !== before.line ||
|
|
511
540
|
after.question !== before.question ||
|
|
512
541
|
after.asked !== before.asked)
|
|
513
542
|
tellSoon(alive);
|
|
514
543
|
}
|
|
515
|
-
function retiredChat(conversation,
|
|
544
|
+
function retiredChat(conversation, listing) {
|
|
516
545
|
if (!conversation.startsWith(NEW_CHAT))
|
|
517
546
|
return false;
|
|
518
547
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
519
|
-
return
|
|
548
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
520
549
|
}
|
|
521
550
|
function live(alive, conversation, change) {
|
|
522
551
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -536,7 +565,6 @@ function openingEnded(alive) {
|
|
|
536
565
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
537
566
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
538
567
|
state: facts.has('state') ? QUIET.state : held.state,
|
|
539
|
-
link: facts.has('link') ? QUIET.link : held.link,
|
|
540
568
|
deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
|
|
541
569
|
deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
|
|
542
570
|
});
|
|
@@ -569,19 +597,13 @@ function handReplicated(alive) {
|
|
|
569
597
|
}
|
|
570
598
|
async function remove(alive, leaving) {
|
|
571
599
|
await alive.deps.durably(async (local) => {
|
|
572
|
-
const kept = new Set(
|
|
573
|
-
...(await local.conversations(leaving)).map(({ conversation }) => conversation),
|
|
574
|
-
...(await local.chatDrafts())
|
|
575
|
-
.filter(({ conversation }) => leaving.includes(conversation))
|
|
576
|
-
.map(({ conversation }) => conversation),
|
|
577
|
-
]);
|
|
578
|
-
await local.dropConversations(leaving);
|
|
600
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
579
601
|
const changed = [];
|
|
580
602
|
for (const conversation of leaving) {
|
|
581
603
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
582
604
|
changed.push(conversation);
|
|
583
605
|
}
|
|
584
|
-
|
|
606
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
585
607
|
alive.forget(conversation);
|
|
586
608
|
setLive(alive, conversation, null);
|
|
587
609
|
await slide(alive, local, conversation, null);
|
|
@@ -610,7 +632,7 @@ async function readsOf(local, conversations) {
|
|
|
610
632
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
611
633
|
}
|
|
612
634
|
function retiredDrafts(alive, list) {
|
|
613
|
-
if (!list.some((
|
|
635
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
614
636
|
return;
|
|
615
637
|
void alive.deps
|
|
616
638
|
.local()
|
|
@@ -774,10 +796,6 @@ function heard(alive, event) {
|
|
|
774
796
|
live(alive, conversation, { state: structuredClone(event.state) });
|
|
775
797
|
return;
|
|
776
798
|
}
|
|
777
|
-
if (event.kind === 'link') {
|
|
778
|
-
live(alive, conversation, { link: { connected: event.connected } });
|
|
779
|
-
return;
|
|
780
|
-
}
|
|
781
799
|
if (event.kind === 'deliveries') {
|
|
782
800
|
live(alive, conversation, {
|
|
783
801
|
deliveryWaiting: [...event.waiting],
|
|
@@ -806,19 +824,27 @@ function heard(alive, event) {
|
|
|
806
824
|
emit(alive, conversation);
|
|
807
825
|
}
|
|
808
826
|
async function kept(alive, local, conversation, following) {
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
827
|
+
const draft = following === null || empty(following) ? null : following;
|
|
828
|
+
if (draft === null)
|
|
811
829
|
await local.dropChatDraft(conversation);
|
|
812
830
|
else
|
|
813
|
-
await local.keepChatDrafts([
|
|
814
|
-
|
|
831
|
+
await local.keepChatDrafts([draft]);
|
|
832
|
+
heldInViews(alive, conversation, { draft });
|
|
815
833
|
}
|
|
816
|
-
function
|
|
834
|
+
function heldInViews(alive, conversation, held) {
|
|
817
835
|
for (const view of alive.views()) {
|
|
818
836
|
if (view.conversation === conversation)
|
|
819
|
-
view.held.set(
|
|
837
|
+
view.held.set(held);
|
|
820
838
|
}
|
|
821
839
|
}
|
|
840
|
+
async function factOf(local, name) {
|
|
841
|
+
return Object.fromEntries((await local.conversationFacts())
|
|
842
|
+
.filter((fact) => fact.name === name)
|
|
843
|
+
.map(({ conversation, value }) => [conversation, value]));
|
|
844
|
+
}
|
|
845
|
+
async function dismissedIn(local, conversation) {
|
|
846
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
847
|
+
}
|
|
822
848
|
async function draftAt(local, conversation) {
|
|
823
849
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
824
850
|
}
|
|
@@ -849,9 +875,9 @@ function moved(alive, agent, operation, to) {
|
|
|
849
875
|
: [{ ...unsent, conversation: to }];
|
|
850
876
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
851
877
|
await local.keepChatDrafts([left, ...taken]);
|
|
852
|
-
|
|
878
|
+
heldInViews(alive, from, { draft: left });
|
|
853
879
|
for (const one of taken)
|
|
854
|
-
|
|
880
|
+
heldInViews(alive, to, { draft: one });
|
|
855
881
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
856
882
|
});
|
|
857
883
|
}
|
|
@@ -882,12 +908,10 @@ async function submitted(alive, conversation, operation, draft) {
|
|
|
882
908
|
});
|
|
883
909
|
return submission;
|
|
884
910
|
}
|
|
885
|
-
async function dispatched(alive, conversation, submission) {
|
|
911
|
+
async function dispatched(alive, conversation, submission, resent = false) {
|
|
886
912
|
const dispatch = alive.sendingBegan(submission.operation);
|
|
887
913
|
try {
|
|
888
|
-
const result = await invoke(alive, 'conversations/send', conversation, submission.operation, {
|
|
889
|
-
text: submission.text,
|
|
890
|
-
});
|
|
914
|
+
const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
|
|
891
915
|
dispatch.set({ answered: result.kind !== 'transport-uncertainty' });
|
|
892
916
|
if (result.kind === 'revoked-authorization')
|
|
893
917
|
return result;
|
|
@@ -895,6 +919,7 @@ async function dispatched(alive, conversation, submission) {
|
|
|
895
919
|
alive.deps.unanswered();
|
|
896
920
|
return result;
|
|
897
921
|
}
|
|
922
|
+
alive.deps.heard(submission.operation, resent);
|
|
898
923
|
const turn = answered(result, 'message_id');
|
|
899
924
|
await withDraft(alive, conversation, async (current, local) => {
|
|
900
925
|
const held = current?.submitted?.find((one) => one.operation === submission.operation);
|
|
@@ -914,15 +939,12 @@ async function dispatched(alive, conversation, submission) {
|
|
|
914
939
|
alive.sendingEnded(submission.operation, dispatch);
|
|
915
940
|
}
|
|
916
941
|
}
|
|
917
|
-
function invoke(alive, name, conversation, operation, extra = {}) {
|
|
918
|
-
return alive.deps.call(name, {
|
|
919
|
-
conversation_id: conversation,
|
|
920
|
-
operation_id: operation,
|
|
921
|
-
...extra,
|
|
922
|
-
});
|
|
942
|
+
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
943
|
+
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
923
944
|
}
|
|
924
|
-
export function conversationSurface(alive) {
|
|
945
|
+
export function conversationSurface(alive, files) {
|
|
925
946
|
return {
|
|
947
|
+
...files,
|
|
926
948
|
list() {
|
|
927
949
|
return new Promise((settle) => {
|
|
928
950
|
const answer = (listed) => {
|
|
@@ -940,7 +962,12 @@ export function conversationSurface(alive) {
|
|
|
940
962
|
return alive.deps.durably(async (local) => {
|
|
941
963
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
942
964
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
943
|
-
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total),
|
|
965
|
+
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
|
|
966
|
+
draft: (await local.chatDraft(conversation)) ?? null,
|
|
967
|
+
ended: await endedIn(alive, conversation),
|
|
968
|
+
dismissed: await dismissedIn(local, conversation),
|
|
969
|
+
pins: (await local.facts()).chatPins,
|
|
970
|
+
}));
|
|
944
971
|
});
|
|
945
972
|
},
|
|
946
973
|
async create(input) {
|
|
@@ -948,7 +975,7 @@ export function conversationSurface(alive) {
|
|
|
948
975
|
const conversation = answered(result, 'conversation_id');
|
|
949
976
|
if (conversation === null)
|
|
950
977
|
return result;
|
|
951
|
-
const listed = (await
|
|
978
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
952
979
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
953
980
|
alive.creating(conversation);
|
|
954
981
|
}
|
|
@@ -1014,40 +1041,53 @@ export function conversationSurface(alive) {
|
|
|
1014
1041
|
message_id: message,
|
|
1015
1042
|
});
|
|
1016
1043
|
},
|
|
1017
|
-
async
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1044
|
+
async pin(figures) {
|
|
1045
|
+
const pins = [...figures];
|
|
1046
|
+
await alive.deps.durably((local) => local.fact('chatPins', pins));
|
|
1047
|
+
const views = [...alive.views()];
|
|
1048
|
+
for (const view of views)
|
|
1049
|
+
view.held.set({ pins });
|
|
1050
|
+
for (const conversation of new Set(views.map((view) => view.conversation))) {
|
|
1051
|
+
emit(alive, conversation);
|
|
1052
|
+
}
|
|
1022
1053
|
},
|
|
1023
|
-
async
|
|
1024
|
-
|
|
1054
|
+
async openTurn(conversation, turn) {
|
|
1055
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1056
|
+
tellList(alive);
|
|
1025
1057
|
},
|
|
1026
|
-
|
|
1058
|
+
dismissSuggestion(conversation, suggestion) {
|
|
1027
1059
|
return alive.deps.durably(async (local) => {
|
|
1028
|
-
|
|
1029
|
-
|
|
1060
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1061
|
+
return;
|
|
1062
|
+
await local.keepConversationFact({
|
|
1063
|
+
conversation,
|
|
1064
|
+
name: 'dismissedSuggestion',
|
|
1065
|
+
value: suggestion,
|
|
1066
|
+
});
|
|
1067
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1068
|
+
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1030
1069
|
});
|
|
1031
1070
|
},
|
|
1032
1071
|
};
|
|
1033
1072
|
}
|
|
1073
|
+
function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
|
|
1074
|
+
return withDraft(alive, conversation, (current) => ({
|
|
1075
|
+
conversation,
|
|
1076
|
+
text: text(current?.text ?? ''),
|
|
1077
|
+
revision,
|
|
1078
|
+
...(current === undefined ? {} : pending(current)),
|
|
1079
|
+
}));
|
|
1080
|
+
}
|
|
1034
1081
|
export function chatDraftSurface(alive) {
|
|
1035
1082
|
return {
|
|
1036
|
-
write(conversation, draft, revision
|
|
1037
|
-
return
|
|
1038
|
-
conversation,
|
|
1039
|
-
text: draft.text,
|
|
1040
|
-
revision,
|
|
1041
|
-
...(current === undefined ? {} : pending(current)),
|
|
1042
|
-
}));
|
|
1083
|
+
write(conversation, draft, revision) {
|
|
1084
|
+
return rewritten(alive, conversation, () => draft.text, revision);
|
|
1043
1085
|
},
|
|
1044
1086
|
prepend(conversation, draft) {
|
|
1045
|
-
return
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
...(current === undefined ? {} : pending(current)),
|
|
1050
|
-
}));
|
|
1087
|
+
return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
|
|
1088
|
+
},
|
|
1089
|
+
append(conversation, draft) {
|
|
1090
|
+
return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
|
|
1051
1091
|
},
|
|
1052
1092
|
discard(conversation) {
|
|
1053
1093
|
return withDraft(alive, conversation, (current) => current === undefined
|
|
@@ -1057,31 +1097,37 @@ export function chatDraftSurface(alive) {
|
|
|
1057
1097
|
};
|
|
1058
1098
|
}
|
|
1059
1099
|
export async function conversationsOpened(alive, local) {
|
|
1060
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1061
|
-
if (conversationList === null ||
|
|
1100
|
+
const { conversationList, agentList, conversationCursor } = await local.facts();
|
|
1101
|
+
if (conversationList === null || agentList === null)
|
|
1102
|
+
return;
|
|
1103
|
+
alive.held.set({ listHeld: true });
|
|
1104
|
+
if (alive.known())
|
|
1062
1105
|
return;
|
|
1063
1106
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1064
1107
|
conversationsLearned(alive);
|
|
1065
1108
|
}
|
|
1109
|
+
export function reconcileOpening(alive) {
|
|
1110
|
+
alive.held.set({ openingRead: true });
|
|
1111
|
+
return reconcileConversations(alive);
|
|
1112
|
+
}
|
|
1066
1113
|
export async function reconcileConversations(alive) {
|
|
1067
1114
|
if (!alive.known())
|
|
1068
1115
|
return;
|
|
1069
1116
|
const local = await alive.deps.local();
|
|
1070
|
-
const [held,
|
|
1117
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1071
1118
|
local.conversations(),
|
|
1072
|
-
local.
|
|
1119
|
+
local.storedConversations(),
|
|
1073
1120
|
local.facts(),
|
|
1074
1121
|
]);
|
|
1075
1122
|
const list = conversationList ?? [];
|
|
1123
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1076
1124
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1077
1125
|
const named = new Set(entries.keys());
|
|
1078
1126
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1079
1127
|
const { replicated } = alive.held.now();
|
|
1080
|
-
const leaving = [
|
|
1081
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1082
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1128
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1083
1129
|
!alive.isCreating(conversation) &&
|
|
1084
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1130
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1085
1131
|
for (const conversation of named) {
|
|
1086
1132
|
if (!replicated.has(conversation) &&
|
|
1087
1133
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1116,6 +1162,17 @@ export async function catchUpConversations(alive, progress) {
|
|
|
1116
1162
|
if (!alive.current())
|
|
1117
1163
|
progress.complete = false;
|
|
1118
1164
|
}
|
|
1165
|
+
export async function holdsSubmission(alive, operation) {
|
|
1166
|
+
if (alive.sending(operation))
|
|
1167
|
+
return true;
|
|
1168
|
+
const local = await alive.deps.local();
|
|
1169
|
+
for (const { conversation } of await local.chatDrafts()) {
|
|
1170
|
+
const held = (await local.chatDraft(conversation))?.submitted;
|
|
1171
|
+
if (held?.some((one) => one.operation === operation && one.turn === null) === true)
|
|
1172
|
+
return true;
|
|
1173
|
+
}
|
|
1174
|
+
return false;
|
|
1175
|
+
}
|
|
1119
1176
|
export async function resendConversations(alive, progress) {
|
|
1120
1177
|
const local = await alive.deps.local();
|
|
1121
1178
|
const tried = new Set();
|
|
@@ -1127,7 +1184,7 @@ export async function resendConversations(alive, progress) {
|
|
|
1127
1184
|
if (alive.deps.closed())
|
|
1128
1185
|
return;
|
|
1129
1186
|
tried.add(submission.operation);
|
|
1130
|
-
const result = await dispatched(alive, conversation, submission);
|
|
1187
|
+
const result = await dispatched(alive, conversation, submission, true);
|
|
1131
1188
|
if (result.kind === 'revoked-authorization')
|
|
1132
1189
|
return;
|
|
1133
1190
|
if (result.kind === 'transport-uncertainty') {
|
|
@@ -1147,22 +1204,25 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1147
1204
|
const { view, watcher } = alive.viewJoined(key, conversation, asked, deliver);
|
|
1148
1205
|
const { held } = view;
|
|
1149
1206
|
const reading = new AbortController();
|
|
1150
|
-
void untilAnswered(() => alive.deps.durably(async (local) => {
|
|
1207
|
+
void untilAnswered(retrying(alive.deps.retries, 'reading', `window ${key}`, () => alive.deps.durably(async (local) => {
|
|
1151
1208
|
if (held.now().window !== null)
|
|
1152
1209
|
return;
|
|
1153
1210
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
1154
1211
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1155
1212
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1213
|
+
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1214
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1156
1215
|
held.set({ window: messages });
|
|
1157
1216
|
held.set({ more });
|
|
1158
1217
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
1159
|
-
}), reading.signal)
|
|
1218
|
+
})), reading.signal)
|
|
1160
1219
|
.then(() => {
|
|
1161
1220
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1162
1221
|
return;
|
|
1163
|
-
const
|
|
1164
|
-
const shown = window ?? [];
|
|
1165
|
-
|
|
1222
|
+
const now = held.now();
|
|
1223
|
+
const shown = now.window ?? [];
|
|
1224
|
+
const frame = sharedFrame(view, shown);
|
|
1225
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1166
1226
|
})
|
|
1167
1227
|
.catch(() => { });
|
|
1168
1228
|
return () => {
|
|
@@ -1178,9 +1238,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1178
1238
|
export function watchConversationAgents(alive, deliver) {
|
|
1179
1239
|
alive.agentListeners.join(deliver);
|
|
1180
1240
|
conversationsLearned(alive);
|
|
1181
|
-
readAgents(alive);
|
|
1182
1241
|
return () => alive.agentListeners.leave(deliver);
|
|
1183
1242
|
}
|
|
1243
|
+
export function watchListedAgents(alive, deliver) {
|
|
1244
|
+
alive.listedListeners.join(deliver);
|
|
1245
|
+
conversationsLearned(alive);
|
|
1246
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1247
|
+
}
|
|
1184
1248
|
export function conversationsChanged(alive, set) {
|
|
1185
1249
|
for (const conversation of set.conversations)
|
|
1186
1250
|
emit(alive, conversation);
|
|
@@ -1192,26 +1256,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1192
1256
|
if (event.whole)
|
|
1193
1257
|
alive.relistBegun();
|
|
1194
1258
|
if (alive.relisting())
|
|
1195
|
-
alive.relistHeard(event.entries);
|
|
1259
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1196
1260
|
if (event.more && alive.relisting())
|
|
1197
1261
|
return;
|
|
1198
1262
|
const whole = alive.relistTaken();
|
|
1199
1263
|
listChanged(alive, {
|
|
1200
1264
|
replacing: whole !== null,
|
|
1201
|
-
set: whole === null ? event.entries : [...whole.values()],
|
|
1265
|
+
set: whole === null ? event.entries : [...whole.conversations.values()],
|
|
1266
|
+
agents: whole === null ? event.agents : [...whole.agents.values()],
|
|
1202
1267
|
gone: null,
|
|
1203
1268
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1204
1269
|
});
|
|
1205
1270
|
return;
|
|
1206
1271
|
}
|
|
1207
1272
|
if (event.kind === 'listed') {
|
|
1208
|
-
alive.relistHeard([event.entry]);
|
|
1209
|
-
listChanged(alive, { replacing: false, set: [event.entry], gone: null });
|
|
1273
|
+
alive.relistHeard([event.entry], []);
|
|
1274
|
+
listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
|
|
1275
|
+
return;
|
|
1276
|
+
}
|
|
1277
|
+
if (event.kind === 'agent') {
|
|
1278
|
+
alive.relistHeard([], [event.agent]);
|
|
1279
|
+
listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
|
|
1210
1280
|
return;
|
|
1211
1281
|
}
|
|
1212
1282
|
if (event.kind === 'unlisted') {
|
|
1213
1283
|
alive.relistDropped(event.conversation);
|
|
1214
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1284
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1215
1285
|
return;
|
|
1216
1286
|
}
|
|
1217
1287
|
heard(alive, event);
|