@agentshouse/mdruntime 0.1.0-c714ba876473f → 0.1.0-c71b36a9c359c
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 +18 -16
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +31 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +48 -9
- package/dist/adapter.d.ts +183 -27
- 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/{binary.d.ts → attachment.d.ts} +8 -4
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +15 -0
- package/dist/authored.d.ts +88 -0
- package/dist/authored.d.ts.map +1 -0
- package/dist/authored.js +345 -0
- package/dist/chain.d.ts +1 -1
- package/dist/chain.d.ts.map +1 -1
- package/dist/chain.js +5 -2
- 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 +24 -8
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +26 -56
- package/dist/collection.d.ts +6 -1
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +23 -9
- 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 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +73 -42
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +12 -6
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +19 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +18 -8
- package/dist/conversation-row.d.ts +20 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +30 -7
- package/dist/conversation.d.ts +25 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +236 -193
- package/dist/declaration.js +3 -3
- package/dist/discovery.d.ts +3 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +30 -5
- 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 +2 -0
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +7 -0
- package/dist/entry.d.ts +25 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +111 -34
- package/dist/failure.d.ts.map +1 -1
- package/dist/failure.js +3 -1
- package/dist/figures.d.ts +1 -1
- package/dist/figures.d.ts.map +1 -1
- package/dist/figures.js +6 -4
- 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 +71 -29
- package/dist/house-query.d.ts +24 -0
- package/dist/house-query.d.ts.map +1 -0
- package/dist/house-query.js +102 -0
- package/dist/identity.d.ts +1 -1
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +1 -1
- package/dist/index.d.ts +21 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -5
- package/dist/install.d.ts +8 -2
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +40 -33
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +40 -25
- 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 +19 -3
- package/dist/live.d.ts.map +1 -1
- package/dist/live.js +94 -36
- package/dist/loaded.d.ts +7 -0
- package/dist/loaded.d.ts.map +1 -0
- package/dist/loaded.js +46 -0
- package/dist/locks.d.ts.map +1 -1
- package/dist/locks.js +4 -2
- package/dist/lost.js +1 -1
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +181 -34
- package/dist/memory.d.ts +7 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +63 -23
- package/dist/messages.d.ts +21 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +43 -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 +10 -7
- 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 +3 -3
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/opened.d.ts +5 -5
- 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 +20 -2
- package/dist/outcome.d.ts +30 -13
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +21 -6
- package/dist/overlay.d.ts +20 -9
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +110 -41
- package/dist/parts.d.ts +3 -1
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -7
- package/dist/paths.d.ts +1 -1
- package/dist/paths.js +1 -1
- package/dist/preparation.d.ts +33 -7
- package/dist/preparation.d.ts.map +1 -1
- package/dist/preparation.js +195 -78
- 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 +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +115 -67
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -0
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +51 -21
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +140 -25
- package/dist/react.d.ts +12 -1
- package/dist/react.d.ts.map +1 -1
- package/dist/readiness.d.ts +23 -4
- package/dist/readiness.d.ts.map +1 -1
- package/dist/readiness.js +18 -10
- package/dist/reads.d.ts +1 -1
- package/dist/reads.d.ts.map +1 -1
- package/dist/reads.js +17 -6
- package/dist/recovery.d.ts +1 -0
- package/dist/recovery.d.ts.map +1 -1
- package/dist/recovery.js +2 -1
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/replica.d.ts +3 -8
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +5 -5
- package/dist/room-draft.d.ts +29 -4
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +239 -18
- package/dist/room-drafts.d.ts.map +1 -1
- package/dist/room-drafts.js +12 -7
- package/dist/room-list.d.ts +10 -0
- package/dist/room-list.d.ts.map +1 -0
- package/dist/room-list.js +47 -0
- package/dist/rows.d.ts +11 -3
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +25 -11
- package/dist/run-tables.d.ts +25 -0
- package/dist/run-tables.d.ts.map +1 -0
- package/dist/run-tables.js +98 -0
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runs.d.ts +27 -0
- package/dist/runs.d.ts.map +1 -0
- package/dist/runs.js +92 -0
- package/dist/runtime.d.ts +5 -2
- 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 +17 -86
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +106 -53
- package/dist/seed.d.ts.map +1 -1
- package/dist/seed.js +2 -2
- package/dist/selector.d.ts +3 -0
- package/dist/selector.d.ts.map +1 -0
- package/dist/selector.js +22 -0
- package/dist/shown.d.ts +5 -2
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +79 -43
- 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 -1
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +8 -0
- package/dist/source.d.ts +24 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +48 -9
- 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 +30 -9
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -27
- 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 +15 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +12 -5
- package/dist/stored.d.ts +41 -16
- package/dist/stored.d.ts.map +1 -1
- package/dist/stored.js +215 -57
- package/dist/surface.d.ts +19 -7
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +57 -19
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +49 -27
- package/dist/tables.d.ts +40 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +109 -326
- package/dist/tallies.d.ts.map +1 -1
- package/dist/tallies.js +3 -4
- package/dist/validation.d.ts +2 -0
- package/dist/validation.d.ts.map +1 -1
- package/dist/validation.js +50 -10
- package/dist/wire.d.ts +30 -14
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +19 -13
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
package/dist/conversation.js
CHANGED
|
@@ -6,7 +6,7 @@ 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';
|
|
@@ -25,17 +25,16 @@ export function unheldView(conversation) {
|
|
|
25
25
|
options: [],
|
|
26
26
|
starting: null,
|
|
27
27
|
state: null,
|
|
28
|
-
link: null,
|
|
29
28
|
deliveryWaiting: [],
|
|
30
29
|
deliveryUnknown: [],
|
|
31
30
|
chatDraft: null,
|
|
32
31
|
dismissedSuggestion: null,
|
|
32
|
+
pins: [],
|
|
33
33
|
};
|
|
34
34
|
}
|
|
35
35
|
export const SESSION_STARTED = 'Session started';
|
|
36
36
|
const NEW_CHAT = 'new:';
|
|
37
37
|
const LISTING = 'listing';
|
|
38
|
-
const AGENTS = 'agents';
|
|
39
38
|
export const CATCHING_UP = 'catching-up';
|
|
40
39
|
export const HISTORY_CONVERSATIONS = 64;
|
|
41
40
|
export function newChat(agent) {
|
|
@@ -209,7 +208,7 @@ function returned(draft, submission, others) {
|
|
|
209
208
|
revision: chatDraftRevision(),
|
|
210
209
|
}, others);
|
|
211
210
|
}
|
|
212
|
-
function viewOf(alive, conversation, held, frame, draft, ended, dismissed) {
|
|
211
|
+
function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
|
|
213
212
|
const facts = alive.liveOf(conversation);
|
|
214
213
|
return {
|
|
215
214
|
conversation,
|
|
@@ -228,38 +227,44 @@ function viewOf(alive, conversation, held, frame, draft, ended, dismissed) {
|
|
|
228
227
|
options: structuredClone(facts.options),
|
|
229
228
|
starting: facts.starting,
|
|
230
229
|
state: sessionOf(facts, held, ended),
|
|
231
|
-
link: facts.link === null ? null : { ...facts.link },
|
|
232
230
|
deliveryWaiting: [...facts.deliveryWaiting],
|
|
233
231
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
234
232
|
chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
|
|
235
233
|
dismissedSuggestion: dismissed,
|
|
234
|
+
pins: [...pins],
|
|
236
235
|
};
|
|
237
236
|
}
|
|
238
|
-
function
|
|
237
|
+
function standing(facts, saved, ended) {
|
|
239
238
|
if (facts.state !== null)
|
|
240
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) {
|
|
241
246
|
const saved = [...held]
|
|
242
247
|
.reverse()
|
|
243
248
|
.map(({ message }) => record(message))
|
|
244
249
|
.find(({ content }) => isTurn(content));
|
|
245
250
|
const at = saved === undefined ? null : text(saved, 'accepted_at');
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
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);
|
|
250
254
|
}
|
|
251
255
|
function emit(alive, conversation) {
|
|
252
256
|
if (alive.deps.closed())
|
|
253
257
|
return;
|
|
254
258
|
for (const view of alive.views()) {
|
|
255
|
-
const
|
|
259
|
+
const held = view.held.now();
|
|
260
|
+
const { window } = held;
|
|
256
261
|
if (view.conversation !== conversation || window === null)
|
|
257
262
|
continue;
|
|
258
263
|
const ready = view.ready();
|
|
259
264
|
if (ready.length === 0)
|
|
260
265
|
continue;
|
|
261
266
|
const frame = sharedFrame(view, window);
|
|
262
|
-
const value = viewOf(alive, conversation, window, frame,
|
|
267
|
+
const value = viewOf(alive, conversation, window, frame, held);
|
|
263
268
|
for (const watcher of ready)
|
|
264
269
|
watcher.notify(value);
|
|
265
270
|
}
|
|
@@ -288,83 +293,118 @@ async function slide(alive, local, conversation, arriving) {
|
|
|
288
293
|
}
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
|
-
function stateOf(
|
|
292
|
-
|
|
293
|
-
|
|
296
|
+
function stateOf({ activity }) {
|
|
297
|
+
if (activity === null)
|
|
298
|
+
return 'idle';
|
|
299
|
+
if (activity.turn === 'asking')
|
|
294
300
|
return 'asking';
|
|
295
|
-
return
|
|
301
|
+
return activity.turn === 'running' || activity.background !== false ? 'working' : 'idle';
|
|
296
302
|
}
|
|
297
303
|
function rowOf(alive, conversation) {
|
|
298
|
-
const { turn, questions } = alive.liveOf(conversation);
|
|
304
|
+
const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
|
|
299
305
|
return {
|
|
300
|
-
state: stateOf(alive, conversation),
|
|
301
306
|
started: turn?.started ?? null,
|
|
302
307
|
line: turn === null ? null : runningLine(turn.parts),
|
|
303
308
|
question: openQuestion(questions),
|
|
304
309
|
asked: questionAsked(questions),
|
|
310
|
+
deliveryWaiting: [...deliveryWaiting],
|
|
305
311
|
};
|
|
306
312
|
}
|
|
307
313
|
async function entries(alive) {
|
|
308
|
-
const
|
|
309
|
-
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)))
|
|
310
320
|
return null;
|
|
311
321
|
const held = list.length === 0
|
|
312
322
|
? []
|
|
313
323
|
: await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
|
|
314
324
|
const rows = new Map(held.map((one) => [one.conversation, one]));
|
|
315
|
-
return list.map((entry) =>
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
325
|
+
return list.map((entry) => {
|
|
326
|
+
const agent = agents.get(entry.agent);
|
|
327
|
+
return {
|
|
328
|
+
conversation: entry.conversation,
|
|
329
|
+
agent: { identity: agent.id, name: agent.name, retired: agent.retired_at !== null },
|
|
330
|
+
name: entry.name,
|
|
331
|
+
created: entry.created,
|
|
332
|
+
outcome: entry.outcome,
|
|
333
|
+
waiting: entry.waiting,
|
|
334
|
+
subject: entry.subject,
|
|
335
|
+
room: entry.room,
|
|
336
|
+
model: entry.model,
|
|
337
|
+
effort: entry.effort,
|
|
338
|
+
state: stateOf(entry),
|
|
339
|
+
...rowOf(alive, entry.conversation),
|
|
340
|
+
...heldFacts(rows.get(entry.conversation), entry),
|
|
341
|
+
jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
|
|
342
|
+
};
|
|
343
|
+
});
|
|
326
344
|
}
|
|
327
|
-
async function
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
330
|
-
return
|
|
331
|
-
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
345
|
+
async function heldListing(alive) {
|
|
346
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
347
|
+
if (conversationList !== null && agentList !== null)
|
|
348
|
+
return { conversations: conversationList, agents: agentList };
|
|
349
|
+
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
350
|
+
? null
|
|
351
|
+
: { conversations: [], agents: [] };
|
|
332
352
|
}
|
|
333
353
|
async function endedIn(alive, conversation) {
|
|
334
|
-
const
|
|
335
|
-
return
|
|
354
|
+
const listing = await heldListing(alive);
|
|
355
|
+
return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
|
|
356
|
+
null);
|
|
357
|
+
}
|
|
358
|
+
function upserted(kept, set, key) {
|
|
359
|
+
const held = new Map(kept.map((one) => [key(one), one]));
|
|
360
|
+
for (const one of set)
|
|
361
|
+
held.set(key(one), { ...one });
|
|
362
|
+
return held;
|
|
363
|
+
}
|
|
364
|
+
async function listStored(alive, local, change) {
|
|
365
|
+
const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
|
|
366
|
+
if (readUntil === null)
|
|
367
|
+
await local.fact('readUntil', new Date().toISOString());
|
|
368
|
+
const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
|
|
369
|
+
for (const entry of change.set)
|
|
370
|
+
alive.created(entry.conversation);
|
|
371
|
+
if (change.gone !== null)
|
|
372
|
+
held.delete(change.gone);
|
|
373
|
+
const list = [...held.values()];
|
|
374
|
+
const agents = [
|
|
375
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
376
|
+
];
|
|
377
|
+
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
378
|
+
await local.fact('conversationList', list);
|
|
379
|
+
}
|
|
380
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
381
|
+
await local.fact('agentList', agents);
|
|
382
|
+
}
|
|
383
|
+
if (change.cursor !== undefined && !alive.held.now().listRefused) {
|
|
384
|
+
if (change.cursor !== conversationCursor) {
|
|
385
|
+
await local.fact('conversationCursor', change.cursor);
|
|
386
|
+
}
|
|
387
|
+
alive.deps.stream()?.hold(change.cursor);
|
|
388
|
+
}
|
|
389
|
+
return { conversations: list, agents };
|
|
336
390
|
}
|
|
337
391
|
function listChanged(alive, change) {
|
|
338
392
|
void alive.deps
|
|
339
|
-
.durably(
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
if (change.gone !== null)
|
|
348
|
-
held.delete(change.gone);
|
|
349
|
-
const list = [...held.values()];
|
|
350
|
-
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
351
|
-
await local.fact('conversationList', list);
|
|
352
|
-
}
|
|
353
|
-
if (change.cursor !== undefined) {
|
|
354
|
-
if (change.cursor !== conversationCursor) {
|
|
355
|
-
await local.fact('conversationCursor', change.cursor);
|
|
356
|
-
}
|
|
357
|
-
alive.deps.stream()?.hold(change.cursor);
|
|
358
|
-
}
|
|
359
|
-
return list;
|
|
393
|
+
.durably((local) => listStored(alive, local, change).catch((error) => {
|
|
394
|
+
alive.held.set({ listRefused: true });
|
|
395
|
+
throw error;
|
|
396
|
+
}))
|
|
397
|
+
.catch(async () => {
|
|
398
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
399
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
360
400
|
})
|
|
361
|
-
.
|
|
362
|
-
.then((list) => {
|
|
401
|
+
.then((listing) => {
|
|
363
402
|
if (alive.deps.closed() || change.paged === true)
|
|
364
403
|
return;
|
|
404
|
+
const list = listing.conversations;
|
|
365
405
|
endedAnew(alive, list);
|
|
366
406
|
if (change.cursor !== undefined) {
|
|
367
|
-
alive.held.set({ listKnown: true });
|
|
407
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
368
408
|
settleBehind(alive, list);
|
|
369
409
|
openingEnded(alive);
|
|
370
410
|
alive.deps.settled();
|
|
@@ -372,11 +412,12 @@ function listChanged(alive, change) {
|
|
|
372
412
|
emitList(alive);
|
|
373
413
|
if (!alive.known())
|
|
374
414
|
return;
|
|
375
|
-
retiredDrafts(alive,
|
|
376
|
-
const { replicated } = alive.held.now();
|
|
377
|
-
if (change.cursor === undefined
|
|
378
|
-
|
|
379
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
415
|
+
retiredDrafts(alive, listing);
|
|
416
|
+
const { replicated, openingRead } = alive.held.now();
|
|
417
|
+
if (change.cursor === undefined
|
|
418
|
+
? list.length !== replicated.size ||
|
|
419
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
420
|
+
: openingRead) {
|
|
380
421
|
alive.deps.again();
|
|
381
422
|
}
|
|
382
423
|
}, uncaught);
|
|
@@ -392,16 +433,16 @@ function endedAnew(alive, list) {
|
|
|
392
433
|
emit(alive, view.conversation);
|
|
393
434
|
}
|
|
394
435
|
}
|
|
395
|
-
function
|
|
396
|
-
const reading =
|
|
436
|
+
function shownListing(alive, work) {
|
|
437
|
+
const reading = heldListing(alive);
|
|
397
438
|
alive.inOrder(async () => {
|
|
398
|
-
const
|
|
439
|
+
const listing = await reading.catch((error) => {
|
|
399
440
|
uncaught(error);
|
|
400
441
|
return null;
|
|
401
442
|
});
|
|
402
|
-
if (
|
|
443
|
+
if (listing === null || alive.deps.closed())
|
|
403
444
|
return;
|
|
404
|
-
work(
|
|
445
|
+
work(listing);
|
|
405
446
|
});
|
|
406
447
|
}
|
|
407
448
|
async function told(alive) {
|
|
@@ -446,84 +487,73 @@ export function conversationsLearned(alive) {
|
|
|
446
487
|
return;
|
|
447
488
|
if (alive.listeners.waiting())
|
|
448
489
|
tellList(alive);
|
|
449
|
-
if (!alive.agentListeners.waiting())
|
|
490
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
450
491
|
return;
|
|
451
|
-
|
|
492
|
+
shownListing(alive, (listing) => {
|
|
493
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
494
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
495
|
+
});
|
|
452
496
|
}
|
|
453
|
-
function
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
:
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
environment: structuredClone(held.environment),
|
|
470
|
-
};
|
|
471
|
-
})
|
|
497
|
+
function agentsOf(listing) {
|
|
498
|
+
return listing.agents
|
|
499
|
+
.filter((agent) => agent.retired_at === null)
|
|
500
|
+
.map((agent) => ({
|
|
501
|
+
identity: agent.id,
|
|
502
|
+
name: agent.name,
|
|
503
|
+
cli: agent.cli,
|
|
504
|
+
model: agent.model,
|
|
505
|
+
effort: agent.effort,
|
|
506
|
+
model_fixed: agent.model_fixed,
|
|
507
|
+
environment: {
|
|
508
|
+
identity: agent.environment,
|
|
509
|
+
name: agent.environment_name,
|
|
510
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
511
|
+
},
|
|
512
|
+
}))
|
|
472
513
|
.sort((left, right) => left.name === right.name
|
|
473
514
|
? left.identity.localeCompare(right.identity)
|
|
474
515
|
: left.name.localeCompare(right.name));
|
|
475
516
|
}
|
|
476
|
-
function readAgents(alive) {
|
|
477
|
-
const stream = alive.deps.stream();
|
|
478
|
-
if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
|
|
479
|
-
return;
|
|
480
|
-
const { agents: read } = stream;
|
|
481
|
-
const { agentListeners } = alive;
|
|
482
|
-
alive.held.set({ agentsReading: true });
|
|
483
|
-
void alive.deps.recovery
|
|
484
|
-
.attempt('agents', async () => {
|
|
485
|
-
if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
|
|
486
|
-
return 'done';
|
|
487
|
-
}
|
|
488
|
-
const listed = await retrying(alive.deps.retries, 'conversations', AGENTS, read)();
|
|
489
|
-
if (listed === null)
|
|
490
|
-
return 'done';
|
|
491
|
-
alive.held.set({ listedAgents: listed });
|
|
492
|
-
emitAgents(alive);
|
|
493
|
-
return 'done';
|
|
494
|
-
})
|
|
495
|
-
.finally(() => {
|
|
496
|
-
alive.held.set({ agentsReading: false });
|
|
497
|
-
});
|
|
498
|
-
}
|
|
499
517
|
function emitAgents(alive) {
|
|
500
|
-
|
|
518
|
+
const { agentListeners, listedListeners } = alive;
|
|
519
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
501
520
|
return;
|
|
502
|
-
|
|
503
|
-
const value =
|
|
521
|
+
shownListing(alive, (listing) => {
|
|
522
|
+
const value = agentsOf(listing);
|
|
504
523
|
const shown = JSON.stringify(value);
|
|
505
|
-
if (shown
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
524
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
525
|
+
alive.held.set({ agentsShown: shown });
|
|
526
|
+
agentListeners.tell(value);
|
|
527
|
+
}
|
|
528
|
+
const listed = JSON.stringify(listing.agents);
|
|
529
|
+
if (listed !== alive.held.now().listedShown) {
|
|
530
|
+
alive.held.set({ listedShown: listed });
|
|
531
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
532
|
+
}
|
|
509
533
|
});
|
|
510
534
|
}
|
|
535
|
+
function ran({ state, process }) {
|
|
536
|
+
return JSON.stringify([state?.running ?? null, process?.running ?? null]);
|
|
537
|
+
}
|
|
511
538
|
function setLive(alive, conversation, next) {
|
|
539
|
+
const was = ran(alive.liveOf(conversation));
|
|
512
540
|
const before = rowOf(alive, conversation);
|
|
513
541
|
alive.holdLive(conversation, next);
|
|
514
542
|
const after = rowOf(alive, conversation);
|
|
515
|
-
if (after.
|
|
543
|
+
if (after.started !== before.started ||
|
|
544
|
+
ran(alive.liveOf(conversation)) !== was ||
|
|
545
|
+
after.deliveryWaiting.join() !== before.deliveryWaiting.join())
|
|
516
546
|
emitList(alive);
|
|
517
547
|
else if (after.line !== before.line ||
|
|
518
548
|
after.question !== before.question ||
|
|
519
549
|
after.asked !== before.asked)
|
|
520
550
|
tellSoon(alive);
|
|
521
551
|
}
|
|
522
|
-
function retiredChat(conversation,
|
|
552
|
+
function retiredChat(conversation, listing) {
|
|
523
553
|
if (!conversation.startsWith(NEW_CHAT))
|
|
524
554
|
return false;
|
|
525
555
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
526
|
-
return
|
|
556
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
527
557
|
}
|
|
528
558
|
function live(alive, conversation, change) {
|
|
529
559
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -543,7 +573,6 @@ function openingEnded(alive) {
|
|
|
543
573
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
544
574
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
545
575
|
state: facts.has('state') ? QUIET.state : held.state,
|
|
546
|
-
link: facts.has('link') ? QUIET.link : held.link,
|
|
547
576
|
deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
|
|
548
577
|
deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
|
|
549
578
|
});
|
|
@@ -576,19 +605,13 @@ function handReplicated(alive) {
|
|
|
576
605
|
}
|
|
577
606
|
async function remove(alive, leaving) {
|
|
578
607
|
await alive.deps.durably(async (local) => {
|
|
579
|
-
const kept = new Set(
|
|
580
|
-
...(await local.conversations(leaving)).map(({ conversation }) => conversation),
|
|
581
|
-
...(await local.chatDrafts())
|
|
582
|
-
.filter(({ conversation }) => leaving.includes(conversation))
|
|
583
|
-
.map(({ conversation }) => conversation),
|
|
584
|
-
]);
|
|
585
|
-
await local.dropConversations(leaving);
|
|
608
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
586
609
|
const changed = [];
|
|
587
610
|
for (const conversation of leaving) {
|
|
588
611
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
589
612
|
changed.push(conversation);
|
|
590
613
|
}
|
|
591
|
-
|
|
614
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
592
615
|
alive.forget(conversation);
|
|
593
616
|
setLive(alive, conversation, null);
|
|
594
617
|
await slide(alive, local, conversation, null);
|
|
@@ -617,7 +640,7 @@ async function readsOf(local, conversations) {
|
|
|
617
640
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
618
641
|
}
|
|
619
642
|
function retiredDrafts(alive, list) {
|
|
620
|
-
if (!list.some((
|
|
643
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
621
644
|
return;
|
|
622
645
|
void alive.deps
|
|
623
646
|
.local()
|
|
@@ -781,10 +804,6 @@ function heard(alive, event) {
|
|
|
781
804
|
live(alive, conversation, { state: structuredClone(event.state) });
|
|
782
805
|
return;
|
|
783
806
|
}
|
|
784
|
-
if (event.kind === 'link') {
|
|
785
|
-
live(alive, conversation, { link: { connected: event.connected } });
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
807
|
if (event.kind === 'deliveries') {
|
|
789
808
|
live(alive, conversation, {
|
|
790
809
|
deliveryWaiting: [...event.waiting],
|
|
@@ -813,21 +832,26 @@ function heard(alive, event) {
|
|
|
813
832
|
emit(alive, conversation);
|
|
814
833
|
}
|
|
815
834
|
async function kept(alive, local, conversation, following) {
|
|
816
|
-
const
|
|
817
|
-
if (
|
|
835
|
+
const draft = following === null || empty(following) ? null : following;
|
|
836
|
+
if (draft === null)
|
|
818
837
|
await local.dropChatDraft(conversation);
|
|
819
838
|
else
|
|
820
|
-
await local.keepChatDrafts([
|
|
821
|
-
|
|
839
|
+
await local.keepChatDrafts([draft]);
|
|
840
|
+
heldInViews(alive, conversation, { draft });
|
|
822
841
|
}
|
|
823
|
-
function
|
|
842
|
+
function heldInViews(alive, conversation, held) {
|
|
824
843
|
for (const view of alive.views()) {
|
|
825
844
|
if (view.conversation === conversation)
|
|
826
|
-
view.held.set(
|
|
845
|
+
view.held.set(held);
|
|
827
846
|
}
|
|
828
847
|
}
|
|
848
|
+
async function factOf(local, name) {
|
|
849
|
+
return Object.fromEntries((await local.conversationFacts())
|
|
850
|
+
.filter((fact) => fact.name === name)
|
|
851
|
+
.map(({ conversation, value }) => [conversation, value]));
|
|
852
|
+
}
|
|
829
853
|
async function dismissedIn(local, conversation) {
|
|
830
|
-
return (await local
|
|
854
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
831
855
|
}
|
|
832
856
|
async function draftAt(local, conversation) {
|
|
833
857
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
@@ -859,9 +883,9 @@ function moved(alive, agent, operation, to) {
|
|
|
859
883
|
: [{ ...unsent, conversation: to }];
|
|
860
884
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
861
885
|
await local.keepChatDrafts([left, ...taken]);
|
|
862
|
-
|
|
886
|
+
heldInViews(alive, from, { draft: left });
|
|
863
887
|
for (const one of taken)
|
|
864
|
-
|
|
888
|
+
heldInViews(alive, to, { draft: one });
|
|
865
889
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
866
890
|
});
|
|
867
891
|
}
|
|
@@ -926,8 +950,9 @@ async function dispatched(alive, conversation, submission, resent = false) {
|
|
|
926
950
|
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
927
951
|
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
928
952
|
}
|
|
929
|
-
export function conversationSurface(alive) {
|
|
953
|
+
export function conversationSurface(alive, files) {
|
|
930
954
|
return {
|
|
955
|
+
...files,
|
|
931
956
|
list() {
|
|
932
957
|
return new Promise((settle) => {
|
|
933
958
|
const answer = (listed) => {
|
|
@@ -945,7 +970,12 @@ export function conversationSurface(alive) {
|
|
|
945
970
|
return alive.deps.durably(async (local) => {
|
|
946
971
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
947
972
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
948
|
-
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total),
|
|
973
|
+
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
|
|
974
|
+
draft: (await local.chatDraft(conversation)) ?? null,
|
|
975
|
+
ended: await endedIn(alive, conversation),
|
|
976
|
+
dismissed: await dismissedIn(local, conversation),
|
|
977
|
+
pins: (await local.facts()).chatPins,
|
|
978
|
+
}));
|
|
949
979
|
});
|
|
950
980
|
},
|
|
951
981
|
async create(input) {
|
|
@@ -953,7 +983,7 @@ export function conversationSurface(alive) {
|
|
|
953
983
|
const conversation = answered(result, 'conversation_id');
|
|
954
984
|
if (conversation === null)
|
|
955
985
|
return result;
|
|
956
|
-
const listed = (await
|
|
986
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
957
987
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
958
988
|
alive.creating(conversation);
|
|
959
989
|
}
|
|
@@ -1011,42 +1041,38 @@ export function conversationSurface(alive) {
|
|
|
1011
1041
|
rename(conversation, name, operation) {
|
|
1012
1042
|
return invoke(alive, 'conversations/rename', conversation, operation, { name });
|
|
1013
1043
|
},
|
|
1014
|
-
|
|
1015
|
-
return invoke(alive, 'conversations/
|
|
1044
|
+
set(conversation, settings, operation) {
|
|
1045
|
+
return invoke(alive, 'conversations/set', conversation, operation, settings);
|
|
1016
1046
|
},
|
|
1017
1047
|
retry(conversation, message, operation) {
|
|
1018
1048
|
return invoke(alive, 'conversations/retry', conversation, operation, {
|
|
1019
1049
|
message_id: message,
|
|
1020
1050
|
});
|
|
1021
1051
|
},
|
|
1022
|
-
async
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1052
|
+
async pin(figures) {
|
|
1053
|
+
const pins = [...figures];
|
|
1054
|
+
await alive.deps.durably((local) => local.fact('chatPins', pins));
|
|
1055
|
+
const views = [...alive.views()];
|
|
1056
|
+
for (const view of views)
|
|
1057
|
+
view.held.set({ pins });
|
|
1058
|
+
for (const conversation of new Set(views.map((view) => view.conversation))) {
|
|
1059
|
+
emit(alive, conversation);
|
|
1060
|
+
}
|
|
1030
1061
|
},
|
|
1031
|
-
openTurn(conversation, turn) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
await local.fact('openedTurns', { ...openedTurns, [conversation]: turn });
|
|
1035
|
-
});
|
|
1062
|
+
async openTurn(conversation, turn) {
|
|
1063
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1064
|
+
tellList(alive);
|
|
1036
1065
|
},
|
|
1037
1066
|
dismissSuggestion(conversation, suggestion) {
|
|
1038
1067
|
return alive.deps.durably(async (local) => {
|
|
1039
|
-
|
|
1040
|
-
if (dismissedSuggestions[conversation] === suggestion)
|
|
1068
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1041
1069
|
return;
|
|
1042
|
-
await local.
|
|
1043
|
-
|
|
1044
|
-
|
|
1070
|
+
await local.keepConversationFact({
|
|
1071
|
+
conversation,
|
|
1072
|
+
name: 'dismissedSuggestion',
|
|
1073
|
+
value: suggestion,
|
|
1045
1074
|
});
|
|
1046
|
-
|
|
1047
|
-
if (view.conversation === conversation)
|
|
1048
|
-
view.held.set({ dismissed: suggestion });
|
|
1049
|
-
}
|
|
1075
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1050
1076
|
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1051
1077
|
});
|
|
1052
1078
|
},
|
|
@@ -1079,31 +1105,37 @@ export function chatDraftSurface(alive) {
|
|
|
1079
1105
|
};
|
|
1080
1106
|
}
|
|
1081
1107
|
export async function conversationsOpened(alive, local) {
|
|
1082
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1083
|
-
if (conversationList === null ||
|
|
1108
|
+
const { conversationList, agentList, conversationCursor } = await local.facts();
|
|
1109
|
+
if (conversationList === null || agentList === null)
|
|
1110
|
+
return;
|
|
1111
|
+
alive.held.set({ listHeld: true });
|
|
1112
|
+
if (alive.known())
|
|
1084
1113
|
return;
|
|
1085
1114
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1086
1115
|
conversationsLearned(alive);
|
|
1087
1116
|
}
|
|
1117
|
+
export function reconcileOpening(alive) {
|
|
1118
|
+
alive.held.set({ openingRead: true });
|
|
1119
|
+
return reconcileConversations(alive);
|
|
1120
|
+
}
|
|
1088
1121
|
export async function reconcileConversations(alive) {
|
|
1089
1122
|
if (!alive.known())
|
|
1090
1123
|
return;
|
|
1091
1124
|
const local = await alive.deps.local();
|
|
1092
|
-
const [held,
|
|
1125
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1093
1126
|
local.conversations(),
|
|
1094
|
-
local.
|
|
1127
|
+
local.storedConversations(),
|
|
1095
1128
|
local.facts(),
|
|
1096
1129
|
]);
|
|
1097
1130
|
const list = conversationList ?? [];
|
|
1131
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1098
1132
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1099
1133
|
const named = new Set(entries.keys());
|
|
1100
1134
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1101
1135
|
const { replicated } = alive.held.now();
|
|
1102
|
-
const leaving = [
|
|
1103
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1104
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1136
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1105
1137
|
!alive.isCreating(conversation) &&
|
|
1106
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1138
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1107
1139
|
for (const conversation of named) {
|
|
1108
1140
|
if (!replicated.has(conversation) &&
|
|
1109
1141
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1187,6 +1219,7 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1187
1219
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1188
1220
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1189
1221
|
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1222
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1190
1223
|
held.set({ window: messages });
|
|
1191
1224
|
held.set({ more });
|
|
1192
1225
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
@@ -1194,10 +1227,10 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1194
1227
|
.then(() => {
|
|
1195
1228
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1196
1229
|
return;
|
|
1197
|
-
const
|
|
1198
|
-
const shown = window ?? [];
|
|
1230
|
+
const now = held.now();
|
|
1231
|
+
const shown = now.window ?? [];
|
|
1199
1232
|
const frame = sharedFrame(view, shown);
|
|
1200
|
-
watcher.notify(viewOf(alive, conversation, shown, frame,
|
|
1233
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1201
1234
|
})
|
|
1202
1235
|
.catch(() => { });
|
|
1203
1236
|
return () => {
|
|
@@ -1213,9 +1246,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1213
1246
|
export function watchConversationAgents(alive, deliver) {
|
|
1214
1247
|
alive.agentListeners.join(deliver);
|
|
1215
1248
|
conversationsLearned(alive);
|
|
1216
|
-
readAgents(alive);
|
|
1217
1249
|
return () => alive.agentListeners.leave(deliver);
|
|
1218
1250
|
}
|
|
1251
|
+
export function watchListedAgents(alive, deliver) {
|
|
1252
|
+
alive.listedListeners.join(deliver);
|
|
1253
|
+
conversationsLearned(alive);
|
|
1254
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1255
|
+
}
|
|
1219
1256
|
export function conversationsChanged(alive, set) {
|
|
1220
1257
|
for (const conversation of set.conversations)
|
|
1221
1258
|
emit(alive, conversation);
|
|
@@ -1227,26 +1264,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1227
1264
|
if (event.whole)
|
|
1228
1265
|
alive.relistBegun();
|
|
1229
1266
|
if (alive.relisting())
|
|
1230
|
-
alive.relistHeard(event.entries);
|
|
1267
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1231
1268
|
if (event.more && alive.relisting())
|
|
1232
1269
|
return;
|
|
1233
1270
|
const whole = alive.relistTaken();
|
|
1234
1271
|
listChanged(alive, {
|
|
1235
1272
|
replacing: whole !== null,
|
|
1236
|
-
set: whole === null ? event.entries : [...whole.values()],
|
|
1273
|
+
set: whole === null ? event.entries : [...whole.conversations.values()],
|
|
1274
|
+
agents: whole === null ? event.agents : [...whole.agents.values()],
|
|
1237
1275
|
gone: null,
|
|
1238
1276
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1239
1277
|
});
|
|
1240
1278
|
return;
|
|
1241
1279
|
}
|
|
1242
1280
|
if (event.kind === 'listed') {
|
|
1243
|
-
alive.relistHeard([event.entry]);
|
|
1244
|
-
listChanged(alive, { replacing: false, set: [event.entry], gone: null });
|
|
1281
|
+
alive.relistHeard([event.entry], []);
|
|
1282
|
+
listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
|
|
1283
|
+
return;
|
|
1284
|
+
}
|
|
1285
|
+
if (event.kind === 'agent') {
|
|
1286
|
+
alive.relistHeard([], [event.agent]);
|
|
1287
|
+
listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
|
|
1245
1288
|
return;
|
|
1246
1289
|
}
|
|
1247
1290
|
if (event.kind === 'unlisted') {
|
|
1248
1291
|
alive.relistDropped(event.conversation);
|
|
1249
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1292
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1250
1293
|
return;
|
|
1251
1294
|
}
|
|
1252
1295
|
heard(alive, event);
|