@agentshouse/mdruntime-adapter 0.1.0-alpha.16 → 0.1.0-alpha.17
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.
- package/AGENTS.md +9 -1
- package/dist/actions.d.ts +3 -8
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +52 -121
- package/dist/actions.js.map +1 -1
- package/dist/stream.d.ts +2 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +18 -38
- package/dist/stream.js.map +1 -1
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -9,7 +9,15 @@ enforcement.
|
|
|
9
9
|
App code reaches the MD Runtime through the remote client. The surfaces are
|
|
10
10
|
Rooms, Slots, Query, Observe, Types, Draft, Save, Queue, History, Call, Log,
|
|
11
11
|
storage loss, the reported persistence answer, deployment facts, Sync Status, reauthorization,
|
|
12
|
-
conversation, the
|
|
12
|
+
conversation, the chat draft, and Presentation State.
|
|
13
|
+
|
|
14
|
+
Each conversation a Provider card names is held complete in the browser.
|
|
15
|
+
Observe one with `observe('conversation', id, { limit }, listener)`: the view
|
|
16
|
+
holds its latest `limit` messages, or all of them, oldest first, with the
|
|
17
|
+
growing text and the session summary while it is viewed, and its chat draft.
|
|
18
|
+
`chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
|
|
19
|
+
sending it is a Provider Action that needs the Provider reachable and is never
|
|
20
|
+
queued.
|
|
13
21
|
|
|
14
22
|
Slots answers each Slot the Provider declares, in its order, with its entries
|
|
15
23
|
in order, each a Room and its segment; a Room two Slots list is the same Room.
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
import { type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
|
|
2
|
-
import type {
|
|
3
|
-
export declare const HISTORY_PAGE = 100;
|
|
1
|
+
import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
4
3
|
export declare const HOUSE_CONVERSATION_CARDS: ConversationCards;
|
|
5
4
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
6
5
|
export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
|
|
7
6
|
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
8
|
-
export declare function
|
|
9
|
-
messages: unknown[];
|
|
10
|
-
} | {
|
|
11
|
-
outcome: ActionResult;
|
|
12
|
-
}>;
|
|
7
|
+
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
13
8
|
//# sourceMappingURL=actions.d.ts.map
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAEvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiBtE,eAAO,MAAM,wBAAwB,EAAE,iBAKtC,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAMvB;AAoED,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuID,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
|
package/dist/actions.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { changeBatchIdentity } from '@agentshouse/mdruntime';
|
|
2
2
|
import { doorRefusal } from './refusal.js';
|
|
3
3
|
import { PRIVATE_LOCATOR } from './transport.js';
|
|
4
|
-
|
|
4
|
+
const HISTORY_PAGE = 100;
|
|
5
5
|
const OCTET_STREAM = 'application/octet-stream';
|
|
6
6
|
const CONVERSATION_ROUTES = new Map([
|
|
7
7
|
[
|
|
@@ -271,148 +271,79 @@ async function sendAction(transport, input) {
|
|
|
271
271
|
return outcome;
|
|
272
272
|
}
|
|
273
273
|
function historyCursor(value) {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
parsed = JSON.parse(value);
|
|
277
|
-
} catch {
|
|
278
|
-
return null;
|
|
279
|
-
}
|
|
280
|
-
const acceptedAt = text(parsed, 'accepted_at');
|
|
281
|
-
const messageId = text(parsed, 'message_id');
|
|
274
|
+
const acceptedAt = text(value, 'accepted_at');
|
|
275
|
+
const messageId = text(value, 'message_id');
|
|
282
276
|
if (acceptedAt === undefined || messageId === undefined) return null;
|
|
283
277
|
return {
|
|
284
278
|
accepted_at: acceptedAt,
|
|
285
279
|
message_id: messageId
|
|
286
280
|
};
|
|
287
281
|
}
|
|
288
|
-
function
|
|
289
|
-
const turn = text(entry, 'message_id');
|
|
290
|
-
if (turn === undefined) return null;
|
|
291
|
-
return {
|
|
292
|
-
turn,
|
|
293
|
-
message: structuredClone(entry)
|
|
294
|
-
};
|
|
295
|
-
}
|
|
296
|
-
function olderCursor(entry) {
|
|
297
|
-
const acceptedAt = text(entry.message, 'accepted_at');
|
|
298
|
-
const messageId = text(entry.message, 'message_id');
|
|
299
|
-
if (acceptedAt === undefined || messageId === undefined) return null;
|
|
282
|
+
function position(cursor) {
|
|
300
283
|
return JSON.stringify({
|
|
301
|
-
accepted_at:
|
|
302
|
-
message_id:
|
|
284
|
+
accepted_at: cursor.accepted_at,
|
|
285
|
+
message_id: cursor.message_id
|
|
303
286
|
});
|
|
304
287
|
}
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
conversation_id: conversationId,
|
|
311
|
-
...after === undefined ? {} : {
|
|
312
|
-
after
|
|
313
|
-
},
|
|
314
|
-
limit: HISTORY_PAGE
|
|
315
|
-
});
|
|
316
|
-
const outcome = actionOutcome(answer, 'conversation.history');
|
|
317
|
-
if (outcome.kind !== 'action') return {
|
|
318
|
-
outcome
|
|
319
|
-
};
|
|
320
|
-
const held = record(outcome.result);
|
|
321
|
-
if (!Array.isArray(held.messages)) return {
|
|
322
|
-
outcome: {
|
|
323
|
-
kind: 'transport-uncertainty'
|
|
324
|
-
}
|
|
325
|
-
};
|
|
326
|
-
for (const entry of held.messages){
|
|
327
|
-
if (text(entry, 'message_id') === undefined) {
|
|
328
|
-
return {
|
|
329
|
-
outcome: {
|
|
330
|
-
kind: 'transport-uncertainty'
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
}
|
|
334
|
-
messages.push(entry);
|
|
335
|
-
}
|
|
336
|
-
if (held.next === null || held.next === undefined) return {
|
|
337
|
-
messages
|
|
338
|
-
};
|
|
339
|
-
const next = record(held.next);
|
|
340
|
-
const acceptedAt = text(next, 'accepted_at');
|
|
341
|
-
const messageId = text(next, 'message_id');
|
|
342
|
-
if (acceptedAt === undefined || messageId === undefined) {
|
|
343
|
-
return {
|
|
344
|
-
outcome: {
|
|
345
|
-
kind: 'transport-uncertainty'
|
|
346
|
-
}
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
after = {
|
|
350
|
-
accepted_at: acceptedAt,
|
|
351
|
-
message_id: messageId
|
|
352
|
-
};
|
|
288
|
+
function positionCursor(value) {
|
|
289
|
+
try {
|
|
290
|
+
return historyCursor(JSON.parse(value));
|
|
291
|
+
} catch {
|
|
292
|
+
return null;
|
|
353
293
|
}
|
|
354
294
|
}
|
|
355
|
-
function
|
|
356
|
-
const
|
|
357
|
-
|
|
358
|
-
const first = page[0];
|
|
359
|
-
const cursor = from === 0 || first === undefined ? null : olderCursor(first);
|
|
360
|
-
if (from > 0 && cursor === null) return {
|
|
361
|
-
kind: 'transport-uncertainty'
|
|
362
|
-
};
|
|
295
|
+
export function acceptedMessage(entry) {
|
|
296
|
+
const cursor = historyCursor(entry);
|
|
297
|
+
if (cursor === null) return null;
|
|
363
298
|
return {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
cursor
|
|
370
|
-
}
|
|
371
|
-
}
|
|
299
|
+
identity: cursor.message_id,
|
|
300
|
+
turn: cursor.message_id,
|
|
301
|
+
position: position(cursor),
|
|
302
|
+
text: text(entry, 'text') ?? '',
|
|
303
|
+
message: structuredClone(entry)
|
|
372
304
|
};
|
|
373
305
|
}
|
|
374
306
|
async function historyAction(transport, input) {
|
|
375
307
|
const conversationId = text(input, 'conversation');
|
|
376
308
|
if (conversationId === undefined) return malformed();
|
|
377
|
-
const
|
|
378
|
-
|
|
379
|
-
if (
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
if ('outcome' in held) return held.outcome;
|
|
309
|
+
const afterValue = text(input, 'after');
|
|
310
|
+
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
311
|
+
if (after === null) return malformed();
|
|
312
|
+
const answer = await transport.door('/door/conversations/history', {
|
|
313
|
+
conversation_id: conversationId,
|
|
314
|
+
...after === undefined ? {} : {
|
|
315
|
+
after
|
|
316
|
+
},
|
|
317
|
+
limit: HISTORY_PAGE
|
|
318
|
+
});
|
|
319
|
+
const outcome = actionOutcome(answer, 'conversation.history');
|
|
320
|
+
if (outcome.kind !== 'action') return outcome;
|
|
321
|
+
const held = record(outcome.result);
|
|
322
|
+
if (!Array.isArray(held.messages)) return {
|
|
323
|
+
kind: 'transport-uncertainty'
|
|
324
|
+
};
|
|
394
325
|
const messages = [];
|
|
395
326
|
for (const entry of held.messages){
|
|
396
|
-
const
|
|
397
|
-
if (
|
|
327
|
+
const message = acceptedMessage(entry);
|
|
328
|
+
if (message === null) return {
|
|
398
329
|
kind: 'transport-uncertainty'
|
|
399
330
|
};
|
|
400
|
-
messages.push(
|
|
331
|
+
messages.push(message);
|
|
401
332
|
}
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
333
|
+
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
334
|
+
if (next === null) return {
|
|
335
|
+
kind: 'transport-uncertainty'
|
|
336
|
+
};
|
|
337
|
+
const page = {
|
|
338
|
+
messages,
|
|
339
|
+
...next === undefined ? {} : {
|
|
340
|
+
next: position(next)
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
return {
|
|
344
|
+
kind: 'action',
|
|
345
|
+
result: page
|
|
346
|
+
};
|
|
416
347
|
}
|
|
417
348
|
|
|
418
349
|
//# sourceMappingURL=actions.js.map
|
package/dist/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/actions.ts"],"sourcesContent":["import {\n changeBatchIdentity,\n type ActionDeclaration,\n type ActionRequest,\n type ActionResult,\n type ConversationCards,\n} from '@agentshouse/mdruntime';\nimport { doorRefusal } from './refusal.js';\nimport { PRIVATE_LOCATOR } from './transport.js';\nimport type { HouseDoor, HouseDoorAnswer, HouseTransport } from './transport.js';\n\nexport const HISTORY_PAGE = 100;\n\nconst OCTET_STREAM = 'application/octet-stream';\n\nconst CONVERSATION_ROUTES: ReadonlyMap<string, string> = new Map([\n ['conversation.create', '/door/conversations/create'],\n ['conversation.send', '/door/conversations/send'],\n ['conversation.answer', '/door/conversations/interaction/answer'],\n ['conversation.interrupt', '/door/conversations/interrupt'],\n ['conversation.kill', '/door/conversations/kill'],\n ['conversation.cancel', '/door/conversations/cancel'],\n ['conversation.delete', '/door/conversations/delete'],\n ['conversation.history', '/door/conversations/history'],\n]);\n\nexport const HOUSE_CONVERSATION_CARDS: ConversationCards = {\n locator: PRIVATE_LOCATOR,\n type: 'conversation',\n identity: 'conversation',\n agent: 'agent',\n};\n\nexport function declaredActions(routes: readonly string[]): readonly ActionDeclaration[] {\n const mapped = new Map(\n [...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]),\n );\n return routes.map((route) => ({\n name: mapped.get(route) ?? route,\n inputShape: {},\n resultKind: 'house',\n }));\n}\n\nexport function houseAction(\n transport: HouseTransport,\n request: ActionRequest,\n): Promise<ActionResult> {\n if (request.name === 'conversation.send') return sendAction(transport, request.input);\n if (request.name === 'conversation.history') return historyAction(transport, request.input);\n const route = routeOf(request.name);\n if (route === null) return Promise.resolve(malformed());\n return carry(transport, route, request.name, request.input);\n}\n\nfunction routeOf(name: string): string | null {\n const mapped = CONVERSATION_ROUTES.get(name);\n if (mapped !== undefined) return mapped;\n const parts = name.split('/');\n if (parts.some((part) => part === '.' || part === '..')) return null;\n try {\n return `/door/${parts.map(encodeURIComponent).join('/')}`;\n } catch {\n return null;\n }\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : {};\n}\n\nfunction text(value: unknown, name: string): string | undefined {\n const held = record(value)[name];\n return typeof held === 'string' ? held : undefined;\n}\n\nfunction operationId(input: unknown): string {\n return text(input, 'operation_id') ?? changeBatchIdentity();\n}\n\nfunction malformed(): ActionResult {\n return { kind: 'rejected', code: 'invalid_request', fields: {} };\n}\n\nfunction bodyOf(name: string, input: unknown): unknown {\n if (name === 'conversation.create') {\n return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };\n }\n if (\n name === 'conversation.interrupt' ||\n name === 'conversation.kill' ||\n name === 'conversation.delete'\n ) {\n return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };\n }\n if (name === 'conversation.cancel') {\n return {\n conversation_id: text(input, 'conversation'),\n message_id: text(input, 'turn'),\n operation_id: operationId(input),\n };\n }\n if (name === 'conversation.answer') {\n const nested = record(record(input).answer);\n return {\n conversation_id: text(input, 'conversation'),\n operation_id: operationId(input),\n interaction_id: text(nested, 'interaction_id'),\n revision: nested.revision,\n response: nested.response,\n };\n }\n return input;\n}\n\nfunction withTurn(body: unknown): unknown {\n const held = record(body);\n const turn = text(held, 'message_id');\n return turn === undefined ? body : { ...held, turn };\n}\n\nexport function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult {\n if (answer.status === 401) return { kind: 'revoked-authorization' };\n const refusal = doorRefusal(answer.body);\n if (refusal !== null) {\n return { kind: 'rejected', code: refusal.code, fields: refusal.fields };\n }\n if (answer.status === 404)\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name } };\n if (answer.status === 0 || answer.status >= 400) return { kind: 'transport-uncertainty' };\n if (name === 'conversation.send') return { kind: 'action', result: withTurn(answer.body) };\n return { kind: 'action', result: answer.body };\n}\n\nasync function carry(\n transport: HouseTransport,\n route: string,\n name: string,\n input: unknown,\n): Promise<ActionResult> {\n const answer = await transport.door(route, bodyOf(name, input));\n return actionOutcome(answer, name);\n}\n\nfunction sendFile(entry: unknown): Record<string, unknown> | null {\n const file = record(entry);\n const name = text(file, 'name');\n const bytes = file.byteLength;\n const sha256 = text(file, 'contentHash');\n if (name === undefined || typeof bytes !== 'number' || sha256 === undefined) return null;\n const mediaType = text(file, 'mediaType');\n const width = file.width;\n const height = file.height;\n return {\n name,\n media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,\n bytes,\n sha256,\n ...(typeof width === 'number' && typeof height === 'number'\n ? { dimensions: { width, height } }\n : {}),\n };\n}\n\nfunction sendFiles(input: unknown): readonly Record<string, unknown>[] | null {\n const files = record(input).files;\n if (files === undefined) return [];\n if (!Array.isArray(files)) return null;\n const declared: Record<string, unknown>[] = [];\n for (const entry of files) {\n const file = sendFile(entry);\n if (file === null) return null;\n declared.push(file);\n }\n return declared;\n}\n\nfunction sendBody(input: unknown): Record<string, unknown> | null {\n const files = sendFiles(input);\n if (files === null) return null;\n const textValue = text(input, 'text');\n return {\n conversation_id: text(input, 'conversation'),\n operation_id: operationId(input),\n ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),\n ...(files.length === 0 ? {} : { files }),\n };\n}\n\nasync function fileBytes(file: unknown): Promise<Uint8Array | null> {\n const blob = record(file).blob;\n if (blob === undefined || typeof blob !== 'object' || blob === null) return null;\n if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function') return null;\n return new Uint8Array(await (blob as Blob).arrayBuffer());\n}\n\nfunction uploadGrant(\n entry: unknown,\n): { method: 'POST'; operation: string; url: string } | 'absent' | null {\n if (!('upload' in record(entry))) return 'absent';\n const upload = record(record(entry).upload);\n if (upload.method !== 'POST') return null;\n if (typeof upload.operation !== 'string' || typeof upload.url !== 'string') return null;\n return { method: 'POST', operation: upload.operation, url: upload.url };\n}\n\nasync function uploadOriginals(\n transport: HouseTransport,\n input: unknown,\n result: unknown,\n): Promise<ActionResult | null> {\n const originals = record(result).originals;\n if (!Array.isArray(originals) || originals.length === 0) return null;\n const files = Array.isArray(record(input).files) ? (record(input).files as unknown[]) : [];\n for (const [index, entry] of originals.entries()) {\n const grant = uploadGrant(entry);\n if (grant === 'absent') continue;\n if (grant === null) return malformed();\n const bytes = index < files.length ? await fileBytes(files[index]) : null;\n if (bytes === null) {\n return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };\n }\n const delivered = await transport.transfer({\n act: 'conversation_original_upload',\n method: 'POST',\n url: grant.url,\n body: bytes,\n operation: grant.operation,\n });\n if (delivered.status === 200) continue;\n return actionOutcome(delivered, 'conversation.send');\n }\n return null;\n}\n\nasync function sendAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const body = sendBody(input);\n if (body === null) return malformed();\n const answer = await transport.door('/door/conversations/send', body);\n const outcome = actionOutcome(answer, 'conversation.send');\n if (outcome.kind !== 'action') return outcome;\n const uploaded = await uploadOriginals(transport, input, outcome.result);\n if (uploaded !== null) return uploaded;\n return outcome;\n}\n\ntype HistoryCursor = { accepted_at: string; message_id: string };\n\nfunction historyCursor(value: string): HistoryCursor | null {\n let parsed: unknown;\n try {\n parsed = JSON.parse(value) as unknown;\n } catch {\n return null;\n }\n const acceptedAt = text(parsed, 'accepted_at');\n const messageId = text(parsed, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) return null;\n return { accepted_at: acceptedAt, message_id: messageId };\n}\n\nfunction turned(entry: unknown): { turn: string; message: unknown } | null {\n const turn = text(entry, 'message_id');\n if (turn === undefined) return null;\n return { turn, message: structuredClone(entry) };\n}\n\nfunction olderCursor(entry: { message: unknown }): string | null {\n const acceptedAt = text(entry.message, 'accepted_at');\n const messageId = text(entry.message, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) return null;\n return JSON.stringify({ accepted_at: acceptedAt, message_id: messageId });\n}\n\nexport async function readConversationHistory(\n transport: HouseDoor,\n conversationId: string,\n): Promise<{ messages: unknown[] } | { outcome: ActionResult }> {\n const messages: unknown[] = [];\n let after: HistoryCursor | undefined;\n for (;;) {\n const answer = await transport.door('/door/conversations/history', {\n conversation_id: conversationId,\n ...(after === undefined ? {} : { after }),\n limit: HISTORY_PAGE,\n });\n const outcome = actionOutcome(answer, 'conversation.history');\n if (outcome.kind !== 'action') return { outcome };\n const held = record(outcome.result);\n if (!Array.isArray(held.messages)) return { outcome: { kind: 'transport-uncertainty' } };\n for (const entry of held.messages) {\n if (text(entry, 'message_id') === undefined) {\n return { outcome: { kind: 'transport-uncertainty' } };\n }\n messages.push(entry);\n }\n if (held.next === null || held.next === undefined) return { messages };\n const next = record(held.next);\n const acceptedAt = text(next, 'accepted_at');\n const messageId = text(next, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) {\n return { outcome: { kind: 'transport-uncertainty' } };\n }\n after = { accepted_at: acceptedAt, message_id: messageId };\n }\n}\n\nfunction historyPage(\n conversationId: string,\n messages: readonly { turn: string; message: unknown }[],\n until: number,\n): ActionResult {\n const from = Math.max(0, until - HISTORY_PAGE);\n const page = messages.slice(from, until);\n const first = page[0];\n const cursor = from === 0 || first === undefined ? null : olderCursor(first);\n if (from > 0 && cursor === null) return { kind: 'transport-uncertainty' };\n return {\n kind: 'action',\n result: {\n conversation_id: conversationId,\n messages: page,\n ...(cursor === null ? {} : { cursor }),\n },\n };\n}\n\nasync function historyAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const conversationId = text(input, 'conversation');\n if (conversationId === undefined) return malformed();\n const cursorValue = text(input, 'cursor');\n let olderThan: HistoryCursor | undefined;\n if (cursorValue !== undefined) {\n const parsed = historyCursor(cursorValue);\n if (parsed === null) {\n return { kind: 'rejected', code: 'unknown-cursor', fields: { cursor: cursorValue } };\n }\n olderThan = parsed;\n }\n const held = await readConversationHistory(transport, conversationId);\n if ('outcome' in held) return held.outcome;\n const messages: { turn: string; message: unknown }[] = [];\n for (const entry of held.messages) {\n const mapped = turned(entry);\n if (mapped === null) return { kind: 'transport-uncertainty' };\n messages.push(mapped);\n }\n if (olderThan === undefined) {\n return historyPage(conversationId, messages, messages.length);\n }\n const at = messages.findIndex(\n (entry) =>\n text(entry.message, 'accepted_at') === olderThan.accepted_at &&\n text(entry.message, 'message_id') === olderThan.message_id,\n );\n if (at === -1) {\n return { kind: 'rejected', code: 'unknown-cursor', fields: { cursor: cursorValue } };\n }\n return historyPage(conversationId, messages, at);\n}\n"],"names":["changeBatchIdentity","doorRefusal","PRIVATE_LOCATOR","HISTORY_PAGE","OCTET_STREAM","CONVERSATION_ROUTES","Map","HOUSE_CONVERSATION_CARDS","locator","type","identity","agent","declaredActions","routes","mapped","map","name","route","slice","length","get","inputShape","resultKind","houseAction","transport","request","sendAction","input","historyAction","routeOf","Promise","resolve","malformed","carry","undefined","parts","split","some","part","encodeURIComponent","join","record","value","text","held","operationId","kind","code","fields","bodyOf","agent_id","operation_id","conversation_id","message_id","nested","answer","interaction_id","revision","response","withTurn","body","turn","actionOutcome","status","refusal","result","door","sendFile","entry","file","bytes","byteLength","sha256","mediaType","width","height","media_type","dimensions","sendFiles","files","Array","isArray","declared","push","sendBody","textValue","fileBytes","blob","arrayBuffer","Uint8Array","uploadGrant","upload","method","operation","url","uploadOriginals","originals","index","entries","grant","delivered","transfer","act","outcome","uploaded","historyCursor","parsed","JSON","parse","acceptedAt","messageId","accepted_at","turned","message","structuredClone","olderCursor","stringify","readConversationHistory","conversationId","messages","after","limit","next","historyPage","until","from","Math","max","page","first","cursor","cursorValue","olderThan","at","findIndex"],"mappings":"AAAA,SACEA,mBAAmB,QAKd,yBAAyB;AAChC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,eAAe,QAAQ,iBAAiB;AAGjD,OAAO,MAAMC,eAAe,IAAI;AAEhC,MAAMC,eAAe;AAErB,MAAMC,sBAAmD,IAAIC,IAAI;IAC/D;QAAC;QAAuB;KAA6B;IACrD;QAAC;QAAqB;KAA2B;IACjD;QAAC;QAAuB;KAAyC;IACjE;QAAC;QAA0B;KAAgC;IAC3D;QAAC;QAAqB;KAA2B;IACjD;QAAC;QAAuB;KAA6B;IACrD;QAAC;QAAuB;KAA6B;IACrD;QAAC;QAAwB;KAA8B;CACxD;AAED,OAAO,MAAMC,2BAA8C;IACzDC,SAASN;IACTO,MAAM;IACNC,UAAU;IACVC,OAAO;AACT,EAAE;AAEF,OAAO,SAASC,gBAAgBC,MAAyB;IACvD,MAAMC,SAAS,IAAIR,IACjB;WAAID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AMmG,cAAcxF,KAAKhB,OAAO;IAChC,IAAIyG;IACJ,IAAID,gBAAgBjG,WAAW;QAC7B,MAAMwE,SAASD,cAAc0B;QAC7B,IAAIzB,WAAW,MAAM;YACnB,OAAO;gBAAE5D,MAAM;gBAAYC,MAAM;gBAAkBC,QAAQ;oBAAEkF,QAAQC;gBAAY;YAAE;QACrF;QACAC,YAAY1B;IACd;IACA,MAAM9D,OAAO,MAAMyE,wBAAwB7F,WAAW8F;IACtD,IAAI,aAAa1E,MAAM,OAAOA,KAAK2D,OAAO;IAC1C,MAAMgB,WAAiD,EAAE;IACzD,KAAK,MAAMnD,SAASxB,KAAK2E,QAAQ,CAAE;QACjC,MAAMzG,SAASkG,OAAO5C;QACtB,IAAItD,WAAW,MAAM,OAAO;YAAEgC,MAAM;QAAwB;QAC5DyE,SAASpC,IAAI,CAACrE;IAChB;IACA,IAAIsH,cAAclG,WAAW;QAC3B,OAAOyF,YAAYL,gBAAgBC,UAAUA,SAASpG,MAAM;IAC9D;IACA,MAAMkH,KAAKd,SAASe,SAAS,CAC3B,CAAClE,QACCzB,KAAKyB,MAAM6C,OAAO,EAAE,mBAAmBmB,UAAUrB,WAAW,IAC5DpE,KAAKyB,MAAM6C,OAAO,EAAE,kBAAkBmB,UAAU/E,UAAU;IAE9D,IAAIgF,OAAO,CAAC,GAAG;QACb,OAAO;YAAEvF,MAAM;YAAYC,MAAM;YAAkBC,QAAQ;gBAAEkF,QAAQC;YAAY;QAAE;IACrF;IACA,OAAOR,YAAYL,gBAAgBC,UAAUc;AAC/C"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/actions.ts"],"sourcesContent":["import {\n changeBatchIdentity,\n type AcceptedMessage,\n type ActionDeclaration,\n type ActionRequest,\n type ActionResult,\n type ConversationCards,\n type ConversationHistoryPage,\n} from '@agentshouse/mdruntime';\nimport { doorRefusal } from './refusal.js';\nimport { PRIVATE_LOCATOR } from './transport.js';\nimport type { HouseDoorAnswer, HouseTransport } from './transport.js';\n\nconst HISTORY_PAGE = 100;\n\nconst OCTET_STREAM = 'application/octet-stream';\n\nconst CONVERSATION_ROUTES: ReadonlyMap<string, string> = new Map([\n ['conversation.create', '/door/conversations/create'],\n ['conversation.send', '/door/conversations/send'],\n ['conversation.answer', '/door/conversations/interaction/answer'],\n ['conversation.interrupt', '/door/conversations/interrupt'],\n ['conversation.kill', '/door/conversations/kill'],\n ['conversation.cancel', '/door/conversations/cancel'],\n ['conversation.delete', '/door/conversations/delete'],\n ['conversation.history', '/door/conversations/history'],\n]);\n\nexport const HOUSE_CONVERSATION_CARDS: ConversationCards = {\n locator: PRIVATE_LOCATOR,\n type: 'conversation',\n identity: 'conversation',\n agent: 'agent',\n};\n\nexport function declaredActions(routes: readonly string[]): readonly ActionDeclaration[] {\n const mapped = new Map(\n [...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]),\n );\n return routes.map((route) => ({\n name: mapped.get(route) ?? route,\n inputShape: {},\n resultKind: 'house',\n }));\n}\n\nexport function houseAction(\n transport: HouseTransport,\n request: ActionRequest,\n): Promise<ActionResult> {\n if (request.name === 'conversation.send') return sendAction(transport, request.input);\n if (request.name === 'conversation.history') return historyAction(transport, request.input);\n const route = routeOf(request.name);\n if (route === null) return Promise.resolve(malformed());\n return carry(transport, route, request.name, request.input);\n}\n\nfunction routeOf(name: string): string | null {\n const mapped = CONVERSATION_ROUTES.get(name);\n if (mapped !== undefined) return mapped;\n const parts = name.split('/');\n if (parts.some((part) => part === '.' || part === '..')) return null;\n try {\n return `/door/${parts.map(encodeURIComponent).join('/')}`;\n } catch {\n return null;\n }\n}\n\nfunction record(value: unknown): Record<string, unknown> {\n return typeof value === 'object' && value !== null ? (value as Record<string, unknown>) : {};\n}\n\nfunction text(value: unknown, name: string): string | undefined {\n const held = record(value)[name];\n return typeof held === 'string' ? held : undefined;\n}\n\nfunction operationId(input: unknown): string {\n return text(input, 'operation_id') ?? changeBatchIdentity();\n}\n\nfunction malformed(): ActionResult {\n return { kind: 'rejected', code: 'invalid_request', fields: {} };\n}\n\nfunction bodyOf(name: string, input: unknown): unknown {\n if (name === 'conversation.create') {\n return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };\n }\n if (\n name === 'conversation.interrupt' ||\n name === 'conversation.kill' ||\n name === 'conversation.delete'\n ) {\n return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };\n }\n if (name === 'conversation.cancel') {\n return {\n conversation_id: text(input, 'conversation'),\n message_id: text(input, 'turn'),\n operation_id: operationId(input),\n };\n }\n if (name === 'conversation.answer') {\n const nested = record(record(input).answer);\n return {\n conversation_id: text(input, 'conversation'),\n operation_id: operationId(input),\n interaction_id: text(nested, 'interaction_id'),\n revision: nested.revision,\n response: nested.response,\n };\n }\n return input;\n}\n\nfunction withTurn(body: unknown): unknown {\n const held = record(body);\n const turn = text(held, 'message_id');\n return turn === undefined ? body : { ...held, turn };\n}\n\nexport function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult {\n if (answer.status === 401) return { kind: 'revoked-authorization' };\n const refusal = doorRefusal(answer.body);\n if (refusal !== null) {\n return { kind: 'rejected', code: refusal.code, fields: refusal.fields };\n }\n if (answer.status === 404)\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name } };\n if (answer.status === 0 || answer.status >= 400) return { kind: 'transport-uncertainty' };\n if (name === 'conversation.send') return { kind: 'action', result: withTurn(answer.body) };\n return { kind: 'action', result: answer.body };\n}\n\nasync function carry(\n transport: HouseTransport,\n route: string,\n name: string,\n input: unknown,\n): Promise<ActionResult> {\n const answer = await transport.door(route, bodyOf(name, input));\n return actionOutcome(answer, name);\n}\n\nfunction sendFile(entry: unknown): Record<string, unknown> | null {\n const file = record(entry);\n const name = text(file, 'name');\n const bytes = file.byteLength;\n const sha256 = text(file, 'contentHash');\n if (name === undefined || typeof bytes !== 'number' || sha256 === undefined) return null;\n const mediaType = text(file, 'mediaType');\n const width = file.width;\n const height = file.height;\n return {\n name,\n media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,\n bytes,\n sha256,\n ...(typeof width === 'number' && typeof height === 'number'\n ? { dimensions: { width, height } }\n : {}),\n };\n}\n\nfunction sendFiles(input: unknown): readonly Record<string, unknown>[] | null {\n const files = record(input).files;\n if (files === undefined) return [];\n if (!Array.isArray(files)) return null;\n const declared: Record<string, unknown>[] = [];\n for (const entry of files) {\n const file = sendFile(entry);\n if (file === null) return null;\n declared.push(file);\n }\n return declared;\n}\n\nfunction sendBody(input: unknown): Record<string, unknown> | null {\n const files = sendFiles(input);\n if (files === null) return null;\n const textValue = text(input, 'text');\n return {\n conversation_id: text(input, 'conversation'),\n operation_id: operationId(input),\n ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),\n ...(files.length === 0 ? {} : { files }),\n };\n}\n\nasync function fileBytes(file: unknown): Promise<Uint8Array | null> {\n const blob = record(file).blob;\n if (blob === undefined || typeof blob !== 'object' || blob === null) return null;\n if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function') return null;\n return new Uint8Array(await (blob as Blob).arrayBuffer());\n}\n\nfunction uploadGrant(\n entry: unknown,\n): { method: 'POST'; operation: string; url: string } | 'absent' | null {\n if (!('upload' in record(entry))) return 'absent';\n const upload = record(record(entry).upload);\n if (upload.method !== 'POST') return null;\n if (typeof upload.operation !== 'string' || typeof upload.url !== 'string') return null;\n return { method: 'POST', operation: upload.operation, url: upload.url };\n}\n\nasync function uploadOriginals(\n transport: HouseTransport,\n input: unknown,\n result: unknown,\n): Promise<ActionResult | null> {\n const originals = record(result).originals;\n if (!Array.isArray(originals) || originals.length === 0) return null;\n const files = Array.isArray(record(input).files) ? (record(input).files as unknown[]) : [];\n for (const [index, entry] of originals.entries()) {\n const grant = uploadGrant(entry);\n if (grant === 'absent') continue;\n if (grant === null) return malformed();\n const bytes = index < files.length ? await fileBytes(files[index]) : null;\n if (bytes === null) {\n return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };\n }\n const delivered = await transport.transfer({\n act: 'conversation_original_upload',\n method: 'POST',\n url: grant.url,\n body: bytes,\n operation: grant.operation,\n });\n if (delivered.status === 200) continue;\n return actionOutcome(delivered, 'conversation.send');\n }\n return null;\n}\n\nasync function sendAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const body = sendBody(input);\n if (body === null) return malformed();\n const answer = await transport.door('/door/conversations/send', body);\n const outcome = actionOutcome(answer, 'conversation.send');\n if (outcome.kind !== 'action') return outcome;\n const uploaded = await uploadOriginals(transport, input, outcome.result);\n if (uploaded !== null) return uploaded;\n return outcome;\n}\n\ntype HistoryCursor = { accepted_at: string; message_id: string };\n\nfunction historyCursor(value: unknown): HistoryCursor | null {\n const acceptedAt = text(value, 'accepted_at');\n const messageId = text(value, 'message_id');\n if (acceptedAt === undefined || messageId === undefined) return null;\n return { accepted_at: acceptedAt, message_id: messageId };\n}\n\nfunction position(cursor: HistoryCursor): string {\n return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });\n}\n\nfunction positionCursor(value: string): HistoryCursor | null {\n try {\n return historyCursor(JSON.parse(value) as unknown);\n } catch {\n return null;\n }\n}\n\nexport function acceptedMessage(entry: unknown): AcceptedMessage | null {\n const cursor = historyCursor(entry);\n if (cursor === null) return null;\n return {\n identity: cursor.message_id,\n turn: cursor.message_id,\n position: position(cursor),\n text: text(entry, 'text') ?? '',\n message: structuredClone(entry),\n };\n}\n\nasync function historyAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const conversationId = text(input, 'conversation');\n if (conversationId === undefined) return malformed();\n const afterValue = text(input, 'after');\n const after = afterValue === undefined ? undefined : positionCursor(afterValue);\n if (after === null) return malformed();\n const answer = await transport.door('/door/conversations/history', {\n conversation_id: conversationId,\n ...(after === undefined ? {} : { after }),\n limit: HISTORY_PAGE,\n });\n const outcome = actionOutcome(answer, 'conversation.history');\n if (outcome.kind !== 'action') return outcome;\n const held = record(outcome.result);\n if (!Array.isArray(held.messages)) return { kind: 'transport-uncertainty' };\n const messages: AcceptedMessage[] = [];\n for (const entry of held.messages) {\n const message = acceptedMessage(entry);\n if (message === null) return { kind: 'transport-uncertainty' };\n messages.push(message);\n }\n const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);\n if (next === null) return { kind: 'transport-uncertainty' };\n const page: ConversationHistoryPage = {\n messages,\n ...(next === undefined ? {} : { next: position(next) }),\n };\n return { kind: 'action', result: page };\n}\n"],"names":["changeBatchIdentity","doorRefusal","PRIVATE_LOCATOR","HISTORY_PAGE","OCTET_STREAM","CONVERSATION_ROUTES","Map","HOUSE_CONVERSATION_CARDS","locator","type","identity","agent","declaredActions","routes","mapped","map","name","route","slice","length","get","inputShape","resultKind","houseAction","transport","request","sendAction","input","historyAction","routeOf","Promise","resolve","malformed","carry","undefined","parts","split","some","part","encodeURIComponent","join","record","value","text","held","operationId","kind","code","fields","bodyOf","agent_id","operation_id","conversation_id","message_id","nested","answer","interaction_id","revision","response","withTurn","body","turn","actionOutcome","status","refusal","result","door","sendFile","entry","file","bytes","byteLength","sha256","mediaType","width","height","media_type","dimensions","sendFiles","files","Array","isArray","declared","push","sendBody","textValue","fileBytes","blob","arrayBuffer","Uint8Array","uploadGrant","upload","method","operation","url","uploadOriginals","originals","index","entries","grant","delivered","transfer","act","outcome","uploaded","historyCursor","acceptedAt","messageId","accepted_at","position","cursor","JSON","stringify","positionCursor","parse","acceptedMessage","message","structuredClone","conversationId","afterValue","after","limit","messages","next","page"],"mappings":"AAAA,SACEA,mBAAmB,QAOd,yBAAyB;AAChC,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,eAAe,QAAQ,iBAAiB;AAGjD,MAAMC,eAAe;AAErB,MAAMC,eAAe;AAErB,MAAMC,sBAAmD,IAAIC,IAAI;IAC/D;QAAC;QAAuB;KAA6B;IACrD;QAAC;QAAqB;KAA2B;IACjD;QAAC;QAAuB;KAAyC;IACjE;QAAC;QAA0B;KAAgC;IAC3D;QAAC;QAAqB;KAA2B;IACjD;QAAC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,IAAIC,UAAU,MAAM,OAAOxF;IAC3B,MAAMuB,SAAS,MAAM/B,UAAU0C,IAAI,CAAC,+BAA+B;QACjEd,iBAAiBkE;QACjB,GAAIE,UAAUtF,YAAY,CAAC,IAAI;YAAEsF;QAAM,CAAC;QACxCC,OAAOtH;IACT;IACA,MAAMoG,UAAUzC,cAAcP,QAAQ;IACtC,IAAIgD,QAAQzD,IAAI,KAAK,UAAU,OAAOyD;IACtC,MAAM3D,OAAOH,OAAO8D,QAAQtC,MAAM;IAClC,IAAI,CAACe,MAAMC,OAAO,CAACrC,KAAK8E,QAAQ,GAAG,OAAO;QAAE5E,MAAM;IAAwB;IAC1E,MAAM4E,WAA8B,EAAE;IACtC,KAAK,MAAMtD,SAASxB,KAAK8E,QAAQ,CAAE;QACjC,MAAMN,UAAUD,gBAAgB/C;QAChC,IAAIgD,YAAY,MAAM,OAAO;YAAEtE,MAAM;QAAwB;QAC7D4E,SAASvC,IAAI,CAACiC;IAChB;IACA,MAAMO,OAAO/E,KAAK+E,IAAI,KAAK,QAAQ/E,KAAK+E,IAAI,KAAKzF,YAAYA,YAAYuE,cAAc7D,KAAK+E,IAAI;IAChG,IAAIA,SAAS,MAAM,OAAO;QAAE7E,MAAM;IAAwB;IAC1D,MAAM8E,OAAgC;QACpCF;QACA,GAAIC,SAASzF,YAAY,CAAC,IAAI;YAAEyF,MAAMd,SAASc;QAAM,CAAC;IACxD;IACA,OAAO;QAAE7E,MAAM;QAAUmB,QAAQ2D;IAAK;AACxC"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { RefreshPage, SelectedRooms
|
|
1
|
+
import type { ConversationStream, RefreshPage, SelectedRooms } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseDoor } from './transport.js';
|
|
4
4
|
import type { HouseMode } from './transport.js';
|
|
@@ -6,7 +6,7 @@ import { type LogPosition } from './version.js';
|
|
|
6
6
|
export type HouseNotifications = SelectedRooms & {
|
|
7
7
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
8
8
|
advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;
|
|
9
|
-
conversations:
|
|
9
|
+
conversations: ConversationStream;
|
|
10
10
|
};
|
|
11
11
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
12
12
|
//# sourceMappingURL=stream.d.ts.map
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAsC,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc7D,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,OAAO,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAAC;IAC1E,aAAa,EAAE,kBAAkB,CAAC;CACnC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA6N5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { acceptedMessage, actionOutcome } from './actions.js';
|
|
2
2
|
import { selects } from './read.js';
|
|
3
3
|
import { roomVersion } from './version.js';
|
|
4
4
|
const HELD_POSITIONS_MAX = 256;
|
|
@@ -6,11 +6,6 @@ function position(value) {
|
|
|
6
6
|
if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
|
|
7
7
|
return BigInt(value);
|
|
8
8
|
}
|
|
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
9
|
export function houseNotifications(transport, mode) {
|
|
15
10
|
const stream = transport.stream;
|
|
16
11
|
const lines = new Map();
|
|
@@ -18,8 +13,8 @@ export function houseNotifications(transport, mode) {
|
|
|
18
13
|
const authorities = new Map();
|
|
19
14
|
const observers = new Set();
|
|
20
15
|
const conversationObservers = new Set();
|
|
21
|
-
const subscribedConversations = new Set();
|
|
22
16
|
let selected = [];
|
|
17
|
+
let replicated = [];
|
|
23
18
|
let viewed = [];
|
|
24
19
|
let listening = false;
|
|
25
20
|
function subscribe() {
|
|
@@ -43,10 +38,11 @@ export function houseNotifications(transport, mode) {
|
|
|
43
38
|
stream.subscribe(named);
|
|
44
39
|
}
|
|
45
40
|
function emitConversation(event) {
|
|
46
|
-
|
|
41
|
+
const delivered = event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;
|
|
42
|
+
if (!delivered.includes(event.conversation)) return;
|
|
47
43
|
for (const observer of conversationObservers)observer(event);
|
|
48
44
|
}
|
|
49
|
-
async function
|
|
45
|
+
async function summarize(conversation) {
|
|
50
46
|
const viewedAnswer = await transport.door('/door/conversations/view', {
|
|
51
47
|
conversation_id: conversation
|
|
52
48
|
});
|
|
@@ -58,22 +54,6 @@ export function houseNotifications(transport, mode) {
|
|
|
58
54
|
summary: structuredClone('session' in summary.result ? summary.result.session : null)
|
|
59
55
|
});
|
|
60
56
|
}
|
|
61
|
-
if (!history) return;
|
|
62
|
-
const heldHistory = await readConversationHistory(transport, conversation);
|
|
63
|
-
if ('outcome' in heldHistory) return;
|
|
64
|
-
const newest = heldHistory.messages.slice(-HISTORY_PAGE);
|
|
65
|
-
for (const entry of newest){
|
|
66
|
-
const turn = messageTurn(entry);
|
|
67
|
-
if (turn === null) return;
|
|
68
|
-
emitConversation({
|
|
69
|
-
kind: 'accepted-message',
|
|
70
|
-
conversation,
|
|
71
|
-
message: {
|
|
72
|
-
turn,
|
|
73
|
-
message: structuredClone(entry)
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
}
|
|
77
57
|
}
|
|
78
58
|
function announce(authority, at) {
|
|
79
59
|
const version = roomVersion(at);
|
|
@@ -117,15 +97,12 @@ export function houseNotifications(transport, mode) {
|
|
|
117
97
|
return;
|
|
118
98
|
}
|
|
119
99
|
if (frame.type === 'message') {
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
100
|
+
const message = acceptedMessage(frame.message);
|
|
101
|
+
if (message === null) return;
|
|
122
102
|
emitConversation({
|
|
123
103
|
kind: 'accepted-message',
|
|
124
104
|
conversation: frame.conversation_id,
|
|
125
|
-
message
|
|
126
|
-
turn,
|
|
127
|
-
message: structuredClone(frame.message)
|
|
128
|
-
}
|
|
105
|
+
message
|
|
129
106
|
});
|
|
130
107
|
return;
|
|
131
108
|
}
|
|
@@ -138,9 +115,11 @@ export function houseNotifications(transport, mode) {
|
|
|
138
115
|
return;
|
|
139
116
|
}
|
|
140
117
|
if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
118
|
+
emitConversation({
|
|
119
|
+
kind: 'gap',
|
|
120
|
+
conversation: frame.authority
|
|
121
|
+
});
|
|
122
|
+
void summarize(frame.authority);
|
|
144
123
|
return;
|
|
145
124
|
}
|
|
146
125
|
if (frame.type === 'subscribed') {
|
|
@@ -186,11 +165,12 @@ export function houseNotifications(transport, mode) {
|
|
|
186
165
|
}
|
|
187
166
|
return {
|
|
188
167
|
conversations: {
|
|
168
|
+
replicate (next) {
|
|
169
|
+
replicated = [
|
|
170
|
+
...next
|
|
171
|
+
];
|
|
172
|
+
},
|
|
189
173
|
view (next) {
|
|
190
|
-
const open = new Set(next);
|
|
191
|
-
for (const conversation of subscribedConversations){
|
|
192
|
-
if (!open.has(conversation)) subscribedConversations.delete(conversation);
|
|
193
|
-
}
|
|
194
174
|
viewed = [
|
|
195
175
|
...next
|
|
196
176
|
];
|
package/dist/stream.js.map
CHANGED
|
@@ -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 type { HouseDoor, HouseStreamAuthority } from './transport.js';\nimport type { HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\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: 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: 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 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 const rooms = new Set<string>();\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined) continue;\n rooms.add(authority);\n }\n for (const room of rooms) named.push({ kind: 'room', room });\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 announce(authority: string, at: LogPosition) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) observer({ locator, roomVersion: version });\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 resubscribed(authority: string, position?: string, logEpoch?: string) {\n if (position === undefined || logEpoch === undefined) {\n interrupt(authority);\n return;\n }\n const held = lines.get(authority)?.logEpoch;\n lines.set(authority, { logEpoch, frames: [] });\n if (held !== logEpoch) announce(authority, { position, logEpoch });\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 === 'subscribed') {\n resubscribed(frame.authority, frame.position, frame.log_epoch);\n return;\n }\n if (frame.type !== 'entries') {\n interrupt(frame.authority);\n return;\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 announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });\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, [...(locators.get(entry.authority) ?? []), entry.locator]);\n authorities.set(entry.locator, entry.authority);\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(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, 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 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) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) 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 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 binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["actionOutcome","HISTORY_PAGE","readConversationHistory","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","messageTurn","message","turn","message_id","houseNotifications","transport","mode","stream","lines","Map","locators","authorities","observers","Set","conversationObservers","subscribedConversations","selected","viewed","listening","subscribe","named","rooms","locator","authority","get","undefined","add","room","push","kind","conversation","emitConversation","event","includes","observer","catchUp","history","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","heldHistory","newest","messages","slice","entry","announce","at","version","interrupt","line","set","logEpoch","frames","resubscribed","held","receive","frame","type","turn_id","text","reconnect","has","log_epoch","last","continued","next","entries","length","conversations","view","open","delete","observe","notify","track","clear","keys","select","advance","tracked","from","start","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;AAGpC,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAkB3B,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,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IAAIC;IAClB,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,MAAMC,QAAQ,IAAIR;QAClB,KAAK,MAAMS,WAAWN,SAAU;YAC9B,MA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AQ,KAAKnE,WAAW,OAAO;oBAClE+D,SAAS,CAACxC,MAAM2C,IAAI,CAAC,GAAG3C,MAAMe,IAAI;oBAClC,IAAIf,MAAM4C,QAAQ,KAAKnE,WAAWgE,SAAS,CAACzC,MAAM2C,IAAI,CAAC,GAAG3C,MAAM4C,QAAQ;oBACxE,MAAMC,UAAUH,SAASI,OAAO,CAAC9C,MAAM2C,IAAI;oBAC3C,IAAIE,YAAY,CAAC,GAAGH,SAASK,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAM1B,OAAOoB,QAAQrC,EAAE,CAAC,CAAC;YACzB,IAAIiB,SAAS1C,WAAW,OAAO;YAC/BjB,MAAM8C,GAAG,CAAC6B,QAAQ5D,SAAS,EAAE;gBAAEgC,UAAUF,KAAKE,QAAQ;gBAAEC,QAAQ+B;YAAQ;YACxE,OAAO;gBACL1D,MAAM;gBACNnC,aAAaA,YAAY;oBAAEE,UAAUuE,KAAKvE,QAAQ,CAACoG,QAAQ;oBAAIzC,UAAUF,KAAKE,QAAQ;gBAAC;gBACvFiC;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} from '@agentshouse/mdruntime';\nimport { acceptedMessage, actionOutcome } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport type { HouseDoor, HouseStreamAuthority } from './transport.js';\nimport type { HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\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};\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 authorities = new Map<string, string>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n let selected: readonly string[] = [];\n let replicated: readonly string[] = [];\n let viewed: readonly string[] = [];\n let listening = false;\n\n function subscribe() {\n const named: HouseStreamAuthority[] = [];\n const rooms = new Set<string>();\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined) continue;\n rooms.add(authority);\n }\n for (const room of rooms) named.push({ kind: 'room', room });\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 const delivered =\n event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;\n if (!delivered.includes(event.conversation)) return;\n for (const observer of conversationObservers) observer(event);\n }\n\n async function summarize(conversation: string) {\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 }\n\n function announce(authority: string, at: LogPosition) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) observer({ locator, roomVersion: version });\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 resubscribed(authority: string, position?: string, logEpoch?: string) {\n if (position === undefined || logEpoch === undefined) {\n interrupt(authority);\n return;\n }\n const held = lines.get(authority)?.logEpoch;\n lines.set(authority, { logEpoch, frames: [] });\n if (held !== logEpoch) announce(authority, { position, logEpoch });\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 message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation: frame.conversation_id, message });\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 emitConversation({ kind: 'gap', conversation: frame.authority });\n void summarize(frame.authority);\n return;\n }\n if (frame.type === 'subscribed') {\n resubscribed(frame.authority, frame.position, frame.log_epoch);\n return;\n }\n if (frame.type !== 'entries') {\n interrupt(frame.authority);\n return;\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 announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });\n }\n\n return {\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n view(next) {\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, [...(locators.get(entry.authority) ?? []), entry.locator]);\n authorities.set(entry.locator, entry.authority);\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(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, 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 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) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) 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 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 binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["acceptedMessage","actionOutcome","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","authorities","observers","Set","conversationObservers","selected","replicated","viewed","listening","subscribe","named","rooms","locator","authority","get","undefined","add","room","push","kind","conversation","emitConversation","event","delivered","includes","observer","summarize","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","announce","at","version","interrupt","line","set","logEpoch","frames","resubscribed","held","receive","frame","type","turn","turn_id","text","message","log_epoch","last","continued","next","entries","length","conversations","replicate","view","observe","notify","delete","track","clear","entry","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","removals","path","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AAOA,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAe;AAE9D,SAASC,OAAO,QAAQ,YAAY;AAGpC,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAkB3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,OAAO,SAASG,mBAAmBC,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IAAIC;IAClB,MAAMC,WAAW,IAAID;IACrB,MAAME,cAAc,IAAIF;IACxB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,IAAIE,WAA8B,EAAE;IACpC,IAAIC,aAAgC,EAAE;IACtC,IAAIC,SAA4B,EAAE;IAClC,IAAIC,YAAY;IAEhB,SAASC;QACP,MAAMC,QAAgC,EAAE;QACxC,MAAMC,QAAQ,IAAIR;QAClB,KAAK,MAAMS,WAAWP,SAAU;YAC9B,MAAMQ,YAAYZ,YAAYa,GAAG,CAACF;YAClC,IAAIC,cAAcE,WAAW;YAC7BJ,MAAMK,GAAG,CAACH;QACZ;QACA,KAAK,MAAMI,QAAQN,MAAOD,MAAMQ,IAAI,CAAC;YAAEC,MAAM;YAAQF;QAAK;QAC1D,KAAK,MAAMG,gBAAgBb,OAAQ;YACjCG,MAAMQ,IAAI,CAAC;gBAAEC,MAAM;gBAAgBC;YAAa;QAClD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1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.17",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -34,6 +34,6 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@agentshouse/mdmodel": "0.1.0-alpha.13",
|
|
37
|
-
"@agentshouse/mdruntime": "0.1.0-alpha.
|
|
37
|
+
"@agentshouse/mdruntime": "0.1.0-alpha.22"
|
|
38
38
|
}
|
|
39
39
|
}
|