@agentshouse/mdruntime-adapter 0.1.0-alpha.5 → 0.1.0-alpha.50
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 +157 -25
- package/README.md +32 -0
- package/dist/actions.d.ts +3 -11
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +201 -232
- package/dist/actions.js.map +1 -1
- package/dist/adapter.d.ts +3 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +242 -173
- package/dist/adapter.js.map +1 -1
- package/dist/discovery.d.ts +39 -15
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +169 -43
- package/dist/discovery.js.map +1 -1
- package/dist/gather.d.ts +3 -0
- package/dist/gather.d.ts.map +1 -0
- package/dist/gather.js +41 -0
- package/dist/gather.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/links.d.ts +11 -0
- package/dist/links.d.ts.map +1 -0
- package/dist/links.js +57 -0
- package/dist/links.js.map +1 -0
- package/dist/map.d.ts +2 -2
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +2 -3
- package/dist/map.js.map +1 -1
- package/dist/model.d.ts +19 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +64 -0
- package/dist/model.js.map +1 -0
- package/dist/read.d.ts +39 -27
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +246 -91
- package/dist/read.js.map +1 -1
- package/dist/refusal.d.ts +4 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +13 -1
- package/dist/refusal.js.map +1 -1
- package/dist/site.d.ts +4 -0
- package/dist/site.d.ts.map +1 -0
- package/dist/site.js +228 -0
- package/dist/site.js.map +1 -0
- package/dist/stream.d.ts +11 -5
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +220 -142
- package/dist/stream.js.map +1 -1
- package/dist/transport.d.ts +57 -29
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +6 -1
- package/dist/transport.js.map +1 -1
- package/dist/version.d.ts +15 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +39 -0
- package/dist/version.js.map +1 -0
- package/dist/write.d.ts +9 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +51 -9
- package/dist/write.js.map +1 -1
- package/package.json +4 -12
package/dist/adapter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/adapter.ts"],"sourcesContent":["import type {\n ActionRequest,\n ActionResult,\n Adapter,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n HistoryRequest,\n HistoryResult,\n ModelIdentity,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n PROVIDER_SELECTION_MODEL_ROOT,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n authorityRoot,\n bootstrapFrom,\n contentPrefixes,\n definitionsFrom,\n modelPrefix,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n} from './read.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n DOOR_BATCH,\n DOOR_BATCH_UPLOAD,\n DOOR_BOOTSTRAP,\n DOOR_DISCOVER,\n DOOR_ENUMERATE,\n DOOR_REVISIONS,\n PRIVATE_AUTHORITY,\n type HouseTransport,\n} from './transport.js';\nimport { sha256Hex } from './digest.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n rejectedMapping,\n revisionBody,\n uploadable,\n} from './write.js';\n\nexport type AgentsHouseAdapterOptions = {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n};\n\ntype HeldModel = { snapshot: ModelResult; identity: ModelIdentity | null };\n\nconst MODEL_ABSENT: ModelResult = { kind: 'model-unavailable', reason: 'not-readable' };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\nconst RESOLVED_OUTCOMES: ReadonlySet<MutationResult['kind']> = new Set([\n 'accepted',\n 'conflicted',\n 'rejected',\n 'expired',\n]);\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\n\nfunction lapsedGrant(outcome: MutationResult): boolean {\n return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';\n}\n\nfunction modelFailure(\n classified: ReturnType<typeof classifyDoor>,\n envelope: ReturnType<typeof parseEnvelope>,\n): ModelResult {\n if (classified === null) {\n return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;\n }\n if (classified.kind === 'revoked-authorization') return { kind: 'revoked-authorization' };\n if (classified.kind === 'transport-uncertainty') return { kind: 'transport-uncertainty' };\n return MODEL_ABSENT;\n}\n\nfunction modelVersion(revisions: readonly string[]): Promise<string> {\n return sha256Hex(JSON.stringify(revisions));\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n const transport = options.transport;\n const notifications = houseNotifications(transport);\n const tracked = new Map<string, TrackedAuthority>();\n const models = new Map<string, HeldModel>();\n const submissions = new Map<string, { sha256: string; body: Record<string, unknown> }>();\n\n function modelKey(locator: string, attached: ModelRequest['attached']): string {\n return `${locator} ${attached}`;\n }\n\n async function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n modelRoot: string,\n identity: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n const read = envelope === null ? null : definitionsFrom(envelope, entry, modelRoot);\n if (read === null) return { snapshot: failure, identity: null };\n const version = await modelVersion(read.revisions);\n return {\n snapshot: { kind: 'model', snapshot: { identity, version, definitions: read.definitions } },\n identity: { identity, version },\n };\n }\n\n async function acquireModels(\n entries: readonly TrackedAuthority[],\n ): Promise<Map<string, HeldModel>> {\n const acquired = new Map<string, HeldModel>();\n const privateEntry = entries.find((entry) => entry.authority === PRIVATE_AUTHORITY);\n const prefixes = entries.map((entry) => modelPrefix(entry, entry.modelRoot));\n if (privateEntry !== undefined) {\n prefixes.push(`${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`);\n }\n const answer = await transport.door(DOOR_BOOTSTRAP, { prefixes });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);\n const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;\n const failure: ModelResult = modelFailure(classified, envelope);\n for (const entry of entries) {\n acquired.set(\n modelKey(entry.locator, 'collection'),\n await held(\n envelope,\n entry,\n entry.modelRoot,\n `${authorityRoot(entry.handle)}/${entry.modelRoot}`,\n failure,\n ),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(\n envelope,\n privateEntry,\n PROVIDER_SELECTION_MODEL_ROOT,\n `${authorityRoot(undefined)}/${PROVIDER_SELECTION_MODEL_ROOT}`,\n failure,\n ),\n );\n }\n return acquired;\n }\n\n function retainModel(key: string, acquired: HeldModel | undefined): HeldModel | undefined {\n if (acquired === undefined) return models.get(key);\n if (acquired.snapshot.kind === 'transport-uncertainty') {\n const previous = models.get(key);\n if (previous !== undefined && previous.identity !== null) return previous;\n }\n models.set(key, acquired);\n return acquired;\n }\n\n function roomOf(authority: HouseAuthority, acquired: Map<string, HeldModel>): DiscoveredRoom {\n const locator = locatorOf(authority);\n const key = modelKey(locator, 'collection');\n const collection = retainModel(key, acquired.get(key));\n if (authority.kind !== 'private') {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = retainModel(\n modelKey(locator, 'typed-selection'),\n acquired.get(modelKey(locator, 'typed-selection')),\n );\n return discoveredRoom(\n authority,\n collection?.identity ?? null,\n providerSelection(selection?.identity ?? null),\n );\n }\n\n function authorityFor(locator: string): TrackedAuthority | undefined {\n return tracked.get(locator);\n }\n\n async function bundled(body: unknown): Promise<unknown> {\n const grant = parseGrant(body);\n if (grant === null) return body;\n if (grant.method !== 'GET') return null;\n const answer = await transport.transfer({\n act: 'working_copy_bundle',\n method: 'GET',\n url: grant.url,\n });\n return answer.status === 200 ? answer.body : null;\n }\n\n async function uploaded(\n identity: string,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n const retained = submissions.get(identity);\n if (retained !== undefined && retained.sha256 === sha256) return { body: retained.body };\n const minted = await transport.door(DOOR_BATCH_UPLOAD, {\n operation_id: identity,\n paths,\n bytes,\n sha256,\n });\n if (minted.status !== 200) {\n return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };\n }\n const grant = parseGrant(minted.body);\n if (grant === null || grant.method !== 'POST') return { outcome: UNCERTAIN };\n const delivered = await transport.transfer({\n act: 'authored_batch_upload',\n method: 'POST',\n url: grant.url,\n body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null) return { outcome: UNCERTAIN };\n const body = {\n operation_id: identity,\n paths,\n upload: { url: holding.url, operation: holding.operation, bytes, sha256 },\n };\n submissions.set(identity, { sha256, body });\n return { body };\n }\n\n async function submit(\n identity: string,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(identity, changes, delta, bytes, entry)\n : { body: { operation_id: identity, changes } };\n if ('outcome' in prepared) return prepared.outcome;\n const answer = await transport.door(DOOR_BATCH, prepared.body);\n return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);\n }\n\n return {\n async authorize() {\n return options.authorize();\n },\n\n async model(_authorization: Authorization, request: ModelRequest): Promise<ModelResult> {\n return models.get(modelKey(request.locator, request.attached))?.snapshot ?? MODEL_ABSENT;\n },\n\n async discover(_authorization: Authorization): Promise<DiscoverResult> {\n const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_AUTHORITY);\n if (classified !== null) {\n if (classified.kind === 'revoked-authorization') return classified;\n if (classified.kind === 'scoped-refusal') {\n return { kind: 'contract-unavailable', code: classified.code, fields: classified.fields };\n }\n return { kind: 'transport-uncertainty' };\n }\n const document = parseDiscovery(answer.body);\n if (document === null) return { kind: 'transport-uncertainty' };\n const entries = trackedFrom(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const acquired = await acquireModels(entries);\n for (const key of [...models.keys()]) {\n if (!entries.some((entry) => key.startsWith(`${entry.locator} `))) models.delete(key);\n }\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\n );\n },\n\n async bootstrap(\n _authorization: Authorization,\n request: BootstrapRequest,\n ): Promise<BootstrapResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: [...contentPrefixes(entry)],\n });\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) {\n return classified.kind === 'beyond-horizon'\n ? { kind: 'transport-uncertainty' }\n : classified;\n }\n const envelope = parseEnvelope(await bundled(answer.body));\n if (envelope === null) return { kind: 'transport-uncertainty' };\n return bootstrapFrom(envelope, entry);\n },\n\n async refresh(_authorization: Authorization, request: RefreshRequest): Promise<RefreshResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const streamed = notifications.advance(entry, request.fromRoomVersion);\n if (streamed !== null) return streamed;\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: [...contentPrefixes(entry)],\n positions: [{ authority: entry.authority, position: request.fromRoomVersion }],\n });\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n const enumeration = parseEnumeration(answer.body);\n if (enumeration === null) return { kind: 'transport-uncertainty' };\n return refreshFrom(enumeration, entry, request.fromRoomVersion);\n },\n\n async mutate(_authorization: Authorization, request: MutationRequest): Promise<MutationResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const mapped = houseChanges(request.changeBatch, entry.handle);\n if (mapped.kind === 'unmapped') return rejectedMapping(mapped);\n const identity = request.changeBatch.id;\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const resent = submissions.has(identity);\n let outcome = await submit(identity, mapped.changes, delta, bytes, entry);\n if (resent && lapsedGrant(outcome)) {\n submissions.delete(identity);\n outcome = await submit(identity, mapped.changes, delta, bytes, entry);\n }\n if (RESOLVED_OUTCOMES.has(outcome.kind)) submissions.delete(identity);\n return outcome;\n },\n\n async history(_authorization: Authorization, request: HistoryRequest): Promise<HistoryResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const answer = await transport.door(\n DOOR_REVISIONS,\n revisionBody({\n path: request.path,\n handle: entry.handle,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),\n }),\n );\n return historyOutcome(answer.status, answer.body, entry.locator, {\n path: request.path,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n });\n },\n\n async action(_authorization: Authorization, request: ActionRequest): Promise<ActionResult> {\n return houseAction(transport, request);\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n };\n}\n"],"names":["DISCOVER_PREFIXES","PROVIDER_SELECTION_MODEL_ROOT","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","authorityRoot","bootstrapFrom","contentPrefixes","definitionsFrom","modelPrefix","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","houseAction","classifyDoor","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","PRIVATE_AUTHORITY","sha256Hex","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","rejectedMapping","revisionBody","uploadable","MODEL_ABSENT","kind","reason","UNCERTAIN","RESOLVED_OUTCOMES","Set","lapsedGrant","outcome","code","modelFailure","classified","envelope","modelVersion","revisions","JSON","stringify","createAgentsHouseAdapter","options","transport","notifications","tracked","Map","models","submissions","modelKey","locator","attached","held","entry","modelRoot","identity","failure","read","snapshot","version","definitions","acquireModels","entries","acquired","privateEntry","find","authority","prefixes","map","undefined","push","answer","door","status","body","bundled","set","handle","retainModel","key","get","previous","roomOf","collection","selection","authorityFor","grant","method","transfer","act","url","uploaded","changes","delta","bytes","paths","sha256","retained","minted","operation_id","delivered","operation","holding","upload","submit","prepared","authorize","model","_authorization","request","discover","fields","document","clear","track","keys","some","startsWith","delete","authorities","bootstrap","pageToken","refresh","streamed","advance","fromRoomVersion","positions","position","enumeration","mutate","mapped","changeBatch","id","resent","has","history","path","revision","action","roomVersions","conversations"],"mappings":"AAmBA,SACEA,iBAAiB,EACjBC,6BAA6B,EAC7BC,cAAc,EACdC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,WAAW,QAGN,iBAAiB;AACxB,SACEC,aAAa,EACbC,aAAa,EACbC,eAAe,EACfC,eAAe,EACfC,WAAW,EACXC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,EACVC,WAAW,QACN,YAAY;AACnB,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,YAAY,QAAQ,eAAe;AAC5C,SAASC,kBAAkB,QAAQ,cAAc;AAC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A,MAAMC,QAAO9B,cAA6B,EAAEC,OAAsB;YAChE,OAAOzG,YAAYuC,WAAWkE;QAChC;QAEA8B,cAAc/F;QACdgG,eAAehG,cAAcgG,aAAa;IAC5C;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/adapter.ts"],"sourcesContent":["import type {\n ActionRequest,\n ActionResult,\n Adapter,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n DiscoverResult,\n DiscoveredRoom,\n HistoryRequest,\n HistoryResult,\n ModelRequest,\n ModelResult,\n MutationRequest,\n MutationResult,\n RefreshRequest,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n DISCOVER_PREFIXES,\n HOUSE_SCHEMA,\n capabilities,\n discoveredRoom,\n locatorOf,\n mapDiscovery,\n parseDiscovery,\n providerSelection,\n trackedFrom,\n type HouseAuthority,\n type TrackedAuthority,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport { gathered, selections } from './gather.js';\nimport { createSiteAdapter } from './site.js';\nimport {\n bootstrapOf,\n contentPrefixes,\n matchesScope,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n schemaFrom,\n schemaPath,\n viewOf,\n type HouseEnumeration,\n type HouseEnvelope,\n} from './read.js';\nimport { enumeratedLinks, scopeLinks, streamedLinks, type RoomLinks } from './links.js';\nimport { houseAction } from './actions.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';\nimport { houseNotifications } from './stream.js';\nimport {\n DOOR_BATCH,\n DOOR_BATCH_UPLOAD,\n DOOR_BOOTSTRAP,\n DOOR_DISCOVER,\n DOOR_ENUMERATE,\n DOOR_REVISIONS,\n DOOR_SELECTION_MAX,\n PRIVATE_LOCATOR,\n type HouseSiteTransport,\n type HouseTransport,\n} from './transport.js';\nimport {\n batchPaths,\n deltaBody,\n deltaBytes,\n deltaDigest,\n historyOutcome,\n houseChanges,\n mutationOutcome,\n operationHead,\n rejectedMapping,\n revisionBody,\n uploadable,\n type OperationHead,\n} from './write.js';\nimport {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\nexport type AgentsHouseAdapterOptions =\n | {\n transport: HouseTransport;\n authorize(): Promise<Authorization>;\n }\n | { site: HouseSiteTransport };\n\nconst UNCERTAIN: MutationResult = { kind: 'transport-uncertainty' };\n\nconst UNCERTAIN_READ = { kind: 'transport-uncertainty' } as const;\n\ntype Enumerating = {\n entry: TrackedAuthority;\n from: LogPosition;\n fromRoomVersion: string;\n minPosition?: string;\n};\n\ntype Submission = { body: Record<string, unknown> } | { outcome: MutationResult };\n\ntype Upload = { url: string; operation: string; bytes: number; sha256: string };\n\ntype Keep = (upload: unknown) => Promise<void>;\n\nfunction lapsedGrant(outcome: MutationResult): boolean {\n return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';\n}\n\nfunction modelFailure(\n classified: ReturnType<typeof classifyDoor>,\n envelope: ReturnType<typeof parseEnvelope>,\n): ModelResult {\n if (classified === null) {\n return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;\n }\n return failedModel(classified);\n}\n\nexport function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter {\n if ('site' in options) return createSiteAdapter(options.site);\n const transport = options.transport;\n const notifications = houseNotifications(transport, 'credential');\n const tracked = new Map<string, TrackedAuthority>();\n const handed = new Map<string, RoomLinks>();\n const models = modelShelf();\n\n function bootstrappedRoom(envelope: HouseEnvelope, entry: TrackedAuthority): BootstrapResult {\n const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));\n if (scope === undefined) return { kind: 'room-not-readable', locator: entry.locator };\n handed.set(entry.locator, scopeLinks(scope));\n return bootstrapOf(scope, entry);\n }\n\n function enumeratedRoom(enumeration: HouseEnumeration, ask: Enumerating): RefreshResult {\n const view = viewOf(enumeration, ask.entry);\n if (view === undefined) return { kind: 'room-not-readable', locator: ask.entry.locator };\n const answer = refreshFrom(view, ask.entry, ask.fromRoomVersion);\n if (answer.kind === 'net-advancement') {\n handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));\n }\n return answer;\n }\n\n function streamed(\n entry: TrackedAuthority,\n request: RefreshRequest,\n from: LogPosition,\n ): RefreshResult | null {\n const links = handed.get(entry.locator);\n if (links?.roomVersion !== request.fromRoomVersion) return null;\n const advanced = notifications.advance(entry, from);\n if (advanced === null) return null;\n if (\n request.minPosition !== undefined &&\n !reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch)\n )\n return null;\n const relinked = streamedLinks(links, advanced);\n if (relinked === null) return null;\n handed.set(entry.locator, relinked);\n return advanced.page;\n }\n\n function held(\n envelope: ReturnType<typeof parseEnvelope>,\n entry: TrackedAuthority,\n schema: string,\n failure: ModelResult,\n ): Promise<HeldModel> {\n return heldModel(\n envelope === null ? null : schemaFrom(envelope, entry, schema),\n schemaPath(entry.handle, schema),\n failure,\n );\n }\n\n function modelPrefixes(entry: TrackedAuthority): readonly string[] {\n return entry.schemas.map((schema) => schemaPath(entry.handle, schema));\n }\n\n async function acquireModels(\n entries: readonly TrackedAuthority[],\n ): Promise<Map<string, HeldModel>> {\n const acquired = new Map<string, HeldModel>();\n for (const part of selections(\n entries,\n (entry) => modelPrefixes(entry).length,\n DOOR_SELECTION_MAX,\n )) {\n const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => modelPrefixes(entry)),\n });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;\n const failure: ModelResult = modelFailure(classified, envelope);\n for (const entry of part) {\n acquired.set(\n modelKey(entry.locator, 'collection'),\n await held(envelope, entry, entry.schema, failure),\n );\n }\n if (privateEntry !== undefined) {\n acquired.set(\n modelKey(privateEntry.locator, 'typed-selection'),\n await held(envelope, privateEntry, HOUSE_SCHEMA, failure),\n );\n }\n }\n return acquired;\n }\n\n function roomOf(authority: HouseAuthority, acquired: Map<string, HeldModel>): DiscoveredRoom {\n const locator = locatorOf(authority);\n const key = modelKey(locator, 'collection');\n const collection = models.retain(key, acquired.get(key));\n if (locator !== PRIVATE_LOCATOR) {\n return discoveredRoom(authority, collection?.identity ?? null, undefined);\n }\n const selection = models.retain(\n modelKey(locator, 'typed-selection'),\n acquired.get(modelKey(locator, 'typed-selection')),\n );\n return discoveredRoom(\n authority,\n collection?.identity ?? null,\n providerSelection(selection?.identity ?? null),\n );\n }\n\n function authorityFor(locator: string): TrackedAuthority | undefined {\n return tracked.get(locator);\n }\n\n function withAt(result: ActionResult): ActionResult {\n if (result.kind !== 'action') return result;\n const body = result.result as Record<string, unknown> | null;\n if (typeof body !== 'object' || body === null) return result;\n const { authority, position, log_epoch: logEpoch } = body;\n if (typeof position !== 'string' || typeof logEpoch !== 'string') return result;\n const locator =\n authority === undefined\n ? PRIVATE_LOCATOR\n : [...tracked.values()].find((entry) => entry.authority === authority)?.locator;\n if (locator === undefined) return result;\n return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };\n }\n\n async function bundled(body: unknown): Promise<unknown> {\n const grant = parseGrant(body);\n if (grant === null) return body;\n if (grant.method !== 'GET') return null;\n const answer = await transport.transfer({\n act: 'local_copy_bundle',\n method: 'GET',\n url: grant.url,\n answer: 'json',\n });\n return answer.status === 200 ? answer.body : null;\n }\n\n function weight(entry: TrackedAuthority): number {\n return contentPrefixes(entry).length;\n }\n\n async function bootstrapped(entries: readonly TrackedAuthority[]): Promise<BootstrapResult[]> {\n const answers: BootstrapResult[] = [];\n for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {\n const answer = await transport.door(DOOR_BOOTSTRAP, {\n prefixes: part.flatMap((entry) => contentPrefixes(entry)),\n });\n const classified = part.map((entry) =>\n classifyDoor(answer.status, answer.body, entry.locator),\n );\n const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;\n part.forEach((entry, index) => {\n const failure = classified[index];\n if (failure === null || failure === undefined) {\n answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));\n return;\n }\n answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);\n });\n }\n return answers;\n }\n\n function layered(asks: readonly Enumerating[]): readonly (readonly Enumerating[])[] {\n const depths = new Map<string, number>();\n const layers: Enumerating[][] = [];\n for (const ask of asks) {\n const depth = depths.get(ask.entry.authority) ?? 0;\n depths.set(ask.entry.authority, depth + 1);\n (layers[depth] ??= []).push(ask);\n }\n return layers;\n }\n\n async function enumerated(asks: readonly Enumerating[]): Promise<RefreshResult[]> {\n const answers = new Map<Enumerating, RefreshResult>();\n const parts = layered(asks).flatMap((layer) =>\n selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX),\n );\n for (const part of parts) {\n let open = [...part];\n while (open.length > 0) {\n const answer = await transport.door(DOOR_ENUMERATE, {\n prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),\n positions: open.map((ask) => ({\n ...presented(ask.entry.authority, ask.from),\n ...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),\n })),\n });\n const refusal = doorRefusal(answer.body);\n if (refusal?.code === 'replica_behind') {\n const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);\n const behind = named.length === 0 ? open : named;\n for (const ask of behind) answers.set(ask, { kind: 'retryable-refusal', ...refusal });\n open = open.filter((ask) => !behind.includes(ask));\n continue;\n }\n const classified = open.map((ask) =>\n classifyDoor(answer.status, answer.body, ask.entry.locator),\n );\n if (classified[0]?.kind === 'beyond-horizon') {\n const named = doorRefusal(answer.body)?.fields.authority;\n const expired = open.filter((ask) => ask.entry.authority === named);\n const answered: RefreshResult =\n expired.length === 0 ? UNCERTAIN_READ : { kind: 'beyond-horizon' };\n const gone = expired.length === 0 ? open : expired;\n for (const ask of gone) answers.set(ask, answered);\n open = open.filter((ask) => !gone.includes(ask));\n continue;\n }\n const enumeration =\n classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;\n open.forEach((ask, index) => {\n const failure = classified[index];\n if (failure !== null && failure !== undefined) {\n answers.set(ask, failure);\n return;\n }\n answers.set(\n ask,\n enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask),\n );\n });\n open = [];\n }\n }\n return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);\n }\n\n const bootstrapTogether = gathered(bootstrapped);\n\n const enumerateTogether = gathered(enumerated);\n\n async function uploaded(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<Submission> {\n const paths = batchPaths(changes);\n const sha256 = await deltaDigest(delta);\n if (handed !== undefined && handed.sha256 === sha256) {\n return { body: { ...head, paths, upload: handed } };\n }\n const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });\n if (minted.status !== 200) {\n return { outcome: mutationOutcome(minted.status, minted.body, entry.locator, entry.handle) };\n }\n const grant = parseGrant(minted.body);\n if (grant === null || grant.method !== 'POST') return { outcome: UNCERTAIN };\n const delivered = await transport.transfer({\n act: 'authored_batch_upload',\n method: 'POST',\n url: grant.url,\n answer: 'json',\n body: `${grant.operation}\\n${delta}`,\n });\n if (delivered.status !== 200) return { outcome: UNCERTAIN };\n const holding = parseGrant(delivered.body);\n if (holding === null || holding.method !== 'POST') return { outcome: UNCERTAIN };\n const upload: Upload = { url: holding.url, operation: holding.operation, bytes, sha256 };\n await keep(upload);\n return { body: { ...head, paths, upload } };\n }\n\n async function submit(\n head: OperationHead,\n changes: readonly Readonly<Record<string, unknown>>[],\n delta: string,\n bytes: number,\n entry: TrackedAuthority,\n handed: Upload | undefined,\n keep: Keep,\n ): Promise<MutationResult> {\n const prepared: Submission = uploadable(bytes)\n ? await uploaded(head, changes, delta, bytes, entry, handed, keep)\n : { body: { ...head, changes } };\n if ('outcome' in prepared) return prepared.outcome;\n const answer = await transport.door(DOOR_BATCH, prepared.body);\n return mutationOutcome(answer.status, answer.body, entry.locator, entry.handle);\n }\n\n return {\n async authorize() {\n return options.authorize();\n },\n\n async model(_authorization: Authorization, request: ModelRequest): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(_authorization: Authorization): Promise<DiscoverResult> {\n const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseDiscovery(answer.body);\n if (document === null) return { kind: 'transport-uncertainty' };\n const entries = trackedFrom(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n for (const locator of handed.keys()) if (!tracked.has(locator)) handed.delete(locator);\n notifications.track(entries);\n const acquired = await acquireModels(entries);\n models.keep(entries.map((entry) => entry.locator));\n return mapDiscovery(\n document,\n document.authorities.map((authority) => roomOf(authority, acquired)),\n capabilities(document.actions),\n );\n },\n\n async bootstrap(\n _authorization: Authorization,\n request: BootstrapRequest,\n ): Promise<BootstrapResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n return bootstrapTogether(entry);\n },\n\n async refresh(_authorization: Authorization, request: RefreshRequest): Promise<RefreshResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return { kind: 'transport-uncertainty' };\n const from = logPosition(request.fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const answered = streamed(entry, request, from);\n if (answered !== null) return answered;\n const minPosition =\n request.minPosition === undefined ? null : logPosition(request.minPosition);\n return enumerateTogether({\n entry,\n from,\n fromRoomVersion: request.fromRoomVersion,\n ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),\n });\n },\n\n async mutate(\n _authorization: Authorization,\n request: MutationRequest,\n keep: Keep,\n ): Promise<MutationResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const mapped = houseChanges(request.changeBatch, entry.handle);\n if (mapped.kind === 'unmapped') return rejectedMapping(mapped);\n const head = operationHead(request.changeBatch);\n const delta = deltaBody(mapped.changes);\n const bytes = deltaBytes(delta);\n const handed = request.upload as Upload | undefined;\n const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);\n if (handed === undefined || !lapsedGrant(outcome)) return outcome;\n return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);\n },\n\n async history(_authorization: Authorization, request: HistoryRequest): Promise<HistoryResult> {\n const entry = authorityFor(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n const answer = await transport.door(\n DOOR_REVISIONS,\n revisionBody({\n path: request.path,\n handle: entry.handle,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n ...(request.pageToken === undefined ? {} : { pageToken: request.pageToken }),\n }),\n );\n return historyOutcome(answer.status, answer.body, entry.locator, {\n path: request.path,\n ...(request.revision === undefined ? {} : { revision: request.revision }),\n });\n },\n\n reached(locator: string, version: string, target: string): boolean {\n return reachedVersion(version, target, authorityFor(locator)?.logEpoch);\n },\n\n async action(_authorization: Authorization, request: ActionRequest): Promise<ActionResult> {\n return withAt(await houseAction(transport, request));\n },\n\n roomVersions: notifications,\n conversations: notifications.conversations,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["DISCOVER_PREFIXES","HOUSE_SCHEMA","capabilities","discoveredRoom","locatorOf","mapDiscovery","parseDiscovery","providerSelection","trackedFrom","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","gathered","selections","createSiteAdapter","bootstrapOf","contentPrefixes","matchesScope","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","schemaFrom","schemaPath","viewOf","enumeratedLinks","scopeLinks","streamedLinks","houseAction","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","DOOR_BATCH","DOOR_BATCH_UPLOAD","DOOR_BOOTSTRAP","DOOR_DISCOVER","DOOR_ENUMERATE","DOOR_REVISIONS","DOOR_SELECTION_MAX","PRIVATE_LOCATOR","batchPaths","deltaBody","deltaBytes","deltaDigest","historyOutcome","houseChanges","mutationOutcome","operationHead","rejectedMapping","revisionBody","uploadable","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","UNCERTAIN_READ","lapsedGrant","outcome","code","modelFailure","classified","envelope","createAgentsHouseAdapter","options","site","transport","notifications","tracked","Map","handed","models","bootstrappedRoom","entry","scope","scopes","find","candidate","undefined","locator","set","enumeratedRoom","enumeration","ask","view","answer","fromRoomVersion","get","streamed","request","from","links","advanced","advance","minPosition","page","logEpoch","relinked","held","schema","failure","handle","modelPrefixes","schemas","map","acquireModels","entries","acquired","part","length","privateEntry","door","prefixes","flatMap","status","body","bundled","roomOf","authority","key","collection","retain","identity","selection","authorityFor","withAt","result","position","log_epoch","values","at","grant","method","transfer","act","url","weight","bootstrapped","answers","forEach","index","push","layered","asks","depths","layers","depth","enumerated","parts","layer","open","positions","min_position","refusal","named","filter","fields","behind","includes","expired","answered","gone","bootstrapTogether","enumerateTogether","uploaded","head","changes","delta","bytes","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","discover","document","clear","keys","has","delete","track","authorities","actions","bootstrap","pageToken","refresh","mutate","mapped","changeBatch","history","path","revision","reached","version","target","action","roomVersions","conversations","serviceMode"],"mappings":"AAkBA,SACEA,iBAAiB,EACjBC,YAAY,EACZC,YAAY,EACZC,cAAc,EACdC,SAAS,EACTC,YAAY,EACZC,cAAc,EACdC,iBAAiB,EACjBC,WAAW,QAGN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SAASC,QAAQ,EAAEC,UAAU,QAAQ,cAAc;AACnD,SAASC,iBAAiB,QA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BACXsJ,MAAM7G,QAAQ6G,IAAI;gBAClBjG,QAAQ5B,MAAM4B,MAAM;gBACpB,GAAIZ,QAAQ8G,QAAQ,KAAKzH,YAAY,CAAC,IAAI;oBAAEyH,UAAU9G,QAAQ8G,QAAQ;gBAAC,CAAC;gBACxE,GAAI9G,QAAQuG,SAAS,KAAKlH,YAAY,CAAC,IAAI;oBAAEkH,WAAWvG,QAAQuG,SAAS;gBAAC,CAAC;YAC7E;YAEF,OAAOrJ,eAAe0C,OAAO6B,MAAM,EAAE7B,OAAO8B,IAAI,EAAE1C,MAAMM,OAAO,EAAE;gBAC/DuH,MAAM7G,QAAQ6G,IAAI;gBAClB,GAAI7G,QAAQ8G,QAAQ,KAAKzH,YAAY,CAAC,IAAI;oBAAEyH,UAAU9G,QAAQ8G,QAAQ;gBAAC,CAAC;YAC1E;QACF;QAEAC,SAAQzH,OAAe,EAAE0H,OAAe,EAAEC,MAAc;YACtD,OAAOtJ,eAAeqJ,SAASC,QAAQ9E,aAAa7C,UAAUiB;QAChE;QAEA,MAAM2G,QAAOtB,cAA6B,EAAE5F,OAAsB;YAChE,OAAOoC,OAAO,MAAMnG,YAAYwC,WAAWuB;QAC7C;QAEAmH,cAAczI;QACd0I,eAAe1I,cAAc0I,aAAa;QAC1CC,aAAa3I,cAAc2I,WAAW;IACxC;AACF"}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Capability, DiscoveredRoom, Discovery, ProviderLimit, Retention, TypedSelection } from '@agentshouse/mdruntime';
|
|
2
|
+
import { type LogPosition } from './version.js';
|
|
2
3
|
export declare const ROOM_CONTRACT_VERSION = 1;
|
|
3
4
|
export declare const MD_MODEL_IDENTITY = "@agentshouse/mdmodel";
|
|
4
5
|
export declare const ROOM_VERSION_NOTIFICATIONS = "room-version-notifications";
|
|
@@ -6,10 +7,14 @@ export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
|
6
7
|
export declare const MOVE_REFERENCE_REWRITES = "move-reference-rewrites";
|
|
7
8
|
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
8
9
|
export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
|
|
9
|
-
export declare const
|
|
10
|
+
export declare const UNTYPED_FOLDERS: readonly string[];
|
|
11
|
+
export declare const RESERVED_NAMES: readonly string[];
|
|
12
|
+
export declare const HOUSE_SCHEMA = "house/schema.yaml";
|
|
13
|
+
export declare const PRIVATE_HANDLE = "private";
|
|
10
14
|
export type HouseBounds = {
|
|
11
15
|
max_authored_file_bytes: number;
|
|
12
16
|
max_batch_operations: number;
|
|
17
|
+
max_batch_documents: number;
|
|
13
18
|
max_path_length: number;
|
|
14
19
|
max_path_depth: number;
|
|
15
20
|
max_mount_files: number;
|
|
@@ -23,39 +28,58 @@ export type HouseOperations = {
|
|
|
23
28
|
write: readonly string[];
|
|
24
29
|
delete: readonly string[];
|
|
25
30
|
};
|
|
26
|
-
export type HouseAuthority = {
|
|
27
|
-
kind: 'room' | 'private';
|
|
31
|
+
export type HouseAuthority = LogPosition & {
|
|
28
32
|
roomRef: string;
|
|
29
|
-
roomHandle: string
|
|
33
|
+
roomHandle: string;
|
|
30
34
|
name: string;
|
|
31
|
-
|
|
32
|
-
modelRoot: string;
|
|
35
|
+
schema: string;
|
|
33
36
|
managedReplication: 'admitted' | 'unavailable';
|
|
34
37
|
protectedPaths: readonly string[];
|
|
35
38
|
operations: HouseOperations;
|
|
36
|
-
position: string;
|
|
37
39
|
};
|
|
38
40
|
export type HouseDiscoveryDocument = {
|
|
39
41
|
bounds: HouseBounds;
|
|
40
42
|
mdModelVersion: string;
|
|
41
43
|
authorities: readonly HouseAuthority[];
|
|
44
|
+
actions: readonly string[];
|
|
42
45
|
};
|
|
43
|
-
export type TrackedAuthority = {
|
|
46
|
+
export type TrackedAuthority = LogPosition & {
|
|
44
47
|
locator: string;
|
|
45
48
|
authority: string;
|
|
46
|
-
handle: string
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
handle: string;
|
|
50
|
+
schema: string;
|
|
51
|
+
schemas: readonly string[];
|
|
52
|
+
};
|
|
53
|
+
export type HouseSiteEntry = {
|
|
54
|
+
roomRef: string;
|
|
55
|
+
segment: string;
|
|
56
|
+
};
|
|
57
|
+
export type HouseSiteSlot = {
|
|
58
|
+
slot: string;
|
|
59
|
+
entries: readonly HouseSiteEntry[];
|
|
60
|
+
};
|
|
61
|
+
export type HouseSiteAuthority = LogPosition & {
|
|
62
|
+
roomRef: string;
|
|
63
|
+
roomHandle: string;
|
|
64
|
+
schema: string;
|
|
65
|
+
};
|
|
66
|
+
export type HouseSiteDiscovery = {
|
|
67
|
+
bounds: HouseBounds;
|
|
68
|
+
mdModelVersion: string;
|
|
69
|
+
slots: readonly HouseSiteSlot[];
|
|
70
|
+
authorities: readonly HouseSiteAuthority[];
|
|
51
71
|
};
|
|
52
72
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
73
|
+
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
74
|
+
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
75
|
+
export declare function siteSlots(document: HouseSiteDiscovery): Discovery['slots'];
|
|
53
76
|
export declare function locatorOf(authority: HouseAuthority): string;
|
|
54
77
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
55
78
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
56
79
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
57
|
-
export declare function capabilities(): readonly Capability[];
|
|
80
|
+
export declare function capabilities(actions: readonly string[]): readonly Capability[];
|
|
81
|
+
export declare function siteCapabilities(): readonly Capability[];
|
|
58
82
|
export declare function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection;
|
|
59
83
|
export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], typedSelection: TypedSelection | undefined): DiscoveredRoom;
|
|
60
|
-
export declare function mapDiscovery(document: HouseDiscoveryDocument, rooms: readonly DiscoveredRoom[]): Discovery;
|
|
84
|
+
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
|
61
85
|
//# sourceMappingURL=discovery.d.ts.map
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,SAAS,EACT,cAAc,EACf,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,SAAS,EACT,cAAc,EACf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AAExD,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AAEvE,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAU,CAAC;AAE1D,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAMrD,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAAS,MAAM,EAAgB,CAAC;AAE9D,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAY3C,CAAC;AAEF,eAAO,MAAM,YAAY,sBAAsB,CAAC;AAEhD,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,MAAM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AAE,CAU9E;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAKxD;AAED,wBAAgB,iBAAiB,CAAC,aAAa,EAAE,cAAc,CAAC,eAAe,CAAC,GAAG,cAAc,CAEhG;AAED,wBAAgB,cAAc,CAC5B,SAAS,EAAE,cAAc,EACzB,aAAa,EAAE,cAAc,CAAC,eAAe,CAAC,EAC9C,cAAc,EAAE,cAAc,GAAG,SAAS,GACzC,cAAc,CAiBhB;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,GAAG,gBAAgB,CAAC,EACnE,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAUX"}
|
package/dist/discovery.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';
|
|
2
|
-
import {
|
|
2
|
+
import { PRIVATE_LOCATOR } from './transport.js';
|
|
3
|
+
import { readPosition, roomVersion } from './version.js';
|
|
3
4
|
export const ROOM_CONTRACT_VERSION = 1;
|
|
4
5
|
export const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';
|
|
5
6
|
export const ROOM_VERSION_NOTIFICATIONS = 'room-version-notifications';
|
|
@@ -10,12 +11,33 @@ export const DISCOVER_PREFIXES = [
|
|
|
10
11
|
];
|
|
11
12
|
export const PROVIDER_SELECTION_ROOTS = [
|
|
12
13
|
'agents',
|
|
13
|
-
'
|
|
14
|
+
'collaboration/routines',
|
|
15
|
+
'house',
|
|
16
|
+
'settings/apps',
|
|
17
|
+
'settings/panel.md'
|
|
14
18
|
];
|
|
15
|
-
export const
|
|
19
|
+
export const UNTYPED_FOLDERS = [
|
|
20
|
+
'capture'
|
|
21
|
+
];
|
|
22
|
+
export const RESERVED_NAMES = [
|
|
23
|
+
'ROOM.md',
|
|
24
|
+
'capture',
|
|
25
|
+
'settings',
|
|
26
|
+
'collaboration',
|
|
27
|
+
'rooms',
|
|
28
|
+
'agents',
|
|
29
|
+
'house',
|
|
30
|
+
'work',
|
|
31
|
+
'entities',
|
|
32
|
+
'schema',
|
|
33
|
+
'commitments'
|
|
34
|
+
];
|
|
35
|
+
export const HOUSE_SCHEMA = 'house/schema.yaml';
|
|
36
|
+
export const PRIVATE_HANDLE = 'private';
|
|
16
37
|
const BOUND_KEYS = [
|
|
17
38
|
'max_authored_file_bytes',
|
|
18
39
|
'max_batch_operations',
|
|
40
|
+
'max_batch_documents',
|
|
19
41
|
'max_path_length',
|
|
20
42
|
'max_path_depth',
|
|
21
43
|
'max_mount_files',
|
|
@@ -58,43 +80,27 @@ function parseOperations(value) {
|
|
|
58
80
|
function parseAuthority(value) {
|
|
59
81
|
if (typeof value !== 'object' || value === null) return null;
|
|
60
82
|
const held = value;
|
|
61
|
-
if (held.kind !== 'room'
|
|
83
|
+
if (held.kind !== 'room') return null;
|
|
62
84
|
if (typeof held.name !== 'string' || held.name.length === 0) return null;
|
|
63
|
-
if (typeof held.
|
|
85
|
+
if (typeof held.model_root !== 'string') return null;
|
|
64
86
|
if (held.managed_replication !== 'admitted' && held.managed_replication !== 'unavailable') {
|
|
65
87
|
return null;
|
|
66
88
|
}
|
|
67
|
-
|
|
89
|
+
const at = readPosition(held);
|
|
68
90
|
const protectedPaths = stringList(held.protected_paths);
|
|
69
91
|
const operations = parseOperations(held.operations);
|
|
70
|
-
if (protectedPaths === null || operations === null) return null;
|
|
71
|
-
if (held.kind === 'private') {
|
|
72
|
-
return {
|
|
73
|
-
kind: 'private',
|
|
74
|
-
roomRef: PRIVATE_AUTHORITY,
|
|
75
|
-
roomHandle: null,
|
|
76
|
-
name: held.name,
|
|
77
|
-
collectionRoot: held.collection_root,
|
|
78
|
-
modelRoot: held.model_root,
|
|
79
|
-
managedReplication: held.managed_replication,
|
|
80
|
-
protectedPaths,
|
|
81
|
-
operations,
|
|
82
|
-
position: held.position
|
|
83
|
-
};
|
|
84
|
-
}
|
|
92
|
+
if (at === null || protectedPaths === null || operations === null) return null;
|
|
85
93
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;
|
|
86
94
|
if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;
|
|
87
95
|
return {
|
|
88
|
-
kind: 'room',
|
|
89
96
|
roomRef: held.room_ref,
|
|
90
97
|
roomHandle: held.room_handle,
|
|
91
98
|
name: held.name,
|
|
92
|
-
|
|
93
|
-
modelRoot: held.model_root,
|
|
99
|
+
schema: held.model_root,
|
|
94
100
|
managedReplication: held.managed_replication,
|
|
95
101
|
protectedPaths,
|
|
96
102
|
operations,
|
|
97
|
-
|
|
103
|
+
...at
|
|
98
104
|
};
|
|
99
105
|
}
|
|
100
106
|
export function parseDiscovery(body) {
|
|
@@ -103,6 +109,8 @@ export function parseDiscovery(body) {
|
|
|
103
109
|
const bounds = parseBounds(held.bounds);
|
|
104
110
|
if (bounds === null) return null;
|
|
105
111
|
if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;
|
|
112
|
+
const actions = stringList(held.actions);
|
|
113
|
+
if (actions === null || new Set(actions).size !== actions.length || actions.some((name)=>name.length === 0)) return null;
|
|
106
114
|
if (!Array.isArray(held.authorities)) return null;
|
|
107
115
|
const authorities = [];
|
|
108
116
|
for (const entry of held.authorities){
|
|
@@ -113,26 +121,120 @@ export function parseDiscovery(body) {
|
|
|
113
121
|
return {
|
|
114
122
|
bounds,
|
|
115
123
|
mdModelVersion: held.md_model_version,
|
|
124
|
+
authorities,
|
|
125
|
+
actions
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function parseSiteEntry(value) {
|
|
129
|
+
if (typeof value !== 'object' || value === null) return null;
|
|
130
|
+
const held = value;
|
|
131
|
+
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;
|
|
132
|
+
if (typeof held.segment !== 'string' || held.segment.length === 0) return null;
|
|
133
|
+
return {
|
|
134
|
+
roomRef: held.room_ref,
|
|
135
|
+
segment: held.segment
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function parseSiteSlot(value) {
|
|
139
|
+
if (typeof value !== 'object' || value === null) return null;
|
|
140
|
+
const held = value;
|
|
141
|
+
if (typeof held.slot !== 'string' || held.slot.length === 0) return null;
|
|
142
|
+
if (!Array.isArray(held.entries)) return null;
|
|
143
|
+
const entries = [];
|
|
144
|
+
for (const entry of held.entries){
|
|
145
|
+
const parsed = parseSiteEntry(entry);
|
|
146
|
+
if (parsed === null) return null;
|
|
147
|
+
entries.push(parsed);
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
slot: held.slot,
|
|
151
|
+
entries
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
function parseSiteAuthority(value) {
|
|
155
|
+
if (typeof value !== 'object' || value === null) return null;
|
|
156
|
+
const held = value;
|
|
157
|
+
if (held.kind !== 'room') return null;
|
|
158
|
+
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0) return null;
|
|
159
|
+
if (typeof held.room_handle !== 'string' || held.room_handle.length === 0) return null;
|
|
160
|
+
if (typeof held.model_root !== 'string') return null;
|
|
161
|
+
const at = readPosition(held);
|
|
162
|
+
if (at === null) return null;
|
|
163
|
+
return {
|
|
164
|
+
roomRef: held.room_ref,
|
|
165
|
+
roomHandle: held.room_handle,
|
|
166
|
+
schema: held.model_root,
|
|
167
|
+
...at
|
|
168
|
+
};
|
|
169
|
+
}
|
|
170
|
+
export function parseSiteDiscovery(body) {
|
|
171
|
+
if (typeof body !== 'object' || body === null) return null;
|
|
172
|
+
const held = body;
|
|
173
|
+
const bounds = parseBounds(held.bounds);
|
|
174
|
+
if (bounds === null) return null;
|
|
175
|
+
if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0) return null;
|
|
176
|
+
if (!Array.isArray(held.slots) || !Array.isArray(held.authorities)) return null;
|
|
177
|
+
const slots = [];
|
|
178
|
+
for (const entry of held.slots){
|
|
179
|
+
const slot = parseSiteSlot(entry);
|
|
180
|
+
if (slot === null) return null;
|
|
181
|
+
slots.push(slot);
|
|
182
|
+
}
|
|
183
|
+
const authorities = [];
|
|
184
|
+
for (const entry of held.authorities){
|
|
185
|
+
const authority = parseSiteAuthority(entry);
|
|
186
|
+
if (authority === null) return null;
|
|
187
|
+
authorities.push(authority);
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
bounds,
|
|
191
|
+
mdModelVersion: held.md_model_version,
|
|
192
|
+
slots,
|
|
116
193
|
authorities
|
|
117
194
|
};
|
|
118
195
|
}
|
|
196
|
+
export function siteTracked(document) {
|
|
197
|
+
return document.authorities.map((authority)=>({
|
|
198
|
+
locator: authority.roomRef,
|
|
199
|
+
authority: authority.roomRef,
|
|
200
|
+
handle: authority.roomHandle,
|
|
201
|
+
schema: authority.schema,
|
|
202
|
+
schemas: [
|
|
203
|
+
authority.schema
|
|
204
|
+
],
|
|
205
|
+
position: authority.position,
|
|
206
|
+
logEpoch: authority.logEpoch
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
export function siteSlots(document) {
|
|
210
|
+
return document.slots.map(({ slot, entries })=>({
|
|
211
|
+
slot,
|
|
212
|
+
entries: entries.map(({ roomRef, segment })=>({
|
|
213
|
+
locator: roomRef,
|
|
214
|
+
segment
|
|
215
|
+
}))
|
|
216
|
+
}));
|
|
217
|
+
}
|
|
119
218
|
export function locatorOf(authority) {
|
|
120
|
-
return authority.roomHandle
|
|
219
|
+
return authority.roomHandle === PRIVATE_HANDLE ? PRIVATE_LOCATOR : authority.roomRef;
|
|
220
|
+
}
|
|
221
|
+
function schemasOf(authority) {
|
|
222
|
+
return authority.roomHandle === PRIVATE_HANDLE ? [
|
|
223
|
+
authority.schema,
|
|
224
|
+
HOUSE_SCHEMA
|
|
225
|
+
] : [
|
|
226
|
+
authority.schema
|
|
227
|
+
];
|
|
121
228
|
}
|
|
122
229
|
export function trackedFrom(document) {
|
|
123
230
|
return document.authorities.map((authority)=>({
|
|
124
231
|
locator: locatorOf(authority),
|
|
125
232
|
authority: authority.roomRef,
|
|
126
|
-
handle: authority.roomHandle
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
PROVIDER_SELECTION_MODEL_ROOT
|
|
132
|
-
] : [
|
|
133
|
-
authority.modelRoot
|
|
134
|
-
],
|
|
135
|
-
roomVersion: authority.position
|
|
233
|
+
handle: authority.roomHandle,
|
|
234
|
+
schema: authority.schema,
|
|
235
|
+
schemas: schemasOf(authority),
|
|
236
|
+
position: authority.position,
|
|
237
|
+
logEpoch: authority.logEpoch
|
|
136
238
|
}));
|
|
137
239
|
}
|
|
138
240
|
export function providerLimits(bounds) {
|
|
@@ -145,6 +247,10 @@ export function providerLimits(bounds) {
|
|
|
145
247
|
name: 'change-batch-operations',
|
|
146
248
|
value: bounds.max_batch_operations
|
|
147
249
|
},
|
|
250
|
+
{
|
|
251
|
+
name: 'change-documents',
|
|
252
|
+
value: bounds.max_batch_documents
|
|
253
|
+
},
|
|
148
254
|
{
|
|
149
255
|
name: 'path-length',
|
|
150
256
|
value: bounds.max_path_length
|
|
@@ -170,14 +276,14 @@ export function declaredRetention(bounds) {
|
|
|
170
276
|
refreshHorizon: bounds.change_retention_seconds
|
|
171
277
|
};
|
|
172
278
|
}
|
|
173
|
-
export function capabilities() {
|
|
279
|
+
export function capabilities(actions) {
|
|
174
280
|
return [
|
|
175
281
|
{
|
|
176
282
|
name: ROOM_VERSION_NOTIFICATIONS
|
|
177
283
|
},
|
|
178
284
|
{
|
|
179
285
|
name: PROVIDER_ACTIONS,
|
|
180
|
-
actions: declaredActions(),
|
|
286
|
+
actions: declaredActions(actions),
|
|
181
287
|
conversationCards: HOUSE_CONVERSATION_CARDS
|
|
182
288
|
},
|
|
183
289
|
{
|
|
@@ -185,6 +291,23 @@ export function capabilities() {
|
|
|
185
291
|
}
|
|
186
292
|
];
|
|
187
293
|
}
|
|
294
|
+
export function siteCapabilities() {
|
|
295
|
+
return [
|
|
296
|
+
{
|
|
297
|
+
name: ROOM_VERSION_NOTIFICATIONS
|
|
298
|
+
},
|
|
299
|
+
{
|
|
300
|
+
name: PROVIDER_ACTIONS,
|
|
301
|
+
actions: [
|
|
302
|
+
{
|
|
303
|
+
name: 'submit',
|
|
304
|
+
inputShape: {},
|
|
305
|
+
resultKind: 'house'
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
}
|
|
309
|
+
];
|
|
310
|
+
}
|
|
188
311
|
export function providerSelection(attachedModel) {
|
|
189
312
|
return {
|
|
190
313
|
roots: [
|
|
@@ -197,8 +320,7 @@ export function discoveredRoom(authority, attachedModel, typedSelection) {
|
|
|
197
320
|
return {
|
|
198
321
|
name: authority.name,
|
|
199
322
|
locator: locatorOf(authority),
|
|
200
|
-
|
|
201
|
-
roomVersion: authority.position,
|
|
323
|
+
roomVersion: roomVersion(authority),
|
|
202
324
|
operations: {
|
|
203
325
|
read: [
|
|
204
326
|
...authority.operations.read
|
|
@@ -221,12 +343,16 @@ export function discoveredRoom(authority, attachedModel, typedSelection) {
|
|
|
221
343
|
...typedSelection === undefined ? {} : {
|
|
222
344
|
typedSelection
|
|
223
345
|
},
|
|
346
|
+
untypedFolders: [
|
|
347
|
+
...UNTYPED_FOLDERS
|
|
348
|
+
],
|
|
224
349
|
providerOwnedPaths: [
|
|
225
|
-
...authority.protectedPaths
|
|
350
|
+
...authority.protectedPaths,
|
|
351
|
+
...schemasOf(authority)
|
|
226
352
|
]
|
|
227
353
|
};
|
|
228
354
|
}
|
|
229
|
-
export function mapDiscovery(document, rooms) {
|
|
355
|
+
export function mapDiscovery(document, rooms, declared) {
|
|
230
356
|
return {
|
|
231
357
|
kind: 'discovery',
|
|
232
358
|
supportedVersions: [
|
|
@@ -237,7 +363,7 @@ export function mapDiscovery(document, rooms) {
|
|
|
237
363
|
version: document.mdModelVersion
|
|
238
364
|
},
|
|
239
365
|
rooms,
|
|
240
|
-
capabilities:
|
|
366
|
+
capabilities: declared,
|
|
241
367
|
providerLimits: providerLimits(document.bounds),
|
|
242
368
|
retention: declaredRetention(document.bounds)
|
|
243
369
|
};
|