@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c83bc1fac9b35
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 +86 -14
- 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/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 +14 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +18 -46
- 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 +17 -5
- 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 -7
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -6
- 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 +20 -7
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +238 -174
- 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 +5 -0
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +23 -12
- 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 +6 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +50 -16
- package/dist/house-query.d.ts +21 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +41 -0
- package/dist/index.d.ts +14 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -4
- 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 +5 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +40 -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 +18 -1
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +102 -24
- package/dist/memory.d.ts +5 -1
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +58 -14
- package/dist/messages.d.ts +12 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +24 -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/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 +13 -1
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +32 -2
- package/dist/overlay.d.ts +4 -1
- 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 +32 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +189 -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/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +1 -7
- 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 +14 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +142 -30
- 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 +16 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +10 -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/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +2 -2
- 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 +253 -30
- 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 +6 -6
- 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 +1 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -124
- package/dist/saves.d.ts +2 -0
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +42 -18
- 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 +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 +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 +25 -13
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +80 -27
- package/dist/surface.d.ts +12 -6
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +58 -26
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +75 -39
- 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 +3 -9
- package/dist/wire.d.ts +33 -10
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -8
- 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 {
|
|
@@ -28,10 +29,14 @@ export function unheldView(conversation) {
|
|
|
28
29
|
deliveryWaiting: [],
|
|
29
30
|
deliveryUnknown: [],
|
|
30
31
|
chatDraft: null,
|
|
32
|
+
dismissedSuggestion: null,
|
|
33
|
+
pins: [],
|
|
31
34
|
};
|
|
32
35
|
}
|
|
33
36
|
export const SESSION_STARTED = 'Session started';
|
|
34
37
|
const NEW_CHAT = 'new:';
|
|
38
|
+
const LISTING = 'listing';
|
|
39
|
+
export const CATCHING_UP = 'catching-up';
|
|
35
40
|
export const HISTORY_CONVERSATIONS = 64;
|
|
36
41
|
export function newChat(agent) {
|
|
37
42
|
return `${NEW_CHAT}${agent}`;
|
|
@@ -194,17 +199,17 @@ function withSubmitted(draft, submitted) {
|
|
|
194
199
|
const { submitted: _held, ...unsent } = draft;
|
|
195
200
|
return submitted.length === 0 ? unsent : { ...unsent, submitted };
|
|
196
201
|
}
|
|
197
|
-
function
|
|
198
|
-
return
|
|
202
|
+
export function joinedDraft(first, second) {
|
|
203
|
+
return [first, second].filter((one) => one !== '').join('\n');
|
|
199
204
|
}
|
|
200
205
|
function returned(draft, submission, others) {
|
|
201
206
|
return withSubmitted({
|
|
202
207
|
conversation: draft.conversation,
|
|
203
|
-
|
|
208
|
+
text: joinedDraft(submission.text, draft.text),
|
|
204
209
|
revision: chatDraftRevision(),
|
|
205
210
|
}, others);
|
|
206
211
|
}
|
|
207
|
-
function viewOf(alive, conversation, held, frame, draft, ended) {
|
|
212
|
+
function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
|
|
208
213
|
const facts = alive.liveOf(conversation);
|
|
209
214
|
return {
|
|
210
215
|
conversation,
|
|
@@ -227,6 +232,8 @@ function viewOf(alive, conversation, held, frame, draft, ended) {
|
|
|
227
232
|
deliveryWaiting: [...facts.deliveryWaiting],
|
|
228
233
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
229
234
|
chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
|
|
235
|
+
dismissedSuggestion: dismissed,
|
|
236
|
+
pins: [...pins],
|
|
230
237
|
};
|
|
231
238
|
}
|
|
232
239
|
function sessionOf(facts, held, ended) {
|
|
@@ -246,13 +253,15 @@ function emit(alive, conversation) {
|
|
|
246
253
|
if (alive.deps.closed())
|
|
247
254
|
return;
|
|
248
255
|
for (const view of alive.views()) {
|
|
249
|
-
const
|
|
256
|
+
const held = view.held.now();
|
|
257
|
+
const { window } = held;
|
|
250
258
|
if (view.conversation !== conversation || window === null)
|
|
251
259
|
continue;
|
|
252
260
|
const ready = view.ready();
|
|
253
261
|
if (ready.length === 0)
|
|
254
262
|
continue;
|
|
255
|
-
const
|
|
263
|
+
const frame = sharedFrame(view, window);
|
|
264
|
+
const value = viewOf(alive, conversation, window, frame, held);
|
|
256
265
|
for (const watcher of ready)
|
|
257
266
|
watcher.notify(value);
|
|
258
267
|
}
|
|
@@ -298,66 +307,92 @@ function rowOf(alive, conversation) {
|
|
|
298
307
|
};
|
|
299
308
|
}
|
|
300
309
|
async function entries(alive) {
|
|
301
|
-
const
|
|
302
|
-
if (
|
|
310
|
+
const listing = await heldListing(alive);
|
|
311
|
+
if (listing === null)
|
|
312
|
+
return null;
|
|
313
|
+
const list = listing.conversations;
|
|
314
|
+
const agents = new Map(listing.agents.map((agent) => [agent.id, agent]));
|
|
315
|
+
if (list.some((entry) => !agents.has(entry.agent)))
|
|
303
316
|
return null;
|
|
304
317
|
const held = list.length === 0
|
|
305
318
|
? []
|
|
306
319
|
: await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
|
|
307
320
|
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
|
-
|
|
321
|
+
return list.map((entry) => {
|
|
322
|
+
const agent = agents.get(entry.agent);
|
|
323
|
+
return {
|
|
324
|
+
conversation: entry.conversation,
|
|
325
|
+
agent: { identity: agent.id, name: agent.name, retired: agent.retired_at !== null },
|
|
326
|
+
name: entry.name,
|
|
327
|
+
created: entry.created,
|
|
328
|
+
finished: entry.finished,
|
|
329
|
+
outcome: entry.outcome,
|
|
330
|
+
waiting: entry.waiting,
|
|
331
|
+
subject: entry.subject,
|
|
332
|
+
...rowOf(alive, entry.conversation),
|
|
333
|
+
...heldFacts(rows.get(entry.conversation), entry),
|
|
334
|
+
};
|
|
335
|
+
});
|
|
319
336
|
}
|
|
320
|
-
async function
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
return
|
|
324
|
-
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
337
|
+
async function heldListing(alive) {
|
|
338
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
339
|
+
if (conversationList !== null && agentList !== null)
|
|
340
|
+
return { conversations: conversationList, agents: agentList };
|
|
341
|
+
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
342
|
+
? null
|
|
343
|
+
: { conversations: [], agents: [] };
|
|
325
344
|
}
|
|
326
345
|
async function endedIn(alive, conversation) {
|
|
327
|
-
const
|
|
328
|
-
return
|
|
346
|
+
const listing = await heldListing(alive);
|
|
347
|
+
return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
|
|
348
|
+
null);
|
|
349
|
+
}
|
|
350
|
+
function upserted(kept, set, key) {
|
|
351
|
+
const held = new Map(kept.map((one) => [key(one), one]));
|
|
352
|
+
for (const one of set)
|
|
353
|
+
held.set(key(one), { ...one });
|
|
354
|
+
return held;
|
|
329
355
|
}
|
|
330
356
|
function listChanged(alive, change) {
|
|
331
357
|
void alive.deps
|
|
332
358
|
.durably(async (local) => {
|
|
333
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
359
|
+
const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
|
|
360
|
+
if (readUntil === null)
|
|
361
|
+
await local.fact('readUntil', new Date().toISOString());
|
|
362
|
+
const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
|
|
363
|
+
for (const entry of change.set)
|
|
338
364
|
alive.created(entry.conversation);
|
|
339
|
-
}
|
|
340
365
|
if (change.gone !== null)
|
|
341
366
|
held.delete(change.gone);
|
|
342
367
|
const list = [...held.values()];
|
|
368
|
+
const agents = [
|
|
369
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
370
|
+
];
|
|
343
371
|
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
344
372
|
await local.fact('conversationList', list);
|
|
345
373
|
}
|
|
374
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
375
|
+
await local.fact('agentList', agents);
|
|
376
|
+
}
|
|
346
377
|
if (change.cursor !== undefined) {
|
|
347
378
|
if (change.cursor !== conversationCursor) {
|
|
348
379
|
await local.fact('conversationCursor', change.cursor);
|
|
349
380
|
}
|
|
350
381
|
alive.deps.stream()?.hold(change.cursor);
|
|
351
382
|
}
|
|
352
|
-
return list;
|
|
383
|
+
return { conversations: list, agents };
|
|
353
384
|
})
|
|
354
|
-
.catch(async () =>
|
|
355
|
-
.
|
|
385
|
+
.catch(async () => {
|
|
386
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
387
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
388
|
+
})
|
|
389
|
+
.then((listing) => {
|
|
356
390
|
if (alive.deps.closed() || change.paged === true)
|
|
357
391
|
return;
|
|
392
|
+
const list = listing.conversations;
|
|
358
393
|
endedAnew(alive, list);
|
|
359
394
|
if (change.cursor !== undefined) {
|
|
360
|
-
alive.held.set({ listKnown: true });
|
|
395
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
361
396
|
settleBehind(alive, list);
|
|
362
397
|
openingEnded(alive);
|
|
363
398
|
alive.deps.settled();
|
|
@@ -365,11 +400,12 @@ function listChanged(alive, change) {
|
|
|
365
400
|
emitList(alive);
|
|
366
401
|
if (!alive.known())
|
|
367
402
|
return;
|
|
368
|
-
retiredDrafts(alive,
|
|
369
|
-
const { replicated } = alive.held.now();
|
|
370
|
-
if (change.cursor === undefined
|
|
371
|
-
|
|
372
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
403
|
+
retiredDrafts(alive, listing);
|
|
404
|
+
const { replicated, openingRead } = alive.held.now();
|
|
405
|
+
if (change.cursor === undefined
|
|
406
|
+
? list.length !== replicated.size ||
|
|
407
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
408
|
+
: openingRead) {
|
|
373
409
|
alive.deps.again();
|
|
374
410
|
}
|
|
375
411
|
}, uncaught);
|
|
@@ -385,23 +421,23 @@ function endedAnew(alive, list) {
|
|
|
385
421
|
emit(alive, view.conversation);
|
|
386
422
|
}
|
|
387
423
|
}
|
|
388
|
-
function
|
|
389
|
-
const reading =
|
|
424
|
+
function shownListing(alive, work) {
|
|
425
|
+
const reading = heldListing(alive);
|
|
390
426
|
alive.inOrder(async () => {
|
|
391
|
-
const
|
|
427
|
+
const listing = await reading.catch((error) => {
|
|
392
428
|
uncaught(error);
|
|
393
429
|
return null;
|
|
394
430
|
});
|
|
395
|
-
if (
|
|
431
|
+
if (listing === null || alive.deps.closed())
|
|
396
432
|
return;
|
|
397
|
-
work(
|
|
433
|
+
work(listing);
|
|
398
434
|
});
|
|
399
435
|
}
|
|
400
436
|
async function told(alive) {
|
|
401
437
|
try {
|
|
402
438
|
while (alive.held.now().listOwed && !alive.deps.closed()) {
|
|
403
439
|
alive.held.set({ listOwed: false });
|
|
404
|
-
const value = await untilAnswered(() => entries(alive), alive.closing);
|
|
440
|
+
const value = await untilAnswered(retrying(alive.deps.retries, 'conversations', LISTING, () => entries(alive)), alive.closing, () => true, alive.deps.recovery);
|
|
405
441
|
if (alive.deps.closed())
|
|
406
442
|
return;
|
|
407
443
|
if (value === null)
|
|
@@ -439,66 +475,48 @@ export function conversationsLearned(alive) {
|
|
|
439
475
|
return;
|
|
440
476
|
if (alive.listeners.waiting())
|
|
441
477
|
tellList(alive);
|
|
442
|
-
if (!alive.agentListeners.waiting())
|
|
478
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
443
479
|
return;
|
|
444
|
-
|
|
480
|
+
shownListing(alive, (listing) => {
|
|
481
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
482
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
483
|
+
});
|
|
445
484
|
}
|
|
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
|
-
})
|
|
485
|
+
function agentsOf(listing) {
|
|
486
|
+
return listing.agents
|
|
487
|
+
.filter((agent) => agent.retired_at === null)
|
|
488
|
+
.map((agent) => ({
|
|
489
|
+
identity: agent.id,
|
|
490
|
+
name: agent.name,
|
|
491
|
+
cli: agent.cli,
|
|
492
|
+
model: agent.model,
|
|
493
|
+
effort: agent.effort,
|
|
494
|
+
environment: {
|
|
495
|
+
identity: agent.environment,
|
|
496
|
+
name: agent.environment_name,
|
|
497
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
498
|
+
},
|
|
499
|
+
}))
|
|
465
500
|
.sort((left, right) => left.name === right.name
|
|
466
501
|
? left.identity.localeCompare(right.identity)
|
|
467
502
|
: left.name.localeCompare(right.name));
|
|
468
503
|
}
|
|
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
504
|
function emitAgents(alive) {
|
|
493
|
-
|
|
505
|
+
const { agentListeners, listedListeners } = alive;
|
|
506
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
494
507
|
return;
|
|
495
|
-
|
|
496
|
-
const value =
|
|
508
|
+
shownListing(alive, (listing) => {
|
|
509
|
+
const value = agentsOf(listing);
|
|
497
510
|
const shown = JSON.stringify(value);
|
|
498
|
-
if (shown
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
511
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
512
|
+
alive.held.set({ agentsShown: shown });
|
|
513
|
+
agentListeners.tell(value);
|
|
514
|
+
}
|
|
515
|
+
const listed = JSON.stringify(listing.agents);
|
|
516
|
+
if (listed !== alive.held.now().listedShown) {
|
|
517
|
+
alive.held.set({ listedShown: listed });
|
|
518
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
519
|
+
}
|
|
502
520
|
});
|
|
503
521
|
}
|
|
504
522
|
function setLive(alive, conversation, next) {
|
|
@@ -512,11 +530,11 @@ function setLive(alive, conversation, next) {
|
|
|
512
530
|
after.asked !== before.asked)
|
|
513
531
|
tellSoon(alive);
|
|
514
532
|
}
|
|
515
|
-
function retiredChat(conversation,
|
|
533
|
+
function retiredChat(conversation, listing) {
|
|
516
534
|
if (!conversation.startsWith(NEW_CHAT))
|
|
517
535
|
return false;
|
|
518
536
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
519
|
-
return
|
|
537
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
520
538
|
}
|
|
521
539
|
function live(alive, conversation, change) {
|
|
522
540
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -569,19 +587,13 @@ function handReplicated(alive) {
|
|
|
569
587
|
}
|
|
570
588
|
async function remove(alive, leaving) {
|
|
571
589
|
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);
|
|
590
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
579
591
|
const changed = [];
|
|
580
592
|
for (const conversation of leaving) {
|
|
581
593
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
582
594
|
changed.push(conversation);
|
|
583
595
|
}
|
|
584
|
-
|
|
596
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
585
597
|
alive.forget(conversation);
|
|
586
598
|
setLive(alive, conversation, null);
|
|
587
599
|
await slide(alive, local, conversation, null);
|
|
@@ -610,7 +622,7 @@ async function readsOf(local, conversations) {
|
|
|
610
622
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
611
623
|
}
|
|
612
624
|
function retiredDrafts(alive, list) {
|
|
613
|
-
if (!list.some((
|
|
625
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
614
626
|
return;
|
|
615
627
|
void alive.deps
|
|
616
628
|
.local()
|
|
@@ -806,19 +818,27 @@ function heard(alive, event) {
|
|
|
806
818
|
emit(alive, conversation);
|
|
807
819
|
}
|
|
808
820
|
async function kept(alive, local, conversation, following) {
|
|
809
|
-
const
|
|
810
|
-
if (
|
|
821
|
+
const draft = following === null || empty(following) ? null : following;
|
|
822
|
+
if (draft === null)
|
|
811
823
|
await local.dropChatDraft(conversation);
|
|
812
824
|
else
|
|
813
|
-
await local.keepChatDrafts([
|
|
814
|
-
|
|
825
|
+
await local.keepChatDrafts([draft]);
|
|
826
|
+
heldInViews(alive, conversation, { draft });
|
|
815
827
|
}
|
|
816
|
-
function
|
|
828
|
+
function heldInViews(alive, conversation, held) {
|
|
817
829
|
for (const view of alive.views()) {
|
|
818
830
|
if (view.conversation === conversation)
|
|
819
|
-
view.held.set(
|
|
831
|
+
view.held.set(held);
|
|
820
832
|
}
|
|
821
833
|
}
|
|
834
|
+
async function factOf(local, name) {
|
|
835
|
+
return Object.fromEntries((await local.conversationFacts())
|
|
836
|
+
.filter((fact) => fact.name === name)
|
|
837
|
+
.map(({ conversation, value }) => [conversation, value]));
|
|
838
|
+
}
|
|
839
|
+
async function dismissedIn(local, conversation) {
|
|
840
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
841
|
+
}
|
|
822
842
|
async function draftAt(local, conversation) {
|
|
823
843
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
824
844
|
}
|
|
@@ -849,9 +869,9 @@ function moved(alive, agent, operation, to) {
|
|
|
849
869
|
: [{ ...unsent, conversation: to }];
|
|
850
870
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
851
871
|
await local.keepChatDrafts([left, ...taken]);
|
|
852
|
-
|
|
872
|
+
heldInViews(alive, from, { draft: left });
|
|
853
873
|
for (const one of taken)
|
|
854
|
-
|
|
874
|
+
heldInViews(alive, to, { draft: one });
|
|
855
875
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
856
876
|
});
|
|
857
877
|
}
|
|
@@ -882,12 +902,10 @@ async function submitted(alive, conversation, operation, draft) {
|
|
|
882
902
|
});
|
|
883
903
|
return submission;
|
|
884
904
|
}
|
|
885
|
-
async function dispatched(alive, conversation, submission) {
|
|
905
|
+
async function dispatched(alive, conversation, submission, resent = false) {
|
|
886
906
|
const dispatch = alive.sendingBegan(submission.operation);
|
|
887
907
|
try {
|
|
888
|
-
const result = await invoke(alive, 'conversations/send', conversation, submission.operation, {
|
|
889
|
-
text: submission.text,
|
|
890
|
-
});
|
|
908
|
+
const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
|
|
891
909
|
dispatch.set({ answered: result.kind !== 'transport-uncertainty' });
|
|
892
910
|
if (result.kind === 'revoked-authorization')
|
|
893
911
|
return result;
|
|
@@ -895,6 +913,7 @@ async function dispatched(alive, conversation, submission) {
|
|
|
895
913
|
alive.deps.unanswered();
|
|
896
914
|
return result;
|
|
897
915
|
}
|
|
916
|
+
alive.deps.heard(submission.operation, resent);
|
|
898
917
|
const turn = answered(result, 'message_id');
|
|
899
918
|
await withDraft(alive, conversation, async (current, local) => {
|
|
900
919
|
const held = current?.submitted?.find((one) => one.operation === submission.operation);
|
|
@@ -914,15 +933,12 @@ async function dispatched(alive, conversation, submission) {
|
|
|
914
933
|
alive.sendingEnded(submission.operation, dispatch);
|
|
915
934
|
}
|
|
916
935
|
}
|
|
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
|
-
});
|
|
936
|
+
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
937
|
+
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
923
938
|
}
|
|
924
|
-
export function conversationSurface(alive) {
|
|
939
|
+
export function conversationSurface(alive, files) {
|
|
925
940
|
return {
|
|
941
|
+
...files,
|
|
926
942
|
list() {
|
|
927
943
|
return new Promise((settle) => {
|
|
928
944
|
const answer = (listed) => {
|
|
@@ -940,7 +956,12 @@ export function conversationSurface(alive) {
|
|
|
940
956
|
return alive.deps.durably(async (local) => {
|
|
941
957
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
942
958
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
943
|
-
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total),
|
|
959
|
+
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
|
|
960
|
+
draft: (await local.chatDraft(conversation)) ?? null,
|
|
961
|
+
ended: await endedIn(alive, conversation),
|
|
962
|
+
dismissed: await dismissedIn(local, conversation),
|
|
963
|
+
pins: (await local.facts()).chatPins,
|
|
964
|
+
}));
|
|
944
965
|
});
|
|
945
966
|
},
|
|
946
967
|
async create(input) {
|
|
@@ -948,7 +969,7 @@ export function conversationSurface(alive) {
|
|
|
948
969
|
const conversation = answered(result, 'conversation_id');
|
|
949
970
|
if (conversation === null)
|
|
950
971
|
return result;
|
|
951
|
-
const listed = (await
|
|
972
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
952
973
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
953
974
|
alive.creating(conversation);
|
|
954
975
|
}
|
|
@@ -1014,40 +1035,53 @@ export function conversationSurface(alive) {
|
|
|
1014
1035
|
message_id: message,
|
|
1015
1036
|
});
|
|
1016
1037
|
},
|
|
1017
|
-
async
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1038
|
+
async pin(figures) {
|
|
1039
|
+
const pins = [...figures];
|
|
1040
|
+
await alive.deps.durably((local) => local.fact('chatPins', pins));
|
|
1041
|
+
const views = [...alive.views()];
|
|
1042
|
+
for (const view of views)
|
|
1043
|
+
view.held.set({ pins });
|
|
1044
|
+
for (const conversation of new Set(views.map((view) => view.conversation))) {
|
|
1045
|
+
emit(alive, conversation);
|
|
1046
|
+
}
|
|
1022
1047
|
},
|
|
1023
|
-
async
|
|
1024
|
-
|
|
1048
|
+
async openTurn(conversation, turn) {
|
|
1049
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1050
|
+
tellList(alive);
|
|
1025
1051
|
},
|
|
1026
|
-
|
|
1052
|
+
dismissSuggestion(conversation, suggestion) {
|
|
1027
1053
|
return alive.deps.durably(async (local) => {
|
|
1028
|
-
|
|
1029
|
-
|
|
1054
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1055
|
+
return;
|
|
1056
|
+
await local.keepConversationFact({
|
|
1057
|
+
conversation,
|
|
1058
|
+
name: 'dismissedSuggestion',
|
|
1059
|
+
value: suggestion,
|
|
1060
|
+
});
|
|
1061
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1062
|
+
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1030
1063
|
});
|
|
1031
1064
|
},
|
|
1032
1065
|
};
|
|
1033
1066
|
}
|
|
1067
|
+
function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
|
|
1068
|
+
return withDraft(alive, conversation, (current) => ({
|
|
1069
|
+
conversation,
|
|
1070
|
+
text: text(current?.text ?? ''),
|
|
1071
|
+
revision,
|
|
1072
|
+
...(current === undefined ? {} : pending(current)),
|
|
1073
|
+
}));
|
|
1074
|
+
}
|
|
1034
1075
|
export function chatDraftSurface(alive) {
|
|
1035
1076
|
return {
|
|
1036
|
-
write(conversation, draft, revision
|
|
1037
|
-
return
|
|
1038
|
-
conversation,
|
|
1039
|
-
text: draft.text,
|
|
1040
|
-
revision,
|
|
1041
|
-
...(current === undefined ? {} : pending(current)),
|
|
1042
|
-
}));
|
|
1077
|
+
write(conversation, draft, revision) {
|
|
1078
|
+
return rewritten(alive, conversation, () => draft.text, revision);
|
|
1043
1079
|
},
|
|
1044
1080
|
prepend(conversation, draft) {
|
|
1045
|
-
return
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
...(current === undefined ? {} : pending(current)),
|
|
1050
|
-
}));
|
|
1081
|
+
return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
|
|
1082
|
+
},
|
|
1083
|
+
append(conversation, draft) {
|
|
1084
|
+
return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
|
|
1051
1085
|
},
|
|
1052
1086
|
discard(conversation) {
|
|
1053
1087
|
return withDraft(alive, conversation, (current) => current === undefined
|
|
@@ -1057,31 +1091,37 @@ export function chatDraftSurface(alive) {
|
|
|
1057
1091
|
};
|
|
1058
1092
|
}
|
|
1059
1093
|
export async function conversationsOpened(alive, local) {
|
|
1060
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1061
|
-
if (conversationList === null ||
|
|
1094
|
+
const { conversationList, agentList, conversationCursor } = await local.facts();
|
|
1095
|
+
if (conversationList === null || agentList === null)
|
|
1096
|
+
return;
|
|
1097
|
+
alive.held.set({ listHeld: true });
|
|
1098
|
+
if (alive.known())
|
|
1062
1099
|
return;
|
|
1063
1100
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1064
1101
|
conversationsLearned(alive);
|
|
1065
1102
|
}
|
|
1103
|
+
export function reconcileOpening(alive) {
|
|
1104
|
+
alive.held.set({ openingRead: true });
|
|
1105
|
+
return reconcileConversations(alive);
|
|
1106
|
+
}
|
|
1066
1107
|
export async function reconcileConversations(alive) {
|
|
1067
1108
|
if (!alive.known())
|
|
1068
1109
|
return;
|
|
1069
1110
|
const local = await alive.deps.local();
|
|
1070
|
-
const [held,
|
|
1111
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1071
1112
|
local.conversations(),
|
|
1072
|
-
local.
|
|
1113
|
+
local.storedConversations(),
|
|
1073
1114
|
local.facts(),
|
|
1074
1115
|
]);
|
|
1075
1116
|
const list = conversationList ?? [];
|
|
1117
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1076
1118
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1077
1119
|
const named = new Set(entries.keys());
|
|
1078
1120
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1079
1121
|
const { replicated } = alive.held.now();
|
|
1080
|
-
const leaving = [
|
|
1081
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1082
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1122
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1083
1123
|
!alive.isCreating(conversation) &&
|
|
1084
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1124
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1085
1125
|
for (const conversation of named) {
|
|
1086
1126
|
if (!replicated.has(conversation) &&
|
|
1087
1127
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1116,6 +1156,17 @@ export async function catchUpConversations(alive, progress) {
|
|
|
1116
1156
|
if (!alive.current())
|
|
1117
1157
|
progress.complete = false;
|
|
1118
1158
|
}
|
|
1159
|
+
export async function holdsSubmission(alive, operation) {
|
|
1160
|
+
if (alive.sending(operation))
|
|
1161
|
+
return true;
|
|
1162
|
+
const local = await alive.deps.local();
|
|
1163
|
+
for (const { conversation } of await local.chatDrafts()) {
|
|
1164
|
+
const held = (await local.chatDraft(conversation))?.submitted;
|
|
1165
|
+
if (held?.some((one) => one.operation === operation && one.turn === null) === true)
|
|
1166
|
+
return true;
|
|
1167
|
+
}
|
|
1168
|
+
return false;
|
|
1169
|
+
}
|
|
1119
1170
|
export async function resendConversations(alive, progress) {
|
|
1120
1171
|
const local = await alive.deps.local();
|
|
1121
1172
|
const tried = new Set();
|
|
@@ -1127,7 +1178,7 @@ export async function resendConversations(alive, progress) {
|
|
|
1127
1178
|
if (alive.deps.closed())
|
|
1128
1179
|
return;
|
|
1129
1180
|
tried.add(submission.operation);
|
|
1130
|
-
const result = await dispatched(alive, conversation, submission);
|
|
1181
|
+
const result = await dispatched(alive, conversation, submission, true);
|
|
1131
1182
|
if (result.kind === 'revoked-authorization')
|
|
1132
1183
|
return;
|
|
1133
1184
|
if (result.kind === 'transport-uncertainty') {
|
|
@@ -1147,22 +1198,25 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1147
1198
|
const { view, watcher } = alive.viewJoined(key, conversation, asked, deliver);
|
|
1148
1199
|
const { held } = view;
|
|
1149
1200
|
const reading = new AbortController();
|
|
1150
|
-
void untilAnswered(() => alive.deps.durably(async (local) => {
|
|
1201
|
+
void untilAnswered(retrying(alive.deps.retries, 'reading', `window ${key}`, () => alive.deps.durably(async (local) => {
|
|
1151
1202
|
if (held.now().window !== null)
|
|
1152
1203
|
return;
|
|
1153
1204
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
1154
1205
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1155
1206
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1207
|
+
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1208
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1156
1209
|
held.set({ window: messages });
|
|
1157
1210
|
held.set({ more });
|
|
1158
1211
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
1159
|
-
}), reading.signal)
|
|
1212
|
+
})), reading.signal)
|
|
1160
1213
|
.then(() => {
|
|
1161
1214
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1162
1215
|
return;
|
|
1163
|
-
const
|
|
1164
|
-
const shown = window ?? [];
|
|
1165
|
-
|
|
1216
|
+
const now = held.now();
|
|
1217
|
+
const shown = now.window ?? [];
|
|
1218
|
+
const frame = sharedFrame(view, shown);
|
|
1219
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1166
1220
|
})
|
|
1167
1221
|
.catch(() => { });
|
|
1168
1222
|
return () => {
|
|
@@ -1178,9 +1232,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1178
1232
|
export function watchConversationAgents(alive, deliver) {
|
|
1179
1233
|
alive.agentListeners.join(deliver);
|
|
1180
1234
|
conversationsLearned(alive);
|
|
1181
|
-
readAgents(alive);
|
|
1182
1235
|
return () => alive.agentListeners.leave(deliver);
|
|
1183
1236
|
}
|
|
1237
|
+
export function watchListedAgents(alive, deliver) {
|
|
1238
|
+
alive.listedListeners.join(deliver);
|
|
1239
|
+
conversationsLearned(alive);
|
|
1240
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1241
|
+
}
|
|
1184
1242
|
export function conversationsChanged(alive, set) {
|
|
1185
1243
|
for (const conversation of set.conversations)
|
|
1186
1244
|
emit(alive, conversation);
|
|
@@ -1192,26 +1250,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1192
1250
|
if (event.whole)
|
|
1193
1251
|
alive.relistBegun();
|
|
1194
1252
|
if (alive.relisting())
|
|
1195
|
-
alive.relistHeard(event.entries);
|
|
1253
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1196
1254
|
if (event.more && alive.relisting())
|
|
1197
1255
|
return;
|
|
1198
1256
|
const whole = alive.relistTaken();
|
|
1199
1257
|
listChanged(alive, {
|
|
1200
1258
|
replacing: whole !== null,
|
|
1201
|
-
set: whole === null ? event.entries : [...whole.values()],
|
|
1259
|
+
set: whole === null ? event.entries : [...whole.conversations.values()],
|
|
1260
|
+
agents: whole === null ? event.agents : [...whole.agents.values()],
|
|
1202
1261
|
gone: null,
|
|
1203
1262
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1204
1263
|
});
|
|
1205
1264
|
return;
|
|
1206
1265
|
}
|
|
1207
1266
|
if (event.kind === 'listed') {
|
|
1208
|
-
alive.relistHeard([event.entry]);
|
|
1209
|
-
listChanged(alive, { replacing: false, set: [event.entry], gone: null });
|
|
1267
|
+
alive.relistHeard([event.entry], []);
|
|
1268
|
+
listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
|
|
1269
|
+
return;
|
|
1270
|
+
}
|
|
1271
|
+
if (event.kind === 'agent') {
|
|
1272
|
+
alive.relistHeard([], [event.agent]);
|
|
1273
|
+
listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
|
|
1210
1274
|
return;
|
|
1211
1275
|
}
|
|
1212
1276
|
if (event.kind === 'unlisted') {
|
|
1213
1277
|
alive.relistDropped(event.conversation);
|
|
1214
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1278
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1215
1279
|
return;
|
|
1216
1280
|
}
|
|
1217
1281
|
heard(alive, event);
|