@agentshouse/mdruntime 0.1.0-c26a54071744b → 0.1.0-c27d511fb284d
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 -22
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +51 -28
- package/dist/adapter.d.ts +136 -29
- 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 +347 -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 +20 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +28 -57
- 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 +14 -14
- 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 +8 -1
- package/dist/conversation-row.d.ts.map +1 -1
- package/dist/conversation-row.js +20 -7
- package/dist/conversation.d.ts +29 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +241 -177
- 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 -8
- 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 +75 -31
- 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 +20 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -6
- package/dist/install.d.ts +9 -3
- package/dist/install.d.ts.map +1 -1
- package/dist/install.js +44 -46
- package/dist/lifecycle.d.ts +1 -1
- package/dist/lifecycle.d.ts.map +1 -1
- package/dist/lifecycle.js +40 -29
- 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 -3
- package/dist/lost.d.ts.map +1 -1
- package/dist/lost.js +2 -3
- package/dist/media.d.ts +19 -3
- package/dist/media.d.ts.map +1 -1
- package/dist/media.js +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 +17 -3
- package/dist/messages.d.ts.map +1 -1
- package/dist/messages.js +29 -10
- package/dist/modal.d.ts +2 -0
- package/dist/modal.d.ts.map +1 -0
- package/dist/modal.js +11 -0
- package/dist/model.d.ts +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 +5 -8
- package/dist/name.d.ts +0 -1
- package/dist/name.d.ts.map +1 -1
- package/dist/name.js +3 -7
- package/dist/observation.d.ts +29 -12
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +206 -69
- package/dist/online.d.ts +7 -0
- package/dist/online.d.ts.map +1 -0
- package/dist/online.js +29 -0
- package/dist/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 -10
- 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 -0
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +31 -5
- 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 +198 -87
- package/dist/presence.d.ts +8 -2
- package/dist/presence.d.ts.map +1 -1
- package/dist/presence.js +24 -13
- package/dist/queries.d.ts +1 -1
- package/dist/queries.d.ts.map +1 -1
- package/dist/queries.js +116 -71
- 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 +54 -39
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +162 -38
- package/dist/react.d.ts +6 -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/reference-forms.d.ts +4 -0
- package/dist/reference-forms.d.ts.map +1 -0
- package/dist/reference-forms.js +74 -0
- package/dist/refresh.d.ts +1 -1
- package/dist/refresh.js +4 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +1 -3
- package/dist/replica.d.ts +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 +45 -0
- package/dist/rows.d.ts +11 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- package/dist/running.d.ts +5 -0
- package/dist/running.d.ts.map +1 -0
- package/dist/running.js +10 -0
- package/dist/runtime.d.ts +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 +17 -86
- package/dist/saves.d.ts +7 -5
- package/dist/saves.d.ts.map +1 -1
- package/dist/saves.js +107 -57
- 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 +2 -2
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +3 -9
- package/dist/source.d.ts +7 -0
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +15 -2
- package/dist/store/installs.d.ts +2 -2
- package/dist/store/installs.d.ts.map +1 -1
- package/dist/store/installs.js +10 -4
- package/dist/store/readiness.d.ts +5 -4
- package/dist/store/readiness.d.ts.map +1 -1
- package/dist/store/readiness.js +28 -12
- package/dist/store/records.d.ts +30 -8
- package/dist/store/records.d.ts.map +1 -1
- package/dist/store/records.js +70 -26
- 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 +13 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +57 -26
- package/dist/sync.d.ts +4 -2
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +52 -35
- package/dist/tables.d.ts +28 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +95 -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 +36 -17
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +20 -14
- package/package.json +4 -4
- package/dist/binary.d.ts.map +0 -1
- package/dist/binary.js +0 -8
- 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,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,16 +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,
|
|
31
|
+
dismissedSuggestion: null,
|
|
32
|
+
pins: [],
|
|
32
33
|
};
|
|
33
34
|
}
|
|
34
35
|
export const SESSION_STARTED = 'Session started';
|
|
35
36
|
const NEW_CHAT = 'new:';
|
|
36
37
|
const LISTING = 'listing';
|
|
37
|
-
const AGENTS = 'agents';
|
|
38
38
|
export const CATCHING_UP = 'catching-up';
|
|
39
39
|
export const HISTORY_CONVERSATIONS = 64;
|
|
40
40
|
export function newChat(agent) {
|
|
@@ -198,17 +198,17 @@ function withSubmitted(draft, submitted) {
|
|
|
198
198
|
const { submitted: _held, ...unsent } = draft;
|
|
199
199
|
return submitted.length === 0 ? unsent : { ...unsent, submitted };
|
|
200
200
|
}
|
|
201
|
-
function
|
|
202
|
-
return
|
|
201
|
+
export function joinedDraft(first, second) {
|
|
202
|
+
return [first, second].filter((one) => one !== '').join('\n');
|
|
203
203
|
}
|
|
204
204
|
function returned(draft, submission, others) {
|
|
205
205
|
return withSubmitted({
|
|
206
206
|
conversation: draft.conversation,
|
|
207
|
-
|
|
207
|
+
text: joinedDraft(submission.text, draft.text),
|
|
208
208
|
revision: chatDraftRevision(),
|
|
209
209
|
}, others);
|
|
210
210
|
}
|
|
211
|
-
function viewOf(alive, conversation, held, frame, draft, ended) {
|
|
211
|
+
function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
|
|
212
212
|
const facts = alive.liveOf(conversation);
|
|
213
213
|
return {
|
|
214
214
|
conversation,
|
|
@@ -227,36 +227,44 @@ function viewOf(alive, conversation, held, frame, draft, ended) {
|
|
|
227
227
|
options: structuredClone(facts.options),
|
|
228
228
|
starting: facts.starting,
|
|
229
229
|
state: sessionOf(facts, held, ended),
|
|
230
|
-
link: facts.link === null ? null : { ...facts.link },
|
|
231
230
|
deliveryWaiting: [...facts.deliveryWaiting],
|
|
232
231
|
deliveryUnknown: [...facts.deliveryUnknown],
|
|
233
232
|
chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
|
|
233
|
+
dismissedSuggestion: dismissed,
|
|
234
|
+
pins: [...pins],
|
|
234
235
|
};
|
|
235
236
|
}
|
|
236
|
-
function
|
|
237
|
+
function standing(facts, saved, ended) {
|
|
237
238
|
if (facts.state !== null)
|
|
238
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) {
|
|
239
246
|
const saved = [...held]
|
|
240
247
|
.reverse()
|
|
241
248
|
.map(({ message }) => record(message))
|
|
242
249
|
.find(({ content }) => isTurn(content));
|
|
243
250
|
const at = saved === undefined ? null : text(saved, 'accepted_at');
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
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);
|
|
248
254
|
}
|
|
249
255
|
function emit(alive, conversation) {
|
|
250
256
|
if (alive.deps.closed())
|
|
251
257
|
return;
|
|
252
258
|
for (const view of alive.views()) {
|
|
253
|
-
const
|
|
259
|
+
const held = view.held.now();
|
|
260
|
+
const { window } = held;
|
|
254
261
|
if (view.conversation !== conversation || window === null)
|
|
255
262
|
continue;
|
|
256
263
|
const ready = view.ready();
|
|
257
264
|
if (ready.length === 0)
|
|
258
265
|
continue;
|
|
259
|
-
const
|
|
266
|
+
const frame = sharedFrame(view, window);
|
|
267
|
+
const value = viewOf(alive, conversation, window, frame, held);
|
|
260
268
|
for (const watcher of ready)
|
|
261
269
|
watcher.notify(value);
|
|
262
270
|
}
|
|
@@ -292,76 +300,106 @@ function stateOf(alive, conversation) {
|
|
|
292
300
|
return facts.turn === null ? 'idle' : 'working';
|
|
293
301
|
}
|
|
294
302
|
function rowOf(alive, conversation) {
|
|
295
|
-
const { turn, questions } = alive.liveOf(conversation);
|
|
303
|
+
const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
|
|
296
304
|
return {
|
|
297
305
|
state: stateOf(alive, conversation),
|
|
298
306
|
started: turn?.started ?? null,
|
|
299
307
|
line: turn === null ? null : runningLine(turn.parts),
|
|
300
308
|
question: openQuestion(questions),
|
|
301
309
|
asked: questionAsked(questions),
|
|
310
|
+
deliveryWaiting: [...deliveryWaiting],
|
|
302
311
|
};
|
|
303
312
|
}
|
|
304
313
|
async function entries(alive) {
|
|
305
|
-
const
|
|
306
|
-
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)))
|
|
307
320
|
return null;
|
|
308
321
|
const held = list.length === 0
|
|
309
322
|
? []
|
|
310
323
|
: await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
|
|
311
324
|
const rows = new Map(held.map((one) => [one.conversation, one]));
|
|
312
|
-
return list.map((entry) =>
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
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
|
+
...rowOf(alive, entry.conversation),
|
|
339
|
+
...heldFacts(rows.get(entry.conversation), entry),
|
|
340
|
+
jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
|
|
341
|
+
};
|
|
342
|
+
});
|
|
323
343
|
}
|
|
324
|
-
async function
|
|
325
|
-
const
|
|
326
|
-
if (
|
|
327
|
-
return
|
|
328
|
-
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
344
|
+
async function heldListing(alive) {
|
|
345
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
346
|
+
if (conversationList !== null && agentList !== null)
|
|
347
|
+
return { conversations: conversationList, agents: agentList };
|
|
348
|
+
return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
|
|
349
|
+
? null
|
|
350
|
+
: { conversations: [], agents: [] };
|
|
329
351
|
}
|
|
330
352
|
async function endedIn(alive, conversation) {
|
|
331
|
-
const
|
|
332
|
-
return
|
|
353
|
+
const listing = await heldListing(alive);
|
|
354
|
+
return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
|
|
355
|
+
null);
|
|
356
|
+
}
|
|
357
|
+
function upserted(kept, set, key) {
|
|
358
|
+
const held = new Map(kept.map((one) => [key(one), one]));
|
|
359
|
+
for (const one of set)
|
|
360
|
+
held.set(key(one), { ...one });
|
|
361
|
+
return held;
|
|
333
362
|
}
|
|
334
363
|
function listChanged(alive, change) {
|
|
335
364
|
void alive.deps
|
|
336
365
|
.durably(async (local) => {
|
|
337
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
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)
|
|
342
371
|
alive.created(entry.conversation);
|
|
343
|
-
}
|
|
344
372
|
if (change.gone !== null)
|
|
345
373
|
held.delete(change.gone);
|
|
346
374
|
const list = [...held.values()];
|
|
375
|
+
const agents = [
|
|
376
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
377
|
+
];
|
|
347
378
|
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
348
379
|
await local.fact('conversationList', list);
|
|
349
380
|
}
|
|
381
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
382
|
+
await local.fact('agentList', agents);
|
|
383
|
+
}
|
|
350
384
|
if (change.cursor !== undefined) {
|
|
351
385
|
if (change.cursor !== conversationCursor) {
|
|
352
386
|
await local.fact('conversationCursor', change.cursor);
|
|
353
387
|
}
|
|
354
388
|
alive.deps.stream()?.hold(change.cursor);
|
|
355
389
|
}
|
|
356
|
-
return list;
|
|
390
|
+
return { conversations: list, agents };
|
|
357
391
|
})
|
|
358
|
-
.catch(async () =>
|
|
359
|
-
.
|
|
392
|
+
.catch(async () => {
|
|
393
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
394
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
395
|
+
})
|
|
396
|
+
.then((listing) => {
|
|
360
397
|
if (alive.deps.closed() || change.paged === true)
|
|
361
398
|
return;
|
|
399
|
+
const list = listing.conversations;
|
|
362
400
|
endedAnew(alive, list);
|
|
363
401
|
if (change.cursor !== undefined) {
|
|
364
|
-
alive.held.set({ listKnown: true });
|
|
402
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
365
403
|
settleBehind(alive, list);
|
|
366
404
|
openingEnded(alive);
|
|
367
405
|
alive.deps.settled();
|
|
@@ -369,11 +407,12 @@ function listChanged(alive, change) {
|
|
|
369
407
|
emitList(alive);
|
|
370
408
|
if (!alive.known())
|
|
371
409
|
return;
|
|
372
|
-
retiredDrafts(alive,
|
|
373
|
-
const { replicated } = alive.held.now();
|
|
374
|
-
if (change.cursor === undefined
|
|
375
|
-
|
|
376
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
410
|
+
retiredDrafts(alive, listing);
|
|
411
|
+
const { replicated, openingRead } = alive.held.now();
|
|
412
|
+
if (change.cursor === undefined
|
|
413
|
+
? list.length !== replicated.size ||
|
|
414
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
415
|
+
: openingRead) {
|
|
377
416
|
alive.deps.again();
|
|
378
417
|
}
|
|
379
418
|
}, uncaught);
|
|
@@ -389,16 +428,16 @@ function endedAnew(alive, list) {
|
|
|
389
428
|
emit(alive, view.conversation);
|
|
390
429
|
}
|
|
391
430
|
}
|
|
392
|
-
function
|
|
393
|
-
const reading =
|
|
431
|
+
function shownListing(alive, work) {
|
|
432
|
+
const reading = heldListing(alive);
|
|
394
433
|
alive.inOrder(async () => {
|
|
395
|
-
const
|
|
434
|
+
const listing = await reading.catch((error) => {
|
|
396
435
|
uncaught(error);
|
|
397
436
|
return null;
|
|
398
437
|
});
|
|
399
|
-
if (
|
|
438
|
+
if (listing === null || alive.deps.closed())
|
|
400
439
|
return;
|
|
401
|
-
work(
|
|
440
|
+
work(listing);
|
|
402
441
|
});
|
|
403
442
|
}
|
|
404
443
|
async function told(alive) {
|
|
@@ -443,84 +482,74 @@ export function conversationsLearned(alive) {
|
|
|
443
482
|
return;
|
|
444
483
|
if (alive.listeners.waiting())
|
|
445
484
|
tellList(alive);
|
|
446
|
-
if (!alive.agentListeners.waiting())
|
|
485
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
447
486
|
return;
|
|
448
|
-
|
|
487
|
+
shownListing(alive, (listing) => {
|
|
488
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
489
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
490
|
+
});
|
|
449
491
|
}
|
|
450
|
-
function
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
environment: structuredClone(held.environment),
|
|
467
|
-
};
|
|
468
|
-
})
|
|
492
|
+
function agentsOf(listing) {
|
|
493
|
+
return listing.agents
|
|
494
|
+
.filter((agent) => agent.retired_at === null)
|
|
495
|
+
.map((agent) => ({
|
|
496
|
+
identity: agent.id,
|
|
497
|
+
name: agent.name,
|
|
498
|
+
cli: agent.cli,
|
|
499
|
+
model: agent.model,
|
|
500
|
+
effort: agent.effort,
|
|
501
|
+
model_fixed: agent.model_fixed,
|
|
502
|
+
environment: {
|
|
503
|
+
identity: agent.environment,
|
|
504
|
+
name: agent.environment_name,
|
|
505
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
506
|
+
},
|
|
507
|
+
}))
|
|
469
508
|
.sort((left, right) => left.name === right.name
|
|
470
509
|
? left.identity.localeCompare(right.identity)
|
|
471
510
|
: left.name.localeCompare(right.name));
|
|
472
511
|
}
|
|
473
|
-
function readAgents(alive) {
|
|
474
|
-
const stream = alive.deps.stream();
|
|
475
|
-
if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
|
|
476
|
-
return;
|
|
477
|
-
const { agents: read } = stream;
|
|
478
|
-
const { agentListeners } = alive;
|
|
479
|
-
alive.held.set({ agentsReading: true });
|
|
480
|
-
void alive.deps.recovery
|
|
481
|
-
.attempt('agents', async () => {
|
|
482
|
-
if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
|
|
483
|
-
return 'done';
|
|
484
|
-
}
|
|
485
|
-
const listed = await retrying(alive.deps.retries, 'conversations', AGENTS, read)();
|
|
486
|
-
if (listed === null)
|
|
487
|
-
return 'done';
|
|
488
|
-
alive.held.set({ listedAgents: listed });
|
|
489
|
-
emitAgents(alive);
|
|
490
|
-
return 'done';
|
|
491
|
-
})
|
|
492
|
-
.finally(() => {
|
|
493
|
-
alive.held.set({ agentsReading: false });
|
|
494
|
-
});
|
|
495
|
-
}
|
|
496
512
|
function emitAgents(alive) {
|
|
497
|
-
|
|
513
|
+
const { agentListeners, listedListeners } = alive;
|
|
514
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
498
515
|
return;
|
|
499
|
-
|
|
500
|
-
const value =
|
|
516
|
+
shownListing(alive, (listing) => {
|
|
517
|
+
const value = agentsOf(listing);
|
|
501
518
|
const shown = JSON.stringify(value);
|
|
502
|
-
if (shown
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
519
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
520
|
+
alive.held.set({ agentsShown: shown });
|
|
521
|
+
agentListeners.tell(value);
|
|
522
|
+
}
|
|
523
|
+
const listed = JSON.stringify(listing.agents);
|
|
524
|
+
if (listed !== alive.held.now().listedShown) {
|
|
525
|
+
alive.held.set({ listedShown: listed });
|
|
526
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
527
|
+
}
|
|
506
528
|
});
|
|
507
529
|
}
|
|
530
|
+
function ran({ state, process }) {
|
|
531
|
+
return JSON.stringify([state?.running ?? null, process?.running ?? null]);
|
|
532
|
+
}
|
|
508
533
|
function setLive(alive, conversation, next) {
|
|
534
|
+
const was = ran(alive.liveOf(conversation));
|
|
509
535
|
const before = rowOf(alive, conversation);
|
|
510
536
|
alive.holdLive(conversation, next);
|
|
511
537
|
const after = rowOf(alive, conversation);
|
|
512
|
-
if (after.state !== before.state ||
|
|
538
|
+
if (after.state !== before.state ||
|
|
539
|
+
after.started !== before.started ||
|
|
540
|
+
ran(alive.liveOf(conversation)) !== was ||
|
|
541
|
+
after.deliveryWaiting.join() !== before.deliveryWaiting.join())
|
|
513
542
|
emitList(alive);
|
|
514
543
|
else if (after.line !== before.line ||
|
|
515
544
|
after.question !== before.question ||
|
|
516
545
|
after.asked !== before.asked)
|
|
517
546
|
tellSoon(alive);
|
|
518
547
|
}
|
|
519
|
-
function retiredChat(conversation,
|
|
548
|
+
function retiredChat(conversation, listing) {
|
|
520
549
|
if (!conversation.startsWith(NEW_CHAT))
|
|
521
550
|
return false;
|
|
522
551
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
523
|
-
return
|
|
552
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
524
553
|
}
|
|
525
554
|
function live(alive, conversation, change) {
|
|
526
555
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -540,7 +569,6 @@ function openingEnded(alive) {
|
|
|
540
569
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
541
570
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
542
571
|
state: facts.has('state') ? QUIET.state : held.state,
|
|
543
|
-
link: facts.has('link') ? QUIET.link : held.link,
|
|
544
572
|
deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
|
|
545
573
|
deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
|
|
546
574
|
});
|
|
@@ -573,19 +601,13 @@ function handReplicated(alive) {
|
|
|
573
601
|
}
|
|
574
602
|
async function remove(alive, leaving) {
|
|
575
603
|
await alive.deps.durably(async (local) => {
|
|
576
|
-
const kept = new Set(
|
|
577
|
-
...(await local.conversations(leaving)).map(({ conversation }) => conversation),
|
|
578
|
-
...(await local.chatDrafts())
|
|
579
|
-
.filter(({ conversation }) => leaving.includes(conversation))
|
|
580
|
-
.map(({ conversation }) => conversation),
|
|
581
|
-
]);
|
|
582
|
-
await local.dropConversations(leaving);
|
|
604
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
583
605
|
const changed = [];
|
|
584
606
|
for (const conversation of leaving) {
|
|
585
607
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
586
608
|
changed.push(conversation);
|
|
587
609
|
}
|
|
588
|
-
|
|
610
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
589
611
|
alive.forget(conversation);
|
|
590
612
|
setLive(alive, conversation, null);
|
|
591
613
|
await slide(alive, local, conversation, null);
|
|
@@ -614,7 +636,7 @@ async function readsOf(local, conversations) {
|
|
|
614
636
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
615
637
|
}
|
|
616
638
|
function retiredDrafts(alive, list) {
|
|
617
|
-
if (!list.some((
|
|
639
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
618
640
|
return;
|
|
619
641
|
void alive.deps
|
|
620
642
|
.local()
|
|
@@ -778,10 +800,6 @@ function heard(alive, event) {
|
|
|
778
800
|
live(alive, conversation, { state: structuredClone(event.state) });
|
|
779
801
|
return;
|
|
780
802
|
}
|
|
781
|
-
if (event.kind === 'link') {
|
|
782
|
-
live(alive, conversation, { link: { connected: event.connected } });
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
803
|
if (event.kind === 'deliveries') {
|
|
786
804
|
live(alive, conversation, {
|
|
787
805
|
deliveryWaiting: [...event.waiting],
|
|
@@ -810,19 +828,27 @@ function heard(alive, event) {
|
|
|
810
828
|
emit(alive, conversation);
|
|
811
829
|
}
|
|
812
830
|
async function kept(alive, local, conversation, following) {
|
|
813
|
-
const
|
|
814
|
-
if (
|
|
831
|
+
const draft = following === null || empty(following) ? null : following;
|
|
832
|
+
if (draft === null)
|
|
815
833
|
await local.dropChatDraft(conversation);
|
|
816
834
|
else
|
|
817
|
-
await local.keepChatDrafts([
|
|
818
|
-
|
|
835
|
+
await local.keepChatDrafts([draft]);
|
|
836
|
+
heldInViews(alive, conversation, { draft });
|
|
819
837
|
}
|
|
820
|
-
function
|
|
838
|
+
function heldInViews(alive, conversation, held) {
|
|
821
839
|
for (const view of alive.views()) {
|
|
822
840
|
if (view.conversation === conversation)
|
|
823
|
-
view.held.set(
|
|
841
|
+
view.held.set(held);
|
|
824
842
|
}
|
|
825
843
|
}
|
|
844
|
+
async function factOf(local, name) {
|
|
845
|
+
return Object.fromEntries((await local.conversationFacts())
|
|
846
|
+
.filter((fact) => fact.name === name)
|
|
847
|
+
.map(({ conversation, value }) => [conversation, value]));
|
|
848
|
+
}
|
|
849
|
+
async function dismissedIn(local, conversation) {
|
|
850
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
851
|
+
}
|
|
826
852
|
async function draftAt(local, conversation) {
|
|
827
853
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
828
854
|
}
|
|
@@ -853,9 +879,9 @@ function moved(alive, agent, operation, to) {
|
|
|
853
879
|
: [{ ...unsent, conversation: to }];
|
|
854
880
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
855
881
|
await local.keepChatDrafts([left, ...taken]);
|
|
856
|
-
|
|
882
|
+
heldInViews(alive, from, { draft: left });
|
|
857
883
|
for (const one of taken)
|
|
858
|
-
|
|
884
|
+
heldInViews(alive, to, { draft: one });
|
|
859
885
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
860
886
|
});
|
|
861
887
|
}
|
|
@@ -920,8 +946,9 @@ async function dispatched(alive, conversation, submission, resent = false) {
|
|
|
920
946
|
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
921
947
|
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
922
948
|
}
|
|
923
|
-
export function conversationSurface(alive) {
|
|
949
|
+
export function conversationSurface(alive, files) {
|
|
924
950
|
return {
|
|
951
|
+
...files,
|
|
925
952
|
list() {
|
|
926
953
|
return new Promise((settle) => {
|
|
927
954
|
const answer = (listed) => {
|
|
@@ -939,7 +966,12 @@ export function conversationSurface(alive) {
|
|
|
939
966
|
return alive.deps.durably(async (local) => {
|
|
940
967
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
941
968
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
942
|
-
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total),
|
|
969
|
+
return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
|
|
970
|
+
draft: (await local.chatDraft(conversation)) ?? null,
|
|
971
|
+
ended: await endedIn(alive, conversation),
|
|
972
|
+
dismissed: await dismissedIn(local, conversation),
|
|
973
|
+
pins: (await local.facts()).chatPins,
|
|
974
|
+
}));
|
|
943
975
|
});
|
|
944
976
|
},
|
|
945
977
|
async create(input) {
|
|
@@ -947,7 +979,7 @@ export function conversationSurface(alive) {
|
|
|
947
979
|
const conversation = answered(result, 'conversation_id');
|
|
948
980
|
if (conversation === null)
|
|
949
981
|
return result;
|
|
950
|
-
const listed = (await
|
|
982
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
951
983
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
952
984
|
alive.creating(conversation);
|
|
953
985
|
}
|
|
@@ -1005,48 +1037,61 @@ export function conversationSurface(alive) {
|
|
|
1005
1037
|
rename(conversation, name, operation) {
|
|
1006
1038
|
return invoke(alive, 'conversations/rename', conversation, operation, { name });
|
|
1007
1039
|
},
|
|
1008
|
-
|
|
1009
|
-
return invoke(alive, 'conversations/
|
|
1040
|
+
set(conversation, settings, operation) {
|
|
1041
|
+
return invoke(alive, 'conversations/set', conversation, operation, settings);
|
|
1010
1042
|
},
|
|
1011
1043
|
retry(conversation, message, operation) {
|
|
1012
1044
|
return invoke(alive, 'conversations/retry', conversation, operation, {
|
|
1013
1045
|
message_id: message,
|
|
1014
1046
|
});
|
|
1015
1047
|
},
|
|
1016
|
-
async
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1048
|
+
async pin(figures) {
|
|
1049
|
+
const pins = [...figures];
|
|
1050
|
+
await alive.deps.durably((local) => local.fact('chatPins', pins));
|
|
1051
|
+
const views = [...alive.views()];
|
|
1052
|
+
for (const view of views)
|
|
1053
|
+
view.held.set({ pins });
|
|
1054
|
+
for (const conversation of new Set(views.map((view) => view.conversation))) {
|
|
1055
|
+
emit(alive, conversation);
|
|
1056
|
+
}
|
|
1021
1057
|
},
|
|
1022
|
-
async
|
|
1023
|
-
|
|
1058
|
+
async openTurn(conversation, turn) {
|
|
1059
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1060
|
+
tellList(alive);
|
|
1024
1061
|
},
|
|
1025
|
-
|
|
1062
|
+
dismissSuggestion(conversation, suggestion) {
|
|
1026
1063
|
return alive.deps.durably(async (local) => {
|
|
1027
|
-
|
|
1028
|
-
|
|
1064
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1065
|
+
return;
|
|
1066
|
+
await local.keepConversationFact({
|
|
1067
|
+
conversation,
|
|
1068
|
+
name: 'dismissedSuggestion',
|
|
1069
|
+
value: suggestion,
|
|
1070
|
+
});
|
|
1071
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1072
|
+
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1029
1073
|
});
|
|
1030
1074
|
},
|
|
1031
1075
|
};
|
|
1032
1076
|
}
|
|
1077
|
+
function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
|
|
1078
|
+
return withDraft(alive, conversation, (current) => ({
|
|
1079
|
+
conversation,
|
|
1080
|
+
text: text(current?.text ?? ''),
|
|
1081
|
+
revision,
|
|
1082
|
+
...(current === undefined ? {} : pending(current)),
|
|
1083
|
+
}));
|
|
1084
|
+
}
|
|
1033
1085
|
export function chatDraftSurface(alive) {
|
|
1034
1086
|
return {
|
|
1035
|
-
write(conversation, draft, revision
|
|
1036
|
-
return
|
|
1037
|
-
conversation,
|
|
1038
|
-
text: draft.text,
|
|
1039
|
-
revision,
|
|
1040
|
-
...(current === undefined ? {} : pending(current)),
|
|
1041
|
-
}));
|
|
1087
|
+
write(conversation, draft, revision) {
|
|
1088
|
+
return rewritten(alive, conversation, () => draft.text, revision);
|
|
1042
1089
|
},
|
|
1043
1090
|
prepend(conversation, draft) {
|
|
1044
|
-
return
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
...(current === undefined ? {} : pending(current)),
|
|
1049
|
-
}));
|
|
1091
|
+
return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
|
|
1092
|
+
},
|
|
1093
|
+
append(conversation, draft) {
|
|
1094
|
+
return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
|
|
1050
1095
|
},
|
|
1051
1096
|
discard(conversation) {
|
|
1052
1097
|
return withDraft(alive, conversation, (current) => current === undefined
|
|
@@ -1056,31 +1101,37 @@ export function chatDraftSurface(alive) {
|
|
|
1056
1101
|
};
|
|
1057
1102
|
}
|
|
1058
1103
|
export async function conversationsOpened(alive, local) {
|
|
1059
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1060
|
-
if (conversationList === null ||
|
|
1104
|
+
const { conversationList, agentList, conversationCursor } = await local.facts();
|
|
1105
|
+
if (conversationList === null || agentList === null)
|
|
1106
|
+
return;
|
|
1107
|
+
alive.held.set({ listHeld: true });
|
|
1108
|
+
if (alive.known())
|
|
1061
1109
|
return;
|
|
1062
1110
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1063
1111
|
conversationsLearned(alive);
|
|
1064
1112
|
}
|
|
1113
|
+
export function reconcileOpening(alive) {
|
|
1114
|
+
alive.held.set({ openingRead: true });
|
|
1115
|
+
return reconcileConversations(alive);
|
|
1116
|
+
}
|
|
1065
1117
|
export async function reconcileConversations(alive) {
|
|
1066
1118
|
if (!alive.known())
|
|
1067
1119
|
return;
|
|
1068
1120
|
const local = await alive.deps.local();
|
|
1069
|
-
const [held,
|
|
1121
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1070
1122
|
local.conversations(),
|
|
1071
|
-
local.
|
|
1123
|
+
local.storedConversations(),
|
|
1072
1124
|
local.facts(),
|
|
1073
1125
|
]);
|
|
1074
1126
|
const list = conversationList ?? [];
|
|
1127
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1075
1128
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1076
1129
|
const named = new Set(entries.keys());
|
|
1077
1130
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1078
1131
|
const { replicated } = alive.held.now();
|
|
1079
|
-
const leaving = [
|
|
1080
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1081
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1132
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1082
1133
|
!alive.isCreating(conversation) &&
|
|
1083
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1134
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1084
1135
|
for (const conversation of named) {
|
|
1085
1136
|
if (!replicated.has(conversation) &&
|
|
1086
1137
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1163,6 +1214,8 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1163
1214
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
1164
1215
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1165
1216
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1217
|
+
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1218
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1166
1219
|
held.set({ window: messages });
|
|
1167
1220
|
held.set({ more });
|
|
1168
1221
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
@@ -1170,9 +1223,10 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1170
1223
|
.then(() => {
|
|
1171
1224
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1172
1225
|
return;
|
|
1173
|
-
const
|
|
1174
|
-
const shown = window ?? [];
|
|
1175
|
-
|
|
1226
|
+
const now = held.now();
|
|
1227
|
+
const shown = now.window ?? [];
|
|
1228
|
+
const frame = sharedFrame(view, shown);
|
|
1229
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1176
1230
|
})
|
|
1177
1231
|
.catch(() => { });
|
|
1178
1232
|
return () => {
|
|
@@ -1188,9 +1242,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1188
1242
|
export function watchConversationAgents(alive, deliver) {
|
|
1189
1243
|
alive.agentListeners.join(deliver);
|
|
1190
1244
|
conversationsLearned(alive);
|
|
1191
|
-
readAgents(alive);
|
|
1192
1245
|
return () => alive.agentListeners.leave(deliver);
|
|
1193
1246
|
}
|
|
1247
|
+
export function watchListedAgents(alive, deliver) {
|
|
1248
|
+
alive.listedListeners.join(deliver);
|
|
1249
|
+
conversationsLearned(alive);
|
|
1250
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1251
|
+
}
|
|
1194
1252
|
export function conversationsChanged(alive, set) {
|
|
1195
1253
|
for (const conversation of set.conversations)
|
|
1196
1254
|
emit(alive, conversation);
|
|
@@ -1202,26 +1260,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1202
1260
|
if (event.whole)
|
|
1203
1261
|
alive.relistBegun();
|
|
1204
1262
|
if (alive.relisting())
|
|
1205
|
-
alive.relistHeard(event.entries);
|
|
1263
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1206
1264
|
if (event.more && alive.relisting())
|
|
1207
1265
|
return;
|
|
1208
1266
|
const whole = alive.relistTaken();
|
|
1209
1267
|
listChanged(alive, {
|
|
1210
1268
|
replacing: whole !== null,
|
|
1211
|
-
set: whole === null ? event.entries : [...whole.values()],
|
|
1269
|
+
set: whole === null ? event.entries : [...whole.conversations.values()],
|
|
1270
|
+
agents: whole === null ? event.agents : [...whole.agents.values()],
|
|
1212
1271
|
gone: null,
|
|
1213
1272
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1214
1273
|
});
|
|
1215
1274
|
return;
|
|
1216
1275
|
}
|
|
1217
1276
|
if (event.kind === 'listed') {
|
|
1218
|
-
alive.relistHeard([event.entry]);
|
|
1219
|
-
listChanged(alive, { replacing: false, set: [event.entry], gone: null });
|
|
1277
|
+
alive.relistHeard([event.entry], []);
|
|
1278
|
+
listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
|
|
1279
|
+
return;
|
|
1280
|
+
}
|
|
1281
|
+
if (event.kind === 'agent') {
|
|
1282
|
+
alive.relistHeard([], [event.agent]);
|
|
1283
|
+
listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
|
|
1220
1284
|
return;
|
|
1221
1285
|
}
|
|
1222
1286
|
if (event.kind === 'unlisted') {
|
|
1223
1287
|
alive.relistDropped(event.conversation);
|
|
1224
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1288
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1225
1289
|
return;
|
|
1226
1290
|
}
|
|
1227
1291
|
heard(alive, event);
|