@agentshouse/mdruntime 0.1.0-cef76ea952695 → 0.1.0-cefb45338245d

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 (295) hide show
  1. package/README.md +21 -19
  2. package/dist/acceptance.d.ts +0 -3
  3. package/dist/acceptance.d.ts.map +1 -1
  4. package/dist/acceptance.js +72 -158
  5. package/dist/act-lanes.d.ts +30 -0
  6. package/dist/act-lanes.d.ts.map +1 -0
  7. package/dist/act-lanes.js +225 -0
  8. package/dist/actions.d.ts +8 -2
  9. package/dist/actions.d.ts.map +1 -1
  10. package/dist/actions.js +174 -75
  11. package/dist/adapter.d.ts +149 -34
  12. package/dist/adapter.d.ts.map +1 -1
  13. package/dist/attached-model.d.ts +0 -1
  14. package/dist/attached-model.d.ts.map +1 -1
  15. package/dist/attached-model.js +2 -7
  16. package/dist/authored.d.ts +88 -0
  17. package/dist/authored.d.ts.map +1 -0
  18. package/dist/authored.js +347 -0
  19. package/dist/binary.d.ts +6 -2
  20. package/dist/binary.d.ts.map +1 -1
  21. package/dist/binary.js +10 -3
  22. package/dist/bootstrap.d.ts +1 -1
  23. package/dist/bootstrap.d.ts.map +1 -1
  24. package/dist/bootstrap.js +6 -19
  25. package/dist/chain.d.ts +1 -1
  26. package/dist/chain.d.ts.map +1 -1
  27. package/dist/chain.js +5 -2
  28. package/dist/change-set.d.ts +4 -0
  29. package/dist/change-set.d.ts.map +1 -1
  30. package/dist/change-set.js +6 -0
  31. package/dist/change.d.ts +6 -2
  32. package/dist/change.d.ts.map +1 -1
  33. package/dist/change.js +3 -0
  34. package/dist/chat-types.d.ts +0 -2
  35. package/dist/chat-types.d.ts.map +1 -1
  36. package/dist/chat-types.js +2 -4
  37. package/dist/client.d.ts +22 -23
  38. package/dist/client.d.ts.map +1 -1
  39. package/dist/client.js +51 -66
  40. package/dist/collection.d.ts +27 -4
  41. package/dist/collection.d.ts.map +1 -1
  42. package/dist/collection.js +34 -10
  43. package/dist/column.d.ts +5 -0
  44. package/dist/column.d.ts.map +1 -0
  45. package/dist/column.js +9 -0
  46. package/dist/compile.d.ts +4 -1
  47. package/dist/compile.d.ts.map +1 -1
  48. package/dist/compile.js +87 -43
  49. package/dist/connection.d.ts +1 -1
  50. package/dist/connection.d.ts.map +1 -1
  51. package/dist/connection.js +36 -27
  52. package/dist/context.d.ts.map +1 -1
  53. package/dist/context.js +1 -1
  54. package/dist/conversation-live.d.ts +25 -11
  55. package/dist/conversation-live.d.ts.map +1 -1
  56. package/dist/conversation-live.js +23 -11
  57. package/dist/conversation-row.d.ts +8 -1
  58. package/dist/conversation-row.d.ts.map +1 -1
  59. package/dist/conversation-row.js +20 -7
  60. package/dist/conversation.d.ts +43 -11
  61. package/dist/conversation.d.ts.map +1 -1
  62. package/dist/conversation.js +312 -184
  63. package/dist/declaration.d.ts +10 -0
  64. package/dist/declaration.d.ts.map +1 -0
  65. package/dist/declaration.js +24 -0
  66. package/dist/discovery.d.ts +3 -1
  67. package/dist/discovery.d.ts.map +1 -1
  68. package/dist/discovery.js +47 -47
  69. package/dist/download.d.ts +6 -0
  70. package/dist/download.d.ts.map +1 -0
  71. package/dist/download.js +42 -0
  72. package/dist/durability.d.ts +5 -0
  73. package/dist/durability.d.ts.map +1 -1
  74. package/dist/durability.js +7 -0
  75. package/dist/entry.d.ts +22 -1
  76. package/dist/entry.d.ts.map +1 -1
  77. package/dist/entry.js +91 -34
  78. package/dist/expectation.d.ts +25 -14
  79. package/dist/expectation.d.ts.map +1 -1
  80. package/dist/expectation.js +51 -20
  81. package/dist/failure.d.ts +2 -0
  82. package/dist/failure.d.ts.map +1 -1
  83. package/dist/failure.js +6 -1
  84. package/dist/figures.d.ts.map +1 -1
  85. package/dist/figures.js +4 -2
  86. package/dist/file.d.ts +1 -1
  87. package/dist/file.d.ts.map +1 -1
  88. package/dist/file.js +3 -2
  89. package/dist/host.d.ts +24 -4
  90. package/dist/host.d.ts.map +1 -1
  91. package/dist/host.js +108 -32
  92. package/dist/house-query.d.ts +24 -0
  93. package/dist/house-query.d.ts.map +1 -0
  94. package/dist/house-query.js +102 -0
  95. package/dist/index.d.ts +23 -14
  96. package/dist/index.d.ts.map +1 -1
  97. package/dist/index.js +16 -8
  98. package/dist/install.d.ts +10 -6
  99. package/dist/install.d.ts.map +1 -1
  100. package/dist/install.js +89 -108
  101. package/dist/lifecycle.d.ts +2 -2
  102. package/dist/lifecycle.d.ts.map +1 -1
  103. package/dist/lifecycle.js +74 -54
  104. package/dist/listing.d.ts +29 -22
  105. package/dist/listing.d.ts.map +1 -1
  106. package/dist/listing.js +71 -79
  107. package/dist/live.d.ts +19 -3
  108. package/dist/live.d.ts.map +1 -1
  109. package/dist/live.js +94 -36
  110. package/dist/loaded.d.ts +7 -0
  111. package/dist/loaded.d.ts.map +1 -0
  112. package/dist/loaded.js +46 -0
  113. package/dist/locks.d.ts +2 -4
  114. package/dist/locks.d.ts.map +1 -1
  115. package/dist/locks.js +10 -38
  116. package/dist/lost.d.ts.map +1 -1
  117. package/dist/lost.js +11 -23
  118. package/dist/media.d.ts +19 -3
  119. package/dist/media.d.ts.map +1 -1
  120. package/dist/media.js +167 -33
  121. package/dist/memory.d.ts +10 -4
  122. package/dist/memory.d.ts.map +1 -1
  123. package/dist/memory.js +98 -37
  124. package/dist/messages.d.ts +17 -3
  125. package/dist/messages.d.ts.map +1 -1
  126. package/dist/messages.js +34 -13
  127. package/dist/modal.d.ts +2 -0
  128. package/dist/modal.d.ts.map +1 -0
  129. package/dist/modal.js +11 -0
  130. package/dist/model.d.ts +4 -3
  131. package/dist/model.d.ts.map +1 -1
  132. package/dist/model.js +6 -5
  133. package/dist/models.d.ts +4 -8
  134. package/dist/models.d.ts.map +1 -1
  135. package/dist/models.js +94 -138
  136. package/dist/name.d.ts +0 -1
  137. package/dist/name.d.ts.map +1 -1
  138. package/dist/name.js +3 -7
  139. package/dist/observation.d.ts +29 -12
  140. package/dist/observation.d.ts.map +1 -1
  141. package/dist/observation.js +206 -69
  142. package/dist/online.d.ts +7 -0
  143. package/dist/online.d.ts.map +1 -0
  144. package/dist/online.js +29 -0
  145. package/dist/opened.d.ts +1 -1
  146. package/dist/opened.d.ts.map +1 -1
  147. package/dist/opened.js +2 -2
  148. package/dist/opening.d.ts.map +1 -1
  149. package/dist/opening.js +21 -12
  150. package/dist/outcome.d.ts +24 -4
  151. package/dist/outcome.d.ts.map +1 -1
  152. package/dist/outcome.js +33 -3
  153. package/dist/overlay.d.ts +9 -5
  154. package/dist/overlay.d.ts.map +1 -1
  155. package/dist/overlay.js +37 -24
  156. package/dist/page-metadata.d.ts +8 -0
  157. package/dist/page-metadata.d.ts.map +1 -0
  158. package/dist/page-metadata.js +19 -0
  159. package/dist/parts.d.ts +4 -9
  160. package/dist/parts.d.ts.map +1 -1
  161. package/dist/parts.js +30 -15
  162. package/dist/preparation.d.ts +33 -7
  163. package/dist/preparation.d.ts.map +1 -1
  164. package/dist/preparation.js +207 -96
  165. package/dist/presence.d.ts +58 -0
  166. package/dist/presence.d.ts.map +1 -0
  167. package/dist/presence.js +231 -0
  168. package/dist/queries.d.ts +2 -2
  169. package/dist/queries.d.ts.map +1 -1
  170. package/dist/queries.js +136 -78
  171. package/dist/query.d.ts +2 -2
  172. package/dist/questions.d.ts +1 -5
  173. package/dist/questions.d.ts.map +1 -1
  174. package/dist/questions.js +3 -8
  175. package/dist/queue.d.ts +40 -0
  176. package/dist/queue.d.ts.map +1 -0
  177. package/dist/queue.js +480 -0
  178. package/dist/reach.d.ts +15 -6
  179. package/dist/reach.d.ts.map +1 -1
  180. package/dist/reach.js +182 -38
  181. package/dist/react.d.ts +11 -5
  182. package/dist/react.d.ts.map +1 -1
  183. package/dist/react.js +28 -5
  184. package/dist/readiness.d.ts +20 -4
  185. package/dist/readiness.d.ts.map +1 -1
  186. package/dist/readiness.js +17 -10
  187. package/dist/reads.d.ts +4 -2
  188. package/dist/reads.d.ts.map +1 -1
  189. package/dist/reads.js +9 -4
  190. package/dist/recovery.d.ts +4 -1
  191. package/dist/recovery.d.ts.map +1 -1
  192. package/dist/recovery.js +31 -8
  193. package/dist/reference-forms.d.ts +4 -0
  194. package/dist/reference-forms.d.ts.map +1 -0
  195. package/dist/reference-forms.js +74 -0
  196. package/dist/refresh.d.ts +1 -1
  197. package/dist/refresh.js +6 -6
  198. package/dist/refusal.d.ts.map +1 -1
  199. package/dist/refusal.js +2 -4
  200. package/dist/replica.d.ts +5 -11
  201. package/dist/replica.d.ts.map +1 -1
  202. package/dist/replica.js +16 -18
  203. package/dist/retried.d.ts +30 -0
  204. package/dist/retried.d.ts.map +1 -0
  205. package/dist/retried.js +72 -0
  206. package/dist/room-draft.d.ts +30 -5
  207. package/dist/room-draft.d.ts.map +1 -1
  208. package/dist/room-draft.js +275 -65
  209. package/dist/room-drafts.d.ts.map +1 -1
  210. package/dist/room-drafts.js +11 -6
  211. package/dist/room-list.d.ts +10 -0
  212. package/dist/room-list.d.ts.map +1 -0
  213. package/dist/room-list.js +45 -0
  214. package/dist/rows.d.ts +11 -2
  215. package/dist/rows.d.ts.map +1 -1
  216. package/dist/rows.js +27 -14
  217. package/dist/running.d.ts +5 -0
  218. package/dist/running.d.ts.map +1 -0
  219. package/dist/running.js +10 -0
  220. package/dist/runtime.d.ts +13 -19
  221. package/dist/runtime.d.ts.map +1 -1
  222. package/dist/save.d.ts +43 -90
  223. package/dist/save.d.ts.map +1 -1
  224. package/dist/save.js +314 -223
  225. package/dist/saves.d.ts +6 -42
  226. package/dist/saves.d.ts.map +1 -1
  227. package/dist/saves.js +176 -718
  228. package/dist/seed.d.ts.map +1 -1
  229. package/dist/seed.js +4 -4
  230. package/dist/shown.d.ts +9 -5
  231. package/dist/shown.d.ts.map +1 -1
  232. package/dist/shown.js +93 -57
  233. package/dist/socket/lanes.d.ts +12 -4
  234. package/dist/socket/lanes.d.ts.map +1 -1
  235. package/dist/socket/lanes.js +34 -8
  236. package/dist/socket/session.d.ts +4 -1
  237. package/dist/socket/session.d.ts.map +1 -1
  238. package/dist/socket/session.js +3 -0
  239. package/dist/socket.d.ts +4 -6
  240. package/dist/socket.d.ts.map +1 -1
  241. package/dist/socket.js +4 -14
  242. package/dist/source.d.ts +7 -7
  243. package/dist/source.d.ts.map +1 -1
  244. package/dist/source.js +15 -2
  245. package/dist/store/installs.d.ts +2 -2
  246. package/dist/store/installs.d.ts.map +1 -1
  247. package/dist/store/installs.js +10 -4
  248. package/dist/store/readiness.d.ts +5 -4
  249. package/dist/store/readiness.d.ts.map +1 -1
  250. package/dist/store/readiness.js +28 -12
  251. package/dist/store/records.d.ts +24 -5
  252. package/dist/store/records.d.ts.map +1 -1
  253. package/dist/store/records.js +68 -22
  254. package/dist/store/rooms-shown.d.ts +8 -0
  255. package/dist/store/rooms-shown.d.ts.map +1 -0
  256. package/dist/store/rooms-shown.js +13 -0
  257. package/dist/store.d.ts +25 -15
  258. package/dist/store.d.ts.map +1 -1
  259. package/dist/store.js +50 -18
  260. package/dist/stored.d.ts +39 -14
  261. package/dist/stored.d.ts.map +1 -1
  262. package/dist/stored.js +217 -59
  263. package/dist/surface.d.ts +14 -8
  264. package/dist/surface.d.ts.map +1 -1
  265. package/dist/surface.js +65 -34
  266. package/dist/sync.d.ts +4 -2
  267. package/dist/sync.d.ts.map +1 -1
  268. package/dist/sync.js +127 -102
  269. package/dist/tables.d.ts +28 -52
  270. package/dist/tables.d.ts.map +1 -1
  271. package/dist/tables.js +95 -326
  272. package/dist/tallies.d.ts.map +1 -1
  273. package/dist/tallies.js +1 -2
  274. package/dist/validation.d.ts +2 -0
  275. package/dist/validation.d.ts.map +1 -1
  276. package/dist/validation.js +51 -11
  277. package/dist/wire.d.ts +71 -12
  278. package/dist/wire.d.ts.map +1 -1
  279. package/dist/wire.js +30 -14
  280. package/package.json +4 -4
  281. package/dist/attempt.d.ts +0 -16
  282. package/dist/attempt.d.ts.map +0 -1
  283. package/dist/attempt.js +0 -70
  284. package/dist/job.d.ts +0 -5
  285. package/dist/job.d.ts.map +0 -1
  286. package/dist/job.js +0 -7
  287. package/dist/log.d.ts +0 -6
  288. package/dist/log.d.ts.map +0 -1
  289. package/dist/log.js +0 -14
  290. package/dist/socket/rooms.d.ts +0 -44
  291. package/dist/socket/rooms.d.ts.map +0 -1
  292. package/dist/socket/rooms.js +0 -90
  293. package/dist/store/fences.d.ts +0 -16
  294. package/dist/store/fences.d.ts.map +0 -1
  295. package/dist/store/fences.js +0 -26
@@ -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,13 +25,17 @@ export function unheldView(conversation) {
24
25
  options: [],
25
26
  starting: null,
26
27
  state: null,
27
- link: null,
28
+ deliveryWaiting: [],
28
29
  deliveryUnknown: [],
29
30
  chatDraft: null,
31
+ dismissedSuggestion: null,
32
+ pins: [],
30
33
  };
31
34
  }
32
35
  export const SESSION_STARTED = 'Session started';
33
36
  const NEW_CHAT = 'new:';
37
+ const LISTING = 'listing';
38
+ export const CATCHING_UP = 'catching-up';
34
39
  export const HISTORY_CONVERSATIONS = 64;
35
40
  export function newChat(agent) {
36
41
  return `${NEW_CHAT}${agent}`;
@@ -74,7 +79,7 @@ function frameOf(asked, messages, more, total) {
74
79
  };
75
80
  }
76
81
  function newestOf(arriving, from) {
77
- return arriving.reduce((top, message) => (top === null || message.position > top ? message.position : top), from);
82
+ return arriving.reduce((top, message) => (top === null || message.change > top ? message.change : top), from);
78
83
  }
79
84
  function acceptedMessage(value) {
80
85
  if (typeof value !== 'object' || value === null)
@@ -83,6 +88,7 @@ function acceptedMessage(value) {
83
88
  if (typeof record.identity !== 'string' ||
84
89
  typeof record.turn !== 'string' ||
85
90
  typeof record.position !== 'string' ||
91
+ typeof record.change !== 'string' ||
86
92
  typeof record.text !== 'string') {
87
93
  return null;
88
94
  }
@@ -90,6 +96,7 @@ function acceptedMessage(value) {
90
96
  identity: record.identity,
91
97
  turn: record.turn,
92
98
  position: record.position,
99
+ change: record.change,
93
100
  text: record.text,
94
101
  message: structuredClone(record.message),
95
102
  };
@@ -191,17 +198,17 @@ function withSubmitted(draft, submitted) {
191
198
  const { submitted: _held, ...unsent } = draft;
192
199
  return submitted.length === 0 ? unsent : { ...unsent, submitted };
193
200
  }
194
- function prepended(draft, said) {
195
- 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');
196
203
  }
197
204
  function returned(draft, submission, others) {
198
205
  return withSubmitted({
199
206
  conversation: draft.conversation,
200
- ...prepended(draft, submission),
207
+ text: joinedDraft(submission.text, draft.text),
201
208
  revision: chatDraftRevision(),
202
209
  }, others);
203
210
  }
204
- function viewOf(alive, conversation, held, frame, draft, ended) {
211
+ function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
205
212
  const facts = alive.liveOf(conversation);
206
213
  return {
207
214
  conversation,
@@ -220,35 +227,44 @@ function viewOf(alive, conversation, held, frame, draft, ended) {
220
227
  options: structuredClone(facts.options),
221
228
  starting: facts.starting,
222
229
  state: sessionOf(facts, held, ended),
223
- link: facts.link === null ? null : { ...facts.link },
230
+ deliveryWaiting: [...facts.deliveryWaiting],
224
231
  deliveryUnknown: [...facts.deliveryUnknown],
225
232
  chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
233
+ dismissedSuggestion: dismissed,
234
+ pins: [...pins],
226
235
  };
227
236
  }
228
- function sessionOf(facts, held, ended) {
237
+ function standing(facts, saved, ended) {
229
238
  if (facts.state !== null)
230
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) {
231
246
  const saved = [...held]
232
247
  .reverse()
233
248
  .map(({ message }) => record(message))
234
249
  .find(({ content }) => isTurn(content));
235
250
  const at = saved === undefined ? null : text(saved, 'accepted_at');
236
- if (saved === undefined || !isTurn(saved.content) || at === null)
237
- return null;
238
- const down = facts.process?.running === false;
239
- 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);
240
254
  }
241
255
  function emit(alive, conversation) {
242
256
  if (alive.deps.closed())
243
257
  return;
244
258
  for (const view of alive.views()) {
245
- const { window, draft, ended } = view.held.now();
259
+ const held = view.held.now();
260
+ const { window } = held;
246
261
  if (view.conversation !== conversation || window === null)
247
262
  continue;
248
263
  const ready = view.ready();
249
264
  if (ready.length === 0)
250
265
  continue;
251
- 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);
252
268
  for (const watcher of ready)
253
269
  watcher.notify(value);
254
270
  }
@@ -284,76 +300,106 @@ function stateOf(alive, conversation) {
284
300
  return facts.turn === null ? 'idle' : 'working';
285
301
  }
286
302
  function rowOf(alive, conversation) {
287
- const { turn, questions } = alive.liveOf(conversation);
303
+ const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
288
304
  return {
289
305
  state: stateOf(alive, conversation),
290
306
  started: turn?.started ?? null,
291
307
  line: turn === null ? null : runningLine(turn.parts),
292
308
  question: openQuestion(questions),
293
309
  asked: questionAsked(questions),
310
+ deliveryWaiting: [...deliveryWaiting],
294
311
  };
295
312
  }
296
313
  async function entries(alive) {
297
- const list = await heldList(alive);
298
- 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)))
299
320
  return null;
300
321
  const held = list.length === 0
301
322
  ? []
302
323
  : await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
303
324
  const rows = new Map(held.map((one) => [one.conversation, one]));
304
- return list.map((entry) => ({
305
- conversation: entry.conversation,
306
- agent: { identity: entry.agent, name: entry.agentName, retired: entry.agentRetired },
307
- name: entry.name,
308
- created: entry.created,
309
- finished: entry.finished,
310
- outcome: entry.outcome,
311
- waiting: entry.waiting,
312
- ...rowOf(alive, entry.conversation),
313
- ...heldFacts(rows.get(entry.conversation), entry),
314
- }));
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
+ });
315
343
  }
316
- async function heldList(alive) {
317
- const stored = (await (await alive.deps.local()).facts()).conversationList;
318
- if (stored !== null)
319
- return stored;
320
- 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: [] };
321
351
  }
322
352
  async function endedIn(alive, conversation) {
323
- const list = await heldList(alive);
324
- 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;
325
362
  }
326
363
  function listChanged(alive, change) {
327
364
  void alive.deps
328
365
  .durably(async (local) => {
329
- const { conversationList, conversationCursor } = await local.facts();
330
- const kept = change.replacing ? [] : (conversationList ?? []);
331
- const held = new Map(kept.map((entry) => [entry.conversation, entry]));
332
- for (const entry of change.set) {
333
- 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)
334
371
  alive.created(entry.conversation);
335
- }
336
372
  if (change.gone !== null)
337
373
  held.delete(change.gone);
338
374
  const list = [...held.values()];
375
+ const agents = [
376
+ ...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
377
+ ];
339
378
  if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
340
379
  await local.fact('conversationList', list);
341
380
  }
381
+ if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
382
+ await local.fact('agentList', agents);
383
+ }
342
384
  if (change.cursor !== undefined) {
343
385
  if (change.cursor !== conversationCursor) {
344
386
  await local.fact('conversationCursor', change.cursor);
345
387
  }
346
388
  alive.deps.stream()?.hold(change.cursor);
347
389
  }
348
- 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 ?? [] };
349
395
  })
350
- .catch(async () => (await (await alive.deps.local()).facts()).conversationList ?? [])
351
- .then((list) => {
396
+ .then((listing) => {
352
397
  if (alive.deps.closed() || change.paged === true)
353
398
  return;
399
+ const list = listing.conversations;
354
400
  endedAnew(alive, list);
355
401
  if (change.cursor !== undefined) {
356
- alive.held.set({ listKnown: true });
402
+ alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
357
403
  settleBehind(alive, list);
358
404
  openingEnded(alive);
359
405
  alive.deps.settled();
@@ -361,11 +407,12 @@ function listChanged(alive, change) {
361
407
  emitList(alive);
362
408
  if (!alive.known())
363
409
  return;
364
- retiredDrafts(alive, list);
365
- const { replicated } = alive.held.now();
366
- if (change.cursor === undefined &&
367
- (list.length !== replicated.size ||
368
- 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) {
369
416
  alive.deps.again();
370
417
  }
371
418
  }, uncaught);
@@ -381,23 +428,23 @@ function endedAnew(alive, list) {
381
428
  emit(alive, view.conversation);
382
429
  }
383
430
  }
384
- function shownList(alive, work) {
385
- const reading = heldList(alive);
431
+ function shownListing(alive, work) {
432
+ const reading = heldListing(alive);
386
433
  alive.inOrder(async () => {
387
- const list = await reading.catch((error) => {
434
+ const listing = await reading.catch((error) => {
388
435
  uncaught(error);
389
436
  return null;
390
437
  });
391
- if (list === null || alive.deps.closed())
438
+ if (listing === null || alive.deps.closed())
392
439
  return;
393
- work(list);
440
+ work(listing);
394
441
  });
395
442
  }
396
443
  async function told(alive) {
397
444
  try {
398
445
  while (alive.held.now().listOwed && !alive.deps.closed()) {
399
446
  alive.held.set({ listOwed: false });
400
- 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);
401
448
  if (alive.deps.closed())
402
449
  return;
403
450
  if (value === null)
@@ -435,75 +482,73 @@ export function conversationsLearned(alive) {
435
482
  return;
436
483
  if (alive.listeners.waiting())
437
484
  tellList(alive);
438
- if (!alive.agentListeners.waiting())
485
+ if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
439
486
  return;
440
- shownList(alive, (list) => alive.agentListeners.welcome(agents(alive, list)));
441
- }
442
- function agents(alive, list) {
443
- const named = new Map();
444
- for (const agent of alive.held.now().listedAgents ?? [])
445
- named.set(agent.agent, agent);
446
- for (const entry of list) {
447
- named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
448
- }
449
- return [...named]
450
- .filter(([, agent]) => !agent.retired)
451
- .map(([identity, agent]) => ({ identity, name: agent.name }))
487
+ shownListing(alive, (listing) => {
488
+ alive.agentListeners.welcome(agentsOf(listing));
489
+ alive.listedListeners.welcome(structuredClone(listing.agents));
490
+ });
491
+ }
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
+ }))
452
507
  .sort((left, right) => left.name === right.name
453
508
  ? left.identity.localeCompare(right.identity)
454
509
  : left.name.localeCompare(right.name));
455
510
  }
456
- function readAgents(alive) {
457
- const stream = alive.deps.stream();
458
- if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
459
- return;
460
- const { agents: read } = stream;
461
- const { agentListeners } = alive;
462
- alive.held.set({ agentsReading: true });
463
- void alive.deps.recovery
464
- .attempt('agents', async () => {
465
- if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
466
- return 'done';
467
- }
468
- const listed = await read();
469
- if (listed === null)
470
- return 'done';
471
- alive.held.set({ listedAgents: listed });
472
- emitAgents(alive);
473
- return 'done';
474
- })
475
- .finally(() => {
476
- alive.held.set({ agentsReading: false });
477
- });
478
- }
479
511
  function emitAgents(alive) {
480
- if (alive.deps.closed() || !alive.agentListeners.told())
512
+ const { agentListeners, listedListeners } = alive;
513
+ if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
481
514
  return;
482
- shownList(alive, (list) => {
483
- const value = agents(alive, list);
515
+ shownListing(alive, (listing) => {
516
+ const value = agentsOf(listing);
484
517
  const shown = JSON.stringify(value);
485
- if (shown === alive.held.now().agentsShown)
486
- return;
487
- alive.held.set({ agentsShown: shown });
488
- 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
+ }
489
527
  });
490
528
  }
529
+ function ran({ state, process }) {
530
+ return JSON.stringify([state?.running ?? null, process?.running ?? null]);
531
+ }
491
532
  function setLive(alive, conversation, next) {
533
+ const was = ran(alive.liveOf(conversation));
492
534
  const before = rowOf(alive, conversation);
493
535
  alive.holdLive(conversation, next);
494
536
  const after = rowOf(alive, conversation);
495
- 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())
496
541
  emitList(alive);
497
542
  else if (after.line !== before.line ||
498
543
  after.question !== before.question ||
499
544
  after.asked !== before.asked)
500
545
  tellSoon(alive);
501
546
  }
502
- function retiredChat(conversation, list) {
547
+ function retiredChat(conversation, listing) {
503
548
  if (!conversation.startsWith(NEW_CHAT))
504
549
  return false;
505
550
  const agent = conversation.slice(NEW_CHAT.length);
506
- return list.some((entry) => entry.agent === agent && entry.agentRetired);
551
+ return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
507
552
  }
508
553
  function live(alive, conversation, change) {
509
554
  alive.factsHeard(conversation, FACTS.filter((one) => one in change));
@@ -523,7 +568,7 @@ function openingEnded(alive) {
523
568
  options: facts.has('options') ? QUIET.options : held.options,
524
569
  starting: facts.has('starting') ? QUIET.starting : held.starting,
525
570
  state: facts.has('state') ? QUIET.state : held.state,
526
- link: facts.has('link') ? QUIET.link : held.link,
571
+ deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
527
572
  deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
528
573
  });
529
574
  emit(alive, conversation);
@@ -555,19 +600,13 @@ function handReplicated(alive) {
555
600
  }
556
601
  async function remove(alive, leaving) {
557
602
  await alive.deps.durably(async (local) => {
558
- const kept = new Set([
559
- ...(await local.conversations(leaving)).map(({ conversation }) => conversation),
560
- ...(await local.chatDrafts())
561
- .filter(({ conversation }) => leaving.includes(conversation))
562
- .map(({ conversation }) => conversation),
563
- ]);
564
- await local.dropConversations(leaving);
603
+ const kept = new Set(await local.dropConversations(leaving));
565
604
  const changed = [];
566
605
  for (const conversation of leaving) {
567
606
  if (kept.has(conversation) || alive.liveHeld(conversation) !== undefined) {
568
607
  changed.push(conversation);
569
608
  }
570
- shownDraft(alive, conversation, null);
609
+ heldInViews(alive, conversation, { draft: null, dismissed: null });
571
610
  alive.forget(conversation);
572
611
  setLive(alive, conversation, null);
573
612
  await slide(alive, local, conversation, null);
@@ -596,7 +635,7 @@ async function readsOf(local, conversations) {
596
635
  return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
597
636
  }
598
637
  function retiredDrafts(alive, list) {
599
- if (!list.some((entry) => entry.agentRetired))
638
+ if (!list.agents.some((agent) => agent.retired_at !== null))
600
639
  return;
601
640
  void alive.deps
602
641
  .local()
@@ -639,14 +678,12 @@ function keep(alive, conversation, message) {
639
678
  if (!alive.held.now().replicated.has(conversation))
640
679
  return;
641
680
  const read = (await readsOf(local, [conversation])).get(conversation)?.read;
642
- const advances = read !== undefined &&
643
- !alive.behind(conversation) &&
644
- (read === null || message.position > read);
681
+ const advances = read !== undefined && !alive.behind(conversation) && (read === null || message.change > read);
645
682
  await sealed(alive, local, conversation, new Set([message.turn]));
646
683
  await local.keepMessages({
647
684
  conversation,
648
685
  messages: [message],
649
- ...(advances ? { read: { at: message.position, partial: false } } : {}),
686
+ ...(advances ? { read: { at: message.change, partial: false } } : {}),
650
687
  });
651
688
  sealTurns(alive, conversation, new Set([message.turn]));
652
689
  await slide(alive, local, conversation, [message]);
@@ -762,18 +799,17 @@ function heard(alive, event) {
762
799
  live(alive, conversation, { state: structuredClone(event.state) });
763
800
  return;
764
801
  }
765
- if (event.kind === 'link') {
766
- live(alive, conversation, { link: { connected: event.connected } });
767
- return;
768
- }
769
802
  if (event.kind === 'deliveries') {
770
- live(alive, conversation, { deliveryUnknown: [...event.unknown] });
803
+ live(alive, conversation, {
804
+ deliveryWaiting: [...event.waiting],
805
+ deliveryUnknown: [...event.unknown],
806
+ });
771
807
  return;
772
808
  }
773
809
  const arriving = acceptedMessage(event.message);
774
810
  if (arriving === null)
775
811
  return;
776
- alive.heardAt(conversation, arriving.position);
812
+ alive.heardAt(conversation, arriving.change);
777
813
  if (alive.held.now().replicated.has(conversation)) {
778
814
  if (alive.deps.full()) {
779
815
  alive.gapOpened(conversation);
@@ -791,19 +827,27 @@ function heard(alive, event) {
791
827
  emit(alive, conversation);
792
828
  }
793
829
  async function kept(alive, local, conversation, following) {
794
- const shown = following === null || empty(following) ? null : following;
795
- if (shown === null)
830
+ const draft = following === null || empty(following) ? null : following;
831
+ if (draft === null)
796
832
  await local.dropChatDraft(conversation);
797
833
  else
798
- await local.keepChatDrafts([shown]);
799
- shownDraft(alive, conversation, shown);
834
+ await local.keepChatDrafts([draft]);
835
+ heldInViews(alive, conversation, { draft });
800
836
  }
801
- function shownDraft(alive, conversation, draft) {
837
+ function heldInViews(alive, conversation, held) {
802
838
  for (const view of alive.views()) {
803
839
  if (view.conversation === conversation)
804
- view.held.set({ draft });
840
+ view.held.set(held);
805
841
  }
806
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
+ }
807
851
  async function draftAt(local, conversation) {
808
852
  return (await local.chatDraft(conversation)) ?? undefined;
809
853
  }
@@ -834,9 +878,9 @@ function moved(alive, agent, operation, to) {
834
878
  : [{ ...unsent, conversation: to }];
835
879
  const left = { ...(taken.length === 0 ? unsent : blank), moves: [...earlier, operation] };
836
880
  await local.keepChatDrafts([left, ...taken]);
837
- shownDraft(alive, from, left);
881
+ heldInViews(alive, from, { draft: left });
838
882
  for (const one of taken)
839
- shownDraft(alive, to, one);
883
+ heldInViews(alive, to, { draft: one });
840
884
  alive.deps.publish(conversationChangeSet([from, to]));
841
885
  });
842
886
  }
@@ -867,13 +911,10 @@ async function submitted(alive, conversation, operation, draft) {
867
911
  });
868
912
  return submission;
869
913
  }
870
- async function dispatched(alive, conversation, submission) {
914
+ async function dispatched(alive, conversation, submission, resent = false) {
871
915
  const dispatch = alive.sendingBegan(submission.operation);
872
916
  try {
873
- const result = await invoke(alive, 'conversations/send', conversation, {
874
- operation_id: submission.operation,
875
- text: submission.text,
876
- });
917
+ const result = await invoke(alive, 'conversations/send', conversation, submission.operation, { text: submission.text }, { step: 'sending', instance: `message ${submission.operation}` });
877
918
  dispatch.set({ answered: result.kind !== 'transport-uncertainty' });
878
919
  if (result.kind === 'revoked-authorization')
879
920
  return result;
@@ -881,6 +922,7 @@ async function dispatched(alive, conversation, submission) {
881
922
  alive.deps.unanswered();
882
923
  return result;
883
924
  }
925
+ alive.deps.heard(submission.operation, resent);
884
926
  const turn = answered(result, 'message_id');
885
927
  await withDraft(alive, conversation, async (current, local) => {
886
928
  const held = current?.submitted?.find((one) => one.operation === submission.operation);
@@ -900,11 +942,12 @@ async function dispatched(alive, conversation, submission) {
900
942
  alive.sendingEnded(submission.operation, dispatch);
901
943
  }
902
944
  }
903
- function invoke(alive, name, conversation, extra = { operation_id: changeBatchIdentity() }) {
904
- 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);
905
947
  }
906
- export function conversationSurface(alive) {
948
+ export function conversationSurface(alive, files) {
907
949
  return {
950
+ ...files,
908
951
  list() {
909
952
  return new Promise((settle) => {
910
953
  const answer = (listed) => {
@@ -922,7 +965,12 @@ export function conversationSurface(alive) {
922
965
  return alive.deps.durably(async (local) => {
923
966
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
924
967
  const total = asked.total ? await local.messageCount(conversation, phrase) : null;
925
- 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
+ }));
926
974
  });
927
975
  },
928
976
  async create(input) {
@@ -930,7 +978,7 @@ export function conversationSurface(alive) {
930
978
  const conversation = answered(result, 'conversation_id');
931
979
  if (conversation === null)
932
980
  return result;
933
- const listed = (await heldList(alive)) ?? [];
981
+ const listed = (await heldListing(alive))?.conversations ?? [];
934
982
  if (!listed.some((entry) => entry.conversation === conversation)) {
935
983
  alive.creating(conversation);
936
984
  }
@@ -959,40 +1007,90 @@ export function conversationSurface(alive) {
959
1007
  }
960
1008
  return OFFLINE;
961
1009
  },
962
- answer(conversation, answer) {
963
- return invoke(alive, 'conversations/interaction/answer', conversation, {
964
- operation_id: changeBatchIdentity(),
965
- ...answer,
1010
+ answer(conversation, answer, operation) {
1011
+ return invoke(alive, 'conversations/interaction/answer', conversation, operation, answer);
1012
+ },
1013
+ interrupt(conversation, operation) {
1014
+ return invoke(alive, 'conversations/interrupt', conversation, operation);
1015
+ },
1016
+ kill(conversation, operation) {
1017
+ return invoke(alive, 'conversations/kill', conversation, operation);
1018
+ },
1019
+ delete(conversation, operation) {
1020
+ return invoke(alive, 'conversations/delete', conversation, operation);
1021
+ },
1022
+ takeOut(conversation, message, operation) {
1023
+ return invoke(alive, 'conversations/take-out', conversation, operation, {
1024
+ message_id: message,
1025
+ });
1026
+ },
1027
+ decide({ request, room, message }, decision, operation) {
1028
+ return alive.deps.call('agent-functions/decide', {
1029
+ room_ref: room,
1030
+ request,
1031
+ ...(message === undefined ? {} : { message }),
1032
+ decision,
1033
+ operation_id: operation,
966
1034
  });
967
1035
  },
968
- interrupt(conversation) {
969
- return invoke(alive, 'conversations/interrupt', conversation);
1036
+ rename(conversation, name, operation) {
1037
+ return invoke(alive, 'conversations/rename', conversation, operation, { name });
970
1038
  },
971
- kill(conversation) {
972
- return invoke(alive, 'conversations/kill', conversation);
1039
+ set(conversation, settings, operation) {
1040
+ return invoke(alive, 'conversations/set', conversation, operation, settings);
973
1041
  },
974
- delete(conversation) {
975
- return invoke(alive, 'conversations/delete', conversation);
1042
+ retry(conversation, message, operation) {
1043
+ return invoke(alive, 'conversations/retry', conversation, operation, {
1044
+ message_id: message,
1045
+ });
1046
+ },
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
+ }
1056
+ },
1057
+ async openTurn(conversation, turn) {
1058
+ await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
1059
+ tellList(alive);
1060
+ },
1061
+ dismissSuggestion(conversation, suggestion) {
1062
+ return alive.deps.durably(async (local) => {
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]));
1072
+ });
976
1073
  },
977
1074
  };
978
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
+ }
979
1084
  export function chatDraftSurface(alive) {
980
1085
  return {
981
- write(conversation, draft, revision = chatDraftRevision()) {
982
- return withDraft(alive, conversation, (current) => ({
983
- conversation,
984
- text: draft.text,
985
- revision,
986
- ...(current === undefined ? {} : pending(current)),
987
- }));
1086
+ write(conversation, draft, revision) {
1087
+ return rewritten(alive, conversation, () => draft.text, revision);
988
1088
  },
989
1089
  prepend(conversation, draft) {
990
- return withDraft(alive, conversation, (current) => ({
991
- conversation,
992
- ...(current === undefined ? { text: draft.text } : prepended(current, draft)),
993
- revision: chatDraftRevision(),
994
- ...(current === undefined ? {} : pending(current)),
995
- }));
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));
996
1094
  },
997
1095
  discard(conversation) {
998
1096
  return withDraft(alive, conversation, (current) => current === undefined
@@ -1002,31 +1100,37 @@ export function chatDraftSurface(alive) {
1002
1100
  };
1003
1101
  }
1004
1102
  export async function conversationsOpened(alive, local) {
1005
- const { conversationList, conversationCursor } = await local.facts();
1006
- 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())
1007
1108
  return;
1008
1109
  alive.deps.stream()?.hold(conversationCursor);
1009
1110
  conversationsLearned(alive);
1010
1111
  }
1112
+ export function reconcileOpening(alive) {
1113
+ alive.held.set({ openingRead: true });
1114
+ return reconcileConversations(alive);
1115
+ }
1011
1116
  export async function reconcileConversations(alive) {
1012
1117
  if (!alive.known())
1013
1118
  return;
1014
1119
  const local = await alive.deps.local();
1015
- const [held, kept, { conversationList }] = await Promise.all([
1120
+ const [held, stored, { conversationList, agentList }] = await Promise.all([
1016
1121
  local.conversations(),
1017
- local.chatDrafts(),
1122
+ local.storedConversations(),
1018
1123
  local.facts(),
1019
1124
  ]);
1020
1125
  const list = conversationList ?? [];
1126
+ const listing = { conversations: list, agents: agentList ?? [] };
1021
1127
  const entries = new Map(list.map((entry) => [entry.conversation, entry]));
1022
1128
  const named = new Set(entries.keys());
1023
1129
  const reads = new Map(held.map((one) => [one.conversation, one]));
1024
1130
  const { replicated } = alive.held.now();
1025
- const leaving = [
1026
- ...new Set([...replicated, ...reads.keys(), ...kept.map(({ conversation }) => conversation)]),
1027
- ].filter((conversation) => !named.has(conversation) &&
1131
+ const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
1028
1132
  !alive.isCreating(conversation) &&
1029
- (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, list)));
1133
+ (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
1030
1134
  for (const conversation of named) {
1031
1135
  if (!replicated.has(conversation) &&
1032
1136
  missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
@@ -1061,6 +1165,17 @@ export async function catchUpConversations(alive, progress) {
1061
1165
  if (!alive.current())
1062
1166
  progress.complete = false;
1063
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
+ }
1064
1179
  export async function resendConversations(alive, progress) {
1065
1180
  const local = await alive.deps.local();
1066
1181
  const tried = new Set();
@@ -1072,7 +1187,7 @@ export async function resendConversations(alive, progress) {
1072
1187
  if (alive.deps.closed())
1073
1188
  return;
1074
1189
  tried.add(submission.operation);
1075
- const result = await dispatched(alive, conversation, submission);
1190
+ const result = await dispatched(alive, conversation, submission, true);
1076
1191
  if (result.kind === 'revoked-authorization')
1077
1192
  return;
1078
1193
  if (result.kind === 'transport-uncertainty') {
@@ -1092,22 +1207,25 @@ export function watchConversation(alive, conversation, options, deliver) {
1092
1207
  const { view, watcher } = alive.viewJoined(key, conversation, asked, deliver);
1093
1208
  const { held } = view;
1094
1209
  const reading = new AbortController();
1095
- void untilAnswered(() => alive.deps.durably(async (local) => {
1210
+ void untilAnswered(retrying(alive.deps.retries, 'reading', `window ${key}`, () => alive.deps.durably(async (local) => {
1096
1211
  if (held.now().window !== null)
1097
1212
  return;
1098
1213
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before);
1099
1214
  held.set({ draft: (await local.chatDraft(conversation)) ?? null });
1100
1215
  held.set({ ended: await endedIn(alive, conversation) });
1216
+ held.set({ dismissed: await dismissedIn(local, conversation) });
1217
+ held.set({ pins: (await local.facts()).chatPins });
1101
1218
  held.set({ window: messages });
1102
1219
  held.set({ more });
1103
1220
  held.set({ total: asked.total ? await local.messageCount(conversation) : null });
1104
- }), reading.signal)
1221
+ })), reading.signal)
1105
1222
  .then(() => {
1106
1223
  if (alive.deps.closed() || !view.admit(watcher))
1107
1224
  return;
1108
- const { window, draft, ended } = held.now();
1109
- const shown = window ?? [];
1110
- 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));
1111
1229
  })
1112
1230
  .catch(() => { });
1113
1231
  return () => {
@@ -1123,9 +1241,13 @@ export function watchConversationList(alive, deliver) {
1123
1241
  export function watchConversationAgents(alive, deliver) {
1124
1242
  alive.agentListeners.join(deliver);
1125
1243
  conversationsLearned(alive);
1126
- readAgents(alive);
1127
1244
  return () => alive.agentListeners.leave(deliver);
1128
1245
  }
1246
+ export function watchListedAgents(alive, deliver) {
1247
+ alive.listedListeners.join(deliver);
1248
+ conversationsLearned(alive);
1249
+ return () => alive.listedListeners.leave(deliver);
1250
+ }
1129
1251
  export function conversationsChanged(alive, set) {
1130
1252
  for (const conversation of set.conversations)
1131
1253
  emit(alive, conversation);
@@ -1137,26 +1259,32 @@ export function receiveConversationEvent(alive, event) {
1137
1259
  if (event.whole)
1138
1260
  alive.relistBegun();
1139
1261
  if (alive.relisting())
1140
- alive.relistHeard(event.entries);
1262
+ alive.relistHeard(event.entries, event.agents);
1141
1263
  if (event.more && alive.relisting())
1142
1264
  return;
1143
1265
  const whole = alive.relistTaken();
1144
1266
  listChanged(alive, {
1145
1267
  replacing: whole !== null,
1146
- 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()],
1147
1270
  gone: null,
1148
1271
  ...(event.more ? { paged: true } : { cursor: event.cursor }),
1149
1272
  });
1150
1273
  return;
1151
1274
  }
1152
1275
  if (event.kind === 'listed') {
1153
- alive.relistHeard([event.entry]);
1154
- 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 });
1155
1283
  return;
1156
1284
  }
1157
1285
  if (event.kind === 'unlisted') {
1158
1286
  alive.relistDropped(event.conversation);
1159
- listChanged(alive, { replacing: false, set: [], gone: event.conversation });
1287
+ listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
1160
1288
  return;
1161
1289
  }
1162
1290
  heard(alive, event);