@agentshouse/mdruntime 0.1.0-cd71aba4d0215 → 0.1.0-cd8d184c6fbe0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -19
- package/dist/acceptance.d.ts.map +1 -1
- package/dist/acceptance.js +32 -22
- package/dist/act-lanes.d.ts +11 -14
- package/dist/act-lanes.d.ts.map +1 -1
- package/dist/act-lanes.js +53 -5
- package/dist/actions.d.ts +1 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +135 -55
- package/dist/adapter.d.ts +168 -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 +27 -15
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +29 -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 +4 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +88 -44
- package/dist/connection.d.ts +1 -1
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +15 -14
- package/dist/context.d.ts.map +1 -1
- package/dist/context.js +1 -1
- package/dist/conversation-live.d.ts +21 -9
- package/dist/conversation-live.d.ts.map +1 -1
- package/dist/conversation-live.js +19 -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 +30 -12
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +273 -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 -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/expectation.d.ts +25 -14
- package/dist/expectation.d.ts.map +1 -1
- package/dist/expectation.js +51 -20
- 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 +77 -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 +23 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -7
- 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 +42 -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 +66 -22
- 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 +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 +22 -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 +21 -7
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +112 -39
- package/dist/parts.d.ts +4 -9
- package/dist/parts.d.ts.map +1 -1
- package/dist/parts.js +30 -15
- 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 +133 -73
- package/dist/query.d.ts +2 -2
- package/dist/query.d.ts.map +1 -1
- package/dist/questions.d.ts +1 -5
- package/dist/questions.d.ts.map +1 -1
- package/dist/questions.js +3 -8
- package/dist/queue.d.ts +2 -2
- package/dist/queue.d.ts.map +1 -1
- package/dist/queue.js +73 -48
- package/dist/reach.d.ts +15 -6
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +180 -39
- package/dist/react.d.ts +16 -11
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +22 -4
- 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 +31 -6
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +262 -36
- 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 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +24 -10
- 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 -4
- package/dist/runtime.d.ts.map +1 -1
- package/dist/save.d.ts +2 -0
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +105 -124
- package/dist/saves.d.ts +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/lanes.d.ts +10 -3
- package/dist/socket/lanes.d.ts.map +1 -1
- package/dist/socket/lanes.js +29 -6
- 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 +6 -4
- package/dist/socket.d.ts.map +1 -1
- package/dist/socket.js +10 -9
- package/dist/source.d.ts +18 -7
- package/dist/source.d.ts.map +1 -1
- package/dist/source.js +36 -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 +20 -8
- package/dist/surface.d.ts.map +1 -1
- package/dist/surface.js +62 -27
- 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 +41 -52
- package/dist/tables.d.ts.map +1 -1
- package/dist/tables.js +110 -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 +40 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +22 -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,110 @@ 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;
|
|
362
|
+
}
|
|
363
|
+
async function listStored(alive, local, change) {
|
|
364
|
+
const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
|
|
365
|
+
if (readUntil === null)
|
|
366
|
+
await local.fact('readUntil', new Date().toISOString());
|
|
367
|
+
const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
|
|
368
|
+
for (const entry of change.set)
|
|
369
|
+
alive.created(entry.conversation);
|
|
370
|
+
if (change.gone !== null)
|
|
371
|
+
held.delete(change.gone);
|
|
372
|
+
const list = [...held.values()];
|
|
373
|
+
const agents = [
|
|
374
|
+
...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
|
|
375
|
+
];
|
|
376
|
+
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
377
|
+
await local.fact('conversationList', list);
|
|
378
|
+
}
|
|
379
|
+
if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
|
|
380
|
+
await local.fact('agentList', agents);
|
|
381
|
+
}
|
|
382
|
+
if (change.cursor !== undefined && !alive.held.now().listRefused) {
|
|
383
|
+
if (change.cursor !== conversationCursor) {
|
|
384
|
+
await local.fact('conversationCursor', change.cursor);
|
|
385
|
+
}
|
|
386
|
+
alive.deps.stream()?.hold(change.cursor);
|
|
387
|
+
}
|
|
388
|
+
return { conversations: list, agents };
|
|
333
389
|
}
|
|
334
390
|
function listChanged(alive, change) {
|
|
335
391
|
void alive.deps
|
|
336
|
-
.durably(
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
}
|
|
344
|
-
if (change.gone !== null)
|
|
345
|
-
held.delete(change.gone);
|
|
346
|
-
const list = [...held.values()];
|
|
347
|
-
if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
|
|
348
|
-
await local.fact('conversationList', list);
|
|
349
|
-
}
|
|
350
|
-
if (change.cursor !== undefined) {
|
|
351
|
-
if (change.cursor !== conversationCursor) {
|
|
352
|
-
await local.fact('conversationCursor', change.cursor);
|
|
353
|
-
}
|
|
354
|
-
alive.deps.stream()?.hold(change.cursor);
|
|
355
|
-
}
|
|
356
|
-
return list;
|
|
392
|
+
.durably((local) => listStored(alive, local, change).catch((error) => {
|
|
393
|
+
alive.held.set({ listRefused: true });
|
|
394
|
+
throw error;
|
|
395
|
+
}))
|
|
396
|
+
.catch(async () => {
|
|
397
|
+
const { conversationList, agentList } = await (await alive.deps.local()).facts();
|
|
398
|
+
return { conversations: conversationList ?? [], agents: agentList ?? [] };
|
|
357
399
|
})
|
|
358
|
-
.
|
|
359
|
-
.then((list) => {
|
|
400
|
+
.then((listing) => {
|
|
360
401
|
if (alive.deps.closed() || change.paged === true)
|
|
361
402
|
return;
|
|
403
|
+
const list = listing.conversations;
|
|
362
404
|
endedAnew(alive, list);
|
|
363
405
|
if (change.cursor !== undefined) {
|
|
364
|
-
alive.held.set({ listKnown: true });
|
|
406
|
+
alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
|
|
365
407
|
settleBehind(alive, list);
|
|
366
408
|
openingEnded(alive);
|
|
367
409
|
alive.deps.settled();
|
|
@@ -369,11 +411,12 @@ function listChanged(alive, change) {
|
|
|
369
411
|
emitList(alive);
|
|
370
412
|
if (!alive.known())
|
|
371
413
|
return;
|
|
372
|
-
retiredDrafts(alive,
|
|
373
|
-
const { replicated } = alive.held.now();
|
|
374
|
-
if (change.cursor === undefined
|
|
375
|
-
|
|
376
|
-
list.some(({ conversation }) => !replicated.has(conversation))
|
|
414
|
+
retiredDrafts(alive, listing);
|
|
415
|
+
const { replicated, openingRead } = alive.held.now();
|
|
416
|
+
if (change.cursor === undefined
|
|
417
|
+
? list.length !== replicated.size ||
|
|
418
|
+
list.some(({ conversation }) => !replicated.has(conversation))
|
|
419
|
+
: openingRead) {
|
|
377
420
|
alive.deps.again();
|
|
378
421
|
}
|
|
379
422
|
}, uncaught);
|
|
@@ -389,16 +432,16 @@ function endedAnew(alive, list) {
|
|
|
389
432
|
emit(alive, view.conversation);
|
|
390
433
|
}
|
|
391
434
|
}
|
|
392
|
-
function
|
|
393
|
-
const reading =
|
|
435
|
+
function shownListing(alive, work) {
|
|
436
|
+
const reading = heldListing(alive);
|
|
394
437
|
alive.inOrder(async () => {
|
|
395
|
-
const
|
|
438
|
+
const listing = await reading.catch((error) => {
|
|
396
439
|
uncaught(error);
|
|
397
440
|
return null;
|
|
398
441
|
});
|
|
399
|
-
if (
|
|
442
|
+
if (listing === null || alive.deps.closed())
|
|
400
443
|
return;
|
|
401
|
-
work(
|
|
444
|
+
work(listing);
|
|
402
445
|
});
|
|
403
446
|
}
|
|
404
447
|
async function told(alive) {
|
|
@@ -443,84 +486,74 @@ export function conversationsLearned(alive) {
|
|
|
443
486
|
return;
|
|
444
487
|
if (alive.listeners.waiting())
|
|
445
488
|
tellList(alive);
|
|
446
|
-
if (!alive.agentListeners.waiting())
|
|
489
|
+
if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
|
|
447
490
|
return;
|
|
448
|
-
|
|
491
|
+
shownListing(alive, (listing) => {
|
|
492
|
+
alive.agentListeners.welcome(agentsOf(listing));
|
|
493
|
+
alive.listedListeners.welcome(structuredClone(listing.agents));
|
|
494
|
+
});
|
|
449
495
|
}
|
|
450
|
-
function
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
.
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
:
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
environment: structuredClone(held.environment),
|
|
467
|
-
};
|
|
468
|
-
})
|
|
496
|
+
function agentsOf(listing) {
|
|
497
|
+
return listing.agents
|
|
498
|
+
.filter((agent) => agent.retired_at === null)
|
|
499
|
+
.map((agent) => ({
|
|
500
|
+
identity: agent.id,
|
|
501
|
+
name: agent.name,
|
|
502
|
+
cli: agent.cli,
|
|
503
|
+
model: agent.model,
|
|
504
|
+
effort: agent.effort,
|
|
505
|
+
model_fixed: agent.model_fixed,
|
|
506
|
+
environment: {
|
|
507
|
+
identity: agent.environment,
|
|
508
|
+
name: agent.environment_name,
|
|
509
|
+
state: agent.environment_connected ? 'online' : 'offline',
|
|
510
|
+
},
|
|
511
|
+
}))
|
|
469
512
|
.sort((left, right) => left.name === right.name
|
|
470
513
|
? left.identity.localeCompare(right.identity)
|
|
471
514
|
: left.name.localeCompare(right.name));
|
|
472
515
|
}
|
|
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
516
|
function emitAgents(alive) {
|
|
497
|
-
|
|
517
|
+
const { agentListeners, listedListeners } = alive;
|
|
518
|
+
if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
|
|
498
519
|
return;
|
|
499
|
-
|
|
500
|
-
const value =
|
|
520
|
+
shownListing(alive, (listing) => {
|
|
521
|
+
const value = agentsOf(listing);
|
|
501
522
|
const shown = JSON.stringify(value);
|
|
502
|
-
if (shown
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
523
|
+
if (shown !== alive.held.now().agentsShown) {
|
|
524
|
+
alive.held.set({ agentsShown: shown });
|
|
525
|
+
agentListeners.tell(value);
|
|
526
|
+
}
|
|
527
|
+
const listed = JSON.stringify(listing.agents);
|
|
528
|
+
if (listed !== alive.held.now().listedShown) {
|
|
529
|
+
alive.held.set({ listedShown: listed });
|
|
530
|
+
listedListeners.tell(structuredClone(listing.agents));
|
|
531
|
+
}
|
|
506
532
|
});
|
|
507
533
|
}
|
|
534
|
+
function ran({ state, process }) {
|
|
535
|
+
return JSON.stringify([state?.running ?? null, process?.running ?? null]);
|
|
536
|
+
}
|
|
508
537
|
function setLive(alive, conversation, next) {
|
|
538
|
+
const was = ran(alive.liveOf(conversation));
|
|
509
539
|
const before = rowOf(alive, conversation);
|
|
510
540
|
alive.holdLive(conversation, next);
|
|
511
541
|
const after = rowOf(alive, conversation);
|
|
512
|
-
if (after.state !== before.state ||
|
|
542
|
+
if (after.state !== before.state ||
|
|
543
|
+
after.started !== before.started ||
|
|
544
|
+
ran(alive.liveOf(conversation)) !== was ||
|
|
545
|
+
after.deliveryWaiting.join() !== before.deliveryWaiting.join())
|
|
513
546
|
emitList(alive);
|
|
514
547
|
else if (after.line !== before.line ||
|
|
515
548
|
after.question !== before.question ||
|
|
516
549
|
after.asked !== before.asked)
|
|
517
550
|
tellSoon(alive);
|
|
518
551
|
}
|
|
519
|
-
function retiredChat(conversation,
|
|
552
|
+
function retiredChat(conversation, listing) {
|
|
520
553
|
if (!conversation.startsWith(NEW_CHAT))
|
|
521
554
|
return false;
|
|
522
555
|
const agent = conversation.slice(NEW_CHAT.length);
|
|
523
|
-
return
|
|
556
|
+
return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
|
|
524
557
|
}
|
|
525
558
|
function live(alive, conversation, change) {
|
|
526
559
|
alive.factsHeard(conversation, FACTS.filter((one) => one in change));
|
|
@@ -540,7 +573,6 @@ function openingEnded(alive) {
|
|
|
540
573
|
options: facts.has('options') ? QUIET.options : held.options,
|
|
541
574
|
starting: facts.has('starting') ? QUIET.starting : held.starting,
|
|
542
575
|
state: facts.has('state') ? QUIET.state : held.state,
|
|
543
|
-
link: facts.has('link') ? QUIET.link : held.link,
|
|
544
576
|
deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
|
|
545
577
|
deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
|
|
546
578
|
});
|
|
@@ -573,19 +605,13 @@ function handReplicated(alive) {
|
|
|
573
605
|
}
|
|
574
606
|
async function remove(alive, leaving) {
|
|
575
607
|
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);
|
|
608
|
+
const kept = new Set(await local.dropConversations(leaving));
|
|
583
609
|
const changed = [];
|
|
584
610
|
for (const conversation of leaving) {
|
|
585
611
|
if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
|
|
586
612
|
changed.push(conversation);
|
|
587
613
|
}
|
|
588
|
-
|
|
614
|
+
heldInViews(alive, conversation, { draft: null, dismissed: null });
|
|
589
615
|
alive.forget(conversation);
|
|
590
616
|
setLive(alive, conversation, null);
|
|
591
617
|
await slide(alive, local, conversation, null);
|
|
@@ -614,7 +640,7 @@ async function readsOf(local, conversations) {
|
|
|
614
640
|
return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
|
|
615
641
|
}
|
|
616
642
|
function retiredDrafts(alive, list) {
|
|
617
|
-
if (!list.some((
|
|
643
|
+
if (!list.agents.some((agent) => agent.retired_at !== null))
|
|
618
644
|
return;
|
|
619
645
|
void alive.deps
|
|
620
646
|
.local()
|
|
@@ -778,10 +804,6 @@ function heard(alive, event) {
|
|
|
778
804
|
live(alive, conversation, { state: structuredClone(event.state) });
|
|
779
805
|
return;
|
|
780
806
|
}
|
|
781
|
-
if (event.kind === 'link') {
|
|
782
|
-
live(alive, conversation, { link: { connected: event.connected } });
|
|
783
|
-
return;
|
|
784
|
-
}
|
|
785
807
|
if (event.kind === 'deliveries') {
|
|
786
808
|
live(alive, conversation, {
|
|
787
809
|
deliveryWaiting: [...event.waiting],
|
|
@@ -810,19 +832,27 @@ function heard(alive, event) {
|
|
|
810
832
|
emit(alive, conversation);
|
|
811
833
|
}
|
|
812
834
|
async function kept(alive, local, conversation, following) {
|
|
813
|
-
const
|
|
814
|
-
if (
|
|
835
|
+
const draft = following === null || empty(following) ? null : following;
|
|
836
|
+
if (draft === null)
|
|
815
837
|
await local.dropChatDraft(conversation);
|
|
816
838
|
else
|
|
817
|
-
await local.keepChatDrafts([
|
|
818
|
-
|
|
839
|
+
await local.keepChatDrafts([draft]);
|
|
840
|
+
heldInViews(alive, conversation, { draft });
|
|
819
841
|
}
|
|
820
|
-
function
|
|
842
|
+
function heldInViews(alive, conversation, held) {
|
|
821
843
|
for (const view of alive.views()) {
|
|
822
844
|
if (view.conversation === conversation)
|
|
823
|
-
view.held.set(
|
|
845
|
+
view.held.set(held);
|
|
824
846
|
}
|
|
825
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
|
+
}
|
|
853
|
+
async function dismissedIn(local, conversation) {
|
|
854
|
+
return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
|
|
855
|
+
}
|
|
826
856
|
async function draftAt(local, conversation) {
|
|
827
857
|
return (await local.chatDraft(conversation)) ?? undefined;
|
|
828
858
|
}
|
|
@@ -853,9 +883,9 @@ function moved(alive, agent, operation, to) {
|
|
|
853
883
|
: [{ ...unsent, conversation: to }];
|
|
854
884
|
const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
|
|
855
885
|
await local.keepChatDrafts([left, ...taken]);
|
|
856
|
-
|
|
886
|
+
heldInViews(alive, from, { draft: left });
|
|
857
887
|
for (const one of taken)
|
|
858
|
-
|
|
888
|
+
heldInViews(alive, to, { draft: one });
|
|
859
889
|
alive.deps.publish(conversationChangeSet([from, to]));
|
|
860
890
|
});
|
|
861
891
|
}
|
|
@@ -886,7 +916,7 @@ async function submitted(alive, conversation, operation, draft) {
|
|
|
886
916
|
});
|
|
887
917
|
return submission;
|
|
888
918
|
}
|
|
889
|
-
async function dispatched(alive, conversation, submission) {
|
|
919
|
+
async function dispatched(alive, conversation, submission, resent = false) {
|
|
890
920
|
const dispatch = alive.sendingBegan(submission.operation);
|
|
891
921
|
try {
|
|
892
922
|
const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
|
|
@@ -897,6 +927,7 @@ async function dispatched(alive, conversation, submission) {
|
|
|
897
927
|
alive.deps.unanswered();
|
|
898
928
|
return result;
|
|
899
929
|
}
|
|
930
|
+
alive.deps.heard(submission.operation, resent);
|
|
900
931
|
const turn = answered(result, 'message_id');
|
|
901
932
|
await withDraft(alive, conversation, async (current, local) => {
|
|
902
933
|
const held = current?.submitted?.find((one) => one.operation === submission.operation);
|
|
@@ -919,8 +950,9 @@ async function dispatched(alive, conversation, submission) {
|
|
|
919
950
|
function invoke(alive, name, conversation, operation, extra = {}, attempt) {
|
|
920
951
|
return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
|
|
921
952
|
}
|
|
922
|
-
export function conversationSurface(alive) {
|
|
953
|
+
export function conversationSurface(alive, files) {
|
|
923
954
|
return {
|
|
955
|
+
...files,
|
|
924
956
|
list() {
|
|
925
957
|
return new Promise((settle) => {
|
|
926
958
|
const answer = (listed) => {
|
|
@@ -938,7 +970,12 @@ export function conversationSurface(alive) {
|
|
|
938
970
|
return alive.deps.durably(async (local) => {
|
|
939
971
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
|
|
940
972
|
const total = asked.total ? await local.messageCount(conversation, phrase) : null;
|
|
941
|
-
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
|
+
}));
|
|
942
979
|
});
|
|
943
980
|
},
|
|
944
981
|
async create(input) {
|
|
@@ -946,7 +983,7 @@ export function conversationSurface(alive) {
|
|
|
946
983
|
const conversation = answered(result, 'conversation_id');
|
|
947
984
|
if (conversation === null)
|
|
948
985
|
return result;
|
|
949
|
-
const listed = (await
|
|
986
|
+
const listed = (await heldListing(alive))?.conversations ?? [];
|
|
950
987
|
if (!listed.some((entry) => entry.conversation === conversation)) {
|
|
951
988
|
alive.creating(conversation);
|
|
952
989
|
}
|
|
@@ -1004,48 +1041,61 @@ export function conversationSurface(alive) {
|
|
|
1004
1041
|
rename(conversation, name, operation) {
|
|
1005
1042
|
return invoke(alive, 'conversations/rename', conversation, operation, { name });
|
|
1006
1043
|
},
|
|
1007
|
-
|
|
1008
|
-
return invoke(alive, 'conversations/
|
|
1044
|
+
set(conversation, settings, operation) {
|
|
1045
|
+
return invoke(alive, 'conversations/set', conversation, operation, settings);
|
|
1009
1046
|
},
|
|
1010
1047
|
retry(conversation, message, operation) {
|
|
1011
1048
|
return invoke(alive, 'conversations/retry', conversation, operation, {
|
|
1012
1049
|
message_id: message,
|
|
1013
1050
|
});
|
|
1014
1051
|
},
|
|
1015
|
-
async
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
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
|
+
}
|
|
1020
1061
|
},
|
|
1021
|
-
async
|
|
1022
|
-
|
|
1062
|
+
async openTurn(conversation, turn) {
|
|
1063
|
+
await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
|
|
1064
|
+
tellList(alive);
|
|
1023
1065
|
},
|
|
1024
|
-
|
|
1066
|
+
dismissSuggestion(conversation, suggestion) {
|
|
1025
1067
|
return alive.deps.durably(async (local) => {
|
|
1026
|
-
|
|
1027
|
-
|
|
1068
|
+
if ((await dismissedIn(local, conversation)) === suggestion)
|
|
1069
|
+
return;
|
|
1070
|
+
await local.keepConversationFact({
|
|
1071
|
+
conversation,
|
|
1072
|
+
name: 'dismissedSuggestion',
|
|
1073
|
+
value: suggestion,
|
|
1074
|
+
});
|
|
1075
|
+
heldInViews(alive, conversation, { dismissed: suggestion });
|
|
1076
|
+
alive.deps.publish(conversationChangeSet([conversation]));
|
|
1028
1077
|
});
|
|
1029
1078
|
},
|
|
1030
1079
|
};
|
|
1031
1080
|
}
|
|
1081
|
+
function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
|
|
1082
|
+
return withDraft(alive, conversation, (current) => ({
|
|
1083
|
+
conversation,
|
|
1084
|
+
text: text(current?.text ?? ''),
|
|
1085
|
+
revision,
|
|
1086
|
+
...(current === undefined ? {} : pending(current)),
|
|
1087
|
+
}));
|
|
1088
|
+
}
|
|
1032
1089
|
export function chatDraftSurface(alive) {
|
|
1033
1090
|
return {
|
|
1034
|
-
write(conversation, draft, revision
|
|
1035
|
-
return
|
|
1036
|
-
conversation,
|
|
1037
|
-
text: draft.text,
|
|
1038
|
-
revision,
|
|
1039
|
-
...(current === undefined ? {} : pending(current)),
|
|
1040
|
-
}));
|
|
1091
|
+
write(conversation, draft, revision) {
|
|
1092
|
+
return rewritten(alive, conversation, () => draft.text, revision);
|
|
1041
1093
|
},
|
|
1042
1094
|
prepend(conversation, draft) {
|
|
1043
|
-
return
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
...(current === undefined ? {} : pending(current)),
|
|
1048
|
-
}));
|
|
1095
|
+
return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
|
|
1096
|
+
},
|
|
1097
|
+
append(conversation, draft) {
|
|
1098
|
+
return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
|
|
1049
1099
|
},
|
|
1050
1100
|
discard(conversation) {
|
|
1051
1101
|
return withDraft(alive, conversation, (current) => current === undefined
|
|
@@ -1055,31 +1105,37 @@ export function chatDraftSurface(alive) {
|
|
|
1055
1105
|
};
|
|
1056
1106
|
}
|
|
1057
1107
|
export async function conversationsOpened(alive, local) {
|
|
1058
|
-
const { conversationList, conversationCursor } = await local.facts();
|
|
1059
|
-
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())
|
|
1060
1113
|
return;
|
|
1061
1114
|
alive.deps.stream()?.hold(conversationCursor);
|
|
1062
1115
|
conversationsLearned(alive);
|
|
1063
1116
|
}
|
|
1117
|
+
export function reconcileOpening(alive) {
|
|
1118
|
+
alive.held.set({ openingRead: true });
|
|
1119
|
+
return reconcileConversations(alive);
|
|
1120
|
+
}
|
|
1064
1121
|
export async function reconcileConversations(alive) {
|
|
1065
1122
|
if (!alive.known())
|
|
1066
1123
|
return;
|
|
1067
1124
|
const local = await alive.deps.local();
|
|
1068
|
-
const [held,
|
|
1125
|
+
const [held, stored, { conversationList, agentList }] = await Promise.all([
|
|
1069
1126
|
local.conversations(),
|
|
1070
|
-
local.
|
|
1127
|
+
local.storedConversations(),
|
|
1071
1128
|
local.facts(),
|
|
1072
1129
|
]);
|
|
1073
1130
|
const list = conversationList ?? [];
|
|
1131
|
+
const listing = { conversations: list, agents: agentList ?? [] };
|
|
1074
1132
|
const entries = new Map(list.map((entry) => [entry.conversation, entry]));
|
|
1075
1133
|
const named = new Set(entries.keys());
|
|
1076
1134
|
const reads = new Map(held.map((one) => [one.conversation, one]));
|
|
1077
1135
|
const { replicated } = alive.held.now();
|
|
1078
|
-
const leaving = [
|
|
1079
|
-
...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
|
|
1080
|
-
].filter((conversation) => !named.has(conversation) &&
|
|
1136
|
+
const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
|
|
1081
1137
|
!alive.isCreating(conversation) &&
|
|
1082
|
-
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation,
|
|
1138
|
+
(!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
|
|
1083
1139
|
for (const conversation of named) {
|
|
1084
1140
|
if (!replicated.has(conversation) &&
|
|
1085
1141
|
missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
|
|
@@ -1114,6 +1170,17 @@ export async function catchUpConversations(alive, progress) {
|
|
|
1114
1170
|
if (!alive.current())
|
|
1115
1171
|
progress.complete = false;
|
|
1116
1172
|
}
|
|
1173
|
+
export async function holdsSubmission(alive, operation) {
|
|
1174
|
+
if (alive.sending(operation))
|
|
1175
|
+
return true;
|
|
1176
|
+
const local = await alive.deps.local();
|
|
1177
|
+
for (const { conversation } of await local.chatDrafts()) {
|
|
1178
|
+
const held = (await local.chatDraft(conversation))?.submitted;
|
|
1179
|
+
if (held?.some((one) => one.operation === operation && one.turn === null) === true)
|
|
1180
|
+
return true;
|
|
1181
|
+
}
|
|
1182
|
+
return false;
|
|
1183
|
+
}
|
|
1117
1184
|
export async function resendConversations(alive, progress) {
|
|
1118
1185
|
const local = await alive.deps.local();
|
|
1119
1186
|
const tried = new Set();
|
|
@@ -1125,7 +1192,7 @@ export async function resendConversations(alive, progress) {
|
|
|
1125
1192
|
if (alive.deps.closed())
|
|
1126
1193
|
return;
|
|
1127
1194
|
tried.add(submission.operation);
|
|
1128
|
-
const result = await dispatched(alive, conversation, submission);
|
|
1195
|
+
const result = await dispatched(alive, conversation, submission, true);
|
|
1129
1196
|
if (result.kind === 'revoked-authorization')
|
|
1130
1197
|
return;
|
|
1131
1198
|
if (result.kind === 'transport-uncertainty') {
|
|
@@ -1151,6 +1218,8 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1151
1218
|
const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
|
|
1152
1219
|
held.set({ draft: (await local.chatDraft(conversation)) ?? null });
|
|
1153
1220
|
held.set({ ended: await endedIn(alive, conversation) });
|
|
1221
|
+
held.set({ dismissed: await dismissedIn(local, conversation) });
|
|
1222
|
+
held.set({ pins: (await local.facts()).chatPins });
|
|
1154
1223
|
held.set({ window: messages });
|
|
1155
1224
|
held.set({ more });
|
|
1156
1225
|
held.set({ total: asked.total ? await local.messageCount(conversation) : null });
|
|
@@ -1158,9 +1227,10 @@ export function watchConversation(alive, conversation, options, deliver) {
|
|
|
1158
1227
|
.then(() => {
|
|
1159
1228
|
if (alive.deps.closed() || !view.admit(watcher))
|
|
1160
1229
|
return;
|
|
1161
|
-
const
|
|
1162
|
-
const shown = window ?? [];
|
|
1163
|
-
|
|
1230
|
+
const now = held.now();
|
|
1231
|
+
const shown = now.window ?? [];
|
|
1232
|
+
const frame = sharedFrame(view, shown);
|
|
1233
|
+
watcher.notify(viewOf(alive, conversation, shown, frame, now));
|
|
1164
1234
|
})
|
|
1165
1235
|
.catch(() => { });
|
|
1166
1236
|
return () => {
|
|
@@ -1176,9 +1246,13 @@ export function watchConversationList(alive, deliver) {
|
|
|
1176
1246
|
export function watchConversationAgents(alive, deliver) {
|
|
1177
1247
|
alive.agentListeners.join(deliver);
|
|
1178
1248
|
conversationsLearned(alive);
|
|
1179
|
-
readAgents(alive);
|
|
1180
1249
|
return () => alive.agentListeners.leave(deliver);
|
|
1181
1250
|
}
|
|
1251
|
+
export function watchListedAgents(alive, deliver) {
|
|
1252
|
+
alive.listedListeners.join(deliver);
|
|
1253
|
+
conversationsLearned(alive);
|
|
1254
|
+
return () => alive.listedListeners.leave(deliver);
|
|
1255
|
+
}
|
|
1182
1256
|
export function conversationsChanged(alive, set) {
|
|
1183
1257
|
for (const conversation of set.conversations)
|
|
1184
1258
|
emit(alive, conversation);
|
|
@@ -1190,26 +1264,32 @@ export function receiveConversationEvent(alive, event) {
|
|
|
1190
1264
|
if (event.whole)
|
|
1191
1265
|
alive.relistBegun();
|
|
1192
1266
|
if (alive.relisting())
|
|
1193
|
-
alive.relistHeard(event.entries);
|
|
1267
|
+
alive.relistHeard(event.entries, event.agents);
|
|
1194
1268
|
if (event.more && alive.relisting())
|
|
1195
1269
|
return;
|
|
1196
1270
|
const whole = alive.relistTaken();
|
|
1197
1271
|
listChanged(alive, {
|
|
1198
1272
|
replacing: whole !== null,
|
|
1199
|
-
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()],
|
|
1200
1275
|
gone: null,
|
|
1201
1276
|
...(event.more ? { paged: true } : { cursor: event.cursor }),
|
|
1202
1277
|
});
|
|
1203
1278
|
return;
|
|
1204
1279
|
}
|
|
1205
1280
|
if (event.kind === 'listed') {
|
|
1206
|
-
alive.relistHeard([event.entry]);
|
|
1207
|
-
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 });
|
|
1208
1288
|
return;
|
|
1209
1289
|
}
|
|
1210
1290
|
if (event.kind === 'unlisted') {
|
|
1211
1291
|
alive.relistDropped(event.conversation);
|
|
1212
|
-
listChanged(alive, { replacing: false, set: [], gone: event.conversation });
|
|
1292
|
+
listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
|
|
1213
1293
|
return;
|
|
1214
1294
|
}
|
|
1215
1295
|
heard(alive, event);
|