@agentshouse/mdruntime 0.1.0-c2af3ddcc243b → 0.1.0-c2d73b235d7d7

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 (266) hide show
  1. package/README.md +14 -13
  2. package/dist/acceptance.d.ts.map +1 -1
  3. package/dist/acceptance.js +32 -3
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +62 -19
  6. package/dist/adapter.d.ts +201 -28
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/attached-model.d.ts +0 -1
  9. package/dist/attached-model.d.ts.map +1 -1
  10. package/dist/attached-model.js +2 -7
  11. package/dist/{binary.d.ts → attachment.d.ts} +8 -4
  12. package/dist/attachment.d.ts.map +1 -0
  13. package/dist/attachment.js +15 -0
  14. package/dist/authored.d.ts +88 -0
  15. package/dist/authored.d.ts.map +1 -0
  16. package/dist/authored.js +345 -0
  17. package/dist/chain.d.ts +1 -1
  18. package/dist/chain.d.ts.map +1 -1
  19. package/dist/chain.js +5 -2
  20. package/dist/change.d.ts +6 -2
  21. package/dist/change.d.ts.map +1 -1
  22. package/dist/change.js +3 -0
  23. package/dist/chat-types.d.ts +0 -2
  24. package/dist/chat-types.d.ts.map +1 -1
  25. package/dist/chat-types.js +2 -4
  26. package/dist/client.d.ts +24 -8
  27. package/dist/client.d.ts.map +1 -1
  28. package/dist/client.js +26 -56
  29. package/dist/collection.d.ts +6 -1
  30. package/dist/collection.d.ts.map +1 -1
  31. package/dist/collection.js +23 -9
  32. package/dist/column.d.ts +5 -0
  33. package/dist/column.d.ts.map +1 -0
  34. package/dist/column.js +9 -0
  35. package/dist/compile.d.ts +2 -1
  36. package/dist/compile.d.ts.map +1 -1
  37. package/dist/compile.js +73 -42
  38. package/dist/connection.d.ts +1 -1
  39. package/dist/connection.d.ts.map +1 -1
  40. package/dist/connection.js +18 -8
  41. package/dist/context.d.ts.map +1 -1
  42. package/dist/context.js +1 -1
  43. package/dist/conversation-live.d.ts +19 -9
  44. package/dist/conversation-live.d.ts.map +1 -1
  45. package/dist/conversation-live.js +18 -8
  46. package/dist/conversation-row.d.ts +23 -1
  47. package/dist/conversation-row.d.ts.map +1 -1
  48. package/dist/conversation-row.js +37 -8
  49. package/dist/conversation.d.ts +26 -12
  50. package/dist/conversation.d.ts.map +1 -1
  51. package/dist/conversation.js +213 -160
  52. package/dist/declaration.js +3 -3
  53. package/dist/discovery.d.ts +3 -1
  54. package/dist/discovery.d.ts.map +1 -1
  55. package/dist/discovery.js +30 -5
  56. package/dist/download.d.ts +6 -0
  57. package/dist/download.d.ts.map +1 -0
  58. package/dist/download.js +42 -0
  59. package/dist/durability.d.ts +1 -0
  60. package/dist/durability.d.ts.map +1 -1
  61. package/dist/durability.js +3 -0
  62. package/dist/entry.d.ts +26 -1
  63. package/dist/entry.d.ts.map +1 -1
  64. package/dist/entry.js +126 -36
  65. package/dist/failure.d.ts.map +1 -1
  66. package/dist/failure.js +3 -1
  67. package/dist/figures.d.ts +1 -1
  68. package/dist/figures.d.ts.map +1 -1
  69. package/dist/figures.js +6 -4
  70. package/dist/file.d.ts +1 -1
  71. package/dist/file.d.ts.map +1 -1
  72. package/dist/file.js +3 -2
  73. package/dist/host.d.ts +7 -2
  74. package/dist/host.d.ts.map +1 -1
  75. package/dist/host.js +71 -29
  76. package/dist/house-query.d.ts +24 -0
  77. package/dist/house-query.d.ts.map +1 -0
  78. package/dist/house-query.js +102 -0
  79. package/dist/identity.d.ts +1 -1
  80. package/dist/identity.d.ts.map +1 -1
  81. package/dist/identity.js +1 -1
  82. package/dist/index.d.ts +21 -12
  83. package/dist/index.d.ts.map +1 -1
  84. package/dist/index.js +11 -5
  85. package/dist/install.d.ts +8 -2
  86. package/dist/install.d.ts.map +1 -1
  87. package/dist/install.js +40 -33
  88. package/dist/lifecycle.d.ts +1 -1
  89. package/dist/lifecycle.d.ts.map +1 -1
  90. package/dist/lifecycle.js +40 -25
  91. package/dist/linked-file.d.ts +7 -0
  92. package/dist/linked-file.d.ts.map +1 -0
  93. package/dist/linked-file.js +16 -0
  94. package/dist/listing.d.ts +24 -12
  95. package/dist/listing.d.ts.map +1 -1
  96. package/dist/listing.js +50 -21
  97. package/dist/live.d.ts +19 -3
  98. package/dist/live.d.ts.map +1 -1
  99. package/dist/live.js +94 -36
  100. package/dist/loaded.d.ts +7 -0
  101. package/dist/loaded.d.ts.map +1 -0
  102. package/dist/loaded.js +46 -0
  103. package/dist/locks.d.ts.map +1 -1
  104. package/dist/locks.js +4 -2
  105. package/dist/lost.js +1 -1
  106. package/dist/media.d.ts +19 -3
  107. package/dist/media.d.ts.map +1 -1
  108. package/dist/media.js +181 -34
  109. package/dist/memory.d.ts +7 -3
  110. package/dist/memory.d.ts.map +1 -1
  111. package/dist/memory.js +64 -23
  112. package/dist/messages.d.ts +12 -1
  113. package/dist/messages.d.ts.map +1 -1
  114. package/dist/messages.js +28 -6
  115. package/dist/modal.d.ts +2 -0
  116. package/dist/modal.d.ts.map +1 -0
  117. package/dist/modal.js +11 -0
  118. package/dist/model.d.ts +10 -7
  119. package/dist/model.d.ts.map +1 -1
  120. package/dist/model.js +7 -1
  121. package/dist/models.d.ts.map +1 -1
  122. package/dist/models.js +3 -3
  123. package/dist/name.d.ts +0 -1
  124. package/dist/name.d.ts.map +1 -1
  125. package/dist/name.js +3 -7
  126. package/dist/observation.d.ts +29 -12
  127. package/dist/observation.d.ts.map +1 -1
  128. package/dist/observation.js +206 -69
  129. package/dist/online.d.ts +7 -0
  130. package/dist/online.d.ts.map +1 -0
  131. package/dist/online.js +29 -0
  132. package/dist/opened.d.ts +5 -5
  133. package/dist/opened.d.ts.map +1 -1
  134. package/dist/opened.js +2 -2
  135. package/dist/opening.d.ts.map +1 -1
  136. package/dist/opening.js +20 -2
  137. package/dist/outcome.d.ts +30 -13
  138. package/dist/outcome.d.ts.map +1 -1
  139. package/dist/outcome.js +21 -6
  140. package/dist/overlay.d.ts +20 -9
  141. package/dist/overlay.d.ts.map +1 -1
  142. package/dist/overlay.js +110 -41
  143. package/dist/parts.d.ts +4 -1
  144. package/dist/parts.d.ts.map +1 -1
  145. package/dist/parts.js +30 -7
  146. package/dist/paths.d.ts +1 -1
  147. package/dist/paths.js +1 -1
  148. package/dist/preparation.d.ts +33 -7
  149. package/dist/preparation.d.ts.map +1 -1
  150. package/dist/preparation.js +195 -78
  151. package/dist/presence.d.ts +8 -2
  152. package/dist/presence.d.ts.map +1 -1
  153. package/dist/presence.js +24 -13
  154. package/dist/queries.d.ts +1 -1
  155. package/dist/queries.d.ts.map +1 -1
  156. package/dist/queries.js +115 -67
  157. package/dist/query.d.ts +2 -2
  158. package/dist/query.d.ts.map +1 -1
  159. package/dist/questions.d.ts +1 -0
  160. package/dist/questions.d.ts.map +1 -1
  161. package/dist/questions.js +3 -1
  162. package/dist/queue.d.ts +1 -1
  163. package/dist/queue.d.ts.map +1 -1
  164. package/dist/queue.js +55 -23
  165. package/dist/reach.d.ts +15 -6
  166. package/dist/reach.d.ts.map +1 -1
  167. package/dist/reach.js +140 -25
  168. package/dist/react.d.ts +12 -1
  169. package/dist/react.d.ts.map +1 -1
  170. package/dist/readiness.d.ts +22 -3
  171. package/dist/readiness.d.ts.map +1 -1
  172. package/dist/readiness.js +18 -10
  173. package/dist/reads.d.ts +1 -1
  174. package/dist/reads.d.ts.map +1 -1
  175. package/dist/reads.js +17 -6
  176. package/dist/recovery.d.ts +1 -0
  177. package/dist/recovery.d.ts.map +1 -1
  178. package/dist/recovery.js +2 -1
  179. package/dist/refresh.d.ts +1 -1
  180. package/dist/refresh.js +4 -4
  181. package/dist/replica.d.ts +3 -8
  182. package/dist/replica.d.ts.map +1 -1
  183. package/dist/replica.js +5 -5
  184. package/dist/room-draft.d.ts +29 -4
  185. package/dist/room-draft.d.ts.map +1 -1
  186. package/dist/room-draft.js +239 -18
  187. package/dist/room-drafts.d.ts.map +1 -1
  188. package/dist/room-drafts.js +12 -7
  189. package/dist/room-list.d.ts +10 -0
  190. package/dist/room-list.d.ts.map +1 -0
  191. package/dist/room-list.js +47 -0
  192. package/dist/rows.d.ts +11 -3
  193. package/dist/rows.d.ts.map +1 -1
  194. package/dist/rows.js +25 -11
  195. package/dist/run-tables.d.ts +25 -0
  196. package/dist/run-tables.d.ts.map +1 -0
  197. package/dist/run-tables.js +98 -0
  198. package/dist/running.d.ts +5 -0
  199. package/dist/running.d.ts.map +1 -0
  200. package/dist/running.js +10 -0
  201. package/dist/runs.d.ts +27 -0
  202. package/dist/runs.d.ts.map +1 -0
  203. package/dist/runs.js +92 -0
  204. package/dist/runtime.d.ts +7 -3
  205. package/dist/runtime.d.ts.map +1 -1
  206. package/dist/save.d.ts +1 -0
  207. package/dist/save.d.ts.map +1 -1
  208. package/dist/save.js +31 -96
  209. package/dist/saves.d.ts +7 -5
  210. package/dist/saves.d.ts.map +1 -1
  211. package/dist/saves.js +109 -55
  212. package/dist/seed.d.ts.map +1 -1
  213. package/dist/seed.js +2 -2
  214. package/dist/selector.d.ts +3 -0
  215. package/dist/selector.d.ts.map +1 -0
  216. package/dist/selector.js +22 -0
  217. package/dist/shown.d.ts +4 -2
  218. package/dist/shown.d.ts.map +1 -1
  219. package/dist/shown.js +83 -51
  220. package/dist/socket/session.d.ts +4 -1
  221. package/dist/socket/session.d.ts.map +1 -1
  222. package/dist/socket/session.js +3 -0
  223. package/dist/socket.d.ts +4 -1
  224. package/dist/socket.d.ts.map +1 -1
  225. package/dist/socket.js +8 -0
  226. package/dist/source.d.ts +42 -0
  227. package/dist/source.d.ts.map +1 -1
  228. package/dist/source.js +76 -9
  229. package/dist/store/installs.d.ts +2 -2
  230. package/dist/store/installs.d.ts.map +1 -1
  231. package/dist/store/installs.js +10 -4
  232. package/dist/store/readiness.d.ts +5 -4
  233. package/dist/store/readiness.d.ts.map +1 -1
  234. package/dist/store/readiness.js +28 -12
  235. package/dist/store/records.d.ts +25 -5
  236. package/dist/store/records.d.ts.map +1 -1
  237. package/dist/store/records.js +59 -23
  238. package/dist/store/rooms-shown.d.ts +8 -0
  239. package/dist/store/rooms-shown.d.ts.map +1 -0
  240. package/dist/store/rooms-shown.js +13 -0
  241. package/dist/store.d.ts +15 -10
  242. package/dist/store.d.ts.map +1 -1
  243. package/dist/store.js +12 -5
  244. package/dist/stored.d.ts +40 -16
  245. package/dist/stored.d.ts.map +1 -1
  246. package/dist/stored.js +210 -52
  247. package/dist/surface.d.ts +19 -7
  248. package/dist/surface.d.ts.map +1 -1
  249. package/dist/surface.js +55 -17
  250. package/dist/sync.d.ts +4 -2
  251. package/dist/sync.d.ts.map +1 -1
  252. package/dist/sync.js +49 -27
  253. package/dist/tables.d.ts +34 -49
  254. package/dist/tables.d.ts.map +1 -1
  255. package/dist/tables.js +84 -325
  256. package/dist/tallies.d.ts.map +1 -1
  257. package/dist/tallies.js +3 -4
  258. package/dist/validation.d.ts +2 -0
  259. package/dist/validation.d.ts.map +1 -1
  260. package/dist/validation.js +50 -10
  261. package/dist/wire.d.ts +30 -14
  262. package/dist/wire.d.ts.map +1 -1
  263. package/dist/wire.js +19 -13
  264. package/package.json +4 -4
  265. package/dist/binary.d.ts.map +0 -1
  266. package/dist/binary.js +0 -8
@@ -6,7 +6,7 @@ import { heldFacts } from './conversation-row.js';
6
6
  import { runtimeError, uncaught } from './failure.js';
7
7
  import { refusedForSpace } from './durability.js';
8
8
  import { changeBatchIdentity, chatDraftRevision } from './identity.js';
9
- import { OFFLINE } from './outcome.js';
9
+ import { OFFLINE, } from './outcome.js';
10
10
  import { runningLine } from './parts.js';
11
11
  import { record, text } from './read.js';
12
12
  import { openQuestion, questionAsked } from './questions.js';
@@ -25,17 +25,16 @@ export function unheldView(conversation) {
25
25
  options: [],
26
26
  starting: null,
27
27
  state: null,
28
- link: null,
29
28
  deliveryWaiting: [],
30
29
  deliveryUnknown: [],
31
30
  chatDraft: null,
32
31
  dismissedSuggestion: null,
32
+ pins: [],
33
33
  };
34
34
  }
35
35
  export const SESSION_STARTED = 'Session started';
36
36
  const NEW_CHAT = 'new:';
37
37
  const LISTING = 'listing';
38
- const AGENTS = 'agents';
39
38
  export const CATCHING_UP = 'catching-up';
40
39
  export const HISTORY_CONVERSATIONS = 64;
41
40
  export function newChat(agent) {
@@ -209,7 +208,7 @@ function returned(draft, submission, others) {
209
208
  revision: chatDraftRevision(),
210
209
  }, others);
211
210
  }
212
- function viewOf(alive, conversation, held, frame, draft, ended, dismissed) {
211
+ function viewOf(alive, conversation, held, frame, { draft, ended, dismissed, pins }) {
213
212
  const facts = alive.liveOf(conversation);
214
213
  return {
215
214
  conversation,
@@ -228,38 +227,44 @@ function viewOf(alive, conversation, held, frame, draft, ended, dismissed) {
228
227
  options: structuredClone(facts.options),
229
228
  starting: facts.starting,
230
229
  state: sessionOf(facts, held, ended),
231
- link: facts.link === null ? null : { ...facts.link },
232
230
  deliveryWaiting: [...facts.deliveryWaiting],
233
231
  deliveryUnknown: [...facts.deliveryUnknown],
234
232
  chatDraft: draft === null || unwritten(draft) ? null : { text: draft.text, revision: draft.revision },
235
233
  dismissedSuggestion: dismissed,
234
+ pins: [...pins],
236
235
  };
237
236
  }
238
- function sessionOf(facts, held, ended) {
237
+ function standing(facts, saved, ended) {
239
238
  if (facts.state !== null)
240
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) {
241
246
  const saved = [...held]
242
247
  .reverse()
243
248
  .map(({ message }) => record(message))
244
249
  .find(({ content }) => isTurn(content));
245
250
  const at = saved === undefined ? null : text(saved, 'accepted_at');
246
- if (saved === undefined || !isTurn(saved.content) || at === null)
247
- return null;
248
- const down = facts.process?.running === false;
249
- 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);
250
254
  }
251
255
  function emit(alive, conversation) {
252
256
  if (alive.deps.closed())
253
257
  return;
254
258
  for (const view of alive.views()) {
255
- const { window, draft, ended, dismissed } = view.held.now();
259
+ const held = view.held.now();
260
+ const { window } = held;
256
261
  if (view.conversation !== conversation || window === null)
257
262
  continue;
258
263
  const ready = view.ready();
259
264
  if (ready.length === 0)
260
265
  continue;
261
266
  const frame = sharedFrame(view, window);
262
- const value = viewOf(alive, conversation, window, frame, draft, ended, dismissed);
267
+ const value = viewOf(alive, conversation, window, frame, held);
263
268
  for (const watcher of ready)
264
269
  watcher.notify(value);
265
270
  }
@@ -288,83 +293,119 @@ async function slide(alive, local, conversation, arriving) {
288
293
  }
289
294
  }
290
295
  }
291
- function stateOf(alive, conversation) {
292
- const facts = alive.liveOf(conversation);
293
- if (facts.questions.length > 0)
296
+ function stateOf({ activity }) {
297
+ if (activity === null)
298
+ return 'idle';
299
+ if (activity.turn === 'asking')
294
300
  return 'asking';
295
- return facts.turn === null ? 'idle' : 'working';
301
+ return activity.turn === 'running' || activity.background !== false ? 'working' : 'idle';
296
302
  }
297
303
  function rowOf(alive, conversation) {
298
- const { turn, questions } = alive.liveOf(conversation);
304
+ const { turn, questions, deliveryWaiting } = alive.liveOf(conversation);
299
305
  return {
300
- state: stateOf(alive, conversation),
301
306
  started: turn?.started ?? null,
302
307
  line: turn === null ? null : runningLine(turn.parts),
303
308
  question: openQuestion(questions),
304
309
  asked: questionAsked(questions),
310
+ deliveryWaiting: [...deliveryWaiting],
305
311
  };
306
312
  }
307
313
  async function entries(alive) {
308
- const list = await heldList(alive);
309
- 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)))
310
320
  return null;
311
321
  const held = list.length === 0
312
322
  ? []
313
323
  : await alive.deps.durably((local) => local.conversationRows(list.map(({ conversation }) => conversation)));
314
324
  const rows = new Map(held.map((one) => [one.conversation, one]));
315
- return list.map((entry) => ({
316
- conversation: entry.conversation,
317
- agent: { identity: entry.agent, name: entry.agentName, retired: entry.agentRetired },
318
- name: entry.name,
319
- created: entry.created,
320
- finished: entry.finished,
321
- outcome: entry.outcome,
322
- waiting: entry.waiting,
323
- ...rowOf(alive, entry.conversation),
324
- ...heldFacts(rows.get(entry.conversation), entry),
325
- }));
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
+ conversation_name: entry.conversationName,
332
+ created: entry.created,
333
+ outcome: entry.outcome,
334
+ waiting: entry.waiting,
335
+ subject: entry.subject,
336
+ room: entry.room,
337
+ model: entry.model,
338
+ effort: entry.effort,
339
+ state: stateOf(entry),
340
+ ...rowOf(alive, entry.conversation),
341
+ ...heldFacts(rows.get(entry.conversation), entry),
342
+ jobs: standing(alive.liveOf(entry.conversation), rows.get(entry.conversation)?.saved ?? null, entry.processEnded)?.running ?? [],
343
+ };
344
+ });
326
345
  }
327
- async function heldList(alive) {
328
- const stored = (await (await alive.deps.local()).facts()).conversationList;
329
- if (stored !== null)
330
- return stored;
331
- return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online() ? null : [];
346
+ async function heldListing(alive) {
347
+ const { conversationList, agentList } = await (await alive.deps.local()).facts();
348
+ if (conversationList !== null && agentList !== null)
349
+ return { conversations: conversationList, agents: agentList };
350
+ return !alive.known() && alive.deps.stream() !== undefined && alive.deps.online()
351
+ ? null
352
+ : { conversations: [], agents: [] };
332
353
  }
333
354
  async function endedIn(alive, conversation) {
334
- const list = await heldList(alive);
335
- return list?.find((entry) => entry.conversation === conversation)?.processEnded ?? null;
355
+ const listing = await heldListing(alive);
356
+ return (listing?.conversations.find((entry) => entry.conversation === conversation)?.processEnded ??
357
+ null);
358
+ }
359
+ function upserted(kept, set, key) {
360
+ const held = new Map(kept.map((one) => [key(one), one]));
361
+ for (const one of set)
362
+ held.set(key(one), { ...one });
363
+ return held;
364
+ }
365
+ async function listStored(alive, local, change) {
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)
371
+ alive.created(entry.conversation);
372
+ if (change.gone !== null)
373
+ held.delete(change.gone);
374
+ const list = [...held.values()];
375
+ const agents = [
376
+ ...upserted(change.replacing ? [] : (agentList ?? []), change.agents, (agent) => agent.id).values(),
377
+ ];
378
+ if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
379
+ await local.fact('conversationList', list);
380
+ }
381
+ if (JSON.stringify(agents) !== JSON.stringify(agentList)) {
382
+ await local.fact('agentList', agents);
383
+ }
384
+ if (change.cursor !== undefined && !alive.held.now().listRefused) {
385
+ if (change.cursor !== conversationCursor) {
386
+ await local.fact('conversationCursor', change.cursor);
387
+ }
388
+ alive.deps.stream()?.hold(change.cursor);
389
+ }
390
+ return { conversations: list, agents };
336
391
  }
337
392
  function listChanged(alive, change) {
338
393
  void alive.deps
339
- .durably(async (local) => {
340
- const { conversationList, conversationCursor } = await local.facts();
341
- const kept = change.replacing ? [] : (conversationList ?? []);
342
- const held = new Map(kept.map((entry) => [entry.conversation, entry]));
343
- for (const entry of change.set) {
344
- held.set(entry.conversation, { ...entry });
345
- alive.created(entry.conversation);
346
- }
347
- if (change.gone !== null)
348
- held.delete(change.gone);
349
- const list = [...held.values()];
350
- if (JSON.stringify(list) !== JSON.stringify(conversationList)) {
351
- await local.fact('conversationList', list);
352
- }
353
- if (change.cursor !== undefined) {
354
- if (change.cursor !== conversationCursor) {
355
- await local.fact('conversationCursor', change.cursor);
356
- }
357
- alive.deps.stream()?.hold(change.cursor);
358
- }
359
- return list;
394
+ .durably((local) => listStored(alive, local, change).catch((error) => {
395
+ alive.held.set({ listRefused: true });
396
+ throw error;
397
+ }))
398
+ .catch(async () => {
399
+ const { conversationList, agentList } = await (await alive.deps.local()).facts();
400
+ return { conversations: conversationList ?? [], agents: agentList ?? [] };
360
401
  })
361
- .catch(async () => (await (await alive.deps.local()).facts()).conversationList ?? [])
362
- .then((list) => {
402
+ .then((listing) => {
363
403
  if (alive.deps.closed() || change.paged === true)
364
404
  return;
405
+ const list = listing.conversations;
365
406
  endedAnew(alive, list);
366
407
  if (change.cursor !== undefined) {
367
- alive.held.set({ listKnown: true });
408
+ alive.held.set({ listKnown: true, listHeld: true, openingListed: true });
368
409
  settleBehind(alive, list);
369
410
  openingEnded(alive);
370
411
  alive.deps.settled();
@@ -372,11 +413,12 @@ function listChanged(alive, change) {
372
413
  emitList(alive);
373
414
  if (!alive.known())
374
415
  return;
375
- retiredDrafts(alive, list);
376
- const { replicated } = alive.held.now();
377
- if (change.cursor === undefined &&
378
- (list.length !== replicated.size ||
379
- list.some(({ conversation }) => !replicated.has(conversation)))) {
416
+ retiredDrafts(alive, listing);
417
+ const { replicated, openingRead } = alive.held.now();
418
+ if (change.cursor === undefined
419
+ ? list.length !== replicated.size ||
420
+ list.some(({ conversation }) => !replicated.has(conversation))
421
+ : openingRead) {
380
422
  alive.deps.again();
381
423
  }
382
424
  }, uncaught);
@@ -392,16 +434,16 @@ function endedAnew(alive, list) {
392
434
  emit(alive, view.conversation);
393
435
  }
394
436
  }
395
- function shownList(alive, work) {
396
- const reading = heldList(alive);
437
+ function shownListing(alive, work) {
438
+ const reading = heldListing(alive);
397
439
  alive.inOrder(async () => {
398
- const list = await reading.catch((error) => {
440
+ const listing = await reading.catch((error) => {
399
441
  uncaught(error);
400
442
  return null;
401
443
  });
402
- if (list === null || alive.deps.closed())
444
+ if (listing === null || alive.deps.closed())
403
445
  return;
404
- work(list);
446
+ work(listing);
405
447
  });
406
448
  }
407
449
  async function told(alive) {
@@ -446,84 +488,73 @@ export function conversationsLearned(alive) {
446
488
  return;
447
489
  if (alive.listeners.waiting())
448
490
  tellList(alive);
449
- if (!alive.agentListeners.waiting())
491
+ if (!alive.agentListeners.waiting() && !alive.listedListeners.waiting())
450
492
  return;
451
- shownList(alive, (list) => alive.agentListeners.welcome(agents(alive, list)));
493
+ shownListing(alive, (listing) => {
494
+ alive.agentListeners.welcome(agentsOf(listing));
495
+ alive.listedListeners.welcome(structuredClone(listing.agents));
496
+ });
452
497
  }
453
- function agents(alive, list) {
454
- const read = new Map((alive.held.now().listedAgents ?? []).map((one) => [one.agent, one]));
455
- const named = new Map(read);
456
- for (const entry of list) {
457
- named.set(entry.agent, { name: entry.agentName, retired: entry.agentRetired });
458
- }
459
- return [...named]
460
- .filter(([, agent]) => !agent.retired)
461
- .map(([identity, agent]) => {
462
- const held = read.get(identity);
463
- return held === undefined
464
- ? { identity, name: agent.name }
465
- : {
466
- identity,
467
- name: agent.name,
468
- cli: held.cli,
469
- environment: structuredClone(held.environment),
470
- };
471
- })
498
+ function agentsOf(listing) {
499
+ return listing.agents
500
+ .filter((agent) => agent.retired_at === null)
501
+ .map((agent) => ({
502
+ identity: agent.id,
503
+ name: agent.name,
504
+ cli: agent.cli,
505
+ model: agent.model,
506
+ effort: agent.effort,
507
+ model_fixed: agent.model_fixed,
508
+ environment: {
509
+ identity: agent.environment,
510
+ name: agent.environment_name,
511
+ state: agent.environment_connected ? 'online' : 'offline',
512
+ },
513
+ }))
472
514
  .sort((left, right) => left.name === right.name
473
515
  ? left.identity.localeCompare(right.identity)
474
516
  : left.name.localeCompare(right.name));
475
517
  }
476
- function readAgents(alive) {
477
- const stream = alive.deps.stream();
478
- if (stream?.agents === undefined || !alive.deps.online() || alive.held.now().agentsReading)
479
- return;
480
- const { agents: read } = stream;
481
- const { agentListeners } = alive;
482
- alive.held.set({ agentsReading: true });
483
- void alive.deps.recovery
484
- .attempt('agents', async () => {
485
- if (!alive.deps.online() || (!agentListeners.waiting() && !agentListeners.told())) {
486
- return 'done';
487
- }
488
- const listed = await retrying(alive.deps.retries, 'conversations', AGENTS, read)();
489
- if (listed === null)
490
- return 'done';
491
- alive.held.set({ listedAgents: listed });
492
- emitAgents(alive);
493
- return 'done';
494
- })
495
- .finally(() => {
496
- alive.held.set({ agentsReading: false });
497
- });
498
- }
499
518
  function emitAgents(alive) {
500
- if (alive.deps.closed() || !alive.agentListeners.told())
519
+ const { agentListeners, listedListeners } = alive;
520
+ if (alive.deps.closed() || (!agentListeners.told() && !listedListeners.told()))
501
521
  return;
502
- shownList(alive, (list) => {
503
- const value = agents(alive, list);
522
+ shownListing(alive, (listing) => {
523
+ const value = agentsOf(listing);
504
524
  const shown = JSON.stringify(value);
505
- if (shown === alive.held.now().agentsShown)
506
- return;
507
- alive.held.set({ agentsShown: shown });
508
- alive.agentListeners.tell(value);
525
+ if (shown !== alive.held.now().agentsShown) {
526
+ alive.held.set({ agentsShown: shown });
527
+ agentListeners.tell(value);
528
+ }
529
+ const listed = JSON.stringify(listing.agents);
530
+ if (listed !== alive.held.now().listedShown) {
531
+ alive.held.set({ listedShown: listed });
532
+ listedListeners.tell(structuredClone(listing.agents));
533
+ }
509
534
  });
510
535
  }
536
+ function ran({ state, process }) {
537
+ return JSON.stringify([state?.running ?? null, process?.running ?? null]);
538
+ }
511
539
  function setLive(alive, conversation, next) {
540
+ const was = ran(alive.liveOf(conversation));
512
541
  const before = rowOf(alive, conversation);
513
542
  alive.holdLive(conversation, next);
514
543
  const after = rowOf(alive, conversation);
515
- if (after.state !== before.state || after.started !== before.started)
544
+ if (after.started !== before.started ||
545
+ ran(alive.liveOf(conversation)) !== was ||
546
+ after.deliveryWaiting.join() !== before.deliveryWaiting.join())
516
547
  emitList(alive);
517
548
  else if (after.line !== before.line ||
518
549
  after.question !== before.question ||
519
550
  after.asked !== before.asked)
520
551
  tellSoon(alive);
521
552
  }
522
- function retiredChat(conversation, list) {
553
+ function retiredChat(conversation, listing) {
523
554
  if (!conversation.startsWith(NEW_CHAT))
524
555
  return false;
525
556
  const agent = conversation.slice(NEW_CHAT.length);
526
- return list.some((entry) => entry.agent === agent && entry.agentRetired);
557
+ return listing.agents.some((one) => one.id === agent && one.retired_at !== null);
527
558
  }
528
559
  function live(alive, conversation, change) {
529
560
  alive.factsHeard(conversation, FACTS.filter((one) => one in change));
@@ -543,7 +574,6 @@ function openingEnded(alive) {
543
574
  options: facts.has('options') ? QUIET.options : held.options,
544
575
  starting: facts.has('starting') ? QUIET.starting : held.starting,
545
576
  state: facts.has('state') ? QUIET.state : held.state,
546
- link: facts.has('link') ? QUIET.link : held.link,
547
577
  deliveryWaiting: facts.has('deliveryWaiting') ? QUIET.deliveryWaiting : held.deliveryWaiting,
548
578
  deliveryUnknown: facts.has('deliveryUnknown') ? QUIET.deliveryUnknown : held.deliveryUnknown,
549
579
  });
@@ -611,7 +641,7 @@ async function readsOf(local, conversations) {
611
641
  return new Map((await local.conversations(conversations)).map((held) => [held.conversation, held]));
612
642
  }
613
643
  function retiredDrafts(alive, list) {
614
- if (!list.some((entry) => entry.agentRetired))
644
+ if (!list.agents.some((agent) => agent.retired_at !== null))
615
645
  return;
616
646
  void alive.deps
617
647
  .local()
@@ -775,10 +805,6 @@ function heard(alive, event) {
775
805
  live(alive, conversation, { state: structuredClone(event.state) });
776
806
  return;
777
807
  }
778
- if (event.kind === 'link') {
779
- live(alive, conversation, { link: { connected: event.connected } });
780
- return;
781
- }
782
808
  if (event.kind === 'deliveries') {
783
809
  live(alive, conversation, {
784
810
  deliveryWaiting: [...event.waiting],
@@ -925,8 +951,9 @@ async function dispatched(alive, conversation, submission, resent = false) {
925
951
  function invoke(alive, name, conversation, operation, extra = {}, attempt) {
926
952
  return alive.deps.call(name, { conversation_id: conversation, operation_id: operation, ...extra }, attempt);
927
953
  }
928
- export function conversationSurface(alive) {
954
+ export function conversationSurface(alive, files) {
929
955
  return {
956
+ ...files,
930
957
  list() {
931
958
  return new Promise((settle) => {
932
959
  const answer = (listed) => {
@@ -944,7 +971,12 @@ export function conversationSurface(alive) {
944
971
  return alive.deps.durably(async (local) => {
945
972
  const { messages, more } = await local.messageWindow(conversation, asked.limit, asked.before, phrase);
946
973
  const total = asked.total ? await local.messageCount(conversation, phrase) : null;
947
- return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), (await local.chatDraft(conversation)) ?? null, await endedIn(alive, conversation), await dismissedIn(local, conversation)));
974
+ return structuredClone(viewOf(alive, conversation, messages, frameOf(asked, messages, more, total), {
975
+ draft: (await local.chatDraft(conversation)) ?? null,
976
+ ended: await endedIn(alive, conversation),
977
+ dismissed: await dismissedIn(local, conversation),
978
+ pins: (await local.facts()).chatPins,
979
+ }));
948
980
  });
949
981
  },
950
982
  async create(input) {
@@ -952,7 +984,7 @@ export function conversationSurface(alive) {
952
984
  const conversation = answered(result, 'conversation_id');
953
985
  if (conversation === null)
954
986
  return result;
955
- const listed = (await heldList(alive)) ?? [];
987
+ const listed = (await heldListing(alive))?.conversations ?? [];
956
988
  if (!listed.some((entry) => entry.conversation === conversation)) {
957
989
  alive.creating(conversation);
958
990
  }
@@ -1010,25 +1042,27 @@ export function conversationSurface(alive) {
1010
1042
  rename(conversation, name, operation) {
1011
1043
  return invoke(alive, 'conversations/rename', conversation, operation, { name });
1012
1044
  },
1013
- option(conversation, option, value, operation) {
1014
- return invoke(alive, 'conversations/option/set', conversation, operation, { option, value });
1045
+ set(conversation, settings, operation) {
1046
+ return invoke(alive, 'conversations/set', conversation, operation, settings);
1015
1047
  },
1016
1048
  retry(conversation, message, operation) {
1017
1049
  return invoke(alive, 'conversations/retry', conversation, operation, {
1018
1050
  message_id: message,
1019
1051
  });
1020
1052
  },
1021
- async pins() {
1022
- return (await (await alive.deps.local()).facts()).chatPins;
1023
- },
1024
- pin(figures) {
1025
- return alive.deps.durably((local) => local.fact('chatPins', [...figures]));
1026
- },
1027
- async openedTurns() {
1028
- return factOf(await alive.deps.local(), 'openedTurn');
1053
+ async pin(figures) {
1054
+ const pins = [...figures];
1055
+ await alive.deps.durably((local) => local.fact('chatPins', pins));
1056
+ const views = [...alive.views()];
1057
+ for (const view of views)
1058
+ view.held.set({ pins });
1059
+ for (const conversation of new Set(views.map((view) => view.conversation))) {
1060
+ emit(alive, conversation);
1061
+ }
1029
1062
  },
1030
- openTurn(conversation, turn) {
1031
- return alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
1063
+ async openTurn(conversation, turn) {
1064
+ await alive.deps.durably((local) => local.keepConversationFact({ conversation, name: 'openedTurn', value: turn }));
1065
+ tellList(alive);
1032
1066
  },
1033
1067
  dismissSuggestion(conversation, suggestion) {
1034
1068
  return alive.deps.durably(async (local) => {
@@ -1072,29 +1106,37 @@ export function chatDraftSurface(alive) {
1072
1106
  };
1073
1107
  }
1074
1108
  export async function conversationsOpened(alive, local) {
1075
- const { conversationList, conversationCursor } = await local.facts();
1076
- if (conversationList === null || alive.known())
1109
+ const { conversationList, agentList, conversationCursor } = await local.facts();
1110
+ if (conversationList === null || agentList === null)
1111
+ return;
1112
+ alive.held.set({ listHeld: true });
1113
+ if (alive.known())
1077
1114
  return;
1078
1115
  alive.deps.stream()?.hold(conversationCursor);
1079
1116
  conversationsLearned(alive);
1080
1117
  }
1118
+ export function reconcileOpening(alive) {
1119
+ alive.held.set({ openingRead: true });
1120
+ return reconcileConversations(alive);
1121
+ }
1081
1122
  export async function reconcileConversations(alive) {
1082
1123
  if (!alive.known())
1083
1124
  return;
1084
1125
  const local = await alive.deps.local();
1085
- const [held, stored, { conversationList }] = await Promise.all([
1126
+ const [held, stored, { conversationList, agentList }] = await Promise.all([
1086
1127
  local.conversations(),
1087
1128
  local.storedConversations(),
1088
1129
  local.facts(),
1089
1130
  ]);
1090
1131
  const list = conversationList ?? [];
1132
+ const listing = { conversations: list, agents: agentList ?? [] };
1091
1133
  const entries = new Map(list.map((entry) => [entry.conversation, entry]));
1092
1134
  const named = new Set(entries.keys());
1093
1135
  const reads = new Map(held.map((one) => [one.conversation, one]));
1094
1136
  const { replicated } = alive.held.now();
1095
1137
  const leaving = [...new Set([...replicated, ...stored])].filter((conversation) => !named.has(conversation) &&
1096
1138
  !alive.isCreating(conversation) &&
1097
- (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, list)));
1139
+ (!conversation.startsWith(NEW_CHAT) || retiredChat(conversation, listing)));
1098
1140
  for (const conversation of named) {
1099
1141
  if (!replicated.has(conversation) &&
1100
1142
  missed(alive, conversation, reads.get(conversation), entries.get(conversation))) {
@@ -1178,6 +1220,7 @@ export function watchConversation(alive, conversation, options, deliver) {
1178
1220
  held.set({ draft: (await local.chatDraft(conversation)) ?? null });
1179
1221
  held.set({ ended: await endedIn(alive, conversation) });
1180
1222
  held.set({ dismissed: await dismissedIn(local, conversation) });
1223
+ held.set({ pins: (await local.facts()).chatPins });
1181
1224
  held.set({ window: messages });
1182
1225
  held.set({ more });
1183
1226
  held.set({ total: asked.total ? await local.messageCount(conversation) : null });
@@ -1185,10 +1228,10 @@ export function watchConversation(alive, conversation, options, deliver) {
1185
1228
  .then(() => {
1186
1229
  if (alive.deps.closed() || !view.admit(watcher))
1187
1230
  return;
1188
- const { window, draft, ended, dismissed } = held.now();
1189
- const shown = window ?? [];
1231
+ const now = held.now();
1232
+ const shown = now.window ?? [];
1190
1233
  const frame = sharedFrame(view, shown);
1191
- watcher.notify(viewOf(alive, conversation, shown, frame, draft, ended, dismissed));
1234
+ watcher.notify(viewOf(alive, conversation, shown, frame, now));
1192
1235
  })
1193
1236
  .catch(() => { });
1194
1237
  return () => {
@@ -1204,9 +1247,13 @@ export function watchConversationList(alive, deliver) {
1204
1247
  export function watchConversationAgents(alive, deliver) {
1205
1248
  alive.agentListeners.join(deliver);
1206
1249
  conversationsLearned(alive);
1207
- readAgents(alive);
1208
1250
  return () => alive.agentListeners.leave(deliver);
1209
1251
  }
1252
+ export function watchListedAgents(alive, deliver) {
1253
+ alive.listedListeners.join(deliver);
1254
+ conversationsLearned(alive);
1255
+ return () => alive.listedListeners.leave(deliver);
1256
+ }
1210
1257
  export function conversationsChanged(alive, set) {
1211
1258
  for (const conversation of set.conversations)
1212
1259
  emit(alive, conversation);
@@ -1218,26 +1265,32 @@ export function receiveConversationEvent(alive, event) {
1218
1265
  if (event.whole)
1219
1266
  alive.relistBegun();
1220
1267
  if (alive.relisting())
1221
- alive.relistHeard(event.entries);
1268
+ alive.relistHeard(event.entries, event.agents);
1222
1269
  if (event.more && alive.relisting())
1223
1270
  return;
1224
1271
  const whole = alive.relistTaken();
1225
1272
  listChanged(alive, {
1226
1273
  replacing: whole !== null,
1227
- set: whole === null ? event.entries : [...whole.values()],
1274
+ set: whole === null ? event.entries : [...whole.conversations.values()],
1275
+ agents: whole === null ? event.agents : [...whole.agents.values()],
1228
1276
  gone: null,
1229
1277
  ...(event.more ? { paged: true } : { cursor: event.cursor }),
1230
1278
  });
1231
1279
  return;
1232
1280
  }
1233
1281
  if (event.kind === 'listed') {
1234
- alive.relistHeard([event.entry]);
1235
- listChanged(alive, { replacing: false, set: [event.entry], gone: null });
1282
+ alive.relistHeard([event.entry], []);
1283
+ listChanged(alive, { replacing: false, set: [event.entry], agents: [], gone: null });
1284
+ return;
1285
+ }
1286
+ if (event.kind === 'agent') {
1287
+ alive.relistHeard([], [event.agent]);
1288
+ listChanged(alive, { replacing: false, set: [], agents: [event.agent], gone: null });
1236
1289
  return;
1237
1290
  }
1238
1291
  if (event.kind === 'unlisted') {
1239
1292
  alive.relistDropped(event.conversation);
1240
- listChanged(alive, { replacing: false, set: [], gone: event.conversation });
1293
+ listChanged(alive, { replacing: false, set: [], agents: [], gone: event.conversation });
1241
1294
  return;
1242
1295
  }
1243
1296
  heard(alive, event);
@@ -1,5 +1,5 @@
1
1
  import { equalValue } from '@agentshouse/mdmodel';
2
- import { authoredAt, covered, normalize } from './paths.js';
2
+ import { documentAt, covered, normalize } from './paths.js';
3
3
  export function declared({ locator: _locator, roomVersion: _roomVersion, ...declaration }) {
4
4
  return declaration;
5
5
  }
@@ -8,10 +8,10 @@ export function sameDeclaration(left, right) {
8
8
  }
9
9
  export function writeRule({ operations, providerOwnedPaths, authoredPaths, }, pathRule, local) {
10
10
  return (path, needs) => {
11
- const normalized = normalize(path);
11
+ const normalized = normalize(path.normalize('NFC'));
12
12
  if (normalized === null || normalized === '')
13
13
  return { code: 'room-root', path };
14
- if (covered(providerOwnedPaths, normalized) || !authoredAt(authoredPaths, normalized)) {
14
+ if (covered(providerOwnedPaths, normalized) || !documentAt(authoredPaths, normalized)) {
15
15
  return { code: 'provider-owned-path', path: normalized };
16
16
  }
17
17
  if (!pathRule(normalized))