@agentshouse/mdruntime 0.1.0-c714ba876473f → 0.1.0-c717ee8bf7934
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 +32 -3
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +62 -19
- package/dist/adapter.d.ts +201 -28
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts +0 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +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 +18 -8
- 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 +23 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +37 -8
- package/dist/conversation.d.ts +26 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +237 -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 +26 -1
- package/dist/entry.d.ts.map +1 -1
- package/dist/entry.js +126 -36
- 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/linked-file.d.ts +7 -0
- package/dist/linked-file.d.ts.map +1 -0
- package/dist/linked-file.js +16 -0
- 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 +64 -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 +4 -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 +1 -1
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +55 -23
- 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 +7 -3
- 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 +31 -96
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +109 -55
- 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 +6 -3
- package/dist/shown.d.ts.map +1 -1
- package/dist/shown.js +90 -53
- 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 +42 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +76 -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,119 @@ 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
|
+
conversation_name: entry.conversationName,
|
|
332
|
+
created: entry.created,
|
|
333
|
+
outcome: entry.outcome,
|
|
334
|
+
waiting: entry.waiting,
|
|
335
|
+
subject: entry.subject,
|
|
336
|
+
room: entry.room,
|
|
337
|
+
model: entry.model,
|
|
338
|
+
effort: entry.effort,
|
|
339
|
+
state: stateOf(entry),
|
|
340
|
+
...rowOf(alive, entry.conversation),
|
|
341
|
+
...heldFacts(rows.get(entry.conversation), entry),
|
|
342
|
+
jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
|
|
343
|
+
};
|
|
344
|
+
});
|
|
326
345
|
}
|
|
327
|
-
async function
|
|
328
|
-
const
|
|
329
|
-
if (
|
|
330
|
-
return
|
|
331
|
-
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
346
|
+
async function heldListing(alive) {
|
|
347
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
348
|
+
if (conversationList !== null && agentList !== null)
|
|
349
|
+
return { conversations: conversationList, agents: agentList };
|
|
350
|
+
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
351
|
+
? null
|
|
352
|
+
: { conversations: [], agents: [] };
|
|
332
353
|
}
|
|
333
354
|
async function endedIn(alive, conversation) {
|
|
334
|
-
const
|
|
335
|
-
return
|
|
355
|
+
const listing = await heldListing(alive);
|
|
356
|
+
return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
|
|
357
|
+
null);
|
|
358
|
+
}
|
|
359
|
+
function upserted(kept, set, key) {
|
|
360
|
+
const held = new Map(kept.map((one) => [key(one), one]));
|
|
361
|
+
for (const one of set)
|
|
362
|
+
held.set(key(one), { ...one });
|
|
363
|
+
return held;
|
|
364
|
+
}
|
|
365
|
+
async function listStored(alive, local, change) {
|
|
366
|
+
const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
|
|
367
|
+
if (readUntil === null)
|
|
368
|
+
await local.fact('readUntil', new Date().toISOString());
|
|
369
|
+
const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
|
|
370
|
+
for (const entry of change.set)
|
|
371
|
+
alive.created(entry.conversation);
|
|
372
|
+
if (change.gone !== null)
|
|
373
|
+
held.delete(change.gone);
|
|
374
|
+
const list = [...held.values()];
|
|
375
|
+
const agents = [
|
|
376
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
377
|
+
];
|
|
378
|
+
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
379
|
+
await local.fact('conversationList', list);
|
|
380
|
+
}
|
|
381
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
382
|
+
await local.fact('agentList', agents);
|
|
383
|
+
}
|
|
384
|
+
if (change.cursor !== undefined && !alive.held.now().listRefused) {
|
|
385
|
+
if (change.cursor !== conversationCursor) {
|
|
386
|
+
await local.fact('conversationCursor', change.cursor);
|
|
387
|
+
}
|
|
388
|
+
alive.deps.stream()?.hold(change.cursor);
|
|
389
|
+
}
|
|
390
|
+
return { conversations: list, agents };
|
|
336
391
|
}
|
|
337
392
|
function listChanged(alive, change) {
|
|
338
393
|
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;
|
|
394
|
+
.durably((local) => listStored(alive, local, change).catch((error) => {
|
|
395
|
+
alive.held.set({ listRefused: true });
|
|
396
|
+
throw error;
|
|
397
|
+
}))
|
|
398
|
+
.catch(async () => {
|
|
399
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
400
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
360
401
|
})
|
|
361
|
-
.
|
|
362
|
-
.then((list) => {
|
|
402
|
+
.then((listing) => {
|
|
363
403
|
if (alive.deps.closed() || change.paged === true)
|
|
364
404
|
return;
|
|
405
|
+
const list = listing.conversations;
|
|
365
406
|
endedAnew(alive, list);
|
|
366
407
|
if (change.cursor !== undefined) {
|
|
367
|
-
alive.held.set({ listKnown: true });
|
|
408
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
368
409
|
settleBehind(alive, list);
|
|
369
410
|
openingEnded(alive);
|
|
370
411
|
alive.deps.settled();
|
|
@@ -372,11 +413,12 @@ function listChanged(alive, change) {
|
|
|
372
413
|
emitList(alive);
|
|
373
414
|
if (!alive.known())
|
|
374
415
|
return;
|
|
375
|
-
retiredDrafts(alive,
|
|
376
|
-
const { replicated } = alive.held.now();
|
|
377
|
-
if (change.cursor === undefined
|
|
378
|
-
|
|
379
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
416
|
+
retiredDrafts(alive, listing);
|
|
417
|
+
const { replicated, openingRead } = alive.held.now();
|
|
418
|
+
if (change.cursor === undefined
|
|
419
|
+
? list.length !== replicated.size ||
|
|
420
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
421
|
+
: openingRead) {
|
|
380
422
|
alive.deps.again();
|
|
381
423
|
}
|
|
382
424
|
}, uncaught);
|
|
@@ -392,16 +434,16 @@ function endedAnew(alive, list) {
|
|
|
392
434
|
emit(alive, view.conversation);
|
|
393
435
|
}
|
|
394
436
|
}
|
|
395
|
-
function
|
|
396
|
-
const reading =
|
|
437
|
+
function shownListing(alive, work) {
|
|
438
|
+
const reading = heldListing(alive);
|
|
397
439
|
alive.inOrder(async () => {
|
|
398
|
-
const
|
|
440
|
+
const listing = await reading.catch((error) => {
|
|
399
441
|
uncaught(error);
|
|
400
442
|
return null;
|
|
401
443
|
});
|
|
402
|
-
if (
|
|
444
|
+
if (listing === null || alive.deps.closed())
|
|
403
445
|
return;
|
|
404
|
-
work(
|
|
446
|
+
work(listing);
|
|
405
447
|
});
|
|
406
448
|
}
|
|
407
449
|
async function told(alive) {
|
|
@@ -446,84 +488,73 @@ export function conversationsLearned(alive) {
|
|
|
446
488
|
return;
|
|
447
489
|
if (alive.listeners.waiting())
|
|
448
490
|
tellList(alive);
|
|
449
|
-
if (!alive.agentListeners.waiting())
|
|
491
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
450
492
|
return;
|
|
451
|
-
|
|
493
|
+
shownListing(alive, (listing) => {
|
|
494
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
495
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
496
|
+
});
|
|
452
497
|
}
|
|
453
|
-
function
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
.
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
:
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
environment: structuredClone(held.environment),
|
|
470
|
-
};
|
|
471
|
-
})
|
|
498
|
+
function agentsOf(listing) {
|
|
499
|
+
return listing.agents
|
|
500
|
+
.filter((agent) => agent.retired_at === null)
|
|
501
|
+
.map((agent) => ({
|
|
502
|
+
identity: agent.id,
|
|
503
|
+
name: agent.name,
|
|
504
|
+
cli: agent.cli,
|
|
505
|
+
model: agent.model,
|
|
506
|
+
effort: agent.effort,
|
|
507
|
+
model_fixed: agent.model_fixed,
|
|
508
|
+
environment: {
|
|
509
|
+
identity: agent.environment,
|
|
510
|
+
name: agent.environment_name,
|
|
511
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
512
|
+
},
|
|
513
|
+
}))
|
|
472
514
|
.sort((left, right) => left.name === right.name
|
|
473
515
|
? left.identity.localeCompare(right.identity)
|
|
474
516
|
: left.name.localeCompare(right.name));
|
|
475
517
|
}
|
|
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
518
|
function emitAgents(alive) {
|
|
500
|
-
|
|
519
|
+
const { agentListeners, listedListeners } = alive;
|
|
520
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
501
521
|
return;
|
|
502
|
-
|
|
503
|
-
const value =
|
|
522
|
+
shownListing(alive, (listing) => {
|
|
523
|
+
const value = agentsOf(listing);
|
|
504
524
|
const shown = JSON.stringify(value);
|
|
505
|
-
if (shown
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
525
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
526
|
+
alive.held.set({ agentsShown: shown });
|
|
527
|
+
agentListeners.tell(value);
|
|
528
|
+
}
|
|
529
|
+
const listed = JSON.stringify(listing.agents);
|
|
530
|
+
if (listed !== alive.held.now().listedShown) {
|
|
531
|
+
alive.held.set({ listedShown: listed });
|
|
532
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
533
|
+
}
|
|
509
534
|
});
|
|
510
535
|
}
|
|
536
|
+
function ran({ state, process }) {
|
|
537
|
+
return JSON.stringify([state?.running ?? null, process?.running ?? null]);
|
|
538
|
+
}
|
|
511
539
|
function setLive(alive, conversation, next) {
|
|
540
|
+
const was = ran(alive.liveOf(conversation));
|
|
512
541
|
const before = rowOf(alive, conversation);
|
|
513
542
|
alive.holdLive(conversation, next);
|
|
514
543
|
const after = rowOf(alive, conversation);
|
|
515
|
-
if (after.
|
|
544
|
+
if (after.started !== before.started ||
|
|
545
|
+
ran(alive.liveOf(conversation)) !== was ||
|
|
546
|
+
after.deliveryWaiting.join() !== before.deliveryWaiting.join())
|
|
516
547
|
emitList(alive);
|
|
517
548
|
else if (after.line !== before.line ||
|
|
518
549
|
after.question !== before.question ||
|
|
519
550
|
after.asked !== before.asked)
|
|
520
551
|
tellSoon(alive);
|
|
521
552
|
}
|
|
522
|
-
function retiredChat(conversation,
|
|
553
|
+
function retiredChat(conversation, listing) {
|
|
523
554
|
if (!conversation.startsWith(NEW_CHAT))
|
|
524
555
|
return false;
|
|
525
556
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
526
|
-
return
|
|
557
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
527
558
|
}
|
|
528
559
|
function live(alive, conversation, change) {
|
|
529
560
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -543,7 +574,6 @@ function openingEnded(alive) {
|
|
|
543
574
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
544
575
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
545
576
|
state: facts.has('state') ? QUIET.state : held.state,
|
|
546
|
-
link: facts.has('link') ? QUIET.link : held.link,
|
|
547
577
|
deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
|
|
548
578
|
deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
|
|
549
579
|
});
|
|
@@ -576,19 +606,13 @@ function handReplicated(alive) {
|
|
|
576
606
|
}
|
|
577
607
|
async function remove(alive, leaving) {
|
|
578
608
|
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);
|
|
609
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
586
610
|
const changed = [];
|
|
587
611
|
for (const conversation of leaving) {
|
|
588
612
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
589
613
|
changed.push(conversation);
|
|
590
614
|
}
|
|
591
|
-
|
|
615
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
592
616
|
alive.forget(conversation);
|
|
593
617
|
setLive(alive, conversation, null);
|
|
594
618
|
await slide(alive, local, conversation, null);
|
|
@@ -617,7 +641,7 @@ async function readsOf(local, conversations) {
|
|
|
617
641
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
618
642
|
}
|
|
619
643
|
function retiredDrafts(alive, list) {
|
|
620
|
-
if (!list.some((
|
|
644
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
621
645
|
return;
|
|
622
646
|
void alive.deps
|
|
623
647
|
.local()
|
|
@@ -781,10 +805,6 @@ function heard(alive, event) {
|
|
|
781
805
|
live(alive, conversation, { state: structuredClone(event.state) });
|
|
782
806
|
return;
|
|
783
807
|
}
|
|
784
|
-
if (event.kind === 'link') {
|
|
785
|
-
live(alive, conversation, { link: { connected: event.connected } });
|
|
786
|
-
return;
|
|
787
|
-
}
|
|
788
808
|
if (event.kind === 'deliveries') {
|
|
789
809
|
live(alive, conversation, {
|
|
790
810
|
deliveryWaiting: [...event.waiting],
|
|
@@ -813,21 +833,26 @@ function heard(alive, event) {
|
|
|
813
833
|
emit(alive, conversation);
|
|
814
834
|
}
|
|
815
835
|
async function kept(alive, local, conversation, following) {
|
|
816
|
-
const
|
|
817
|
-
if (
|
|
836
|
+
const draft = following === null || empty(following) ? null : following;
|
|
837
|
+
if (draft === null)
|
|
818
838
|
await local.dropChatDraft(conversation);
|
|
819
839
|
else
|
|
820
|
-
await local.keepChatDrafts([
|
|
821
|
-
|
|
840
|
+
await local.keepChatDrafts([draft]);
|
|
841
|
+
heldInViews(alive, conversation, { draft });
|
|
822
842
|
}
|
|
823
|
-
function
|
|
843
|
+
function heldInViews(alive, conversation, held) {
|
|
824
844
|
for (const view of alive.views()) {
|
|
825
845
|
if (view.conversation === conversation)
|
|
826
|
-
view.held.set(
|
|
846
|
+
view.held.set(held);
|
|
827
847
|
}
|
|
828
848
|
}
|
|
849
|
+
async function factOf(local, name) {
|
|
850
|
+
return Object.fromEntries((await local.conversationFacts())
|
|
851
|
+
.filter((fact) => fact.name === name)
|
|
852
|
+
.map(({ conversation, value }) => [conversation, value]));
|
|
853
|
+
}
|
|
829
854
|
async function dismissedIn(local, conversation) {
|
|
830
|
-
return (await local
|
|
855
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
831
856
|
}
|
|
832
857
|
async function draftAt(local, conversation) {
|
|
833
858
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
@@ -859,9 +884,9 @@ function moved(alive, agent, operation, to) {
|
|
|
859
884
|
: [{ ...unsent, conversation: to }];
|
|
860
885
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
861
886
|
await local.keepChatDrafts([left, ...taken]);
|
|
862
|
-
|
|
887
|
+
heldInViews(alive, from, { draft: left });
|
|
863
888
|
for (const one of taken)
|
|
864
|
-
|
|
889
|
+
heldInViews(alive, to, { draft: one });
|
|
865
890
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
866
891
|
});
|
|
867
892
|
}
|
|
@@ -926,8 +951,9 @@ async function dispatched(alive, conversation, submission, resent = false) {
|
|
|
926
951
|
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
927
952
|
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
928
953
|
}
|
|
929
|
-
export function conversationSurface(alive) {
|
|
954
|
+
export function conversationSurface(alive, files) {
|
|
930
955
|
return {
|
|
956
|
+
...files,
|
|
931
957
|
list() {
|
|
932
958
|
return new Promise((settle) => {
|
|
933
959
|
const answer = (listed) => {
|
|
@@ -945,7 +971,12 @@ export function conversationSurface(alive) {
|
|
|
945
971
|
return alive.deps.durably(async (local) => {
|
|
946
972
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
947
973
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
948
|
-
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total),
|
|
974
|
+
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
|
|
975
|
+
draft: (await local.chatDraft(conversation)) ?? null,
|
|
976
|
+
ended: await endedIn(alive, conversation),
|
|
977
|
+
dismissed: await dismissedIn(local, conversation),
|
|
978
|
+
pins: (await local.facts()).chatPins,
|
|
979
|
+
}));
|
|
949
980
|
});
|
|
950
981
|
},
|
|
951
982
|
async create(input) {
|
|
@@ -953,7 +984,7 @@ export function conversationSurface(alive) {
|
|
|
953
984
|
const conversation = answered(result, 'conversation_id');
|
|
954
985
|
if (conversation === null)
|
|
955
986
|
return result;
|
|
956
|
-
const listed = (await
|
|
987
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
957
988
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
958
989
|
alive.creating(conversation);
|
|
959
990
|
}
|
|
@@ -1011,42 +1042,38 @@ export function conversationSurface(alive) {
|
|
|
1011
1042
|
rename(conversation, name, operation) {
|
|
1012
1043
|
return invoke(alive, 'conversations/rename', conversation, operation, { name });
|
|
1013
1044
|
},
|
|
1014
|
-
|
|
1015
|
-
return invoke(alive, 'conversations/
|
|
1045
|
+
set(conversation, settings, operation) {
|
|
1046
|
+
return invoke(alive, 'conversations/set', conversation, operation, settings);
|
|
1016
1047
|
},
|
|
1017
1048
|
retry(conversation, message, operation) {
|
|
1018
1049
|
return invoke(alive, 'conversations/retry', conversation, operation, {
|
|
1019
1050
|
message_id: message,
|
|
1020
1051
|
});
|
|
1021
1052
|
},
|
|
1022
|
-
async
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1053
|
+
async pin(figures) {
|
|
1054
|
+
const pins = [...figures];
|
|
1055
|
+
await alive.deps.durably((local) => local.fact('chatPins', pins));
|
|
1056
|
+
const views = [...alive.views()];
|
|
1057
|
+
for (const view of views)
|
|
1058
|
+
view.held.set({ pins });
|
|
1059
|
+
for (const conversation of new Set(views.map((view) => view.conversation))) {
|
|
1060
|
+
emit(alive, conversation);
|
|
1061
|
+
}
|
|
1030
1062
|
},
|
|
1031
|
-
openTurn(conversation, turn) {
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
await local.fact('openedTurns', { ...openedTurns, [conversation]: turn });
|
|
1035
|
-
});
|
|
1063
|
+
async openTurn(conversation, turn) {
|
|
1064
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1065
|
+
tellList(alive);
|
|
1036
1066
|
},
|
|
1037
1067
|
dismissSuggestion(conversation, suggestion) {
|
|
1038
1068
|
return alive.deps.durably(async (local) => {
|
|
1039
|
-
|
|
1040
|
-
if (dismissedSuggestions[conversation] === suggestion)
|
|
1069
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1041
1070
|
return;
|
|
1042
|
-
await local.
|
|
1043
|
-
|
|
1044
|
-
|
|
1071
|
+
await local.keepConversationFact({
|
|
1072
|
+
conversation,
|
|
1073
|
+
name: 'dismissedSuggestion',
|
|
1074
|
+
value: suggestion,
|
|
1045
1075
|
});
|
|
1046
|
-
|
|
1047
|
-
if (view.conversation === conversation)
|
|
1048
|
-
view.held.set({ dismissed: suggestion });
|
|
1049
|
-
}
|
|
1076
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1050
1077
|
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1051
1078
|
});
|
|
1052
1079
|
},
|
|
@@ -1079,31 +1106,37 @@ export function chatDraftSurface(alive) {
|
|
|
1079
1106
|
};
|
|
1080
1107
|
}
|
|
1081
1108
|
export async function conversationsOpened(alive, local) {
|
|
1082
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1083
|
-
if (conversationList === null ||
|
|
1109
|
+
const { conversationList, agentList, conversationCursor } = await local.facts();
|
|
1110
|
+
if (conversationList === null || agentList === null)
|
|
1111
|
+
return;
|
|
1112
|
+
alive.held.set({ listHeld: true });
|
|
1113
|
+
if (alive.known())
|
|
1084
1114
|
return;
|
|
1085
1115
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1086
1116
|
conversationsLearned(alive);
|
|
1087
1117
|
}
|
|
1118
|
+
export function reconcileOpening(alive) {
|
|
1119
|
+
alive.held.set({ openingRead: true });
|
|
1120
|
+
return reconcileConversations(alive);
|
|
1121
|
+
}
|
|
1088
1122
|
export async function reconcileConversations(alive) {
|
|
1089
1123
|
if (!alive.known())
|
|
1090
1124
|
return;
|
|
1091
1125
|
const local = await alive.deps.local();
|
|
1092
|
-
const [held,
|
|
1126
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1093
1127
|
local.conversations(),
|
|
1094
|
-
local.
|
|
1128
|
+
local.storedConversations(),
|
|
1095
1129
|
local.facts(),
|
|
1096
1130
|
]);
|
|
1097
1131
|
const list = conversationList ?? [];
|
|
1132
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1098
1133
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1099
1134
|
const named = new Set(entries.keys());
|
|
1100
1135
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1101
1136
|
const { replicated } = alive.held.now();
|
|
1102
|
-
const leaving = [
|
|
1103
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1104
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1137
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1105
1138
|
!alive.isCreating(conversation) &&
|
|
1106
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1139
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1107
1140
|
for (const conversation of named) {
|
|
1108
1141
|
if (!replicated.has(conversation) &&
|
|
1109
1142
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1187,6 +1220,7 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1187
1220
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1188
1221
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1189
1222
|
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1223
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1190
1224
|
held.set({ window: messages });
|
|
1191
1225
|
held.set({ more });
|
|
1192
1226
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
@@ -1194,10 +1228,10 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1194
1228
|
.then(() => {
|
|
1195
1229
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1196
1230
|
return;
|
|
1197
|
-
const
|
|
1198
|
-
const shown = window ?? [];
|
|
1231
|
+
const now = held.now();
|
|
1232
|
+
const shown = now.window ?? [];
|
|
1199
1233
|
const frame = sharedFrame(view, shown);
|
|
1200
|
-
watcher.notify(viewOf(alive, conversation, shown, frame,
|
|
1234
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1201
1235
|
})
|
|
1202
1236
|
.catch(() => { });
|
|
1203
1237
|
return () => {
|
|
@@ -1213,9 +1247,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1213
1247
|
export function watchConversationAgents(alive, deliver) {
|
|
1214
1248
|
alive.agentListeners.join(deliver);
|
|
1215
1249
|
conversationsLearned(alive);
|
|
1216
|
-
readAgents(alive);
|
|
1217
1250
|
return () => alive.agentListeners.leave(deliver);
|
|
1218
1251
|
}
|
|
1252
|
+
export function watchListedAgents(alive, deliver) {
|
|
1253
|
+
alive.listedListeners.join(deliver);
|
|
1254
|
+
conversationsLearned(alive);
|
|
1255
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1256
|
+
}
|
|
1219
1257
|
export function conversationsChanged(alive, set) {
|
|
1220
1258
|
for (const conversation of set.conversations)
|
|
1221
1259
|
emit(alive, conversation);
|
|
@@ -1227,26 +1265,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1227
1265
|
if (event.whole)
|
|
1228
1266
|
alive.relistBegun();
|
|
1229
1267
|
if (alive.relisting())
|
|
1230
|
-
alive.relistHeard(event.entries);
|
|
1268
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1231
1269
|
if (event.more && alive.relisting())
|
|
1232
1270
|
return;
|
|
1233
1271
|
const whole = alive.relistTaken();
|
|
1234
1272
|
listChanged(alive, {
|
|
1235
1273
|
replacing: whole !== null,
|
|
1236
|
-
set: whole === null ? event.entries : [...whole.values()],
|
|
1274
|
+
set: whole === null ? event.entries : [...whole.conversations.values()],
|
|
1275
|
+
agents: whole === null ? event.agents : [...whole.agents.values()],
|
|
1237
1276
|
gone: null,
|
|
1238
1277
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1239
1278
|
});
|
|
1240
1279
|
return;
|
|
1241
1280
|
}
|
|
1242
1281
|
if (event.kind === 'listed') {
|
|
1243
|
-
alive.relistHeard([event.entry]);
|
|
1244
|
-
listChanged(alive, { replacing: false, set: [event.entry], gone: null });
|
|
1282
|
+
alive.relistHeard([event.entry], []);
|
|
1283
|
+
listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
|
|
1284
|
+
return;
|
|
1285
|
+
}
|
|
1286
|
+
if (event.kind === 'agent') {
|
|
1287
|
+
alive.relistHeard([], [event.agent]);
|
|
1288
|
+
listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
|
|
1245
1289
|
return;
|
|
1246
1290
|
}
|
|
1247
1291
|
if (event.kind === 'unlisted') {
|
|
1248
1292
|
alive.relistDropped(event.conversation);
|
|
1249
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1293
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1250
1294
|
return;
|
|
1251
1295
|
}
|
|
1252
1296
|
heard(alive, event);
|