@agentshouse/mdruntime-adapter 0.1.0-alpha.45 → 0.1.0-alpha.47
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +6 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +58 -29
- package/dist/actions.js.map +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +14 -10
- package/dist/adapter.js.map +1 -1
- package/dist/read.d.ts +3 -1
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +55 -4
- package/dist/read.js.map +1 -1
- package/dist/site.js +1 -1
- package/dist/site.js.map +1 -1
- package/dist/stream.d.ts +2 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +20 -40
- package/dist/stream.js.map +1 -1
- package/dist/transport.d.ts +4 -0
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js.map +1 -1
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -33,6 +33,12 @@ queued.
|
|
|
33
33
|
Slots answers each Slot the Provider declares, in its order, with its entries
|
|
34
34
|
in order, each a Room and its segment; a Room two Slots list is the same Room.
|
|
35
35
|
|
|
36
|
+
Each Room in Rooms lists its `attachments`, the files the Provider holds for it
|
|
37
|
+
that its Documents link by the Provider's reference, ordered by `reference`,
|
|
38
|
+
each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
|
|
39
|
+
`entry`. They are as the Provider last declared them and hold no bytes;
|
|
40
|
+
open one through the Provider Action that serves it.
|
|
41
|
+
|
|
36
42
|
Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
37
43
|
touch the network.
|
|
38
44
|
History and Call go to the Provider through the Adapter. A Call result whose
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,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
|
-
|
|
352
|
-
const
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
372
|
-
const message = acceptedMessage(
|
|
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
|
-
|
|
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
|
|
419
|
+
result
|
|
391
420
|
};
|
|
392
421
|
}
|
|
393
422
|
|
package/dist/actions.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/actions.ts"],"sourcesContent":["import {\n changeBatchIdentity,\n type 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,gBAAgBC,MAAyB;IACvD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MmG,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","limit","answered","page"],"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adapter.d.ts.map
CHANGED
|
@@ -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;
|
|
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;AAmCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAsYpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -15,6 +15,7 @@ const UNCERTAIN = {
|
|
|
15
15
|
const UNCERTAIN_READ = {
|
|
16
16
|
kind: 'transport-uncertainty'
|
|
17
17
|
};
|
|
18
|
+
const NO_ATTACHMENTS = new Set();
|
|
18
19
|
function lapsedGrant(outcome) {
|
|
19
20
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
20
21
|
}
|
|
@@ -31,7 +32,14 @@ export function createAgentsHouseAdapter(options) {
|
|
|
31
32
|
const transport = options.transport;
|
|
32
33
|
const notifications = houseNotifications(transport, 'credential');
|
|
33
34
|
const tracked = new Map();
|
|
35
|
+
const handed = new Map();
|
|
34
36
|
const models = modelShelf();
|
|
37
|
+
function handing(entry, answer) {
|
|
38
|
+
if ((answer.kind === 'bootstrap' || answer.kind === 'net-advancement') && answer.attachments !== undefined) {
|
|
39
|
+
handed.set(entry.locator, new Set(answer.attachments.map((attachment)=>attachment.reference)));
|
|
40
|
+
}
|
|
41
|
+
return answer;
|
|
42
|
+
}
|
|
35
43
|
function held(envelope, entry, schema, failure) {
|
|
36
44
|
return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
|
|
37
45
|
}
|
|
@@ -286,6 +294,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
286
294
|
const entries = trackedFrom(document);
|
|
287
295
|
tracked.clear();
|
|
288
296
|
for (const entry of entries)tracked.set(entry.locator, entry);
|
|
297
|
+
for (const locator of handed.keys())if (!tracked.has(locator)) handed.delete(locator);
|
|
289
298
|
notifications.track(entries);
|
|
290
299
|
const acquired = await acquireModels(entries);
|
|
291
300
|
models.keep(entries.map((entry)=>entry.locator));
|
|
@@ -300,7 +309,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
300
309
|
if (request.pageToken !== undefined) return {
|
|
301
310
|
kind: 'transport-uncertainty'
|
|
302
311
|
};
|
|
303
|
-
return bootstrapTogether(entry);
|
|
312
|
+
return handing(entry, await bootstrapTogether(entry));
|
|
304
313
|
},
|
|
305
314
|
async refresh (_authorization, request) {
|
|
306
315
|
const entry = authorityFor(request.locator);
|
|
@@ -315,17 +324,17 @@ export function createAgentsHouseAdapter(options) {
|
|
|
315
324
|
if (from === null) return {
|
|
316
325
|
kind: 'beyond-horizon'
|
|
317
326
|
};
|
|
318
|
-
const streamed = notifications.advance(entry, from);
|
|
327
|
+
const streamed = notifications.advance(entry, from, handed.get(entry.locator) ?? NO_ATTACHMENTS);
|
|
319
328
|
if (streamed !== null && (request.minPosition === undefined || reachedVersion(streamed.roomVersion, request.minPosition, entry.logEpoch))) return streamed;
|
|
320
329
|
const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
|
|
321
|
-
return enumerateTogether({
|
|
330
|
+
return handing(entry, await enumerateTogether({
|
|
322
331
|
entry,
|
|
323
332
|
from,
|
|
324
333
|
fromRoomVersion: request.fromRoomVersion,
|
|
325
334
|
...minPosition?.logEpoch === from.logEpoch ? {
|
|
326
335
|
minPosition: minPosition.position
|
|
327
336
|
} : {}
|
|
328
|
-
});
|
|
337
|
+
}));
|
|
329
338
|
},
|
|
330
339
|
async mutate (_authorization, request, keep) {
|
|
331
340
|
const entry = authorityFor(request.locator);
|
|
@@ -370,12 +379,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
370
379
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
371
380
|
},
|
|
372
381
|
async action (_authorization, request) {
|
|
373
|
-
|
|
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;
|
|
382
|
+
return withAt(await houseAction(transport, request));
|
|
379
383
|
},
|
|
380
384
|
roomVersions: notifications,
|
|
381
385
|
conversations: notifications.conversations,
|
package/dist/adapter.js.map
CHANGED
|
@@ -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;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,QAAQ;gBAAC,CAAC;gBACxE,GAAIjB,QAAQQ,SAAS,KAAKnG,YAAY,CAAC,IAAI;oBAAEmG,WAAWR,QAAQQ,SAAS;gBAAC,CAAC;YAC7E;YAEF,OAAOvI,eAAe4C,OAAOI,MAAM,EAAEJ,OAAOK,IAAI,EAAEpB,MAAMM,OAAO,EAAE;gBAC/D4G,MAAMhB,QAAQgB,IAAI;gBAClB,GAAIhB,QAAQiB,QAAQ,KAAK5G,YAAY,CAAC,IAAI;oBAAE4G,UAAUjB,QAAQiB,QAAQ;gBAAC,CAAC;YAC1E;QACF;QAEAC,SAAQ9G,OAAe,EAAE+G,OAAe,EAAEC,MAAc;YACtD,OAAO1I,eAAeyI,SAASC,QAAQtF,aAAa1B,UAAU+B;QAChE;QAEA,MAAMkF,QAAOtB,cAA6B,EAAEC,OAAsB;YAChE,MAAMhE,SAASD,OAAO,MAAM/E,YAAYwC,WAAWwG;YACnD,MAAMzB,WAAYyB,QAAQsB,KAAK,EAAwCC;YACvE,IACEvB,QAAQwB,IAAI,KAAK,yBACjBxF,OAAOnD,IAAI,KAAK,YAChB,OAAO0F,aAAa,UACpB;gBACA9E,cAAcgI,QAAQ,CAAClD;YACzB;YACA,OAAOvC;QACT;QAEA0F,cAAcjI;QACdkI,eAAelI,cAAckI,aAAa;QAC1CC,aAAanI,cAAcmI,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\nconst NO_ATTACHMENTS: ReadonlySet<string> = new Set();\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 handed = new Map<string, ReadonlySet<string>>();\n const models = modelShelf();\n\n function handing<T extends BootstrapResult | RefreshResult>(\n entry: TrackedAuthority,\n answer: T,\n ): T {\n if (\n (answer.kind === 'bootstrap' || answer.kind === 'net-advancement') &&\n answer.attachments !== undefined\n ) {\n handed.set(\n entry.locator,\n new Set(answer.attachments.map((attachment) => attachment.reference)),\n );\n }\n return answer;\n }\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 for (const locator of handed.keys()) if (!tracked.has(locator)) handed.delete(locator);\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 handing(entry, await 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(\n entry,\n from,\n handed.get(entry.locator) ?? NO_ATTACHMENTS,\n );\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 handing(\n entry,\n await enumerateTogether({\n entry,\n from,\n fromRoomVersion: request.fromRoomVersion,\n ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),\n }),\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","NO_ATTACHMENTS","Set","lapsedGrant","outcome","code","modelFailure","classified","envelope","createAgentsHouseAdapter","options","site","transport","notifications","tracked","Map","handed","models","handing","entry","answer","attachments","undefined","set","locator","map","attachment","reference","held","schema","failure","handle","modelPrefixes","own","acquireModels","entries","acquired","part","length","privateEntry","find","door","prefixes","flatMap","status","body","bundled","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","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","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","request","discover","document","clear","keys","has","delete","track","authorities","actions","bootstrap","pageToken","refresh","streamed","advance","mutate","mapped","changeBatch","history","path","revision","reached","version","target","action","roomVersions","conversations","serviceMode"],"mappings":"AAkBA,SACEA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;YAC1E;QACF;QAEAC,SAAQrH,OAAe,EAAEsH,OAAe,EAAEC,MAAc;YACtD,OAAOnJ,eAAekJ,SAASC,QAAQvF,aAAahC,UAAUqC;QAChE;QAEA,MAAMmF,QAAOzB,cAA6B,EAAEC,OAAsB;YAChE,OAAO/D,OAAO,MAAMvF,YAAY0C,WAAW4G;QAC7C;QAEAyB,cAAcpI;QACdqI,eAAerI,cAAcqI,aAAa;QAC1CC,aAAatI,cAAcsI,WAAW;IACxC;AACF"}
|
package/dist/read.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BootstrapPage, BootstrapResult, RefreshResult } from '@agentshouse/mdruntime';
|
|
1
|
+
import type { BootstrapPage, BootstrapResult, RefreshResult, RoomAttachment } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseMode } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
@@ -17,6 +17,7 @@ export type HouseScope = LogPosition & {
|
|
|
17
17
|
anchor: string;
|
|
18
18
|
files: readonly HouseManifestFile[];
|
|
19
19
|
contents: readonly HouseContent[];
|
|
20
|
+
attachments?: readonly RoomAttachment[];
|
|
20
21
|
};
|
|
21
22
|
export type HouseEnvelope = {
|
|
22
23
|
scopes: readonly HouseScope[];
|
|
@@ -48,6 +49,7 @@ export type HouseEnumeration = {
|
|
|
48
49
|
authorities: readonly (LogPosition & {
|
|
49
50
|
authority: string;
|
|
50
51
|
changes: readonly HouseChange[];
|
|
52
|
+
attachments?: readonly RoomAttachment[];
|
|
51
53
|
})[];
|
|
52
54
|
};
|
|
53
55
|
export declare function authorityRoot(handle: string | undefined): string;
|
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAEf,aAAa,
|
|
1
|
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value !== 'object' || value === null) return null;
|
|
65
|
+
const { attachment, name, bytes, media_type: mediaType } = value;
|
|
66
|
+
if (typeof attachment !== 'string' || typeof name !== 'string') return null;
|
|
67
|
+
if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0) return null;
|
|
68
|
+
if (mediaType !== null && typeof mediaType !== 'string') return null;
|
|
69
|
+
return {
|
|
70
|
+
reference: attachment,
|
|
71
|
+
name,
|
|
72
|
+
byteLength: bytes,
|
|
73
|
+
mediaType,
|
|
74
|
+
entry: value
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function parseOriginals(value) {
|
|
78
|
+
if (!Array.isArray(value)) return null;
|
|
79
|
+
const attachments = [];
|
|
80
|
+
for (const entry of value){
|
|
81
|
+
const attachment = parseOriginal(entry);
|
|
82
|
+
if (attachment === null) return null;
|
|
83
|
+
attachments.push(attachment);
|
|
84
|
+
}
|
|
85
|
+
return attachments;
|
|
86
|
+
}
|
|
87
|
+
function declared(attachments) {
|
|
88
|
+
return attachments === undefined ? {} : {
|
|
89
|
+
attachments
|
|
90
|
+
};
|
|
91
|
+
}
|
|
63
92
|
function parseFile(value, mode) {
|
|
64
93
|
if (typeof value !== 'object' || value === null) return null;
|
|
65
94
|
const file = value;
|
|
@@ -110,12 +139,21 @@ function parseScope(value, mode) {
|
|
|
110
139
|
content: content.content
|
|
111
140
|
});
|
|
112
141
|
}
|
|
113
|
-
return {
|
|
142
|
+
if (mode === 'site') return {
|
|
114
143
|
anchor: manifest.anchor,
|
|
115
144
|
...at,
|
|
116
145
|
files,
|
|
117
146
|
contents
|
|
118
147
|
};
|
|
148
|
+
const attachments = parseOriginals(held.originals);
|
|
149
|
+
if (attachments === null) return null;
|
|
150
|
+
return {
|
|
151
|
+
anchor: manifest.anchor,
|
|
152
|
+
...at,
|
|
153
|
+
files,
|
|
154
|
+
contents,
|
|
155
|
+
attachments
|
|
156
|
+
};
|
|
119
157
|
}
|
|
120
158
|
export function parseEnvelope(body) {
|
|
121
159
|
if (typeof body !== 'object' || body === null) return null;
|
|
@@ -190,10 +228,21 @@ export function parseEnumeration(body, mode) {
|
|
|
190
228
|
if (mapped === null) return null;
|
|
191
229
|
changes.push(mapped);
|
|
192
230
|
}
|
|
231
|
+
if (mode === 'site') {
|
|
232
|
+
authorities.push({
|
|
233
|
+
authority: held.authority,
|
|
234
|
+
...at,
|
|
235
|
+
changes
|
|
236
|
+
});
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const attachments = parseOriginals(held.originals);
|
|
240
|
+
if (attachments === null) return null;
|
|
193
241
|
authorities.push({
|
|
194
242
|
authority: held.authority,
|
|
195
243
|
...at,
|
|
196
|
-
changes
|
|
244
|
+
changes,
|
|
245
|
+
attachments
|
|
197
246
|
});
|
|
198
247
|
}
|
|
199
248
|
return {
|
|
@@ -297,7 +346,8 @@ export function bootstrapOf(scope, tracked) {
|
|
|
297
346
|
documents,
|
|
298
347
|
revisions,
|
|
299
348
|
changes,
|
|
300
|
-
binaryTargets: binaryTargets.sort()
|
|
349
|
+
binaryTargets: binaryTargets.sort(),
|
|
350
|
+
...declared(scope.attachments)
|
|
301
351
|
};
|
|
302
352
|
}
|
|
303
353
|
export function schemaFrom(envelope, tracked, schema) {
|
|
@@ -353,7 +403,8 @@ export function refreshFrom(enumeration, tracked, fromRoomVersion) {
|
|
|
353
403
|
revisions,
|
|
354
404
|
changes,
|
|
355
405
|
binaryTargets: binaryTargets.sort(),
|
|
356
|
-
removals: removals.sort()
|
|
406
|
+
removals: removals.sort(),
|
|
407
|
+
...declared(view.attachments)
|
|
357
408
|
};
|
|
358
409
|
}
|
|
359
410
|
|
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_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,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,KA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ACF;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"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/read.ts"],"sourcesContent":["import type {\n BootstrapPage,\n BootstrapResult,\n ChangeAuthor,\n RefreshResult,\n RoomAttachment,\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 attachments?: readonly RoomAttachment[];\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 attachments?: readonly RoomAttachment[];\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 parseOriginal(value: unknown): RoomAttachment | null {\n if (typeof value !== 'object' || value === null) return null;\n const { attachment, name, bytes, media_type: mediaType } = value as Record<string, unknown>;\n if (typeof attachment !== 'string' || typeof name !== 'string') return null;\n if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0) return null;\n if (mediaType !== null && typeof mediaType !== 'string') return null;\n return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };\n}\n\nfunction parseOriginals(value: unknown): readonly RoomAttachment[] | null {\n if (!Array.isArray(value)) return null;\n const attachments: RoomAttachment[] = [];\n for (const entry of value) {\n const attachment = parseOriginal(entry);\n if (attachment === null) return null;\n attachments.push(attachment);\n }\n return attachments;\n}\n\nfunction declared(attachments: readonly RoomAttachment[] | undefined) {\n return attachments === undefined ? {} : { attachments };\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 if (mode === 'site') return { anchor: manifest.anchor, ...at, files, contents };\n const attachments = parseOriginals(held.originals);\n if (attachments === null) return null;\n return { anchor: manifest.anchor, ...at, files, contents, attachments };\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 if (mode === 'site') {\n authorities.push({ authority: held.authority, ...at, changes });\n continue;\n }\n const attachments = parseOriginals(held.originals);\n if (attachments === null) return null;\n authorities.push({ authority: held.authority, ...at, changes, attachments });\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 ...declared(scope.attachments),\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 ...declared(view.attachments),\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","parseOriginal","attachment","bytes","media_type","mediaType","Number","isSafeInteger","reference","byteLength","entry","parseOriginals","Array","isArray","attachments","push","declared","parseFile","mode","file","path","sha256","revision","version","parseScope","manifest","contents","scope","at","anchor","length","room_handle","files","content","originals","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","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":"AAOA,SACEA,eAAe,EACfC,wBAAwB,EACxBC,cAAc,QAET,iBAAiB;AAExB,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAkD3E,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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AO5C,IAAI,KAAKxB,WAAWmE,OAAO,CAACC,OAAOxB,IAAI,CAAC,GAAGwB,OAAO5C,IAAI;YACjE;QACF;QACA0E,cAAc3D,IAAI,CAAC6B,OAAOxB,IAAI;QAC9BqD,SAAS,CAAC7B,OAAOxB,IAAI,CAAC,GAAGwB,OAAOpC,SAAS,CAACc,QAAQ;IACpD;IACA,OAAO;QACL9B,MAAM;QACNnB,aAAaA,YAAY0E;QACzByB;QACAC;QACA9B;QACA+B,eAAeA,cAAcE,IAAI;QACjCM,UAAUA,SAASN,IAAI;QACvB,GAAG5D,SAAS+B,KAAKjC,WAAW,CAAC;IAC/B;AACF"}
|
package/dist/site.js
CHANGED
|
@@ -92,7 +92,7 @@ export function createSiteAdapter(transport) {
|
|
|
92
92
|
if (from === null) return {
|
|
93
93
|
kind: 'beyond-horizon'
|
|
94
94
|
};
|
|
95
|
-
const streamed = notifications.advance(entry, from);
|
|
95
|
+
const streamed = notifications.advance(entry, from, null);
|
|
96
96
|
if (streamed !== null) return streamed;
|
|
97
97
|
const found = await enumeration(entry, from);
|
|
98
98
|
if ('kind' in found) return found;
|
package/dist/site.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/site.ts"],"sourcesContent":["import type {\n Adapter,\n AdapterFailure,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n ModelResult,\n RefreshResult,\n RetryableRefusal,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\n UNTYPED_FOLDERS,\n mapDiscovery,\n parseSiteDiscovery,\n siteCapabilities,\n siteSlots,\n siteTracked,\n type SiteTracked,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport {\n advancedScope,\n bootstrapOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\n schemaOf,\n schemaPath,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n PRIVATE_LOCATOR,\n SITE_DOOR_BOOTSTRAP,\n SITE_DOOR_DISCOVER,\n SITE_DOOR_ENUMERATE,\n SITE_DOOR_SUBMIT,\n type HouseSiteTransport,\n} from './transport.js';\nimport {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\ntype Refused = AdapterFailure | RetryableRefusal | { kind: 'beyond-horizon' };\n\ntype CaughtUp = { scope: HouseScope } | { failure: AdapterFailure };\n\ntype Acquired = { roomVersion: string; model: HeldModel };\n\nconst UNCERTAIN = { kind: 'transport-uncertainty' } as const;\n\nfunction siteRoom(\n tracked: SiteTracked,\n attachedModel: DiscoveredRoom['attachedModel'],\n): DiscoveredRoom {\n return {\n name: tracked.handle,\n locator: tracked.locator,\n roomVersion: roomVersion(tracked),\n operations: { read: [''], sync: [''], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n untypedFolders: [...UNTYPED_FOLDERS],\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' || refused.kind === 'retryable-refusal'\n ? UNCERTAIN\n : refused;\n}\n\nexport function createSiteAdapter(transport: HouseSiteTransport): Adapter {\n const notifications = houseNotifications(transport, 'site');\n const tracked = new Map<string, SiteTracked>();\n const models = modelShelf();\n const acquired = new Map<string, Acquired>();\n let caught = new Map<string, CaughtUp>();\n\n async function enumeration(\n entry: SiteTracked,\n from: LogPosition,\n ): Promise<HouseEnumeration | Refused> {\n const answer = await transport.door(SITE_DOOR_ENUMERATE, {\n positions: [presented(entry.authority, from)],\n });\n const behind = doorRefusal(answer.body);\n if (behind?.code === 'replica_behind') return { kind: 'retryable-refusal', ...behind };\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;\n }\n\n async function caughtUp(entry: SiteTracked): Promise<CaughtUp> {\n const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return { failure: settled(classified) };\n const scope = parseSiteBootstrap(answer.body);\n if (scope === null) return { failure: UNCERTAIN };\n if (roomVersion(scope) === roomVersion(entry)) return { scope };\n const found = await enumeration(entry, scope);\n if ('kind' in found) return { failure: settled(found) };\n const view = found.authorities.find((held) => held.authority === entry.authority);\n if (view === undefined)\n return { failure: { kind: 'room-not-readable', locator: entry.locator } };\n return { scope: advancedScope(scope, view) };\n }\n\n async function refreshed(entry: SiteTracked, fromRoomVersion: string): Promise<RefreshResult> {\n const from = logPosition(fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (streamed !== null) return streamed;\n const found = await enumeration(entry, from);\n if ('kind' in found) return found;\n return refreshFrom(found, entry, fromRoomVersion);\n }\n\n async function acquire(entry: SiteTracked, held: CaughtUp): Promise<HeldModel> {\n if ('failure' in held) return { snapshot: failedModel(held.failure), identity: null };\n const model = await heldModel(\n schemaOf(held.scope, entry.schema),\n schemaPath(entry.handle, entry.schema),\n MODEL_ABSENT,\n );\n acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });\n return model;\n }\n\n return {\n async authorize() {\n return {};\n },\n\n async model(_authorization, request): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(): Promise<DiscoverResult> {\n const answer = await transport.read(SITE_DOOR_DISCOVER);\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseSiteDiscovery(answer.body);\n if (document === null) return UNCERTAIN;\n const entries = siteTracked(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const published = new Set(entries.map((entry) => entry.authority));\n for (const authority of [...acquired.keys()]) {\n if (!published.has(authority)) acquired.delete(authority);\n }\n const fresh = new Map<string, CaughtUp>();\n const current = new Map<string, HeldModel>();\n for (const entry of entries) {\n const kept = acquired.get(entry.authority);\n if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {\n current.set(entry.authority, kept.model);\n continue;\n }\n const held = await caughtUp(entry);\n fresh.set(entry.authority, held);\n current.set(entry.authority, await acquire(entry, held));\n }\n caught = fresh;\n const rooms = entries.map((entry) => {\n const shelved = models.retain(\n modelKey(entry.locator, 'collection'),\n current.get(entry.authority),\n );\n return siteRoom(entry, shelved?.identity ?? null);\n });\n models.keep(entries.map((entry) => entry.locator));\n return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };\n },\n\n async bootstrap(_authorization, request): Promise<BootstrapResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const held = caught.get(entry.authority) ?? (await caughtUp(entry));\n if ('failure' in held) return held.failure;\n return bootstrapOf(held.scope, entry);\n },\n\n async refresh(_authorization, request): Promise<RefreshResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const result = await refreshed(entry, request.fromRoomVersion);\n if (result.kind === 'beyond-horizon') caught.delete(entry.authority);\n const answered =\n result.kind === 'net-advancement'\n ? result.roomVersion\n : result.kind === 'still-current'\n ? request.fromRoomVersion\n : null;\n if (\n request.minPosition !== undefined &&\n answered !== null &&\n !reachedVersion(answered, request.minPosition, entry.logEpoch)\n ) {\n return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };\n }\n return result;\n },\n\n async mutate() {\n return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };\n },\n\n async history() {\n return { kind: 'no-history' };\n },\n\n reached(locator, version, target) {\n return reachedVersion(version, target, tracked.get(locator)?.logEpoch);\n },\n\n async action(_authorization, request) {\n if (request.name !== 'submit') {\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };\n }\n if (!transport.online()) return UNCERTAIN;\n return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');\n },\n\n roomVersions: notifications,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["actionOutcome","UNTYPED_FOLDERS","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","bootstrapOf","parseEnumeration","parseSiteBootstrap","refreshFrom","schemaOf","schemaPath","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","name","handle","locator","operations","read","sync","write","delete","replica","selection","admission","untypedFolders","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","behind","body","code","classified","status","caughtUp","failure","scope","found","view","authorities","find","held","undefined","refreshed","fromRoomVersion","streamed","advance","acquire","snapshot","identity","model","schema","set","authorize","_authorization","request","discover","document","entries","clear","track","published","Set","map","keys","has","fresh","current","kept","get","rooms","shelved","retain","keep","slots","bootstrap","pageToken","refresh","result","answered","minPosition","logEpoch","fields","mutate","affected","history","reached","version","target","action","online","input","roomVersions","serviceMode"],"mappings":"AAUA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACEC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,SAAS,EACTC,WAAW,QAEN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SACEC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,kBAAkB,EAClBC,WAAW,EACXC,Q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J,MAAM;oBAAYmC,MAAM;oBAAwBmD,QAAQ;wBAAElF,MAAMuD,QAAQvD,IAAI;oBAAC;gBAAE;YAC1F;YACA,IAAI,CAACgB,UAAU0E,MAAM,IAAI,OAAO/F;YAChC,OAAOhC,cAAc,MAAMqD,UAAUU,IAAI,CAACpC,kBAAkBiE,QAAQoC,KAAK,GAAG;QAC9E;QAEAC,cAAc3E;QACd4E,aAAa5E,cAAc4E,WAAW;IACxC;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/site.ts"],"sourcesContent":["import type {\n Adapter,\n AdapterFailure,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n ModelResult,\n RefreshResult,\n RetryableRefusal,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\n UNTYPED_FOLDERS,\n mapDiscovery,\n parseSiteDiscovery,\n siteCapabilities,\n siteSlots,\n siteTracked,\n type SiteTracked,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport {\n advancedScope,\n bootstrapOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\n schemaOf,\n schemaPath,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n PRIVATE_LOCATOR,\n SITE_DOOR_BOOTSTRAP,\n SITE_DOOR_DISCOVER,\n SITE_DOOR_ENUMERATE,\n SITE_DOOR_SUBMIT,\n type HouseSiteTransport,\n} from './transport.js';\nimport {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\ntype Refused = AdapterFailure | RetryableRefusal | { kind: 'beyond-horizon' };\n\ntype CaughtUp = { scope: HouseScope } | { failure: AdapterFailure };\n\ntype Acquired = { roomVersion: string; model: HeldModel };\n\nconst UNCERTAIN = { kind: 'transport-uncertainty' } as const;\n\nfunction siteRoom(\n tracked: SiteTracked,\n attachedModel: DiscoveredRoom['attachedModel'],\n): DiscoveredRoom {\n return {\n name: tracked.handle,\n locator: tracked.locator,\n roomVersion: roomVersion(tracked),\n operations: { read: [''], sync: [''], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n untypedFolders: [...UNTYPED_FOLDERS],\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' || refused.kind === 'retryable-refusal'\n ? UNCERTAIN\n : refused;\n}\n\nexport function createSiteAdapter(transport: HouseSiteTransport): Adapter {\n const notifications = houseNotifications(transport, 'site');\n const tracked = new Map<string, SiteTracked>();\n const models = modelShelf();\n const acquired = new Map<string, Acquired>();\n let caught = new Map<string, CaughtUp>();\n\n async function enumeration(\n entry: SiteTracked,\n from: LogPosition,\n ): Promise<HouseEnumeration | Refused> {\n const answer = await transport.door(SITE_DOOR_ENUMERATE, {\n positions: [presented(entry.authority, from)],\n });\n const behind = doorRefusal(answer.body);\n if (behind?.code === 'replica_behind') return { kind: 'retryable-refusal', ...behind };\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;\n }\n\n async function caughtUp(entry: SiteTracked): Promise<CaughtUp> {\n const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return { failure: settled(classified) };\n const scope = parseSiteBootstrap(answer.body);\n if (scope === null) return { failure: UNCERTAIN };\n if (roomVersion(scope) === roomVersion(entry)) return { scope };\n const found = await enumeration(entry, scope);\n if ('kind' in found) return { failure: settled(found) };\n const view = found.authorities.find((held) => held.authority === entry.authority);\n if (view === undefined)\n return { failure: { kind: 'room-not-readable', locator: entry.locator } };\n return { scope: advancedScope(scope, view) };\n }\n\n async function refreshed(entry: SiteTracked, fromRoomVersion: string): Promise<RefreshResult> {\n const from = logPosition(fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from, null);\n if (streamed !== null) return streamed;\n const found = await enumeration(entry, from);\n if ('kind' in found) return found;\n return refreshFrom(found, entry, fromRoomVersion);\n }\n\n async function acquire(entry: SiteTracked, held: CaughtUp): Promise<HeldModel> {\n if ('failure' in held) return { snapshot: failedModel(held.failure), identity: null };\n const model = await heldModel(\n schemaOf(held.scope, entry.schema),\n schemaPath(entry.handle, entry.schema),\n MODEL_ABSENT,\n );\n acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });\n return model;\n }\n\n return {\n async authorize() {\n return {};\n },\n\n async model(_authorization, request): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(): Promise<DiscoverResult> {\n const answer = await transport.read(SITE_DOOR_DISCOVER);\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseSiteDiscovery(answer.body);\n if (document === null) return UNCERTAIN;\n const entries = siteTracked(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const published = new Set(entries.map((entry) => entry.authority));\n for (const authority of [...acquired.keys()]) {\n if (!published.has(authority)) acquired.delete(authority);\n }\n const fresh = new Map<string, CaughtUp>();\n const current = new Map<string, HeldModel>();\n for (const entry of entries) {\n const kept = acquired.get(entry.authority);\n if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {\n current.set(entry.authority, kept.model);\n continue;\n }\n const held = await caughtUp(entry);\n fresh.set(entry.authority, held);\n current.set(entry.authority, await acquire(entry, held));\n }\n caught = fresh;\n const rooms = entries.map((entry) => {\n const shelved = models.retain(\n modelKey(entry.locator, 'collection'),\n current.get(entry.authority),\n );\n return siteRoom(entry, shelved?.identity ?? null);\n });\n models.keep(entries.map((entry) => entry.locator));\n return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };\n },\n\n async bootstrap(_authorization, request): Promise<BootstrapResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const held = caught.get(entry.authority) ?? (await caughtUp(entry));\n if ('failure' in held) return held.failure;\n return bootstrapOf(held.scope, entry);\n },\n\n async refresh(_authorization, request): Promise<RefreshResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const result = await refreshed(entry, request.fromRoomVersion);\n if (result.kind === 'beyond-horizon') caught.delete(entry.authority);\n const answered =\n result.kind === 'net-advancement'\n ? result.roomVersion\n : result.kind === 'still-current'\n ? request.fromRoomVersion\n : null;\n if (\n request.minPosition !== undefined &&\n answered !== null &&\n !reachedVersion(answered, request.minPosition, entry.logEpoch)\n ) {\n return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };\n }\n return result;\n },\n\n async mutate() {\n return { kind: 'rejected', affected: {}, code: 'write-grant', fields: {} };\n },\n\n async history() {\n return { kind: 'no-history' };\n },\n\n reached(locator, version, target) {\n return reachedVersion(version, target, tracked.get(locator)?.logEpoch);\n },\n\n async action(_authorization, request) {\n if (request.name !== 'submit') {\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };\n }\n if (!transport.online()) return UNCERTAIN;\n return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');\n },\n\n roomVersions: notifications,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["actionOutcome","UNTYPED_FOLDERS","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","bootstrapOf","parseEnumeration","parseSiteBootstrap","refreshFrom","schemaOf","schemaPath","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","name","handle","locator","operations","read","sync","write","delete","replica","selection","admission","untypedFolders","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","behind","body","code","classified","status","caughtUp","failure","scope","found","view","authorities","find","held","undefined","refreshed","fromRoomVersion","streamed","advance","acquire","snapshot","identity","model","schema","set","authorize","_authorization","request","discover","document","entries","clear","track","published","Set","map","keys","has","fresh","current","kept","get","rooms","shelved","retain","keep","slots","bootstrap","pageToken","refresh","result","answered","minPosition","logEpoch","fields","mutate","affected","history","reached","version","target","action","online","input","roomVersions","serviceMode"],"mappings":"AAUA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACEC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,SAAS,EACTC,WAAW,QAEN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SACEC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,kBAAkB,EAClBC,WAAW,EACXC,QAAQ,EACRC,UAAU,QAGL,YAAY;AACnB,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ,eAAe;AAC3E,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,eAAe,EACfC,mBAAmB,EACnBC,kBAAkB,EAClBC,mBAAmB,EACnBC,gBAAgB,QAEX,iBAAiB;AACxB,SACEC,WAAW,EACXC,SAAS,EACTC,cAAc,EACdC,WAAW,QAEN,eAAe;AAQtB,MAAMC,YAAY;IAAEC,MAAM;AAAwB;AAElD,SAASC,SACPC,OAAoB,EACpBC,aAA8C;IAE9C,OAAO;QACLC,MAAMF,QAAQG,MAAM;QACpBC,SAASJ,QAAQI,OAAO;QACxBR,aA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,IAAI,KAAK,kBAAkByB,OAAOd,MAAM,CAACgB,MAAMK,SAAS;YACnE,MAAMmD,WACJD,OAAOlF,IAAI,KAAK,oBACZkF,OAAOpF,WAAW,GAClBoF,OAAOlF,IAAI,KAAK,kBACd2D,QAAQX,eAAe,GACvB;YACR,IACEW,QAAQyB,WAAW,KAAKtC,aACxBqC,aAAa,QACb,CAACtF,eAAesF,UAAUxB,QAAQyB,WAAW,EAAEzD,MAAM0D,QAAQ,GAC7D;gBACA,OAAO;oBAAErF,MAAM;oBAAqBmC,MAAM;oBAAkBmD,QAAQ,CAAC;gBAAE;YACzE;YACA,OAAOJ;QACT;QAEA,MAAMK;YACJ,OAAO;gBAAEvF,MAAM;gBAAYwF,UAAU,CAAC;gBAAGrD,MAAM;gBAAemD,QAAQ,CAAC;YAAE;QAC3E;QAEA,MAAMG;YACJ,OAAO;gBAAEzF,MAAM;YAAa;QAC9B;QAEA0F,SAAQpF,OAAO,EAAEqF,OAAO,EAAEC,MAAM;YAC9B,OAAO/F,eAAe8F,SAASC,QAAQ1F,QAAQuE,GAAG,CAACnE,UAAU+E;QAC/D;QAEA,MAAMQ,QAAOnC,cAAc,EAAEC,OAAO;YAClC,IAAIA,QAAQvD,IAAI,KAAK,UAAU;gBAC7B,OAAO;oBAAEJ,MAAM;oBAAYmC,MAAM;oBAAwBmD,QAAQ;wBAAElF,MAAMuD,QAAQvD,IAAI;oBAAC;gBAAE;YAC1F;YACA,IAAI,CAACgB,UAAU0E,MAAM,IAAI,OAAO/F;YAChC,OAAOhC,cAAc,MAAMqD,UAAUU,IAAI,CAACpC,kBAAkBiE,QAAQoC,KAAK,GAAG;QAC9E;QAEAC,cAAc3E;QACd4E,aAAa5E,cAAc4E,WAAW;IACxC;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 {
|
|
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
|
-
advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;
|
|
7
|
+
advance(tracked: TrackedAuthority, from: LogPosition, attachments: ReadonlySet<string> | null): 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
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAsC,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAgB7D,MAAM,MAAM,kBAAkB,GAAG,aAAa,GAAG;IAC/C,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,OAAO,CACL,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,EACjB,WAAW,EAAE,WAAW,CAAC,MAAM,CAAC,GAAG,IAAI,GACtC,WAAW,GAAG,IAAI,CAAC;IACtB,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAeF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAoQ5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import { acceptedMessage
|
|
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
|
|
5
|
+
const ATTACHMENT_REFERENCE = /at_[1-9a-hjkmnp-tv-z][0-9a-hjkmnp-tv-z]*\.[0-9a-hjkmnp-tv-z]/g;
|
|
6
|
+
function mayRelink(entry, attachments) {
|
|
7
|
+
if (entry.kind === 'removed' || entry.text === undefined) return true;
|
|
8
|
+
for (const [reference] of entry.text.matchAll(ATTACHMENT_REFERENCE)){
|
|
9
|
+
if (!attachments.has(reference)) return true;
|
|
10
|
+
}
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
7
13
|
function position(value) {
|
|
8
14
|
if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
|
|
9
15
|
return BigInt(value);
|
|
@@ -17,10 +23,8 @@ export function houseNotifications(transport, mode) {
|
|
|
17
23
|
const conversationObservers = new Set();
|
|
18
24
|
const modeObservers = new Set();
|
|
19
25
|
let replicated = [];
|
|
20
|
-
let privateAuthority;
|
|
21
26
|
const live = new Set();
|
|
22
27
|
const noted = new Set();
|
|
23
|
-
const asked = new Map();
|
|
24
28
|
let listening = false;
|
|
25
29
|
let catching = false;
|
|
26
30
|
function listen() {
|
|
@@ -40,23 +44,6 @@ export function houseNotifications(transport, mode) {
|
|
|
40
44
|
note: null
|
|
41
45
|
});
|
|
42
46
|
}
|
|
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
47
|
function reopened() {
|
|
61
48
|
const gapped = new Set([
|
|
62
49
|
...replicated,
|
|
@@ -68,7 +55,6 @@ export function houseNotifications(transport, mode) {
|
|
|
68
55
|
kind: 'gap',
|
|
69
56
|
conversation
|
|
70
57
|
});
|
|
71
|
-
for (const conversation of replicated)void question(conversation);
|
|
72
58
|
}
|
|
73
59
|
function converse(frame) {
|
|
74
60
|
const conversation = frame.conversation_id;
|
|
@@ -136,6 +122,14 @@ export function houseNotifications(transport, mode) {
|
|
|
136
122
|
});
|
|
137
123
|
return;
|
|
138
124
|
}
|
|
125
|
+
if (frame.type === 'interactions') {
|
|
126
|
+
emitConversation({
|
|
127
|
+
kind: 'questions',
|
|
128
|
+
conversation,
|
|
129
|
+
questions: structuredClone(frame.interactions)
|
|
130
|
+
});
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
139
133
|
const message = acceptedMessage(frame.message);
|
|
140
134
|
if (message === null) return;
|
|
141
135
|
emitConversation({
|
|
@@ -175,20 +169,11 @@ export function houseNotifications(transport, mode) {
|
|
|
175
169
|
for (const observer of modeObservers)observer(mode);
|
|
176
170
|
return;
|
|
177
171
|
}
|
|
178
|
-
if (frame.type === 'draft' || frame.type === 'working-note' || frame.type === 'process' || frame.type === 'commands' || frame.type === 'options' || frame.type === 'message') {
|
|
172
|
+
if (frame.type === 'draft' || frame.type === 'working-note' || frame.type === 'process' || frame.type === 'commands' || frame.type === 'options' || frame.type === 'interactions' || frame.type === 'message') {
|
|
179
173
|
converse(frame);
|
|
180
174
|
return;
|
|
181
175
|
}
|
|
182
176
|
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
177
|
const at = position(frame.position);
|
|
193
178
|
if (at === null) {
|
|
194
179
|
interrupt(frame.authority);
|
|
@@ -233,16 +218,11 @@ export function houseNotifications(transport, mode) {
|
|
|
233
218
|
};
|
|
234
219
|
}
|
|
235
220
|
},
|
|
236
|
-
question (conversation) {
|
|
237
|
-
void question(conversation);
|
|
238
|
-
},
|
|
239
221
|
conversations: {
|
|
240
222
|
replicate (next) {
|
|
241
|
-
const entering = next.filter((conversation)=>!replicated.includes(conversation));
|
|
242
223
|
replicated = [
|
|
243
224
|
...next
|
|
244
225
|
];
|
|
245
|
-
for (const conversation of entering)void question(conversation);
|
|
246
226
|
},
|
|
247
227
|
observe (notify) {
|
|
248
228
|
conversationObservers.add(notify);
|
|
@@ -259,7 +239,6 @@ export function houseNotifications(transport, mode) {
|
|
|
259
239
|
track (entries) {
|
|
260
240
|
locators.clear();
|
|
261
241
|
schemas.clear();
|
|
262
|
-
privateAuthority = entries.find((entry)=>entry.locator === PRIVATE_LOCATOR)?.authority;
|
|
263
242
|
for (const entry of entries){
|
|
264
243
|
locators.set(entry.authority, [
|
|
265
244
|
...locators.get(entry.authority) ?? [],
|
|
@@ -285,7 +264,7 @@ export function houseNotifications(transport, mode) {
|
|
|
285
264
|
observers.delete(notify);
|
|
286
265
|
};
|
|
287
266
|
},
|
|
288
|
-
advance (tracked, from) {
|
|
267
|
+
advance (tracked, from, attachments) {
|
|
289
268
|
const line = lines.get(tracked.authority);
|
|
290
269
|
const start = position(from.position);
|
|
291
270
|
if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;
|
|
@@ -298,6 +277,7 @@ export function houseNotifications(transport, mode) {
|
|
|
298
277
|
const removals = [];
|
|
299
278
|
for (const frame of pending){
|
|
300
279
|
for (const entry of frame.entries){
|
|
280
|
+
if (attachments !== null && mayRelink(entry, attachments)) return null;
|
|
301
281
|
if (!selects(tracked, entry.path)) continue;
|
|
302
282
|
if (entry.kind === 'removed') {
|
|
303
283
|
delete documents[entry.path];
|
package/dist/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n 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,qBAAqB;AAE3B,MAAMC,oBAAoB;AAoB1B,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,IAAIC;IACJ,MAAMC,OAAO,IAAIL;IACjB,MAAMM,QAAQ,IAAIN;IAClB,MAAMO,QAAQ,IAAIX;IAClB,IAAIY,YAAY;IAChB,IAAIC,WAAW;IAEf,SAASC;QACP,IAAIF,WAAW;QACfA,YAAY;QACZd,OAAOiB,OAAO,CAACC;IACjB;IAEA,SAASC,iBAAiBC,KAAwB;QAChD,IAAIA,MAAMC,IAAI,KAAK,SAASD,MAAMC,IAAI,KAAK,oBAAoBV,KAAKW,GAAG,CAACF,MAA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,CAACjC,MAAMI,IAAI,CAAC;yBAC7C6B,OAAO,CAACjC,MAAMI,IAAI,CAAC,GAAGiC;oBAC3B,MAAMC,UAAUJ,SAASK,OAAO,CAACvC,MAAMI,IAAI;oBAC3C,IAAIkC,YAAY,CAAC,GAAGJ,SAASM,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAMhC,OAAOuB,QAAQvC,EAAE,CAAC,CAAC;YACzB,IAAIgB,SAASV,WAAW,OAAO;YAC/BpE,MAAM8B,GAAG,CAACmE,QAAQpC,SAAS,EAAE;gBAAEQ,UAAUF,KAAKE,QAAQ;gBAAEC,QAAQ+B;YAAQ;YACxE,OAAO;gBACLjF,MAAM;gBACN/B,aAAaA,YAAY;oBAAEG,UAAUsF,KAAKtF,QAAQ,CAACyH,QAAQ;oBAAI5C,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\nconst ATTACHMENT_REFERENCE = /at_[1-9a-hjkmnp-tv-z][0-9a-hjkmnp-tv-z]*\\.[0-9a-hjkmnp-tv-z]/g;\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(\n tracked: TrackedAuthority,\n from: LogPosition,\n attachments: ReadonlySet<string> | null,\n ): RefreshPage | null;\n conversations: ConversationStream;\n serviceMode: ServiceModeSignal;\n};\n\nfunction mayRelink(entry: HouseStreamEntry, attachments: ReadonlySet<string>): boolean {\n if (entry.kind === 'removed' || entry.text === undefined) return true;\n for (const [reference] of entry.text.matchAll(ATTACHMENT_REFERENCE)) {\n if (!attachments.has(reference)) return true;\n }\n return false;\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, attachments) {\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 (attachments !== null && mayRelink(entry, attachments)) return null;\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","ATTACHMENT_REFERENCE","mayRelink","entry","attachments","kind","text","undefined","reference","matchAll","has","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","add","conversation","observer","unnote","delete","note","reopened","gapped","clear","converse","frame","conversation_id","type","turn","turn_id","plan","structuredClone","steps","noteId","note_id","running","commands","options","questions","interactions","message","role","announce","authority","at","modelChanged","version","locator","get","interrupt","line","set","logEpoch","frames","service_mode","log_epoch","last","continued","next","entries","length","addresses","some","includes","path","serviceMode","notify","conversations","replicate","opened","track","keys","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;AAE3B,MAAMC,u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CkB,OAAO,CAACrG,MAAMmF,IAAI,CAAC,GAAGsB;oBAC3B,MAAMC,UAAUJ,SAASK,OAAO,CAAC3G,MAAMmF,IAAI;oBAC3C,IAAIuB,YAAY,CAAC,GAAGJ,SAASM,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAM/B,OAAOsB,QAAQlC,EAAE,CAAC,CAAC;YACzB,IAAIY,SAASvE,WAAW,OAAO;YAC/BY,MAAMsD,GAAG,CAACuB,QAAQ/B,SAAS,EAAE;gBAAES,UAAUF,KAAKE,QAAQ;gBAAEC,QAAQyB;YAAQ;YACxE,OAAO;gBACL/F,MAAM;gBACNN,aAAaA,YAAY;oBAAEY,UAAUmE,KAAKnE,QAAQ,CAACqG,QAAQ;oBAAItC,UAAUF,KAAKE,QAAQ;gBAAC;gBACvF4B;gBACAC;gBACAC;gBACAS,eAAe,EAAE;gBACjBR,UAAUA,SAASS,IAAI;YACzB;QACF;IACF;AACF"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -61,6 +61,10 @@ export type HouseStreamFrame = {
|
|
|
61
61
|
type: 'message';
|
|
62
62
|
conversation_id: string;
|
|
63
63
|
message: unknown;
|
|
64
|
+
} | {
|
|
65
|
+
type: 'interactions';
|
|
66
|
+
conversation_id: string;
|
|
67
|
+
interactions: readonly unknown[];
|
|
64
68
|
} | {
|
|
65
69
|
type: 'working-note';
|
|
66
70
|
conversation_id: string;
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAEhE,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,i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Ae,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAC,SAAS,CAAC,CAAA;CAAE,GACrF;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAE7C,MAAM,MAAM,WAAW,GAAG;IACxB,OAAO,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;IAChE,MAAM,CAAC,MAAM,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACtB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7D,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,SAAS,GAAG;IACvC,QAAQ,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAChE,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG;IAC3C,MAAM,IAAI,OAAO,CAAC;IAClB,IAAI,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;CAC/C,CAAC"}
|
package/dist/transport.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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: '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"}
|
|
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.
|
|
3
|
+
"version": "0.1.0-alpha.47",
|
|
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.
|
|
29
|
+
"@agentshouse/mdruntime": "0.1.0-alpha.49"
|
|
30
30
|
}
|
|
31
31
|
}
|