@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.
Files changed (283) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +32 -22
  4. package/dist/act-lanes.d.ts +11 -14
  5. package/dist/act-lanes.d.ts.map +1 -1
  6. package/dist/act-lanes.js +53 -5
  7. package/dist/actions.d.ts +1 -0
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +135 -55
  10. package/dist/adapter.d.ts +168 -29
  11. package/dist/adapter.d.ts.map +1 -1
  12. package/dist/attached-model.d.ts +0 -1
  13. package/dist/attached-model.d.ts.map +1 -1
  14. package/dist/attached-model.js +2 -7
  15. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  16. package/dist/attachment.d.ts.map +1 -0
  17. package/dist/attachment.js +15 -0
  18. package/dist/authored.d.ts +88 -0
  19. package/dist/authored.d.ts.map +1 -0
  20. package/dist/authored.js +347 -0
  21. package/dist/chain.d.ts +1 -1
  22. package/dist/chain.d.ts.map +1 -1
  23. package/dist/chain.js +5 -2
  24. package/dist/change.d.ts +6 -2
  25. package/dist/change.d.ts.map +1 -1
  26. package/dist/change.js +3 -0
  27. package/dist/chat-types.d.ts +0 -2
  28. package/dist/chat-types.d.ts.map +1 -1
  29. package/dist/chat-types.js +2 -4
  30. package/dist/client.d.ts +27 -15
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +29 -57
  33. package/dist/collection.d.ts +6 -1
  34. package/dist/collection.d.ts.map +1 -1
  35. package/dist/collection.js +23 -9
  36. package/dist/column.d.ts +5 -0
  37. package/dist/column.d.ts.map +1 -0
  38. package/dist/column.js +9 -0
  39. package/dist/compile.d.ts +4 -1
  40. package/dist/compile.d.ts.map +1 -1
  41. package/dist/compile.js +88 -44
  42. package/dist/connection.d.ts +1 -1
  43. package/dist/connection.d.ts.map +1 -1
  44. package/dist/connection.js +15 -14
  45. package/dist/context.d.ts.map +1 -1
  46. package/dist/context.js +1 -1
  47. package/dist/conversation-live.d.ts +21 -9
  48. package/dist/conversation-live.d.ts.map +1 -1
  49. package/dist/conversation-live.js +19 -8
  50. package/dist/conversation-row.d.ts +20 -1
  51. package/dist/conversation-row.d.ts.map +1 -1
  52. package/dist/conversation-row.js +30 -7
  53. package/dist/conversation.d.ts +30 -12
  54. package/dist/conversation.d.ts.map +1 -1
  55. package/dist/conversation.js +273 -193
  56. package/dist/declaration.js +3 -3
  57. package/dist/discovery.d.ts +3 -1
  58. package/dist/discovery.d.ts.map +1 -1
  59. package/dist/discovery.js +30 -8
  60. package/dist/download.d.ts +6 -0
  61. package/dist/download.d.ts.map +1 -0
  62. package/dist/download.js +42 -0
  63. package/dist/durability.d.ts +2 -0
  64. package/dist/durability.d.ts.map +1 -1
  65. package/dist/durability.js +7 -0
  66. package/dist/entry.d.ts +25 -1
  67. package/dist/entry.d.ts.map +1 -1
  68. package/dist/entry.js +111 -34
  69. package/dist/expectation.d.ts +25 -14
  70. package/dist/expectation.d.ts.map +1 -1
  71. package/dist/expectation.js +51 -20
  72. package/dist/failure.d.ts.map +1 -1
  73. package/dist/failure.js +3 -1
  74. package/dist/figures.d.ts +1 -1
  75. package/dist/figures.d.ts.map +1 -1
  76. package/dist/figures.js +6 -4
  77. package/dist/file.d.ts +1 -1
  78. package/dist/file.d.ts.map +1 -1
  79. package/dist/file.js +3 -2
  80. package/dist/host.d.ts +7 -2
  81. package/dist/host.d.ts.map +1 -1
  82. package/dist/host.js +77 -31
  83. package/dist/house-query.d.ts +24 -0
  84. package/dist/house-query.d.ts.map +1 -0
  85. package/dist/house-query.js +102 -0
  86. package/dist/identity.d.ts +1 -1
  87. package/dist/identity.d.ts.map +1 -1
  88. package/dist/identity.js +1 -1
  89. package/dist/index.d.ts +23 -14
  90. package/dist/index.d.ts.map +1 -1
  91. package/dist/index.js +13 -7
  92. package/dist/install.d.ts +9 -3
  93. package/dist/install.d.ts.map +1 -1
  94. package/dist/install.js +44 -46
  95. package/dist/lifecycle.d.ts +1 -1
  96. package/dist/lifecycle.d.ts.map +1 -1
  97. package/dist/lifecycle.js +42 -29
  98. package/dist/listing.d.ts +24 -12
  99. package/dist/listing.d.ts.map +1 -1
  100. package/dist/listing.js +50 -21
  101. package/dist/live.d.ts +19 -3
  102. package/dist/live.d.ts.map +1 -1
  103. package/dist/live.js +94 -36
  104. package/dist/loaded.d.ts +7 -0
  105. package/dist/loaded.d.ts.map +1 -0
  106. package/dist/loaded.js +46 -0
  107. package/dist/locks.d.ts.map +1 -1
  108. package/dist/locks.js +4 -3
  109. package/dist/lost.d.ts.map +1 -1
  110. package/dist/lost.js +2 -3
  111. package/dist/media.d.ts +19 -3
  112. package/dist/media.d.ts.map +1 -1
  113. package/dist/media.js +181 -34
  114. package/dist/memory.d.ts +7 -3
  115. package/dist/memory.d.ts.map +1 -1
  116. package/dist/memory.js +66 -22
  117. package/dist/messages.d.ts +21 -3
  118. package/dist/messages.d.ts.map +1 -1
  119. package/dist/messages.js +43 -13
  120. package/dist/modal.d.ts +2 -0
  121. package/dist/modal.d.ts.map +1 -0
  122. package/dist/modal.js +11 -0
  123. package/dist/model.d.ts +10 -7
  124. package/dist/model.d.ts.map +1 -1
  125. package/dist/model.js +7 -1
  126. package/dist/models.d.ts.map +1 -1
  127. package/dist/models.js +5 -8
  128. package/dist/name.d.ts +0 -1
  129. package/dist/name.d.ts.map +1 -1
  130. package/dist/name.js +3 -7
  131. package/dist/observation.d.ts +29 -12
  132. package/dist/observation.d.ts.map +1 -1
  133. package/dist/observation.js +206 -69
  134. package/dist/online.d.ts +7 -0
  135. package/dist/online.d.ts.map +1 -0
  136. package/dist/online.js +29 -0
  137. package/dist/opened.d.ts +5 -5
  138. package/dist/opened.d.ts.map +1 -1
  139. package/dist/opened.js +2 -2
  140. package/dist/opening.d.ts.map +1 -1
  141. package/dist/opening.js +22 -10
  142. package/dist/outcome.d.ts +30 -13
  143. package/dist/outcome.d.ts.map +1 -1
  144. package/dist/outcome.js +21 -6
  145. package/dist/overlay.d.ts +21 -7
  146. package/dist/overlay.d.ts.map +1 -1
  147. package/dist/overlay.js +112 -39
  148. package/dist/parts.d.ts +4 -9
  149. package/dist/parts.d.ts.map +1 -1
  150. package/dist/parts.js +30 -15
  151. package/dist/paths.d.ts +1 -1
  152. package/dist/paths.js +1 -1
  153. package/dist/preparation.d.ts +33 -7
  154. package/dist/preparation.d.ts.map +1 -1
  155. package/dist/preparation.js +198 -87
  156. package/dist/presence.d.ts +8 -2
  157. package/dist/presence.d.ts.map +1 -1
  158. package/dist/presence.js +24 -13
  159. package/dist/queries.d.ts +1 -1
  160. package/dist/queries.d.ts.map +1 -1
  161. package/dist/queries.js +133 -73
  162. package/dist/query.d.ts +2 -2
  163. package/dist/query.d.ts.map +1 -1
  164. package/dist/questions.d.ts +1 -5
  165. package/dist/questions.d.ts.map +1 -1
  166. package/dist/questions.js +3 -8
  167. package/dist/queue.d.ts +2 -2
  168. package/dist/queue.d.ts.map +1 -1
  169. package/dist/queue.js +73 -48
  170. package/dist/reach.d.ts +15 -6
  171. package/dist/reach.d.ts.map +1 -1
  172. package/dist/reach.js +180 -39
  173. package/dist/react.d.ts +16 -11
  174. package/dist/react.d.ts.map +1 -1
  175. package/dist/react.js +22 -4
  176. package/dist/readiness.d.ts +23 -4
  177. package/dist/readiness.d.ts.map +1 -1
  178. package/dist/readiness.js +18 -10
  179. package/dist/reads.d.ts +1 -1
  180. package/dist/reads.d.ts.map +1 -1
  181. package/dist/reads.js +17 -6
  182. package/dist/recovery.d.ts +1 -0
  183. package/dist/recovery.d.ts.map +1 -1
  184. package/dist/recovery.js +2 -1
  185. package/dist/reference-forms.d.ts +4 -0
  186. package/dist/reference-forms.d.ts.map +1 -0
  187. package/dist/reference-forms.js +74 -0
  188. package/dist/refresh.d.ts +1 -1
  189. package/dist/refresh.js +4 -4
  190. package/dist/refusal.d.ts.map +1 -1
  191. package/dist/refusal.js +1 -3
  192. package/dist/replica.d.ts +3 -8
  193. package/dist/replica.d.ts.map +1 -1
  194. package/dist/replica.js +5 -5
  195. package/dist/room-draft.d.ts +31 -6
  196. package/dist/room-draft.d.ts.map +1 -1
  197. package/dist/room-draft.js +262 -36
  198. package/dist/room-drafts.d.ts.map +1 -1
  199. package/dist/room-drafts.js +12 -7
  200. package/dist/room-list.d.ts +10 -0
  201. package/dist/room-list.d.ts.map +1 -0
  202. package/dist/room-list.js +47 -0
  203. package/dist/rows.d.ts +11 -2
  204. package/dist/rows.d.ts.map +1 -1
  205. package/dist/rows.js +24 -10
  206. package/dist/run-tables.d.ts +25 -0
  207. package/dist/run-tables.d.ts.map +1 -0
  208. package/dist/run-tables.js +98 -0
  209. package/dist/running.d.ts +5 -0
  210. package/dist/running.d.ts.map +1 -0
  211. package/dist/running.js +10 -0
  212. package/dist/runs.d.ts +27 -0
  213. package/dist/runs.d.ts.map +1 -0
  214. package/dist/runs.js +92 -0
  215. package/dist/runtime.d.ts +5 -4
  216. package/dist/runtime.d.ts.map +1 -1
  217. package/dist/save.d.ts +2 -0
  218. package/dist/save.d.ts.map +1 -1
  219. package/dist/save.js +105 -124
  220. package/dist/saves.d.ts +7 -5
  221. package/dist/saves.d.ts.map +1 -1
  222. package/dist/saves.js +107 -57
  223. package/dist/seed.d.ts.map +1 -1
  224. package/dist/seed.js +2 -2
  225. package/dist/selector.d.ts +3 -0
  226. package/dist/selector.d.ts.map +1 -0
  227. package/dist/selector.js +22 -0
  228. package/dist/shown.d.ts +5 -2
  229. package/dist/shown.d.ts.map +1 -1
  230. package/dist/shown.js +79 -43
  231. package/dist/socket/lanes.d.ts +10 -3
  232. package/dist/socket/lanes.d.ts.map +1 -1
  233. package/dist/socket/lanes.js +29 -6
  234. package/dist/socket/session.d.ts +4 -1
  235. package/dist/socket/session.d.ts.map +1 -1
  236. package/dist/socket/session.js +3 -0
  237. package/dist/socket.d.ts +6 -4
  238. package/dist/socket.d.ts.map +1 -1
  239. package/dist/socket.js +10 -9
  240. package/dist/source.d.ts +18 -7
  241. package/dist/source.d.ts.map +1 -1
  242. package/dist/source.js +36 -2
  243. package/dist/store/installs.d.ts +2 -2
  244. package/dist/store/installs.d.ts.map +1 -1
  245. package/dist/store/installs.js +10 -4
  246. package/dist/store/readiness.d.ts +5 -4
  247. package/dist/store/readiness.d.ts.map +1 -1
  248. package/dist/store/readiness.js +28 -12
  249. package/dist/store/records.d.ts +30 -8
  250. package/dist/store/records.d.ts.map +1 -1
  251. package/dist/store/records.js +70 -26
  252. package/dist/store/rooms-shown.d.ts +8 -0
  253. package/dist/store/rooms-shown.d.ts.map +1 -0
  254. package/dist/store/rooms-shown.js +13 -0
  255. package/dist/store.d.ts +15 -10
  256. package/dist/store.d.ts.map +1 -1
  257. package/dist/store.js +12 -5
  258. package/dist/stored.d.ts +41 -16
  259. package/dist/stored.d.ts.map +1 -1
  260. package/dist/stored.js +215 -57
  261. package/dist/surface.d.ts +20 -8
  262. package/dist/surface.d.ts.map +1 -1
  263. package/dist/surface.js +62 -27
  264. package/dist/sync.d.ts +4 -2
  265. package/dist/sync.d.ts.map +1 -1
  266. package/dist/sync.js +52 -35
  267. package/dist/tables.d.ts +41 -52
  268. package/dist/tables.d.ts.map +1 -1
  269. package/dist/tables.js +110 -326
  270. package/dist/tallies.d.ts.map +1 -1
  271. package/dist/tallies.js +3 -4
  272. package/dist/validation.d.ts +2 -0
  273. package/dist/validation.d.ts.map +1 -1
  274. package/dist/validation.js +50 -10
  275. package/dist/wire.d.ts +40 -16
  276. package/dist/wire.d.ts.map +1 -1
  277. package/dist/wire.js +22 -14
  278. package/package.json +4 -4
  279. package/dist/binary.d.ts.map +0 -1
  280. package/dist/binary.js +0 -8
  281. package/dist/log.d.ts +0 -6
  282. package/dist/log.d.ts.map +0 -1
  283. package/dist/log.js +0 -14
@@ -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 prepended(draft, said) {
202
- return { text: [said.text, draft.text].filter((one) => one !== '').join('\n') };
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
- ...prepended(draft, submission),
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 sessionOf(facts, held, ended) {
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
- if (saved === undefined || !isTurn(saved.content) || at === null)
245
- return null;
246
- const down = facts.process?.running === false;
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 { window, draft, ended } = view.held.now();
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 value = viewOf(alive, conversation, window, sharedFrame(view, window), draft, ended);
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 list = await heldList(alive);
306
- if (list === null)
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
- conversation: entry.conversation,
314
- agent: { identity: entry.agent, name: entry.agentName, retired: entry.agentRetired },
315
- name: entry.name,
316
- created: entry.created,
317
- finished: entry.finished,
318
- outcome: entry.outcome,
319
- waiting: entry.waiting,
320
- ...rowOf(alive, entry.conversation),
321
- ...heldFacts(rows.get(entry.conversation), entry),
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 heldList(alive) {
325
- const stored = (await (await alive.deps.local()).facts()).conversationList;
326
- if (stored !== null)
327
- return stored;
328
- return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online() ? null : [];
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 list = await heldList(alive);
332
- return list?.find((entry) => entry.conversation === conversation)?.processEnded ?? null;
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(async (local) => {
337
- const { conversationList, conversationCursor } = await local.facts();
338
- const kept = change.replacing ? [] : (conversationList ?? []);
339
- const held = new Map(kept.map((entry) => [entry.conversation, entry]));
340
- for (const entry of change.set) {
341
- held.set(entry.conversation, { ...entry });
342
- alive.created(entry.conversation);
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
- .catch(async () => (await (await alive.deps.local()).facts()).conversationList ?? [])
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, list);
373
- const { replicated } = alive.held.now();
374
- if (change.cursor === undefined &&
375
- (list.length !== replicated.size ||
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 shownList(alive, work) {
393
- const reading = heldList(alive);
435
+ function shownListing(alive, work) {
436
+ const reading = heldListing(alive);
394
437
  alive.inOrder(async () => {
395
- const list = await reading.catch((error) => {
438
+ const listing = await reading.catch((error) => {
396
439
  uncaught(error);
397
440
  return null;
398
441
  });
399
- if (list === null || alive.deps.closed())
442
+ if (listing === null || alive.deps.closed())
400
443
  return;
401
- work(list);
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
- shownList(alive, (list) => alive.agentListeners.welcome(agents(alive, list)));
491
+ shownListing(alive, (listing) => {
492
+ alive.agentListeners.welcome(agentsOf(listing));
493
+ alive.listedListeners.welcome(structuredClone(listing.agents));
494
+ });
449
495
  }
450
- function agents(alive, list) {
451
- const read = new Map((alive.held.now().listedAgents ?? []).map((one) => [one.agent, one]));
452
- const named = new Map(read);
453
- for (const entry of list) {
454
- named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
455
- }
456
- return [...named]
457
- .filter(([, agent]) => !agent.retired)
458
- .map(([identity, agent]) => {
459
- const held = read.get(identity);
460
- return held === undefined
461
- ? { identity, name: agent.name }
462
- : {
463
- identity,
464
- name: agent.name,
465
- cli: held.cli,
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
- if (alive.deps.closed() || !alive.agentListeners.told())
517
+ const { agentListeners, listedListeners } = alive;
518
+ if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
498
519
  return;
499
- shownList(alive, (list) => {
500
- const value = agents(alive, list);
520
+ shownListing(alive, (listing) => {
521
+ const value = agentsOf(listing);
501
522
  const shown = JSON.stringify(value);
502
- if (shown === alive.held.now().agentsShown)
503
- return;
504
- alive.held.set({ agentsShown: shown });
505
- alive.agentListeners.tell(value);
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 || after.started !== before.started)
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, list) {
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 list.some((entry) => entry.agent === agent && entry.agentRetired);
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
- shownDraft(alive, conversation, null);
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((entry) => entry.agentRetired))
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 shown = following === null || empty(following) ? null : following;
814
- if (shown === null)
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([shown]);
818
- shownDraft(alive, conversation, shown);
839
+ await local.keepChatDrafts([draft]);
840
+ heldInViews(alive, conversation, { draft });
819
841
  }
820
- function shownDraft(alive, conversation, draft) {
842
+ function heldInViews(alive, conversation, held) {
821
843
  for (const view of alive.views()) {
822
844
  if (view.conversation === conversation)
823
- view.held.set({ draft });
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
- shownDraft(alive, from, left);
886
+ heldInViews(alive, from, { draft: left });
857
887
  for (const one of taken)
858
- shownDraft(alive, to, one);
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), (await local.chatDraft(conversation)) ?? null, await endedIn(alive, conversation)));
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 heldList(alive)) ?? [];
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
- option(conversation, option, value, operation) {
1008
- return invoke(alive, 'conversations/option/set', conversation, operation, { option, value });
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 pins() {
1016
- return (await (await alive.deps.local()).facts()).chatPins;
1017
- },
1018
- pin(figures) {
1019
- return alive.deps.durably((local) => local.fact('chatPins', [...figures]));
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 openedTurns() {
1022
- return (await (await alive.deps.local()).facts()).openedTurns;
1062
+ async openTurn(conversation, turn) {
1063
+ await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
1064
+ tellList(alive);
1023
1065
  },
1024
- openTurn(conversation, turn) {
1066
+ dismissSuggestion(conversation, suggestion) {
1025
1067
  return alive.deps.durably(async (local) => {
1026
- const { openedTurns } = await local.facts();
1027
- await local.fact('openedTurns', { ...openedTurns, [conversation]: turn });
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 = chatDraftRevision()) {
1035
- return withDraft(alive, conversation, (current) => ({
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 withDraft(alive, conversation, (current) => ({
1044
- conversation,
1045
- ...(current === undefined ? { text: draft.text } : prepended(current, draft)),
1046
- revision: chatDraftRevision(),
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 || alive.known())
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, kept, { conversationList }] = await Promise.all([
1125
+ const [held, stored, { conversationList, agentList }] = await Promise.all([
1069
1126
  local.conversations(),
1070
- local.chatDrafts(),
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, list)));
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 { window, draft, ended } = held.now();
1162
- const shown = window ?? [];
1163
- watcher.notify(viewOf(alive, conversation, shown, sharedFrame(view, shown), draft, ended));
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);