@agentshouse/mdruntime 0.1.0-cc2e934017fb1 → 0.1.0-cc4575cb1254b

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 (265) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +15 -24
  4. package/dist/act-lanes.d.ts +30 -0
  5. package/dist/act-lanes.d.ts.map +1 -0
  6. package/dist/act-lanes.js +225 -0
  7. package/dist/actions.d.ts +8 -2
  8. package/dist/actions.d.ts.map +1 -1
  9. package/dist/actions.js +139 -68
  10. package/dist/adapter.d.ts +114 -24
  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/authored.d.ts +88 -0
  16. package/dist/authored.d.ts.map +1 -0
  17. package/dist/authored.js +347 -0
  18. package/dist/binary.d.ts +6 -2
  19. package/dist/binary.d.ts.map +1 -1
  20. package/dist/binary.js +10 -3
  21. package/dist/change.d.ts +6 -2
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/change.js +3 -0
  24. package/dist/chat-types.d.ts +0 -2
  25. package/dist/chat-types.d.ts.map +1 -1
  26. package/dist/chat-types.js +2 -4
  27. package/dist/client.d.ts +20 -14
  28. package/dist/client.d.ts.map +1 -1
  29. package/dist/client.js +32 -60
  30. package/dist/collection.d.ts +5 -1
  31. package/dist/collection.d.ts.map +1 -1
  32. package/dist/collection.js +16 -8
  33. package/dist/column.d.ts +5 -0
  34. package/dist/column.d.ts.map +1 -0
  35. package/dist/column.js +9 -0
  36. package/dist/compile.d.ts +2 -0
  37. package/dist/compile.d.ts.map +1 -1
  38. package/dist/compile.js +21 -11
  39. package/dist/connection.d.ts +1 -1
  40. package/dist/connection.d.ts.map +1 -1
  41. package/dist/connection.js +22 -16
  42. package/dist/context.d.ts.map +1 -1
  43. package/dist/context.js +1 -1
  44. package/dist/conversation-live.d.ts +23 -10
  45. package/dist/conversation-live.d.ts.map +1 -1
  46. package/dist/conversation-live.js +18 -8
  47. package/dist/conversation-row.d.ts +8 -1
  48. package/dist/conversation-row.d.ts.map +1 -1
  49. package/dist/conversation-row.js +20 -7
  50. package/dist/conversation.d.ts +26 -15
  51. package/dist/conversation.d.ts.map +1 -1
  52. package/dist/conversation.js +270 -206
  53. package/dist/declaration.js +1 -1
  54. package/dist/discovery.d.ts +3 -1
  55. package/dist/discovery.d.ts.map +1 -1
  56. package/dist/discovery.js +36 -9
  57. package/dist/download.d.ts +6 -0
  58. package/dist/download.d.ts.map +1 -0
  59. package/dist/download.js +42 -0
  60. package/dist/durability.d.ts +5 -0
  61. package/dist/durability.d.ts.map +1 -1
  62. package/dist/durability.js +7 -0
  63. package/dist/entry.d.ts +14 -0
  64. package/dist/entry.d.ts.map +1 -1
  65. package/dist/entry.js +45 -16
  66. package/dist/expectation.d.ts +25 -14
  67. package/dist/expectation.d.ts.map +1 -1
  68. package/dist/expectation.js +51 -20
  69. package/dist/failure.d.ts +2 -0
  70. package/dist/failure.d.ts.map +1 -1
  71. package/dist/failure.js +6 -1
  72. package/dist/figures.d.ts.map +1 -1
  73. package/dist/figures.js +4 -2
  74. package/dist/file.d.ts +1 -1
  75. package/dist/file.d.ts.map +1 -1
  76. package/dist/file.js +3 -2
  77. package/dist/host.d.ts +7 -2
  78. package/dist/host.d.ts.map +1 -1
  79. package/dist/host.js +80 -34
  80. package/dist/house-query.d.ts +24 -0
  81. package/dist/house-query.d.ts.map +1 -0
  82. package/dist/house-query.js +67 -0
  83. package/dist/index.d.ts +18 -11
  84. package/dist/index.d.ts.map +1 -1
  85. package/dist/index.js +12 -6
  86. package/dist/install.d.ts +10 -4
  87. package/dist/install.d.ts.map +1 -1
  88. package/dist/install.js +45 -46
  89. package/dist/lifecycle.d.ts +1 -1
  90. package/dist/lifecycle.d.ts.map +1 -1
  91. package/dist/lifecycle.js +50 -32
  92. package/dist/listing.d.ts +24 -12
  93. package/dist/listing.d.ts.map +1 -1
  94. package/dist/listing.js +50 -21
  95. package/dist/live.d.ts +5 -3
  96. package/dist/live.d.ts.map +1 -1
  97. package/dist/live.js +71 -30
  98. package/dist/loaded.d.ts +7 -0
  99. package/dist/loaded.d.ts.map +1 -0
  100. package/dist/loaded.js +46 -0
  101. package/dist/locks.d.ts.map +1 -1
  102. package/dist/locks.js +4 -3
  103. package/dist/lost.d.ts.map +1 -1
  104. package/dist/lost.js +2 -3
  105. package/dist/media.d.ts +19 -3
  106. package/dist/media.d.ts.map +1 -1
  107. package/dist/media.js +167 -33
  108. package/dist/memory.d.ts +7 -3
  109. package/dist/memory.d.ts.map +1 -1
  110. package/dist/memory.js +77 -29
  111. package/dist/messages.d.ts +17 -3
  112. package/dist/messages.d.ts.map +1 -1
  113. package/dist/messages.js +29 -10
  114. package/dist/modal.d.ts +2 -0
  115. package/dist/modal.d.ts.map +1 -0
  116. package/dist/modal.js +11 -0
  117. package/dist/model.d.ts +4 -2
  118. package/dist/model.d.ts.map +1 -1
  119. package/dist/model.js +7 -1
  120. package/dist/models.d.ts.map +1 -1
  121. package/dist/models.js +5 -8
  122. package/dist/name.d.ts +0 -1
  123. package/dist/name.d.ts.map +1 -1
  124. package/dist/name.js +3 -7
  125. package/dist/observation.d.ts +29 -12
  126. package/dist/observation.d.ts.map +1 -1
  127. package/dist/observation.js +206 -69
  128. package/dist/online.d.ts +7 -0
  129. package/dist/online.d.ts.map +1 -0
  130. package/dist/online.js +29 -0
  131. package/dist/opening.d.ts.map +1 -1
  132. package/dist/opening.js +20 -10
  133. package/dist/outcome.d.ts +24 -4
  134. package/dist/outcome.d.ts.map +1 -1
  135. package/dist/outcome.js +33 -3
  136. package/dist/overlay.d.ts +7 -4
  137. package/dist/overlay.d.ts.map +1 -1
  138. package/dist/overlay.js +11 -9
  139. package/dist/parts.d.ts +4 -9
  140. package/dist/parts.d.ts.map +1 -1
  141. package/dist/parts.js +30 -15
  142. package/dist/preparation.d.ts +33 -7
  143. package/dist/preparation.d.ts.map +1 -1
  144. package/dist/preparation.js +198 -87
  145. package/dist/presence.d.ts +8 -2
  146. package/dist/presence.d.ts.map +1 -1
  147. package/dist/presence.js +24 -13
  148. package/dist/queries.d.ts +2 -2
  149. package/dist/queries.d.ts.map +1 -1
  150. package/dist/queries.js +81 -64
  151. package/dist/query.d.ts +2 -2
  152. package/dist/questions.d.ts +1 -5
  153. package/dist/questions.d.ts.map +1 -1
  154. package/dist/questions.js +3 -8
  155. package/dist/queue.d.ts +2 -2
  156. package/dist/queue.d.ts.map +1 -1
  157. package/dist/queue.js +73 -48
  158. package/dist/reach.d.ts +15 -6
  159. package/dist/reach.d.ts.map +1 -1
  160. package/dist/reach.js +166 -41
  161. package/dist/react.d.ts +11 -5
  162. package/dist/react.d.ts.map +1 -1
  163. package/dist/react.js +28 -5
  164. package/dist/readiness.d.ts +20 -4
  165. package/dist/readiness.d.ts.map +1 -1
  166. package/dist/readiness.js +17 -10
  167. package/dist/reads.d.ts +4 -2
  168. package/dist/reads.d.ts.map +1 -1
  169. package/dist/reads.js +7 -3
  170. package/dist/recovery.d.ts +4 -1
  171. package/dist/recovery.d.ts.map +1 -1
  172. package/dist/recovery.js +31 -8
  173. package/dist/reference-forms.d.ts +4 -0
  174. package/dist/reference-forms.d.ts.map +1 -0
  175. package/dist/reference-forms.js +74 -0
  176. package/dist/refresh.d.ts +1 -1
  177. package/dist/refresh.js +4 -4
  178. package/dist/refusal.d.ts.map +1 -1
  179. package/dist/refusal.js +1 -3
  180. package/dist/replica.d.ts.map +1 -1
  181. package/dist/replica.js +4 -4
  182. package/dist/retried.d.ts +30 -0
  183. package/dist/retried.d.ts.map +1 -0
  184. package/dist/retried.js +72 -0
  185. package/dist/room-draft.d.ts +30 -5
  186. package/dist/room-draft.d.ts.map +1 -1
  187. package/dist/room-draft.js +258 -32
  188. package/dist/room-drafts.d.ts.map +1 -1
  189. package/dist/room-drafts.js +11 -6
  190. package/dist/room-list.d.ts +10 -0
  191. package/dist/room-list.d.ts.map +1 -0
  192. package/dist/room-list.js +45 -0
  193. package/dist/rows.d.ts +10 -2
  194. package/dist/rows.d.ts.map +1 -1
  195. package/dist/rows.js +23 -10
  196. package/dist/running.d.ts +5 -0
  197. package/dist/running.d.ts.map +1 -0
  198. package/dist/running.js +10 -0
  199. package/dist/runtime.d.ts +6 -4
  200. package/dist/runtime.d.ts.map +1 -1
  201. package/dist/save.d.ts +2 -0
  202. package/dist/save.d.ts.map +1 -1
  203. package/dist/save.js +105 -124
  204. package/dist/saves.d.ts +4 -2
  205. package/dist/saves.d.ts.map +1 -1
  206. package/dist/saves.js +66 -21
  207. package/dist/seed.d.ts.map +1 -1
  208. package/dist/seed.js +2 -2
  209. package/dist/shown.d.ts +5 -2
  210. package/dist/shown.d.ts.map +1 -1
  211. package/dist/shown.js +79 -43
  212. package/dist/socket/lanes.d.ts +12 -4
  213. package/dist/socket/lanes.d.ts.map +1 -1
  214. package/dist/socket/lanes.js +34 -8
  215. package/dist/socket/session.d.ts +4 -1
  216. package/dist/socket/session.d.ts.map +1 -1
  217. package/dist/socket/session.js +3 -0
  218. package/dist/socket.d.ts +4 -3
  219. package/dist/socket.d.ts.map +1 -1
  220. package/dist/socket.js +4 -9
  221. package/dist/source.d.ts +7 -7
  222. package/dist/source.d.ts.map +1 -1
  223. package/dist/source.js +15 -2
  224. package/dist/store/installs.d.ts +2 -2
  225. package/dist/store/installs.d.ts.map +1 -1
  226. package/dist/store/installs.js +10 -4
  227. package/dist/store/readiness.d.ts +5 -4
  228. package/dist/store/readiness.d.ts.map +1 -1
  229. package/dist/store/readiness.js +28 -12
  230. package/dist/store/records.d.ts +21 -5
  231. package/dist/store/records.d.ts.map +1 -1
  232. package/dist/store/records.js +63 -22
  233. package/dist/store/rooms-shown.d.ts +8 -0
  234. package/dist/store/rooms-shown.d.ts.map +1 -0
  235. package/dist/store/rooms-shown.js +13 -0
  236. package/dist/store.d.ts +17 -10
  237. package/dist/store.d.ts.map +1 -1
  238. package/dist/store.js +18 -6
  239. package/dist/stored.d.ts +38 -14
  240. package/dist/stored.d.ts.map +1 -1
  241. package/dist/stored.js +203 -55
  242. package/dist/surface.d.ts +14 -8
  243. package/dist/surface.d.ts.map +1 -1
  244. package/dist/surface.js +59 -27
  245. package/dist/sync.d.ts +4 -2
  246. package/dist/sync.d.ts.map +1 -1
  247. package/dist/sync.js +76 -40
  248. package/dist/tables.d.ts +22 -52
  249. package/dist/tables.d.ts.map +1 -1
  250. package/dist/tables.js +90 -324
  251. package/dist/tallies.d.ts.map +1 -1
  252. package/dist/tallies.js +1 -2
  253. package/dist/validation.d.ts +2 -0
  254. package/dist/validation.d.ts.map +1 -1
  255. package/dist/validation.js +47 -10
  256. package/dist/wire.d.ts +38 -15
  257. package/dist/wire.d.ts.map +1 -1
  258. package/dist/wire.js +20 -13
  259. package/package.json +3 -3
  260. package/dist/attempt.d.ts +0 -16
  261. package/dist/attempt.d.ts.map +0 -1
  262. package/dist/attempt.js +0 -70
  263. package/dist/log.d.ts +0 -6
  264. package/dist/log.d.ts.map +0 -1
  265. package/dist/log.js +0 -14
@@ -6,11 +6,12 @@ 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';
13
13
  import { untilAnswered } from './recovery.js';
14
+ import { retrying } from './retried.js';
14
15
  import { capped, FROM_START, messageOrder, precedes } from './windows.js';
15
16
  export function unheldView(conversation) {
16
17
  return {
@@ -24,14 +25,17 @@ export function unheldView(conversation) {
24
25
  options: [],
25
26
  starting: null,
26
27
  state: null,
27
- link: null,
28
28
  deliveryWaiting: [],
29
29
  deliveryUnknown: [],
30
30
  chatDraft: null,
31
+ dismissedSuggestion: null,
32
+ pins: [],
31
33
  };
32
34
  }
33
35
  export const SESSION_STARTED = 'Session started';
34
36
  const NEW_CHAT = 'new:';
37
+ const LISTING = 'listing';
38
+ export const CATCHING_UP = 'catching-up';
35
39
  export const HISTORY_CONVERSATIONS = 64;
36
40
  export function newChat(agent) {
37
41
  return `${NEW_CHAT}${agent}`;
@@ -194,17 +198,17 @@ function withSubmitted(draft, submitted) {
194
198
  const { submitted: _held, ...unsent } = draft;
195
199
  return submitted.length === 0 ? unsent : { ...unsent, submitted };
196
200
  }
197
- function prepended(draft, said) {
198
- 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');
199
203
  }
200
204
  function returned(draft, submission, others) {
201
205
  return withSubmitted({
202
206
  conversation: draft.conversation,
203
- ...prepended(draft, submission),
207
+ text: joinedDraft(submission.text, draft.text),
204
208
  revision: chatDraftRevision(),
205
209
  }, others);
206
210
  }
207
- function viewOf(alive, conversation, held, frame, draft, ended) {
211
+ function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
208
212
  const facts = alive.liveOf(conversation);
209
213
  return {
210
214
  conversation,
@@ -223,36 +227,44 @@ function viewOf(alive, conversation, held, frame, draft, ended) {
223
227
  options: structuredClone(facts.options),
224
228
  starting: facts.starting,
225
229
  state: sessionOf(facts, held, ended),
226
- link: facts.link === null ? null : { ...facts.link },
227
230
  deliveryWaiting: [...facts.deliveryWaiting],
228
231
  deliveryUnknown: [...facts.deliveryUnknown],
229
232
  chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
233
+ dismissedSuggestion: dismissed,
234
+ pins: [...pins],
230
235
  };
231
236
  }
232
- function sessionOf(facts, held, ended) {
237
+ function standing(facts, saved, ended) {
233
238
  if (facts.state !== null)
234
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) {
235
246
  const saved = [...held]
236
247
  .reverse()
237
248
  .map(({ message }) => record(message))
238
249
  .find(({ content }) => isTurn(content));
239
250
  const at = saved === undefined ? null : text(saved, 'accepted_at');
240
- if (saved === undefined || !isTurn(saved.content) || at === null)
241
- return null;
242
- const down = facts.process?.running === false;
243
- 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);
244
254
  }
245
255
  function emit(alive, conversation) {
246
256
  if (alive.deps.closed())
247
257
  return;
248
258
  for (const view of alive.views()) {
249
- const { window, draft, ended } = view.held.now();
259
+ const held = view.held.now();
260
+ const { window } = held;
250
261
  if (view.conversation !== conversation || window === null)
251
262
  continue;
252
263
  const ready = view.ready();
253
264
  if (ready.length === 0)
254
265
  continue;
255
- 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);
256
268
  for (const watcher of ready)
257
269
  watcher.notify(value);
258
270
  }
@@ -288,76 +300,103 @@ function stateOf(alive, conversation) {
288
300
  return facts.turn === null ? 'idle' : 'working';
289
301
  }
290
302
  function rowOf(alive, conversation) {
291
- const { turn, questions } = alive.liveOf(conversation);
303
+ const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
292
304
  return {
293
305
  state: stateOf(alive, conversation),
294
306
  started: turn?.started ?? null,
295
307
  line: turn === null ? null : runningLine(turn.parts),
296
308
  question: openQuestion(questions),
297
309
  asked: questionAsked(questions),
310
+ deliveryWaiting: [...deliveryWaiting],
298
311
  };
299
312
  }
300
313
  async function entries(alive) {
301
- const list = await heldList(alive);
302
- 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)))
303
320
  return null;
304
321
  const held = list.length === 0
305
322
  ? []
306
323
  : await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
307
324
  const rows = new Map(held.map((one) => [one.conversation, one]));
308
- return list.map((entry) => ({
309
- conversation: entry.conversation,
310
- agent: { identity: entry.agent, name: entry.agentName, retired: entry.agentRetired },
311
- name: entry.name,
312
- created: entry.created,
313
- finished: entry.finished,
314
- outcome: entry.outcome,
315
- waiting: entry.waiting,
316
- ...rowOf(alive, entry.conversation),
317
- ...heldFacts(rows.get(entry.conversation), entry),
318
- }));
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
+ ...rowOf(alive, entry.conversation),
336
+ ...heldFacts(rows.get(entry.conversation), entry),
337
+ jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
338
+ };
339
+ });
319
340
  }
320
- async function heldList(alive) {
321
- const stored = (await (await alive.deps.local()).facts()).conversationList;
322
- if (stored !== null)
323
- return stored;
324
- return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online() ? null : [];
341
+ async function heldListing(alive) {
342
+ const { conversationList, agentList } = await (await alive.deps.local()).facts();
343
+ if (conversationList !== null && agentList !== null)
344
+ return { conversations: conversationList, agents: agentList };
345
+ return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
346
+ ? null
347
+ : { conversations: [], agents: [] };
325
348
  }
326
349
  async function endedIn(alive, conversation) {
327
- const list = await heldList(alive);
328
- return list?.find((entry) => entry.conversation === conversation)?.processEnded ?? null;
350
+ const listing = await heldListing(alive);
351
+ return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
352
+ null);
353
+ }
354
+ function upserted(kept, set, key) {
355
+ const held = new Map(kept.map((one) => [key(one), one]));
356
+ for (const one of set)
357
+ held.set(key(one), { ...one });
358
+ return held;
329
359
  }
330
360
  function listChanged(alive, change) {
331
361
  void alive.deps
332
362
  .durably(async (local) => {
333
- const { conversationList, conversationCursor } = await local.facts();
334
- const kept = change.replacing ? [] : (conversationList ?? []);
335
- const held = new Map(kept.map((entry) => [entry.conversation, entry]));
336
- for (const entry of change.set) {
337
- held.set(entry.conversation, { ...entry });
363
+ const { conversationList, agentList, conversationCursor, readUntil } = await local.facts();
364
+ if (readUntil === null)
365
+ await local.fact('readUntil', new Date().toISOString());
366
+ const held = upserted(change.replacing ? [] : (conversationList ?? []), change.set, (entry) => entry.conversation);
367
+ for (const entry of change.set)
338
368
  alive.created(entry.conversation);
339
- }
340
369
  if (change.gone !== null)
341
370
  held.delete(change.gone);
342
371
  const list = [...held.values()];
372
+ const agents = [
373
+ ...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
374
+ ];
343
375
  if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
344
376
  await local.fact('conversationList', list);
345
377
  }
378
+ if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
379
+ await local.fact('agentList', agents);
380
+ }
346
381
  if (change.cursor !== undefined) {
347
382
  if (change.cursor !== conversationCursor) {
348
383
  await local.fact('conversationCursor', change.cursor);
349
384
  }
350
385
  alive.deps.stream()?.hold(change.cursor);
351
386
  }
352
- return list;
387
+ return { conversations: list, agents };
388
+ })
389
+ .catch(async () => {
390
+ const { conversationList, agentList } = await (await alive.deps.local()).facts();
391
+ return { conversations: conversationList ?? [], agents: agentList ?? [] };
353
392
  })
354
- .catch(async () => (await (await alive.deps.local()).facts()).conversationList ?? [])
355
- .then((list) => {
393
+ .then((listing) => {
356
394
  if (alive.deps.closed() || change.paged === true)
357
395
  return;
396
+ const list = listing.conversations;
358
397
  endedAnew(alive, list);
359
398
  if (change.cursor !== undefined) {
360
- alive.held.set({ listKnown: true });
399
+ alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
361
400
  settleBehind(alive, list);
362
401
  openingEnded(alive);
363
402
  alive.deps.settled();
@@ -365,11 +404,12 @@ function listChanged(alive, change) {
365
404
  emitList(alive);
366
405
  if (!alive.known())
367
406
  return;
368
- retiredDrafts(alive, list);
369
- const { replicated } = alive.held.now();
370
- if (change.cursor === undefined &&
371
- (list.length !== replicated.size ||
372
- list.some(({ conversation }) => !replicated.has(conversation)))) {
407
+ retiredDrafts(alive, listing);
408
+ const { replicated, openingRead } = alive.held.now();
409
+ if (change.cursor === undefined
410
+ ? list.length !== replicated.size ||
411
+ list.some(({ conversation }) => !replicated.has(conversation))
412
+ : openingRead) {
373
413
  alive.deps.again();
374
414
  }
375
415
  }, uncaught);
@@ -385,23 +425,23 @@ function endedAnew(alive, list) {
385
425
  emit(alive, view.conversation);
386
426
  }
387
427
  }
388
- function shownList(alive, work) {
389
- const reading = heldList(alive);
428
+ function shownListing(alive, work) {
429
+ const reading = heldListing(alive);
390
430
  alive.inOrder(async () => {
391
- const list = await reading.catch((error) => {
431
+ const listing = await reading.catch((error) => {
392
432
  uncaught(error);
393
433
  return null;
394
434
  });
395
- if (list === null || alive.deps.closed())
435
+ if (listing === null || alive.deps.closed())
396
436
  return;
397
- work(list);
437
+ work(listing);
398
438
  });
399
439
  }
400
440
  async function told(alive) {
401
441
  try {
402
442
  while (alive.held.now().listOwed && !alive.deps.closed()) {
403
443
  alive.held.set({ listOwed: false });
404
- const value = await untilAnswered(() => entries(alive), alive.closing);
444
+ const value = await untilAnswered(retrying(alive.deps.retries, 'conversations', LISTING, () => entries(alive)), alive.closing, () => true, alive.deps.recovery);
405
445
  if (alive.deps.closed())
406
446
  return;
407
447
  if (value === null)
@@ -439,84 +479,73 @@ export function conversationsLearned(alive) {
439
479
  return;
440
480
  if (alive.listeners.waiting())
441
481
  tellList(alive);
442
- if (!alive.agentListeners.waiting())
482
+ if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
443
483
  return;
444
- shownList(alive, (list) => alive.agentListeners.welcome(agents(alive, list)));
484
+ shownListing(alive, (listing) => {
485
+ alive.agentListeners.welcome(agentsOf(listing));
486
+ alive.listedListeners.welcome(structuredClone(listing.agents));
487
+ });
445
488
  }
446
- function agents(alive, list) {
447
- const read = new Map((alive.held.now().listedAgents ?? []).map((one) => [one.agent, one]));
448
- const named = new Map(read);
449
- for (const entry of list) {
450
- named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
451
- }
452
- return [...named]
453
- .filter(([, agent]) => !agent.retired)
454
- .map(([identity, agent]) => {
455
- const held = read.get(identity);
456
- return held === undefined
457
- ? { identity, name: agent.name }
458
- : {
459
- identity,
460
- name: agent.name,
461
- cli: held.cli,
462
- environment: structuredClone(held.environment),
463
- };
464
- })
489
+ function agentsOf(listing) {
490
+ return listing.agents
491
+ .filter((agent) => agent.retired_at === null)
492
+ .map((agent) => ({
493
+ identity: agent.id,
494
+ name: agent.name,
495
+ cli: agent.cli,
496
+ model: agent.model,
497
+ effort: agent.effort,
498
+ environment: {
499
+ identity: agent.environment,
500
+ name: agent.environment_name,
501
+ state: agent.environment_connected ? 'online' : 'offline',
502
+ },
503
+ }))
465
504
  .sort((left, right) => left.name === right.name
466
505
  ? left.identity.localeCompare(right.identity)
467
506
  : left.name.localeCompare(right.name));
468
507
  }
469
- function readAgents(alive) {
470
- const stream = alive.deps.stream();
471
- if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
472
- return;
473
- const { agents: read } = stream;
474
- const { agentListeners } = alive;
475
- alive.held.set({ agentsReading: true });
476
- void alive.deps.recovery
477
- .attempt('agents', async () => {
478
- if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
479
- return 'done';
480
- }
481
- const listed = await read();
482
- if (listed === null)
483
- return 'done';
484
- alive.held.set({ listedAgents: listed });
485
- emitAgents(alive);
486
- return 'done';
487
- })
488
- .finally(() => {
489
- alive.held.set({ agentsReading: false });
490
- });
491
- }
492
508
  function emitAgents(alive) {
493
- if (alive.deps.closed() || !alive.agentListeners.told())
509
+ const { agentListeners, listedListeners } = alive;
510
+ if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
494
511
  return;
495
- shownList(alive, (list) => {
496
- const value = agents(alive, list);
512
+ shownListing(alive, (listing) => {
513
+ const value = agentsOf(listing);
497
514
  const shown = JSON.stringify(value);
498
- if (shown === alive.held.now().agentsShown)
499
- return;
500
- alive.held.set({ agentsShown: shown });
501
- alive.agentListeners.tell(value);
515
+ if (shown !== alive.held.now().agentsShown) {
516
+ alive.held.set({ agentsShown: shown });
517
+ agentListeners.tell(value);
518
+ }
519
+ const listed = JSON.stringify(listing.agents);
520
+ if (listed !== alive.held.now().listedShown) {
521
+ alive.held.set({ listedShown: listed });
522
+ listedListeners.tell(structuredClone(listing.agents));
523
+ }
502
524
  });
503
525
  }
526
+ function ran({ state, process }) {
527
+ return JSON.stringify([state?.running ?? null, process?.running ?? null]);
528
+ }
504
529
  function setLive(alive, conversation, next) {
530
+ const was = ran(alive.liveOf(conversation));
505
531
  const before = rowOf(alive, conversation);
506
532
  alive.holdLive(conversation, next);
507
533
  const after = rowOf(alive, conversation);
508
- if (after.state !== before.state || after.started !== before.started)
534
+ if (after.state !== before.state ||
535
+ after.started !== before.started ||
536
+ ran(alive.liveOf(conversation)) !== was ||
537
+ after.deliveryWaiting.join() !== before.deliveryWaiting.join())
509
538
  emitList(alive);
510
539
  else if (after.line !== before.line ||
511
540
  after.question !== before.question ||
512
541
  after.asked !== before.asked)
513
542
  tellSoon(alive);
514
543
  }
515
- function retiredChat(conversation, list) {
544
+ function retiredChat(conversation, listing) {
516
545
  if (!conversation.startsWith(NEW_CHAT))
517
546
  return false;
518
547
  const agent = conversation.slice(NEW_CHAT.length);
519
- return list.some((entry) => entry.agent === agent && entry.agentRetired);
548
+ return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
520
549
  }
521
550
  function live(alive, conversation, change) {
522
551
  alive.factsHeard(conversation, FACTS.filter((one) => one in change));
@@ -536,7 +565,6 @@ function openingEnded(alive) {
536
565
  options: facts.has('options') ? QUIET.options : held.options,
537
566
  starting: facts.has('starting') ? QUIET.starting : held.starting,
538
567
  state: facts.has('state') ? QUIET.state : held.state,
539
- link: facts.has('link') ? QUIET.link : held.link,
540
568
  deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
541
569
  deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
542
570
  });
@@ -569,19 +597,13 @@ function handReplicated(alive) {
569
597
  }
570
598
  async function remove(alive, leaving) {
571
599
  await alive.deps.durably(async (local) => {
572
- const kept = new Set([
573
- ...(await local.conversations(leaving)).map(({ conversation }) => conversation),
574
- ...(await local.chatDrafts())
575
- .filter(({ conversation }) => leaving.includes(conversation))
576
- .map(({ conversation }) => conversation),
577
- ]);
578
- await local.dropConversations(leaving);
600
+ const kept = new Set(await local.dropConversations(leaving));
579
601
  const changed = [];
580
602
  for (const conversation of leaving) {
581
603
  if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
582
604
  changed.push(conversation);
583
605
  }
584
- shownDraft(alive, conversation, null);
606
+ heldInViews(alive, conversation, { draft: null, dismissed: null });
585
607
  alive.forget(conversation);
586
608
  setLive(alive, conversation, null);
587
609
  await slide(alive, local, conversation, null);
@@ -610,7 +632,7 @@ async function readsOf(local, conversations) {
610
632
  return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
611
633
  }
612
634
  function retiredDrafts(alive, list) {
613
- if (!list.some((entry) => entry.agentRetired))
635
+ if (!list.agents.some((agent) => agent.retired_at !== null))
614
636
  return;
615
637
  void alive.deps
616
638
  .local()
@@ -774,10 +796,6 @@ function heard(alive, event) {
774
796
  live(alive, conversation, { state: structuredClone(event.state) });
775
797
  return;
776
798
  }
777
- if (event.kind === 'link') {
778
- live(alive, conversation, { link: { connected: event.connected } });
779
- return;
780
- }
781
799
  if (event.kind === 'deliveries') {
782
800
  live(alive, conversation, {
783
801
  deliveryWaiting: [...event.waiting],
@@ -806,19 +824,27 @@ function heard(alive, event) {
806
824
  emit(alive, conversation);
807
825
  }
808
826
  async function kept(alive, local, conversation, following) {
809
- const shown = following === null || empty(following) ? null : following;
810
- if (shown === null)
827
+ const draft = following === null || empty(following) ? null : following;
828
+ if (draft === null)
811
829
  await local.dropChatDraft(conversation);
812
830
  else
813
- await local.keepChatDrafts([shown]);
814
- shownDraft(alive, conversation, shown);
831
+ await local.keepChatDrafts([draft]);
832
+ heldInViews(alive, conversation, { draft });
815
833
  }
816
- function shownDraft(alive, conversation, draft) {
834
+ function heldInViews(alive, conversation, held) {
817
835
  for (const view of alive.views()) {
818
836
  if (view.conversation === conversation)
819
- view.held.set({ draft });
837
+ view.held.set(held);
820
838
  }
821
839
  }
840
+ async function factOf(local, name) {
841
+ return Object.fromEntries((await local.conversationFacts())
842
+ .filter((fact) => fact.name === name)
843
+ .map(({ conversation, value }) => [conversation, value]));
844
+ }
845
+ async function dismissedIn(local, conversation) {
846
+ return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
847
+ }
822
848
  async function draftAt(local, conversation) {
823
849
  return (await local.chatDraft(conversation)) ?? undefined;
824
850
  }
@@ -849,9 +875,9 @@ function moved(alive, agent, operation, to) {
849
875
  : [{ ...unsent, conversation: to }];
850
876
  const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
851
877
  await local.keepChatDrafts([left, ...taken]);
852
- shownDraft(alive, from, left);
878
+ heldInViews(alive, from, { draft: left });
853
879
  for (const one of taken)
854
- shownDraft(alive, to, one);
880
+ heldInViews(alive, to, { draft: one });
855
881
  alive.deps.publish(conversationChangeSet([from, to]));
856
882
  });
857
883
  }
@@ -882,13 +908,10 @@ async function submitted(alive, conversation, operation, draft) {
882
908
  });
883
909
  return submission;
884
910
  }
885
- async function dispatched(alive, conversation, submission) {
911
+ async function dispatched(alive, conversation, submission, resent = false) {
886
912
  const dispatch = alive.sendingBegan(submission.operation);
887
913
  try {
888
- const result = await invoke(alive, 'conversations/send', conversation, {
889
- operation_id: submission.operation,
890
- text: submission.text,
891
- });
914
+ const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
892
915
  dispatch.set({ answered: result.kind !== 'transport-uncertainty' });
893
916
  if (result.kind === 'revoked-authorization')
894
917
  return result;
@@ -896,6 +919,7 @@ async function dispatched(alive, conversation, submission) {
896
919
  alive.deps.unanswered();
897
920
  return result;
898
921
  }
922
+ alive.deps.heard(submission.operation, resent);
899
923
  const turn = answered(result, 'message_id');
900
924
  await withDraft(alive, conversation, async (current, local) => {
901
925
  const held = current?.submitted?.find((one) => one.operation === submission.operation);
@@ -915,11 +939,12 @@ async function dispatched(alive, conversation, submission) {
915
939
  alive.sendingEnded(submission.operation, dispatch);
916
940
  }
917
941
  }
918
- function invoke(alive, name, conversation, extra = { operation_id: changeBatchIdentity() }) {
919
- return alive.deps.call(name, { conversation_id: conversation, ...extra });
942
+ function invoke(alive, name, conversation, operation, extra = {}, attempt) {
943
+ return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
920
944
  }
921
- export function conversationSurface(alive) {
945
+ export function conversationSurface(alive, files) {
922
946
  return {
947
+ ...files,
923
948
  list() {
924
949
  return new Promise((settle) => {
925
950
  const answer = (listed) => {
@@ -937,7 +962,12 @@ export function conversationSurface(alive) {
937
962
  return alive.deps.durably(async (local) => {
938
963
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
939
964
  const total = asked.total ? await local.messageCount(conversation, phrase) : null;
940
- return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), (await local.chatDraft(conversation)) ?? null, await endedIn(alive, conversation)));
965
+ return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
966
+ draft: (await local.chatDraft(conversation)) ?? null,
967
+ ended: await endedIn(alive, conversation),
968
+ dismissed: await dismissedIn(local, conversation),
969
+ pins: (await local.facts()).chatPins,
970
+ }));
941
971
  });
942
972
  },
943
973
  async create(input) {
@@ -945,7 +975,7 @@ export function conversationSurface(alive) {
945
975
  const conversation = answered(result, 'conversation_id');
946
976
  if (conversation === null)
947
977
  return result;
948
- const listed = (await heldList(alive)) ?? [];
978
+ const listed = (await heldListing(alive))?.conversations ?? [];
949
979
  if (!listed.some((entry) => entry.conversation === conversation)) {
950
980
  alive.creating(conversation);
951
981
  }
@@ -974,25 +1004,21 @@ export function conversationSurface(alive) {
974
1004
  }
975
1005
  return OFFLINE;
976
1006
  },
977
- answer(conversation, answer) {
978
- return invoke(alive, 'conversations/interaction/answer', conversation, {
979
- operation_id: changeBatchIdentity(),
980
- ...answer,
981
- });
1007
+ answer(conversation, answer, operation) {
1008
+ return invoke(alive, 'conversations/interaction/answer', conversation, operation, answer);
982
1009
  },
983
- interrupt(conversation) {
984
- return invoke(alive, 'conversations/interrupt', conversation);
1010
+ interrupt(conversation, operation) {
1011
+ return invoke(alive, 'conversations/interrupt', conversation, operation);
985
1012
  },
986
- kill(conversation) {
987
- return invoke(alive, 'conversations/kill', conversation);
1013
+ kill(conversation, operation) {
1014
+ return invoke(alive, 'conversations/kill', conversation, operation);
988
1015
  },
989
- delete(conversation) {
990
- return invoke(alive, 'conversations/delete', conversation);
1016
+ delete(conversation, operation) {
1017
+ return invoke(alive, 'conversations/delete', conversation, operation);
991
1018
  },
992
1019
  takeOut(conversation, message, operation) {
993
- return invoke(alive, 'conversations/take-out', conversation, {
1020
+ return invoke(alive, 'conversations/take-out', conversation, operation, {
994
1021
  message_id: message,
995
- operation_id: operation,
996
1022
  });
997
1023
  },
998
1024
  decide({ request, room, message }, decision, operation) {
@@ -1005,55 +1031,63 @@ export function conversationSurface(alive) {
1005
1031
  });
1006
1032
  },
1007
1033
  rename(conversation, name, operation) {
1008
- return invoke(alive, 'conversations/rename', conversation, { name, operation_id: operation });
1034
+ return invoke(alive, 'conversations/rename', conversation, operation, { name });
1009
1035
  },
1010
1036
  option(conversation, option, value, operation) {
1011
- return invoke(alive, 'conversations/option/set', conversation, {
1012
- option,
1013
- value,
1014
- operation_id: operation,
1015
- });
1037
+ return invoke(alive, 'conversations/option/set', conversation, operation, { option, value });
1016
1038
  },
1017
1039
  retry(conversation, message, operation) {
1018
- return invoke(alive, 'conversations/retry', conversation, {
1040
+ return invoke(alive, 'conversations/retry', conversation, operation, {
1019
1041
  message_id: message,
1020
- operation_id: operation,
1021
1042
  });
1022
1043
  },
1023
- async pins() {
1024
- return (await (await alive.deps.local()).facts()).chatPins;
1025
- },
1026
- pin(figures) {
1027
- return alive.deps.durably((local) => local.fact('chatPins', [...figures]));
1044
+ async pin(figures) {
1045
+ const pins = [...figures];
1046
+ await alive.deps.durably((local) => local.fact('chatPins', pins));
1047
+ const views = [...alive.views()];
1048
+ for (const view of views)
1049
+ view.held.set({ pins });
1050
+ for (const conversation of new Set(views.map((view) => view.conversation))) {
1051
+ emit(alive, conversation);
1052
+ }
1028
1053
  },
1029
- async openedTurns() {
1030
- return (await (await alive.deps.local()).facts()).openedTurns;
1054
+ async openTurn(conversation, turn) {
1055
+ await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
1056
+ tellList(alive);
1031
1057
  },
1032
- openTurn(conversation, turn) {
1058
+ dismissSuggestion(conversation, suggestion) {
1033
1059
  return alive.deps.durably(async (local) => {
1034
- const { openedTurns } = await local.facts();
1035
- await local.fact('openedTurns', { ...openedTurns, [conversation]: turn });
1060
+ if ((await dismissedIn(local, conversation)) === suggestion)
1061
+ return;
1062
+ await local.keepConversationFact({
1063
+ conversation,
1064
+ name: 'dismissedSuggestion',
1065
+ value: suggestion,
1066
+ });
1067
+ heldInViews(alive, conversation, { dismissed: suggestion });
1068
+ alive.deps.publish(conversationChangeSet([conversation]));
1036
1069
  });
1037
1070
  },
1038
1071
  };
1039
1072
  }
1073
+ function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
1074
+ return withDraft(alive, conversation, (current) => ({
1075
+ conversation,
1076
+ text: text(current?.text ?? ''),
1077
+ revision,
1078
+ ...(current === undefined ? {} : pending(current)),
1079
+ }));
1080
+ }
1040
1081
  export function chatDraftSurface(alive) {
1041
1082
  return {
1042
- write(conversation, draft, revision = chatDraftRevision()) {
1043
- return withDraft(alive, conversation, (current) => ({
1044
- conversation,
1045
- text: draft.text,
1046
- revision,
1047
- ...(current === undefined ? {} : pending(current)),
1048
- }));
1083
+ write(conversation, draft, revision) {
1084
+ return rewritten(alive, conversation, () => draft.text, revision);
1049
1085
  },
1050
1086
  prepend(conversation, draft) {
1051
- return withDraft(alive, conversation, (current) => ({
1052
- conversation,
1053
- ...(current === undefined ? { text: draft.text } : prepended(current, draft)),
1054
- revision: chatDraftRevision(),
1055
- ...(current === undefined ? {} : pending(current)),
1056
- }));
1087
+ return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
1088
+ },
1089
+ append(conversation, draft) {
1090
+ return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
1057
1091
  },
1058
1092
  discard(conversation) {
1059
1093
  return withDraft(alive, conversation, (current) => current === undefined
@@ -1063,31 +1097,37 @@ export function chatDraftSurface(alive) {
1063
1097
  };
1064
1098
  }
1065
1099
  export async function conversationsOpened(alive, local) {
1066
- const { conversationList, conversationCursor } = await local.facts();
1067
- if (conversationList === null || alive.known())
1100
+ const { conversationList, agentList, conversationCursor } = await local.facts();
1101
+ if (conversationList === null || agentList === null)
1102
+ return;
1103
+ alive.held.set({ listHeld: true });
1104
+ if (alive.known())
1068
1105
  return;
1069
1106
  alive.deps.stream()?.hold(conversationCursor);
1070
1107
  conversationsLearned(alive);
1071
1108
  }
1109
+ export function reconcileOpening(alive) {
1110
+ alive.held.set({ openingRead: true });
1111
+ return reconcileConversations(alive);
1112
+ }
1072
1113
  export async function reconcileConversations(alive) {
1073
1114
  if (!alive.known())
1074
1115
  return;
1075
1116
  const local = await alive.deps.local();
1076
- const [held, kept, { conversationList }] = await Promise.all([
1117
+ const [held, stored, { conversationList, agentList }] = await Promise.all([
1077
1118
  local.conversations(),
1078
- local.chatDrafts(),
1119
+ local.storedConversations(),
1079
1120
  local.facts(),
1080
1121
  ]);
1081
1122
  const list = conversationList ?? [];
1123
+ const listing = { conversations: list, agents: agentList ?? [] };
1082
1124
  const entries = new Map(list.map((entry) => [entry.conversation, entry]));
1083
1125
  const named = new Set(entries.keys());
1084
1126
  const reads = new Map(held.map((one) => [one.conversation, one]));
1085
1127
  const { replicated } = alive.held.now();
1086
- const leaving = [
1087
- ...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
1088
- ].filter((conversation) => !named.has(conversation) &&
1128
+ const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
1089
1129
  !alive.isCreating(conversation) &&
1090
- (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, list)));
1130
+ (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
1091
1131
  for (const conversation of named) {
1092
1132
  if (!replicated.has(conversation) &&
1093
1133
  missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
@@ -1122,6 +1162,17 @@ export async function catchUpConversations(alive, progress) {
1122
1162
  if (!alive.current())
1123
1163
  progress.complete = false;
1124
1164
  }
1165
+ export async function holdsSubmission(alive, operation) {
1166
+ if (alive.sending(operation))
1167
+ return true;
1168
+ const local = await alive.deps.local();
1169
+ for (const { conversation } of await local.chatDrafts()) {
1170
+ const held = (await local.chatDraft(conversation))?.submitted;
1171
+ if (held?.some((one) => one.operation === operation && one.turn === null) === true)
1172
+ return true;
1173
+ }
1174
+ return false;
1175
+ }
1125
1176
  export async function resendConversations(alive, progress) {
1126
1177
  const local = await alive.deps.local();
1127
1178
  const tried = new Set();
@@ -1133,7 +1184,7 @@ export async function resendConversations(alive, progress) {
1133
1184
  if (alive.deps.closed())
1134
1185
  return;
1135
1186
  tried.add(submission.operation);
1136
- const result = await dispatched(alive, conversation, submission);
1187
+ const result = await dispatched(alive, conversation, submission, true);
1137
1188
  if (result.kind === 'revoked-authorization')
1138
1189
  return;
1139
1190
  if (result.kind === 'transport-uncertainty') {
@@ -1153,22 +1204,25 @@ export function watchConversation(alive, conversation, options, deliver) {
1153
1204
  const { view, watcher } = alive.viewJoined(key, conversation, asked, deliver);
1154
1205
  const { held } = view;
1155
1206
  const reading = new AbortController();
1156
- void untilAnswered(() => alive.deps.durably(async (local) => {
1207
+ void untilAnswered(retrying(alive.deps.retries, 'reading', `window ${key}`, () => alive.deps.durably(async (local) => {
1157
1208
  if (held.now().window !== null)
1158
1209
  return;
1159
1210
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
1160
1211
  held.set({ draft: (await local.chatDraft(conversation)) ?? null });
1161
1212
  held.set({ ended: await endedIn(alive, conversation) });
1213
+ held.set({ dismissed: await dismissedIn(local, conversation) });
1214
+ held.set({ pins: (await local.facts()).chatPins });
1162
1215
  held.set({ window: messages });
1163
1216
  held.set({ more });
1164
1217
  held.set({ total: asked.total ? await local.messageCount(conversation) : null });
1165
- }), reading.signal)
1218
+ })), reading.signal)
1166
1219
  .then(() => {
1167
1220
  if (alive.deps.closed() || !view.admit(watcher))
1168
1221
  return;
1169
- const { window, draft, ended } = held.now();
1170
- const shown = window ?? [];
1171
- watcher.notify(viewOf(alive, conversation, shown, sharedFrame(view, shown), draft, ended));
1222
+ const now = held.now();
1223
+ const shown = now.window ?? [];
1224
+ const frame = sharedFrame(view, shown);
1225
+ watcher.notify(viewOf(alive, conversation, shown, frame, now));
1172
1226
  })
1173
1227
  .catch(() => { });
1174
1228
  return () => {
@@ -1184,9 +1238,13 @@ export function watchConversationList(alive, deliver) {
1184
1238
  export function watchConversationAgents(alive, deliver) {
1185
1239
  alive.agentListeners.join(deliver);
1186
1240
  conversationsLearned(alive);
1187
- readAgents(alive);
1188
1241
  return () => alive.agentListeners.leave(deliver);
1189
1242
  }
1243
+ export function watchListedAgents(alive, deliver) {
1244
+ alive.listedListeners.join(deliver);
1245
+ conversationsLearned(alive);
1246
+ return () => alive.listedListeners.leave(deliver);
1247
+ }
1190
1248
  export function conversationsChanged(alive, set) {
1191
1249
  for (const conversation of set.conversations)
1192
1250
  emit(alive, conversation);
@@ -1198,26 +1256,32 @@ export function receiveConversationEvent(alive, event) {
1198
1256
  if (event.whole)
1199
1257
  alive.relistBegun();
1200
1258
  if (alive.relisting())
1201
- alive.relistHeard(event.entries);
1259
+ alive.relistHeard(event.entries, event.agents);
1202
1260
  if (event.more && alive.relisting())
1203
1261
  return;
1204
1262
  const whole = alive.relistTaken();
1205
1263
  listChanged(alive, {
1206
1264
  replacing: whole !== null,
1207
- set: whole === null ? event.entries : [...whole.values()],
1265
+ set: whole === null ? event.entries : [...whole.conversations.values()],
1266
+ agents: whole === null ? event.agents : [...whole.agents.values()],
1208
1267
  gone: null,
1209
1268
  ...(event.more ? { paged: true } : { cursor: event.cursor }),
1210
1269
  });
1211
1270
  return;
1212
1271
  }
1213
1272
  if (event.kind === 'listed') {
1214
- alive.relistHeard([event.entry]);
1215
- listChanged(alive, { replacing: false, set: [event.entry], gone: null });
1273
+ alive.relistHeard([event.entry], []);
1274
+ listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
1275
+ return;
1276
+ }
1277
+ if (event.kind === 'agent') {
1278
+ alive.relistHeard([], [event.agent]);
1279
+ listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
1216
1280
  return;
1217
1281
  }
1218
1282
  if (event.kind === 'unlisted') {
1219
1283
  alive.relistDropped(event.conversation);
1220
- listChanged(alive, { replacing: false, set: [], gone: event.conversation });
1284
+ listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
1221
1285
  return;
1222
1286
  }
1223
1287
  heard(alive, event);