@agentshouse/mdruntime 0.1.0-c806ecaf4afed → 0.1.0-c809974611fbc

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