@agentshouse/mdruntime-adapter 0.1.0-alpha.35 → 0.1.0-alpha.37
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 +19 -5
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +62 -16
- package/dist/actions.js.map +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +11 -3
- package/dist/adapter.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +0 -1
- package/dist/refusal.js.map +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +2 -1
- package/dist/site.js.map +1 -1
- package/dist/stream.d.ts +4 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +144 -45
- package/dist/stream.js.map +1 -1
- package/dist/transport.d.ts +23 -4
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js.map +1 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +27 -2
- package/dist/write.js.map +1 -1
- package/package.json +2 -2
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} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\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 selectionRoots,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure } 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 { logPosition, presented, roomVersion, type LogPosition } from './version.js';\n\ntype Refused = AdapterFailure | { 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 const read = selectionRoots(tracked);\n return {\n name: tracked.handle,\n locator: tracked.locator,\n collectionRoot: tracked.collectionRoot,\n roomVersion: roomVersion(tracked),\n operations: { read: [...read], sync: [...read], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' ? UNCERTAIN : 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 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 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 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 };\n}\n"],"names":["actionOutcome","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","bootstrapOf","parseEnumeration","parseSiteBootstrap","refreshFrom","schemaOf","schemaPath","selectionRoots","classifyDoor","discoveryFailure","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","read","name","handle","locator","collectionRoot","operations","sync","write","delete","replica","selection","admission","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","classified","status","body","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","mutate","affected","code","fields","history","action","online","input","roomVersions"],"mappings":"AASA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACEC,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,EACVC,cAAc,QAGT,YAAY;AACnB,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,eAAe;AAC9D,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,eAAe,EACfC,mBAAmB,EACnBC,kBAAkB,EAClBC,mBAAmB,EACnBC,gBAAgB,QAEX,iBAAiB;AACxB,SAASC,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAA0B,eAAe;AAQrF,MAAMC,YAAY;IAAEC,MAAM;AAAwB;AAElD,SAASC,SACPC,OAAoB,EACpBC,aAA8C;IAE9C,MAAMC,OAAOjB,eAAee;IAC5B,OAAO;QACLG,MAAMH,QAAQI,MAAM;QACpBC,SAASL,QAAQK,OAAO;QACxBC,gBAAg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AAQ,CAAC;YAAE;QAC3E;QAEA,MAAMC;YACJ,OAAO;gBAAErF,MAAM;YAAa;QAC9B;QAEA,MAAMsF,QAAO9B,cAAc,EAAEC,OAAO;YAClC,IAAIA,QAAQpD,IAAI,KAAK,UAAU;gBAC7B,OAAO;oBAAEL,MAAM;oBAAYmF,MAAM;oBAAwBC,QAAQ;wBAAE/E,MAAMoD,QAAQpD,IAAI;oBAAC;gBAAE;YAC1F;YACA,IAAI,CAACe,UAAUmE,MAAM,IAAI,OAAOxF;YAChC,OAAO9B,cAAc,MAAMmD,UAAUU,IAAI,CAACnC,kBAAkB8D,QAAQ+B,KAAK,GAAG;QAC9E;QAEAC,cAAcpE;IAChB;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} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\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 selectionRoots,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure } 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 { logPosition, presented, roomVersion, type LogPosition } from './version.js';\n\ntype Refused = AdapterFailure | { 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 const read = selectionRoots(tracked);\n return {\n name: tracked.handle,\n locator: tracked.locator,\n collectionRoot: tracked.collectionRoot,\n roomVersion: roomVersion(tracked),\n operations: { read: [...read], sync: [...read], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' ? UNCERTAIN : 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 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 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 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","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","bootstrapOf","parseEnumeration","parseSiteBootstrap","refreshFrom","schemaOf","schemaPath","selectionRoots","classifyDoor","discoveryFailure","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","read","name","handle","locator","collectionRoot","operations","sync","write","delete","replica","selection","admission","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","classified","status","body","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","mutate","affected","code","fields","history","action","online","input","roomVersions","serviceMode"],"mappings":"AASA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACEC,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,EACVC,cAAc,QAGT,YAAY;AACnB,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,eAAe;AAC9D,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,eAAe,EACfC,mBAAmB,EACnBC,kBAAkB,EAClBC,mBAAmB,EACnBC,gBAAgB,QAEX,iBAAiB;AACxB,SAASC,WAAW,EAAEC,SAAS,EAAEC,WAAW,QAA0B,eAAe;AAQrF,MAAMC,YAAY;IAAEC,MAAM;AAAwB;AAElD,SAASC,SACPC,OAAoB,EACpBC,aAA8C;IAE9C,MAAMC,OAAOjB,eAAee;IAC5B,OAAO;QACLG,MAAMH,QAAQI,MAAM;QACpBC,SAASL,QAAQK,OAAO;QACxBC,gBAAgBN,QAAQM,cAAc;QACtCV,aAAaA,YAAYI;QACzBO,YAAY;YAAEL,MAAM;mBAAIA;aAAK;YAAEM,MAAM;mBAAIN;aAAK;YAAEO,OAAO,EAAE;YAAEC,QAAQ,EAAE;QAAC;QACtEC,SAAS;YAAEC,WAAWZ,QAAQK,OAAO;YAAEQ,WAAW;QAAW;QAC7DZ;QACAa,oBAAoB,EAAE;IACxB;AACF;AAEA,SAASC,QAAQC,OAAgB;IAC/B,OAAOA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UmE,MAAM,IAAI,OAAOxF;YAChC,OAAO9B,cAAc,MAAMmD,UAAUU,IAAI,CAACnC,kBAAkB8D,QAAQ+B,KAAK,GAAG;QAC9E;QAEAC,cAAcpE;QACdqE,aAAarE,cAAcqE,WAAW;IACxC;AACF"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
|
-
import type { ConversationStream, RefreshPage, SelectedRooms } from '@agentshouse/mdruntime';
|
|
1
|
+
import type { ConversationStream, RefreshPage, SelectedRooms, ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type
|
|
3
|
+
import { type HouseDoor, type HouseMode } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
5
5
|
export type HouseNotifications = SelectedRooms & {
|
|
6
6
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
7
7
|
advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;
|
|
8
8
|
conversations: ConversationStream;
|
|
9
|
+
serviceMode: ServiceModeSignal;
|
|
10
|
+
question(conversation: string): void;
|
|
9
11
|
};
|
|
10
12
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
11
13
|
//# 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,
|
|
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,EAEL,KAAK,SAAS,EACd,KAAK,SAAS,EAGf,MAAM,gBAAgB,CAAC;AACxB,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,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,WAAW,GAAG,IAAI,CAAC;IAC1E,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;IAC/B,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CACtC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA2R5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { acceptedMessage, actionOutcome } from './actions.js';
|
|
2
2
|
import { selects } from './read.js';
|
|
3
|
+
import { PRIVATE_LOCATOR } from './transport.js';
|
|
3
4
|
import { roomVersion } from './version.js';
|
|
4
5
|
const HELD_POSITIONS_MAX = 256;
|
|
6
|
+
const CONVERSATION_CARD = /^agents\/([^/]+)\.md$/;
|
|
5
7
|
function position(value) {
|
|
6
8
|
if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
|
|
7
9
|
return BigInt(value);
|
|
@@ -13,8 +15,12 @@ export function houseNotifications(transport, mode) {
|
|
|
13
15
|
const schemas = new Map();
|
|
14
16
|
const observers = new Set();
|
|
15
17
|
const conversationObservers = new Set();
|
|
18
|
+
const modeObservers = new Set();
|
|
16
19
|
let replicated = [];
|
|
17
|
-
let
|
|
20
|
+
let privateAuthority;
|
|
21
|
+
const live = new Set();
|
|
22
|
+
const noted = new Set();
|
|
23
|
+
const asked = new Map();
|
|
18
24
|
let listening = false;
|
|
19
25
|
let catching = false;
|
|
20
26
|
function listen() {
|
|
@@ -23,29 +29,122 @@ export function houseNotifications(transport, mode) {
|
|
|
23
29
|
stream.observe(receive);
|
|
24
30
|
}
|
|
25
31
|
function emitConversation(event) {
|
|
26
|
-
|
|
27
|
-
if (!delivered.includes(event.conversation)) return;
|
|
32
|
+
if (event.kind !== 'gap' && event.kind !== 'accepted-message') live.add(event.conversation);
|
|
28
33
|
for (const observer of conversationObservers)observer(event);
|
|
29
34
|
}
|
|
30
|
-
|
|
31
|
-
|
|
35
|
+
function unnote(conversation) {
|
|
36
|
+
if (!noted.delete(conversation)) return;
|
|
37
|
+
emitConversation({
|
|
38
|
+
kind: 'working-note',
|
|
39
|
+
conversation,
|
|
40
|
+
note: null
|
|
41
|
+
});
|
|
42
|
+
}
|
|
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', {
|
|
32
47
|
conversation_id: conversation
|
|
33
48
|
});
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
+
});
|
|
42
59
|
}
|
|
43
60
|
function reopened() {
|
|
44
|
-
|
|
61
|
+
const gapped = new Set([
|
|
62
|
+
...replicated,
|
|
63
|
+
...live
|
|
64
|
+
]);
|
|
65
|
+
live.clear();
|
|
66
|
+
noted.clear();
|
|
67
|
+
for (const conversation of gapped)emitConversation({
|
|
45
68
|
kind: 'gap',
|
|
46
69
|
conversation
|
|
47
70
|
});
|
|
48
|
-
for (const conversation of
|
|
71
|
+
for (const conversation of replicated)void question(conversation);
|
|
72
|
+
}
|
|
73
|
+
function converse(frame) {
|
|
74
|
+
const conversation = frame.conversation_id;
|
|
75
|
+
if (frame.type === 'draft') {
|
|
76
|
+
unnote(conversation);
|
|
77
|
+
emitConversation({
|
|
78
|
+
kind: 'growing-text',
|
|
79
|
+
conversation,
|
|
80
|
+
turn: frame.turn_id,
|
|
81
|
+
text: frame.text
|
|
82
|
+
});
|
|
83
|
+
emitConversation({
|
|
84
|
+
kind: 'plan',
|
|
85
|
+
conversation,
|
|
86
|
+
turn: frame.turn_id,
|
|
87
|
+
plan: structuredClone(frame.steps)
|
|
88
|
+
});
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
if (frame.type === 'working-note') {
|
|
92
|
+
noted.add(conversation);
|
|
93
|
+
emitConversation({
|
|
94
|
+
kind: 'working-note',
|
|
95
|
+
conversation,
|
|
96
|
+
note: {
|
|
97
|
+
noteId: frame.note_id,
|
|
98
|
+
text: frame.text
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
if (frame.type === 'process') {
|
|
104
|
+
emitConversation({
|
|
105
|
+
kind: 'process',
|
|
106
|
+
conversation,
|
|
107
|
+
running: frame.running
|
|
108
|
+
});
|
|
109
|
+
if (frame.running) return;
|
|
110
|
+
emitConversation({
|
|
111
|
+
kind: 'commands',
|
|
112
|
+
conversation,
|
|
113
|
+
commands: []
|
|
114
|
+
});
|
|
115
|
+
emitConversation({
|
|
116
|
+
kind: 'options',
|
|
117
|
+
conversation,
|
|
118
|
+
options: []
|
|
119
|
+
});
|
|
120
|
+
unnote(conversation);
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
if (frame.type === 'commands') {
|
|
124
|
+
emitConversation({
|
|
125
|
+
kind: 'commands',
|
|
126
|
+
conversation,
|
|
127
|
+
commands: structuredClone(frame.commands)
|
|
128
|
+
});
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
if (frame.type === 'options') {
|
|
132
|
+
emitConversation({
|
|
133
|
+
kind: 'options',
|
|
134
|
+
conversation,
|
|
135
|
+
options: structuredClone(frame.options)
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const message = acceptedMessage(frame.message);
|
|
140
|
+
if (message === null) return;
|
|
141
|
+
emitConversation({
|
|
142
|
+
kind: 'accepted-message',
|
|
143
|
+
conversation,
|
|
144
|
+
message
|
|
145
|
+
});
|
|
146
|
+
if (frame.message.role === 'user') return;
|
|
147
|
+
unnote(conversation);
|
|
49
148
|
}
|
|
50
149
|
function announce(authority, at, modelChanged) {
|
|
51
150
|
const version = roomVersion(at);
|
|
@@ -70,34 +169,26 @@ export function houseNotifications(transport, mode) {
|
|
|
70
169
|
});
|
|
71
170
|
}
|
|
72
171
|
function receive(frame) {
|
|
73
|
-
if (frame.type === '
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
turn: frame.turn_id,
|
|
78
|
-
text: frame.text
|
|
79
|
-
});
|
|
172
|
+
if (frame.type === 'signal') {
|
|
173
|
+
const mode = frame.service_mode;
|
|
174
|
+
if (mode !== 'open' && mode !== 'write-halted') return;
|
|
175
|
+
for (const observer of modeObservers)observer(mode);
|
|
80
176
|
return;
|
|
81
177
|
}
|
|
82
|
-
if (frame.type === 'message') {
|
|
83
|
-
|
|
84
|
-
if (message === null) return;
|
|
85
|
-
emitConversation({
|
|
86
|
-
kind: 'accepted-message',
|
|
87
|
-
conversation: frame.conversation_id,
|
|
88
|
-
message
|
|
89
|
-
});
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
|
-
if (frame.type === 'session') {
|
|
93
|
-
emitConversation({
|
|
94
|
-
kind: 'session-summary',
|
|
95
|
-
conversation: frame.conversation_id,
|
|
96
|
-
summary: structuredClone(frame.summary)
|
|
97
|
-
});
|
|
178
|
+
if (frame.type === 'draft' || frame.type === 'working-note' || frame.type === 'process' || frame.type === 'commands' || frame.type === 'options' || frame.type === 'message') {
|
|
179
|
+
converse(frame);
|
|
98
180
|
return;
|
|
99
181
|
}
|
|
100
182
|
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
|
+
}
|
|
101
192
|
const at = position(frame.position);
|
|
102
193
|
if (at === null) {
|
|
103
194
|
interrupt(frame.authority);
|
|
@@ -133,18 +224,25 @@ export function houseNotifications(transport, mode) {
|
|
|
133
224
|
}, frame.entries.some((entry)=>addresses.includes(entry.path)));
|
|
134
225
|
}
|
|
135
226
|
return {
|
|
227
|
+
serviceMode: {
|
|
228
|
+
observe (notify) {
|
|
229
|
+
modeObservers.add(notify);
|
|
230
|
+
listen();
|
|
231
|
+
return ()=>{
|
|
232
|
+
modeObservers.delete(notify);
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
question (conversation) {
|
|
237
|
+
void question(conversation);
|
|
238
|
+
},
|
|
136
239
|
conversations: {
|
|
137
240
|
replicate (next) {
|
|
241
|
+
const entering = next.filter((conversation)=>!replicated.includes(conversation));
|
|
138
242
|
replicated = [
|
|
139
243
|
...next
|
|
140
244
|
];
|
|
141
|
-
|
|
142
|
-
view (next) {
|
|
143
|
-
const entering = next.filter((conversation)=>!viewed.includes(conversation));
|
|
144
|
-
viewed = [
|
|
145
|
-
...next
|
|
146
|
-
];
|
|
147
|
-
for (const conversation of entering)void summarize(conversation);
|
|
245
|
+
for (const conversation of entering)void question(conversation);
|
|
148
246
|
},
|
|
149
247
|
observe (notify) {
|
|
150
248
|
conversationObservers.add(notify);
|
|
@@ -161,6 +259,7 @@ export function houseNotifications(transport, mode) {
|
|
|
161
259
|
track (entries) {
|
|
162
260
|
locators.clear();
|
|
163
261
|
schemas.clear();
|
|
262
|
+
privateAuthority = entries.find((entry)=>entry.locator === PRIVATE_LOCATOR)?.authority;
|
|
164
263
|
for (const entry of entries){
|
|
165
264
|
locators.set(entry.authority, [
|
|
166
265
|
...locators.get(entry.authority) ?? [],
|
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} from '@agentshouse/mdruntime';\nimport { acceptedMessage, actionOutcome } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } from './read.js';\nimport type { HouseDoor, HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;\n conversations: ConversationStream;\n};\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 let replicated: readonly string[] = [];\n let viewed: readonly 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 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 reopened() {\n for (const conversation of replicated) emitConversation({ kind: 'gap', conversation });\n for (const conversation of viewed) void summarize(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 === '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 !== '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 conversations: {\n replicate(next) {\n replicated = [...next];\n },\n view(next) {\n const entering = next.filter((conversation) => !viewed.includes(conversation));\n viewed = [...next];\n for (const conversation of entering) void summarize(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 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 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","schemas","observers","Set","conversationObservers","replicated","viewed","listening","catching","listen","observe","receive","emitConversation","event","delivered","kind","includes","conversation","observer","summarize","viewedAnswer","door","conversation_id","summary","result","structuredClone","session","reopened","announce","authority","at","modelChanged","version","locator","get","interrupt","line","undefined","set","logEpoch","frames","frame","type","turn","turn_id","text","message","log_epoch","last","continued","next","entries","length","addresses","some","entry","path","conversations","replicate","view","entering","filter","notify","add","opened","delete","track","clear","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","removals","push","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AAOA,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAe;AAE9D,SAASC,OAAO,QAAQ,YAAY;AAEpC,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,UAAU,IAAIF;IACpB,MAAMG,YAAY,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MxC,IAAI,KAAK,WAAW;wBAC5B,OAAO+D,SAAS,CAACvB,MAAMC,IAAI,CAAC;wBAC5B,OAAOuB,SAAS,CAACxB,MAAMC,IAAI,CAAC;wBAC5B,IAAI,CAACwB,SAAShE,QAAQ,CAACuC,MAAMC,IAAI,GAAGwB,SAASC,IAAI,CAAC1B,MAAMC,IAAI;wBAC5D;oBACF;oBACA,IAAID,MAAMV,IAAI,KAAKR,WAAW,OAAO;oBACrC,IAAIzC,SAAS,gBAAgB2D,MAAM2B,QAAQ,KAAK7C,WAAW,OAAO;oBAClEyC,SAAS,CAACvB,MAAMC,IAAI,CAAC,GAAGD,MAAMV,IAAI;oBAClC,IAAIU,MAAM2B,QAAQ,KAAK7C,WAAW0C,SAAS,CAACxB,MAAMC,IAAI,CAAC,GAAGD,MAAM2B,QAAQ;oBACxE,MAAMC,UAAUH,SAASI,OAAO,CAAC7B,MAAMC,IAAI;oBAC3C,IAAI2B,YAAY,CAAC,GAAGH,SAASK,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAMnC,OAAO4B,QAAQ9C,EAAE,CAAC,CAAC;YACzB,IAAIkB,SAASX,WAAW,OAAO;YAC/BvC,MAAMwC,GAAG,CAACkC,QAAQ3C,SAAS,EAAE;gBAAEU,UAAUH,KAAKG,QAAQ;gBAAEC,QAAQoC;YAAQ;YACxE,OAAO;gBACL7D,MAAM;gBACN3B,aAAaA,YAAY;oBAAEE,UAAU0D,KAAK1D,QAAQ,CAACgG,QAAQ;oBAAI/C,UAAUH,KAAKG,QAAQ;gBAAC;gBACvFuC;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 ServiceMode,\n ServiceModeSignal,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage, actionOutcome } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { selects } 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 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","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","removals","push","revision","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AASA,SAASA,eAAe,EAAEC,aAAa,QAAQ,eAAe;AAE9D,SAASC,OAAO,QAAQ,YAAY;AACpC,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,IAAI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,MAAMmC,QAAQ;oBACxE,MAAMC,UAAUH,SAASI,OAAO,CAACrC,MAAMI,IAAI;oBAC3C,IAAIgC,YAAY,CAAC,GAAGH,SAASK,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAM9B,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,CAACuH,QAAQ;oBAAI1C,UAAUF,KAAKE,QAAQ;gBAAC;gBACvFkC;gBACAC;gBACAQ,eAAe,EAAE;gBACjBP,UAAUA,SAASQ,IAAI;YACzB;QACF;IACF;AACF"}
|
package/dist/transport.d.ts
CHANGED
|
@@ -14,12 +14,14 @@ export type HouseDoorAnswer = {
|
|
|
14
14
|
status: number;
|
|
15
15
|
body: unknown;
|
|
16
16
|
};
|
|
17
|
-
export type HouseByteAct = 'working_copy_bundle' | 'authored_batch_upload' | 'conversation_original_upload';
|
|
17
|
+
export type HouseByteAct = 'working_copy_bundle' | 'authored_batch_upload' | 'conversation_original_upload' | 'original_upload' | 'original_download';
|
|
18
18
|
export type HouseByteBody = string | ArrayBuffer | Uint8Array;
|
|
19
|
+
export type HouseByteAnswer = 'json' | 'bytes';
|
|
19
20
|
export type HouseByteTransfer = {
|
|
20
21
|
act: HouseByteAct;
|
|
21
22
|
method: 'GET' | 'POST';
|
|
22
23
|
url: string;
|
|
24
|
+
answer: HouseByteAnswer;
|
|
23
25
|
body?: HouseByteBody;
|
|
24
26
|
operation?: string;
|
|
25
27
|
};
|
|
@@ -38,17 +40,34 @@ export type HouseStreamFrame = {
|
|
|
38
40
|
} | {
|
|
39
41
|
type: 'draft';
|
|
40
42
|
conversation_id: string;
|
|
41
|
-
session_id: string;
|
|
42
43
|
turn_id: string;
|
|
43
44
|
text: string;
|
|
45
|
+
blocks: readonly unknown[];
|
|
46
|
+
steps: readonly unknown[];
|
|
44
47
|
} | {
|
|
45
48
|
type: 'message';
|
|
46
49
|
conversation_id: string;
|
|
47
50
|
message: unknown;
|
|
48
51
|
} | {
|
|
49
|
-
type: '
|
|
52
|
+
type: 'working-note';
|
|
50
53
|
conversation_id: string;
|
|
51
|
-
|
|
54
|
+
note_id: string;
|
|
55
|
+
text: string;
|
|
56
|
+
} | {
|
|
57
|
+
type: 'process';
|
|
58
|
+
conversation_id: string;
|
|
59
|
+
running: boolean;
|
|
60
|
+
} | {
|
|
61
|
+
type: 'commands';
|
|
62
|
+
conversation_id: string;
|
|
63
|
+
commands: readonly unknown[];
|
|
64
|
+
} | {
|
|
65
|
+
type: 'options';
|
|
66
|
+
conversation_id: string;
|
|
67
|
+
options: readonly unknown[];
|
|
68
|
+
} | {
|
|
69
|
+
type: 'signal';
|
|
70
|
+
service_mode: string;
|
|
52
71
|
};
|
|
53
72
|
export type HouseStream = {
|
|
54
73
|
observe(receive: (frame: HouseStreamFrame) => void): () => void;
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -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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AO,EAAE,CAAA;CAAE,GAC3E;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,eAAe,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,SAAS,OAAO,EAAE,CAAA;CAAE,GACzE;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":["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 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 | {\n type: 'draft';\n conversation_id: string;\n
|
|
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 | '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};\n\nexport type HouseStreamFrame =\n | {\n type: 'entries';\n authority: string;\n position: string;\n log_epoch: string;\n entries: readonly HouseStreamEntry[];\n }\n | {\n type: 'draft';\n conversation_id: string;\n turn_id: string;\n text: string;\n blocks: readonly unknown[];\n steps: readonly unknown[];\n }\n | { type: 'message'; conversation_id: string; message: unknown }\n | { type: 'working-note'; conversation_id: string; note_id: string; text: string }\n | { type: 'process'; conversation_id: string; running: boolean }\n | { type: 'commands'; conversation_id: string; commands: readonly unknown[] }\n | { type: 'options'; conversation_id: string; options: readonly unknown[] }\n | { type: 'signal'; service_mode: string };\n\nexport type HouseStream = {\n observe(receive: (frame: HouseStreamFrame) => void): () => void;\n opened(notify: () => void): () => void;\n};\n\nexport type HouseDoor = {\n door(route: string, body: unknown): Promise<HouseDoorAnswer>;\n stream: HouseStream;\n};\n\nexport type HouseTransport = HouseDoor & {\n transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;\n};\n\nexport type HouseSiteTransport = HouseDoor & {\n online(): boolean;\n read(route: string): Promise<HouseDoorAnswer>;\n};\n"],"names":["DOOR_DISCOVER","DOOR_BOOTSTRAP","DOOR_ENUMERATE","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_REVISIONS","SITE_DOOR_DISCOVER","SITE_DOOR_BOOTSTRAP","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","PRIVATE_LOCATOR"],"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/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,
|
|
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,wBAAwB,CAAC;AAMhC,eAAO,MAAM,uBAAuB,QAAkB,CAAC;AAEvD,eAAO,MAAM,iBAAiB,KAAK,CAAC;AAEpC,eAAO,MAAM,gBAAgB,QAAuC,CAAC;AAErE,MAAM,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAE/D,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,GACvD;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AA2GrD,wBAAgB,YAAY,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,GAAG,SAAS,GAAG,aAAa,CAQ1F;AAED,MAAM,MAAM,aAAa,GAAG;IAC1B,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B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AAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,aAAa,CAiDf"}
|
package/dist/write.js
CHANGED
|
@@ -221,6 +221,11 @@ function affectedOf(held) {
|
|
|
221
221
|
}
|
|
222
222
|
export function mutationOutcome(status, body, locator, handle) {
|
|
223
223
|
const refusal = doorRefusal(body);
|
|
224
|
+
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
225
|
+
return {
|
|
226
|
+
kind: 'write-halted'
|
|
227
|
+
};
|
|
228
|
+
}
|
|
224
229
|
if (refusal !== null && refusal.code === 'rate_limited') {
|
|
225
230
|
const reset = refusal.fields.retry_at;
|
|
226
231
|
return {
|
|
@@ -317,6 +322,25 @@ export function revisionBody(input) {
|
|
|
317
322
|
}
|
|
318
323
|
};
|
|
319
324
|
}
|
|
325
|
+
function revisionAuthor(entry) {
|
|
326
|
+
const user = entry.author_user;
|
|
327
|
+
const site = entry.author_site;
|
|
328
|
+
const name = entry.author_site_name;
|
|
329
|
+
if (typeof user === 'string' && site === undefined && name === undefined) {
|
|
330
|
+
return {
|
|
331
|
+
kind: 'user',
|
|
332
|
+
id: user
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
if (user === null && typeof site === 'string' && typeof name === 'string') {
|
|
336
|
+
return {
|
|
337
|
+
kind: 'site',
|
|
338
|
+
id: site,
|
|
339
|
+
name
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return null;
|
|
343
|
+
}
|
|
320
344
|
export function historyOutcome(status, body, locator, request) {
|
|
321
345
|
const classified = classifyDoor(status, body, locator);
|
|
322
346
|
if (classified !== null) {
|
|
@@ -370,14 +394,15 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
370
394
|
};
|
|
371
395
|
const revisions = [];
|
|
372
396
|
for (const entry of entries){
|
|
373
|
-
|
|
397
|
+
const author = revisionAuthor(entry);
|
|
398
|
+
if (typeof entry.revision !== 'string' || author === null || typeof entry.created_at !== 'string') {
|
|
374
399
|
return {
|
|
375
400
|
kind: 'transport-uncertainty'
|
|
376
401
|
};
|
|
377
402
|
}
|
|
378
403
|
revisions.push({
|
|
379
404
|
revision: entry.revision,
|
|
380
|
-
author
|
|
405
|
+
author,
|
|
381
406
|
time: entry.created_at
|
|
382
407
|
});
|
|
383
408
|
}
|