@agentshouse/mdruntime-adapter 0.1.0-alpha.4 → 0.1.0-alpha.41

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 (50) hide show
  1. package/AGENTS.md +143 -23
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +3 -11
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +176 -236
  6. package/dist/actions.js.map +1 -1
  7. package/dist/adapter.d.ts +3 -1
  8. package/dist/adapter.d.ts.map +1 -1
  9. package/dist/adapter.js +78 -137
  10. package/dist/adapter.js.map +1 -1
  11. package/dist/discovery.d.ts +39 -11
  12. package/dist/discovery.d.ts.map +1 -1
  13. package/dist/discovery.js +153 -39
  14. package/dist/discovery.js.map +1 -1
  15. package/dist/index.d.ts +1 -1
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/model.d.ts +19 -0
  19. package/dist/model.d.ts.map +1 -0
  20. package/dist/model.js +64 -0
  21. package/dist/model.js.map +1 -0
  22. package/dist/read.d.ts +31 -19
  23. package/dist/read.d.ts.map +1 -1
  24. package/dist/read.js +172 -55
  25. package/dist/read.js.map +1 -1
  26. package/dist/refusal.d.ts +4 -1
  27. package/dist/refusal.d.ts.map +1 -1
  28. package/dist/refusal.js +13 -1
  29. package/dist/refusal.js.map +1 -1
  30. package/dist/site.d.ts +4 -0
  31. package/dist/site.d.ts.map +1 -0
  32. package/dist/site.js +206 -0
  33. package/dist/site.js.map +1 -0
  34. package/dist/stream.d.ts +8 -5
  35. package/dist/stream.d.ts.map +1 -1
  36. package/dist/stream.js +240 -136
  37. package/dist/stream.js.map +1 -1
  38. package/dist/transport.d.ts +47 -29
  39. package/dist/transport.d.ts.map +1 -1
  40. package/dist/transport.js +5 -1
  41. package/dist/transport.js.map +1 -1
  42. package/dist/version.d.ts +14 -0
  43. package/dist/version.d.ts.map +1 -0
  44. package/dist/version.js +29 -0
  45. package/dist/version.js.map +1 -0
  46. package/dist/write.d.ts +6 -0
  47. package/dist/write.d.ts.map +1 -1
  48. package/dist/write.js +51 -9
  49. package/dist/write.js.map +1 -1
  50. package/package.json +4 -12
package/dist/stream.js CHANGED
@@ -1,167 +1,255 @@
1
- import { actionOutcome, HISTORY_PAGE, readConversationHistory } from './actions.js';
2
- import { selects } from './read.js';
3
- import { PRIVATE_AUTHORITY } from './transport.js';
1
+ import { acceptedMessage, actionOutcome } from './actions.js';
2
+ import { headChange, selects } from './read.js';
3
+ import { PRIVATE_LOCATOR } from './transport.js';
4
+ import { roomVersion } from './version.js';
4
5
  const HELD_POSITIONS_MAX = 256;
6
+ const CONVERSATION_CARD = /^agents\/([^/]+)\.md$/;
5
7
  function position(value) {
6
8
  if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
7
9
  return BigInt(value);
8
10
  }
9
- function messageTurn(message) {
10
- if (typeof message !== 'object' || message === null) return null;
11
- const turn = message.message_id;
12
- return typeof turn === 'string' ? turn : null;
13
- }
14
- export function houseNotifications(transport) {
11
+ export function houseNotifications(transport, mode) {
15
12
  const stream = transport.stream;
16
- const held = new Map();
13
+ const lines = new Map();
17
14
  const locators = new Map();
18
- const authorities = new Map();
15
+ const schemas = new Map();
19
16
  const observers = new Set();
20
17
  const conversationObservers = new Set();
21
- const subscribedConversations = new Set();
22
- let selected = [];
23
- let viewed = [];
18
+ const modeObservers = new Set();
19
+ let replicated = [];
20
+ let privateAuthority;
21
+ const live = new Set();
22
+ const noted = new Set();
23
+ const asked = new Map();
24
24
  let listening = false;
25
- function subscribe() {
26
- const named = [];
27
- for (const locator of selected){
28
- const authority = authorities.get(locator);
29
- if (authority === undefined || authority === PRIVATE_AUTHORITY) continue;
30
- named.push({
31
- kind: 'room',
32
- room: authority
33
- });
34
- }
35
- if (authorities.has(PRIVATE_AUTHORITY)) named.push({
36
- kind: 'private'
37
- });
38
- for (const conversation of viewed){
39
- named.push({
40
- kind: 'conversation',
41
- conversation
42
- });
43
- }
44
- stream.subscribe(named);
25
+ let catching = false;
26
+ function listen() {
27
+ if (listening) return;
28
+ listening = true;
29
+ stream.observe(receive);
45
30
  }
46
31
  function emitConversation(event) {
47
- if (!viewed.includes(event.conversation)) return;
32
+ if (event.kind !== 'gap' && event.kind !== 'accepted-message') live.add(event.conversation);
48
33
  for (const observer of conversationObservers)observer(event);
49
34
  }
50
- async function catchUp(conversation, history) {
51
- const viewedAnswer = await transport.door('/door/conversations/view', {
35
+ function unnote(conversation) {
36
+ if (!noted.delete(conversation)) return;
37
+ emitConversation({
38
+ kind: 'working-note',
39
+ conversation,
40
+ note: null
41
+ });
42
+ }
43
+ async function question(conversation) {
44
+ const sequence = (asked.get(conversation) ?? 0) + 1;
45
+ asked.set(conversation, sequence);
46
+ const answer = await transport.door('/door/conversations/interaction/read', {
52
47
  conversation_id: conversation
53
48
  });
54
- const summary = actionOutcome(viewedAnswer, 'conversations/view');
55
- if (summary.kind === 'action' && typeof summary.result === 'object' && summary.result !== null) {
49
+ if (asked.get(conversation) !== sequence || !replicated.includes(conversation)) return;
50
+ const outcome = actionOutcome(answer, 'conversations/interaction/read');
51
+ if (outcome.kind !== 'action') return;
52
+ const { interactions } = outcome.result;
53
+ if (!Array.isArray(interactions)) return;
54
+ emitConversation({
55
+ kind: 'questions',
56
+ conversation,
57
+ questions: structuredClone(interactions)
58
+ });
59
+ }
60
+ function reopened() {
61
+ const gapped = new Set([
62
+ ...replicated,
63
+ ...live
64
+ ]);
65
+ live.clear();
66
+ noted.clear();
67
+ for (const conversation of gapped)emitConversation({
68
+ kind: 'gap',
69
+ conversation
70
+ });
71
+ for (const conversation of replicated)void question(conversation);
72
+ }
73
+ function converse(frame) {
74
+ const conversation = frame.conversation_id;
75
+ if (frame.type === 'draft') {
76
+ unnote(conversation);
56
77
  emitConversation({
57
- kind: 'session-summary',
78
+ kind: 'growing-text',
58
79
  conversation,
59
- summary: structuredClone('session' in summary.result ? summary.result.session : null)
80
+ turn: frame.turn_id,
81
+ text: frame.text
60
82
  });
83
+ emitConversation({
84
+ kind: 'plan',
85
+ conversation,
86
+ turn: frame.turn_id,
87
+ plan: structuredClone(frame.steps)
88
+ });
89
+ return;
61
90
  }
62
- if (!history) return;
63
- const heldHistory = await readConversationHistory(transport, conversation);
64
- if ('outcome' in heldHistory) return;
65
- const newest = heldHistory.messages.slice(-HISTORY_PAGE);
66
- for (const entry of newest){
67
- const turn = messageTurn(entry);
68
- if (turn === null) return;
91
+ if (frame.type === 'working-note') {
92
+ noted.add(conversation);
69
93
  emitConversation({
70
- kind: 'accepted-message',
94
+ kind: 'working-note',
71
95
  conversation,
72
- message: {
73
- turn,
74
- message: structuredClone(entry)
96
+ note: {
97
+ noteId: frame.note_id,
98
+ text: frame.text
75
99
  }
76
100
  });
101
+ return;
77
102
  }
78
- }
79
- function receive(frame) {
80
- if (frame.type === 'draft') {
103
+ if (frame.type === 'process') {
81
104
  emitConversation({
82
- kind: 'growing-text',
83
- conversation: frame.conversation_id,
84
- turn: frame.turn_id,
85
- text: frame.text
105
+ kind: 'process',
106
+ conversation,
107
+ running: frame.running
108
+ });
109
+ if (frame.running) return;
110
+ emitConversation({
111
+ kind: 'commands',
112
+ conversation,
113
+ commands: []
114
+ });
115
+ emitConversation({
116
+ kind: 'options',
117
+ conversation,
118
+ options: []
86
119
  });
120
+ unnote(conversation);
87
121
  return;
88
122
  }
89
- if (frame.type === 'message') {
90
- const turn = messageTurn(frame.message);
91
- if (turn === null) return;
123
+ if (frame.type === 'commands') {
92
124
  emitConversation({
93
- kind: 'accepted-message',
94
- conversation: frame.conversation_id,
95
- message: {
96
- turn,
97
- message: structuredClone(frame.message)
98
- }
125
+ kind: 'commands',
126
+ conversation,
127
+ commands: structuredClone(frame.commands)
99
128
  });
100
129
  return;
101
130
  }
102
- if (frame.type === 'session') {
131
+ if (frame.type === 'options') {
103
132
  emitConversation({
104
- kind: 'session-summary',
105
- conversation: frame.conversation_id,
106
- summary: structuredClone(frame.summary)
133
+ kind: 'options',
134
+ conversation,
135
+ options: structuredClone(frame.options)
107
136
  });
108
137
  return;
109
138
  }
110
- if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {
111
- const reconnect = subscribedConversations.has(frame.authority);
112
- subscribedConversations.add(frame.authority);
113
- void catchUp(frame.authority, reconnect);
139
+ const message = acceptedMessage(frame.message);
140
+ if (message === null) return;
141
+ emitConversation({
142
+ kind: 'accepted-message',
143
+ conversation,
144
+ message
145
+ });
146
+ if (frame.message.role === 'user') return;
147
+ unnote(conversation);
148
+ }
149
+ function announce(authority, at, modelChanged) {
150
+ const version = roomVersion(at);
151
+ for (const locator of locators.get(authority) ?? []){
152
+ for (const observer of observers){
153
+ observer(modelChanged ? {
154
+ locator,
155
+ roomVersion: version,
156
+ modelChanged: true
157
+ } : {
158
+ locator,
159
+ roomVersion: version
160
+ });
161
+ }
162
+ }
163
+ }
164
+ function interrupt(authority) {
165
+ const line = lines.get(authority);
166
+ if (line !== undefined) lines.set(authority, {
167
+ logEpoch: line.logEpoch,
168
+ frames: []
169
+ });
170
+ }
171
+ function receive(frame) {
172
+ if (frame.type === 'signal') {
173
+ const mode = frame.service_mode;
174
+ if (mode !== 'open' && mode !== 'write-halted') return;
175
+ for (const observer of modeObservers)observer(mode);
114
176
  return;
115
177
  }
116
- if (frame.type !== 'entries') {
117
- held.delete(frame.authority);
178
+ if (frame.type === 'draft' || frame.type === 'working-note' || frame.type === 'process' || frame.type === 'commands' || frame.type === 'options' || frame.type === 'message') {
179
+ converse(frame);
118
180
  return;
119
181
  }
182
+ if (frame.type !== 'entries') return;
183
+ if (frame.authority === privateAuthority) {
184
+ for (const entry of frame.entries){
185
+ const card = CONVERSATION_CARD.exec(entry.path);
186
+ const conversation = card?.[1];
187
+ if (conversation !== undefined && entry.kind === 'edited' && replicated.includes(conversation)) {
188
+ void question(conversation);
189
+ }
190
+ }
191
+ }
120
192
  const at = position(frame.position);
121
193
  if (at === null) {
122
- held.delete(frame.authority);
194
+ interrupt(frame.authority);
123
195
  return;
124
196
  }
125
- const run = held.get(frame.authority) ?? [];
126
- const last = run.at(-1);
127
- const continued = last !== undefined && last.position + 1n === at;
128
- const next = continued ? [
129
- ...run,
130
- {
131
- position: at,
132
- entries: frame.entries
133
- }
134
- ] : [
135
- {
136
- position: at,
137
- entries: frame.entries
138
- }
139
- ];
140
- held.set(frame.authority, next.length > HELD_POSITIONS_MAX ? [] : next);
141
- const locator = locators.get(frame.authority);
142
- if (locator === undefined) return;
143
- for (const observer of observers)observer({
144
- locator,
145
- roomVersion: frame.position
146
- });
197
+ const line = lines.get(frame.authority);
198
+ if (line?.logEpoch === frame.log_epoch) {
199
+ const last = line.frames.at(-1);
200
+ const continued = last !== undefined && last.position + 1n === at;
201
+ const next = continued ? [
202
+ ...line.frames,
203
+ {
204
+ position: at,
205
+ entries: frame.entries
206
+ }
207
+ ] : [
208
+ {
209
+ position: at,
210
+ entries: frame.entries
211
+ }
212
+ ];
213
+ lines.set(frame.authority, {
214
+ logEpoch: line.logEpoch,
215
+ frames: next.length > HELD_POSITIONS_MAX ? [] : next
216
+ });
217
+ } else {
218
+ interrupt(frame.authority);
219
+ }
220
+ const addresses = schemas.get(frame.authority) ?? [];
221
+ announce(frame.authority, {
222
+ position: frame.position,
223
+ logEpoch: frame.log_epoch
224
+ }, frame.entries.some((entry)=>addresses.includes(entry.path)));
147
225
  }
148
226
  return {
227
+ serviceMode: {
228
+ observe (notify) {
229
+ modeObservers.add(notify);
230
+ listen();
231
+ return ()=>{
232
+ modeObservers.delete(notify);
233
+ };
234
+ }
235
+ },
236
+ question (conversation) {
237
+ void question(conversation);
238
+ },
149
239
  conversations: {
150
- view (next) {
151
- const open = new Set(next);
152
- for (const conversation of subscribedConversations){
153
- if (!open.has(conversation)) subscribedConversations.delete(conversation);
154
- }
155
- viewed = [
240
+ replicate (next) {
241
+ const entering = next.filter((conversation)=>!replicated.includes(conversation));
242
+ replicated = [
156
243
  ...next
157
244
  ];
158
- subscribe();
245
+ for (const conversation of entering)void question(conversation);
159
246
  },
160
247
  observe (notify) {
161
248
  conversationObservers.add(notify);
162
- if (!listening) {
163
- listening = true;
164
- stream.observe(receive);
249
+ listen();
250
+ if (!catching) {
251
+ catching = true;
252
+ stream.opened(reopened);
165
253
  }
166
254
  return ()=>{
167
255
  conversationObservers.delete(notify);
@@ -170,40 +258,43 @@ export function houseNotifications(transport) {
170
258
  },
171
259
  track (entries) {
172
260
  locators.clear();
173
- authorities.clear();
261
+ schemas.clear();
262
+ privateAuthority = entries.find((entry)=>entry.locator === PRIVATE_LOCATOR)?.authority;
174
263
  for (const entry of entries){
175
- locators.set(entry.authority, entry.locator);
176
- authorities.set(entry.locator, entry.authority);
264
+ locators.set(entry.authority, [
265
+ ...locators.get(entry.authority) ?? [],
266
+ entry.locator
267
+ ]);
268
+ schemas.set(entry.authority, entry.schemas);
269
+ if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {
270
+ lines.set(entry.authority, {
271
+ logEpoch: entry.logEpoch,
272
+ frames: []
273
+ });
274
+ }
177
275
  }
178
- for (const authority of held.keys()){
179
- if (!locators.has(authority)) held.delete(authority);
276
+ for (const authority of lines.keys()){
277
+ if (!locators.has(authority)) lines.delete(authority);
180
278
  }
181
279
  },
182
- select (named) {
183
- selected = [
184
- ...named
185
- ];
186
- subscribe();
187
- },
280
+ select () {},
188
281
  observe (notify) {
189
282
  observers.add(notify);
190
- if (!listening) {
191
- listening = true;
192
- stream.observe(receive);
193
- }
283
+ listen();
194
284
  return ()=>{
195
285
  observers.delete(notify);
196
286
  };
197
287
  },
198
- advance (tracked, fromRoomVersion) {
199
- const run = held.get(tracked.authority);
200
- const from = position(fromRoomVersion);
201
- if (run === undefined || from === null) return null;
202
- const at = run.findIndex((frame)=>frame.position === from + 1n);
288
+ advance (tracked, from) {
289
+ const line = lines.get(tracked.authority);
290
+ const start = position(from.position);
291
+ if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;
292
+ const at = line.frames.findIndex((frame)=>frame.position === start + 1n);
203
293
  if (at === -1) return null;
204
- const pending = run.slice(at);
294
+ const pending = line.frames.slice(at);
205
295
  const documents = {};
206
296
  const revisions = {};
297
+ const changes = {};
207
298
  const removals = [];
208
299
  for (const frame of pending){
209
300
  for (const entry of frame.entries){
@@ -211,24 +302,37 @@ export function houseNotifications(transport) {
211
302
  if (entry.kind === 'removed') {
212
303
  delete documents[entry.path];
213
304
  delete revisions[entry.path];
305
+ delete changes[entry.path];
214
306
  if (!removals.includes(entry.path)) removals.push(entry.path);
215
307
  continue;
216
308
  }
217
- if (entry.text === undefined || entry.revision === undefined) return null;
309
+ if (entry.text === undefined) return null;
310
+ if (mode === 'credential' && entry.revision === undefined) return null;
311
+ const head = headChange(entry);
312
+ if (head === null) return null;
218
313
  documents[entry.path] = entry.text;
219
- revisions[entry.path] = entry.revision;
314
+ if (entry.revision !== undefined) revisions[entry.path] = entry.revision;
315
+ if (head === undefined) delete changes[entry.path];
316
+ else changes[entry.path] = head;
220
317
  const removed = removals.indexOf(entry.path);
221
318
  if (removed !== -1) removals.splice(removed, 1);
222
319
  }
223
320
  }
224
321
  const last = pending.at(-1);
225
322
  if (last === undefined) return null;
226
- held.set(tracked.authority, pending);
323
+ lines.set(tracked.authority, {
324
+ logEpoch: line.logEpoch,
325
+ frames: pending
326
+ });
227
327
  return {
228
328
  kind: 'net-advancement',
229
- roomVersion: last.position.toString(),
329
+ roomVersion: roomVersion({
330
+ position: last.position.toString(),
331
+ logEpoch: line.logEpoch
332
+ }),
230
333
  documents,
231
334
  revisions,
335
+ changes,
232
336
  binaryTargets: [],
233
337
  removals: removals.sort()
234
338
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ViewedConversations,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome, HISTORY_PAGE, readConversationHistory } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport { PRIVATE_AUTHORITY, type HouseStreamAuthority, type HouseTransport } from './transport.js';\nimport type { HouseStreamEntry, HouseStreamFrame } from './transport.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, fromRoomVersion: string): RefreshPage | null;\n conversations: ViewedConversations;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nfunction messageTurn(message: unknown): string | null {\n if (typeof message !== 'object' || message === null) return null;\n const turn = (message as { message_id?: unknown }).message_id;\n return typeof turn === 'string' ? turn : null;\n}\n\nexport function houseNotifications(transport: HouseTransport): HouseNotifications {\n const stream = transport.stream;\n const held = new Map<string, HeldFrame[]>();\n const locators = new Map<string, string>();\n const authorities = new Map<string, string>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const subscribedConversations = new Set<string>();\n let selected: readonly string[] = [];\n let viewed: readonly string[] = [];\n let listening = false;\n\n function subscribe() {\n const named: HouseStreamAuthority[] = [];\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined || authority === PRIVATE_AUTHORITY) continue;\n named.push({ kind: 'room', room: authority });\n }\n if (authorities.has(PRIVATE_AUTHORITY)) named.push({ kind: 'private' });\n for (const conversation of viewed) {\n named.push({ kind: 'conversation', conversation });\n }\n stream.subscribe(named);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (!viewed.includes(event.conversation)) return;\n for (const observer of conversationObservers) observer(event);\n }\n\n async function catchUp(conversation: string, history: boolean) {\n const viewedAnswer = await transport.door('/door/conversations/view', {\n conversation_id: conversation,\n });\n const summary = actionOutcome(viewedAnswer, 'conversations/view');\n if (\n summary.kind === 'action' &&\n typeof summary.result === 'object' &&\n summary.result !== null\n ) {\n emitConversation({\n kind: 'session-summary',\n conversation,\n summary: structuredClone('session' in summary.result ? summary.result.session : null),\n });\n }\n if (!history) return;\n const heldHistory = await readConversationHistory(transport, conversation);\n if ('outcome' in heldHistory) return;\n const newest = heldHistory.messages.slice(-HISTORY_PAGE);\n for (const entry of newest) {\n const turn = messageTurn(entry);\n if (turn === null) return;\n emitConversation({\n kind: 'accepted-message',\n conversation,\n message: { turn, message: structuredClone(entry) },\n });\n }\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'draft') {\n emitConversation({\n kind: 'growing-text',\n conversation: frame.conversation_id,\n turn: frame.turn_id,\n text: frame.text,\n });\n return;\n }\n if (frame.type === 'message') {\n const turn = messageTurn(frame.message);\n if (turn === null) return;\n emitConversation({\n kind: 'accepted-message',\n conversation: frame.conversation_id,\n message: { turn, message: structuredClone(frame.message) },\n });\n return;\n }\n if (frame.type === 'session') {\n emitConversation({\n kind: 'session-summary',\n conversation: frame.conversation_id,\n summary: structuredClone(frame.summary),\n });\n return;\n }\n if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {\n const reconnect = subscribedConversations.has(frame.authority);\n subscribedConversations.add(frame.authority);\n void catchUp(frame.authority, reconnect);\n return;\n }\n if (frame.type !== 'entries') {\n held.delete(frame.authority);\n return;\n }\n const at = position(frame.position);\n if (at === null) {\n held.delete(frame.authority);\n return;\n }\n const run = held.get(frame.authority) ?? [];\n const last = run.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...run, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n held.set(frame.authority, next.length > HELD_POSITIONS_MAX ? [] : next);\n const locator = locators.get(frame.authority);\n if (locator === undefined) return;\n for (const observer of observers) observer({ locator, roomVersion: frame.position });\n }\n\n return {\n conversations: {\n view(next) {\n const open = new Set(next);\n for (const conversation of subscribedConversations) {\n if (!open.has(conversation)) subscribedConversations.delete(conversation);\n }\n viewed = [...next];\n subscribe();\n },\n observe(notify) {\n conversationObservers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n authorities.clear();\n for (const entry of entries) {\n locators.set(entry.authority, entry.locator);\n authorities.set(entry.locator, entry.authority);\n }\n for (const authority of held.keys()) {\n if (!locators.has(authority)) held.delete(authority);\n }\n },\n select(named) {\n selected = [...named];\n subscribe();\n },\n observe(notify) {\n observers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, fromRoomVersion) {\n const run = held.get(tracked.authority);\n const from = position(fromRoomVersion);\n if (run === undefined || from === null) return null;\n const at = run.findIndex((frame) => frame.position === from + 1n);\n if (at === -1) return null;\n const pending = run.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined || entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n revisions[entry.path] = entry.revision;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n held.set(tracked.authority, pending);\n return {\n kind: 'net-advancement',\n roomVersion: last.position.toString(),\n documents,\n revisions,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["actionOutcome","HISTORY_PAGE","readConversationHistory","selects","PRIVATE_AUTHORITY","HELD_POSITIONS_MAX","position","value","test","BigInt","messageTurn","message","turn","message_id","houseNotifications","transport","stream","held","Map","locators","authorities","observers","Set","conversationObservers","subscribedConversations","selected","viewed","listening","subscribe","named","locator","authority","get","undefined","push","kind","room","has","conversation","emitConversation","event","includes","observer","catchUp","history","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","heldHistory","newest","messages","slice","entry","receive","frame","type","turn_id","text","reconnect","add","delete","at","run","last","continued","next","entries","set","length","roomVersion","conversations","view","open","observe","notify","track","clear","keys","select","advance","tracked","fromRoomVersion","from","findIndex","pending","documents","revisions","removals","path","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AAOA,SAASA,aAAa,EAAEC,YAAY,EAAEC,uBAAuB,QAAQ,eAAe;AAEpF,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,iBAAiB,QAAwD,iBAAiB;AAGnG,MAAMC,qBAAqB;AAa3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,SAASG,YAAYC,OAAgB;IACnC,IAAI,OAAOA,YAAY,YAAYA,YAAY,MAAM,OAAO;IAC5D,MAAMC,OAAO,AAACD,QAAqCE,UAAU;IAC7D,OAAO,OAAOD,SAAS,WAAWA,OAAO;AAC3C;AAEA,OAAO,SAASE,mBAAmBC,SAAyB;IAC1D,MAAMC,SAASD,UAAUC,MAAM;IAC/B,MAAMC,OAAO,IAAIC;IACjB,MAAMC,WAAW,IAAID;IACrB,MAAME,cAAc,IAAIF;IACxB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,MAAME,0BAA0B,IAAIF;IACpC,IAAIG,WAA8B,EAAE;IACpC,IAAIC,SAA4B,EAAE;IAClC,IAAIC,YAAY;IAEhB,SAASC;QACP,MAAMC,QAAgC,EAAE;QACxC,KAAK,MAAMC,WAAWL,SAAU;YAC9B,MAAMM,YAAYX,YAAYY,GAAG,CAACF;YAClC,IAAIC,cAAcE,aAAaF,cAAc3B,mBAAmB;YAChEyB,MAAMK,IAAI,CAAC;gBAAEC,MAAM;gBAAQC,MAAML;YAAU;QAC7C;QACA,IAAIX,YAAYiB,GAAG,CAACjC,oBAAoByB,MAAMK,IAAI,CA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AC/C;YACF;YACA,MAAM3B,OAAOqB,QAAQvB,EAAE,CAAC,CAAC;YACzB,IAAIE,SAASlC,WAAW,OAAO;YAC/BhB,KAAKsD,GAAG,CAACa,QAAQrD,SAAS,EAAEyD;YAC5B,OAAO;gBACLrD,MAAM;gBACNsC,aAAaN,KAAK7D,QAAQ,CAAC2F,QAAQ;gBACnCR;gBACAC;gBACAQ,eAAe,EAAE;gBACjBP,UAAUA,SAASQ,IAAI;YACzB;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n ConversationStream,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ServiceMode,\n ServiceModeSignal,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage, actionOutcome } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { headChange, selects, type HeadChange } from './read.js';\nimport {\n PRIVATE_LOCATOR,\n type HouseDoor,\n type HouseMode,\n type HouseStreamEntry,\n type HouseStreamFrame,\n} from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\nconst CONVERSATION_CARD = /^agents\\/([^/]+)\\.md$/;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;\n conversations: ConversationStream;\n serviceMode: ServiceModeSignal;\n question(conversation: string): void;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const schemas = new Map<string, readonly string[]>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const modeObservers = new Set<(mode: ServiceMode) => void>();\n let replicated: readonly string[] = [];\n let privateAuthority: string | undefined;\n const live = new Set<string>();\n const noted = new Set<string>();\n const asked = new Map<string, number>();\n let listening = false;\n let catching = false;\n\n function listen() {\n if (listening) return;\n listening = true;\n stream.observe(receive);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (event.kind !== 'gap' && event.kind !== 'accepted-message') live.add(event.conversation);\n for (const observer of conversationObservers) observer(event);\n }\n\n function unnote(conversation: string) {\n if (!noted.delete(conversation)) return;\n emitConversation({ kind: 'working-note', conversation, note: null });\n }\n\n async function question(conversation: string) {\n const sequence = (asked.get(conversation) ?? 0) + 1;\n asked.set(conversation, sequence);\n const answer = await transport.door('/door/conversations/interaction/read', {\n conversation_id: conversation,\n });\n if (asked.get(conversation) !== sequence || !replicated.includes(conversation)) return;\n const outcome = actionOutcome(answer, 'conversations/interaction/read');\n if (outcome.kind !== 'action') return;\n const { interactions } = outcome.result as { interactions?: unknown };\n if (!Array.isArray(interactions)) return;\n emitConversation({\n kind: 'questions',\n conversation,\n questions: structuredClone(interactions),\n });\n }\n\n function reopened() {\n const gapped = new Set([...replicated, ...live]);\n live.clear();\n noted.clear();\n for (const conversation of gapped) emitConversation({ kind: 'gap', conversation });\n for (const conversation of replicated) void question(conversation);\n }\n\n function converse(frame: Exclude<HouseStreamFrame, { type: 'entries' | 'signal' }>) {\n const conversation = frame.conversation_id;\n if (frame.type === 'draft') {\n unnote(conversation);\n emitConversation({\n kind: 'growing-text',\n conversation,\n turn: frame.turn_id,\n text: frame.text,\n });\n emitConversation({\n kind: 'plan',\n conversation,\n turn: frame.turn_id,\n plan: structuredClone(frame.steps),\n });\n return;\n }\n if (frame.type === 'working-note') {\n noted.add(conversation);\n emitConversation({\n kind: 'working-note',\n conversation,\n note: { noteId: frame.note_id, text: frame.text },\n });\n return;\n }\n if (frame.type === 'process') {\n emitConversation({ kind: 'process', conversation, running: frame.running });\n if (frame.running) return;\n emitConversation({ kind: 'commands', conversation, commands: [] });\n emitConversation({ kind: 'options', conversation, options: [] });\n unnote(conversation);\n return;\n }\n if (frame.type === 'commands') {\n emitConversation({\n kind: 'commands',\n conversation,\n commands: structuredClone(frame.commands),\n });\n return;\n }\n if (frame.type === 'options') {\n emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });\n return;\n }\n const message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation, message });\n if ((frame.message as { role?: unknown }).role === 'user') return;\n unnote(conversation);\n }\n\n function announce(authority: string, at: LogPosition, modelChanged: boolean) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) {\n observer(\n modelChanged\n ? { locator, roomVersion: version, modelChanged: true }\n : { locator, roomVersion: version },\n );\n }\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'signal') {\n const mode = frame.service_mode;\n if (mode !== 'open' && mode !== 'write-halted') return;\n for (const observer of modeObservers) observer(mode);\n return;\n }\n if (\n frame.type === 'draft' ||\n frame.type === 'working-note' ||\n frame.type === 'process' ||\n frame.type === 'commands' ||\n frame.type === 'options' ||\n frame.type === 'message'\n ) {\n converse(frame);\n return;\n }\n if (frame.type !== 'entries') return;\n if (frame.authority === privateAuthority) {\n for (const entry of frame.entries) {\n const card = CONVERSATION_CARD.exec(entry.path);\n const conversation = card?.[1];\n if (\n conversation !== undefined &&\n entry.kind === 'edited' &&\n replicated.includes(conversation)\n ) {\n void question(conversation);\n }\n }\n }\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n const addresses = schemas.get(frame.authority) ?? [];\n announce(\n frame.authority,\n { position: frame.position, logEpoch: frame.log_epoch },\n frame.entries.some((entry) => addresses.includes(entry.path)),\n );\n }\n\n return {\n serviceMode: {\n observe(notify) {\n modeObservers.add(notify);\n listen();\n return () => {\n modeObservers.delete(notify);\n };\n },\n },\n question(conversation) {\n void question(conversation);\n },\n conversations: {\n replicate(next) {\n const entering = next.filter((conversation) => !replicated.includes(conversation));\n replicated = [...next];\n for (const conversation of entering) void question(conversation);\n },\n observe(notify) {\n conversationObservers.add(notify);\n listen();\n if (!catching) {\n catching = true;\n stream.opened(reopened);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n schemas.clear();\n privateAuthority = entries.find((entry) => entry.locator === PRIVATE_LOCATOR)?.authority;\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n schemas.set(entry.authority, entry.schemas);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select() {},\n observe(notify) {\n observers.add(notify);\n listen();\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n delete changes[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n const head = headChange(entry);\n if (head === null) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n if (head === undefined) delete changes[entry.path];\n else changes[entry.path] = head;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),\n documents,\n revisions,\n changes,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["acceptedMessage","actionOutcome","headChange","selects","PRIVATE_LOCATOR","roomVersion","HELD_POSITIONS_MAX","CONVERSATION_CARD","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","schemas","observers","Set","conversationObservers","modeObservers","replicated","privateAuthority","live","noted","asked","listening","catching","listen","observe","receive","emitConversation","event","kind","add","conversation","observer","unnote","delete","note","question","sequence","get","set","answer","door","conversation_id","includes","outcome","interactions","result","Array","isArray","questions","structuredClone","reopened","gapped","clear","converse","frame","type","turn","turn_id","text","plan","steps","noteId","note_id","running","commands","options","message","role","announce","authority","at","modelChanged","version","locator","interrupt","line","undefined","logEpoch","frames","service_mode","entry","entries","card","exec","path","log_epoch","last","continued","next","length","addresses","some","serviceMode","notify","conversations","replicate","entering","filter","opened","track","find","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","changes","removals","push","revision","head","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AASA,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAe;AAE9D,SAASC,UAAU,EAAEC,OA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