@agentshouse/mdruntime-adapter 0.1.0-alpha.47 → 0.1.0-alpha.49
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/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +40 -20
- package/dist/adapter.js.map +1 -1
- package/dist/discovery.d.ts +4 -6
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +5 -4
- package/dist/discovery.js.map +1 -1
- package/dist/links.d.ts +11 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +57 -0
- package/dist/links.js.map +1 -0
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +2 -3
- package/dist/map.js.map +1 -1
- package/dist/read.d.ts +12 -11
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +12 -24
- package/dist/read.js.map +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +10 -5
- package/dist/site.js.map +1 -1
- package/dist/stream.d.ts +6 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +14 -20
- package/dist/stream.js.map +1 -1
- package/dist/write.d.ts +3 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js.map +1 -1
- package/package.json +1 -1
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 } 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,uBAAuB;AAuB7B,SAASC,UAAUC,KAAuB,EAAEC,WAAgC;IAC1E,IAAID,MAAME,IAAI,KAAK,aAAaF,MAAMG,IAAI,KAAKC,WAAW,OAAO;IACjE,KAAK,MAAM,CAACC,UAAU,IAAIL,MAAMG,IAAI,CAACG,QAAQ,CAACR,sBAAuB;QACnE,IAAI,CAACG,YAAYM,GAAG,CAACF,YAAY,OAAO;IAC1C;IACA,OAAO;AACT;AAEA,SAASG,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,OAAO,SAASG,mBAAmBC,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IAAIC;IAClB,MAAMC,WAAW,IAAID;IACrB,MAAME,UAAU,IAAIF;IACpB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,MAAME,gBAAgB,IAAIF;IAC1B,IAAIG,aAAgC,EAAE;IACtC,MAAMC,OAAO,IAAIJ;IACjB,MAAMK,QAAQ,IAAIL;IAClB,IAAIM,YAAY;IAChB,IAAIC,WAAW;IAEf,SAASC;QACP,IAAIF,WAAW;QACfA,YAAY;QACZZ,OAAOe,OAAO,CAACC;IACjB;IAEA,SAASC,iBAAiBC,KAAwB;QAChD,IAAIA,MAAM/B,IAAI,KAAK,SAAS+B,MAAM/B,IAAI,KAAK,oBAAoBuB,KAAKS,GAAG,CAACD,MAAME,YAAY;QAC1F,KAAK,MAAMC,YAAYd,sBAAuBc,SAASH;IACzD;IAEA,SAASI,OAAOF,YAAoB;QAClC,IAA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nF,MAAMG,IAAI;oBAClC,IAAIH,MAAMwG,QAAQ,KAAKpG,WAAWgG,SAAS,CAACpG,MAAMmF,IAAI,CAAC,GAAGnF,MAAMwG,QAAQ;oBACxE,IAAIC,SAASrG,WAAW,OAAOiG,OAAO,CAACrG,MAAMmF,IAAI,CAAC;yBAC7CkB,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"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n ConversationStream,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ServiceMode,\n ServiceModeSignal,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { headChange, selects, type HeadChange } from './read.js';\nimport type { HouseDoor, HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type StreamedAdvancement = {\n page: RefreshPage;\n entries: readonly HouseStreamEntry[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): StreamedAdvancement | null;\n conversations: ConversationStream;\n serviceMode: ServiceModeSignal;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const schemas = new Map<string, readonly string[]>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const modeObservers = new Set<(mode: ServiceMode) => void>();\n let replicated: readonly string[] = [];\n const live = new Set<string>();\n const noted = new Set<string>();\n let listening = false;\n let catching = false;\n\n function listen() {\n if (listening) return;\n listening = true;\n stream.observe(receive);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (event.kind !== 'gap' && event.kind !== 'accepted-message') live.add(event.conversation);\n for (const observer of conversationObservers) observer(event);\n }\n\n function unnote(conversation: string) {\n if (!noted.delete(conversation)) return;\n emitConversation({ kind: 'working-note', conversation, note: null });\n }\n\n function reopened() {\n const gapped = new Set([...replicated, ...live]);\n live.clear();\n noted.clear();\n for (const conversation of gapped) emitConversation({ kind: 'gap', conversation });\n }\n\n function converse(frame: Exclude<HouseStreamFrame, { type: 'entries' | 'signal' }>) {\n const conversation = frame.conversation_id;\n if (frame.type === 'draft') {\n unnote(conversation);\n emitConversation({\n kind: 'growing-text',\n conversation,\n turn: frame.turn_id,\n text: frame.text,\n });\n emitConversation({\n kind: 'plan',\n conversation,\n turn: frame.turn_id,\n plan: structuredClone(frame.steps),\n });\n return;\n }\n if (frame.type === 'working-note') {\n noted.add(conversation);\n emitConversation({\n kind: 'working-note',\n conversation,\n note: { noteId: frame.note_id, text: frame.text },\n });\n return;\n }\n if (frame.type === 'process') {\n emitConversation({ kind: 'process', conversation, running: frame.running });\n if (frame.running) return;\n emitConversation({ kind: 'commands', conversation, commands: [] });\n emitConversation({ kind: 'options', conversation, options: [] });\n unnote(conversation);\n return;\n }\n if (frame.type === 'commands') {\n emitConversation({\n kind: 'commands',\n conversation,\n commands: structuredClone(frame.commands),\n });\n return;\n }\n if (frame.type === 'options') {\n emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });\n return;\n }\n if (frame.type === 'interactions') {\n emitConversation({\n kind: 'questions',\n conversation,\n questions: structuredClone(frame.interactions),\n });\n return;\n }\n const message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation, message });\n if ((frame.message as { role?: unknown }).role === 'user') return;\n unnote(conversation);\n }\n\n function announce(authority: string, at: LogPosition, modelChanged: boolean) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) {\n observer(\n modelChanged\n ? { locator, roomVersion: version, modelChanged: true }\n : { locator, roomVersion: version },\n );\n }\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'signal') {\n const mode = frame.service_mode;\n if (mode !== 'open' && mode !== 'write-halted') return;\n for (const observer of modeObservers) observer(mode);\n return;\n }\n if (\n frame.type === 'draft' ||\n frame.type === 'working-note' ||\n frame.type === 'process' ||\n frame.type === 'commands' ||\n frame.type === 'options' ||\n frame.type === 'interactions' ||\n frame.type === 'message'\n ) {\n converse(frame);\n return;\n }\n if (frame.type !== 'entries') return;\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n const addresses = schemas.get(frame.authority) ?? [];\n announce(\n frame.authority,\n { position: frame.position, logEpoch: frame.log_epoch },\n frame.entries.some((entry) => addresses.includes(entry.path)),\n );\n }\n\n return {\n serviceMode: {\n observe(notify) {\n modeObservers.add(notify);\n listen();\n return () => {\n modeObservers.delete(notify);\n };\n },\n },\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n observe(notify) {\n conversationObservers.add(notify);\n listen();\n if (!catching) {\n catching = true;\n stream.opened(reopened);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n schemas.clear();\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n schemas.set(entry.authority, entry.schemas);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select() {},\n observe(notify) {\n observers.add(notify);\n listen();\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n delete changes[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n const head = headChange(entry);\n if (head === null) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n if (head === undefined) delete changes[entry.path];\n else changes[entry.path] = head;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n page: {\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 entries: pending.flatMap((frame) => frame.entries),\n };\n },\n };\n}\n"],"names":["acceptedMessage","headChange","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","schemas","observers","Set","conversationObservers","modeObservers","replicated","live","noted","listening","catching","listen","observe","receive","emitConversation","event","kind","add","conversation","observer","unnote","delete","note","reopened","gapped","clear","converse","frame","conversation_id","type","turn","turn_id","text","plan","structuredClone","steps","noteId","note_id","running","commands","options","questions","interactions","message","role","announce","authority","at","modelChanged","version","locator","get","interrupt","line","undefined","set","logEpoch","frames","service_mode","log_epoch","last","continued","next","entries","length","addresses","some","entry","includes","path","serviceMode","notify","conversations","replicate","opened","track","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","changes","removals","push","revision","head","removed","indexOf","splice","page","toString","binaryTargets","sort","flatMap"],"mappings":"AASA,SAASA,eAAe,QAAQ,eAAe;AAE/C,SAASC,UAAU,EAAEC,OAAO,QAAyB,YAAY;AAEjE,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAwB3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,OAAO,SAASG,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oBACAC;oBACAC;oBACAU,eAAe,EAAE;oBACjBT,UAAUA,SAASU,IAAI;gBACzB;gBACApC,SAASqB,QAAQgB,OAAO,CAAC,CAACzE,QAAUA,MAAMoC,OAAO;YACnD;QACF;IACF;AACF"}
|
package/dist/write.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type ChangeMapping = {
|
|
|
11
11
|
path: string;
|
|
12
12
|
rule: string;
|
|
13
13
|
};
|
|
14
|
-
export declare function houseChanges(batch: ChangeBatch, handle: string
|
|
14
|
+
export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
|
|
15
15
|
export type OperationHead = {
|
|
16
16
|
readonly operation_id: string;
|
|
17
17
|
readonly app_ref?: string;
|
|
@@ -23,7 +23,7 @@ export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
|
23
23
|
export declare function deltaBytes(delta: string): number;
|
|
24
24
|
export declare function uploadable(bytes: number): boolean;
|
|
25
25
|
export declare function deltaDigest(delta: string): Promise<string>;
|
|
26
|
-
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string
|
|
26
|
+
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string): MutationResult;
|
|
27
27
|
export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
28
28
|
kind: 'unmapped';
|
|
29
29
|
}>): {
|
|
@@ -36,7 +36,7 @@ export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
|
36
36
|
};
|
|
37
37
|
export declare function revisionBody(input: {
|
|
38
38
|
path: string;
|
|
39
|
-
handle: string
|
|
39
|
+
handle: string;
|
|
40
40
|
revision?: string;
|
|
41
41
|
pageToken?: string;
|
|
42
42
|
}): Record<string, unknown>;
|
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,WAAW,EAEX,aAAa,EAEb,cAAc,EAEf,MAAM,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,GAC3C,aAAa,CAiDf"}
|
package/dist/write.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/write.ts"],"sourcesContent":["import type {\n Change,\n ChangeBatch,\n HistoryAuthor,\n HistoryResult,\n HistoryRevision,\n MutationResult,\n Precondition,\n} from '@agentshouse/mdruntime';\nimport { sha256Hex, textBytes } from './digest.js';\nimport { nativePath, roomLocalPath } from './map.js';\nimport { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';\nimport { readPosition, roomVersion } from './version.js';\n\nexport const INLINE_BODY_LIMIT_BYTES = 4 * 1024 * 1024;\n\nexport const UPLOAD_LINE_BYTES = 37;\n\nexport const UPLOAD_BYTES_MAX = 32 * 1024 * 1024 - UPLOAD_LINE_BYTES;\n\nexport type HouseOperation = Readonly<Record<string, unknown>>;\n\nexport type ChangeMapping =\n | { kind: 'changes'; changes: readonly HouseOperation[] }\n | { kind: 'unmapped'; path: string; rule: string };\n\ntype Existence = { base: string } | { kind: 'presence' };\n\nfunction priorField(batch: ChangeBatch, path: string, name: string) {\n return batch.preconditions.find(\n (precondition): precondition is Extract<Precondition, { kind: 'field' }> =>\n precondition.kind === 'field' && precondition.path === path && precondition.name === name,\n );\n}\n\nfunction priorSection(batch: ChangeBatch, path: string, name: string) {\n return batch.preconditions.find(\n (precondition): precondition is Extract<Precondition, { kind: 'section' }> =>\n precondition.kind === 'section' && precondition.path === path && precondition.name === name,\n );\n}\n\nfunction priorPreamble(batch: ChangeBatch, path: string) {\n return batch.preconditions.find(\n (precondition): precondition is Extract<Precondition, { kind: 'preamble' }> =>\n precondition.kind === 'preamble' && precondition.path === path,\n );\n}\n\nfunction priorAbsence(batch: ChangeBatch, path: string) {\n return batch.preconditions.find(\n (precondition) => precondition.kind === 'absent' && precondition.path === path,\n );\n}\n\nfunction priorExistence(batch: ChangeBatch, path: string): Existence | undefined {\n const precondition = batch.preconditions.find(\n (held) => held.path === path && (held.kind === 'revision' || held.kind === 'present'),\n );\n if (precondition === undefined) return undefined;\n return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };\n}\n\nfunction created(change: Extract<Change, { kind: 'create' }>, path: string): HouseOperation | null {\n if ('content' in change) return { op: 'create', path, content: change.content };\n const { type, ...fields } = change.fields;\n if (typeof type !== 'string' || type.length === 0) return null;\n return { op: 'create_typed', path, type, fields, sections: change.sections };\n}\n\ntype MappedOperation = { operation: HouseOperation } | { rule: string };\n\nfunction operationOf(\n batch: ChangeBatch,\n change: Change,\n handle: string | undefined,\n): MappedOperation {\n const path = nativePath(change.path, handle);\n if (change.kind === 'field') {\n const prior = priorField(batch, change.path, change.name);\n if (prior === undefined) return { rule: 'precondition-missing' };\n return {\n operation: {\n op: 'set_field',\n path,\n field: change.name,\n value: change.value,\n ...(prior.value === undefined ? {} : { base: prior.value }),\n },\n };\n }\n if (change.kind === 'section') {\n const prior = priorSection(batch, change.path, change.name);\n if (prior === undefined) return { rule: 'precondition-missing' };\n return {\n operation: {\n op: 'replace_section',\n path,\n section: change.name,\n base: prior.value,\n content: change.value,\n },\n };\n }\n if (change.kind === 'preamble') {\n const prior = priorPreamble(batch, change.path);\n if (prior === undefined) return { rule: 'precondition-missing' };\n return {\n operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },\n };\n }\n if (change.kind === 'create') {\n if (priorAbsence(batch, change.path) === undefined) return { rule: 'precondition-missing' };\n const operation = created(change, path);\n return operation === null ? { rule: 'type-missing' } : { operation };\n }\n const existence = priorExistence(batch, change.path);\n if (existence === undefined) return { rule: 'precondition-missing' };\n if (!('base' in existence)) return { rule: 'presence-base-unrepresentable' };\n if (change.kind === 'replace') {\n return { operation: { op: 'replace', path, base: existence.base, content: change.content } };\n }\n if (change.kind === 'move') {\n if (priorAbsence(batch, change.to) === undefined) return { rule: 'precondition-missing' };\n return {\n operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },\n };\n }\n return { operation: { op: 'remove', path, base: existence.base } };\n}\n\nexport function houseChanges(batch: ChangeBatch, handle: string | undefined): ChangeMapping {\n const changes: HouseOperation[] = [];\n for (const change of batch.changes) {\n const mapped = operationOf(batch, change, handle);\n if ('rule' in mapped) return { kind: 'unmapped', path: change.path, rule: mapped.rule };\n changes.push(mapped.operation);\n }\n return { kind: 'changes', changes };\n}\n\nexport type OperationHead = {\n readonly operation_id: string;\n readonly app_ref?: string;\n readonly release?: string;\n};\n\nexport function operationHead(batch: ChangeBatch): OperationHead {\n const writer = batch.writtenBy;\n return writer === undefined\n ? { operation_id: batch.id }\n : { operation_id: batch.id, app_ref: writer.app, release: writer.release };\n}\n\nexport function batchPaths(changes: readonly HouseOperation[]): readonly string[] {\n return [\n ...new Set(\n changes.flatMap((change) =>\n change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)],\n ),\n ),\n ].sort();\n}\n\nexport function deltaBody(changes: readonly HouseOperation[]): string {\n return JSON.stringify({ changes });\n}\n\nexport function deltaBytes(delta: string): number {\n return textBytes(delta);\n}\n\nexport function uploadable(bytes: number): boolean {\n return bytes > INLINE_BODY_LIMIT_BYTES && bytes <= UPLOAD_BYTES_MAX;\n}\n\nexport function deltaDigest(delta: string): Promise<string> {\n return sha256Hex(delta);\n}\n\ntype Material = { path: string; content: string | null; revision: string | null };\n\nfunction material(value: unknown, handle: string | undefined): readonly Material[] | null {\n if (!Array.isArray(value)) return null;\n const held: Material[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null) return null;\n const file = entry as Record<string, unknown>;\n if (typeof file.path !== 'string') return null;\n if (file.content !== null && typeof file.content !== 'string') return null;\n if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')\n return null;\n let path: string;\n try {\n path = roomLocalPath(file.path, handle);\n } catch {\n return null;\n }\n held.push({\n path,\n content: file.content,\n revision: typeof file.revision === 'string' ? file.revision : null,\n });\n }\n return held;\n}\n\nfunction affectedOf(held: readonly Material[]): Readonly<Record<string, string>> {\n const affected: Record<string, string> = {};\n for (const entry of held) {\n if (entry.content !== null) affected[entry.path] = entry.content;\n }\n return affected;\n}\n\nexport function mutationOutcome(\n status: number,\n body: unknown,\n locator: string,\n handle: string | undefined,\n): MutationResult {\n const refusal = doorRefusal(body);\n if (refusal !== null && refusal.code === 'service_mode_write_halted') {\n return { kind: 'write-halted' };\n }\n if (refusal !== null && refusal.code === 'rate_limited') {\n const reset = refusal.fields.retry_at;\n return {\n kind: 'retryable-refusal',\n code: refusal.code,\n fields: refusal.fields,\n ...(typeof reset === 'string' ? { reset } : {}),\n };\n }\n if (refusal !== null && refusal.code === 'operation_expired') return { kind: 'expired' };\n if (refusal !== null && refusal.code === 'edit_conflict') {\n const { current, ...fields } = refusal.fields;\n const held = material(current, handle) ?? [];\n return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };\n }\n if (refusal !== null && status === 404) {\n return scopedRefusal(locator, 'undisclosed', refusal);\n }\n const classified = classifyDoor(status, body, locator);\n if (classified !== null && classified.kind !== 'scoped-refusal') {\n return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;\n }\n if (classified !== null && status === 403) return classified;\n if (refusal !== null && status >= 400) {\n return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };\n }\n if (status !== 200 || typeof body !== 'object' || body === null) {\n return { kind: 'transport-uncertainty' };\n }\n const held = body as Record<string, unknown>;\n const at = readPosition(held);\n if (at === null) return { kind: 'transport-uncertainty' };\n const contents = material(held.contents, handle);\n if (contents === null) return { kind: 'transport-uncertainty' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const entry of contents) {\n if (entry.content === null || entry.revision === null) {\n removals.push(entry.path);\n continue;\n }\n documents[entry.path] = entry.content;\n revisions[entry.path] = entry.revision;\n }\n return {\n kind: 'accepted',\n roomVersion: roomVersion(at),\n documents,\n revisions,\n removals: removals.sort(),\n };\n}\n\nexport function rejectedMapping(mapping: Extract<ChangeMapping, { kind: 'unmapped' }>) {\n return {\n kind: 'rejected' as const,\n affected: {},\n code: mapping.rule,\n fields: { path: mapping.path },\n };\n}\n\nexport function revisionBody(input: {\n path: string;\n handle: string | undefined;\n revision?: string;\n pageToken?: string;\n}): Record<string, unknown> {\n return {\n path: nativePath(input.path, input.handle),\n ...(input.revision === undefined ? {} : { revision: input.revision }),\n ...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),\n };\n}\n\nfunction revisionAuthor(entry: Readonly<Record<string, unknown>>): HistoryAuthor | null {\n const user = entry.author_user;\n const site = entry.author_site;\n const name = entry.author_site_name;\n if (typeof user === 'string' && site === undefined && name === undefined) {\n return { kind: 'user', id: user };\n }\n if (user === null && typeof site === 'string' && typeof name === 'string') {\n return { kind: 'site', id: site, name };\n }\n return null;\n}\n\nexport function historyOutcome(\n status: number,\n body: unknown,\n locator: string,\n request: { path: string; revision?: string },\n): HistoryResult {\n const classified = classifyDoor(status, body, locator);\n if (classified !== null) {\n return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;\n }\n if (status !== 200 || typeof body !== 'object' || body === null) {\n return { kind: 'transport-uncertainty' };\n }\n const held = body as Record<string, unknown>;\n if (!Array.isArray(held.revisions)) return { kind: 'transport-uncertainty' };\n const entries: Record<string, unknown>[] = [];\n for (const entry of held.revisions) {\n if (typeof entry !== 'object' || entry === null) return { kind: 'transport-uncertainty' };\n entries.push(entry as Record<string, unknown>);\n }\n if (request.revision !== undefined) {\n const named = entries[0];\n if (named === undefined) return { kind: 'no-history' };\n if (named.unavailable === true) {\n return {\n kind: 'scoped-refusal',\n locator,\n scope: 'content',\n code: 'retained_history_unavailable',\n fields: { path: request.path, revision: request.revision },\n };\n }\n if (typeof named.content !== 'string') return { kind: 'transport-uncertainty' };\n return { kind: 'revision', content: named.content };\n }\n if (entries.length === 0) return { kind: 'no-history' };\n const revisions: HistoryRevision[] = [];\n for (const entry of entries) {\n const author = revisionAuthor(entry);\n if (\n typeof entry.revision !== 'string' ||\n author === null ||\n typeof entry.created_at !== 'string'\n ) {\n return { kind: 'transport-uncertainty' };\n }\n revisions.push({ revision: entry.revision, author, time: entry.created_at });\n }\n const next = held.next_before;\n return {\n kind: 'history',\n revisions,\n ...(typeof next === 'number' ? { pageToken: String(next) } : {}),\n };\n}\n"],"names":["sha256Hex","textBytes","nativePath","roomLocalPath","classifyDoor","doorRefusal","scopedRefusal","readPosition","roomVersion","INLINE_BODY_LIMIT_BYTES","UPLOAD_LINE_BYTES","UPLOAD_BYTES_MAX","priorField","batch","path","name","preconditions","find","precondition","kind","priorSection","priorPreamble","priorAbsence","priorExistence","held","undefined","base","revision","created","change","op","content","type","fields","length","sections","operationOf","handle","prior","rule","operation","field","value","section","existence","to","houseChanges","changes","mapped","push","operationHead","writer","writtenBy","operation_id","id","app_ref","app","release","batchPaths","Set","flatMap","String","sort","deltaBody","JSON","stringify","deltaBytes","delta","uploadable","bytes","deltaDigest","material","Array","isArray","entry","file","affectedOf","affected","mutationOutcome","status","body","locator","refusal","code","reset","retry_at","current","classified","at","contents","documents","revisions","removals","rejectedMapping","mapping","revisionBody","input","pageToken","before","Number","revisionAuthor","user","author_user","site","author_site","author_site_name","historyOutcome","request","entries","named","unavailable","scope","author","created_at","time","next","next_before"],"mappings":"AASA,SAASA,SAAS,EAAEC,SAAS,QAAQ,cAAc;AACnD,SAASC,UAAU,EAAEC,aAAa,QAAQ,WAAW;AACrD,SAASC,YAAY,EAAEC,WAAW,EAAEC,aAAa,QAAQ,eAAe;AACxE,SAASC,YAAY,EAAEC,WAAW,QAAQ,eAAe;AAEzD,OAAO,MAAMC,0BAA0B,IAAI,OAAO,KAAK;AAEvD,OAAO,MAAMC,oBAAoB,GAAG;AAEpC,OAAO,MAAMC,mBAAmB,KAAK,OAAO,OAAOD,kBAAkB;AAUrE,SAASE,WAAWC,KAAkB,EAAEC,IAAY,EAAEC,IAAY;IAChE,OAAOF,MAAMG,aAAa,CAACC,IAAI,CAC7B,CAACC,eACCA,aAAaC,IAAI,KAAK,WAAWD,aAAaJ,IAAI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F,WAAW;IAC7B,OAAO;QACLjG,MAAM;QACNwE;QACA,GAAI,OAAOwB,SAAS,WAAW;YAAElB,WAAWpC,OAAOsD;QAAM,IAAI,CAAC,CAAC;IACjE;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/write.ts"],"sourcesContent":["import type {\n Change,\n ChangeBatch,\n HistoryAuthor,\n HistoryResult,\n HistoryRevision,\n MutationResult,\n Precondition,\n} from '@agentshouse/mdruntime';\nimport { sha256Hex, textBytes } from './digest.js';\nimport { nativePath, roomLocalPath } from './map.js';\nimport { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';\nimport { readPosition, roomVersion } from './version.js';\n\nexport const INLINE_BODY_LIMIT_BYTES = 4 * 1024 * 1024;\n\nexport const UPLOAD_LINE_BYTES = 37;\n\nexport const UPLOAD_BYTES_MAX = 32 * 1024 * 1024 - UPLOAD_LINE_BYTES;\n\nexport type HouseOperation = Readonly<Record<string, unknown>>;\n\nexport type ChangeMapping =\n | { kind: 'changes'; changes: readonly HouseOperation[] }\n | { kind: 'unmapped'; path: string; rule: string };\n\ntype Existence = { base: string } | { kind: 'presence' };\n\nfunction priorField(batch: ChangeBatch, path: string, name: string) {\n return batch.preconditions.find(\n (precondition): precondition is Extract<Precondition, { kind: 'field' }> =>\n precondition.kind === 'field' && precondition.path === path && precondition.name === name,\n );\n}\n\nfunction priorSection(batch: ChangeBatch, path: string, name: string) {\n return batch.preconditions.find(\n (precondition): precondition is Extract<Precondition, { kind: 'section' }> =>\n precondition.kind === 'section' && precondition.path === path && precondition.name === name,\n );\n}\n\nfunction priorPreamble(batch: ChangeBatch, path: string) {\n return batch.preconditions.find(\n (precondition): precondition is Extract<Precondition, { kind: 'preamble' }> =>\n precondition.kind === 'preamble' && precondition.path === path,\n );\n}\n\nfunction priorAbsence(batch: ChangeBatch, path: string) {\n return batch.preconditions.find(\n (precondition) => precondition.kind === 'absent' && precondition.path === path,\n );\n}\n\nfunction priorExistence(batch: ChangeBatch, path: string): Existence | undefined {\n const precondition = batch.preconditions.find(\n (held) => held.path === path && (held.kind === 'revision' || held.kind === 'present'),\n );\n if (precondition === undefined) return undefined;\n return precondition.kind === 'revision' ? { base: precondition.revision } : { kind: 'presence' };\n}\n\nfunction created(change: Extract<Change, { kind: 'create' }>, path: string): HouseOperation | null {\n if ('content' in change) return { op: 'create', path, content: change.content };\n const { type, ...fields } = change.fields;\n if (typeof type !== 'string' || type.length === 0) return null;\n return { op: 'create_typed', path, type, fields, sections: change.sections };\n}\n\ntype MappedOperation = { operation: HouseOperation } | { rule: string };\n\nfunction operationOf(batch: ChangeBatch, change: Change, handle: string): MappedOperation {\n const path = nativePath(change.path, handle);\n if (change.kind === 'field') {\n const prior = priorField(batch, change.path, change.name);\n if (prior === undefined) return { rule: 'precondition-missing' };\n return {\n operation: {\n op: 'set_field',\n path,\n field: change.name,\n value: change.value,\n ...(prior.value === undefined ? {} : { base: prior.value }),\n },\n };\n }\n if (change.kind === 'section') {\n const prior = priorSection(batch, change.path, change.name);\n if (prior === undefined) return { rule: 'precondition-missing' };\n return {\n operation: {\n op: 'replace_section',\n path,\n section: change.name,\n base: prior.value,\n content: change.value,\n },\n };\n }\n if (change.kind === 'preamble') {\n const prior = priorPreamble(batch, change.path);\n if (prior === undefined) return { rule: 'precondition-missing' };\n return {\n operation: { op: 'replace_preamble', path, base: prior.value, content: change.value },\n };\n }\n if (change.kind === 'create') {\n if (priorAbsence(batch, change.path) === undefined) return { rule: 'precondition-missing' };\n const operation = created(change, path);\n return operation === null ? { rule: 'type-missing' } : { operation };\n }\n const existence = priorExistence(batch, change.path);\n if (existence === undefined) return { rule: 'precondition-missing' };\n if (!('base' in existence)) return { rule: 'presence-base-unrepresentable' };\n if (change.kind === 'replace') {\n return { operation: { op: 'replace', path, base: existence.base, content: change.content } };\n }\n if (change.kind === 'move') {\n if (priorAbsence(batch, change.to) === undefined) return { rule: 'precondition-missing' };\n return {\n operation: { op: 'rename', path, to: nativePath(change.to, handle), base: existence.base },\n };\n }\n return { operation: { op: 'remove', path, base: existence.base } };\n}\n\nexport function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping {\n const changes: HouseOperation[] = [];\n for (const change of batch.changes) {\n const mapped = operationOf(batch, change, handle);\n if ('rule' in mapped) return { kind: 'unmapped', path: change.path, rule: mapped.rule };\n changes.push(mapped.operation);\n }\n return { kind: 'changes', changes };\n}\n\nexport type OperationHead = {\n readonly operation_id: string;\n readonly app_ref?: string;\n readonly release?: string;\n};\n\nexport function operationHead(batch: ChangeBatch): OperationHead {\n const writer = batch.writtenBy;\n return writer === undefined\n ? { operation_id: batch.id }\n : { operation_id: batch.id, app_ref: writer.app, release: writer.release };\n}\n\nexport function batchPaths(changes: readonly HouseOperation[]): readonly string[] {\n return [\n ...new Set(\n changes.flatMap((change) =>\n change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)],\n ),\n ),\n ].sort();\n}\n\nexport function deltaBody(changes: readonly HouseOperation[]): string {\n return JSON.stringify({ changes });\n}\n\nexport function deltaBytes(delta: string): number {\n return textBytes(delta);\n}\n\nexport function uploadable(bytes: number): boolean {\n return bytes > INLINE_BODY_LIMIT_BYTES && bytes <= UPLOAD_BYTES_MAX;\n}\n\nexport function deltaDigest(delta: string): Promise<string> {\n return sha256Hex(delta);\n}\n\ntype Material = { path: string; content: string | null; revision: string | null };\n\nfunction material(value: unknown, handle: string): readonly Material[] | null {\n if (!Array.isArray(value)) return null;\n const held: Material[] = [];\n for (const entry of value) {\n if (typeof entry !== 'object' || entry === null) return null;\n const file = entry as Record<string, unknown>;\n if (typeof file.path !== 'string') return null;\n if (file.content !== null && typeof file.content !== 'string') return null;\n if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')\n return null;\n let path: string;\n try {\n path = roomLocalPath(file.path, handle);\n } catch {\n return null;\n }\n held.push({\n path,\n content: file.content,\n revision: typeof file.revision === 'string' ? file.revision : null,\n });\n }\n return held;\n}\n\nfunction affectedOf(held: readonly Material[]): Readonly<Record<string, string>> {\n const affected: Record<string, string> = {};\n for (const entry of held) {\n if (entry.content !== null) affected[entry.path] = entry.content;\n }\n return affected;\n}\n\nexport function mutationOutcome(\n status: number,\n body: unknown,\n locator: string,\n handle: string,\n): MutationResult {\n const refusal = doorRefusal(body);\n if (refusal !== null && refusal.code === 'service_mode_write_halted') {\n return { kind: 'write-halted' };\n }\n if (refusal !== null && refusal.code === 'rate_limited') {\n const reset = refusal.fields.retry_at;\n return {\n kind: 'retryable-refusal',\n code: refusal.code,\n fields: refusal.fields,\n ...(typeof reset === 'string' ? { reset } : {}),\n };\n }\n if (refusal !== null && refusal.code === 'operation_expired') return { kind: 'expired' };\n if (refusal !== null && refusal.code === 'edit_conflict') {\n const { current, ...fields } = refusal.fields;\n const held = material(current, handle) ?? [];\n return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };\n }\n if (refusal !== null && status === 404) {\n return scopedRefusal(locator, 'undisclosed', refusal);\n }\n const classified = classifyDoor(status, body, locator);\n if (classified !== null && classified.kind !== 'scoped-refusal') {\n return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;\n }\n if (classified !== null && status === 403) return classified;\n if (refusal !== null && status >= 400) {\n return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };\n }\n if (status !== 200 || typeof body !== 'object' || body === null) {\n return { kind: 'transport-uncertainty' };\n }\n const held = body as Record<string, unknown>;\n const at = readPosition(held);\n if (at === null) return { kind: 'transport-uncertainty' };\n const contents = material(held.contents, handle);\n if (contents === null) return { kind: 'transport-uncertainty' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const removals: string[] = [];\n for (const entry of contents) {\n if (entry.content === null || entry.revision === null) {\n removals.push(entry.path);\n continue;\n }\n documents[entry.path] = entry.content;\n revisions[entry.path] = entry.revision;\n }\n return {\n kind: 'accepted',\n roomVersion: roomVersion(at),\n documents,\n revisions,\n removals: removals.sort(),\n };\n}\n\nexport function rejectedMapping(mapping: Extract<ChangeMapping, { kind: 'unmapped' }>) {\n return {\n kind: 'rejected' as const,\n affected: {},\n code: mapping.rule,\n fields: { path: mapping.path },\n };\n}\n\nexport function revisionBody(input: {\n path: string;\n handle: string;\n revision?: string;\n pageToken?: string;\n}): Record<string, unknown> {\n return {\n path: nativePath(input.path, input.handle),\n ...(input.revision === undefined ? {} : { revision: input.revision }),\n ...(input.pageToken === undefined ? {} : { before: Number(input.pageToken) }),\n };\n}\n\nfunction revisionAuthor(entry: Readonly<Record<string, unknown>>): HistoryAuthor | null {\n const user = entry.author_user;\n const site = entry.author_site;\n const name = entry.author_site_name;\n if (typeof user === 'string' && site === undefined && name === undefined) {\n return { kind: 'user', id: user };\n }\n if (user === null && typeof site === 'string' && typeof name === 'string') {\n return { kind: 'site', id: site, name };\n }\n return null;\n}\n\nexport function historyOutcome(\n status: number,\n body: unknown,\n locator: string,\n request: { path: string; revision?: string },\n): HistoryResult {\n const classified = classifyDoor(status, body, locator);\n if (classified !== null) {\n return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;\n }\n if (status !== 200 || typeof body !== 'object' || body === null) {\n return { kind: 'transport-uncertainty' };\n }\n const held = body as Record<string, unknown>;\n if (!Array.isArray(held.revisions)) return { kind: 'transport-uncertainty' };\n const entries: Record<string, unknown>[] = [];\n for (const entry of held.revisions) {\n if (typeof entry !== 'object' || entry === null) return { kind: 'transport-uncertainty' };\n entries.push(entry as Record<string, unknown>);\n }\n if (request.revision !== undefined) {\n const named = entries[0];\n if (named === undefined) return { kind: 'no-history' };\n if (named.unavailable === true) {\n return {\n kind: 'scoped-refusal',\n locator,\n scope: 'content',\n code: 'retained_history_unavailable',\n fields: { path: request.path, revision: request.revision },\n };\n }\n if (typeof named.content !== 'string') return { kind: 'transport-uncertainty' };\n return { kind: 'revision', content: named.content };\n }\n if (entries.length === 0) return { kind: 'no-history' };\n const revisions: HistoryRevision[] = [];\n for (const entry of entries) {\n const author = revisionAuthor(entry);\n if (\n typeof entry.revision !== 'string' ||\n author === null ||\n typeof entry.created_at !== 'string'\n ) {\n return { kind: 'transport-uncertainty' };\n }\n revisions.push({ revision: entry.revision, author, time: entry.created_at });\n }\n const next = held.next_before;\n return {\n kind: 'history',\n revisions,\n ...(typeof next === 'number' ? { pageToken: String(next) } : {}),\n };\n}\n"],"names":["sha256Hex","textBytes","nativePath","roomLocalPath","classifyDoor","doorRefusal","scopedRefusal","readPosition","roomVersion","INLINE_BODY_LIMIT_BYTES","UPLOAD_LINE_BYTES","UPLOAD_BYTES_MAX","priorField","batch","path","name","preconditions","find","precondition","kind","priorSection","priorPreamble","priorAbsence","priorExistence","held","undefined","base","revision","created","change","op","content","type","fields","length","sections","operationOf","handle","prior","rule","operation","field","value","section","existence","to","houseChanges","changes","mapped","push","operationHead","writer","writtenBy","operation_id","id","app_ref","app","release","batchPaths","Set","flatMap","String","sort","deltaBody","JSON","stringify","deltaBytes","delta","uploadable","bytes","deltaDigest","material","Array","isArray","entry","file","affectedOf","affected","mutationOutcome","status","body","locator","refusal","code","reset","retry_at","current","classified","at","contents","documents","revisions","removals","rejectedMapping","mapping","revisionBody","input","pageToken","before","Number","revisionAuthor","user","author_user","site","author_site","author_site_name","historyOutcome","request","entries","named","unavailable","scope","author","created_at","time","next","next_before"],"mappings":"AASA,SAASA,SAAS,EAAEC,SAAS,QAAQ,cAAc;AACnD,SAASC,UAAU,EAAEC,aAAa,QAAQ,WAAW;AACrD,SAASC,YAAY,EAAEC,WAAW,EAAEC,aAAa,QAAQ,eAAe;AACxE,SAASC,YAAY,EAAEC,WAAW,QAAQ,eAAe;AAEzD,OAAO,MAAMC,0BAA0B,IAAI,OAAO,KAAK;AAEvD,OAAO,MAAMC,oBAAoB,GAAG;AAEpC,OAAO,MAAMC,mBAAmB,KAAK,OAAO,OAAOD,kBAAkB;AAUrE,SAASE,WAAWC,KAAkB,EAAEC,IAAY,EAAEC,IAAY;IAChE,OAAOF,MAAMG,aAAa,CAACC,IAAI,CAC7B,CAACC,eACCA,aAAaC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