@agentshouse/mdruntime-adapter 0.1.0-alpha.15 → 0.1.0-alpha.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ViewedConversations,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome, HISTORY_PAGE, readConversationHistory } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport { PRIVATE_AUTHORITY, type HouseDoor, type HouseStreamAuthority } from './transport.js';\nimport type { HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;\n conversations: ViewedConversations;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nfunction messageTurn(message: unknown): string | null {\n if (typeof message !== 'object' || message === null) return null;\n const turn = (message as { message_id?: unknown }).message_id;\n return typeof turn === 'string' ? turn : null;\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const authorities = new Map<string, string>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const subscribedConversations = new Set<string>();\n let selected: readonly string[] = [];\n let viewed: readonly string[] = [];\n let listening = false;\n\n function subscribe() {\n const named: HouseStreamAuthority[] = [];\n const rooms = new Set<string>();\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined || authority === PRIVATE_AUTHORITY) continue;\n rooms.add(authority);\n }\n for (const room of rooms) named.push({ kind: 'room', room });\n if (authorities.has(PRIVATE_AUTHORITY)) named.push({ kind: 'private' });\n for (const conversation of viewed) {\n named.push({ kind: 'conversation', conversation });\n }\n stream.subscribe(named);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (!viewed.includes(event.conversation)) return;\n for (const observer of conversationObservers) observer(event);\n }\n\n async function catchUp(conversation: string, history: boolean) {\n const viewedAnswer = await transport.door('/door/conversations/view', {\n conversation_id: conversation,\n });\n const summary = actionOutcome(viewedAnswer, 'conversations/view');\n if (\n summary.kind === 'action' &&\n typeof summary.result === 'object' &&\n summary.result !== null\n ) {\n emitConversation({\n kind: 'session-summary',\n conversation,\n summary: structuredClone('session' in summary.result ? summary.result.session : null),\n });\n }\n if (!history) return;\n const heldHistory = await readConversationHistory(transport, conversation);\n if ('outcome' in heldHistory) return;\n const newest = heldHistory.messages.slice(-HISTORY_PAGE);\n for (const entry of newest) {\n const turn = messageTurn(entry);\n if (turn === null) return;\n emitConversation({\n kind: 'accepted-message',\n conversation,\n message: { turn, message: structuredClone(entry) },\n });\n }\n }\n\n function announce(authority: string, at: LogPosition) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) observer({ locator, roomVersion: version });\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function resubscribed(authority: string, position?: string, logEpoch?: string) {\n if (position === undefined || logEpoch === undefined) {\n interrupt(authority);\n return;\n }\n const held = lines.get(authority)?.logEpoch;\n lines.set(authority, { logEpoch, frames: [] });\n if (held !== logEpoch) announce(authority, { position, logEpoch });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'draft') {\n emitConversation({\n kind: 'growing-text',\n conversation: frame.conversation_id,\n turn: frame.turn_id,\n text: frame.text,\n });\n return;\n }\n if (frame.type === 'message') {\n const turn = messageTurn(frame.message);\n if (turn === null) return;\n emitConversation({\n kind: 'accepted-message',\n conversation: frame.conversation_id,\n message: { turn, message: structuredClone(frame.message) },\n });\n return;\n }\n if (frame.type === 'session') {\n emitConversation({\n kind: 'session-summary',\n conversation: frame.conversation_id,\n summary: structuredClone(frame.summary),\n });\n return;\n }\n if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {\n const reconnect = subscribedConversations.has(frame.authority);\n subscribedConversations.add(frame.authority);\n void catchUp(frame.authority, reconnect);\n return;\n }\n if (frame.type === 'subscribed') {\n resubscribed(frame.authority, frame.position, frame.log_epoch);\n return;\n }\n if (frame.type !== 'entries') {\n interrupt(frame.authority);\n return;\n }\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });\n }\n\n return {\n conversations: {\n view(next) {\n const open = new Set(next);\n for (const conversation of subscribedConversations) {\n if (!open.has(conversation)) subscribedConversations.delete(conversation);\n }\n viewed = [...next];\n subscribe();\n },\n observe(notify) {\n conversationObservers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n authorities.clear();\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n authorities.set(entry.locator, entry.authority);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select(named) {\n selected = [...named];\n subscribe();\n },\n observe(notify) {\n observers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),\n documents,\n revisions,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["actionOutcome","HISTORY_PAGE","readConversationHistory","selects","PRIVATE_AUTHORITY","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","messageTurn","message","turn","message_id","houseNotifications","transport","mode","stream","lines","Map","locators","authorities","observers","Set","conversationObservers","subscribedConversations","selected","viewed","listening","subscribe","named","rooms","locator","authority","get","undefined","add","room","push","kind","has","conversation","emitConversation","event","includes","observer","catchUp","history","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","heldHistory","newest","messages","slice","entry","announce","at","version","interrupt","line","set","logEpoch","frames","resubscribed","held","receive","frame","type","turn_id","text","reconnect","log_epoch","last","continued","next","entries","length","conversations","view","open","delete","observe","notify","track","clear","keys","select","advance","tracked","from","start","findIndex","pending","documents","revisions","removals","path","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AAOA,SAASA,aAAa,EAAEC,YAAY,EAAEC,uBAAuB,QAAQ,eAAe;AAEpF,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,iBAAiB,QAAmD,iBAAiB;AAE9F,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAkB3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,SAASG,YAAYC,OAAgB;IACnC,IAAI,OAAOA,YAAY,YAAYA,YAAY,MAAM,OAAO;IAC5D,MAAMC,OAAO,AAACD,QAAqCE,UAAU;IAC7D,OAAO,OAAOD,SAAS,WAAWA,OAAO;AAC3C;AAEA,OAAO,SAASE,mBAAmBC,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IAAIC;IAClB,MAAMC,WAAW,IAAID;IACrB,MAAME,cAAc,IAAIF;IACxB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,MAAME,0BAA0B,IAAIF;IACpC,IAAIG,WAA8B,EAAE;IACpC,IAAIC,SAA4B,EAAE;IAClC,IAAIC,YAAY;IAEhB,SAASC;QACP,MAAMC,QAAgC,EAAE;QACxC,MAAMC,QAAQ,IAAIR;QAClB,KAAK,MAAMS,WAAWN,SAAU;YAC9B,MAAMO,YAAYZ,YAAYa,GAAG,CAACF;YAClC,IAAIC,cAAcE,aAAaF,cAAc9B,mBAAmB;YAChE4B,MAAMK,GAAG,CAACH;Q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,KAAKnE,WAAW,OAAO;oBAClE+D,SAAS,CAACvC,MAAM0C,IAAI,CAAC,GAAG1C,MAAMe,IAAI;oBAClC,IAAIf,MAAM2C,QAAQ,KAAKnE,WAAWgE,SAAS,CAACxC,MAAM0C,IAAI,CAAC,GAAG1C,MAAM2C,QAAQ;oBACxE,MAAMC,UAAUH,SAASI,OAAO,CAAC7C,MAAM0C,IAAI;oBAC3C,IAAIE,YAAY,CAAC,GAAGH,SAASK,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAM1B,OAAOoB,QAAQpC,EAAE,CAAC,CAAC;YACzB,IAAIgB,SAAS1C,WAAW,OAAO;YAC/BjB,MAAM+C,GAAG,CAAC4B,QAAQ5D,SAAS,EAAE;gBAAEiC,UAAUF,KAAKE,QAAQ;gBAAEC,QAAQ8B;YAAQ;YACxE,OAAO;gBACL1D,MAAM;gBACNnC,aAAaA,YAAY;oBAAEE,UAAUuE,KAAKvE,QAAQ,CAACoG,QAAQ;oBAAIxC,UAAUF,KAAKE,QAAQ;gBAAC;gBACvFgC;gBACAC;gBACAQ,eAAe,EAAE;gBACjBP,UAAUA,SAASQ,IAAI;YACzB;QACF;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n ConversationStream,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage, actionOutcome } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport type { HouseDoor, HouseStreamAuthority } from './transport.js';\nimport type { HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;\n conversations: ConversationStream;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const authorities = new Map<string, string>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n let selected: readonly string[] = [];\n let replicated: readonly string[] = [];\n let viewed: readonly string[] = [];\n let listening = false;\n\n function subscribe() {\n const named: HouseStreamAuthority[] = [];\n const rooms = new Set<string>();\n for (const locator of selected) {\n const authority = authorities.get(locator);\n if (authority === undefined) continue;\n rooms.add(authority);\n }\n for (const room of rooms) named.push({ kind: 'room', room });\n for (const conversation of viewed) {\n named.push({ kind: 'conversation', conversation });\n }\n stream.subscribe(named);\n }\n\n function emitConversation(event: ConversationEvent) {\n const delivered =\n event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;\n if (!delivered.includes(event.conversation)) return;\n for (const observer of conversationObservers) observer(event);\n }\n\n async function summarize(conversation: string) {\n const viewedAnswer = await transport.door('/door/conversations/view', {\n conversation_id: conversation,\n });\n const summary = actionOutcome(viewedAnswer, 'conversations/view');\n if (\n summary.kind === 'action' &&\n typeof summary.result === 'object' &&\n summary.result !== null\n ) {\n emitConversation({\n kind: 'session-summary',\n conversation,\n summary: structuredClone('session' in summary.result ? summary.result.session : null),\n });\n }\n }\n\n function announce(authority: string, at: LogPosition) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) observer({ locator, roomVersion: version });\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function resubscribed(authority: string, position?: string, logEpoch?: string) {\n if (position === undefined || logEpoch === undefined) {\n interrupt(authority);\n return;\n }\n const held = lines.get(authority)?.logEpoch;\n lines.set(authority, { logEpoch, frames: [] });\n if (held !== logEpoch) announce(authority, { position, logEpoch });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'draft') {\n emitConversation({\n kind: 'growing-text',\n conversation: frame.conversation_id,\n turn: frame.turn_id,\n text: frame.text,\n });\n return;\n }\n if (frame.type === 'message') {\n const message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation: frame.conversation_id, message });\n return;\n }\n if (frame.type === 'session') {\n emitConversation({\n kind: 'session-summary',\n conversation: frame.conversation_id,\n summary: structuredClone(frame.summary),\n });\n return;\n }\n if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {\n emitConversation({ kind: 'gap', conversation: frame.authority });\n void summarize(frame.authority);\n return;\n }\n if (frame.type === 'subscribed') {\n resubscribed(frame.authority, frame.position, frame.log_epoch);\n return;\n }\n if (frame.type !== 'entries') {\n interrupt(frame.authority);\n return;\n }\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n announce(frame.authority, { position: frame.position, logEpoch: frame.log_epoch });\n }\n\n return {\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n view(next) {\n viewed = [...next];\n subscribe();\n },\n observe(notify) {\n conversationObservers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n authorities.clear();\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n authorities.set(entry.locator, entry.authority);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select(named) {\n selected = [...named];\n subscribe();\n },\n observe(notify) {\n observers.add(notify);\n if (!listening) {\n listening = true;\n stream.observe(receive);\n }\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),\n documents,\n revisions,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["acceptedMessage","actionOutcome","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","authorities","observers","Set","conversationObservers","selected","replicated","viewed","listening","subscribe","named","rooms","locator","authority","get","undefined","add","room","push","kind","conversation","emitConversation","event","delivered","includes","observer","summarize","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","announce","at","version","interrupt","line","set","logEpoch","frames","resubscribed","held","receive","frame","type","turn","turn_id","text","message","log_epoch","last","continued","next","entries","length","conversations","replicate","view","observe","notify","delete","track","clear","entry","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","removals","path","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AAOA,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAe;AAE9D,SAASC,OAAO,QAAQ,YAAY;AAGpC,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAkB3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,OAAO,SAASG,mBAAmBC,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IAAIC;IAClB,MAAMC,WAAW,IAAID;IACrB,MAAME,cAAc,IAAIF;IACxB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,IAAIE,WAA8B,EAAE;IACpC,IAAIC,aAAgC,EAAE;IACtC,IAAIC,SAA4B,EAAE;IAClC,IAAIC,YAAY;IAEhB,SAASC;QACP,MAAMC,QAAgC,EAAE;QACxC,MAAMC,QAAQ,IAAIR;QAClB,KAAK,MAAMS,WAAWP,SAAU;YAC9B,MAAMQ,YAAYZ,YAAYa,GAAG,CAACF;YAClC,IAAIC,cAAcE,WAAW;YAC7BJ,MAAMK,GAAG,CAACH;QACZ;QACA,KAAK,MAAMI,QAAQN,MAAOD,MAAMQ,IAAI,CAAC;YAAEC,MAAM;YAAQF;QAAK;QAC1D,KAAK,MAAMG,gBAAgBb,OAAQ;YACjCG,MAAMQ,IAAI,CAAC;gBAAEC,MAAM;gBAAgBC;YAAa;QAClD;QACAvB,OA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8
8
  export declare const SITE_DOOR_BOOTSTRAP = "/_house/door/bootstrap/";
9
9
  export declare const SITE_DOOR_ENUMERATE = "/_house/door/enumerate";
10
10
  export declare const SITE_DOOR_SUBMIT = "/_house/door/submit";
11
- export declare const PRIVATE_AUTHORITY = "private";
11
+ export declare const PRIVATE_LOCATOR = "private";
12
12
  export type HouseMode = 'credential' | 'site';
13
13
  export type HouseDoorAnswer = {
14
14
  status: number;
@@ -26,8 +26,6 @@ export type HouseByteTransfer = {
26
26
  export type HouseStreamAuthority = {
27
27
  kind: 'room';
28
28
  room: string;
29
- } | {
30
- kind: 'private';
31
29
  } | {
32
30
  kind: 'conversation';
33
31
  conversation: string;
@@ -1 +1 @@
1
- {"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAE9C,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAExC,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AAEtD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAE7D,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAE5D,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAE3C,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB,qBAAqB,GACrB,uBAAuB,GACvB,8BAA8B,CAAC;AAEnC,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,WAAW,GA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AE,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 CHANGED
@@ -8,6 +8,6 @@ export const SITE_DOOR_DISCOVER = '/_house/door/discover';
8
8
  export const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';
9
9
  export const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';
10
10
  export const SITE_DOOR_SUBMIT = '/_house/door/submit';
11
- export const PRIVATE_AUTHORITY = 'private';
11
+ export const PRIVATE_LOCATOR = 'private';
12
12
 
13
13
  //# sourceMappingURL=transport.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/transport.ts"],"sourcesContent":["export const DOOR_DISCOVER = '/door/discover';\n\nexport const DOOR_BOOTSTRAP = '/door/bootstrap';\n\nexport const DOOR_ENUMERATE = '/door/enumerate';\n\nexport const DOOR_BATCH = '/door/batch';\n\nexport const DOOR_BATCH_UPLOAD = '/door/batch-upload';\n\nexport const DOOR_REVISIONS = '/door/revisions';\n\nexport const SITE_DOOR_DISCOVER = '/_house/door/discover';\n\nexport const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';\n\nexport const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';\n\nexport const SITE_DOOR_SUBMIT = '/_house/door/submit';\n\nexport const PRIVATE_AUTHORITY = 'private';\n\nexport type HouseMode = 'credential' | 'site';\n\nexport type HouseDoorAnswer = {\n status: number;\n body: unknown;\n};\n\nexport type HouseByteAct =\n | 'working_copy_bundle'\n | 'authored_batch_upload'\n | 'conversation_original_upload';\n\nexport type HouseByteBody = string | ArrayBuffer | Uint8Array;\n\nexport type HouseByteTransfer = {\n act: HouseByteAct;\n method: 'GET' | 'POST';\n url: string;\n body?: HouseByteBody;\n operation?: string;\n};\n\nexport type HouseStreamAuthority =\n | { kind: 'room'; room: string }\n | { kind: 'private' }\n | { kind: 'conversation'; conversation: string };\n\nexport type HouseStreamEntry = {\n path: string;\n kind: 'edited' | 'removed';\n revision?: string;\n text?: string;\n};\n\nexport type HouseStreamFrame =\n | {\n type: 'entries';\n authority: string;\n position: string;\n log_epoch: string;\n entries: readonly HouseStreamEntry[];\n }\n | { type: 'subscribed'; authority: string; position?: string; log_epoch?: string }\n | { type: 'refused'; authority: string; code: string }\n | { type: 'unsubscribed'; authority: string; code?: string }\n | {\n type: 'draft';\n conversation_id: string;\n session_id: string;\n turn_id: string;\n text: string;\n }\n | { type: 'message'; conversation_id: string; message: unknown }\n | { type: 'session'; conversation_id: string; summary: unknown };\n\nexport type HouseStream = {\n subscribe(authorities: readonly HouseStreamAuthority[]): void;\n observe(receive: (frame: HouseStreamFrame) => 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_AUTHORITY"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,iBAAiB;AAE9C,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,aAAa,cAAc;AAExC,OAAO,MAAMC,oBAAoB,qBAAqB;AAEtD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,qBAAqB,wBAAwB;AAE1D,OAAO,MAAMC,sBAAsB,0BAA0B;AAE7D,OAAO,MAAMC,sBAAsB,yBAAyB;AAE5D,OAAO,MAAMC,mBAAmB,sBAAsB;AAEtD,OAAO,MAAMC,oBAAoB,UAAU"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/transport.ts"],"sourcesContent":["export const DOOR_DISCOVER = '/door/discover';\n\nexport const DOOR_BOOTSTRAP = '/door/bootstrap';\n\nexport const DOOR_ENUMERATE = '/door/enumerate';\n\nexport const DOOR_BATCH = '/door/batch';\n\nexport const DOOR_BATCH_UPLOAD = '/door/batch-upload';\n\nexport const DOOR_REVISIONS = '/door/revisions';\n\nexport const SITE_DOOR_DISCOVER = '/_house/door/discover';\n\nexport const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';\n\nexport const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';\n\nexport const SITE_DOOR_SUBMIT = '/_house/door/submit';\n\nexport const PRIVATE_LOCATOR = 'private';\n\nexport type HouseMode = 'credential' | 'site';\n\nexport type HouseDoorAnswer = {\n status: number;\n body: unknown;\n};\n\nexport type HouseByteAct =\n | 'working_copy_bundle'\n | 'authored_batch_upload'\n | 'conversation_original_upload';\n\nexport type HouseByteBody = string | ArrayBuffer | Uint8Array;\n\nexport type HouseByteTransfer = {\n act: HouseByteAct;\n method: 'GET' | 'POST';\n url: string;\n body?: HouseByteBody;\n operation?: string;\n};\n\nexport type HouseStreamAuthority =\n | { kind: 'room'; room: string }\n | { kind: 'conversation'; conversation: string };\n\nexport type HouseStreamEntry = {\n path: string;\n kind: 'edited' | 'removed';\n revision?: string;\n text?: string;\n};\n\nexport type HouseStreamFrame =\n | {\n type: 'entries';\n authority: string;\n position: string;\n log_epoch: string;\n entries: readonly HouseStreamEntry[];\n }\n | { type: 'subscribed'; authority: string; position?: string; log_epoch?: string }\n | { type: 'refused'; authority: string; code: string }\n | { type: 'unsubscribed'; authority: string; code?: string }\n | {\n type: 'draft';\n conversation_id: string;\n session_id: string;\n turn_id: string;\n text: string;\n }\n | { type: 'message'; conversation_id: string; message: unknown }\n | { type: 'session'; conversation_id: string; summary: unknown };\n\nexport type HouseStream = {\n subscribe(authorities: readonly HouseStreamAuthority[]): void;\n observe(receive: (frame: HouseStreamFrame) => 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"],"mappings":"AAAA,OAAO,MAAMA,gBAAgB,iBAAiB;AAE9C,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,aAAa,cAAc;AAExC,OAAO,MAAMC,oBAAoB,qBAAqB;AAEtD,OAAO,MAAMC,iBAAiB,kBAAkB;AAEhD,OAAO,MAAMC,qBAAqB,wBAAwB;AAE1D,OAAO,MAAMC,sBAAsB,0BAA0B;AAE7D,OAAO,MAAMC,sBAAsB,yBAAyB;AAE5D,OAAO,MAAMC,mBAAmB,sBAAsB;AAEtD,OAAO,MAAMC,kBAAkB,UAAU"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-alpha.15",
3
+ "version": "0.1.0-alpha.17",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,6 +34,6 @@
34
34
  },
35
35
  "dependencies": {
36
36
  "@agentshouse/mdmodel": "0.1.0-alpha.13",
37
- "@agentshouse/mdruntime": "0.1.0-alpha.20"
37
+ "@agentshouse/mdruntime": "0.1.0-alpha.22"
38
38
  }
39
39
  }