@agentshouse/mdruntime-adapter 0.1.0-alpha.15 → 0.1.0-alpha.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +9 -1
- package/dist/actions.d.ts +3 -8
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +54 -123
- package/dist/actions.js.map +1 -1
- package/dist/adapter.js +5 -5
- package/dist/adapter.js.map +1 -1
- package/dist/discovery.d.ts +0 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +5 -20
- package/dist/discovery.js.map +1 -1
- package/dist/read.d.ts +0 -2
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +5 -8
- package/dist/read.js.map +1 -1
- package/dist/site.js +2 -2
- package/dist/site.js.map +1 -1
- package/dist/stream.d.ts +3 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +19 -43
- package/dist/stream.js.map +1 -1
- package/dist/transport.d.ts +1 -3
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -1
- package/dist/transport.js.map +1 -1
- package/package.json +2 -2
package/dist/discovery.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PRIVATE_LOCATOR } from './transport.js';
|
|
3
3
|
import { readPosition, roomVersion } from './version.js';
|
|
4
4
|
export const ROOM_CONTRACT_VERSION = 1;
|
|
5
5
|
export const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';
|
|
@@ -59,7 +59,7 @@ function parseOperations(value) {
|
|
|
59
59
|
function parseAuthority(value) {
|
|
60
60
|
if (typeof value !== 'object' || value === null) return null;
|
|
61
61
|
const held = value;
|
|
62
|
-
if (held.kind !== 'room'
|
|
62
|
+
if (held.kind !== 'room') return null;
|
|
63
63
|
if (typeof held.name !== 'string' || held.name.length === 0) return null;
|
|
64
64
|
if (typeof held.collection_root !== 'string' || typeof held.model_root !== 'string') return null;
|
|
65
65
|
if (held.managed_replication !== 'admitted' && held.managed_replication !== 'unavailable') {
|
|
@@ -69,24 +69,9 @@ function parseAuthority(value) {
|
|
|
69
69
|
const protectedPaths = stringList(held.protected_paths);
|
|
70
70
|
const operations = parseOperations(held.operations);
|
|
71
71
|
if (at === null || protectedPaths === null || operations === null) return null;
|
|
72
|
-
if (held.kind === 'private') {
|
|
73
|
-
return {
|
|
74
|
-
kind: 'private',
|
|
75
|
-
roomRef: PRIVATE_AUTHORITY,
|
|
76
|
-
roomHandle: null,
|
|
77
|
-
name: held.name,
|
|
78
|
-
collectionRoot: held.collection_root,
|
|
79
|
-
modelRoot: held.model_root,
|
|
80
|
-
managedReplication: held.managed_replication,
|
|
81
|
-
protectedPaths,
|
|
82
|
-
operations,
|
|
83
|
-
...at
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
72
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;
|
|
87
|
-
if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;
|
|
73
|
+
if (held.room_handle !== null && (typeof held.room_handle !== 'string' || held.room_handle.length === 0)) return null;
|
|
88
74
|
return {
|
|
89
|
-
kind: 'room',
|
|
90
75
|
roomRef: held.room_ref,
|
|
91
76
|
roomHandle: held.room_handle,
|
|
92
77
|
name: held.name,
|
|
@@ -213,7 +198,7 @@ export function siteSlots(document) {
|
|
|
213
198
|
}));
|
|
214
199
|
}
|
|
215
200
|
export function locatorOf(authority) {
|
|
216
|
-
return authority.roomHandle ??
|
|
201
|
+
return authority.roomHandle ?? PRIVATE_LOCATOR;
|
|
217
202
|
}
|
|
218
203
|
export function trackedFrom(document) {
|
|
219
204
|
return document.authorities.map((authority)=>({
|
|
@@ -222,7 +207,7 @@ export function trackedFrom(document) {
|
|
|
222
207
|
handle: authority.roomHandle ?? undefined,
|
|
223
208
|
collectionRoot: authority.collectionRoot,
|
|
224
209
|
modelRoot: authority.modelRoot,
|
|
225
|
-
modelRoots: authority.
|
|
210
|
+
modelRoots: authority.roomHandle === null ? [
|
|
226
211
|
authority.modelRoot,
|
|
227
212
|
PROVIDER_SELECTION_MODEL_ROOT
|
|
228
213
|
] : [
|
package/dist/discovery.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/discovery.ts"],"sourcesContent":["import type {\n Capability,\n DiscoveredRoom,\n Discovery,\n ProviderLimit,\n Retention,\n TypedSelection,\n} from '@agentshouse/mdruntime';\nimport { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';\nimport { PRIVATE_AUTHORITY } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport const ROOM_CONTRACT_VERSION = 1;\n\nexport const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';\n\nexport const ROOM_VERSION_NOTIFICATIONS = 'room-version-notifications';\n\nexport const PROVIDER_ACTIONS = 'provider-actions';\n\nexport const MOVE_REFERENCE_REWRITES = 'move-reference-rewrites';\n\nexport const DISCOVER_PREFIXES: readonly string[] = ['/'];\n\nexport const PROVIDER_SELECTION_ROOTS: readonly string[] = ['agents', 'house'];\n\nexport const PROVIDER_SELECTION_MODEL_ROOT = 'house/settings/model';\n\nexport type HouseBounds = {\n max_authored_file_bytes: number;\n max_batch_operations: number;\n max_path_length: number;\n max_path_depth: number;\n max_mount_files: number;\n max_mount_bytes: number;\n change_retention_seconds: number;\n operation_retention_seconds: number;\n};\n\nexport type HouseOperations = {\n read: readonly string[];\n sync: readonly string[];\n write: readonly string[];\n delete: readonly string[];\n};\n\nexport type HouseAuthority = LogPosition & {\n kind: 'room' | 'private';\n roomRef: string;\n roomHandle: string | null;\n name: string;\n collectionRoot: string;\n modelRoot: string;\n managedReplication: 'admitted' | 'unavailable';\n protectedPaths: readonly string[];\n operations: HouseOperations;\n};\n\nexport type HouseDiscoveryDocument = {\n bounds: HouseBounds;\n mdModelVersion: string;\n authorities: readonly HouseAuthority[];\n actions: readonly string[];\n};\n\nexport type TrackedAuthority = LogPosition & {\n locator: string;\n authority: string;\n handle: string | undefined;\n collectionRoot: string;\n modelRoot: string;\n modelRoots: readonly string[];\n};\n\nexport type HouseSiteEntry = {\n roomRef: string;\n segment: string;\n};\n\nexport type HouseSiteSlot = {\n slot: string;\n entries: readonly HouseSiteEntry[];\n};\n\nexport type HouseSiteAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string;\n collectionRoot: string;\n modelRoot: string;\n};\n\nexport type HouseSiteDiscovery = {\n bounds: HouseBounds;\n mdModelVersion: string;\n slots: readonly HouseSiteSlot[];\n authorities: readonly HouseSiteAuthority[];\n};\n\nexport type SiteTracked = TrackedAuthority & { handle: string };\n\nconst BOUND_KEYS: readonly (keyof HouseBounds)[] = [\n 'max_authored_file_bytes',\n 'max_batch_operations',\n 'max_path_length',\n 'max_path_depth',\n 'max_mount_files',\n 'max_mount_bytes',\n 'change_retention_seconds',\n 'operation_retention_seconds',\n];\n\nconst OPERATION_KEYS: readonly (keyof HouseOperations)[] = ['read', 'sync', 'write', 'delete'];\n\nfunction stringList(value: unknown): readonly string[] | null {\n if (!Array.isArray(value)) return null;\n return value.every((entry) => typeof entry === 'string') ? (value as string[]) : null;\n}\n\nfunction parseBounds(value: unknown): HouseBounds | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const bounds: Partial<HouseBounds> = {};\n for (const key of BOUND_KEYS) {\n const amount = held[key];\n if (typeof amount !== 'number' || !Number.isFinite(amount)) return null;\n bounds[key] = amount;\n }\n return bounds as HouseBounds;\n}\n\nfunction parseOperations(value: unknown): HouseOperations | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const operations: Partial<Record<keyof HouseOperations, readonly string[]>> = {};\n for (const key of OPERATION_KEYS) {\n const scopes = stringList(held[key]);\n if (scopes === null) return null;\n operations[key] = scopes;\n }\n return operations as HouseOperations;\n}\n\nfunction parseAuthority(value: unknown): HouseAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room' && held.kind !== 'private') return null;\n if (typeof held.name !== 'string' || held.name.length === 0) return null;\n if (typeof held.collection_root !== 'string' || typeof held.model_root !== 'string') return null;\n if (held.managed_replication !== 'admitted' && held.managed_replication !== 'unavailable') {\n return null;\n }\n const at = readPosition(held);\n const protectedPaths = stringList(held.protected_paths);\n const operations = parseOperations(held.operations);\n if (at === null || protectedPaths === null || operations === null) return null;\n if (held.kind === 'private') {\n return {\n kind: 'private',\n roomRef: PRIVATE_AUTHORITY,\n roomHandle: null,\n name: held.name,\n collectionRoot: held.collection_root,\n modelRoot: held.model_root,\n managedReplication: held.managed_replication,\n protectedPaths,\n operations,\n ...at,\n };\n }\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;\n return {\n kind: 'room',\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n name: held.name,\n collectionRoot: held.collection_root,\n modelRoot: held.model_root,\n managedReplication: held.managed_replication,\n protectedPaths,\n operations,\n ...at,\n };\n}\n\nexport function parseDiscovery(body: unknown): HouseDiscoveryDocument | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n const actions = stringList(held.actions);\n if (\n actions === null ||\n new Set(actions).size !== actions.length ||\n actions.some((name) => name.length === 0)\n )\n return null;\n if (!Array.isArray(held.authorities)) return null;\n const authorities: HouseAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, authorities, actions };\n}\n\nfunction parseSiteEntry(value: unknown): HouseSiteEntry | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.segment !== 'string' || held.segment.length === 0) return null;\n return { roomRef: held.room_ref, segment: held.segment };\n}\n\nfunction parseSiteSlot(value: unknown): HouseSiteSlot | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.slot !== 'string' || held.slot.length === 0) return null;\n if (!Array.isArray(held.entries)) return null;\n const entries: HouseSiteEntry[] = [];\n for (const entry of held.entries) {\n const parsed = parseSiteEntry(entry);\n if (parsed === null) return null;\n entries.push(parsed);\n }\n return { slot: held.slot, entries };\n}\n\nfunction parseSiteAuthority(value: unknown): HouseSiteAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;\n if (typeof held.collection_root !== 'string' || typeof held.model_root !== 'string') return null;\n const at = readPosition(held);\n if (at === null) return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n collectionRoot: held.collection_root,\n modelRoot: held.model_root,\n ...at,\n };\n}\n\nexport function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n if (!Array.isArray(held.slots) || !Array.isArray(held.authorities)) return null;\n const slots: HouseSiteSlot[] = [];\n for (const entry of held.slots) {\n const slot = parseSiteSlot(entry);\n if (slot === null) return null;\n slots.push(slot);\n }\n const authorities: HouseSiteAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseSiteAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, slots, authorities };\n}\n\nexport function siteTracked(document: HouseSiteDiscovery): SiteTracked[] {\n return document.authorities.map((authority) => ({\n locator: authority.roomRef,\n authority: authority.roomRef,\n handle: authority.roomHandle,\n collectionRoot: authority.collectionRoot,\n modelRoot: authority.modelRoot,\n modelRoots: [authority.modelRoot],\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function siteSlots(document: HouseSiteDiscovery): Discovery['slots'] {\n return document.slots.map(({ slot, entries }) => ({\n slot,\n entries: entries.map(({ roomRef, segment }) => ({ locator: roomRef, segment })),\n }));\n}\n\nexport function locatorOf(authority: HouseAuthority): string {\n return authority.roomHandle ?? PRIVATE_AUTHORITY;\n}\n\nexport function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[] {\n return document.authorities.map((authority) => ({\n locator: locatorOf(authority),\n authority: authority.roomRef,\n handle: authority.roomHandle ?? undefined,\n collectionRoot: authority.collectionRoot,\n modelRoot: authority.modelRoot,\n modelRoots:\n authority.kind === 'private'\n ? [authority.modelRoot, PROVIDER_SELECTION_MODEL_ROOT]\n : [authority.modelRoot],\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function providerLimits(bounds: HouseBounds): readonly ProviderLimit[] {\n return [\n { name: 'document-size', value: bounds.max_authored_file_bytes },\n { name: 'change-batch-operations', value: bounds.max_batch_operations },\n { name: 'path-length', value: bounds.max_path_length },\n { name: 'path-depth', value: bounds.max_path_depth },\n { name: 'write-rate' },\n { name: 'content-ceiling' },\n ];\n}\n\nexport function declaredRetention(bounds: HouseBounds): Retention {\n return {\n history: { kind: 'no-declared-time-bound' },\n outcome: bounds.operation_retention_seconds,\n refreshHorizon: bounds.change_retention_seconds,\n };\n}\n\nexport function capabilities(actions: readonly string[]): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n {\n name: PROVIDER_ACTIONS,\n actions: declaredActions(actions),\n conversationCards: HOUSE_CONVERSATION_CARDS,\n },\n { name: MOVE_REFERENCE_REWRITES },\n ];\n}\n\nexport function siteCapabilities(): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },\n ];\n}\n\nexport function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection {\n return { roots: [...PROVIDER_SELECTION_ROOTS], attachedModel };\n}\n\nexport function discoveredRoom(\n authority: HouseAuthority,\n attachedModel: DiscoveredRoom['attachedModel'],\n typedSelection: TypedSelection | undefined,\n): DiscoveredRoom {\n return {\n name: authority.name,\n locator: locatorOf(authority),\n collectionRoot: authority.collectionRoot,\n roomVersion: roomVersion(authority),\n operations: {\n read: [...authority.operations.read],\n sync: [...authority.operations.sync],\n write: [...authority.operations.write],\n delete: [...authority.operations.delete],\n },\n replica: { selection: locatorOf(authority), admission: authority.managedReplication },\n attachedModel,\n ...(typedSelection === undefined ? {} : { typedSelection }),\n providerOwnedPaths: [...authority.protectedPaths],\n };\n}\n\nexport function mapDiscovery(\n document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>,\n rooms: readonly DiscoveredRoom[],\n declared: readonly Capability[],\n): Discovery {\n return {\n kind: 'discovery',\n supportedVersions: [ROOM_CONTRACT_VERSION],\n mdModel: { identity: MD_MODEL_IDENTITY, version: document.mdModelVersion },\n rooms,\n capabilities: declared,\n providerLimits: providerLimits(document.bounds),\n retention: declaredRetention(document.bounds),\n };\n}\n"],"names":["declaredActions","HOUSE_CONVERSATION_CARDS","PRIVATE_AUTHORITY","readPosition","roomVersion","ROOM_CONTRACT_VERSION","MD_MODEL_IDENTITY","ROOM_VERSION_NOTIFICATIONS","PROVIDER_ACTIONS","MOVE_REFERENCE_REWRITES","DISCOVER_PREFIXES","PROVIDER_SELECTION_ROOTS","PROVIDER_SELECTION_MODEL_ROOT","BOUND_KEYS","OPERATION_KEYS","stringList","value","Array","isArray","every","entry","parseBounds","held","bounds","key","amount","Number","isFinite","parseOperations","operations","scopes","parseAuthority","kind","name","length","collection_root","model_root","managed_replication","at","protectedPaths","protected_paths","roomRef","roomHandle","collectionRoot","modelRoot","managedReplication","room_ref","room_handle","parseDiscovery","body","md_model_version","actions","Set","size","some","authorities","authority","push","mdModelVersion","parseSiteEntry","segment","parseSiteSlot","slot","entries","parsed","parseSiteAuthority","parseSiteDiscovery","slots","siteTracked","document","map","locator","handle","modelRoots","position","logEpoch","siteSlots","locatorOf","trackedFrom","undefined","providerLimits","max_authored_file_bytes","max_batch_operations","max_path_length","max_path_depth","declaredRetention","history","outcome","operation_retention_seconds","refreshHorizon","change_retention_seconds","capabilities","conversationCards","siteCapabilities","inputShape","resultKind","providerSelection","attachedModel","roots","discoveredRoom","typedSelection","read","sync","write","delete","replica","selection","admission","providerOwnedPaths","mapDiscovery","rooms","declared","supportedVersions","mdModel","identity","version","retention"],"mappings":"AAQA,SAASA,eAAe,EAAEC,wBAAwB,QAAQ,eAAe;AACzE,SAASC,iBAAiB,QAAQ,iBAAiB;AACnD,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAE3E,OAAO,MAAMC,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,oBAAoB,uBAAuB;AAExD,OAAO,MAAMC,6BAA6B,6BAA6B;AAEvE,OAAO,MAAMC,mBAAmB,mBAAmB;AAEnD,OAAO,MAAMC,0BAA0B,0BAA0B;AAEjE,OAAO,MAAMC,oBAAuC;IAAC;CAAI,CAAC;AAE1D,OAAO,MAAMC,2BAA8C;IAAC;IAAU;CAAQ,CAAC;AAE/E,OAAO,MAAMC,gCAAgC,uBAAuB;AA0EpE,MAAMC,aAA6C;IACjD;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,iBAAqD;IAAC;IAAQ;IAAQ;IAAS;CAAS;AAE9F,SAASC,WAAWC,KAAc;IAChC,IAAI,CAACC,MAAMC,OAAO,CAACF,QAAQ,OAAO;IAClC,OAAOA,MAAMG,KAAK,CAAC,CAACC,QAAU,OAAOA,UAAU,YAAaJ,QAAqB;AACnF;AAEA,SAASK,YAAYL,KAAc;IACjC,IAAI,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AAI9C,UAAU3B,UAAU,CAACyE,IAAI;aAAC;YACpCC,OAAO;mBAAI/C,UAAU3B,UAAU,CAAC0E,KAAK;aAAC;YACtCC,QAAQ;mBAAIhD,UAAU3B,UAAU,CAAC2E,MAAM;aAAC;QAC1C;QACAC,SAAS;YAAEC,WAAW7B,UAAUrB;YAAYmD,WAAWnD,UAAUX,kBAAkB;QAAC;QACpFoD;QACA,GAAIG,mBAAmBrB,YAAY,CAAC,IAAI;YAAEqB;QAAe,CAAC;QAC1DQ,oBAAoB;eAAIpD,UAAUjB,cAAc;SAAC;IACnD;AACF;AAEA,OAAO,SAASsE,aACdxC,QAAmE,EACnEyC,KAAgC,EAChCC,QAA+B;IAE/B,OAAO;QACL/E,MAAM;QACNgF,mBAAmB;YAAC3G;SAAsB;QAC1C4G,SAAS;YAAEC,UAAU5G;YAAmB6G,SAAS9C,SAASX,cAAc;QAAC;QACzEoD;QACAnB,cAAcoB;QACd/B,gBAAgBA,eAAeX,SAAS9C,MAAM;QAC9C6F,WAAW/B,kBAAkBhB,SAAS9C,MAAM;IAC9C;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/discovery.ts"],"sourcesContent":["import type {\n Capability,\n DiscoveredRoom,\n Discovery,\n ProviderLimit,\n Retention,\n TypedSelection,\n} from '@agentshouse/mdruntime';\nimport { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';\nimport { PRIVATE_LOCATOR } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport const ROOM_CONTRACT_VERSION = 1;\n\nexport const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';\n\nexport const ROOM_VERSION_NOTIFICATIONS = 'room-version-notifications';\n\nexport const PROVIDER_ACTIONS = 'provider-actions';\n\nexport const MOVE_REFERENCE_REWRITES = 'move-reference-rewrites';\n\nexport const DISCOVER_PREFIXES: readonly string[] = ['/'];\n\nexport const PROVIDER_SELECTION_ROOTS: readonly string[] = ['agents', 'house'];\n\nexport const PROVIDER_SELECTION_MODEL_ROOT = 'house/settings/model';\n\nexport type HouseBounds = {\n max_authored_file_bytes: number;\n max_batch_operations: number;\n max_path_length: number;\n max_path_depth: number;\n max_mount_files: number;\n max_mount_bytes: number;\n change_retention_seconds: number;\n operation_retention_seconds: number;\n};\n\nexport type HouseOperations = {\n read: readonly string[];\n sync: readonly string[];\n write: readonly string[];\n delete: readonly string[];\n};\n\nexport type HouseAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string | null;\n name: string;\n collectionRoot: string;\n modelRoot: string;\n managedReplication: 'admitted' | 'unavailable';\n protectedPaths: readonly string[];\n operations: HouseOperations;\n};\n\nexport type HouseDiscoveryDocument = {\n bounds: HouseBounds;\n mdModelVersion: string;\n authorities: readonly HouseAuthority[];\n actions: readonly string[];\n};\n\nexport type TrackedAuthority = LogPosition & {\n locator: string;\n authority: string;\n handle: string | undefined;\n collectionRoot: string;\n modelRoot: string;\n modelRoots: readonly string[];\n};\n\nexport type HouseSiteEntry = {\n roomRef: string;\n segment: string;\n};\n\nexport type HouseSiteSlot = {\n slot: string;\n entries: readonly HouseSiteEntry[];\n};\n\nexport type HouseSiteAuthority = LogPosition & {\n roomRef: string;\n roomHandle: string;\n collectionRoot: string;\n modelRoot: string;\n};\n\nexport type HouseSiteDiscovery = {\n bounds: HouseBounds;\n mdModelVersion: string;\n slots: readonly HouseSiteSlot[];\n authorities: readonly HouseSiteAuthority[];\n};\n\nexport type SiteTracked = TrackedAuthority & { handle: string };\n\nconst BOUND_KEYS: readonly (keyof HouseBounds)[] = [\n 'max_authored_file_bytes',\n 'max_batch_operations',\n 'max_path_length',\n 'max_path_depth',\n 'max_mount_files',\n 'max_mount_bytes',\n 'change_retention_seconds',\n 'operation_retention_seconds',\n];\n\nconst OPERATION_KEYS: readonly (keyof HouseOperations)[] = ['read', 'sync', 'write', 'delete'];\n\nfunction stringList(value: unknown): readonly string[] | null {\n if (!Array.isArray(value)) return null;\n return value.every((entry) => typeof entry === 'string') ? (value as string[]) : null;\n}\n\nfunction parseBounds(value: unknown): HouseBounds | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const bounds: Partial<HouseBounds> = {};\n for (const key of BOUND_KEYS) {\n const amount = held[key];\n if (typeof amount !== 'number' || !Number.isFinite(amount)) return null;\n bounds[key] = amount;\n }\n return bounds as HouseBounds;\n}\n\nfunction parseOperations(value: unknown): HouseOperations | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n const operations: Partial<Record<keyof HouseOperations, readonly string[]>> = {};\n for (const key of OPERATION_KEYS) {\n const scopes = stringList(held[key]);\n if (scopes === null) return null;\n operations[key] = scopes;\n }\n return operations as HouseOperations;\n}\n\nfunction parseAuthority(value: unknown): HouseAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.name !== 'string' || held.name.length === 0) return null;\n if (typeof held.collection_root !== 'string' || typeof held.model_root !== 'string') return null;\n if (held.managed_replication !== 'admitted' && held.managed_replication !== 'unavailable') {\n return null;\n }\n const at = readPosition(held);\n const protectedPaths = stringList(held.protected_paths);\n const operations = parseOperations(held.operations);\n if (at === null || protectedPaths === null || operations === null) return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (\n held.room_handle !== null &&\n (typeof held.room_handle !== 'string' || held.room_handle.length === 0)\n )\n return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n name: held.name,\n collectionRoot: held.collection_root,\n modelRoot: held.model_root,\n managedReplication: held.managed_replication,\n protectedPaths,\n operations,\n ...at,\n };\n}\n\nexport function parseDiscovery(body: unknown): HouseDiscoveryDocument | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n const actions = stringList(held.actions);\n if (\n actions === null ||\n new Set(actions).size !== actions.length ||\n actions.some((name) => name.length === 0)\n )\n return null;\n if (!Array.isArray(held.authorities)) return null;\n const authorities: HouseAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, authorities, actions };\n}\n\nfunction parseSiteEntry(value: unknown): HouseSiteEntry | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.segment !== 'string' || held.segment.length === 0) return null;\n return { roomRef: held.room_ref, segment: held.segment };\n}\n\nfunction parseSiteSlot(value: unknown): HouseSiteSlot | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.slot !== 'string' || held.slot.length === 0) return null;\n if (!Array.isArray(held.entries)) return null;\n const entries: HouseSiteEntry[] = [];\n for (const entry of held.entries) {\n const parsed = parseSiteEntry(entry);\n if (parsed === null) return null;\n entries.push(parsed);\n }\n return { slot: held.slot, entries };\n}\n\nfunction parseSiteAuthority(value: unknown): HouseSiteAuthority | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (held.kind !== 'room') return null;\n if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;\n if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;\n if (typeof held.collection_root !== 'string' || typeof held.model_root !== 'string') return null;\n const at = readPosition(held);\n if (at === null) return null;\n return {\n roomRef: held.room_ref,\n roomHandle: held.room_handle,\n collectionRoot: held.collection_root,\n modelRoot: held.model_root,\n ...at,\n };\n}\n\nexport function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null {\n if (typeof body !== 'object' || body === null) return null;\n const held = body as Record<string, unknown>;\n const bounds = parseBounds(held.bounds);\n if (bounds === null) return null;\n if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;\n if (!Array.isArray(held.slots) || !Array.isArray(held.authorities)) return null;\n const slots: HouseSiteSlot[] = [];\n for (const entry of held.slots) {\n const slot = parseSiteSlot(entry);\n if (slot === null) return null;\n slots.push(slot);\n }\n const authorities: HouseSiteAuthority[] = [];\n for (const entry of held.authorities) {\n const authority = parseSiteAuthority(entry);\n if (authority === null) return null;\n authorities.push(authority);\n }\n return { bounds, mdModelVersion: held.md_model_version, slots, authorities };\n}\n\nexport function siteTracked(document: HouseSiteDiscovery): SiteTracked[] {\n return document.authorities.map((authority) => ({\n locator: authority.roomRef,\n authority: authority.roomRef,\n handle: authority.roomHandle,\n collectionRoot: authority.collectionRoot,\n modelRoot: authority.modelRoot,\n modelRoots: [authority.modelRoot],\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function siteSlots(document: HouseSiteDiscovery): Discovery['slots'] {\n return document.slots.map(({ slot, entries }) => ({\n slot,\n entries: entries.map(({ roomRef, segment }) => ({ locator: roomRef, segment })),\n }));\n}\n\nexport function locatorOf(authority: HouseAuthority): string {\n return authority.roomHandle ?? PRIVATE_LOCATOR;\n}\n\nexport function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[] {\n return document.authorities.map((authority) => ({\n locator: locatorOf(authority),\n authority: authority.roomRef,\n handle: authority.roomHandle ?? undefined,\n collectionRoot: authority.collectionRoot,\n modelRoot: authority.modelRoot,\n modelRoots:\n authority.roomHandle === null\n ? [authority.modelRoot, PROVIDER_SELECTION_MODEL_ROOT]\n : [authority.modelRoot],\n position: authority.position,\n logEpoch: authority.logEpoch,\n }));\n}\n\nexport function providerLimits(bounds: HouseBounds): readonly ProviderLimit[] {\n return [\n { name: 'document-size', value: bounds.max_authored_file_bytes },\n { name: 'change-batch-operations', value: bounds.max_batch_operations },\n { name: 'path-length', value: bounds.max_path_length },\n { name: 'path-depth', value: bounds.max_path_depth },\n { name: 'write-rate' },\n { name: 'content-ceiling' },\n ];\n}\n\nexport function declaredRetention(bounds: HouseBounds): Retention {\n return {\n history: { kind: 'no-declared-time-bound' },\n outcome: bounds.operation_retention_seconds,\n refreshHorizon: bounds.change_retention_seconds,\n };\n}\n\nexport function capabilities(actions: readonly string[]): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n {\n name: PROVIDER_ACTIONS,\n actions: declaredActions(actions),\n conversationCards: HOUSE_CONVERSATION_CARDS,\n },\n { name: MOVE_REFERENCE_REWRITES },\n ];\n}\n\nexport function siteCapabilities(): readonly Capability[] {\n return [\n { name: ROOM_VERSION_NOTIFICATIONS },\n { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },\n ];\n}\n\nexport function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection {\n return { roots: [...PROVIDER_SELECTION_ROOTS], attachedModel };\n}\n\nexport function discoveredRoom(\n authority: HouseAuthority,\n attachedModel: DiscoveredRoom['attachedModel'],\n typedSelection: TypedSelection | undefined,\n): DiscoveredRoom {\n return {\n name: authority.name,\n locator: locatorOf(authority),\n collectionRoot: authority.collectionRoot,\n roomVersion: roomVersion(authority),\n operations: {\n read: [...authority.operations.read],\n sync: [...authority.operations.sync],\n write: [...authority.operations.write],\n delete: [...authority.operations.delete],\n },\n replica: { selection: locatorOf(authority), admission: authority.managedReplication },\n attachedModel,\n ...(typedSelection === undefined ? {} : { typedSelection }),\n providerOwnedPaths: [...authority.protectedPaths],\n };\n}\n\nexport function mapDiscovery(\n document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>,\n rooms: readonly DiscoveredRoom[],\n declared: readonly Capability[],\n): Discovery {\n return {\n kind: 'discovery',\n supportedVersions: [ROOM_CONTRACT_VERSION],\n mdModel: { identity: MD_MODEL_IDENTITY, version: document.mdModelVersion },\n rooms,\n capabilities: declared,\n providerLimits: providerLimits(document.bounds),\n retention: declaredRetention(document.bounds),\n };\n}\n"],"names":["declaredActions","HOUSE_CONVERSATION_CARDS","PRIVATE_LOCATOR","readPosition","roomVersion","ROOM_CONTRACT_VERSION","MD_MODEL_IDENTITY","ROOM_VERSION_NOTIFICATIONS","PROVIDER_ACTIONS","MOVE_REFERENCE_REWRITES","DISCOVER_PREFIXES","PROVIDER_SELECTION_ROOTS","PROVIDER_SELECTION_MODEL_ROOT","BOUND_KEYS","OPERATION_KEYS","stringList","value","Array","isArray","every","entry","parseBounds","held","bounds","key","amount","Number","isFinite","parseOperations","operations","scopes","parseAuthority","kind","name","length","collection_root","model_root","managed_replication","at","protectedPaths","protected_paths","room_ref","room_handle","roomRef","roomHandle","collectionRoot","modelRoot","managedReplication","parseDiscovery","body","md_model_version","actions","Set","size","some","authorities","authority","push","mdModelVersion","parseSiteEntry","segment","parseSiteSlot","slot","entries","parsed","parseSiteAuthority","parseSiteDiscovery","slots","siteTracked","document","map","locator","handle","modelRoots","position","logEpoch","siteSlots","locatorOf","trackedFrom","undefined","providerLimits","max_authored_file_bytes","max_batch_operations","max_path_length","max_path_depth","declaredRetention","history","outcome","operation_retention_seconds","refreshHorizon","change_retention_seconds","capabilities","conversationCards","siteCapabilities","inputShape","resultKind","providerSelection","attachedModel","roots","discoveredRoom","typedSelection","read","sync","write","delete","replica","selection","admission","providerOwnedPaths","mapDiscovery","rooms","declared","supportedVersions","mdModel","identity","version","retention"],"mappings":"AAQA,SAASA,eAAe,EAAEC,wBAAwB,QAAQ,eAAe;AACzE,SAASC,eAAe,QAAQ,iBAAiB;AACjD,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAE3E,OAAO,MAAMC,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,oBAAoB,uBAAuB;AAExD,OAAO,MAAMC,6BAA6B,6BAA6B;AAEvE,OAAO,MAAMC,mBAAmB,mBAAmB;AAEnD,OAAO,MAAMC,0BAA0B,0BAA0B;AAEjE,OAAO,MAAMC,oBAAuC;IAAC;CAAI,CAAC;AAE1D,OAAO,MAAMC,2BAA8C;IAAC;IAAU;CAAQ,CAAC;AAE/E,OAAO,MAAMC,gCAAgC,uBAAuB;AA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U3B,UAAU,CAACwE,IAAI;aAAC;YACpCC,MAAM;mBAAI9C,UAAU3B,UAAU,CAACyE,IAAI;aAAC;YACpCC,OAAO;mBAAI/C,UAAU3B,UAAU,CAAC0E,KAAK;aAAC;YACtCC,QAAQ;mBAAIhD,UAAU3B,UAAU,CAAC2E,MAAM;aAAC;QAC1C;QACAC,SAAS;YAAEC,WAAW7B,UAAUrB;YAAYmD,WAAWnD,UAAUT,kBAAkB;QAAC;QACpFkD;QACA,GAAIG,mBAAmBrB,YAAY,CAAC,IAAI;YAAEqB;QAAe,CAAC;QAC1DQ,oBAAoB;eAAIpD,UAAUjB,cAAc;SAAC;IACnD;AACF;AAEA,OAAO,SAASsE,aACdxC,QAAmE,EACnEyC,KAAgC,EAChCC,QAA+B;IAE/B,OAAO;QACL/E,MAAM;QACNgF,mBAAmB;YAAC3G;SAAsB;QAC1C4G,SAAS;YAAEC,UAAU5G;YAAmB6G,SAAS9C,SAASX,cAAc;QAAC;QACzEoD;QACAnB,cAAcoB;QACd/B,gBAAgBA,eAAeX,SAAS9C,MAAM;QAC9C6F,WAAW/B,kBAAkBhB,SAAS9C,MAAM;IAC9C;AACF"}
|
package/dist/read.d.ts
CHANGED
|
@@ -12,9 +12,7 @@ export type HouseContent = {
|
|
|
12
12
|
content: string;
|
|
13
13
|
};
|
|
14
14
|
export type HouseScope = LogPosition & {
|
|
15
|
-
scope: 'room' | 'private';
|
|
16
15
|
anchor: string;
|
|
17
|
-
roomHandle: string | undefined;
|
|
18
16
|
files: readonly HouseManifestFile[];
|
|
19
17
|
contents: readonly HouseContent[];
|
|
20
18
|
};
|
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5F,OAAO,EAA4B,KAAK,gBAAgB,EA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AAgB,GAAG,IAAI,CAa3F;AAED,wBAAgB,WAAW,CACzB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,gBAAgB,EACzB,eAAe,EAAE,MAAM,GACtB,aAAa,CA8Bf"}
|
package/dist/read.js
CHANGED
|
@@ -62,9 +62,10 @@ function parseScope(value, mode) {
|
|
|
62
62
|
if (typeof held.manifest !== 'object' || held.manifest === null) return null;
|
|
63
63
|
if (!Array.isArray(held.contents)) return null;
|
|
64
64
|
const manifest = held.manifest;
|
|
65
|
-
if (manifest.scope !== 'room'
|
|
65
|
+
if (manifest.scope !== 'room') return null;
|
|
66
66
|
const at = readPosition(manifest);
|
|
67
|
-
if (typeof manifest.anchor !== 'string' || at === null) return null;
|
|
67
|
+
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null) return null;
|
|
68
|
+
if (manifest.room_handle !== null && (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)) return null;
|
|
68
69
|
if (!Array.isArray(manifest.files)) return null;
|
|
69
70
|
const files = [];
|
|
70
71
|
for (const entry of manifest.files){
|
|
@@ -83,9 +84,7 @@ function parseScope(value, mode) {
|
|
|
83
84
|
});
|
|
84
85
|
}
|
|
85
86
|
return {
|
|
86
|
-
scope: manifest.scope,
|
|
87
87
|
anchor: manifest.anchor,
|
|
88
|
-
roomHandle: typeof manifest.room_handle === 'string' ? manifest.room_handle : undefined,
|
|
89
88
|
...at,
|
|
90
89
|
files,
|
|
91
90
|
contents
|
|
@@ -105,8 +104,7 @@ export function parseEnvelope(body) {
|
|
|
105
104
|
};
|
|
106
105
|
}
|
|
107
106
|
export function parseSiteBootstrap(body) {
|
|
108
|
-
|
|
109
|
-
return scope !== null && scope.scope === 'room' ? scope : null;
|
|
107
|
+
return parseScope(body, 'site');
|
|
110
108
|
}
|
|
111
109
|
function parseChange(value, mode) {
|
|
112
110
|
if (typeof value !== 'object' || value === null) return null;
|
|
@@ -216,8 +214,7 @@ export function advancedScope(scope, view) {
|
|
|
216
214
|
};
|
|
217
215
|
}
|
|
218
216
|
export function matchesScope(scope, tracked) {
|
|
219
|
-
|
|
220
|
-
return scope.roomHandle === tracked.handle || scope.anchor === tracked.authority;
|
|
217
|
+
return scope.anchor === tracked.authority;
|
|
221
218
|
}
|
|
222
219
|
export function withinRoot(path, root) {
|
|
223
220
|
return path === root || path.startsWith(`${root}/`);
|
package/dist/read.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/read.ts"],"sourcesContent":["import type { BootstrapPage, BootstrapResult, RefreshResult } from '@agentshouse/mdruntime';\nimport { PROVIDER_SELECTION_ROOTS, type TrackedAuthority } from './discovery.js';\nimport type { HouseMode } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport type HouseManifestFile = {\n path: string;\n revision: string | undefined;\n version: string;\n};\n\nexport type HouseContent = {\n path: string;\n content: string;\n};\n\nexport type HouseScope = LogPosition & {\n scope: 'room' | 'private';\n anchor: string;\n roomHandle: string | undefined;\n files: readonly HouseManifestFile[];\n contents: readonly HouseContent[];\n};\n\nexport type HouseEnvelope = {\n scopes: readonly HouseScope[];\n};\n\nexport type HouseGrant = {\n method: 'GET' | 'POST';\n operation: string;\n url: string;\n};\n\nexport type HouseChange =\n | { path: string; removed: true }\n | { path: string; content: string; revision: string | undefined; version: string }\n | { path: string; reference: { revision: string } };\n\nexport type HouseEnumeration = {\n authorities: readonly (LogPosition & {\n authority: string;\n changes: readonly HouseChange[];\n })[];\n};\n\nexport function authorityRoot(handle: string | undefined): string {\n return handle === undefined ? '/private' : `/rooms/${handle}`;\n}\n\nexport const ROOM_README = 'ROOM.md';\n\nexport function selectionRoots(tracked: TrackedAuthority): readonly string[] {\n if (tracked.handle === undefined) {\n return [tracked.collectionRoot, ...PROVIDER_SELECTION_ROOTS];\n }\n return [ROOM_README, tracked.collectionRoot];\n}\n\nexport function contentPrefixes(tracked: TrackedAuthority): readonly string[] {\n const root = authorityRoot(tracked.handle);\n return selectionRoots(tracked)\n .filter((entry) => entry !== ROOM_README)\n .map((entry) => `${root}/${entry}`);\n}\n\nexport function modelPrefix(tracked: TrackedAuthority, modelRoot: string): string {\n return `${authorityRoot(tracked.handle)}/${modelRoot}`;\n}\n\nexport function parseGrant(body: unknown): HouseGrant | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {\n return null;\n }\n const transfer = body.transfer as Record<string, unknown>;\n if (transfer.method !== 'GET' && transfer.method !== 'POST') return null;\n if (typeof transfer.operation !== 'string' || typeof transfer.url !== 'string') return null;\n return { method: transfer.method, operation: transfer.operation, url: transfer.url };\n}\n\nfunction parseFile(value: unknown, mode: HouseMode): HouseManifestFile | null {\n if (typeof value !== 'object' || value === null) return null;\n const file = value as Record<string, unknown>;\n if (typeof file.path !== 'string') return null;\n if (mode === 'site') {\n if (typeof file.sha256 !== 'string') return null;\n return { path: file.path, revision: undefined, version: file.sha256 };\n }\n if (typeof file.revision !== 'string') return null;\n return { path: file.path, revision: file.revision, version: file.revision };\n}\n\nfunction parseScope(value: unknown, mode: HouseMode): HouseScope | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.manifest !== 'object' || held.manifest === null) return null;\n if (!Array.isArray(held.contents)) return null;\n const manifest = held.manifest as Record<string, unknown>;\n if (manifest.scope !== 'room' && manifest.scope !== 'private') return null;\n const at = readPosition(manifest);\n if (typeof manifest.anchor !== 'string' || at === null) return null;\n if (!Array.isArray(manifest.files)) return null;\n const files: HouseManifestFile[] = [];\n for (const entry of manifest.files) {\n const file = parseFile(entry, mode);\n if (file === null) return null;\n files.push(file);\n }\n const contents: HouseContent[] = [];\n for (const entry of held.contents) {\n if (typeof entry !== 'object' || entry === null) return null;\n const content = entry as Record<string, unknown>;\n if (typeof content.path !== 'string' || typeof content.content !== 'string') return null;\n contents.push({ path: content.path, content: content.content });\n }\n return {\n scope: manifest.scope,\n anchor: manifest.anchor,\n roomHandle: typeof manifest.room_handle === 'string' ? manifest.room_handle : undefined,\n ...at,\n files,\n contents,\n };\n}\n\nexport function parseEnvelope(body: unknown): HouseEnvelope | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('scopes' in body) || !Array.isArray(body.scopes)) return null;\n const scopes: HouseScope[] = [];\n for (const entry of body.scopes) {\n const scope = parseScope(entry, 'credential');\n if (scope === null) return null;\n scopes.push(scope);\n }\n return { scopes };\n}\n\nexport function parseSiteBootstrap(body: unknown): HouseScope | null {\n const scope = parseScope(body, 'site');\n return scope !== null && scope.scope === 'room' ? scope : null;\n}\n\nfunction parseChange(value: unknown, mode: HouseMode): HouseChange | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.path !== 'string') return null;\n if (held.removed === true) return { path: held.path, removed: true };\n if (mode === 'site') {\n if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;\n return { path: held.path, content: held.content, revision: undefined, version: held.sha256 };\n }\n if (typeof held.content === 'string' && typeof held.revision === 'string') {\n return {\n path: held.path,\n content: held.content,\n revision: held.revision,\n version: held.revision,\n };\n }\n if (typeof held.reference === 'object' && held.reference !== null) {\n const reference = held.reference as Record<string, unknown>;\n if (typeof reference.revision !== 'string') return null;\n return { path: held.path, reference: { revision: reference.revision } };\n }\n return null;\n}\n\nexport function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('authorities' in body) || !Array.isArray(body.authorities)) return null;\n const authorities: HouseEnumeration['authorities'][number][] = [];\n for (const entry of body.authorities) {\n if (typeof entry !== 'object' || entry === null) return null;\n const held = entry as Record<string, unknown>;\n const at = readPosition(held);\n if (typeof held.authority !== 'string' || at === null) return null;\n if (!Array.isArray(held.changes)) return null;\n const changes: HouseChange[] = [];\n for (const change of held.changes) {\n const mapped = parseChange(change, mode);\n if (mapped === null) return null;\n changes.push(mapped);\n }\n authorities.push({ authority: held.authority, ...at, changes });\n }\n return { authorities };\n}\n\nexport function advancedScope(\n scope: HouseScope,\n view: HouseEnumeration['authorities'][number],\n): HouseScope {\n const files = new Map(scope.files.map((file) => [file.path, file]));\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n for (const change of view.changes) {\n files.delete(change.path);\n contents.delete(change.path);\n if ('removed' in change) continue;\n if ('content' in change) {\n files.set(change.path, {\n path: change.path,\n revision: change.revision,\n version: change.version,\n });\n contents.set(change.path, change.content);\n continue;\n }\n const { revision } = change.reference;\n files.set(change.path, { path: change.path, revision, version: revision });\n }\n return {\n ...scope,\n position: view.position,\n logEpoch: view.logEpoch,\n files: [...files.values()],\n contents: [...contents].map(([path, content]) => ({ path, content })),\n };\n}\n\nexport function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean {\n if (tracked.handle === undefined) return scope.scope === 'private';\n return scope.roomHandle === tracked.handle || scope.anchor === tracked.authority;\n}\n\nexport function withinRoot(path: string, root: string): boolean {\n return path === root || path.startsWith(`${root}/`);\n}\n\nexport function selects(tracked: TrackedAuthority, path: string): boolean {\n if (tracked.modelRoots.some((root) => withinRoot(path, root))) return false;\n return selectionRoots(tracked).some((root) => withinRoot(path, root));\n}\n\nexport function bootstrapFrom(envelope: HouseEnvelope, tracked: TrackedAuthority): BootstrapResult {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n return bootstrapOf(scope, tracked);\n}\n\nexport function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage {\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const binaryTargets: string[] = [];\n for (const file of scope.files) {\n if (!selects(tracked, file.path)) continue;\n if (file.revision !== undefined) revisions[file.path] = file.revision;\n const content = contents.get(file.path);\n if (content === undefined) binaryTargets.push(file.path);\n else documents[file.path] = content;\n }\n return {\n kind: 'bootstrap',\n roomVersion: roomVersion(scope),\n documents,\n revisions,\n binaryTargets: binaryTargets.sort(),\n };\n}\n\nexport type HouseDefinitions = {\n definitions: Readonly<Record<string, string>>;\n versions: readonly string[];\n};\n\nexport const MODEL_DEFINITION_ADDRESS = 'types';\n\nexport function definitionAddress(path: string): string {\n return `${MODEL_DEFINITION_ADDRESS}/${path.slice(path.lastIndexOf('/') + 1)}`;\n}\n\nexport function definitionsFrom(\n envelope: HouseEnvelope,\n tracked: TrackedAuthority,\n modelRoot: string,\n): HouseDefinitions | null {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return null;\n return definitionsOf(scope, modelRoot);\n}\n\nexport function definitionsOf(scope: HouseScope, modelRoot: string): HouseDefinitions | null {\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n const definitions: Record<string, string> = {};\n const versions: string[] = [];\n for (const file of scope.files) {\n if (!withinRoot(file.path, modelRoot)) continue;\n const content = contents.get(file.path);\n const address = definitionAddress(file.path);\n if (content === undefined || Object.hasOwn(definitions, address)) return null;\n definitions[address] = content;\n versions.push(`${file.path} ${file.version}`);\n }\n return { definitions, versions: versions.sort() };\n}\n\nexport function refreshFrom(\n enumeration: HouseEnumeration,\n tracked: TrackedAuthority,\n fromRoomVersion: string,\n): RefreshResult {\n const view = enumeration.authorities.find((entry) => entry.authority === tracked.authority);\n if (view === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n if (roomVersion(view) === fromRoomVersion) return { kind: 'still-current' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const binaryTargets: string[] = [];\n const removals: string[] = [];\n for (const change of view.changes) {\n if (!selects(tracked, change.path)) continue;\n if ('removed' in change) {\n removals.push(change.path);\n continue;\n }\n if ('content' in change) {\n documents[change.path] = change.content;\n if (change.revision !== undefined) revisions[change.path] = change.revision;\n continue;\n }\n binaryTargets.push(change.path);\n revisions[change.path] = change.reference.revision;\n }\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion(view),\n documents,\n revisions,\n binaryTargets: binaryTargets.sort(),\n removals: removals.sort(),\n };\n}\n"],"names":["PROVIDER_SELECTION_ROOTS","readPosition","roomVersion","authorityRoot","handle","undefined","ROOM_README","selectionRoots","tracked","collectionRoot","contentPrefixes","root","filter","entry","map","modelPrefix","modelRoot","parseGrant","body","transfer","method","operation","url","parseFile","value","mode","file","path","sha256","revision","version","parseScope","held","manifest","Array","isArray","contents","scope","at","anchor","files","push","content","roomHandle","room_handle","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","reference","parseEnumeration","authorities","authority","changes","change","mapped","advancedScope","view","Map","delete","set","position","logEpoch","values","matchesScope","withinRoot","startsWith","selects","modelRoots","some","bootstrapFrom","envelope","find","kind","locator","bootstrapOf","documents","revisions","binaryTargets","get","sort","MODEL_DEFINITION_ADDRESS","definitionAddress","slice","lastIndexOf","definitionsFrom","definitionsOf","definitions","versions","address","Object","hasOwn","refreshFrom","enumeration","fromRoomVersion","removals"],"mappings":"AACA,SAASA,wBAAwB,QAA+B,iBAAiB;AAEjF,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AA2C3E,OAAO,SAASC,cAAcC,MAA0B;IACtD,OAAOA,WAAWC,YAAY,aAAa,CAAC,OAAO,EAAED,QAAQ;AAC/D;AAEA,OAAO,MAAME,cAAc,UAAU;AAErC,OAAO,SAASC,eAAeC,OAAyB;IACtD,IAAIA,QAAQJ,MAAM,KAAKC,WAAW;QAChC,OAAO;YAACG,QAAQC,cAAc;eAAKT;SAAyB;IAC9D;IACA,OAAO;QAACM;QAAaE,QAAQC,cAAc;KAAC;AAC9C;AAEA,OAAO,SAASC,gBAAgBF,OAAyB;IACvD,MAAMG,OAAOR,cAAcK,QAAQJ,MAAM;IACzC,OAAOG,eAAeC,SACnBI,MAAM,CAAC,CAACC,QAAUA,UAAUP,aAC5BQ,GAAG,CAAC,CAACD,QAAU,GAAGF,KAAK,CAAC,EAAEE,OAAO;AACtC;AAEA,OAA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QAAqBC,SAASnE,QAAQmE,OAAO;IAAC;IACrF,IAAIzE,YAAYwD,UAAUqC,iBAAiB,OAAO;QAAErB,MAAM;IAAgB;IAC1E,MAAMG,YAAoC,CAAC;IAC3C,MAAMC,YAAoC,CAAC;IAC3C,MAAMC,gBAA0B,EAAE;IAClC,MAAMiB,WAAqB,EAAE;IAC7B,KAAK,MAAMzC,UAAUG,KAAKJ,OAAO,CAAE;QACjC,IAAI,CAACc,QAAQ5D,SAAS+C,OAAO5B,IAAI,GAAG;QACpC,IAAI,aAAa4B,QAAQ;YACvByC,SAASvD,IAAI,CAACc,OAAO5B,IAAI;YACzB;QACF;QACA,IAAI,aAAa4B,QAAQ;YACvBsB,SAAS,CAACtB,OAAO5B,IAAI,CAAC,GAAG4B,OAAOb,OAAO;YACvC,IAAIa,OAAO1B,QAAQ,KAAKxB,WAAWyE,SAAS,CAACvB,OAAO5B,IAAI,CAAC,GAAG4B,OAAO1B,QAAQ;YAC3E;QACF;QACAkD,cAActC,IAAI,CAACc,OAAO5B,IAAI;QAC9BmD,SAAS,CAACvB,OAAO5B,IAAI,CAAC,GAAG4B,OAAOL,SAAS,CAACrB,QAAQ;IACpD;IACA,OAAO;QACL6C,MAAM;QACNxE,aAAaA,YAAYwD;QACzBmB;QACAC;QACAC,eAAeA,cAAcE,IAAI;QACjCe,UAAUA,SAASf,IAAI;IACzB;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/read.ts"],"sourcesContent":["import type { BootstrapPage, BootstrapResult, RefreshResult } from '@agentshouse/mdruntime';\nimport { PROVIDER_SELECTION_ROOTS, type TrackedAuthority } from './discovery.js';\nimport type { HouseMode } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport type HouseManifestFile = {\n path: string;\n revision: string | undefined;\n version: string;\n};\n\nexport type HouseContent = {\n path: string;\n content: string;\n};\n\nexport type HouseScope = LogPosition & {\n anchor: string;\n files: readonly HouseManifestFile[];\n contents: readonly HouseContent[];\n};\n\nexport type HouseEnvelope = {\n scopes: readonly HouseScope[];\n};\n\nexport type HouseGrant = {\n method: 'GET' | 'POST';\n operation: string;\n url: string;\n};\n\nexport type HouseChange =\n | { path: string; removed: true }\n | { path: string; content: string; revision: string | undefined; version: string }\n | { path: string; reference: { revision: string } };\n\nexport type HouseEnumeration = {\n authorities: readonly (LogPosition & {\n authority: string;\n changes: readonly HouseChange[];\n })[];\n};\n\nexport function authorityRoot(handle: string | undefined): string {\n return handle === undefined ? '/private' : `/rooms/${handle}`;\n}\n\nexport const ROOM_README = 'ROOM.md';\n\nexport function selectionRoots(tracked: TrackedAuthority): readonly string[] {\n if (tracked.handle === undefined) {\n return [tracked.collectionRoot, ...PROVIDER_SELECTION_ROOTS];\n }\n return [ROOM_README, tracked.collectionRoot];\n}\n\nexport function contentPrefixes(tracked: TrackedAuthority): readonly string[] {\n const root = authorityRoot(tracked.handle);\n return selectionRoots(tracked)\n .filter((entry) => entry !== ROOM_README)\n .map((entry) => `${root}/${entry}`);\n}\n\nexport function modelPrefix(tracked: TrackedAuthority, modelRoot: string): string {\n return `${authorityRoot(tracked.handle)}/${modelRoot}`;\n}\n\nexport function parseGrant(body: unknown): HouseGrant | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {\n return null;\n }\n const transfer = body.transfer as Record<string, unknown>;\n if (transfer.method !== 'GET' && transfer.method !== 'POST') return null;\n if (typeof transfer.operation !== 'string' || typeof transfer.url !== 'string') return null;\n return { method: transfer.method, operation: transfer.operation, url: transfer.url };\n}\n\nfunction parseFile(value: unknown, mode: HouseMode): HouseManifestFile | null {\n if (typeof value !== 'object' || value === null) return null;\n const file = value as Record<string, unknown>;\n if (typeof file.path !== 'string') return null;\n if (mode === 'site') {\n if (typeof file.sha256 !== 'string') return null;\n return { path: file.path, revision: undefined, version: file.sha256 };\n }\n if (typeof file.revision !== 'string') return null;\n return { path: file.path, revision: file.revision, version: file.revision };\n}\n\nfunction parseScope(value: unknown, mode: HouseMode): HouseScope | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.manifest !== 'object' || held.manifest === null) return null;\n if (!Array.isArray(held.contents)) return null;\n const manifest = held.manifest as Record<string, unknown>;\n if (manifest.scope !== 'room') return null;\n const at = readPosition(manifest);\n if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)\n return null;\n if (\n manifest.room_handle !== null &&\n (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)\n )\n return null;\n if (!Array.isArray(manifest.files)) return null;\n const files: HouseManifestFile[] = [];\n for (const entry of manifest.files) {\n const file = parseFile(entry, mode);\n if (file === null) return null;\n files.push(file);\n }\n const contents: HouseContent[] = [];\n for (const entry of held.contents) {\n if (typeof entry !== 'object' || entry === null) return null;\n const content = entry as Record<string, unknown>;\n if (typeof content.path !== 'string' || typeof content.content !== 'string') return null;\n contents.push({ path: content.path, content: content.content });\n }\n return {\n anchor: manifest.anchor,\n ...at,\n files,\n contents,\n };\n}\n\nexport function parseEnvelope(body: unknown): HouseEnvelope | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('scopes' in body) || !Array.isArray(body.scopes)) return null;\n const scopes: HouseScope[] = [];\n for (const entry of body.scopes) {\n const scope = parseScope(entry, 'credential');\n if (scope === null) return null;\n scopes.push(scope);\n }\n return { scopes };\n}\n\nexport function parseSiteBootstrap(body: unknown): HouseScope | null {\n return parseScope(body, 'site');\n}\n\nfunction parseChange(value: unknown, mode: HouseMode): HouseChange | null {\n if (typeof value !== 'object' || value === null) return null;\n const held = value as Record<string, unknown>;\n if (typeof held.path !== 'string') return null;\n if (held.removed === true) return { path: held.path, removed: true };\n if (mode === 'site') {\n if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;\n return { path: held.path, content: held.content, revision: undefined, version: held.sha256 };\n }\n if (typeof held.content === 'string' && typeof held.revision === 'string') {\n return {\n path: held.path,\n content: held.content,\n revision: held.revision,\n version: held.revision,\n };\n }\n if (typeof held.reference === 'object' && held.reference !== null) {\n const reference = held.reference as Record<string, unknown>;\n if (typeof reference.revision !== 'string') return null;\n return { path: held.path, reference: { revision: reference.revision } };\n }\n return null;\n}\n\nexport function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null {\n if (typeof body !== 'object' || body === null) return null;\n if (!('authorities' in body) || !Array.isArray(body.authorities)) return null;\n const authorities: HouseEnumeration['authorities'][number][] = [];\n for (const entry of body.authorities) {\n if (typeof entry !== 'object' || entry === null) return null;\n const held = entry as Record<string, unknown>;\n const at = readPosition(held);\n if (typeof held.authority !== 'string' || at === null) return null;\n if (!Array.isArray(held.changes)) return null;\n const changes: HouseChange[] = [];\n for (const change of held.changes) {\n const mapped = parseChange(change, mode);\n if (mapped === null) return null;\n changes.push(mapped);\n }\n authorities.push({ authority: held.authority, ...at, changes });\n }\n return { authorities };\n}\n\nexport function advancedScope(\n scope: HouseScope,\n view: HouseEnumeration['authorities'][number],\n): HouseScope {\n const files = new Map(scope.files.map((file) => [file.path, file]));\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n for (const change of view.changes) {\n files.delete(change.path);\n contents.delete(change.path);\n if ('removed' in change) continue;\n if ('content' in change) {\n files.set(change.path, {\n path: change.path,\n revision: change.revision,\n version: change.version,\n });\n contents.set(change.path, change.content);\n continue;\n }\n const { revision } = change.reference;\n files.set(change.path, { path: change.path, revision, version: revision });\n }\n return {\n ...scope,\n position: view.position,\n logEpoch: view.logEpoch,\n files: [...files.values()],\n contents: [...contents].map(([path, content]) => ({ path, content })),\n };\n}\n\nexport function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean {\n return scope.anchor === tracked.authority;\n}\n\nexport function withinRoot(path: string, root: string): boolean {\n return path === root || path.startsWith(`${root}/`);\n}\n\nexport function selects(tracked: TrackedAuthority, path: string): boolean {\n if (tracked.modelRoots.some((root) => withinRoot(path, root))) return false;\n return selectionRoots(tracked).some((root) => withinRoot(path, root));\n}\n\nexport function bootstrapFrom(envelope: HouseEnvelope, tracked: TrackedAuthority): BootstrapResult {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n return bootstrapOf(scope, tracked);\n}\n\nexport function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage {\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const binaryTargets: string[] = [];\n for (const file of scope.files) {\n if (!selects(tracked, file.path)) continue;\n if (file.revision !== undefined) revisions[file.path] = file.revision;\n const content = contents.get(file.path);\n if (content === undefined) binaryTargets.push(file.path);\n else documents[file.path] = content;\n }\n return {\n kind: 'bootstrap',\n roomVersion: roomVersion(scope),\n documents,\n revisions,\n binaryTargets: binaryTargets.sort(),\n };\n}\n\nexport type HouseDefinitions = {\n definitions: Readonly<Record<string, string>>;\n versions: readonly string[];\n};\n\nexport const MODEL_DEFINITION_ADDRESS = 'types';\n\nexport function definitionAddress(path: string): string {\n return `${MODEL_DEFINITION_ADDRESS}/${path.slice(path.lastIndexOf('/') + 1)}`;\n}\n\nexport function definitionsFrom(\n envelope: HouseEnvelope,\n tracked: TrackedAuthority,\n modelRoot: string,\n): HouseDefinitions | null {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return null;\n return definitionsOf(scope, modelRoot);\n}\n\nexport function definitionsOf(scope: HouseScope, modelRoot: string): HouseDefinitions | null {\n const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));\n const definitions: Record<string, string> = {};\n const versions: string[] = [];\n for (const file of scope.files) {\n if (!withinRoot(file.path, modelRoot)) continue;\n const content = contents.get(file.path);\n const address = definitionAddress(file.path);\n if (content === undefined || Object.hasOwn(definitions, address)) return null;\n definitions[address] = content;\n versions.push(`${file.path} ${file.version}`);\n }\n return { definitions, versions: versions.sort() };\n}\n\nexport function refreshFrom(\n enumeration: HouseEnumeration,\n tracked: TrackedAuthority,\n fromRoomVersion: string,\n): RefreshResult {\n const view = enumeration.authorities.find((entry) => entry.authority === tracked.authority);\n if (view === undefined) return { kind: 'room-not-readable', locator: tracked.locator };\n if (roomVersion(view) === fromRoomVersion) return { kind: 'still-current' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const binaryTargets: string[] = [];\n const removals: string[] = [];\n for (const change of view.changes) {\n if (!selects(tracked, change.path)) continue;\n if ('removed' in change) {\n removals.push(change.path);\n continue;\n }\n if ('content' in change) {\n documents[change.path] = change.content;\n if (change.revision !== undefined) revisions[change.path] = change.revision;\n continue;\n }\n binaryTargets.push(change.path);\n revisions[change.path] = change.reference.revision;\n }\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion(view),\n documents,\n revisions,\n binaryTargets: binaryTargets.sort(),\n removals: removals.sort(),\n };\n}\n"],"names":["PROVIDER_SELECTION_ROOTS","readPosition","roomVersion","authorityRoot","handle","undefined","ROOM_README","selectionRoots","tracked","collectionRoot","contentPrefixes","root","filter","entry","map","modelPrefix","modelRoot","parseGrant","body","transfer","method","operation","url","parseFile","value","mode","file","path","sha256","revision","version","parseScope","held","manifest","Array","isArray","contents","scope","at","anchor","length","room_handle","files","push","content","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","reference","parseEnumeration","authorities","authority","changes","change","mapped","advancedScope","view","Map","delete","set","position","logEpoch","values","matchesScope","withinRoot","startsWith","selects","modelRoots","some","bootstrapFrom","envelope","find","kind","locator","bootstrapOf","documents","revisions","binaryTargets","get","sort","MODEL_DEFINITION_ADDRESS","definitionAddress","slice","lastIndexOf","definitionsFrom","definitionsOf","definitions","versions","address","Object","hasOwn","refreshFrom","enumeration","fromRoomVersion","removals"],"mappings":"AACA,SAASA,wBAAwB,QAA+B,iBAAiB;AAEjF,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAyC3E,OAAO,SAASC,cAAcC,MAA0B;IACtD,OAAOA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/dist/site.js
CHANGED
|
@@ -4,7 +4,7 @@ import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf } from './mo
|
|
|
4
4
|
import { advancedScope, authorityRoot, bootstrapOf, definitionsOf, parseEnumeration, parseSiteBootstrap, refreshFrom, selectionRoots } from './read.js';
|
|
5
5
|
import { classifyDoor, discoveryFailure } from './refusal.js';
|
|
6
6
|
import { houseNotifications } from './stream.js';
|
|
7
|
-
import {
|
|
7
|
+
import { PRIVATE_LOCATOR, SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT } from './transport.js';
|
|
8
8
|
import { logPosition, presented, roomVersion } from './version.js';
|
|
9
9
|
const UNCERTAIN = {
|
|
10
10
|
kind: 'transport-uncertainty'
|
|
@@ -113,7 +113,7 @@ export function createSiteAdapter(transport) {
|
|
|
113
113
|
},
|
|
114
114
|
async discover () {
|
|
115
115
|
const answer = await transport.door(SITE_DOOR_DISCOVER, {});
|
|
116
|
-
const classified = classifyDoor(answer.status, answer.body,
|
|
116
|
+
const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
|
|
117
117
|
if (classified !== null) return discoveryFailure(classified);
|
|
118
118
|
const document = parseSiteDiscovery(answer.body);
|
|
119
119
|
if (document === null) return UNCERTAIN;
|
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 authorityRoot,\n bootstrapOf,\n definitionsOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\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_AUTHORITY,\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 definitionsOf(held.scope, entry.modelRoot),\n `${authorityRoot(entry.handle)}/${entry.modelRoot}`,\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.door(SITE_DOOR_DISCOVER, {});\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);\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","authorityRoot","bootstrapOf","definitionsOf","parseEnumeration","parseSiteBootstrap","refreshFrom","selectionRoots","classifyDoor","discoveryFailure","houseNotifications","PRIVATE_AUTHORITY","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","modelRoot","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,aAAa,EACbC,WAAW,EACXC,aAAa,EACbC,gBAAgB,EAChBC,kBAAkB,EAClBC,WAAW,EACXC,cAAc,QAGT,YAAY;AACnB,SAASC,YAAY,EAAEC,gBAAgB,QAAQ,eAAe;AAC9D,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,iBAAiB,EACjBC,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,SAC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C,OAAOhF,IAAI,KAAK,kBAAkByB,OAAOb,MAAM,CAACe,MAAMK,SAAS;YACnE,OAAOgD;QACT;QAEA,MAAMC;YACJ,OAAO;gBAAEjF,MAAM;gBAAYkF,UAAU,CAAC;gBAAGC,MAAM;gBAAeC,QAAQ,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 authorityRoot,\n bootstrapOf,\n definitionsOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\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 definitionsOf(held.scope, entry.modelRoot),\n `${authorityRoot(entry.handle)}/${entry.modelRoot}`,\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.door(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","authorityRoot","bootstrapOf","definitionsOf","parseEnumeration","parseSiteBootstrap","refreshFrom","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","modelRoot","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,aAAa,EACbC,WAAW,EACXC,aAAa,EACbC,gBAAgB,EAChBC,kBAAkB,EAClBC,WAAW,EACXC,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;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sF,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"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { RefreshPage, SelectedRooms
|
|
1
|
+
import type { ConversationStream, RefreshPage, SelectedRooms } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import {
|
|
3
|
+
import type { HouseDoor } from './transport.js';
|
|
4
4
|
import type { HouseMode } from './transport.js';
|
|
5
5
|
import { type LogPosition } from './version.js';
|
|
6
6
|
export type HouseNotifications = SelectedRooms & {
|
|
7
7
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
8
8
|
advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;
|
|
9
|
-
conversations:
|
|
9
|
+
conversations: ConversationStream;
|
|
10
10
|
};
|
|
11
11
|
export declare function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications;
|
|
12
12
|
//# sourceMappingURL=stream.d.ts.map
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,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,EACd,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAwB,MAAM,gBAAgB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAsC,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc7D,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;CACnC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA6N5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,17 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { acceptedMessage, actionOutcome } from './actions.js';
|
|
2
2
|
import { selects } from './read.js';
|
|
3
|
-
import { PRIVATE_AUTHORITY } from './transport.js';
|
|
4
3
|
import { roomVersion } from './version.js';
|
|
5
4
|
const HELD_POSITIONS_MAX = 256;
|
|
6
5
|
function position(value) {
|
|
7
6
|
if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;
|
|
8
7
|
return BigInt(value);
|
|
9
8
|
}
|
|
10
|
-
function messageTurn(message) {
|
|
11
|
-
if (typeof message !== 'object' || message === null) return null;
|
|
12
|
-
const turn = message.message_id;
|
|
13
|
-
return typeof turn === 'string' ? turn : null;
|
|
14
|
-
}
|
|
15
9
|
export function houseNotifications(transport, mode) {
|
|
16
10
|
const stream = transport.stream;
|
|
17
11
|
const lines = new Map();
|
|
@@ -19,8 +13,8 @@ export function houseNotifications(transport, mode) {
|
|
|
19
13
|
const authorities = new Map();
|
|
20
14
|
const observers = new Set();
|
|
21
15
|
const conversationObservers = new Set();
|
|
22
|
-
const subscribedConversations = new Set();
|
|
23
16
|
let selected = [];
|
|
17
|
+
let replicated = [];
|
|
24
18
|
let viewed = [];
|
|
25
19
|
let listening = false;
|
|
26
20
|
function subscribe() {
|
|
@@ -28,16 +22,13 @@ export function houseNotifications(transport, mode) {
|
|
|
28
22
|
const rooms = new Set();
|
|
29
23
|
for (const locator of selected){
|
|
30
24
|
const authority = authorities.get(locator);
|
|
31
|
-
if (authority === undefined
|
|
25
|
+
if (authority === undefined) continue;
|
|
32
26
|
rooms.add(authority);
|
|
33
27
|
}
|
|
34
28
|
for (const room of rooms)named.push({
|
|
35
29
|
kind: 'room',
|
|
36
30
|
room
|
|
37
31
|
});
|
|
38
|
-
if (authorities.has(PRIVATE_AUTHORITY)) named.push({
|
|
39
|
-
kind: 'private'
|
|
40
|
-
});
|
|
41
32
|
for (const conversation of viewed){
|
|
42
33
|
named.push({
|
|
43
34
|
kind: 'conversation',
|
|
@@ -47,10 +38,11 @@ export function houseNotifications(transport, mode) {
|
|
|
47
38
|
stream.subscribe(named);
|
|
48
39
|
}
|
|
49
40
|
function emitConversation(event) {
|
|
50
|
-
|
|
41
|
+
const delivered = event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;
|
|
42
|
+
if (!delivered.includes(event.conversation)) return;
|
|
51
43
|
for (const observer of conversationObservers)observer(event);
|
|
52
44
|
}
|
|
53
|
-
async function
|
|
45
|
+
async function summarize(conversation) {
|
|
54
46
|
const viewedAnswer = await transport.door('/door/conversations/view', {
|
|
55
47
|
conversation_id: conversation
|
|
56
48
|
});
|
|
@@ -62,22 +54,6 @@ export function houseNotifications(transport, mode) {
|
|
|
62
54
|
summary: structuredClone('session' in summary.result ? summary.result.session : null)
|
|
63
55
|
});
|
|
64
56
|
}
|
|
65
|
-
if (!history) return;
|
|
66
|
-
const heldHistory = await readConversationHistory(transport, conversation);
|
|
67
|
-
if ('outcome' in heldHistory) return;
|
|
68
|
-
const newest = heldHistory.messages.slice(-HISTORY_PAGE);
|
|
69
|
-
for (const entry of newest){
|
|
70
|
-
const turn = messageTurn(entry);
|
|
71
|
-
if (turn === null) return;
|
|
72
|
-
emitConversation({
|
|
73
|
-
kind: 'accepted-message',
|
|
74
|
-
conversation,
|
|
75
|
-
message: {
|
|
76
|
-
turn,
|
|
77
|
-
message: structuredClone(entry)
|
|
78
|
-
}
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
57
|
}
|
|
82
58
|
function announce(authority, at) {
|
|
83
59
|
const version = roomVersion(at);
|
|
@@ -121,15 +97,12 @@ export function houseNotifications(transport, mode) {
|
|
|
121
97
|
return;
|
|
122
98
|
}
|
|
123
99
|
if (frame.type === 'message') {
|
|
124
|
-
const
|
|
125
|
-
if (
|
|
100
|
+
const message = acceptedMessage(frame.message);
|
|
101
|
+
if (message === null) return;
|
|
126
102
|
emitConversation({
|
|
127
103
|
kind: 'accepted-message',
|
|
128
104
|
conversation: frame.conversation_id,
|
|
129
|
-
message
|
|
130
|
-
turn,
|
|
131
|
-
message: structuredClone(frame.message)
|
|
132
|
-
}
|
|
105
|
+
message
|
|
133
106
|
});
|
|
134
107
|
return;
|
|
135
108
|
}
|
|
@@ -142,9 +115,11 @@ export function houseNotifications(transport, mode) {
|
|
|
142
115
|
return;
|
|
143
116
|
}
|
|
144
117
|
if (frame.type === 'subscribed' && viewed.includes(frame.authority)) {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
118
|
+
emitConversation({
|
|
119
|
+
kind: 'gap',
|
|
120
|
+
conversation: frame.authority
|
|
121
|
+
});
|
|
122
|
+
void summarize(frame.authority);
|
|
148
123
|
return;
|
|
149
124
|
}
|
|
150
125
|
if (frame.type === 'subscribed') {
|
|
@@ -190,11 +165,12 @@ export function houseNotifications(transport, mode) {
|
|
|
190
165
|
}
|
|
191
166
|
return {
|
|
192
167
|
conversations: {
|
|
168
|
+
replicate (next) {
|
|
169
|
+
replicated = [
|
|
170
|
+
...next
|
|
171
|
+
];
|
|
172
|
+
},
|
|
193
173
|
view (next) {
|
|
194
|
-
const open = new Set(next);
|
|
195
|
-
for (const conversation of subscribedConversations){
|
|
196
|
-
if (!open.has(conversation)) subscribedConversations.delete(conversation);
|
|
197
|
-
}
|
|
198
174
|
viewed = [
|
|
199
175
|
...next
|
|
200
176
|
];
|