@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c0105dbd22806

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 (214) hide show
  1. package/AGENTS.md +299 -0
  2. package/README.md +54 -0
  3. package/dist/adapter.d.ts +246 -40
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/adapter.js +1 -10
  6. package/dist/attached-model.d.ts +11 -0
  7. package/dist/attached-model.d.ts.map +1 -0
  8. package/dist/attached-model.js +47 -0
  9. package/dist/attempt.d.ts +16 -0
  10. package/dist/attempt.d.ts.map +1 -0
  11. package/dist/attempt.js +70 -0
  12. package/dist/binary.d.ts +23 -0
  13. package/dist/binary.d.ts.map +1 -0
  14. package/dist/binary.js +8 -0
  15. package/dist/bootstrap.d.ts +17 -7
  16. package/dist/bootstrap.d.ts.map +1 -1
  17. package/dist/bootstrap.js +97 -41
  18. package/dist/change-set.d.ts +33 -0
  19. package/dist/change-set.d.ts.map +1 -0
  20. package/dist/change-set.js +90 -0
  21. package/dist/change.d.ts +24 -0
  22. package/dist/change.d.ts.map +1 -1
  23. package/dist/change.js +31 -5
  24. package/dist/chat/acts.d.ts +34 -0
  25. package/dist/chat/acts.d.ts.map +1 -0
  26. package/dist/chat/acts.js +36 -0
  27. package/dist/chat/context.d.ts +3 -0
  28. package/dist/chat/context.d.ts.map +1 -0
  29. package/dist/chat/context.js +10 -0
  30. package/dist/chat/input.d.ts +9 -0
  31. package/dist/chat/input.d.ts.map +1 -0
  32. package/dist/chat/input.js +99 -0
  33. package/dist/chat/kit.d.ts +60 -0
  34. package/dist/chat/kit.d.ts.map +1 -0
  35. package/dist/chat/kit.js +123 -0
  36. package/dist/chat/lasting.d.ts +6 -0
  37. package/dist/chat/lasting.d.ts.map +1 -0
  38. package/dist/chat/lasting.js +19 -0
  39. package/dist/chat/list.d.ts +26 -0
  40. package/dist/chat/list.d.ts.map +1 -0
  41. package/dist/chat/list.js +62 -0
  42. package/dist/chat/markdown.d.ts +20 -0
  43. package/dist/chat/markdown.d.ts.map +1 -0
  44. package/dist/chat/markdown.js +188 -0
  45. package/dist/chat/message.d.ts +6 -0
  46. package/dist/chat/message.d.ts.map +1 -0
  47. package/dist/chat/message.js +192 -0
  48. package/dist/chat/messages.d.ts +21 -0
  49. package/dist/chat/messages.d.ts.map +1 -0
  50. package/dist/chat/messages.js +151 -0
  51. package/dist/chat/name.d.ts +6 -0
  52. package/dist/chat/name.d.ts.map +1 -0
  53. package/dist/chat/name.js +37 -0
  54. package/dist/chat/opened.d.ts +11 -0
  55. package/dist/chat/opened.d.ts.map +1 -0
  56. package/dist/chat/opened.js +17 -0
  57. package/dist/chat/overlay.d.ts +31 -0
  58. package/dist/chat/overlay.d.ts.map +1 -0
  59. package/dist/chat/overlay.js +97 -0
  60. package/dist/chat/parts.d.ts +57 -0
  61. package/dist/chat/parts.d.ts.map +1 -0
  62. package/dist/chat/parts.js +119 -0
  63. package/dist/chat/process.d.ts +20 -0
  64. package/dist/chat/process.d.ts.map +1 -0
  65. package/dist/chat/process.js +32 -0
  66. package/dist/chat/provider.d.ts +63 -0
  67. package/dist/chat/provider.d.ts.map +1 -0
  68. package/dist/chat/provider.js +645 -0
  69. package/dist/chat/question.d.ts +9 -0
  70. package/dist/chat/question.d.ts.map +1 -0
  71. package/dist/chat/question.js +80 -0
  72. package/dist/chat/questions.d.ts +31 -0
  73. package/dist/chat/questions.d.ts.map +1 -0
  74. package/dist/chat/questions.js +111 -0
  75. package/dist/chat/read.d.ts +5 -0
  76. package/dist/chat/read.d.ts.map +1 -0
  77. package/dist/chat/read.js +13 -0
  78. package/dist/chat/ready.d.ts +33 -0
  79. package/dist/chat/ready.d.ts.map +1 -0
  80. package/dist/chat/ready.js +91 -0
  81. package/dist/chat/style.d.ts +4 -0
  82. package/dist/chat/style.d.ts.map +1 -0
  83. package/dist/chat/style.js +302 -0
  84. package/dist/chat.d.ts +14 -0
  85. package/dist/chat.d.ts.map +1 -0
  86. package/dist/chat.js +8 -0
  87. package/dist/client.d.ts +49 -33
  88. package/dist/client.d.ts.map +1 -1
  89. package/dist/client.js +164 -183
  90. package/dist/collection.d.ts +9 -17
  91. package/dist/collection.d.ts.map +1 -1
  92. package/dist/collection.js +83 -89
  93. package/dist/connection.d.ts +66 -48
  94. package/dist/connection.d.ts.map +1 -1
  95. package/dist/connection.js +1964 -1173
  96. package/dist/conversation.d.ts +65 -24
  97. package/dist/conversation.d.ts.map +1 -1
  98. package/dist/conversation.js +675 -334
  99. package/dist/durability.js +6 -6
  100. package/dist/entry.d.ts +17 -0
  101. package/dist/entry.d.ts.map +1 -0
  102. package/dist/entry.js +156 -0
  103. package/dist/expectation.d.ts +21 -0
  104. package/dist/expectation.d.ts.map +1 -0
  105. package/dist/expectation.js +70 -0
  106. package/dist/failure.d.ts +13 -0
  107. package/dist/failure.d.ts.map +1 -0
  108. package/dist/failure.js +19 -0
  109. package/dist/fence.d.ts +6 -0
  110. package/dist/fence.d.ts.map +1 -0
  111. package/dist/fence.js +10 -0
  112. package/dist/file.d.ts +2 -2
  113. package/dist/file.d.ts.map +1 -1
  114. package/dist/file.js +48 -71
  115. package/dist/host.d.ts +15 -3
  116. package/dist/host.d.ts.map +1 -1
  117. package/dist/host.js +109 -127
  118. package/dist/identity.d.ts +4 -0
  119. package/dist/identity.d.ts.map +1 -1
  120. package/dist/identity.js +22 -9
  121. package/dist/index.d.ts +17 -11
  122. package/dist/index.d.ts.map +1 -1
  123. package/dist/index.js +4 -3
  124. package/dist/log.js +5 -6
  125. package/dist/memory.d.ts +19 -8
  126. package/dist/memory.d.ts.map +1 -1
  127. package/dist/memory.js +304 -216
  128. package/dist/model.d.ts +16 -30
  129. package/dist/model.d.ts.map +1 -1
  130. package/dist/model.js +21 -21
  131. package/dist/observation.d.ts +27 -0
  132. package/dist/observation.d.ts.map +1 -0
  133. package/dist/observation.js +95 -0
  134. package/dist/open.d.ts +2 -0
  135. package/dist/open.d.ts.map +1 -0
  136. package/dist/open.js +1 -0
  137. package/dist/outcome.d.ts +37 -31
  138. package/dist/outcome.d.ts.map +1 -1
  139. package/dist/outcome.js +36 -18
  140. package/dist/overlay.d.ts +22 -4
  141. package/dist/overlay.d.ts.map +1 -1
  142. package/dist/overlay.js +236 -54
  143. package/dist/paths.d.ts +0 -2
  144. package/dist/paths.d.ts.map +1 -1
  145. package/dist/paths.js +6 -29
  146. package/dist/query.d.ts +219 -10
  147. package/dist/query.d.ts.map +1 -1
  148. package/dist/query.js +462 -15
  149. package/dist/reach.d.ts +42 -0
  150. package/dist/reach.d.ts.map +1 -0
  151. package/dist/reach.js +294 -0
  152. package/dist/react.d.ts +41 -0
  153. package/dist/react.d.ts.map +1 -0
  154. package/dist/react.js +64 -0
  155. package/dist/read-side.d.ts +18 -0
  156. package/dist/read-side.d.ts.map +1 -0
  157. package/dist/read-side.js +440 -0
  158. package/dist/refresh.d.ts +15 -5
  159. package/dist/refresh.d.ts.map +1 -1
  160. package/dist/refresh.js +64 -41
  161. package/dist/replica.d.ts +28 -5
  162. package/dist/replica.d.ts.map +1 -1
  163. package/dist/replica.js +249 -40
  164. package/dist/room-draft.d.ts +144 -0
  165. package/dist/room-draft.d.ts.map +1 -0
  166. package/dist/room-draft.js +438 -0
  167. package/dist/rows.d.ts +46 -0
  168. package/dist/rows.d.ts.map +1 -0
  169. package/dist/rows.js +145 -0
  170. package/dist/save.d.ts +33 -5
  171. package/dist/save.d.ts.map +1 -1
  172. package/dist/save.js +630 -366
  173. package/dist/search.d.ts +62 -0
  174. package/dist/search.d.ts.map +1 -0
  175. package/dist/search.js +125 -0
  176. package/dist/status.d.ts +6 -8
  177. package/dist/status.d.ts.map +1 -1
  178. package/dist/status.js +8 -20
  179. package/dist/store.d.ts +89 -34
  180. package/dist/store.d.ts.map +1 -1
  181. package/dist/store.js +513 -132
  182. package/dist/transfer.d.ts +5 -0
  183. package/dist/transfer.d.ts.map +1 -1
  184. package/dist/transfer.js +1 -5
  185. package/dist/wire.d.ts +59 -19
  186. package/dist/wire.d.ts.map +1 -1
  187. package/dist/wire.js +88 -105
  188. package/package.json +34 -16
  189. package/dist/adapter.js.map +0 -1
  190. package/dist/bootstrap.js.map +0 -1
  191. package/dist/change.js.map +0 -1
  192. package/dist/client.js.map +0 -1
  193. package/dist/collection.js.map +0 -1
  194. package/dist/connection.js.map +0 -1
  195. package/dist/conversation.js.map +0 -1
  196. package/dist/durability.js.map +0 -1
  197. package/dist/file.js.map +0 -1
  198. package/dist/host.js.map +0 -1
  199. package/dist/identity.js.map +0 -1
  200. package/dist/index.js.map +0 -1
  201. package/dist/log.js.map +0 -1
  202. package/dist/memory.js.map +0 -1
  203. package/dist/model.js.map +0 -1
  204. package/dist/outcome.js.map +0 -1
  205. package/dist/overlay.js.map +0 -1
  206. package/dist/paths.js.map +0 -1
  207. package/dist/query.js.map +0 -1
  208. package/dist/refresh.js.map +0 -1
  209. package/dist/replica.js.map +0 -1
  210. package/dist/save.js.map +0 -1
  211. package/dist/status.js.map +0 -1
  212. package/dist/store.js.map +0 -1
  213. package/dist/transfer.js.map +0 -1
  214. package/dist/wire.js.map +0 -1
@@ -1,401 +1,742 @@
1
+ import { conversationChangeSet } from './change-set.js';
2
+ import { runtimeError } from './failure.js';
1
3
  import { declaredFile } from './file.js';
2
- const NO_TURNS = new Set();
3
- function carriedMessage(value) {
4
- if (typeof value !== 'object' || value === null) return null;
5
- const record = value;
6
- if (typeof record.turn !== 'string') return null;
7
- return structuredClone(value);
8
- }
9
- function historyPage(result) {
10
- if (result.kind !== 'action') return null;
11
- const answer = result.result;
12
- if (typeof answer !== 'object' || answer === null) return null;
13
- const record = answer;
14
- if (!Array.isArray(record.messages)) return null;
15
- const messages = [];
16
- for (const entry of record.messages){
17
- const carried = carriedMessage(entry);
18
- if (carried !== null) messages.push(carried);
19
- }
4
+ import { chatDraftRevision } from './identity.js';
5
+ const QUIET = {
6
+ turn: null,
7
+ questions: [],
8
+ process: null,
9
+ commands: [],
10
+ options: [],
11
+ };
12
+ export function unheldView(conversation) {
20
13
  return {
21
- messages,
22
- cursor: typeof record.cursor === 'string' ? record.cursor : null
14
+ conversation,
15
+ messages: [],
16
+ turn: null,
17
+ questions: [],
18
+ process: null,
19
+ commands: [],
20
+ options: [],
21
+ chatDraft: null,
23
22
  };
24
23
  }
25
- function turnOf(result) {
26
- if (result.kind !== 'action') return null;
27
- const answer = result.result;
28
- if (typeof answer !== 'object' || answer === null) return null;
29
- const record = answer;
30
- return typeof record.turn === 'string' ? record.turn : null;
24
+ function startedTurn(turn, operation) {
25
+ if (operation.op === 'begin')
26
+ return { turn, started: operation.at, parts: [], context: null };
27
+ if (operation.op === 'context') {
28
+ return {
29
+ turn,
30
+ started: null,
31
+ parts: [],
32
+ context: { used: operation.used, window: operation.window },
33
+ };
34
+ }
35
+ return operation.op === 'start' && operation.index === 0
36
+ ? { turn, started: null, parts: [structuredClone(operation.part)], context: null }
37
+ : null;
31
38
  }
32
- function newest(held, page, arrived) {
33
- const arriving = new Set(page.messages.map((entry)=>entry.turn));
34
- const overlap = held.messages.findIndex((entry)=>arriving.has(entry.turn));
35
- const carried = overlap === -1 ? [] : held.messages.slice(0, overlap);
36
- const placed = new Set([
37
- ...carried,
38
- ...page.messages
39
- ].map((entry)=>entry.turn));
40
- const live = held.messages.filter((entry)=>arrived.has(entry.turn) && !placed.has(entry.turn));
39
+ function changedFields(part, operation) {
40
+ if (operation.op === 'append') {
41
+ return { text: `${String(part.text ?? '')}${operation.text}` };
42
+ }
43
+ if (operation.op === 'status') {
44
+ return { status: operation.status, result: structuredClone(operation.result) };
45
+ }
46
+ if (operation.op === 'count')
47
+ return { count: operation.count };
48
+ return { entries: structuredClone(operation.entries) };
49
+ }
50
+ function appliedTurn(held, operation) {
51
+ if (operation.op === 'begin')
52
+ return { ...held, started: operation.at };
53
+ if (operation.op === 'context') {
54
+ return { ...held, context: { used: operation.used, window: operation.window } };
55
+ }
56
+ if (operation.op === 'start') {
57
+ if (operation.index !== 0 && operation.index !== held.parts.length)
58
+ return null;
59
+ return {
60
+ ...held,
61
+ parts: [...held.parts.slice(0, operation.index), structuredClone(operation.part)],
62
+ };
63
+ }
64
+ const part = held.parts[operation.index];
65
+ if (typeof part !== 'object' || part === null)
66
+ return null;
67
+ const changed = { ...part, ...changedFields(part, operation) };
41
68
  return {
42
69
  ...held,
43
- messages: [
44
- ...carried,
45
- ...page.messages,
46
- ...live
47
- ],
48
- cursor: overlap === -1 ? page.cursor : held.cursor
70
+ parts: held.parts.map((kept, at) => (at === operation.index ? changed : kept)),
49
71
  };
50
72
  }
51
- function older(held, page) {
52
- const present = new Set(held.messages.map((entry)=>entry.turn));
73
+ function ordered(left, right) {
74
+ if (left.position !== right.position)
75
+ return left.position < right.position ? -1 : 1;
76
+ if (left.identity !== right.identity)
77
+ return left.identity < right.identity ? -1 : 1;
78
+ return 0;
79
+ }
80
+ function merged(held, arriving) {
81
+ const byIdentity = new Map(held.map((message) => [message.identity, message]));
82
+ for (const message of arriving)
83
+ byIdentity.set(message.identity, message);
84
+ return [...byIdentity.values()].sort(ordered);
85
+ }
86
+ function acceptedMessage(value) {
87
+ if (typeof value !== 'object' || value === null)
88
+ return null;
89
+ const record = value;
90
+ if (typeof record.identity !== 'string' ||
91
+ typeof record.turn !== 'string' ||
92
+ typeof record.position !== 'string' ||
93
+ typeof record.text !== 'string') {
94
+ return null;
95
+ }
53
96
  return {
54
- ...held,
55
- messages: [
56
- ...page.messages.filter((entry)=>!present.has(entry.turn)),
57
- ...held.messages
58
- ],
59
- cursor: page.cursor
97
+ identity: record.identity,
98
+ turn: record.turn,
99
+ position: record.position,
100
+ text: record.text,
101
+ message: structuredClone(record.message),
60
102
  };
61
103
  }
62
- function sealed(held, arriving) {
63
- const at = held.messages.findIndex((entry)=>entry.turn === arriving.turn);
64
- if (at === -1) return {
65
- ...held,
66
- messages: [
67
- ...held.messages,
68
- arriving
69
- ]
70
- };
71
- const messages = [
72
- ...held.messages
73
- ];
74
- messages[at] = arriving;
104
+ function historyPage(value) {
105
+ if (typeof value !== 'object' || value === null)
106
+ return null;
107
+ const record = value;
108
+ if (typeof record.conversation !== 'string' || !Array.isArray(record.messages))
109
+ return null;
110
+ if (record.next !== undefined && typeof record.next !== 'string')
111
+ return null;
112
+ const messages = [];
113
+ for (const entry of record.messages) {
114
+ const message = acceptedMessage(entry);
115
+ if (message === null)
116
+ return null;
117
+ messages.push(message);
118
+ }
75
119
  return {
76
- ...held,
77
- messages
120
+ conversation: record.conversation,
121
+ messages,
122
+ ...(record.next === undefined ? {} : { next: record.next }),
78
123
  };
79
124
  }
125
+ function historyPages(result) {
126
+ if (result.kind !== 'action')
127
+ return null;
128
+ const answer = result.result;
129
+ if (typeof answer !== 'object' || answer === null)
130
+ return null;
131
+ const { histories } = answer;
132
+ if (!Array.isArray(histories))
133
+ return null;
134
+ const pages = [];
135
+ for (const entry of histories) {
136
+ const page = historyPage(entry);
137
+ if (page === null)
138
+ return null;
139
+ pages.push(page);
140
+ }
141
+ return pages;
142
+ }
143
+ function turnOf(result) {
144
+ if (result.kind !== 'action')
145
+ return null;
146
+ const answer = result.result;
147
+ if (typeof answer !== 'object' || answer === null)
148
+ return null;
149
+ const record = answer;
150
+ return typeof record.turn === 'string' ? record.turn : null;
151
+ }
152
+ function limitOf(options) {
153
+ const { limit } = options;
154
+ if (limit === undefined)
155
+ return undefined;
156
+ if (!Number.isInteger(limit) || limit < 0) {
157
+ throw runtimeError('invalid-limit', `conversation limit must be a non-negative integer, got ${String(limit)}`);
158
+ }
159
+ return limit;
160
+ }
80
161
  export function createConversationStore(deps) {
81
- const held = new Map();
82
- const composed = new Map();
83
- const growing = new Map();
84
- const viewers = new Set();
85
- const issued = new Map();
86
- const live = new Map();
87
- let handed;
88
- function heldOf(conversation) {
89
- return held.get(conversation) ?? {
90
- messages: [],
91
- cursor: null,
92
- summary: null
93
- };
162
+ const messages = new Map();
163
+ const reads = new Map();
164
+ const drafts = new Map();
165
+ const sending = new Map();
166
+ const behind = new Set();
167
+ const gaps = new Map();
168
+ const lives = new Map();
169
+ const views = new Map();
170
+ const listing = new Map();
171
+ const listWatchers = new Set();
172
+ let listKnown = false;
173
+ const agentWatchers = new Set();
174
+ let agentNames = new Map();
175
+ let retiredAgents = new Set();
176
+ let agentsRead = null;
177
+ let replicated = new Set();
178
+ let handedReplicated;
179
+ function liveOf(conversation) {
180
+ return lives.get(conversation) ?? QUIET;
94
181
  }
95
- function instructionOf(conversation) {
96
- return composed.get(conversation) ?? {
97
- text: '',
98
- files: [],
99
- turn: null
100
- };
182
+ function shownMessages(conversation, limit) {
183
+ const held = messages.get(conversation) ?? [];
184
+ const shown = limit === undefined ? held : held.slice(Math.max(0, held.length - limit));
185
+ return shown.map(({ identity, turn, text, message }) => ({
186
+ identity,
187
+ turn,
188
+ text,
189
+ message: structuredClone(message),
190
+ }));
101
191
  }
102
- function viewOf(conversation) {
103
- const carried = heldOf(conversation);
104
- const unsent = composed.get(conversation);
192
+ function viewOf(conversation, limit, shown = shownMessages(conversation, limit)) {
193
+ const draft = drafts.get(conversation);
194
+ const facts = liveOf(conversation);
105
195
  return {
106
196
  conversation,
107
- messages: structuredClone(carried.messages),
108
- olderPages: carried.cursor !== null,
109
- growingText: growing.get(conversation) ?? null,
110
- summary: structuredClone(carried.summary),
111
- instruction: unsent === undefined || unsent.turn !== null ? null : {
112
- text: unsent.text,
113
- files: [
114
- ...unsent.files
115
- ]
116
- }
197
+ messages: shown,
198
+ turn: structuredClone(facts.turn),
199
+ questions: structuredClone(facts.questions),
200
+ process: facts.process === null ? null : { ...facts.process },
201
+ commands: structuredClone(facts.commands),
202
+ options: structuredClone(facts.options),
203
+ chatDraft: draft === undefined || draft.turn !== null || sending.get(conversation)?.draft === draft
204
+ ? null
205
+ : { text: draft.text, files: [...draft.files], revision: draft.revision },
117
206
  };
118
207
  }
119
- function emit(conversation) {
120
- if (deps.closed()) return;
121
- for (const viewer of viewers){
122
- if (viewer.conversation === conversation && viewer.ready) viewer.notify(viewOf(conversation));
208
+ function emit(conversation, messagesChanged = true) {
209
+ if (deps.closed())
210
+ return;
211
+ for (const view of views.values()) {
212
+ if (view.conversation !== conversation)
213
+ continue;
214
+ if (messagesChanged)
215
+ view.messages = null;
216
+ const ready = [...view.watchers].filter((watcher) => watcher.ready);
217
+ if (ready.length === 0)
218
+ continue;
219
+ view.messages ??= shownMessages(conversation, view.limit);
220
+ const value = viewOf(conversation, view.limit, view.messages);
221
+ for (const watcher of ready)
222
+ watcher.notify(value);
123
223
  }
124
224
  }
125
- function viewed() {
126
- return [
127
- ...new Set([
128
- ...viewers
129
- ].map((viewer)=>viewer.conversation))
130
- ].sort();
131
- }
132
- function hand() {
133
- const path = deps.path();
134
- if (path === undefined) return;
135
- const open = viewed();
136
- const named = JSON.stringify(open);
137
- if (named === handed) return;
138
- handed = named;
139
- path.view(open);
140
- }
141
- function keptRecord(conversation) {
142
- const carried = heldOf(conversation);
143
- return {
144
- conversation,
145
- messages: carried.messages,
146
- cursor: carried.cursor,
147
- summary: carried.summary
148
- };
225
+ function stateOf(conversation) {
226
+ const facts = liveOf(conversation);
227
+ if (facts.questions.length > 0)
228
+ return 'asking';
229
+ return facts.turn === null ? 'idle' : 'working';
230
+ }
231
+ function entries() {
232
+ return [...listing.values()].map((entry) => ({
233
+ conversation: entry.conversation,
234
+ agent: { identity: entry.agent, name: agentNames.get(entry.agent) ?? null },
235
+ name: entry.name,
236
+ created: entry.created,
237
+ finished: entry.finished,
238
+ outcome: entry.outcome,
239
+ state: stateOf(entry.conversation),
240
+ started: lives.get(entry.conversation)?.turn?.started ?? null,
241
+ }));
242
+ }
243
+ function emitList() {
244
+ if (deps.closed() || listWatchers.size === 0)
245
+ return;
246
+ const value = entries();
247
+ for (const watcher of listWatchers)
248
+ watcher(value);
249
+ }
250
+ function agents() {
251
+ return [...agentNames]
252
+ .filter(([identity]) => !retiredAgents.has(identity))
253
+ .map(([identity, name]) => ({ identity, name }))
254
+ .sort((left, right) => left.name === right.name
255
+ ? left.identity.localeCompare(right.identity)
256
+ : left.name.localeCompare(right.name));
257
+ }
258
+ function emitAgents() {
259
+ if (deps.closed() || agentWatchers.size === 0)
260
+ return;
261
+ const value = agents();
262
+ for (const watcher of agentWatchers)
263
+ watcher(value);
264
+ }
265
+ function setLive(conversation, next) {
266
+ const before = stateOf(conversation);
267
+ const began = lives.get(conversation)?.turn?.started;
268
+ if (next === null)
269
+ lives.delete(conversation);
270
+ else
271
+ lives.set(conversation, next);
272
+ if (!listing.has(conversation))
273
+ return;
274
+ if (stateOf(conversation) !== before || next?.turn?.started !== began)
275
+ emitList();
149
276
  }
150
- async function settle(local, conversation) {
151
- const sent = instructionOf(conversation).turn;
152
- if (sent === null) return;
153
- if (!heldOf(conversation).messages.some((entry)=>entry.turn === sent)) return;
154
- composed.delete(conversation);
155
- await local.dropInstruction(conversation);
156
- }
157
- async function keep(conversation, next) {
158
- const kept = await deps.durably(async (local)=>{
159
- const following = next(heldOf(conversation));
160
- if (following === null) return false;
161
- held.set(conversation, following);
162
- await local.keepConversation(keptRecord(conversation));
163
- await settle(local, conversation);
164
- return true;
277
+ async function readAgents() {
278
+ const declaration = deps.agents();
279
+ if (declaration === undefined)
280
+ return;
281
+ const { documents } = await deps.documents(declaration.locator);
282
+ const names = new Map();
283
+ const retired = new Set();
284
+ for (const document of documents) {
285
+ if (document.type !== declaration.type)
286
+ continue;
287
+ const identity = document.fields?.[declaration.identity];
288
+ const name = document.fields?.[declaration.name];
289
+ if (typeof identity !== 'string' || typeof name !== 'string')
290
+ continue;
291
+ names.set(identity, name);
292
+ const ended = declaration.retired === undefined ? null : document.fields?.[declaration.retired];
293
+ if (ended !== undefined && ended !== null)
294
+ retired.add(identity);
295
+ }
296
+ const named = JSON.stringify([...names]) !== JSON.stringify([...agentNames]);
297
+ if (!named && JSON.stringify([...retired]) === JSON.stringify([...retiredAgents]))
298
+ return;
299
+ agentNames = names;
300
+ retiredAgents = retired;
301
+ if (named)
302
+ emitList();
303
+ emitAgents();
304
+ }
305
+ function agentsReady() {
306
+ agentsRead ??= readAgents().catch(() => {
307
+ agentsRead = null;
308
+ });
309
+ return agentsRead;
310
+ }
311
+ function live(conversation, change) {
312
+ setLive(conversation, { ...liveOf(conversation), ...change });
313
+ emit(conversation, false);
314
+ }
315
+ function relayed(conversation, turn, operation) {
316
+ const held = liveOf(conversation).turn;
317
+ const next = held?.turn === turn ? appliedTurn(held, operation) : startedTurn(turn, operation);
318
+ if (next !== null)
319
+ live(conversation, { turn: next });
320
+ }
321
+ function sealTurns(conversation, turns) {
322
+ const held = lives.get(conversation);
323
+ if (held?.turn == null || !turns.has(held.turn.turn))
324
+ return false;
325
+ setLive(conversation, { ...held, turn: null });
326
+ return true;
327
+ }
328
+ function handReplicated() {
329
+ const stream = deps.stream();
330
+ if (stream === undefined)
331
+ return;
332
+ const held = [...replicated].sort();
333
+ const named = JSON.stringify(held);
334
+ if (named === handedReplicated)
335
+ return;
336
+ handedReplicated = named;
337
+ stream.replicate(held);
338
+ }
339
+ async function remove(leaving) {
340
+ await deps.durably(async (local) => {
341
+ await local.dropConversations(leaving);
342
+ const removed = [];
343
+ const changed = [];
344
+ for (const conversation of leaving) {
345
+ for (const message of messages.get(conversation) ?? []) {
346
+ removed.push({ conversation, identity: message.identity });
347
+ }
348
+ if (messages.has(conversation) || drafts.has(conversation) || lives.has(conversation)) {
349
+ changed.push(conversation);
350
+ }
351
+ messages.delete(conversation);
352
+ reads.delete(conversation);
353
+ drafts.delete(conversation);
354
+ behind.delete(conversation);
355
+ setLive(conversation, null);
356
+ }
357
+ if (changed.length > 0)
358
+ deps.publish(conversationChangeSet(removed, changed));
165
359
  });
166
- if (kept) emit(conversation);
167
- return kept;
168
- }
169
- async function keepInstruction(conversation, next) {
170
- await deps.durably(async (local)=>{
171
- const stored = next(instructionOf(conversation));
172
- composed.set(conversation, stored);
173
- await local.keepInstruction({
360
+ }
361
+ function gap(conversation) {
362
+ gaps.set(conversation, (gaps.get(conversation) ?? 0) + 1);
363
+ behind.add(conversation);
364
+ }
365
+ function keep(conversation, message) {
366
+ return deps.durably(async (local) => {
367
+ if (!replicated.has(conversation))
368
+ return;
369
+ const read = reads.get(conversation);
370
+ const advances = read !== undefined &&
371
+ !behind.has(conversation) &&
372
+ (read === null || message.position > read);
373
+ const sealed = drafts.get(conversation)?.turn === message.turn;
374
+ await local.keepMessages({
174
375
  conversation,
175
- ...stored
376
+ messages: [message],
377
+ ...(advances ? { read: message.position } : {}),
378
+ sealed,
176
379
  });
177
- await settle(local, conversation);
380
+ messages.set(conversation, merged(messages.get(conversation) ?? [], [message]));
381
+ if (advances)
382
+ reads.set(conversation, message.position);
383
+ if (sealed)
384
+ drafts.delete(conversation);
385
+ sealTurns(conversation, new Set([message.turn]));
386
+ deps.publish(conversationChangeSet([{ conversation, identity: message.identity }], [conversation]));
178
387
  });
179
- emit(conversation);
180
388
  }
181
- async function dropInstruction(conversation) {
182
- await deps.durably(async (local)=>{
183
- composed.delete(conversation);
184
- await local.dropInstruction(conversation);
389
+ async function readHistories(conversations) {
390
+ const generations = new Map(conversations.map((one) => [one, gaps.get(one) ?? 0]));
391
+ const starts = new Map(conversations.map((one) => [one, reads.get(one)]));
392
+ const arriving = new Map();
393
+ const complete = new Set();
394
+ let asking = conversations.map((conversation) => ({
395
+ conversation,
396
+ after: starts.get(conversation) ?? undefined,
397
+ }));
398
+ while (asking.length > 0) {
399
+ const result = await deps.call('conversation.history', {
400
+ conversations: asking.map(({ conversation, after }) => ({
401
+ conversation,
402
+ ...(after === undefined ? {} : { after }),
403
+ })),
404
+ });
405
+ const pages = historyPages(result);
406
+ if (pages === null)
407
+ return result;
408
+ const asked = new Set(asking.map(({ conversation }) => conversation));
409
+ const following = [];
410
+ for (const page of pages) {
411
+ if (!asked.has(page.conversation))
412
+ continue;
413
+ arriving.set(page.conversation, [
414
+ ...(arriving.get(page.conversation) ?? []),
415
+ ...page.messages,
416
+ ]);
417
+ if (page.next === undefined)
418
+ complete.add(page.conversation);
419
+ else
420
+ following.push({ conversation: page.conversation, after: page.next });
421
+ }
422
+ asking = following;
423
+ }
424
+ for (const [conversation, held] of arriving) {
425
+ if (!complete.has(conversation))
426
+ continue;
427
+ await keepHistory(conversation, held, starts.get(conversation), generations.get(conversation) ?? 0);
428
+ }
429
+ return null;
430
+ }
431
+ function keepHistory(conversation, arriving, from, generation) {
432
+ return deps.durably(async (local) => {
433
+ if (!replicated.has(conversation))
434
+ return;
435
+ const newest = arriving.reduce((top, message) => (top === null || message.position > top ? message.position : top), from ?? null);
436
+ const turn = drafts.get(conversation)?.turn;
437
+ const sealed = arriving.some((message) => message.turn === turn);
438
+ await local.keepMessages({ conversation, messages: arriving, read: newest, sealed });
439
+ messages.set(conversation, merged(messages.get(conversation) ?? [], arriving));
440
+ reads.set(conversation, newest);
441
+ if (sealed)
442
+ drafts.delete(conversation);
443
+ sealTurns(conversation, new Set(arriving.map((message) => message.turn)));
444
+ if ((gaps.get(conversation) ?? 0) === generation)
445
+ behind.delete(conversation);
446
+ if (arriving.length > 0 || sealed) {
447
+ deps.publish(conversationChangeSet(arriving.map((message) => ({ conversation, identity: message.identity })), [conversation]));
448
+ }
185
449
  });
186
- emit(conversation);
187
450
  }
188
- function supersede(conversation) {
189
- issued.set(conversation, (issued.get(conversation) ?? 0) + 1);
451
+ function heard(event) {
452
+ const { conversation } = event;
453
+ if (event.kind === 'gap') {
454
+ if (replicated.has(conversation))
455
+ gap(conversation);
456
+ const held = lives.get(conversation);
457
+ if (held === undefined)
458
+ return;
459
+ setLive(conversation, { ...QUIET, turn: held.turn });
460
+ emit(conversation, false);
461
+ return;
462
+ }
463
+ if (event.kind === 'turn') {
464
+ relayed(conversation, event.turn, event.operation);
465
+ return;
466
+ }
467
+ if (event.kind === 'questions') {
468
+ live(conversation, { questions: structuredClone(event.questions) });
469
+ return;
470
+ }
471
+ if (event.kind === 'process') {
472
+ live(conversation, { process: { running: event.running } });
473
+ return;
474
+ }
475
+ if (event.kind === 'commands') {
476
+ live(conversation, { commands: structuredClone(event.commands) });
477
+ return;
478
+ }
479
+ if (event.kind === 'options') {
480
+ live(conversation, { options: structuredClone(event.options) });
481
+ return;
482
+ }
483
+ const arriving = acceptedMessage(event.message);
484
+ if (arriving === null)
485
+ return;
486
+ if (replicated.has(conversation)) {
487
+ void keep(conversation, arriving).catch(() => { });
488
+ return;
489
+ }
490
+ if (sealTurns(conversation, new Set([arriving.turn])))
491
+ emit(conversation);
190
492
  }
191
- async function fill(conversation, cursor) {
192
- const generation = issued.get(conversation);
193
- const result = await deps.call('conversation.history', {
194
- conversation,
195
- ...cursor === null ? {} : {
196
- cursor
493
+ function withDraft(conversation, next) {
494
+ return deps.durably(async (local) => {
495
+ const following = next(drafts.get(conversation));
496
+ if (following === undefined)
497
+ return;
498
+ if (following === null) {
499
+ await local.dropChatDraft(conversation);
500
+ drafts.delete(conversation);
197
501
  }
502
+ else {
503
+ await local.keepChatDraft(following);
504
+ drafts.set(conversation, following);
505
+ }
506
+ deps.publish(conversationChangeSet([], [conversation]));
198
507
  });
199
- const page = historyPage(result);
200
- if (page === null) return result;
201
- const landed = await keep(conversation, (carried)=>{
202
- if (issued.get(conversation) !== generation) return null;
203
- if (cursor !== null) return carried.cursor === cursor ? older(carried, page) : null;
204
- return newest(carried, page, live.get(conversation) ?? NO_TURNS);
205
- });
206
- if (landed && cursor === null) live.delete(conversation);
207
- return result;
208
508
  }
209
509
  function invoke(name, conversation, extra = {}) {
210
- return deps.call(name, {
211
- conversation,
212
- ...extra
213
- });
510
+ return deps.call(name, { conversation, ...extra });
214
511
  }
215
512
  const surface = {
216
- list () {
217
- const declaration = deps.cards();
218
- if (declaration === undefined) return Promise.resolve([]);
219
- const documents = deps.documents().documents.filter((document)=>document.room === declaration.locator);
220
- const entries = [];
221
- for (const card of documents){
222
- if (card.type !== declaration.type) continue;
223
- const identity = card.fields[declaration.identity];
224
- if (typeof identity !== 'string') continue;
225
- const agent = documents.find((document)=>document.backlinks.some((backlink)=>backlink.path === card.path && backlink.field === declaration.agent));
226
- entries.push({
227
- conversation: identity,
228
- card,
229
- agent: agent ?? null
230
- });
231
- }
232
- entries.sort((left, right)=>left.conversation < right.conversation ? -1 : 1);
233
- return Promise.resolve(entries);
234
- },
235
- read (conversation) {
236
- return deps.durably(()=>Promise.resolve(viewOf(conversation)));
237
- },
238
- older (conversation) {
239
- const cursor = heldOf(conversation).cursor;
240
- if (cursor === null) return Promise.resolve(null);
241
- return fill(conversation, cursor);
513
+ async list() {
514
+ await agentsReady();
515
+ return entries();
242
516
  },
243
- compose (conversation, supplied) {
244
- return keepInstruction(conversation, ()=>({
245
- text: supplied.text,
246
- files: [
247
- ...supplied.files
248
- ],
249
- turn: null
250
- }));
517
+ async read(conversation, options = {}) {
518
+ const limit = limitOf(options);
519
+ return deps.durably(() => Promise.resolve(viewOf(conversation, limit)));
251
520
  },
252
- discard (conversation) {
253
- return dropInstruction(conversation);
254
- },
255
- create (input) {
521
+ create(input) {
256
522
  return deps.call('conversation.create', input);
257
523
  },
258
- async send (conversation) {
259
- const unsent = instructionOf(conversation);
260
- const files = await Promise.all(unsent.files.map(declaredFile));
261
- const result = await invoke('conversation.send', conversation, {
262
- text: unsent.text,
263
- files
264
- });
265
- const turn = turnOf(result);
266
- if (turn === null) return result;
267
- await keepInstruction(conversation, (stored)=>({
268
- ...stored,
269
- turn
270
- }));
271
- return result;
524
+ async send(conversation) {
525
+ const draft = drafts.get(conversation);
526
+ const pending = draft === undefined ? undefined : { draft };
527
+ if (pending !== undefined) {
528
+ sending.set(conversation, pending);
529
+ deps.publish(conversationChangeSet([], [conversation]));
530
+ }
531
+ try {
532
+ const files = await Promise.all((draft?.files ?? []).map(async (file) => ({
533
+ ...(await declaredFile(file)),
534
+ blob: file.blob,
535
+ })));
536
+ const result = await invoke('conversation.send', conversation, {
537
+ text: draft?.text ?? '',
538
+ files,
539
+ });
540
+ const turn = turnOf(result);
541
+ if (turn === null || draft === undefined)
542
+ return result;
543
+ await withDraft(conversation, (current) => {
544
+ if (current !== draft)
545
+ return undefined;
546
+ const sealed = (messages.get(conversation) ?? []).some((message) => message.turn === turn);
547
+ return sealed ? null : { ...draft, turn };
548
+ });
549
+ return result;
550
+ }
551
+ finally {
552
+ if (pending !== undefined && sending.get(conversation) === pending) {
553
+ sending.delete(conversation);
554
+ if (drafts.get(conversation) === draft) {
555
+ deps.publish(conversationChangeSet([], [conversation]));
556
+ }
557
+ }
558
+ }
272
559
  },
273
- answer (conversation, answer) {
274
- return invoke('conversation.answer', conversation, {
275
- answer
276
- });
560
+ answer(conversation, answer) {
561
+ return invoke('conversation.answer', conversation, { answer });
277
562
  },
278
- interrupt (conversation) {
563
+ interrupt(conversation) {
279
564
  return invoke('conversation.interrupt', conversation);
280
565
  },
281
- kill (conversation) {
566
+ kill(conversation) {
282
567
  return invoke('conversation.kill', conversation);
283
568
  },
284
- async cancel (conversation, turn) {
285
- const result = await invoke('conversation.cancel', conversation, {
286
- turn
287
- });
288
- if (result.kind !== 'action') return result;
289
- if (instructionOf(conversation).turn === turn) {
290
- await keepInstruction(conversation, (stored)=>({
291
- ...stored,
292
- turn: null
293
- }));
294
- }
569
+ async cancel(conversation, turn) {
570
+ const result = await invoke('conversation.cancel', conversation, { turn });
571
+ if (result.kind !== 'action')
572
+ return result;
573
+ await withDraft(conversation, (current) => current === undefined || current.turn !== turn ? undefined : { ...current, turn: null });
295
574
  return result;
296
575
  },
297
- async delete (conversation) {
298
- const result = await invoke('conversation.delete', conversation);
299
- if (result.kind !== 'action') return result;
300
- growing.delete(conversation);
301
- live.delete(conversation);
302
- supersede(conversation);
303
- await deps.durably(async (local)=>{
304
- held.delete(conversation);
305
- composed.delete(conversation);
306
- await local.dropConversation(conversation);
307
- await local.dropInstruction(conversation);
308
- });
309
- emit(conversation);
310
- return result;
311
- }
576
+ delete(conversation) {
577
+ return invoke('conversation.delete', conversation);
578
+ },
579
+ };
580
+ const chatDraft = {
581
+ write(conversation, draft, revision = chatDraftRevision()) {
582
+ return withDraft(conversation, () => ({
583
+ conversation,
584
+ text: draft.text,
585
+ files: [...draft.files],
586
+ turn: null,
587
+ revision,
588
+ }));
589
+ },
590
+ discard(conversation) {
591
+ return withDraft(conversation, (current) => (current === undefined ? undefined : null));
592
+ },
312
593
  };
313
594
  return {
314
595
  surface,
315
- hydrate (conversations, instructions) {
316
- held.clear();
317
- for (const stored of conversations){
318
- held.set(stored.conversation, {
319
- messages: stored.messages,
320
- cursor: stored.cursor,
321
- summary: stored.summary
322
- });
596
+ chatDraft,
597
+ hydrate(held, stored) {
598
+ messages.clear();
599
+ reads.clear();
600
+ for (const view of views.values())
601
+ view.messages = null;
602
+ for (const entry of held) {
603
+ messages.set(entry.conversation, [...entry.messages].sort(ordered));
604
+ if (entry.read !== undefined)
605
+ reads.set(entry.conversation, entry.read);
323
606
  }
324
- composed.clear();
325
- for (const stored of instructions){
326
- composed.set(stored.conversation, {
327
- text: stored.text,
328
- files: stored.files,
329
- turn: stored.turn
330
- });
607
+ drafts.clear();
608
+ for (const record of stored)
609
+ drafts.set(record.conversation, record);
610
+ },
611
+ async reconcile() {
612
+ if (!listKnown)
613
+ return;
614
+ const named = new Set(listing.keys());
615
+ const leaving = [
616
+ ...new Set([...replicated, ...messages.keys(), ...reads.keys(), ...drafts.keys()]),
617
+ ].filter((conversation) => !named.has(conversation));
618
+ for (const conversation of named) {
619
+ if (!replicated.has(conversation))
620
+ behind.add(conversation);
621
+ }
622
+ replicated = named;
623
+ handReplicated();
624
+ if (leaving.length > 0)
625
+ await remove(leaving);
626
+ },
627
+ async catchUp(progress) {
628
+ const reading = [...behind].filter((conversation) => replicated.has(conversation)).sort();
629
+ if (reading.length > 0 && !deps.closed()) {
630
+ const failed = await readHistories(reading);
631
+ if (failed?.kind === 'transport-uncertainty')
632
+ progress.reachable = false;
331
633
  }
634
+ if (behind.size > 0)
635
+ progress.complete = false;
332
636
  },
333
- observe (conversation, notify) {
334
- const first = !viewed().includes(conversation);
335
- const viewer = {
637
+ current() {
638
+ return behind.size === 0;
639
+ },
640
+ reconnected() {
641
+ for (const conversation of replicated)
642
+ gap(conversation);
643
+ },
644
+ watch(conversation, options, deliver) {
645
+ const limit = limitOf(options);
646
+ const key = JSON.stringify([conversation, limit ?? null]);
647
+ const view = views.get(key) ?? {
336
648
  conversation,
337
- notify,
338
- ready: false
649
+ limit,
650
+ watchers: new Set(),
651
+ messages: null,
339
652
  };
340
- viewers.add(viewer);
341
- if (first) {
342
- live.set(conversation, new Set());
343
- supersede(conversation);
344
- }
345
- hand();
346
- void deps.durably(()=>Promise.resolve()).then(async ()=>{
347
- if (deps.closed() || !viewers.has(viewer)) return;
348
- viewer.ready = true;
349
- viewer.notify(viewOf(conversation));
350
- if (first) await fill(conversation, null);
351
- }).catch(()=>{});
352
- return ()=>{
353
- if (!viewers.delete(viewer)) return;
354
- if (!viewed().includes(conversation)) {
355
- growing.delete(conversation);
356
- live.delete(conversation);
357
- }
358
- hand();
653
+ views.set(key, view);
654
+ const watcher = { notify: deliver, ready: false };
655
+ view.watchers.add(watcher);
656
+ void deps
657
+ .durably(() => Promise.resolve())
658
+ .then(() => {
659
+ if (deps.closed() || !view.watchers.has(watcher))
660
+ return;
661
+ watcher.ready = true;
662
+ watcher.notify(viewOf(conversation, limit));
663
+ })
664
+ .catch(() => { });
665
+ return () => {
666
+ if (!view.watchers.delete(watcher))
667
+ return;
668
+ if (view.watchers.size === 0)
669
+ views.delete(key);
359
670
  };
360
671
  },
361
- receive (event) {
362
- if (deps.closed() || !viewed().includes(event.conversation)) return;
363
- if (event.kind === 'growing-text') {
364
- growing.set(event.conversation, {
365
- turn: event.turn,
366
- text: event.text
672
+ watchList(deliver) {
673
+ listWatchers.add(deliver);
674
+ void agentsReady().then(() => {
675
+ if (!deps.closed() && listWatchers.has(deliver))
676
+ deliver(entries());
677
+ });
678
+ return () => {
679
+ listWatchers.delete(deliver);
680
+ };
681
+ },
682
+ watchAgents(deliver) {
683
+ agentWatchers.add(deliver);
684
+ void agentsReady().then(() => {
685
+ if (!deps.closed() && agentWatchers.has(deliver))
686
+ deliver(agents());
687
+ });
688
+ return () => {
689
+ agentWatchers.delete(deliver);
690
+ };
691
+ },
692
+ changed(set) {
693
+ for (const conversation of set.conversations)
694
+ emit(conversation);
695
+ const declaration = deps.agents();
696
+ if (declaration !== undefined &&
697
+ set.documents.some((change) => change.locator === declaration.locator)) {
698
+ agentsRead = readAgents().catch(() => {
699
+ agentsRead = null;
367
700
  });
368
- emit(event.conversation);
369
- return;
370
- }
371
- if (event.kind === 'session-summary') {
372
- const summary = structuredClone(event.summary);
373
- void keep(event.conversation, (carried)=>({
374
- ...carried,
375
- summary
376
- })).catch(()=>{});
377
- return;
378
701
  }
379
- const arriving = carriedMessage(event.message);
380
- if (arriving === null) return;
381
- live.get(event.conversation)?.add(arriving.turn);
382
- if (growing.get(event.conversation)?.turn === arriving.turn) {
383
- growing.delete(event.conversation);
702
+ },
703
+ receive(event) {
704
+ if (deps.closed())
705
+ return false;
706
+ if (event.kind === 'list' || event.kind === 'listed' || event.kind === 'unlisted') {
707
+ if (event.kind === 'list') {
708
+ listing.clear();
709
+ for (const entry of event.entries)
710
+ listing.set(entry.conversation, { ...entry });
711
+ listKnown = true;
712
+ }
713
+ else if (event.kind === 'listed') {
714
+ listing.set(event.entry.conversation, { ...event.entry });
715
+ }
716
+ else {
717
+ listing.delete(event.conversation);
718
+ }
719
+ emitList();
720
+ return (event.kind !== 'list' &&
721
+ listKnown &&
722
+ (listing.size !== replicated.size ||
723
+ [...listing.keys()].some((conversation) => !replicated.has(conversation))));
384
724
  }
385
- void deps.durably(async (local)=>{
386
- held.set(event.conversation, sealed(heldOf(event.conversation), arriving));
387
- await local.keepConversation(keptRecord(event.conversation));
388
- await settle(local, event.conversation);
389
- }).then(()=>{
390
- emit(event.conversation);
391
- }).catch(()=>{});
725
+ heard(event);
726
+ return false;
727
+ },
728
+ messages() {
729
+ return [...messages].flatMap(([conversation, held]) => held.map(({ identity, text }) => ({ conversation, identity, text })));
730
+ },
731
+ message(conversation, identity) {
732
+ const held = messages.get(conversation)?.find((message) => message.identity === identity);
733
+ return held === undefined ? null : { conversation, identity, text: held.text };
734
+ },
735
+ close() {
736
+ views.clear();
737
+ lives.clear();
738
+ listWatchers.clear();
739
+ agentWatchers.clear();
392
740
  },
393
- close () {
394
- viewers.clear();
395
- growing.clear();
396
- live.clear();
397
- }
398
741
  };
399
742
  }
400
-
401
- //# sourceMappingURL=conversation.js.map