@agentshouse/mdruntime 0.1.0-cc2e934017fb1 → 0.1.0-cc3efa51a7546

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 (284) 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 +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 +161 -71
  10. package/dist/adapter.d.ts +137 -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 +21 -15
  31. package/dist/client.d.ts.map +1 -1
  32. package/dist/client.js +33 -61
  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 +34 -16
  54. package/dist/conversation.d.ts.map +1 -1
  55. package/dist/conversation.js +274 -207
  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 +82 -36
  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 -14
  91. package/dist/index.d.ts.map +1 -1
  92. package/dist/index.js +16 -8
  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 +50 -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 +80 -32
  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 +20 -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 +168 -43
  174. package/dist/react.d.ts +11 -5
  175. package/dist/react.d.ts.map +1 -1
  176. package/dist/react.js +28 -5
  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 +45 -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/running.d.ts +5 -0
  211. package/dist/running.d.ts.map +1 -0
  212. package/dist/running.js +10 -0
  213. package/dist/runtime.d.ts +7 -4
  214. package/dist/runtime.d.ts.map +1 -1
  215. package/dist/save.d.ts +2 -0
  216. package/dist/save.d.ts.map +1 -1
  217. package/dist/save.js +105 -124
  218. package/dist/saves.d.ts +7 -5
  219. package/dist/saves.d.ts.map +1 -1
  220. package/dist/saves.js +107 -57
  221. package/dist/seed.d.ts.map +1 -1
  222. package/dist/seed.js +2 -2
  223. package/dist/selector.d.ts +3 -0
  224. package/dist/selector.d.ts.map +1 -0
  225. package/dist/selector.js +22 -0
  226. package/dist/shown.d.ts +5 -2
  227. package/dist/shown.d.ts.map +1 -1
  228. package/dist/shown.js +79 -43
  229. package/dist/socket/lanes.d.ts +12 -4
  230. package/dist/socket/lanes.d.ts.map +1 -1
  231. package/dist/socket/lanes.js +34 -8
  232. package/dist/socket/session.d.ts +4 -1
  233. package/dist/socket/session.d.ts.map +1 -1
  234. package/dist/socket/session.js +3 -0
  235. package/dist/socket.d.ts +4 -3
  236. package/dist/socket.d.ts.map +1 -1
  237. package/dist/socket.js +4 -9
  238. package/dist/source.d.ts +7 -7
  239. package/dist/source.d.ts.map +1 -1
  240. package/dist/source.js +15 -2
  241. package/dist/store/installs.d.ts +2 -2
  242. package/dist/store/installs.d.ts.map +1 -1
  243. package/dist/store/installs.js +10 -4
  244. package/dist/store/readiness.d.ts +5 -4
  245. package/dist/store/readiness.d.ts.map +1 -1
  246. package/dist/store/readiness.js +28 -12
  247. package/dist/store/records.d.ts +30 -8
  248. package/dist/store/records.d.ts.map +1 -1
  249. package/dist/store/records.js +70 -26
  250. package/dist/store/rooms-shown.d.ts +8 -0
  251. package/dist/store/rooms-shown.d.ts.map +1 -0
  252. package/dist/store/rooms-shown.js +13 -0
  253. package/dist/store.d.ts +17 -10
  254. package/dist/store.d.ts.map +1 -1
  255. package/dist/store.js +18 -6
  256. package/dist/stored.d.ts +41 -16
  257. package/dist/stored.d.ts.map +1 -1
  258. package/dist/stored.js +215 -57
  259. package/dist/surface.d.ts +14 -8
  260. package/dist/surface.d.ts.map +1 -1
  261. package/dist/surface.js +59 -27
  262. package/dist/sync.d.ts +4 -2
  263. package/dist/sync.d.ts.map +1 -1
  264. package/dist/sync.js +76 -40
  265. package/dist/tables.d.ts +28 -52
  266. package/dist/tables.d.ts.map +1 -1
  267. package/dist/tables.js +95 -326
  268. package/dist/tallies.d.ts.map +1 -1
  269. package/dist/tallies.js +3 -4
  270. package/dist/validation.d.ts +2 -0
  271. package/dist/validation.d.ts.map +1 -1
  272. package/dist/validation.js +50 -10
  273. package/dist/wire.d.ts +39 -16
  274. package/dist/wire.d.ts.map +1 -1
  275. package/dist/wire.js +21 -14
  276. package/package.json +4 -4
  277. package/dist/attempt.d.ts +0 -16
  278. package/dist/attempt.d.ts.map +0 -1
  279. package/dist/attempt.js +0 -70
  280. package/dist/binary.d.ts.map +0 -1
  281. package/dist/binary.js +0 -8
  282. package/dist/log.d.ts +0 -6
  283. package/dist/log.d.ts.map +0 -1
  284. 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 };
391
+ })
392
+ .catch(async () => {
393
+ const { conversationList, agentList } = await (await alive.deps.local()).facts();
394
+ return { conversations: conversationList ?? [], agents: agentList ?? [] };
353
395
  })
354
- .catch(async () => (await (await alive.deps.local()).facts()).conversationList ?? [])
355
- .then((list) => {
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,73 @@ 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
+ environment: {
502
+ identity: agent.environment,
503
+ name: agent.environment_name,
504
+ state: agent.environment_connected ? 'online' : 'offline',
505
+ },
506
+ }))
465
507
  .sort((left, right) => left.name === right.name
466
508
  ? left.identity.localeCompare(right.identity)
467
509
  : left.name.localeCompare(right.name));
468
510
  }
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
511
  function emitAgents(alive) {
493
- if (alive.deps.closed() || !alive.agentListeners.told())
512
+ const { agentListeners, listedListeners } = alive;
513
+ if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
494
514
  return;
495
- shownList(alive, (list) => {
496
- const value = agents(alive, list);
515
+ shownListing(alive, (listing) => {
516
+ const value = agentsOf(listing);
497
517
  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);
518
+ if (shown !== alive.held.now().agentsShown) {
519
+ alive.held.set({ agentsShown: shown });
520
+ agentListeners.tell(value);
521
+ }
522
+ const listed = JSON.stringify(listing.agents);
523
+ if (listed !== alive.held.now().listedShown) {
524
+ alive.held.set({ listedShown: listed });
525
+ listedListeners.tell(structuredClone(listing.agents));
526
+ }
502
527
  });
503
528
  }
529
+ function ran({ state, process }) {
530
+ return JSON.stringify([state?.running ?? null, process?.running ?? null]);
531
+ }
504
532
  function setLive(alive, conversation, next) {
533
+ const was = ran(alive.liveOf(conversation));
505
534
  const before = rowOf(alive, conversation);
506
535
  alive.holdLive(conversation, next);
507
536
  const after = rowOf(alive, conversation);
508
- if (after.state !== before.state || after.started !== before.started)
537
+ if (after.state !== before.state ||
538
+ after.started !== before.started ||
539
+ ran(alive.liveOf(conversation)) !== was ||
540
+ after.deliveryWaiting.join() !== before.deliveryWaiting.join())
509
541
  emitList(alive);
510
542
  else if (after.line !== before.line ||
511
543
  after.question !== before.question ||
512
544
  after.asked !== before.asked)
513
545
  tellSoon(alive);
514
546
  }
515
- function retiredChat(conversation, list) {
547
+ function retiredChat(conversation, listing) {
516
548
  if (!conversation.startsWith(NEW_CHAT))
517
549
  return false;
518
550
  const agent = conversation.slice(NEW_CHAT.length);
519
- return list.some((entry) => entry.agent === agent && entry.agentRetired);
551
+ return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
520
552
  }
521
553
  function live(alive, conversation, change) {
522
554
  alive.factsHeard(conversation, FACTS.filter((one) => one in change));
@@ -536,7 +568,6 @@ function openingEnded(alive) {
536
568
  options: facts.has('options') ? QUIET.options : held.options,
537
569
  starting: facts.has('starting') ? QUIET.starting : held.starting,
538
570
  state: facts.has('state') ? QUIET.state : held.state,
539
- link: facts.has('link') ? QUIET.link : held.link,
540
571
  deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
541
572
  deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
542
573
  });
@@ -569,19 +600,13 @@ function handReplicated(alive) {
569
600
  }
570
601
  async function remove(alive, leaving) {
571
602
  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);
603
+ const kept = new Set(await local.dropConversations(leaving));
579
604
  const changed = [];
580
605
  for (const conversation of leaving) {
581
606
  if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
582
607
  changed.push(conversation);
583
608
  }
584
- shownDraft(alive, conversation, null);
609
+ heldInViews(alive, conversation, { draft: null, dismissed: null });
585
610
  alive.forget(conversation);
586
611
  setLive(alive, conversation, null);
587
612
  await slide(alive, local, conversation, null);
@@ -610,7 +635,7 @@ async function readsOf(local, conversations) {
610
635
  return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
611
636
  }
612
637
  function retiredDrafts(alive, list) {
613
- if (!list.some((entry) => entry.agentRetired))
638
+ if (!list.agents.some((agent) => agent.retired_at !== null))
614
639
  return;
615
640
  void alive.deps
616
641
  .local()
@@ -774,10 +799,6 @@ function heard(alive, event) {
774
799
  live(alive, conversation, { state: structuredClone(event.state) });
775
800
  return;
776
801
  }
777
- if (event.kind === 'link') {
778
- live(alive, conversation, { link: { connected: event.connected } });
779
- return;
780
- }
781
802
  if (event.kind === 'deliveries') {
782
803
  live(alive, conversation, {
783
804
  deliveryWaiting: [...event.waiting],
@@ -806,19 +827,27 @@ function heard(alive, event) {
806
827
  emit(alive, conversation);
807
828
  }
808
829
  async function kept(alive, local, conversation, following) {
809
- const shown = following === null || empty(following) ? null : following;
810
- if (shown === null)
830
+ const draft = following === null || empty(following) ? null : following;
831
+ if (draft === null)
811
832
  await local.dropChatDraft(conversation);
812
833
  else
813
- await local.keepChatDrafts([shown]);
814
- shownDraft(alive, conversation, shown);
834
+ await local.keepChatDrafts([draft]);
835
+ heldInViews(alive, conversation, { draft });
815
836
  }
816
- function shownDraft(alive, conversation, draft) {
837
+ function heldInViews(alive, conversation, held) {
817
838
  for (const view of alive.views()) {
818
839
  if (view.conversation === conversation)
819
- view.held.set({ draft });
840
+ view.held.set(held);
820
841
  }
821
842
  }
843
+ async function factOf(local, name) {
844
+ return Object.fromEntries((await local.conversationFacts())
845
+ .filter((fact) => fact.name === name)
846
+ .map(({ conversation, value }) => [conversation, value]));
847
+ }
848
+ async function dismissedIn(local, conversation) {
849
+ return (await factOf(local, 'dismissedSuggestion'))[conversation] ?? null;
850
+ }
822
851
  async function draftAt(local, conversation) {
823
852
  return (await local.chatDraft(conversation)) ?? undefined;
824
853
  }
@@ -849,9 +878,9 @@ function moved(alive, agent, operation, to) {
849
878
  : [{ ...unsent, conversation: to }];
850
879
  const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
851
880
  await local.keepChatDrafts([left, ...taken]);
852
- shownDraft(alive, from, left);
881
+ heldInViews(alive, from, { draft: left });
853
882
  for (const one of taken)
854
- shownDraft(alive, to, one);
883
+ heldInViews(alive, to, { draft: one });
855
884
  alive.deps.publish(conversationChangeSet([from, to]));
856
885
  });
857
886
  }
@@ -882,13 +911,10 @@ async function submitted(alive, conversation, operation, draft) {
882
911
  });
883
912
  return submission;
884
913
  }
885
- async function dispatched(alive, conversation, submission) {
914
+ async function dispatched(alive, conversation, submission, resent = false) {
886
915
  const dispatch = alive.sendingBegan(submission.operation);
887
916
  try {
888
- const result = await invoke(alive, 'conversations/send', conversation, {
889
- operation_id: submission.operation,
890
- text: submission.text,
891
- });
917
+ const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
892
918
  dispatch.set({ answered: result.kind !== 'transport-uncertainty' });
893
919
  if (result.kind === 'revoked-authorization')
894
920
  return result;
@@ -896,6 +922,7 @@ async function dispatched(alive, conversation, submission) {
896
922
  alive.deps.unanswered();
897
923
  return result;
898
924
  }
925
+ alive.deps.heard(submission.operation, resent);
899
926
  const turn = answered(result, 'message_id');
900
927
  await withDraft(alive, conversation, async (current, local) => {
901
928
  const held = current?.submitted?.find((one) => one.operation === submission.operation);
@@ -915,11 +942,12 @@ async function dispatched(alive, conversation, submission) {
915
942
  alive.sendingEnded(submission.operation, dispatch);
916
943
  }
917
944
  }
918
- function invoke(alive, name, conversation, extra = { operation_id: changeBatchIdentity() }) {
919
- return alive.deps.call(name, { conversation_id: conversation, ...extra });
945
+ function invoke(alive, name, conversation, operation, extra = {}, attempt) {
946
+ return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
920
947
  }
921
- export function conversationSurface(alive) {
948
+ export function conversationSurface(alive, files) {
922
949
  return {
950
+ ...files,
923
951
  list() {
924
952
  return new Promise((settle) => {
925
953
  const answer = (listed) => {
@@ -937,7 +965,12 @@ export function conversationSurface(alive) {
937
965
  return alive.deps.durably(async (local) => {
938
966
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
939
967
  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)));
968
+ return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
969
+ draft: (await local.chatDraft(conversation)) ?? null,
970
+ ended: await endedIn(alive, conversation),
971
+ dismissed: await dismissedIn(local, conversation),
972
+ pins: (await local.facts()).chatPins,
973
+ }));
941
974
  });
942
975
  },
943
976
  async create(input) {
@@ -945,7 +978,7 @@ export function conversationSurface(alive) {
945
978
  const conversation = answered(result, 'conversation_id');
946
979
  if (conversation === null)
947
980
  return result;
948
- const listed = (await heldList(alive)) ?? [];
981
+ const listed = (await heldListing(alive))?.conversations ?? [];
949
982
  if (!listed.some((entry) => entry.conversation === conversation)) {
950
983
  alive.creating(conversation);
951
984
  }
@@ -974,25 +1007,21 @@ export function conversationSurface(alive) {
974
1007
  }
975
1008
  return OFFLINE;
976
1009
  },
977
- answer(conversation, answer) {
978
- return invoke(alive, 'conversations/interaction/answer', conversation, {
979
- operation_id: changeBatchIdentity(),
980
- ...answer,
981
- });
1010
+ answer(conversation, answer, operation) {
1011
+ return invoke(alive, 'conversations/interaction/answer', conversation, operation, answer);
982
1012
  },
983
- interrupt(conversation) {
984
- return invoke(alive, 'conversations/interrupt', conversation);
1013
+ interrupt(conversation, operation) {
1014
+ return invoke(alive, 'conversations/interrupt', conversation, operation);
985
1015
  },
986
- kill(conversation) {
987
- return invoke(alive, 'conversations/kill', conversation);
1016
+ kill(conversation, operation) {
1017
+ return invoke(alive, 'conversations/kill', conversation, operation);
988
1018
  },
989
- delete(conversation) {
990
- return invoke(alive, 'conversations/delete', conversation);
1019
+ delete(conversation, operation) {
1020
+ return invoke(alive, 'conversations/delete', conversation, operation);
991
1021
  },
992
1022
  takeOut(conversation, message, operation) {
993
- return invoke(alive, 'conversations/take-out', conversation, {
1023
+ return invoke(alive, 'conversations/take-out', conversation, operation, {
994
1024
  message_id: message,
995
- operation_id: operation,
996
1025
  });
997
1026
  },
998
1027
  decide({ request, room, message }, decision, operation) {
@@ -1005,55 +1034,63 @@ export function conversationSurface(alive) {
1005
1034
  });
1006
1035
  },
1007
1036
  rename(conversation, name, operation) {
1008
- return invoke(alive, 'conversations/rename', conversation, { name, operation_id: operation });
1037
+ return invoke(alive, 'conversations/rename', conversation, operation, { name });
1009
1038
  },
1010
- option(conversation, option, value, operation) {
1011
- return invoke(alive, 'conversations/option/set', conversation, {
1012
- option,
1013
- value,
1014
- operation_id: operation,
1015
- });
1039
+ set(conversation, settings, operation) {
1040
+ return invoke(alive, 'conversations/set', conversation, operation, settings);
1016
1041
  },
1017
1042
  retry(conversation, message, operation) {
1018
- return invoke(alive, 'conversations/retry', conversation, {
1043
+ return invoke(alive, 'conversations/retry', conversation, operation, {
1019
1044
  message_id: message,
1020
- operation_id: operation,
1021
1045
  });
1022
1046
  },
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]));
1047
+ async pin(figures) {
1048
+ const pins = [...figures];
1049
+ await alive.deps.durably((local) => local.fact('chatPins', pins));
1050
+ const views = [...alive.views()];
1051
+ for (const view of views)
1052
+ view.held.set({ pins });
1053
+ for (const conversation of new Set(views.map((view) => view.conversation))) {
1054
+ emit(alive, conversation);
1055
+ }
1028
1056
  },
1029
- async openedTurns() {
1030
- return (await (await alive.deps.local()).facts()).openedTurns;
1057
+ async openTurn(conversation, turn) {
1058
+ await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
1059
+ tellList(alive);
1031
1060
  },
1032
- openTurn(conversation, turn) {
1061
+ dismissSuggestion(conversation, suggestion) {
1033
1062
  return alive.deps.durably(async (local) => {
1034
- const { openedTurns } = await local.facts();
1035
- await local.fact('openedTurns', { ...openedTurns, [conversation]: turn });
1063
+ if ((await dismissedIn(local, conversation)) === suggestion)
1064
+ return;
1065
+ await local.keepConversationFact({
1066
+ conversation,
1067
+ name: 'dismissedSuggestion',
1068
+ value: suggestion,
1069
+ });
1070
+ heldInViews(alive, conversation, { dismissed: suggestion });
1071
+ alive.deps.publish(conversationChangeSet([conversation]));
1036
1072
  });
1037
1073
  },
1038
1074
  };
1039
1075
  }
1076
+ function rewritten(alive, conversation, text, revision = chatDraftRevision()) {
1077
+ return withDraft(alive, conversation, (current) => ({
1078
+ conversation,
1079
+ text: text(current?.text ?? ''),
1080
+ revision,
1081
+ ...(current === undefined ? {} : pending(current)),
1082
+ }));
1083
+ }
1040
1084
  export function chatDraftSurface(alive) {
1041
1085
  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
- }));
1086
+ write(conversation, draft, revision) {
1087
+ return rewritten(alive, conversation, () => draft.text, revision);
1049
1088
  },
1050
1089
  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
- }));
1090
+ return rewritten(alive, conversation, (held) => joinedDraft(draft.text, held));
1091
+ },
1092
+ append(conversation, draft) {
1093
+ return rewritten(alive, conversation, (held) => joinedDraft(held, draft.text));
1057
1094
  },
1058
1095
  discard(conversation) {
1059
1096
  return withDraft(alive, conversation, (current) => current === undefined
@@ -1063,31 +1100,37 @@ export function chatDraftSurface(alive) {
1063
1100
  };
1064
1101
  }
1065
1102
  export async function conversationsOpened(alive, local) {
1066
- const { conversationList, conversationCursor } = await local.facts();
1067
- if (conversationList === null || alive.known())
1103
+ const { conversationList, agentList, conversationCursor } = await local.facts();
1104
+ if (conversationList === null || agentList === null)
1105
+ return;
1106
+ alive.held.set({ listHeld: true });
1107
+ if (alive.known())
1068
1108
  return;
1069
1109
  alive.deps.stream()?.hold(conversationCursor);
1070
1110
  conversationsLearned(alive);
1071
1111
  }
1112
+ export function reconcileOpening(alive) {
1113
+ alive.held.set({ openingRead: true });
1114
+ return reconcileConversations(alive);
1115
+ }
1072
1116
  export async function reconcileConversations(alive) {
1073
1117
  if (!alive.known())
1074
1118
  return;
1075
1119
  const local = await alive.deps.local();
1076
- const [held, kept, { conversationList }] = await Promise.all([
1120
+ const [held, stored, { conversationList, agentList }] = await Promise.all([
1077
1121
  local.conversations(),
1078
- local.chatDrafts(),
1122
+ local.storedConversations(),
1079
1123
  local.facts(),
1080
1124
  ]);
1081
1125
  const list = conversationList ?? [];
1126
+ const listing = { conversations: list, agents: agentList ?? [] };
1082
1127
  const entries = new Map(list.map((entry) => [entry.conversation, entry]));
1083
1128
  const named = new Set(entries.keys());
1084
1129
  const reads = new Map(held.map((one) => [one.conversation, one]));
1085
1130
  const { replicated } = alive.held.now();
1086
- const leaving = [
1087
- ...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
1088
- ].filter((conversation) => !named.has(conversation) &&
1131
+ const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
1089
1132
  !alive.isCreating(conversation) &&
1090
- (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, list)));
1133
+ (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
1091
1134
  for (const conversation of named) {
1092
1135
  if (!replicated.has(conversation) &&
1093
1136
  missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
@@ -1122,6 +1165,17 @@ export async function catchUpConversations(alive, progress) {
1122
1165
  if (!alive.current())
1123
1166
  progress.complete = false;
1124
1167
  }
1168
+ export async function holdsSubmission(alive, operation) {
1169
+ if (alive.sending(operation))
1170
+ return true;
1171
+ const local = await alive.deps.local();
1172
+ for (const { conversation } of await local.chatDrafts()) {
1173
+ const held = (await local.chatDraft(conversation))?.submitted;
1174
+ if (held?.some((one) => one.operation === operation && one.turn === null) === true)
1175
+ return true;
1176
+ }
1177
+ return false;
1178
+ }
1125
1179
  export async function resendConversations(alive, progress) {
1126
1180
  const local = await alive.deps.local();
1127
1181
  const tried = new Set();
@@ -1133,7 +1187,7 @@ export async function resendConversations(alive, progress) {
1133
1187
  if (alive.deps.closed())
1134
1188
  return;
1135
1189
  tried.add(submission.operation);
1136
- const result = await dispatched(alive, conversation, submission);
1190
+ const result = await dispatched(alive, conversation, submission, true);
1137
1191
  if (result.kind === 'revoked-authorization')
1138
1192
  return;
1139
1193
  if (result.kind === 'transport-uncertainty') {
@@ -1153,22 +1207,25 @@ export function watchConversation(alive, conversation, options, deliver) {
1153
1207
  const { view, watcher } = alive.viewJoined(key, conversation, asked, deliver);
1154
1208
  const { held } = view;
1155
1209
  const reading = new AbortController();
1156
- void untilAnswered(() => alive.deps.durably(async (local) => {
1210
+ void untilAnswered(retrying(alive.deps.retries, 'reading', `window ${key}`, () => alive.deps.durably(async (local) => {
1157
1211
  if (held.now().window !== null)
1158
1212
  return;
1159
1213
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
1160
1214
  held.set({ draft: (await local.chatDraft(conversation)) ?? null });
1161
1215
  held.set({ ended: await endedIn(alive, conversation) });
1216
+ held.set({ dismissed: await dismissedIn(local, conversation) });
1217
+ held.set({ pins: (await local.facts()).chatPins });
1162
1218
  held.set({ window: messages });
1163
1219
  held.set({ more });
1164
1220
  held.set({ total: asked.total ? await local.messageCount(conversation) : null });
1165
- }), reading.signal)
1221
+ })), reading.signal)
1166
1222
  .then(() => {
1167
1223
  if (alive.deps.closed() || !view.admit(watcher))
1168
1224
  return;
1169
- const { window, draft, ended } = held.now();
1170
- const shown = window ?? [];
1171
- watcher.notify(viewOf(alive, conversation, shown, sharedFrame(view, shown), draft, ended));
1225
+ const now = held.now();
1226
+ const shown = now.window ?? [];
1227
+ const frame = sharedFrame(view, shown);
1228
+ watcher.notify(viewOf(alive, conversation, shown, frame, now));
1172
1229
  })
1173
1230
  .catch(() => { });
1174
1231
  return () => {
@@ -1184,9 +1241,13 @@ export function watchConversationList(alive, deliver) {
1184
1241
  export function watchConversationAgents(alive, deliver) {
1185
1242
  alive.agentListeners.join(deliver);
1186
1243
  conversationsLearned(alive);
1187
- readAgents(alive);
1188
1244
  return () => alive.agentListeners.leave(deliver);
1189
1245
  }
1246
+ export function watchListedAgents(alive, deliver) {
1247
+ alive.listedListeners.join(deliver);
1248
+ conversationsLearned(alive);
1249
+ return () => alive.listedListeners.leave(deliver);
1250
+ }
1190
1251
  export function conversationsChanged(alive, set) {
1191
1252
  for (const conversation of set.conversations)
1192
1253
  emit(alive, conversation);
@@ -1198,26 +1259,32 @@ export function receiveConversationEvent(alive, event) {
1198
1259
  if (event.whole)
1199
1260
  alive.relistBegun();
1200
1261
  if (alive.relisting())
1201
- alive.relistHeard(event.entries);
1262
+ alive.relistHeard(event.entries, event.agents);
1202
1263
  if (event.more && alive.relisting())
1203
1264
  return;
1204
1265
  const whole = alive.relistTaken();
1205
1266
  listChanged(alive, {
1206
1267
  replacing: whole !== null,
1207
- set: whole === null ? event.entries : [...whole.values()],
1268
+ set: whole === null ? event.entries : [...whole.conversations.values()],
1269
+ agents: whole === null ? event.agents : [...whole.agents.values()],
1208
1270
  gone: null,
1209
1271
  ...(event.more ? { paged: true } : { cursor: event.cursor }),
1210
1272
  });
1211
1273
  return;
1212
1274
  }
1213
1275
  if (event.kind === 'listed') {
1214
- alive.relistHeard([event.entry]);
1215
- listChanged(alive, { replacing: false, set: [event.entry], gone: null });
1276
+ alive.relistHeard([event.entry], []);
1277
+ listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
1278
+ return;
1279
+ }
1280
+ if (event.kind === 'agent') {
1281
+ alive.relistHeard([], [event.agent]);
1282
+ listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
1216
1283
  return;
1217
1284
  }
1218
1285
  if (event.kind === 'unlisted') {
1219
1286
  alive.relistDropped(event.conversation);
1220
- listChanged(alive, { replacing: false, set: [], gone: event.conversation });
1287
+ listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
1221
1288
  return;
1222
1289
  }
1223
1290
  heard(alive, event);