@agentshouse/mdruntime-adapter 0.1.0-alpha.44 → 0.1.0-alpha.46

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.
@@ -1 +1 @@
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;AAgBtE,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,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
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,EAGvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,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,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
package/dist/actions.js CHANGED
@@ -2,6 +2,7 @@ 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
+ const HISTORY_CONVERSATIONS = 64;
5
6
  const OCTET_STREAM = 'application/octet-stream';
6
7
  const CONVERSATION_ROUTES = new Map([
7
8
  [
@@ -348,46 +349,74 @@ export function acceptedMessage(entry) {
348
349
  message: structuredClone(entry)
349
350
  };
350
351
  }
351
- async function historyAction(transport, input) {
352
- const conversationId = text(input, 'conversation');
353
- if (conversationId === undefined) return malformed();
354
- const afterValue = text(input, 'after');
355
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
356
- if (after === null) return malformed();
357
- const answer = await transport.door('/door/conversations/history', {
358
- conversation_id: conversationId,
359
- ...after === undefined ? {} : {
360
- after
361
- },
362
- limit: HISTORY_PAGE
363
- });
364
- const outcome = actionOutcome(answer, 'conversation.history');
365
- if (outcome.kind !== 'action') return outcome;
366
- const held = record(outcome.result);
367
- if (!Array.isArray(held.messages)) return {
368
- kind: 'transport-uncertainty'
369
- };
352
+ function historyPage(entry) {
353
+ const held = record(entry);
354
+ const conversation = text(held, 'conversation_id');
355
+ if (conversation === undefined || !Array.isArray(held.messages)) return null;
370
356
  const messages = [];
371
- for (const entry of held.messages){
372
- const message = acceptedMessage(entry);
373
- if (message === null) return {
374
- kind: 'transport-uncertainty'
375
- };
357
+ for (const one of held.messages){
358
+ const message = acceptedMessage(one);
359
+ if (message === null) return null;
376
360
  messages.push(message);
377
361
  }
378
362
  const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
379
- if (next === null) return {
380
- kind: 'transport-uncertainty'
381
- };
382
- const page = {
363
+ if (next === null) return null;
364
+ return {
365
+ conversation,
383
366
  messages,
384
367
  ...next === undefined ? {} : {
385
368
  next: position(next)
386
369
  }
387
370
  };
371
+ }
372
+ function historyAsks(input) {
373
+ const asked = record(input).conversations;
374
+ if (!Array.isArray(asked) || asked.length === 0) return null;
375
+ const asks = [];
376
+ for (const entry of asked){
377
+ const conversationId = text(entry, 'conversation');
378
+ if (conversationId === undefined) return null;
379
+ const afterValue = text(entry, 'after');
380
+ const after = afterValue === undefined ? undefined : positionCursor(afterValue);
381
+ if (after === null) return null;
382
+ asks.push({
383
+ conversation_id: conversationId,
384
+ ...after === undefined ? {} : {
385
+ after
386
+ }
387
+ });
388
+ }
389
+ return asks;
390
+ }
391
+ async function historyAction(transport, input) {
392
+ const asks = historyAsks(input);
393
+ if (asks === null) return malformed();
394
+ const histories = [];
395
+ for(let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS){
396
+ const answer = await transport.door('/door/conversations/history', {
397
+ conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
398
+ limit: HISTORY_PAGE
399
+ });
400
+ const outcome = actionOutcome(answer, 'conversation.history');
401
+ if (outcome.kind !== 'action') return outcome;
402
+ const answered = record(outcome.result).histories;
403
+ if (!Array.isArray(answered)) return {
404
+ kind: 'transport-uncertainty'
405
+ };
406
+ for (const entry of answered){
407
+ const page = historyPage(entry);
408
+ if (page === null) return {
409
+ kind: 'transport-uncertainty'
410
+ };
411
+ histories.push(page);
412
+ }
413
+ }
414
+ const result = {
415
+ histories
416
+ };
388
417
  return {
389
418
  kind: 'action',
390
- result: page
419
+ result
391
420
  };
392
421
  }
393
422
 
@@ -1 +1 @@
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.delete', '/door/conversations/delete'],\n ['conversation.history', '/door/conversations/history'],\n]);\n\nexport const HOUSE_CONVERSATION_CARDS: ConversationCards = {\n locator: PRIVATE_LOCATOR,\n type: 'house-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 if (request.name === 'attachments/upload') return attachAction(transport, request.input);\n if (request.name === 'attachments/get') return openAction(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.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 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 delivered(answer: HouseDoorAnswer, name: string): ActionResult | null {\n return answer.status === 200 ? null : actionOutcome(answer, name);\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 failed = delivered(\n await transport.transfer({\n act: 'conversation_original_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: bytes,\n operation: grant.operation,\n }),\n 'conversation.send',\n );\n if (failed !== null) return failed;\n }\n return null;\n}\n\nasync function attachAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const { blob, ...descriptor } = record(input);\n const bytes = await fileBytes({ blob });\n if (bytes === null) return malformed();\n const answer = await transport.door('/door/attachments/upload', descriptor);\n const outcome = actionOutcome(answer, 'attachments/upload');\n if (outcome.kind !== 'action') return outcome;\n const grant = uploadGrant(outcome.result);\n if (grant === 'absent') return outcome;\n if (grant === null) return malformed();\n const stored = await transport.transfer({\n act: 'original_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: bytes,\n operation: grant.operation,\n });\n return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };\n}\n\nasync function openAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const answer = await transport.door('/door/attachments/get', input);\n const outcome = actionOutcome(answer, 'attachments/get');\n if (outcome.kind !== 'action') return outcome;\n const { download, ...opened } = record(outcome.result);\n if (download === undefined) return outcome;\n const grant = record(download);\n if (grant.method !== 'GET' || typeof grant.url !== 'string') return malformed();\n const read = await transport.transfer({\n act: 'original_download',\n method: 'GET',\n url: grant.url,\n answer: 'bytes',\n });\n const failed = delivered(read, 'attachments/get');\n if (failed !== null) return failed;\n if (!(read.body instanceof Blob)) return { kind: 'transport-uncertainty' };\n return { kind: 'action', result: { ...opened, blob: read.body } };\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: text(entry, 'turn_id') ?? 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","attachAction","openAction","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","nested","answer","interaction_id","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","delivered","uploadGrant","upload","method","operation","url","uploadOriginals","originals","index","entries","grant","failed","transfer","act","descriptor","outcome","stored","download","opened","read","Blob","uploaded","historyCursor","acceptedAt","messageId","accepted_at","message_id","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;QAAuB;KAA6B;IACrD;QAAC;QAAwB;KAA8B;CACxD;AAED,OAAO,MAAMC,2BAA8C;IACzDC,SAASN;IACTO,MAAM;IACNC,UAAU;IACVC,OAAO;AACT,EAAE;AAEF,OAAO,SAASC,gBA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G,KAAc;IACpE,MAAMmG,iBAAiBjF,KAAKlB,OAAO;IACnC,IAAImG,mBAAmB1F,WAAW,OAAOF;IACzC,MAAM6F,aAAalF,KAAKlB,OAAO;IAC/B,MAAMqG,QAAQD,eAAe3F,YAAYA,YAAYqF,eAAeM;IACpE,IAAIC,UAAU,MAAM,OAAO9F;IAC3B,MAAMsB,SAAS,MAAMhC,UAAU0C,IAAI,CAAC,+BAA+B;QACjEZ,iBAAiBwE;QACjB,GAAIE,UAAU5F,YAAY,CAAC,IAAI;YAAE4F;QAAM,CAAC;QACxCC,OAAO9H;IACT;IACA,MAAMsG,UAAU3C,cAAcN,QAAQ;IACtC,IAAIiD,QAAQzD,IAAI,KAAK,UAAU,OAAOyD;IACtC,MAAM3D,OAAOH,OAAO8D,QAAQxC,MAAM;IAClC,IAAI,CAACe,MAAMC,OAAO,CAACnC,KAAKoF,QAAQ,GAAG,OAAO;QAAElF,MAAM;IAAwB;IAC1E,MAAMkF,WAA8B,EAAE;IACtC,KAAK,MAAM9D,SAAStB,KAAKoF,QAAQ,CAAE;QACjC,MAAMN,UAAUD,gBAAgBvD;QAChC,IAAIwD,YAAY,MAAM,OAAO;YAAE5E,MAAM;QAAwB;QAC7DkF,SAAS/C,IAAI,CAACyC;IAChB;IACA,MAAMO,OAAOrF,KAAKqF,IAAI,KAAK,QAAQrF,KAAKqF,IAAI,KAAK/F,YAAYA,YAAY4E,cAAclE,KAAKqF,IAAI;IAChG,IAAIA,SAAS,MAAM,OAAO;QAAEnF,MAAM;IAAwB;IAC1D,MAAMoF,OAAgC;QACpCF;QACA,GAAIC,SAAS/F,YAAY,CAAC,IAAI;YAAE+F,MAAMd,SAASc;QAAM,CAAC;IACxD;IACA,OAAO;QAAEnF,MAAM;QAAUiB,QAAQmE;IAAK;AACxC"}
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 ConversationHistories,\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 HISTORY_CONVERSATIONS = 64;\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.delete', '/door/conversations/delete'],\n ['conversation.history', '/door/conversations/history'],\n]);\n\nexport const HOUSE_CONVERSATION_CARDS: ConversationCards = {\n locator: PRIVATE_LOCATOR,\n type: 'house-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 if (request.name === 'attachments/upload') return attachAction(transport, request.input);\n if (request.name === 'attachments/get') return openAction(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.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 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 delivered(answer: HouseDoorAnswer, name: string): ActionResult | null {\n return answer.status === 200 ? null : actionOutcome(answer, name);\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 failed = delivered(\n await transport.transfer({\n act: 'conversation_original_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: bytes,\n operation: grant.operation,\n }),\n 'conversation.send',\n );\n if (failed !== null) return failed;\n }\n return null;\n}\n\nasync function attachAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const { blob, ...descriptor } = record(input);\n const bytes = await fileBytes({ blob });\n if (bytes === null) return malformed();\n const answer = await transport.door('/door/attachments/upload', descriptor);\n const outcome = actionOutcome(answer, 'attachments/upload');\n if (outcome.kind !== 'action') return outcome;\n const grant = uploadGrant(outcome.result);\n if (grant === 'absent') return outcome;\n if (grant === null) return malformed();\n const stored = await transport.transfer({\n act: 'original_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: bytes,\n operation: grant.operation,\n });\n return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };\n}\n\nasync function openAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const answer = await transport.door('/door/attachments/get', input);\n const outcome = actionOutcome(answer, 'attachments/get');\n if (outcome.kind !== 'action') return outcome;\n const { download, ...opened } = record(outcome.result);\n if (download === undefined) return outcome;\n const grant = record(download);\n if (grant.method !== 'GET' || typeof grant.url !== 'string') return malformed();\n const read = await transport.transfer({\n act: 'original_download',\n method: 'GET',\n url: grant.url,\n answer: 'bytes',\n });\n const failed = delivered(read, 'attachments/get');\n if (failed !== null) return failed;\n if (!(read.body instanceof Blob)) return { kind: 'transport-uncertainty' };\n return { kind: 'action', result: { ...opened, blob: read.body } };\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: text(entry, 'turn_id') ?? cursor.message_id,\n position: position(cursor),\n text: text(entry, 'text') ?? '',\n message: structuredClone(entry),\n };\n}\n\nfunction historyPage(entry: unknown): ConversationHistoryPage | null {\n const held = record(entry);\n const conversation = text(held, 'conversation_id');\n if (conversation === undefined || !Array.isArray(held.messages)) return null;\n const messages: AcceptedMessage[] = [];\n for (const one of held.messages) {\n const message = acceptedMessage(one);\n if (message === null) return null;\n messages.push(message);\n }\n const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);\n if (next === null) return null;\n return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };\n}\n\nfunction historyAsks(input: unknown): Record<string, unknown>[] | null {\n const asked = record(input).conversations;\n if (!Array.isArray(asked) || asked.length === 0) return null;\n const asks: Record<string, unknown>[] = [];\n for (const entry of asked) {\n const conversationId = text(entry, 'conversation');\n if (conversationId === undefined) return null;\n const afterValue = text(entry, 'after');\n const after = afterValue === undefined ? undefined : positionCursor(afterValue);\n if (after === null) return null;\n asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });\n }\n return asks;\n}\n\nasync function historyAction(transport: HouseTransport, input: unknown): Promise<ActionResult> {\n const asks = historyAsks(input);\n if (asks === null) return malformed();\n const histories: ConversationHistoryPage[] = [];\n for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {\n const answer = await transport.door('/door/conversations/history', {\n conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),\n limit: HISTORY_PAGE,\n });\n const outcome = actionOutcome(answer, 'conversation.history');\n if (outcome.kind !== 'action') return outcome;\n const answered = record(outcome.result).histories;\n if (!Array.isArray(answered)) return { kind: 'transport-uncertainty' };\n for (const entry of answered) {\n const page = historyPage(entry);\n if (page === null) return { kind: 'transport-uncertainty' };\n histories.push(page);\n }\n }\n const result: ConversationHistories = { histories };\n return { kind: 'action', result };\n}\n"],"names":["changeBatchIdentity","doorRefusal","PRIVATE_LOCATOR","HISTORY_PAGE","HISTORY_CONVERSATIONS","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","attachAction","openAction","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","nested","answer","interaction_id","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","delivered","uploadGrant","upload","method","operation","url","uploadOriginals","originals","index","entries","grant","failed","transfer","act","descriptor","outcome","stored","download","opened","read","Blob","uploaded","historyCursor","acceptedAt","messageId","accepted_at","message_id","position","cursor","JSON","stringify","positionCursor","parse","acceptedMessage","message","structuredClone","historyPage","conversation","messages","one","next","historyAsks","asked","conversations","asks","conversationId","afterValue","after","histories","at","lim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}
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAsXpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA6WpF"}
package/dist/adapter.js CHANGED
@@ -370,12 +370,7 @@ export function createAgentsHouseAdapter(options) {
370
370
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
371
371
  },
372
372
  async action (_authorization, request) {
373
- const result = withAt(await houseAction(transport, request));
374
- const answered = request.input?.conversation;
375
- if (request.name === 'conversation.answer' && result.kind === 'action' && typeof answered === 'string') {
376
- notifications.question(answered);
377
- }
378
- return result;
373
+ return withAt(await houseAction(transport, request));
379
374
  },
380
375
  roomVersions: notifications,
381
376
  conversations: notifications.conversations,
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/adapter.ts"],"sourcesContent":["import type {\n ActionRequest,\n ActionResult,\n Adapter,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n HistoryRequest,\n HistoryResult,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n HOUSE_SCHEMA,\n capabilities,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport { gathered, selections } from './gather.js';\nimport { createSiteAdapter } from './site.js';\nimport {\n bootstrapFrom,\n contentPrefixes,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n schemaFrom,\n schemaPath,\n} from './read.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n DOOR_BATCH,\n DOOR_BATCH_UPLOAD,\n DOOR_BOOTSTRAP,\n DOOR_DISCOVER,\n DOOR_ENUMERATE,\n DOOR_REVISIONS,\n DOOR_SELECTION_MAX,\n PRIVATE_LOCATOR,\n type HouseSiteTransport,\n type HouseTransport,\n} from './transport.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n operationHead,\n rejectedMapping,\n revisionBody,\n uploadable,\n type OperationHead,\n} from './write.js';\nimport {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\nexport type AgentsHouseAdapterOptions =\n | {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n }\n | { site: HouseSiteTransport };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\nconst UNCERTAIN_READ = { kind: 'transport-uncertainty' } as const;\n\ntype Enumerating = {\n entry: TrackedAuthority;\n from: LogPosition;\n fromRoomVersion: string;\n minPosition?: string;\n};\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\n\ntype Upload = { url: string; operation: string; bytes: number; sha256: string };\n\ntype Keep = (upload: unknown) => Promise<void>;\n\nfunction lapsedGrant(outcome: MutationResult): boolean {\n return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';\n}\n\nfunction modelFailure(\n classified: ReturnType<typeof classifyDoor>,\n envelope: ReturnType<typeof parseEnvelope>,\n): ModelResult {\n if (classified === null) {\n return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;\n }\n return failedModel(classified);\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n if ('site' in options) return createSiteAdapter(options.site);\n const transport = options.transport;\n const notifications = houseNotifications(transport, 'credential');\n const tracked = new Map<string, TrackedAuthority>();\n const models = modelShelf();\n\n function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n schema: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n return heldModel(\n envelope === null ? null : schemaFrom(envelope, entry, schema),\n schemaPath(entry.handle, schema),\n failure,\n );\n }\n\n function modelPrefixes(entry: TrackedAuthority): readonly string[] {\n const own = schemaPath(entry.handle, entry.schema);\n return entry.locator === PRIVATE_LOCATOR ? [own, schemaPath(undefined, HOUSE_SCHEMA)] : [own];\n }\n\n async function acquireModels(\n entries: readonly TrackedAuthority[],\n ): Promise<Map<string, HeldModel>> {\n const acquired = new Map<string, HeldModel>();\n for (const part of selections(\n entries,\n (entry) => modelPrefixes(entry).length,\n DOOR_SELECTION_MAX,\n )) {\n const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => modelPrefixes(entry)),\n });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;\n const failure: ModelResult = modelFailure(classified, envelope);\n for (const entry of part) {\n acquired.set(\n modelKey(entry.locator, 'collection'),\n await held(envelope, entry, entry.schema, failure),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(envelope, privateEntry, HOUSE_SCHEMA, failure),\n );\n }\n }\n return acquired;\n }\n\n function roomOf(authority: HouseAuthority, acquired: Map<string, HeldModel>): DiscoveredRoom {\n const locator = locatorOf(authority);\n const key = modelKey(locator, 'collection');\n const collection = models.retain(key, acquired.get(key));\n if (authority.roomHandle !== null) {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = models.retain(\n modelKey(locator, 'typed-selection'),\n acquired.get(modelKey(locator, 'typed-selection')),\n );\n return discoveredRoom(\n authority,\n collection?.identity ?? null,\n providerSelection(selection?.identity ?? null),\n );\n }\n\n function authorityFor(locator: string): TrackedAuthority | undefined {\n return tracked.get(locator);\n }\n\n function withAt(result: ActionResult): ActionResult {\n if (result.kind !== 'action') return result;\n const body = result.result as Record<string, unknown> | null;\n if (typeof body !== 'object' || body === null) return result;\n const { authority, position, log_epoch: logEpoch } = body;\n if (typeof position !== 'string' || typeof logEpoch !== 'string') return result;\n const locator =\n authority === undefined\n ? PRIVATE_LOCATOR\n : [...tracked.values()].find((entry) => entry.authority === authority)?.locator;\n if (locator === undefined) return result;\n return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };\n }\n\n async function bundled(body: unknown): Promise<unknown> {\n const grant = parseGrant(body);\n if (grant === null) return body;\n if (grant.method !== 'GET') return null;\n const answer = await transport.transfer({\n act: 'local_copy_bundle',\n method: 'GET',\n url: grant.url,\n answer: 'json',\n });\n return answer.status === 200 ? answer.body : null;\n }\n\n function weight(entry: TrackedAuthority): number {\n return contentPrefixes(entry).length;\n }\n\n async function bootstrapped(entries: readonly TrackedAuthority[]): Promise<BootstrapResult[]> {\n const answers: BootstrapResult[] = [];\n for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => contentPrefixes(entry)),\n });\n const classified = part.map((entry) =>\n classifyDoor(answer.status, answer.body, entry.locator),\n );\n const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;\n part.forEach((entry, index) => {\n const failure = classified[index];\n if (failure === null || failure === undefined) {\n answers.push(envelope === null ? UNCERTAIN_READ : bootstrapFrom(envelope, entry));\n return;\n }\n answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);\n });\n }\n return answers;\n }\n\n function layered(asks: readonly Enumerating[]): readonly (readonly Enumerating[])[] {\n const depths = new Map<string, number>();\n const layers: Enumerating[][] = [];\n for (const ask of asks) {\n const depth = depths.get(ask.entry.authority) ?? 0;\n depths.set(ask.entry.authority, depth + 1);\n (layers[depth] ??= []).push(ask);\n }\n return layers;\n }\n\n async function enumerated(asks: readonly Enumerating[]): Promise<RefreshResult[]> {\n const answers = new Map<Enumerating, RefreshResult>();\n const parts = layered(asks).flatMap((layer) =>\n selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX),\n );\n for (const part of parts) {\n let open = [...part];\n while (open.length > 0) {\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),\n positions: open.map((ask) => ({\n ...presented(ask.entry.authority, ask.from),\n ...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),\n })),\n });\n const refusal = doorRefusal(answer.body);\n if (refusal?.code === 'replica_behind') {\n const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);\n const behind = named.length === 0 ? open : named;\n for (const ask of behind) answers.set(ask, { kind: 'retryable-refusal', ...refusal });\n open = open.filter((ask) => !behind.includes(ask));\n continue;\n }\n const classified = open.map((ask) =>\n classifyDoor(answer.status, answer.body, ask.entry.locator),\n );\n if (classified[0]?.kind === 'beyond-horizon') {\n const named = doorRefusal(answer.body)?.fields.authority;\n const expired = open.filter((ask) => ask.entry.authority === named);\n const answered: RefreshResult =\n expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };\n const gone = expired.length === 0 ? open : expired;\n for (const ask of gone) answers.set(ask, answered);\n open = open.filter((ask) => !gone.includes(ask));\n continue;\n }\n const enumeration =\n classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;\n open.forEach((ask, index) => {\n const failure = classified[index];\n if (failure !== null && failure !== undefined) {\n answers.set(ask, failure);\n return;\n }\n answers.set(\n ask,\n enumeration === null\n ? UNCERTAIN_READ\n : refreshFrom(enumeration, ask.entry, ask.fromRoomVersion),\n );\n });\n open = [];\n }\n }\n return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);\n }\n\n const bootstrapTogether = gathered(bootstrapped);\n\n const enumerateTogether = gathered(enumerated);\n\n async function uploaded(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n if (handed !== undefined && handed.sha256 === sha256) {\n return { body: { ...head, paths, upload: handed } };\n }\n const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });\n if (minted.status !== 200) {\n return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };\n }\n const grant = parseGrant(minted.body);\n if (grant === null || grant.method !== 'POST') return { outcome: UNCERTAIN };\n const delivered = await transport.transfer({\n act: 'authored_batch_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null || holding.method !== 'POST') return { outcome: UNCERTAIN };\n const upload: Upload = { url: holding.url, operation: holding.operation, bytes, sha256 };\n await keep(upload);\n return { body: { ...head, paths, upload } };\n }\n\n async function submit(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(head, changes, delta, bytes, entry, handed, keep)\n : { body: { ...head, changes } };\n if ('outcome' in prepared) return prepared.outcome;\n const answer = await transport.door(DOOR_BATCH, prepared.body);\n return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);\n }\n\n return {\n async authorize() {\n return options.authorize();\n },\n\n async model(_authorization: Authorization, request: ModelRequest): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(_authorization: Authorization): Promise<DiscoverResult> {\n const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseDiscovery(answer.body);\n if (document === null) return { kind: 'transport-uncertainty' };\n const entries = trackedFrom(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const acquired = await acquireModels(entries);\n models.keep(entries.map((entry) => entry.locator));\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\n capabilities(document.actions),\n );\n },\n\n async bootstrap(\n _authorization: Authorization,\n request: BootstrapRequest,\n ): Promise<BootstrapResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n return bootstrapTogether(entry);\n },\n\n async refresh(_authorization: Authorization, request: RefreshRequest): Promise<RefreshResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const from = logPosition(request.fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (\n streamed !== null &&\n (request.minPosition === undefined ||\n reachedVersion(streamed.roomVersion, request.minPosition, entry.logEpoch))\n )\n return streamed;\n const minPosition =\n request.minPosition === undefined ? null : logPosition(request.minPosition);\n return enumerateTogether({\n entry,\n from,\n fromRoomVersion: request.fromRoomVersion,\n ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),\n });\n },\n\n async mutate(\n _authorization: Authorization,\n request: MutationRequest,\n keep: Keep,\n ): Promise<MutationResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const mapped = houseChanges(request.changeBatch, entry.handle);\n if (mapped.kind === 'unmapped') return rejectedMapping(mapped);\n const head = operationHead(request.changeBatch);\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const handed = request.upload as Upload | undefined;\n const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);\n if (handed === undefined || !lapsedGrant(outcome)) return outcome;\n return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);\n },\n\n async history(_authorization: Authorization, request: HistoryRequest): Promise<HistoryResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const answer = await transport.door(\n DOOR_REVISIONS,\n revisionBody({\n path: request.path,\n handle: entry.handle,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),\n }),\n );\n return historyOutcome(answer.status, answer.body, entry.locator, {\n path: request.path,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n });\n },\n\n reached(locator: string, version: string, target: string): boolean {\n return reachedVersion(version, target, authorityFor(locator)?.logEpoch);\n },\n\n async action(_authorization: Authorization, request: ActionRequest): Promise<ActionResult> {\n const result = withAt(await houseAction(transport, request));\n const answered = (request.input as { conversation?: unknown } | null)?.conversation;\n if (\n request.name === 'conversation.answer' &&\n result.kind === 'action' &&\n typeof answered === 'string'\n ) {\n notifications.question(answered);\n }\n return result;\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["DISCOVER_PREFIXES","HOUSE_SCHEMA","capabilities","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","gathered","selections","createSiteAdapter","bootstrapFrom","contentPrefixes","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","schemaFrom","schemaPath","houseAction","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","DOOR_SELECTION_MAX","PRIVATE_LOCATOR","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","operationHead","rejectedMapping","revisionBody","uploadable","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","UNCERTAIN_READ","lapsedGrant","outcome","code","modelFailure","classified","envelope","createAgentsHouseAdapter","options","site","transport","notifications","tracked","Map","models","held","entry","schema","failure","handle","modelPrefixes","own","locator","undefined","acquireModels","entries","acquired","part","length","privateEntry","find","answer","door","prefixes","flatMap","status","body","bundled","set","roomOf","authority","key","collection","retain","get","roomHandle","identity","selection","authorityFor","withAt","result","position","log_epoch","logEpoch","values","at","grant","method","transfer","act","url","weight","bootstrapped","answers","map","forEach","index","push","layered","asks","depths","layers","ask","depth","enumerated","parts","layer","open","positions","from","minPosition","min_position","refusal","named","filter","fields","behind","includes","expired","answered","gone","enumeration","fromRoomVersion","bootstrapTogether","enumerateTogether","uploaded","head","changes","delta","bytes","handed","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","request","discover","document","clear","track","authorities","actions","bootstrap","pageToken","refresh","streamed","advance","mutate","mapped","changeBatch","history","path","revision","reached","version","target","action","input","conversation","name","question","roomVersions","conversations","serviceMode"],"mappings":"AAkBA,SACEA,iBAAiB,EACjBC,YAAY,EACZC,YAAY,EACZC,cAAc,EACdC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,WAAW,QAGN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SACEC,aAAa,EACbC,eAAe,EACfC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,UAAU,QACL,YAAY;AACnB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ,eAAe;AAC3E,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,UAAU,EACVC,iBAAiB,EACjBC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,kBAAkB,EAClBC,eAAe,QAGV,iBAAiB;AACxB,SACEC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,aAAa,EACbC,eAAe,EACfC,YAAY,EACZC,UAAU,QAEL,aAAa;AACpB,SACEC,WAAW,EACXC,SAAS,EACTC,cAAc,EACdC,WAAW,QAEN,eAAe;AAStB,MAAMC,YAA4B;IAAEC,MAAM;AAAwB;AAElE,MAAMC,iBAAiB;IAAED,MAAM;AAAwB;AAevD,SAASE,YAAYC,OAAuB;IAC1C,OAAOA,QAAQH,IAAI,KAAK,cAAcG,QAAQC,IAAI,KAAK;AACzD;AAEA,SAASC,aACPC,UAA2C,EAC3CC,QAA0C;IAE1C,IAAID,eAAe,MAAM;QACv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I,WAAW;IACxC;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/adapter.ts"],"sourcesContent":["import type {\n ActionRequest,\n ActionResult,\n Adapter,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n HistoryRequest,\n HistoryResult,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n HOUSE_SCHEMA,\n capabilities,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport { gathered, selections } from './gather.js';\nimport { createSiteAdapter } from './site.js';\nimport {\n bootstrapFrom,\n contentPrefixes,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n schemaFrom,\n schemaPath,\n} from './read.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n DOOR_BATCH,\n DOOR_BATCH_UPLOAD,\n DOOR_BOOTSTRAP,\n DOOR_DISCOVER,\n DOOR_ENUMERATE,\n DOOR_REVISIONS,\n DOOR_SELECTION_MAX,\n PRIVATE_LOCATOR,\n type HouseSiteTransport,\n type HouseTransport,\n} from './transport.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n operationHead,\n rejectedMapping,\n revisionBody,\n uploadable,\n type OperationHead,\n} from './write.js';\nimport {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\nexport type AgentsHouseAdapterOptions =\n | {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n }\n | { site: HouseSiteTransport };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\nconst UNCERTAIN_READ = { kind: 'transport-uncertainty' } as const;\n\ntype Enumerating = {\n entry: TrackedAuthority;\n from: LogPosition;\n fromRoomVersion: string;\n minPosition?: string;\n};\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\n\ntype Upload = { url: string; operation: string; bytes: number; sha256: string };\n\ntype Keep = (upload: unknown) => Promise<void>;\n\nfunction lapsedGrant(outcome: MutationResult): boolean {\n return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';\n}\n\nfunction modelFailure(\n classified: ReturnType<typeof classifyDoor>,\n envelope: ReturnType<typeof parseEnvelope>,\n): ModelResult {\n if (classified === null) {\n return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;\n }\n return failedModel(classified);\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n if ('site' in options) return createSiteAdapter(options.site);\n const transport = options.transport;\n const notifications = houseNotifications(transport, 'credential');\n const tracked = new Map<string, TrackedAuthority>();\n const models = modelShelf();\n\n function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n schema: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n return heldModel(\n envelope === null ? null : schemaFrom(envelope, entry, schema),\n schemaPath(entry.handle, schema),\n failure,\n );\n }\n\n function modelPrefixes(entry: TrackedAuthority): readonly string[] {\n const own = schemaPath(entry.handle, entry.schema);\n return entry.locator === PRIVATE_LOCATOR ? [own, schemaPath(undefined, HOUSE_SCHEMA)] : [own];\n }\n\n async function acquireModels(\n entries: readonly TrackedAuthority[],\n ): Promise<Map<string, HeldModel>> {\n const acquired = new Map<string, HeldModel>();\n for (const part of selections(\n entries,\n (entry) => modelPrefixes(entry).length,\n DOOR_SELECTION_MAX,\n )) {\n const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => modelPrefixes(entry)),\n });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;\n const failure: ModelResult = modelFailure(classified, envelope);\n for (const entry of part) {\n acquired.set(\n modelKey(entry.locator, 'collection'),\n await held(envelope, entry, entry.schema, failure),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(envelope, privateEntry, HOUSE_SCHEMA, failure),\n );\n }\n }\n return acquired;\n }\n\n function roomOf(authority: HouseAuthority, acquired: Map<string, HeldModel>): DiscoveredRoom {\n const locator = locatorOf(authority);\n const key = modelKey(locator, 'collection');\n const collection = models.retain(key, acquired.get(key));\n if (authority.roomHandle !== null) {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = models.retain(\n modelKey(locator, 'typed-selection'),\n acquired.get(modelKey(locator, 'typed-selection')),\n );\n return discoveredRoom(\n authority,\n collection?.identity ?? null,\n providerSelection(selection?.identity ?? null),\n );\n }\n\n function authorityFor(locator: string): TrackedAuthority | undefined {\n return tracked.get(locator);\n }\n\n function withAt(result: ActionResult): ActionResult {\n if (result.kind !== 'action') return result;\n const body = result.result as Record<string, unknown> | null;\n if (typeof body !== 'object' || body === null) return result;\n const { authority, position, log_epoch: logEpoch } = body;\n if (typeof position !== 'string' || typeof logEpoch !== 'string') return result;\n const locator =\n authority === undefined\n ? PRIVATE_LOCATOR\n : [...tracked.values()].find((entry) => entry.authority === authority)?.locator;\n if (locator === undefined) return result;\n return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };\n }\n\n async function bundled(body: unknown): Promise<unknown> {\n const grant = parseGrant(body);\n if (grant === null) return body;\n if (grant.method !== 'GET') return null;\n const answer = await transport.transfer({\n act: 'local_copy_bundle',\n method: 'GET',\n url: grant.url,\n answer: 'json',\n });\n return answer.status === 200 ? answer.body : null;\n }\n\n function weight(entry: TrackedAuthority): number {\n return contentPrefixes(entry).length;\n }\n\n async function bootstrapped(entries: readonly TrackedAuthority[]): Promise<BootstrapResult[]> {\n const answers: BootstrapResult[] = [];\n for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => contentPrefixes(entry)),\n });\n const classified = part.map((entry) =>\n classifyDoor(answer.status, answer.body, entry.locator),\n );\n const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;\n part.forEach((entry, index) => {\n const failure = classified[index];\n if (failure === null || failure === undefined) {\n answers.push(envelope === null ? UNCERTAIN_READ : bootstrapFrom(envelope, entry));\n return;\n }\n answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);\n });\n }\n return answers;\n }\n\n function layered(asks: readonly Enumerating[]): readonly (readonly Enumerating[])[] {\n const depths = new Map<string, number>();\n const layers: Enumerating[][] = [];\n for (const ask of asks) {\n const depth = depths.get(ask.entry.authority) ?? 0;\n depths.set(ask.entry.authority, depth + 1);\n (layers[depth] ??= []).push(ask);\n }\n return layers;\n }\n\n async function enumerated(asks: readonly Enumerating[]): Promise<RefreshResult[]> {\n const answers = new Map<Enumerating, RefreshResult>();\n const parts = layered(asks).flatMap((layer) =>\n selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX),\n );\n for (const part of parts) {\n let open = [...part];\n while (open.length > 0) {\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),\n positions: open.map((ask) => ({\n ...presented(ask.entry.authority, ask.from),\n ...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),\n })),\n });\n const refusal = doorRefusal(answer.body);\n if (refusal?.code === 'replica_behind') {\n const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);\n const behind = named.length === 0 ? open : named;\n for (const ask of behind) answers.set(ask, { kind: 'retryable-refusal', ...refusal });\n open = open.filter((ask) => !behind.includes(ask));\n continue;\n }\n const classified = open.map((ask) =>\n classifyDoor(answer.status, answer.body, ask.entry.locator),\n );\n if (classified[0]?.kind === 'beyond-horizon') {\n const named = doorRefusal(answer.body)?.fields.authority;\n const expired = open.filter((ask) => ask.entry.authority === named);\n const answered: RefreshResult =\n expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };\n const gone = expired.length === 0 ? open : expired;\n for (const ask of gone) answers.set(ask, answered);\n open = open.filter((ask) => !gone.includes(ask));\n continue;\n }\n const enumeration =\n classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;\n open.forEach((ask, index) => {\n const failure = classified[index];\n if (failure !== null && failure !== undefined) {\n answers.set(ask, failure);\n return;\n }\n answers.set(\n ask,\n enumeration === null\n ? UNCERTAIN_READ\n : refreshFrom(enumeration, ask.entry, ask.fromRoomVersion),\n );\n });\n open = [];\n }\n }\n return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);\n }\n\n const bootstrapTogether = gathered(bootstrapped);\n\n const enumerateTogether = gathered(enumerated);\n\n async function uploaded(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n if (handed !== undefined && handed.sha256 === sha256) {\n return { body: { ...head, paths, upload: handed } };\n }\n const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });\n if (minted.status !== 200) {\n return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };\n }\n const grant = parseGrant(minted.body);\n if (grant === null || grant.method !== 'POST') return { outcome: UNCERTAIN };\n const delivered = await transport.transfer({\n act: 'authored_batch_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null || holding.method !== 'POST') return { outcome: UNCERTAIN };\n const upload: Upload = { url: holding.url, operation: holding.operation, bytes, sha256 };\n await keep(upload);\n return { body: { ...head, paths, upload } };\n }\n\n async function submit(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(head, changes, delta, bytes, entry, handed, keep)\n : { body: { ...head, changes } };\n if ('outcome' in prepared) return prepared.outcome;\n const answer = await transport.door(DOOR_BATCH, prepared.body);\n return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);\n }\n\n return {\n async authorize() {\n return options.authorize();\n },\n\n async model(_authorization: Authorization, request: ModelRequest): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(_authorization: Authorization): Promise<DiscoverResult> {\n const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseDiscovery(answer.body);\n if (document === null) return { kind: 'transport-uncertainty' };\n const entries = trackedFrom(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const acquired = await acquireModels(entries);\n models.keep(entries.map((entry) => entry.locator));\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\n capabilities(document.actions),\n );\n },\n\n async bootstrap(\n _authorization: Authorization,\n request: BootstrapRequest,\n ): Promise<BootstrapResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n return bootstrapTogether(entry);\n },\n\n async refresh(_authorization: Authorization, request: RefreshRequest): Promise<RefreshResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const from = logPosition(request.fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (\n streamed !== null &&\n (request.minPosition === undefined ||\n reachedVersion(streamed.roomVersion, request.minPosition, entry.logEpoch))\n )\n return streamed;\n const minPosition =\n request.minPosition === undefined ? null : logPosition(request.minPosition);\n return enumerateTogether({\n entry,\n from,\n fromRoomVersion: request.fromRoomVersion,\n ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),\n });\n },\n\n async mutate(\n _authorization: Authorization,\n request: MutationRequest,\n keep: Keep,\n ): Promise<MutationResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const mapped = houseChanges(request.changeBatch, entry.handle);\n if (mapped.kind === 'unmapped') return rejectedMapping(mapped);\n const head = operationHead(request.changeBatch);\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const handed = request.upload as Upload | undefined;\n const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);\n if (handed === undefined || !lapsedGrant(outcome)) return outcome;\n return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);\n },\n\n async history(_authorization: Authorization, request: HistoryRequest): Promise<HistoryResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const answer = await transport.door(\n DOOR_REVISIONS,\n revisionBody({\n path: request.path,\n handle: entry.handle,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),\n }),\n );\n return historyOutcome(answer.status, answer.body, entry.locator, {\n path: request.path,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n });\n },\n\n reached(locator: string, version: string, target: string): boolean {\n return reachedVersion(version, target, authorityFor(locator)?.logEpoch);\n },\n\n async action(_authorization: Authorization, request: ActionRequest): Promise<ActionResult> {\n return withAt(await houseAction(transport, request));\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["DISCOVER_PREFIXES","HOUSE_SCHEMA","capabilities","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","gathered","selections","createSiteAdapter","bootstrapFrom","contentPrefixes","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","schemaFrom","schemaPath","houseAction","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","DOOR_SELECTION_MAX","PRIVATE_LOCATOR","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","operationHead","rejectedMapping","revisionBody","uploadable","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","UNCERTAIN_READ","lapsedGrant","outcome","code","modelFailure","classified","envelope","createAgentsHouseAdapter","options","site","transport","notifications","tracked","Map","models","held","entry","schema","failure","handle","modelPrefixes","own","locator","undefined","acquireModels","entries","acquired","part","length","privateEntry","find","answer","door","prefixes","flatMap","status","body","bundled","set","roomOf","authority","key","collection","retain","get","roomHandle","identity","selection","authorityFor","withAt","result","position","log_epoch","logEpoch","values","at","grant","method","transfer","act","url","weight","bootstrapped","answers","map","forEach","index","push","layered","asks","depths","layers","ask","depth","enumerated","parts","layer","open","positions","from","minPosition","min_position","refusal","named","filter","fields","behind","includes","expired","answered","gone","enumeration","fromRoomVersion","bootstrapTogether","enumerateTogether","uploaded","head","changes","delta","bytes","handed","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","request","discover","document","clear","track","authorities","actions","bootstrap","pageToken","refresh","streamed","advance","mutate","mapped","changeBatch","history","path","revision","reached","version","target","action","roomVersions","conversations","serviceMode"],"mappings":"AAkBA,SACEA,iBAAiB,EACjBC,YAAY,EACZC,YAAY,EAC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house',
15
16
  'settings/apps',
16
17
  'settings/panel.md'
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/discovery.ts"],"sourcesContent":["import type {\n Capability,\n DiscoveredRoom,\n Discovery,\n ProviderLimit,\n Retention,\n TypedSelection,\n} from '@agentshouse/mdruntime';\nimport { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';\nimport { PRIVATE_LOCATOR } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport const ROOM_CONTRACT_VERSION = 1;\n\nexport const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';\n\nexport const ROOM_VERSION_NOTIFICATIONS = 'room-version-notifications';\n\nexport const PROVIDER_ACTIONS = 'provider-actions';\n\nexport const MOVE_REFERENCE_REWRITES = 'move-reference-rewrites';\n\nexport const DISCOVER_PREFIXES: readonly string[] = ['/'];\n\nexport const PROVIDER_SELECTION_ROOTS: readonly string[] = [\n 'agents',\n 'house',\n 'settings/apps',\n 'settings/panel.md',\n];\n\nexport const UNTYPED_FOLDERS: readonly string[] = ['capture'];\n\nexport const RESERVED_NAMES: readonly string[] = [\n 'ROOM.md',\n 'capture',\n 'settings',\n 'collaboration',\n 'rooms',\n 'agents',\n 'house',\n 'work',\n 'entities',\n 'schema',\n 'commitments',\n];\n\nexport const HOUSE_SCHEMA = 'house/schema.yaml';\n\nexport type HouseBounds = {\n max_authored_file_bytes: number;\n max_batch_operations: number;\n max_batch_documents: number;\n max_path_length: number;\n max_path_depth: number;\n max_mount_files: number;\n max_mount_bytes: number;\n change_retention_seconds: number;\n operation_retention_seconds: number;\n};\n\nexport type HouseOperations = {\n read: readonly string[];\n sync: readonly string[];\n write: readonly string[];\n delete: readonly string[];\n};\n\nexport type HouseAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string | null;\n name: string;\n schema: string;\n managedReplication: 'admitted' | 'unavailable';\n protectedPaths: readonly string[];\n operations: HouseOperations;\n};\n\nexport type HouseDiscoveryDocument = {\n bounds: HouseBounds;\n mdModelVersion: string;\n authorities: readonly HouseAuthority[];\n actions: readonly string[];\n};\n\nexport type TrackedAuthority = LogPosition & {\n locator: string;\n authority: string;\n handle: string | undefined;\n schema: string;\n schemas: readonly string[];\n};\n\nexport type HouseSiteEntry = {\n roomRef: string;\n segment: string;\n};\n\nexport type HouseSiteSlot = {\n slot: string;\n entries: readonly HouseSiteEntry[];\n};\n\nexport type HouseSiteAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string;\n schema: string;\n};\n\nexport type HouseSiteDiscovery = {\n bounds: HouseBounds;\n mdModelVersion: string;\n slots: readonly HouseSiteSlot[];\n authorities: readonly HouseSiteAuthority[];\n};\n\nexport type SiteTracked = TrackedAuthority & { handle: string };\n\nconst BOUND_KEYS: readonly (keyof HouseBounds)[] = [\n 'max_authored_file_bytes',\n 'max_batch_operations',\n 'max_batch_documents',\n 'max_path_length',\n 'max_path_depth',\n 'max_mount_files',\n 'max_mount_bytes',\n 'change_retention_seconds',\n 'operation_retention_seconds',\n];\n\nconst OPERATION_KEYS: readonly (keyof HouseOperations)[] = ['read', 'sync', 'write', 'delete'];\n\nfunction stringList(value: unknown): readonly string[] | null {\n if (!Array.isArray(value)) return null;\n return value.every((entry) => typeof entry === 'string') ? (value as string[]) : null;\n}\n\nfunction parseBounds(value: unknown): HouseBounds | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const bounds: Partial<HouseBounds> = {};\n for (const key of BOUND_KEYS) {\n const amount = held[key];\n if (typeof amount !== 'number' || !Number.isFinite(amount)) return null;\n bounds[key] = amount;\n }\n return bounds as HouseBounds;\n}\n\nfunction parseOperations(value: unknown): HouseOperations | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const operations: Partial<Record<keyof HouseOperations, readonly string[]>> = {};\n for (const key of OPERATION_KEYS) {\n const scopes = stringList(held[key]);\n if (scopes === null) return null;\n operations[key] = scopes;\n }\n return operations as HouseOperations;\n}\n\nfunction parseAuthority(value: unknown): HouseAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.name !== 'string' || held.name.length === 0) return null;\n if (typeof held.model_root !== 'string') return null;\n if (held.managed_replication !== 'admitted' && held.managed_replication !== 'unavailable') {\n return null;\n }\n const at = readPosition(held);\n const protectedPaths = stringList(held.protected_paths);\n const operations = parseOperations(held.operations);\n if (at === null || protectedPaths === null || operations === null) return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (\n held.room_handle !== null &&\n (typeof held.room_handle !== 'string' || held.room_handle.length === 0)\n )\n return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n name: held.name,\n schema: held.model_root,\n managedReplication: held.managed_replication,\n protectedPaths,\n operations,\n ...at,\n };\n}\n\nexport function parseDiscovery(body: unknown): HouseDiscoveryDocument | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n const actions = stringList(held.actions);\n if (\n actions === null ||\n new Set(actions).size !== actions.length ||\n actions.some((name) => name.length === 0)\n )\n return null;\n if (!Array.isArray(held.authorities)) return null;\n const authorities: HouseAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, authorities, actions };\n}\n\nfunction parseSiteEntry(value: unknown): HouseSiteEntry | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.segment !== 'string' || held.segment.length === 0) return null;\n return { roomRef: held.room_ref, segment: held.segment };\n}\n\nfunction parseSiteSlot(value: unknown): HouseSiteSlot | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.slot !== 'string' || held.slot.length === 0) return null;\n if (!Array.isArray(held.entries)) return null;\n const entries: HouseSiteEntry[] = [];\n for (const entry of held.entries) {\n const parsed = parseSiteEntry(entry);\n if (parsed === null) return null;\n entries.push(parsed);\n }\n return { slot: held.slot, entries };\n}\n\nfunction parseSiteAuthority(value: unknown): HouseSiteAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;\n if (typeof held.model_root !== 'string') return null;\n const at = readPosition(held);\n if (at === null) return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n schema: held.model_root,\n ...at,\n };\n}\n\nexport function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n if (!Array.isArray(held.slots) || !Array.isArray(held.authorities)) return null;\n const slots: HouseSiteSlot[] = [];\n for (const entry of held.slots) {\n const slot = parseSiteSlot(entry);\n if (slot === null) return null;\n slots.push(slot);\n }\n const authorities: HouseSiteAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseSiteAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, slots, authorities };\n}\n\nexport function siteTracked(document: HouseSiteDiscovery): SiteTracked[] {\n return document.authorities.map((authority) => ({\n locator: authority.roomRef,\n authority: authority.roomRef,\n handle: authority.roomHandle,\n schema: authority.schema,\n schemas: [authority.schema],\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function siteSlots(document: HouseSiteDiscovery): Discovery['slots'] {\n return document.slots.map(({ slot, entries }) => ({\n slot,\n entries: entries.map(({ roomRef, segment }) => ({ locator: roomRef, segment })),\n }));\n}\n\nexport function locatorOf(authority: HouseAuthority): string {\n return authority.roomHandle === null ? PRIVATE_LOCATOR : authority.roomRef;\n}\n\nfunction schemasOf(authority: HouseAuthority): readonly string[] {\n return authority.roomHandle === null ? [authority.schema, HOUSE_SCHEMA] : [authority.schema];\n}\n\nexport function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[] {\n return document.authorities.map((authority) => ({\n locator: locatorOf(authority),\n authority: authority.roomRef,\n handle: authority.roomHandle ?? undefined,\n schema: authority.schema,\n schemas: schemasOf(authority),\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function providerLimits(bounds: HouseBounds): readonly ProviderLimit[] {\n return [\n { name: 'document-size', value: bounds.max_authored_file_bytes },\n { name: 'change-batch-operations', value: bounds.max_batch_operations },\n { name: 'change-documents', value: bounds.max_batch_documents },\n { name: 'path-length', value: bounds.max_path_length },\n { name: 'path-depth', value: bounds.max_path_depth },\n { name: 'write-rate' },\n { name: 'content-ceiling' },\n ];\n}\n\nexport function declaredRetention(bounds: HouseBounds): Retention {\n return {\n history: { kind: 'no-declared-time-bound' },\n outcome: bounds.operation_retention_seconds,\n refreshHorizon: bounds.change_retention_seconds,\n };\n}\n\nexport function capabilities(actions: readonly string[]): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n {\n name: PROVIDER_ACTIONS,\n actions: declaredActions(actions),\n conversationCards: HOUSE_CONVERSATION_CARDS,\n },\n { name: MOVE_REFERENCE_REWRITES },\n ];\n}\n\nexport function siteCapabilities(): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },\n ];\n}\n\nexport function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection {\n return { roots: [...PROVIDER_SELECTION_ROOTS], attachedModel };\n}\n\nexport function discoveredRoom(\n authority: HouseAuthority,\n attachedModel: DiscoveredRoom['attachedModel'],\n typedSelection: TypedSelection | undefined,\n): DiscoveredRoom {\n return {\n name: authority.name,\n locator: locatorOf(authority),\n roomVersion: roomVersion(authority),\n operations: {\n read: [...authority.operations.read],\n sync: [...authority.operations.sync],\n write: [...authority.operations.write],\n delete: [...authority.operations.delete],\n },\n replica: { selection: locatorOf(authority), admission: authority.managedReplication },\n attachedModel,\n ...(typedSelection === undefined ? {} : { typedSelection }),\n untypedFolders: [...UNTYPED_FOLDERS],\n providerOwnedPaths: [...authority.protectedPaths, ...schemasOf(authority)],\n };\n}\n\nexport function mapDiscovery(\n document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>,\n rooms: readonly DiscoveredRoom[],\n declared: readonly Capability[],\n): Discovery {\n return {\n kind: 'discovery',\n supportedVersions: [ROOM_CONTRACT_VERSION],\n mdModel: { identity: MD_MODEL_IDENTITY, version: document.mdModelVersion },\n rooms,\n capabilities: declared,\n providerLimits: providerLimits(document.bounds),\n retention: declaredRetention(document.bounds),\n };\n}\n"],"names":["declaredActions","HOUSE_CONVERSATION_CARDS","PRIVATE_LOCATOR","readPosition","roomVersion","ROOM_CONTRACT_VERSION","MD_MODEL_IDENTITY","ROOM_VERSION_NOTIFICATIONS","PROVIDER_ACTIONS","MOVE_REFERENCE_REWRITES","DISCOVER_PREFIXES","PROVIDER_SELECTION_ROOTS","UNTYPED_FOLDERS","RESERVED_NAMES","HOUSE_SCHEMA","BOUND_KEYS","OPERATION_KEYS","stringList","value","Array","isArray","every","entry","parseBounds","held","bounds","key","amount","Number","isFinite","parseOperations","operations","scopes","parseAuthority","kind","name","length","model_root","managed_replication","at","protectedPaths","protected_paths","room_ref","room_handle","roomRef","roomHandle","schema","managedReplication","parseDiscovery","body","md_model_version","actions","Set","size","some","authorities","authority","push","mdModelVersion","parseSiteEntry","segment","parseSiteSlot","slot","entries","parsed","parseSiteAuthority","parseSiteDiscovery","slots","siteTracked","document","map","locator","handle","schemas","position","logEpoch","siteSlots","locatorOf","schemasOf","trackedFrom","undefined","providerLimits","max_authored_file_bytes","max_batch_operations","max_batch_documents","max_path_length","max_path_depth","declaredRetention","history","outcome","operation_retention_seconds","refreshHorizon","change_retention_seconds","capabilities","conversationCards","siteCapabilities","inputShape","resultKind","providerSelection","attachedModel","roots","discoveredRoom","typedSelection","read","sync","write","delete","replica","selection","admission","untypedFolders","providerOwnedPaths","mapDiscovery","rooms","declared","supportedVersions","mdModel","identity","version","retention"],"mappings":"AAQA,SAASA,eAAe,EAAEC,wBAAwB,QAAQ,eAAe;AACzE,SAASC,eAAe,QAAQ,iBAAiB;AACjD,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAE3E,OAAO,MAAMC,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,oBAAoB,uBAAuB;AAExD,OAAO,MAAMC,6BAA6B,6BAA6B;AAEvE,OAAO,MAAMC,mBAAmB,mBAAmB;AAEnD,OAAO,MAAMC,0BAA0B,0BAA0B;AAEjE,OAAO,MAAMC,oBAAuC;IAAC;CAAI,CAAC;AAE1D,OAAO,MAAMC,2BAA8C;IACzD;IACA;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,kBAAqC;IAAC;CAAU,CAAC;AAE9D,OAAO,MAAMC,iBAAoC;IAC/C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,eAAe,oBAAoB;AAuEhD,MAAMC,aAA6C;IACjD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,iBAAqD;IAAC;IAAQ;IAAQ;IAAS;CAAS;AAE9F,SAASC,WAAWC,KAAc;IAChC,IAAI,CAACC,MAAMC,OAAO,CAACF,QAAQ,OAAO;IAClC,OAAOA,MAAMG,KAAK,CAAC,CAACC,QAAU,OAAOA,UAAU,YAAaJ,QAAqB;AACnF;AAEA,SAASK,YAAYL,KAAc;IACjC,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM,O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B,cAAc;eAAKsC,UAAUtB;SAAW;IAC5E;AACF;AAEA,OAAO,SAASwD,aACd3C,QAAmE,EACnE4C,KAAgC,EAChCC,QAA+B;IAE/B,OAAO;QACLhF,MAAM;QACNiF,mBAAmB;YAAC9G;SAAsB;QAC1C+G,SAAS;YAAEC,UAAU/G;YAAmBgH,SAASjD,SAASX,cAAc;QAAC;QACzEuD;QACApB,cAAcqB;QACdjC,gBAAgBA,eAAeZ,SAAS5C,MAAM;QAC9C8F,WAAWhC,kBAAkBlB,SAAS5C,MAAM;IAC9C;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/discovery.ts"],"sourcesContent":["import type {\n Capability,\n DiscoveredRoom,\n Discovery,\n ProviderLimit,\n Retention,\n TypedSelection,\n} from '@agentshouse/mdruntime';\nimport { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';\nimport { PRIVATE_LOCATOR } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport const ROOM_CONTRACT_VERSION = 1;\n\nexport const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';\n\nexport const ROOM_VERSION_NOTIFICATIONS = 'room-version-notifications';\n\nexport const PROVIDER_ACTIONS = 'provider-actions';\n\nexport const MOVE_REFERENCE_REWRITES = 'move-reference-rewrites';\n\nexport const DISCOVER_PREFIXES: readonly string[] = ['/'];\n\nexport const PROVIDER_SELECTION_ROOTS: readonly string[] = [\n 'agents',\n 'collaboration/routines',\n 'house',\n 'settings/apps',\n 'settings/panel.md',\n];\n\nexport const UNTYPED_FOLDERS: readonly string[] = ['capture'];\n\nexport const RESERVED_NAMES: readonly string[] = [\n 'ROOM.md',\n 'capture',\n 'settings',\n 'collaboration',\n 'rooms',\n 'agents',\n 'house',\n 'work',\n 'entities',\n 'schema',\n 'commitments',\n];\n\nexport const HOUSE_SCHEMA = 'house/schema.yaml';\n\nexport type HouseBounds = {\n max_authored_file_bytes: number;\n max_batch_operations: number;\n max_batch_documents: number;\n max_path_length: number;\n max_path_depth: number;\n max_mount_files: number;\n max_mount_bytes: number;\n change_retention_seconds: number;\n operation_retention_seconds: number;\n};\n\nexport type HouseOperations = {\n read: readonly string[];\n sync: readonly string[];\n write: readonly string[];\n delete: readonly string[];\n};\n\nexport type HouseAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string | null;\n name: string;\n schema: string;\n managedReplication: 'admitted' | 'unavailable';\n protectedPaths: readonly string[];\n operations: HouseOperations;\n};\n\nexport type HouseDiscoveryDocument = {\n bounds: HouseBounds;\n mdModelVersion: string;\n authorities: readonly HouseAuthority[];\n actions: readonly string[];\n};\n\nexport type TrackedAuthority = LogPosition & {\n locator: string;\n authority: string;\n handle: string | undefined;\n schema: string;\n schemas: readonly string[];\n};\n\nexport type HouseSiteEntry = {\n roomRef: string;\n segment: string;\n};\n\nexport type HouseSiteSlot = {\n slot: string;\n entries: readonly HouseSiteEntry[];\n};\n\nexport type HouseSiteAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string;\n schema: string;\n};\n\nexport type HouseSiteDiscovery = {\n bounds: HouseBounds;\n mdModelVersion: string;\n slots: readonly HouseSiteSlot[];\n authorities: readonly HouseSiteAuthority[];\n};\n\nexport type SiteTracked = TrackedAuthority & { handle: string };\n\nconst BOUND_KEYS: readonly (keyof HouseBounds)[] = [\n 'max_authored_file_bytes',\n 'max_batch_operations',\n 'max_batch_documents',\n 'max_path_length',\n 'max_path_depth',\n 'max_mount_files',\n 'max_mount_bytes',\n 'change_retention_seconds',\n 'operation_retention_seconds',\n];\n\nconst OPERATION_KEYS: readonly (keyof HouseOperations)[] = ['read', 'sync', 'write', 'delete'];\n\nfunction stringList(value: unknown): readonly string[] | null {\n if (!Array.isArray(value)) return null;\n return value.every((entry) => typeof entry === 'string') ? (value as string[]) : null;\n}\n\nfunction parseBounds(value: unknown): HouseBounds | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const bounds: Partial<HouseBounds> = {};\n for (const key of BOUND_KEYS) {\n const amount = held[key];\n if (typeof amount !== 'number' || !Number.isFinite(amount)) return null;\n bounds[key] = amount;\n }\n return bounds as HouseBounds;\n}\n\nfunction parseOperations(value: unknown): HouseOperations | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const operations: Partial<Record<keyof HouseOperations, readonly string[]>> = {};\n for (const key of OPERATION_KEYS) {\n const scopes = stringList(held[key]);\n if (scopes === null) return null;\n operations[key] = scopes;\n }\n return operations as HouseOperations;\n}\n\nfunction parseAuthority(value: unknown): HouseAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.name !== 'string' || held.name.length === 0) return null;\n if (typeof held.model_root !== 'string') return null;\n if (held.managed_replication !== 'admitted' && held.managed_replication !== 'unavailable') {\n return null;\n }\n const at = readPosition(held);\n const protectedPaths = stringList(held.protected_paths);\n const operations = parseOperations(held.operations);\n if (at === null || protectedPaths === null || operations === null) return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (\n held.room_handle !== null &&\n (typeof held.room_handle !== 'string' || held.room_handle.length === 0)\n )\n return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n name: held.name,\n schema: held.model_root,\n managedReplication: held.managed_replication,\n protectedPaths,\n operations,\n ...at,\n };\n}\n\nexport function parseDiscovery(body: unknown): HouseDiscoveryDocument | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n const actions = stringList(held.actions);\n if (\n actions === null ||\n new Set(actions).size !== actions.length ||\n actions.some((name) => name.length === 0)\n )\n return null;\n if (!Array.isArray(held.authorities)) return null;\n const authorities: HouseAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, authorities, actions };\n}\n\nfunction parseSiteEntry(value: unknown): HouseSiteEntry | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.segment !== 'string' || held.segment.length === 0) return null;\n return { roomRef: held.room_ref, segment: held.segment };\n}\n\nfunction parseSiteSlot(value: unknown): HouseSiteSlot | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.slot !== 'string' || held.slot.length === 0) return null;\n if (!Array.isArray(held.entries)) return null;\n const entries: HouseSiteEntry[] = [];\n for (const entry of held.entries) {\n const parsed = parseSiteEntry(entry);\n if (parsed === null) return null;\n entries.push(parsed);\n }\n return { slot: held.slot, entries };\n}\n\nfunction parseSiteAuthority(value: unknown): HouseSiteAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;\n if (typeof held.model_root !== 'string') return null;\n const at = readPosition(held);\n if (at === null) return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n schema: held.model_root,\n ...at,\n };\n}\n\nexport function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n if (!Array.isArray(held.slots) || !Array.isArray(held.authorities)) return null;\n const slots: HouseSiteSlot[] = [];\n for (const entry of held.slots) {\n const slot = parseSiteSlot(entry);\n if (slot === null) return null;\n slots.push(slot);\n }\n const authorities: HouseSiteAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseSiteAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, slots, authorities };\n}\n\nexport function siteTracked(document: HouseSiteDiscovery): SiteTracked[] {\n return document.authorities.map((authority) => ({\n locator: authority.roomRef,\n authority: authority.roomRef,\n handle: authority.roomHandle,\n schema: authority.schema,\n schemas: [authority.schema],\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function siteSlots(document: HouseSiteDiscovery): Discovery['slots'] {\n return document.slots.map(({ slot, entries }) => ({\n slot,\n entries: entries.map(({ roomRef, segment }) => ({ locator: roomRef, segment })),\n }));\n}\n\nexport function locatorOf(authority: HouseAuthority): string {\n return authority.roomHandle === null ? PRIVATE_LOCATOR : authority.roomRef;\n}\n\nfunction schemasOf(authority: HouseAuthority): readonly string[] {\n return authority.roomHandle === null ? [authority.schema, HOUSE_SCHEMA] : [authority.schema];\n}\n\nexport function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[] {\n return document.authorities.map((authority) => ({\n locator: locatorOf(authority),\n authority: authority.roomRef,\n handle: authority.roomHandle ?? undefined,\n schema: authority.schema,\n schemas: schemasOf(authority),\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function providerLimits(bounds: HouseBounds): readonly ProviderLimit[] {\n return [\n { name: 'document-size', value: bounds.max_authored_file_bytes },\n { name: 'change-batch-operations', value: bounds.max_batch_operations },\n { name: 'change-documents', value: bounds.max_batch_documents },\n { name: 'path-length', value: bounds.max_path_length },\n { name: 'path-depth', value: bounds.max_path_depth },\n { name: 'write-rate' },\n { name: 'content-ceiling' },\n ];\n}\n\nexport function declaredRetention(bounds: HouseBounds): Retention {\n return {\n history: { kind: 'no-declared-time-bound' },\n outcome: bounds.operation_retention_seconds,\n refreshHorizon: bounds.change_retention_seconds,\n };\n}\n\nexport function capabilities(actions: readonly string[]): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n {\n name: PROVIDER_ACTIONS,\n actions: declaredActions(actions),\n conversationCards: HOUSE_CONVERSATION_CARDS,\n },\n { name: MOVE_REFERENCE_REWRITES },\n ];\n}\n\nexport function siteCapabilities(): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },\n ];\n}\n\nexport function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection {\n return { roots: [...PROVIDER_SELECTION_ROOTS], attachedModel };\n}\n\nexport function discoveredRoom(\n authority: HouseAuthority,\n attachedModel: DiscoveredRoom['attachedModel'],\n typedSelection: TypedSelection | undefined,\n): DiscoveredRoom {\n return {\n name: authority.name,\n locator: locatorOf(authority),\n roomVersion: roomVersion(authority),\n operations: {\n read: [...authority.operations.read],\n sync: [...authority.operations.sync],\n write: [...authority.operations.write],\n delete: [...authority.operations.delete],\n },\n replica: { selection: locatorOf(authority), admission: authority.managedReplication },\n attachedModel,\n ...(typedSelection === undefined ? {} : { typedSelection }),\n untypedFolders: [...UNTYPED_FOLDERS],\n providerOwnedPaths: [...authority.protectedPaths, ...schemasOf(authority)],\n };\n}\n\nexport function mapDiscovery(\n document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>,\n rooms: readonly DiscoveredRoom[],\n declared: readonly Capability[],\n): Discovery {\n return {\n kind: 'discovery',\n supportedVersions: [ROOM_CONTRACT_VERSION],\n mdModel: { identity: MD_MODEL_IDENTITY, version: document.mdModelVersion },\n rooms,\n capabilities: declared,\n providerLimits: providerLimits(document.bounds),\n retention: declaredRetention(document.bounds),\n };\n}\n"],"names":["declaredActions","HOUSE_CONVERSATION_CARDS","PRIVATE_LOCATOR","readPosition","roomVersion","ROOM_CONTRACT_VERSION","MD_MODEL_IDENTITY","ROOM_VERSION_NOTIFICATIONS","PROVIDER_ACTIONS","MOVE_REFERENCE_REWRITES","DISCOVER_PREFIXES","PROVIDER_SELECTION_ROOTS","UNTYPED_FOLDERS","RESERVED_NAMES","HOUSE_SCHEMA","BOUND_KEYS","OPERATION_KEYS","stringList","value","Array","isArray","every","entry","parseBounds","held","bounds","key","amount","Number","isFinite","parseOperations","operations","scopes","parseAuthority","kind","name","length","model_root","managed_replication","at","protectedPaths","protected_paths","room_ref","room_handle","roomRef","roomHandle","schema","managedReplication","parseDiscovery","body","md_model_version","actions","Set","size","some","authorities","authority","push","mdModelVersion","parseSiteEntry","segment","parseSiteSlot","slot","entries","parsed","parseSiteAuthority","parseSiteDiscovery","slots","siteTracked","document","map","locator","handle","schemas","position","logEpoch","siteSlots","locatorOf","schemasOf","trackedFrom","undefined","providerLimits","max_authored_file_bytes","max_batch_operations","max_batch_documents","max_path_length","max_path_depth","declaredRetention","history","outcome","operation_retention_seconds","refreshHorizon","change_retention_seconds","capabilities","conversationCards","siteCapabilities","inputShape","resultKind","providerSelection","attachedModel","roots","discoveredRoom","typedSelection","read","sync","write","delete","replica","selection","admission","untypedFolders","providerOwnedPaths","mapDiscovery","rooms","declared","supportedVersions","mdModel","identity","version","retention"],"mappings":"AAQA,SAASA,eAAe,EAAEC,wBAAwB,QAAQ,eAAe;AACzE,SAASC,eAAe,QAAQ,iBAAiB;AACjD,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAE3E,OAAO,MAAMC,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,oBAAoB,uBAAuB;AAExD,OAAO,MAAMC,6BAA6B,6BAA6B;AAEvE,OAAO,MAAMC,mBAAmB,mBAAmB;AAEnD,OAAO,MAAMC,0BAA0B,0BAA0B;AAEjE,OAAO,MAAMC,oBAAuC;IAAC;CAAI,CAAC;AAE1D,OAAO,MAAMC,2BAA8C;IACzD;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,kBAAqC;IAAC;CAAU,CAAC;AAE9D,OAAO,MAAMC,iBAAoC;IAC/C;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD,CAAC;AAEF,OAAO,MAAMC,eAAe,oBAAoB;AAuEhD,MAAMC,aAA6C;IACjD;IACA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mBAAIjD,UAAUzB,UAAU,CAAC0E,KAAK;aAAC;YACtCC,QAAQ;mBAAIlD,UAAUzB,UAAU,CAAC2E,MAAM;aAAC;QAC1C;QACAC,SAAS;YAAEC,WAAW/B,UAAUrB;YAAYqD,WAAWrD,UAAUT,kBAAkB;QAAC;QACpFoD;QACA,GAAIG,mBAAmBtB,YAAY,CAAC,IAAI;YAAEsB;QAAe,CAAC;QAC1DQ,gBAAgB;eAAIlG;SAAgB;QACpCmG,oBAAoB;eAAIvD,UAAUhB,cAAc;eAAKsC,UAAUtB;SAAW;IAC5E;AACF;AAEA,OAAO,SAASwD,aACd3C,QAAmE,EACnE4C,KAAgC,EAChCC,QAA+B;IAE/B,OAAO;QACLhF,MAAM;QACNiF,mBAAmB;YAAC9G;SAAsB;QAC1C+G,SAAS;YAAEC,UAAU/G;YAAmBgH,SAASjD,SAASX,cAAc;QAAC;QACzEuD;QACApB,cAAcqB;QACdjC,gBAAgBA,eAAeZ,SAAS5C,MAAM;QAC9C8F,WAAWhC,kBAAkBlB,SAAS5C,MAAM;IAC9C;AACF"}
package/dist/read.js CHANGED
@@ -248,13 +248,16 @@ export function advancedScope(scope, view) {
248
248
  export function matchesScope(scope, tracked) {
249
249
  return scope.anchor === tracked.authority;
250
250
  }
251
- const ROOM_README = 'ROOM.md';
251
+ const ROOM_HOMES = [
252
+ 'ROOM.md',
253
+ 'collaboration'
254
+ ];
252
255
  function homes(tracked) {
253
256
  return tracked.handle === undefined ? [
254
257
  ...UNTYPED_FOLDERS,
255
258
  ...PROVIDER_SELECTION_ROOTS
256
259
  ] : [
257
- ROOM_README,
260
+ ...ROOM_HOMES,
258
261
  ...UNTYPED_FOLDERS
259
262
  ];
260
263
  }
package/dist/read.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/read.ts"],"sourcesContent":["import type {\n BootstrapPage,\n BootstrapResult,\n ChangeAuthor,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n UNTYPED_FOLDERS,\n PROVIDER_SELECTION_ROOTS,\n RESERVED_NAMES,\n type TrackedAuthority,\n} from './discovery.js';\nimport type { HouseMode } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport type HeadChange = BootstrapPage['changes'][string];\n\nexport type HouseManifestFile = {\n path: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\n};\n\nexport type HouseContent = {\n path: string;\n content: string;\n};\n\nexport type HouseScope = LogPosition & {\n anchor: string;\n files: readonly HouseManifestFile[];\n contents: readonly HouseContent[];\n};\n\nexport type HouseEnvelope = {\n scopes: readonly HouseScope[];\n};\n\nexport type HouseGrant =\n | { method: 'GET'; url: string }\n | { method: 'POST'; operation: string; url: string };\n\nexport type HouseChange =\n | { path: string; removed: true }\n | {\n path: string;\n content: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\n }\n | { path: string; reference: { revision: string } };\n\nexport type HouseEnumeration = {\n authorities: readonly (LogPosition & {\n authority: string;\n changes: readonly HouseChange[];\n })[];\n};\n\nexport function authorityRoot(handle: string | undefined): string {\n return handle === undefined ? '/private' : `/rooms/${handle}`;\n}\n\nexport function contentPrefixes(tracked: TrackedAuthority): readonly string[] {\n return [authorityRoot(tracked.handle)];\n}\n\nexport function schemaPath(handle: string | undefined, schema: string): string {\n return `${authorityRoot(handle)}/${schema}`;\n}\n\nexport function parseGrant(body: unknown): HouseGrant | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {\n return null;\n }\n const transfer = body.transfer as Record<string, unknown>;\n if (typeof transfer.url !== 'string') return null;\n if (transfer.method === 'GET') return { method: 'GET', url: transfer.url };\n if (transfer.method !== 'POST' || typeof transfer.operation !== 'string') return null;\n return { method: 'POST', operation: transfer.operation, url: transfer.url };\n}\n\nfunction changeAuthor(value: unknown): ChangeAuthor | null {\n if (typeof value !== 'object' || value === null) return null;\n const { user, site, name } = value as Record<string, unknown>;\n if (typeof name !== 'string') return null;\n if (typeof user === 'string' && site === undefined) return { kind: 'user', id: user, name };\n if (typeof site === 'string' && user === undefined) return { kind: 'site', id: site, name };\n return null;\n}\n\nexport function headChange(held: {\n readonly author?: unknown;\n readonly created_at?: unknown;\n}): HeadChange | undefined | null {\n const author = held.author === undefined ? null : changeAuthor(held.author);\n if (held.author !== undefined && author === null) return null;\n if (held.created_at === undefined) return undefined;\n if (typeof held.created_at !== 'string') return null;\n return { author, time: held.created_at };\n}\n\nfunction headed(head: HeadChange | undefined) {\n return head === undefined ? {} : { head };\n}\n\nfunction parseFile(value: unknown, mode: HouseMode): HouseManifestFile | null {\n if (typeof value !== 'object' || value === null) return null;\n const file = value as Record<string, unknown>;\n if (typeof file.path !== 'string') return null;\n const head = headChange(file);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof file.sha256 !== 'string') return null;\n return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };\n }\n if (typeof file.revision !== 'string') return null;\n return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };\n}\n\nfunction parseScope(value: unknown, mode: HouseMode): HouseScope | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.manifest !== 'object' || held.manifest === null) return null;\n if (!Array.isArray(held.contents)) return null;\n const manifest = held.manifest as Record<string, unknown>;\n if (manifest.scope !== 'room') return null;\n const at = readPosition(manifest);\n if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)\n return null;\n if (\n manifest.room_handle !== null &&\n (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)\n )\n return null;\n if (!Array.isArray(manifest.files)) return null;\n const files: HouseManifestFile[] = [];\n for (const entry of manifest.files) {\n const file = parseFile(entry, mode);\n if (file === null) return null;\n files.push(file);\n }\n const contents: HouseContent[] = [];\n for (const entry of held.contents) {\n if (typeof entry !== 'object' || entry === null) return null;\n const content = entry as Record<string, unknown>;\n if (typeof content.path !== 'string' || typeof content.content !== 'string') return null;\n contents.push({ path: content.path, content: content.content });\n }\n return {\n anchor: manifest.anchor,\n ...at,\n files,\n contents,\n };\n}\n\nexport function parseEnvelope(body: unknown): HouseEnvelope | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('scopes' in body) || !Array.isArray(body.scopes)) return null;\n const scopes: HouseScope[] = [];\n for (const entry of body.scopes) {\n const scope = parseScope(entry, 'credential');\n if (scope === null) return null;\n scopes.push(scope);\n }\n return { scopes };\n}\n\nexport function parseSiteBootstrap(body: unknown): HouseScope | null {\n return parseScope(body, 'site');\n}\n\nfunction parseChange(value: unknown, mode: HouseMode): HouseChange | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.path !== 'string') return null;\n if (held.removed === true) return { path: held.path, removed: true };\n const head = headChange(held);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;\n return {\n path: held.path,\n content: held.content,\n revision: undefined,\n version: held.sha256,\n ...headed(head),\n };\n }\n if (typeof held.content === 'string' && typeof held.revision === 'string') {\n return {\n path: held.path,\n content: held.content,\n revision: held.revision,\n version: held.revision,\n ...headed(head),\n };\n }\n if (typeof held.reference === 'object' && held.reference !== null) {\n const reference = held.reference as Record<string, unknown>;\n if (typeof reference.revision !== 'string') return null;\n return { path: held.path, reference: { revision: reference.revision } };\n }\n return null;\n}\n\nexport function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('authorities' in body) || !Array.isArray(body.authorities)) return null;\n const authorities: HouseEnumeration['authorities'][number][] = [];\n for (const entry of body.authorities) {\n if (typeof entry !== 'object' || entry === null) return null;\n const held = entry as Record<string, unknown>;\n const at = readPosition(held);\n if (typeof held.authority !== 'string' || at === null) return null;\n if (!Array.isArray(held.changes)) return null;\n const changes: HouseChange[] = [];\n for (const change of held.changes) {\n const mapped = parseChange(change, mode);\n if (mapped === null) return null;\n changes.push(mapped);\n }\n authorities.push({ authority: held.authority, ...at, changes });\n }\n return { authorities };\n}\n\nexport function advancedScope(\n scope: HouseScope,\n view: HouseEnumeration['authorities'][number],\n): HouseScope {\n const files = new Map(scope.files.map((file) => [file.path, file]));\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n for (const change of view.changes) {\n files.delete(change.path);\n contents.delete(change.path);\n if ('removed' in change) continue;\n if ('content' in change) {\n files.set(change.path, {\n path: change.path,\n revision: change.revision,\n version: change.version,\n ...headed(change.head),\n });\n contents.set(change.path, change.content);\n continue;\n }\n const { revision } = change.reference;\n files.set(change.path, { path: change.path, revision, version: revision });\n }\n return {\n ...scope,\n position: view.position,\n logEpoch: view.logEpoch,\n files: [...files.values()],\n contents: [...contents].map(([path, content]) => ({ path, content })),\n };\n}\n\nexport function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean {\n return scope.anchor === tracked.authority;\n}\n\nconst ROOM_README = 'ROOM.md';\n\nfunction homes(tracked: TrackedAuthority): readonly string[] {\n return tracked.handle === undefined\n ? [...UNTYPED_FOLDERS, ...PROVIDER_SELECTION_ROOTS]\n : [ROOM_README, ...UNTYPED_FOLDERS];\n}\n\nexport function selects(tracked: TrackedAuthority, path: string): boolean {\n if (tracked.schemas.includes(path)) return false;\n const first = path.split('/', 1)[0].toLowerCase();\n return (\n !RESERVED_NAMES.some((name) => name.toLowerCase() === first) ||\n homes(tracked).some((home) => path === home || path.startsWith(`${home}/`))\n );\n}\n\nexport function bootstrapFrom(envelope: HouseEnvelope, tracked: TrackedAuthority): BootstrapResult {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n return bootstrapOf(scope, tracked);\n}\n\nexport function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage {\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const binaryTargets: string[] = [];\n for (const file of scope.files) {\n if (!selects(tracked, file.path)) continue;\n if (file.revision !== undefined) revisions[file.path] = file.revision;\n if (file.head !== undefined) changes[file.path] = file.head;\n const content = contents.get(file.path);\n if (content === undefined) binaryTargets.push(file.path);\n else documents[file.path] = content;\n }\n return {\n kind: 'bootstrap',\n roomVersion: roomVersion(scope),\n documents,\n revisions,\n changes,\n binaryTargets: binaryTargets.sort(),\n };\n}\n\nexport type HouseSchema = {\n schema: string | null;\n version: string | null;\n};\n\nexport function schemaFrom(\n envelope: HouseEnvelope,\n tracked: TrackedAuthority,\n schema: string,\n): HouseSchema | null {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return null;\n return schemaOf(scope, schema);\n}\n\nexport function schemaOf(scope: HouseScope, schema: string): HouseSchema | null {\n const file = scope.files.find((entry) => entry.path === schema);\n if (file === undefined) return { schema: null, version: null };\n const content = scope.contents.find((entry) => entry.path === schema);\n return content === undefined ? null : { schema: content.content, version: file.version };\n}\n\nexport function refreshFrom(\n enumeration: HouseEnumeration,\n tracked: TrackedAuthority,\n fromRoomVersion: string,\n): RefreshResult {\n const view = enumeration.authorities.find((entry) => entry.authority === tracked.authority);\n if (view === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n if (roomVersion(view) === fromRoomVersion) return { kind: 'still-current' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const binaryTargets: string[] = [];\n const removals: string[] = [];\n for (const change of view.changes) {\n if (!selects(tracked, change.path)) continue;\n if ('removed' in change) {\n removals.push(change.path);\n continue;\n }\n if ('content' in change) {\n documents[change.path] = change.content;\n if (change.revision !== undefined) revisions[change.path] = change.revision;\n if (change.head !== undefined) changes[change.path] = change.head;\n continue;\n }\n binaryTargets.push(change.path);\n revisions[change.path] = change.reference.revision;\n }\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion(view),\n documents,\n revisions,\n changes,\n binaryTargets: binaryTargets.sort(),\n removals: removals.sort(),\n };\n}\n"],"names":["UNTYPED_FOLDERS","PROVIDER_SELECTION_ROOTS","RESERVED_NAMES","readPosition","roomVersion","authorityRoot","handle","undefined","contentPrefixes","tracked","schemaPath","schema","parseGrant","body","transfer","url","method","operation","changeAuthor","value","user","site","name","kind","id","headChange","held","author","created_at","time","headed","head","parseFile","mode","file","path","sha256","revision","version","parseScope","manifest","Array","isArray","contents","scope","at","anchor","length","room_handle","files","entry","push","content","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","reference","parseEnumeration","authorities","authority","changes","change","mapped","advancedScope","view","Map","map","delete","set","position","logEpoch","values","matchesScope","ROOM_README","homes","selects","schemas","includes","first","split","toLowerCase","some","home","startsWith","bootstrapFrom","envelope","find","locator","bootstrapOf","documents","revisions","binaryTargets","get","sort","schemaFrom","schemaOf","refreshFrom","enumeration","fromRoomVersion","removals"],"mappings":"AAMA,SACEA,eAAe,EACfC,wBAAwB,EACxBC,cAAc,QAET,iBAAiB;AAExB,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAgD3E,OAAO,SAASC,cAAcC,MAA0B;IACtD,OAAOA,WAAWC,YAAY,aAAa,CAAC,OAAO,EAAED,QAAQ;AAC/D;AAEA,OAAO,SAASE,gBAAgBC,OAAyB;IACvD,OAAO;QAACJ,cAAcI,QAAQH,MAAM;KAAE;AACxC;AAEA,OAAO,SAASI,WAAWJ,MAA0B,EAAEK,MAAc;IACnE,OAAO,GAAGN,cAAcC,QAAQ,CAAC,EAAEK,QAAQ;AAC7C;AAEA,OAAO,SAASC,WAAWC,IAAa;IACtC,IAAI,OAAOA,SAAS,YAAYA,SAAS,MAAM,OAAO;IACtD,IAAI,CAAE,CAAA,cAAcA,IAAG,KAAM,OAAOA,KAAKC,QAAQ,KAAK,YAAYD,KAAKC,QAAQ,KAAK,MAAM;QACxF,OAAO;IACT;IACA,MAAMA,WAAWD,KAAKC,QAAQ;IAC9B,IAAI,OAAOA,SAASC,GAAG,KAAK,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AI,CAACY,OAAO5B,IAAI;QAC9ByD,SAAS,CAAC7B,OAAO5B,IAAI,CAAC,GAAG4B,OAAOL,SAAS,CAACrB,QAAQ;IACpD;IACA,OAAO;QACLd,MAAM;QACNnB,aAAaA,YAAY8D;QACzByB;QACAC;QACA9B;QACA+B,eAAeA,cAAcE,IAAI;QACjCM,UAAUA,SAASN,IAAI;IACzB;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/read.ts"],"sourcesContent":["import type {\n BootstrapPage,\n BootstrapResult,\n ChangeAuthor,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n UNTYPED_FOLDERS,\n PROVIDER_SELECTION_ROOTS,\n RESERVED_NAMES,\n type TrackedAuthority,\n} from './discovery.js';\nimport type { HouseMode } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport type HeadChange = BootstrapPage['changes'][string];\n\nexport type HouseManifestFile = {\n path: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\n};\n\nexport type HouseContent = {\n path: string;\n content: string;\n};\n\nexport type HouseScope = LogPosition & {\n anchor: string;\n files: readonly HouseManifestFile[];\n contents: readonly HouseContent[];\n};\n\nexport type HouseEnvelope = {\n scopes: readonly HouseScope[];\n};\n\nexport type HouseGrant =\n | { method: 'GET'; url: string }\n | { method: 'POST'; operation: string; url: string };\n\nexport type HouseChange =\n | { path: string; removed: true }\n | {\n path: string;\n content: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\n }\n | { path: string; reference: { revision: string } };\n\nexport type HouseEnumeration = {\n authorities: readonly (LogPosition & {\n authority: string;\n changes: readonly HouseChange[];\n })[];\n};\n\nexport function authorityRoot(handle: string | undefined): string {\n return handle === undefined ? '/private' : `/rooms/${handle}`;\n}\n\nexport function contentPrefixes(tracked: TrackedAuthority): readonly string[] {\n return [authorityRoot(tracked.handle)];\n}\n\nexport function schemaPath(handle: string | undefined, schema: string): string {\n return `${authorityRoot(handle)}/${schema}`;\n}\n\nexport function parseGrant(body: unknown): HouseGrant | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {\n return null;\n }\n const transfer = body.transfer as Record<string, unknown>;\n if (typeof transfer.url !== 'string') return null;\n if (transfer.method === 'GET') return { method: 'GET', url: transfer.url };\n if (transfer.method !== 'POST' || typeof transfer.operation !== 'string') return null;\n return { method: 'POST', operation: transfer.operation, url: transfer.url };\n}\n\nfunction changeAuthor(value: unknown): ChangeAuthor | null {\n if (typeof value !== 'object' || value === null) return null;\n const { user, site, name } = value as Record<string, unknown>;\n if (typeof name !== 'string') return null;\n if (typeof user === 'string' && site === undefined) return { kind: 'user', id: user, name };\n if (typeof site === 'string' && user === undefined) return { kind: 'site', id: site, name };\n return null;\n}\n\nexport function headChange(held: {\n readonly author?: unknown;\n readonly created_at?: unknown;\n}): HeadChange | undefined | null {\n const author = held.author === undefined ? null : changeAuthor(held.author);\n if (held.author !== undefined && author === null) return null;\n if (held.created_at === undefined) return undefined;\n if (typeof held.created_at !== 'string') return null;\n return { author, time: held.created_at };\n}\n\nfunction headed(head: HeadChange | undefined) {\n return head === undefined ? {} : { head };\n}\n\nfunction parseFile(value: unknown, mode: HouseMode): HouseManifestFile | null {\n if (typeof value !== 'object' || value === null) return null;\n const file = value as Record<string, unknown>;\n if (typeof file.path !== 'string') return null;\n const head = headChange(file);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof file.sha256 !== 'string') return null;\n return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };\n }\n if (typeof file.revision !== 'string') return null;\n return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };\n}\n\nfunction parseScope(value: unknown, mode: HouseMode): HouseScope | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.manifest !== 'object' || held.manifest === null) return null;\n if (!Array.isArray(held.contents)) return null;\n const manifest = held.manifest as Record<string, unknown>;\n if (manifest.scope !== 'room') return null;\n const at = readPosition(manifest);\n if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)\n return null;\n if (\n manifest.room_handle !== null &&\n (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)\n )\n return null;\n if (!Array.isArray(manifest.files)) return null;\n const files: HouseManifestFile[] = [];\n for (const entry of manifest.files) {\n const file = parseFile(entry, mode);\n if (file === null) return null;\n files.push(file);\n }\n const contents: HouseContent[] = [];\n for (const entry of held.contents) {\n if (typeof entry !== 'object' || entry === null) return null;\n const content = entry as Record<string, unknown>;\n if (typeof content.path !== 'string' || typeof content.content !== 'string') return null;\n contents.push({ path: content.path, content: content.content });\n }\n return {\n anchor: manifest.anchor,\n ...at,\n files,\n contents,\n };\n}\n\nexport function parseEnvelope(body: unknown): HouseEnvelope | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('scopes' in body) || !Array.isArray(body.scopes)) return null;\n const scopes: HouseScope[] = [];\n for (const entry of body.scopes) {\n const scope = parseScope(entry, 'credential');\n if (scope === null) return null;\n scopes.push(scope);\n }\n return { scopes };\n}\n\nexport function parseSiteBootstrap(body: unknown): HouseScope | null {\n return parseScope(body, 'site');\n}\n\nfunction parseChange(value: unknown, mode: HouseMode): HouseChange | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.path !== 'string') return null;\n if (held.removed === true) return { path: held.path, removed: true };\n const head = headChange(held);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;\n return {\n path: held.path,\n content: held.content,\n revision: undefined,\n version: held.sha256,\n ...headed(head),\n };\n }\n if (typeof held.content === 'string' && typeof held.revision === 'string') {\n return {\n path: held.path,\n content: held.content,\n revision: held.revision,\n version: held.revision,\n ...headed(head),\n };\n }\n if (typeof held.reference === 'object' && held.reference !== null) {\n const reference = held.reference as Record<string, unknown>;\n if (typeof reference.revision !== 'string') return null;\n return { path: held.path, reference: { revision: reference.revision } };\n }\n return null;\n}\n\nexport function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('authorities' in body) || !Array.isArray(body.authorities)) return null;\n const authorities: HouseEnumeration['authorities'][number][] = [];\n for (const entry of body.authorities) {\n if (typeof entry !== 'object' || entry === null) return null;\n const held = entry as Record<string, unknown>;\n const at = readPosition(held);\n if (typeof held.authority !== 'string' || at === null) return null;\n if (!Array.isArray(held.changes)) return null;\n const changes: HouseChange[] = [];\n for (const change of held.changes) {\n const mapped = parseChange(change, mode);\n if (mapped === null) return null;\n changes.push(mapped);\n }\n authorities.push({ authority: held.authority, ...at, changes });\n }\n return { authorities };\n}\n\nexport function advancedScope(\n scope: HouseScope,\n view: HouseEnumeration['authorities'][number],\n): HouseScope {\n const files = new Map(scope.files.map((file) => [file.path, file]));\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n for (const change of view.changes) {\n files.delete(change.path);\n contents.delete(change.path);\n if ('removed' in change) continue;\n if ('content' in change) {\n files.set(change.path, {\n path: change.path,\n revision: change.revision,\n version: change.version,\n ...headed(change.head),\n });\n contents.set(change.path, change.content);\n continue;\n }\n const { revision } = change.reference;\n files.set(change.path, { path: change.path, revision, version: revision });\n }\n return {\n ...scope,\n position: view.position,\n logEpoch: view.logEpoch,\n files: [...files.values()],\n contents: [...contents].map(([path, content]) => ({ path, content })),\n };\n}\n\nexport function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean {\n return scope.anchor === tracked.authority;\n}\n\nconst ROOM_HOMES: readonly string[] = ['ROOM.md', 'collaboration'];\n\nfunction homes(tracked: TrackedAuthority): readonly string[] {\n return tracked.handle === undefined\n ? [...UNTYPED_FOLDERS, ...PROVIDER_SELECTION_ROOTS]\n : [...ROOM_HOMES, ...UNTYPED_FOLDERS];\n}\n\nexport function selects(tracked: TrackedAuthority, path: string): boolean {\n if (tracked.schemas.includes(path)) return false;\n const first = path.split('/', 1)[0].toLowerCase();\n return (\n !RESERVED_NAMES.some((name) => name.toLowerCase() === first) ||\n homes(tracked).some((home) => path === home || path.startsWith(`${home}/`))\n );\n}\n\nexport function bootstrapFrom(envelope: HouseEnvelope, tracked: TrackedAuthority): BootstrapResult {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n return bootstrapOf(scope, tracked);\n}\n\nexport function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage {\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const binaryTargets: string[] = [];\n for (const file of scope.files) {\n if (!selects(tracked, file.path)) continue;\n if (file.revision !== undefined) revisions[file.path] = file.revision;\n if (file.head !== undefined) changes[file.path] = file.head;\n const content = contents.get(file.path);\n if (content === undefined) binaryTargets.push(file.path);\n else documents[file.path] = content;\n }\n return {\n kind: 'bootstrap',\n roomVersion: roomVersion(scope),\n documents,\n revisions,\n changes,\n binaryTargets: binaryTargets.sort(),\n };\n}\n\nexport type HouseSchema = {\n schema: string | null;\n version: string | null;\n};\n\nexport function schemaFrom(\n envelope: HouseEnvelope,\n tracked: TrackedAuthority,\n schema: string,\n): HouseSchema | null {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return null;\n return schemaOf(scope, schema);\n}\n\nexport function schemaOf(scope: HouseScope, schema: string): HouseSchema | null {\n const file = scope.files.find((entry) => entry.path === schema);\n if (file === undefined) return { schema: null, version: null };\n const content = scope.contents.find((entry) => entry.path === schema);\n return content === undefined ? null : { schema: content.content, version: file.version };\n}\n\nexport function refreshFrom(\n enumeration: HouseEnumeration,\n tracked: TrackedAuthority,\n fromRoomVersion: string,\n): RefreshResult {\n const view = enumeration.authorities.find((entry) => entry.authority === tracked.authority);\n if (view === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n if (roomVersion(view) === fromRoomVersion) return { kind: 'still-current' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const binaryTargets: string[] = [];\n const removals: string[] = [];\n for (const change of view.changes) {\n if (!selects(tracked, change.path)) continue;\n if ('removed' in change) {\n removals.push(change.path);\n continue;\n }\n if ('content' in change) {\n documents[change.path] = change.content;\n if (change.revision !== undefined) revisions[change.path] = change.revision;\n if (change.head !== undefined) changes[change.path] = change.head;\n continue;\n }\n binaryTargets.push(change.path);\n revisions[change.path] = change.reference.revision;\n }\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion(view),\n documents,\n revisions,\n changes,\n binaryTargets: binaryTargets.sort(),\n removals: removals.sort(),\n };\n}\n"],"names":["UNTYPED_FOLDERS","PROVIDER_SELECTION_ROOTS","RESERVED_NAMES","readPosition","roomVersion","authorityRoot","handle","undefined","contentPrefixes","tracked","schemaPath","schema","parseGrant","body","transfer","url","method","operation","changeAuthor","value","user","site","name","kind","id","headChange","held","author","created_at","time","headed","head","parseFile","mode","file","path","sha256","revision","version","parseScope","manifest","Array","isArray","contents","scope","at","anchor","length","room_handle","files","entry","push","content","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","reference","parseEnumeration","authorities","authority","changes","change","mapped","advancedScope","view","Map","map","delete","set","position","logEpoch","values","matchesScope","ROOM_HOMES","homes","selects","schemas","includes","first","split","toLowerCase","some","home","startsWith","bootstrapFrom","envelope","find","locator","bootstrapOf","documents","revisions","binaryTargets","get","sort","schemaFrom","schemaOf","refreshFrom","enumeration","fromRoomVersion","removals"],"mappings":"AAMA,SACEA,eAAe,EACfC,wBAAwB,EACxBC,cAAc,QAET,iBAAiB;AAExB,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAgD3E,OAAO,SAASC,cAAcC,MAA0B;IACtD,OAAOA,WAAWC,YAAY,aAAa,CAAC,OAAO,EAAED,QAAQ;AAC/D;AAEA,OAAO,SAASE,gBAAgBC,OAAyB;IACvD,OAAO;QAACJ,cA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sD,OAAO5B,IAAI,GAAG;QACpC,IAAI,aAAa4B,QAAQ;YACvBsC,SAASlD,IAAI,CAACY,OAAO5B,IAAI;YACzB;QACF;QACA,IAAI,aAAa4B,QAAQ;YACvB4B,SAAS,CAAC5B,OAAO5B,IAAI,CAAC,GAAG4B,OAAOX,OAAO;YACvC,IAAIW,OAAO1B,QAAQ,KAAK9B,WAAWqF,SAAS,CAAC7B,OAAO5B,IAAI,CAAC,GAAG4B,OAAO1B,QAAQ;YAC3E,IAAI0B,OAAOhC,IAAI,KAAKxB,WAAWuD,OAAO,CAACC,OAAO5B,IAAI,CAAC,GAAG4B,OAAOhC,IAAI;YACjE;QACF;QACA8D,cAAc1C,IAAI,CAACY,OAAO5B,IAAI;QAC9ByD,SAAS,CAAC7B,OAAO5B,IAAI,CAAC,GAAG4B,OAAOL,SAAS,CAACrB,QAAQ;IACpD;IACA,OAAO;QACLd,MAAM;QACNnB,aAAaA,YAAY8D;QACzByB;QACAC;QACA9B;QACA+B,eAAeA,cAAcE,IAAI;QACjCM,UAAUA,SAASN,IAAI;IACzB;AACF"}
package/dist/stream.d.ts CHANGED
@@ -1,13 +1,12 @@
1
1
  import type { ConversationStream, RefreshPage, SelectedRooms, ServiceModeSignal } from '@agentshouse/mdruntime';
2
2
  import type { TrackedAuthority } from './discovery.js';
3
- import { type HouseDoor, type HouseMode } from './transport.js';
3
+ import type { HouseDoor, HouseMode } from './transport.js';
4
4
  import { type LogPosition } from './version.js';
5
5
  export type HouseNotifications = SelectedRooms & {
6
6
  track(authorities: readonly TrackedAuthority[]): void;
7
7
  advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;
8
8
  conversations: ConversationStream;
9
9
  serviceMode: ServiceModeSignal;
10
- question(conversation: string): void;
11
10
  };
12
11
  export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
13
12
  //# sourceMappingURL=stream.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../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AC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAAC;IAC1E,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAmQ5F"}
package/dist/stream.js CHANGED
@@ -1,9 +1,7 @@
1
- import { acceptedMessage, actionOutcome } from './actions.js';
1
+ import { acceptedMessage } from './actions.js';
2
2
  import { headChange, selects } from './read.js';
3
- import { PRIVATE_LOCATOR } from './transport.js';
4
3
  import { roomVersion } from './version.js';
5
4
  const HELD_POSITIONS_MAX = 256;
6
- const CONVERSATION_CARD = /^agents\/([^/]+)\.md$/;
7
5
  function position(value) {
8
6
  if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
9
7
  return BigInt(value);
@@ -17,10 +15,8 @@ export function houseNotifications(transport, mode) {
17
15
  const conversationObservers = new Set();
18
16
  const modeObservers = new Set();
19
17
  let replicated = [];
20
- let privateAuthority;
21
18
  const live = new Set();
22
19
  const noted = new Set();
23
- const asked = new Map();
24
20
  let listening = false;
25
21
  let catching = false;
26
22
  function listen() {
@@ -40,23 +36,6 @@ export function houseNotifications(transport, mode) {
40
36
  note: null
41
37
  });
42
38
  }
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', {
47
- conversation_id: conversation
48
- });
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
39
  function reopened() {
61
40
  const gapped = new Set([
62
41
  ...replicated,
@@ -68,7 +47,6 @@ export function houseNotifications(transport, mode) {
68
47
  kind: 'gap',
69
48
  conversation
70
49
  });
71
- for (const conversation of replicated)void question(conversation);
72
50
  }
73
51
  function converse(frame) {
74
52
  const conversation = frame.conversation_id;
@@ -136,6 +114,14 @@ export function houseNotifications(transport, mode) {
136
114
  });
137
115
  return;
138
116
  }
117
+ if (frame.type === 'interactions') {
118
+ emitConversation({
119
+ kind: 'questions',
120
+ conversation,
121
+ questions: structuredClone(frame.interactions)
122
+ });
123
+ return;
124
+ }
139
125
  const message = acceptedMessage(frame.message);
140
126
  if (message === null) return;
141
127
  emitConversation({
@@ -175,20 +161,11 @@ export function houseNotifications(transport, mode) {
175
161
  for (const observer of modeObservers)observer(mode);
176
162
  return;
177
163
  }
178
- if (frame.type === 'draft' || frame.type === 'working-note' || frame.type === 'process' || frame.type === 'commands' || frame.type === 'options' || frame.type === 'message') {
164
+ if (frame.type === 'draft' || frame.type === 'working-note' || frame.type === 'process' || frame.type === 'commands' || frame.type === 'options' || frame.type === 'interactions' || frame.type === 'message') {
179
165
  converse(frame);
180
166
  return;
181
167
  }
182
168
  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
- }
192
169
  const at = position(frame.position);
193
170
  if (at === null) {
194
171
  interrupt(frame.authority);
@@ -233,16 +210,11 @@ export function houseNotifications(transport, mode) {
233
210
  };
234
211
  }
235
212
  },
236
- question (conversation) {
237
- void question(conversation);
238
- },
239
213
  conversations: {
240
214
  replicate (next) {
241
- const entering = next.filter((conversation)=>!replicated.includes(conversation));
242
215
  replicated = [
243
216
  ...next
244
217
  ];
245
- for (const conversation of entering)void question(conversation);
246
218
  },
247
219
  observe (notify) {
248
220
  conversationObservers.add(notify);
@@ -259,7 +231,6 @@ export function houseNotifications(transport, mode) {
259
231
  track (entries) {
260
232
  locators.clear();
261
233
  schemas.clear();
262
- privateAuthority = entries.find((entry)=>entry.locator === PRIVATE_LOCATOR)?.authority;
263
234
  for (const entry of entries){
264
235
  locators.set(entry.authority, [
265
236
  ...locators.get(entry.authority) ?? [],
@@ -1 +1 @@
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,OAAO,QAAyB,YAAY;AACjE,SACEC,eAAe,QAKV,iBAAiB;AACxB,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,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BAAI5C,UAAUF,KAAKE,QAAQ;gBAAC;gBACvFkC;gBACAC;gBACAC;gBACAS,eAAe,EAAE;gBACjBR,UAAUA,SAASS,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 } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { headChange, selects, type HeadChange } from './read.js';\nimport type { HouseDoor, 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 serviceMode: ServiceModeSignal;\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 const live = new Set<string>();\n const noted = new Set<string>();\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 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 }\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 if (frame.type === 'interactions') {\n emitConversation({\n kind: 'questions',\n conversation,\n questions: structuredClone(frame.interactions),\n });\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 === 'interactions' ||\n frame.type === 'message'\n ) {\n converse(frame);\n return;\n }\n if (frame.type !== 'entries') return;\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 conversations: {\n replicate(next) {\n replicated = [...next];\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 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","headChange","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","schemas","observers","Set","conversationObservers","modeObservers","replicated","live","noted","listening","catching","listen","observe","receive","emitConversation","event","kind","add","conversation","observer","unnote","delete","note","reopened","gapped","clear","converse","frame","conversation_id","type","turn","turn_id","text","plan","structuredClone","steps","noteId","note_id","running","commands","options","questions","interactions","message","role","announce","authority","at","modelChanged","version","locator","get","interrupt","line","undefined","set","logEpoch","frames","service_mode","log_epoch","last","continued","next","entries","length","addresses","some","entry","includes","path","serviceMode","notify","conversations","replicate","opened","track","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,QAAQ,eAAe;AAE/C,SAASC,UAAU,EAAEC,OAAO,QAAyB,YAAY;AAEjE,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAmB3B,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,UAAU,IAAIF;IACpB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,MAAME,gBAAgB,IAAIF;IAC1B,IAAIG,aAAgC,EAAE;IACtC,MAAMC,OAAO,IAAIJ;IACjB,MAAMK,QAAQ,IAAIL;IAClB,IAAIM,YAAY;IAChB,IAAIC,WAAW;IAEf,SAASC;QACP,IAAIF,WAAW;QACfA,YAAY;QACZZ,OAAOe,OAAO,CAACC;IACjB;IAEA,SAASC,iBAAiBC,KAAwB;QAChD,IAAIA,MAAMC,IAAI,KAAK,SAASD,MAAMC,IAAI,KAAK,oBAAoBT,KAAKU,GAAG,CAACF,MAAMG,YAAY;QAC1F,KAAK,MAAMC,YAAYf,sBAAuBe,SAASJ;IACzD;IAEA,SAASK,OAAOF,YAAoB;QAClC,IAAI,CAACV,MAAMa,MAAM,CAACH,eAAe;QACjCJ,iBAAiB;YAAEE,MAAM;YAAgBE;YAAcI,MAAM;QAAK;IACpE;IAEA,SAASC;QACP,MAAMC,SAAS,IAAIrB,IAA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AUJ,SAASK,OAAO,CAAC3B,MAAME,IAAI;oBAC3C,IAAIwB,YAAY,CAAC,GAAGJ,SAASM,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAMjC,OAAOwB,QAAQrC,EAAE,CAAC,CAAC;YACzB,IAAIa,SAASN,WAAW,OAAO;YAC/BxD,MAAMyD,GAAG,CAACyB,QAAQlC,SAAS,EAAE;gBAAEU,UAAUH,KAAKG,QAAQ;gBAAEC,QAAQ2B;YAAQ;YACxE,OAAO;gBACLpE,MAAM;gBACN5B,aAAaA,YAAY;oBAAEE,UAAUsE,KAAKtE,QAAQ,CAAC0G,QAAQ;oBAAIxC,UAAUH,KAAKG,QAAQ;gBAAC;gBACvF8B;gBACAC;gBACAC;gBACAS,eAAe,EAAE;gBACjBR,UAAUA,SAASS,IAAI;YACzB;QACF;IACF;AACF"}
@@ -1,3 +1,4 @@
1
+ import type { ConversationEvent } from '@agentshouse/mdruntime';
1
2
  export declare const DOOR_DISCOVER = "/door/discover";
2
3
  export declare const DOOR_BOOTSTRAP = "/door/bootstrap";
3
4
  export declare const DOOR_ENUMERATE = "/door/enumerate";
@@ -40,6 +41,9 @@ export type HouseStreamEntry = {
40
41
  };
41
42
  created_at?: string;
42
43
  };
44
+ type LiveFact<K extends ConversationEvent['kind']> = Extract<ConversationEvent, {
45
+ kind: K;
46
+ }>;
43
47
  export type HouseStreamFrame = {
44
48
  type: 'entries';
45
49
  authority: string;
@@ -52,11 +56,15 @@ export type HouseStreamFrame = {
52
56
  turn_id: string;
53
57
  text: string;
54
58
  blocks: readonly unknown[];
55
- steps: readonly unknown[];
59
+ steps: LiveFact<'plan'>['plan'];
56
60
  } | {
57
61
  type: 'message';
58
62
  conversation_id: string;
59
63
  message: unknown;
64
+ } | {
65
+ type: 'interactions';
66
+ conversation_id: string;
67
+ interactions: readonly unknown[];
60
68
  } | {
61
69
  type: 'working-note';
62
70
  conversation_id: string;
@@ -69,11 +77,11 @@ export type HouseStreamFrame = {
69
77
  } | {
70
78
  type: 'commands';
71
79
  conversation_id: string;
72
- commands: readonly unknown[];
80
+ commands: LiveFact<'commands'>['commands'];
73
81
  } | {
74
82
  type: 'options';
75
83
  conversation_id: string;
76
- options: readonly unknown[];
84
+ options: LiveFact<'options'>['options'];
77
85
  } | {
78
86
  type: 'signal';
79
87
  service_mode: string;
@@ -93,4 +101,5 @@ export type HouseSiteTransport = HouseDoor & {
93
101
  online(): boolean;
94
102
  read(route: string): Promise<HouseDoorAnswer>;
95
103
  };
104
+ export {};
96
105
  //# sourceMappingURL=transport.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAE9C,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAExC,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AAEtD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAE7D,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAE5D,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,eAAO,MAAM,eAAe,YAAY,CAAC;AAEzC,eAAO,MAAM,kBAAkB,MAAM,CAAC;AAEtC,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB,mBAAmB,GACnB,uBAAuB,GACvB,8BAA8B,GAC9B,iBAAiB,GACjB,mBAAmB,CAAC;AAExB,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,GAAG,UA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@@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/transport.ts"],"sourcesContent":["export const DOOR_DISCOVER = '/door/discover';\n\nexport const DOOR_BOOTSTRAP = '/door/bootstrap';\n\nexport const DOOR_ENUMERATE = '/door/enumerate';\n\nexport const DOOR_BATCH = '/door/batch';\n\nexport const DOOR_BATCH_UPLOAD = '/door/batch-upload';\n\nexport const DOOR_REVISIONS = '/door/revisions';\n\nexport const SITE_DOOR_DISCOVER = '/_house/door/discover';\n\nexport const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';\n\nexport const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';\n\nexport const SITE_DOOR_SUBMIT = '/_house/door/submit';\n\nexport const PRIVATE_LOCATOR = 'private';\n\nexport const DOOR_SELECTION_MAX = 256;\n\nexport type HouseMode = 'credential' | 'site';\n\nexport type HouseDoorAnswer = {\n status: number;\n body: unknown;\n};\n\nexport type HouseByteAct =\n | 'local_copy_bundle'\n | 'authored_batch_upload'\n | 'conversation_original_upload'\n | 'original_upload'\n | 'original_download';\n\nexport type HouseByteBody = string | ArrayBuffer | Uint8Array;\n\nexport type HouseByteAnswer = 'json' | 'bytes';\n\nexport type HouseByteTransfer = {\n act: HouseByteAct;\n method: 'GET' | 'POST';\n url: string;\n answer: HouseByteAnswer;\n body?: HouseByteBody;\n operation?: string;\n};\n\nexport type HouseStreamEntry = {\n path: string;\n kind: 'edited' | 'removed';\n revision?: string;\n text?: string;\n author?: { user: string; name: string } | { site: string; name: string };\n created_at?: string;\n};\n\nexport type HouseStreamFrame =\n | {\n type: 'entries';\n authority: string;\n position: string;\n log_epoch: string;\n entries: readonly HouseStreamEntry[];\n }\n | {\n type: 'draft';\n conversation_id: string;\n turn_id: string;\n text: string;\n blocks: readonly unknown[];\n steps: readonly unknown[];\n }\n | { type: 'message'; conversation_id: string; message: unknown }\n | { type: 'working-note'; conversation_id: string; note_id: string; text: string }\n | { type: 'process'; conversation_id: string; running: boolean }\n | { type: 'commands'; conversation_id: string; commands: readonly unknown[] }\n | { type: 'options'; conversation_id: string; options: readonly unknown[] }\n | { type: 'signal'; service_mode: string };\n\nexport type HouseStream = {\n observe(receive: (frame: HouseStreamFrame) => void): () => void;\n opened(notify: () => void): () => void;\n};\n\nexport type HouseDoor = {\n door(route: string, body: unknown): Promise<HouseDoorAnswer>;\n stream: HouseStream;\n};\n\nexport type HouseTransport = HouseDoor & {\n transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;\n};\n\nexport type HouseSiteTransport = HouseDoor & {\n online(): boolean;\n read(route: string): Promise<HouseDoorAnswer>;\n};\n"],"names":["DOOR_DISCOVER","DOOR_BOOTSTRAP","DOOR_ENUMERATE","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_REVISIONS","SITE_DOOR_DISCOVER","SITE_DOOR_BOOTSTRAP","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","PRIVATE_LOCATOR","DOOR_SELECTION_MAX"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,iBAAiB;AAE9C,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,aAAa,cAAc;AAExC,OAAO,MAAMC,oBAAoB,qBAAqB;AAEtD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,qBAAqB,wBAAwB;AAE1D,OAAO,MAAMC,sBAAsB,0BAA0B;AAE7D,OAAO,MAAMC,sBAAsB,yBAAyB;AAE5D,OAAO,MAAMC,mBAAmB,sBAAsB;AAEtD,OAAO,MAAMC,kBAAkB,UAAU;AAEzC,OAAO,MAAMC,qBAAqB,IAAI"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/transport.ts"],"sourcesContent":["import type { ConversationEvent } from '@agentshouse/mdruntime';\n\nexport const DOOR_DISCOVER = '/door/discover';\n\nexport const DOOR_BOOTSTRAP = '/door/bootstrap';\n\nexport const DOOR_ENUMERATE = '/door/enumerate';\n\nexport const DOOR_BATCH = '/door/batch';\n\nexport const DOOR_BATCH_UPLOAD = '/door/batch-upload';\n\nexport const DOOR_REVISIONS = '/door/revisions';\n\nexport const SITE_DOOR_DISCOVER = '/_house/door/discover';\n\nexport const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';\n\nexport const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';\n\nexport const SITE_DOOR_SUBMIT = '/_house/door/submit';\n\nexport const PRIVATE_LOCATOR = 'private';\n\nexport const DOOR_SELECTION_MAX = 256;\n\nexport type HouseMode = 'credential' | 'site';\n\nexport type HouseDoorAnswer = {\n status: number;\n body: unknown;\n};\n\nexport type HouseByteAct =\n | 'local_copy_bundle'\n | 'authored_batch_upload'\n | 'conversation_original_upload'\n | 'original_upload'\n | 'original_download';\n\nexport type HouseByteBody = string | ArrayBuffer | Uint8Array;\n\nexport type HouseByteAnswer = 'json' | 'bytes';\n\nexport type HouseByteTransfer = {\n act: HouseByteAct;\n method: 'GET' | 'POST';\n url: string;\n answer: HouseByteAnswer;\n body?: HouseByteBody;\n operation?: string;\n};\n\nexport type HouseStreamEntry = {\n path: string;\n kind: 'edited' | 'removed';\n revision?: string;\n text?: string;\n author?: { user: string; name: string } | { site: string; name: string };\n created_at?: string;\n};\n\ntype LiveFact<K extends ConversationEvent['kind']> = Extract<ConversationEvent, { kind: K }>;\n\nexport type HouseStreamFrame =\n | {\n type: 'entries';\n authority: string;\n position: string;\n log_epoch: string;\n entries: readonly HouseStreamEntry[];\n }\n | {\n type: 'draft';\n conversation_id: string;\n turn_id: string;\n text: string;\n blocks: readonly unknown[];\n steps: LiveFact<'plan'>['plan'];\n }\n | { type: 'message'; conversation_id: string; message: unknown }\n | { type: 'interactions'; conversation_id: string; interactions: readonly unknown[] }\n | { type: 'working-note'; conversation_id: string; note_id: string; text: string }\n | { type: 'process'; conversation_id: string; running: boolean }\n | { type: 'commands'; conversation_id: string; commands: LiveFact<'commands'>['commands'] }\n | { type: 'options'; conversation_id: string; options: LiveFact<'options'>['options'] }\n | { type: 'signal'; service_mode: string };\n\nexport type HouseStream = {\n observe(receive: (frame: HouseStreamFrame) => void): () => void;\n opened(notify: () => void): () => void;\n};\n\nexport type HouseDoor = {\n door(route: string, body: unknown): Promise<HouseDoorAnswer>;\n stream: HouseStream;\n};\n\nexport type HouseTransport = HouseDoor & {\n transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;\n};\n\nexport type HouseSiteTransport = HouseDoor & {\n online(): boolean;\n read(route: string): Promise<HouseDoorAnswer>;\n};\n"],"names":["DOOR_DISCOVER","DOOR_BOOTSTRAP","DOOR_ENUMERATE","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_REVISIONS","SITE_DOOR_DISCOVER","SITE_DOOR_BOOTSTRAP","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","PRIVATE_LOCATOR","DOOR_SELECTION_MAX"],"mappings":"AAEA,OAAO,MAAMA,gBAAgB,iBAAiB;AAE9C,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,aAAa,cAAc;AAExC,OAAO,MAAMC,oBAAoB,qBAAqB;AAEtD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,qBAAqB,wBAAwB;AAE1D,OAAO,MAAMC,sBAAsB,0BAA0B;AAE7D,OAAO,MAAMC,sBAAsB,yBAAyB;AAE5D,OAAO,MAAMC,mBAAmB,sBAAsB;AAEtD,OAAO,MAAMC,kBAAkB,UAAU;AAEzC,OAAO,MAAMC,qBAAqB,IAAI"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-alpha.44",
3
+ "version": "0.1.0-alpha.46",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -26,6 +26,6 @@
26
26
  ],
27
27
  "dependencies": {
28
28
  "@agentshouse/mdmodel": "0.1.0-alpha.19",
29
- "@agentshouse/mdruntime": "0.1.0-alpha.46"
29
+ "@agentshouse/mdruntime": "0.1.0-alpha.48"
30
30
  }
31
31
  }