@agentshouse/mdruntime-adapter 0.1.0-alpha.46 → 0.1.0-alpha.48
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 +6 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +40 -5
- package/dist/adapter.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/read.d.ts +11 -8
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +59 -18
- package/dist/read.js.map +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +9 -4
- package/dist/site.js.map +1 -1
- package/dist/stream.d.ts +6 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +13 -10
- package/dist/stream.js.map +1 -1
- package/package.json +2 -2
package/AGENTS.md
CHANGED
|
@@ -33,6 +33,12 @@ queued.
|
|
|
33
33
|
Slots answers each Slot the Provider declares, in its order, with its entries
|
|
34
34
|
in order, each a Room and its segment; a Room two Slots list is the same Room.
|
|
35
35
|
|
|
36
|
+
Each Room in Rooms lists its `attachments`, the files the Provider holds for it
|
|
37
|
+
that its Documents link by the Provider's reference, ordered by `reference`,
|
|
38
|
+
each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
|
|
39
|
+
`entry`. They are as the Provider last declared them and hold no bytes;
|
|
40
|
+
open one through the Provider Action that serves it.
|
|
41
|
+
|
|
36
42
|
Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
37
43
|
touch the network.
|
|
38
44
|
History and Call go to the Provider through the Adapter. A Call result whose
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA6YpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -2,7 +2,8 @@ import { DISCOVER_PREFIXES, HOUSE_SCHEMA, capabilities, discoveredRoom, locatorO
|
|
|
2
2
|
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf } from './model.js';
|
|
3
3
|
import { gathered, selections } from './gather.js';
|
|
4
4
|
import { createSiteAdapter } from './site.js';
|
|
5
|
-
import {
|
|
5
|
+
import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, schemaFrom, schemaPath, viewOf } from './read.js';
|
|
6
|
+
import { enumeratedLinks, scopeLinks, streamedLinks } from './links.js';
|
|
6
7
|
import { houseAction } from './actions.js';
|
|
7
8
|
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
8
9
|
import { houseNotifications } from './stream.js';
|
|
@@ -31,7 +32,40 @@ export function createAgentsHouseAdapter(options) {
|
|
|
31
32
|
const transport = options.transport;
|
|
32
33
|
const notifications = houseNotifications(transport, 'credential');
|
|
33
34
|
const tracked = new Map();
|
|
35
|
+
const handed = new Map();
|
|
34
36
|
const models = modelShelf();
|
|
37
|
+
function bootstrappedRoom(envelope, entry) {
|
|
38
|
+
const scope = envelope.scopes.find((candidate)=>matchesScope(candidate, entry));
|
|
39
|
+
if (scope === undefined) return {
|
|
40
|
+
kind: 'room-not-readable',
|
|
41
|
+
locator: entry.locator
|
|
42
|
+
};
|
|
43
|
+
handed.set(entry.locator, scopeLinks(scope));
|
|
44
|
+
return bootstrapOf(scope, entry);
|
|
45
|
+
}
|
|
46
|
+
function enumeratedRoom(enumeration, ask) {
|
|
47
|
+
const view = viewOf(enumeration, ask.entry);
|
|
48
|
+
if (view === undefined) return {
|
|
49
|
+
kind: 'room-not-readable',
|
|
50
|
+
locator: ask.entry.locator
|
|
51
|
+
};
|
|
52
|
+
const answer = refreshFrom(view, ask.entry, ask.fromRoomVersion);
|
|
53
|
+
if (answer.kind === 'net-advancement') {
|
|
54
|
+
handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
|
|
55
|
+
}
|
|
56
|
+
return answer;
|
|
57
|
+
}
|
|
58
|
+
function streamed(entry, request, from) {
|
|
59
|
+
const links = handed.get(entry.locator);
|
|
60
|
+
if (links?.roomVersion !== request.fromRoomVersion) return null;
|
|
61
|
+
const advanced = notifications.advance(entry, from);
|
|
62
|
+
if (advanced === null) return null;
|
|
63
|
+
if (request.minPosition !== undefined && !reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch)) return null;
|
|
64
|
+
const relinked = streamedLinks(links, advanced);
|
|
65
|
+
if (relinked === null) return null;
|
|
66
|
+
handed.set(entry.locator, relinked);
|
|
67
|
+
return advanced.page;
|
|
68
|
+
}
|
|
35
69
|
function held(envelope, entry, schema, failure) {
|
|
36
70
|
return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
|
|
37
71
|
}
|
|
@@ -123,7 +157,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
123
157
|
part.forEach((entry, index)=>{
|
|
124
158
|
const failure = classified[index];
|
|
125
159
|
if (failure === null || failure === undefined) {
|
|
126
|
-
answers.push(envelope === null ? UNCERTAIN_READ :
|
|
160
|
+
answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
|
|
127
161
|
return;
|
|
128
162
|
}
|
|
129
163
|
answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
|
|
@@ -188,7 +222,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
188
222
|
answers.set(ask, failure);
|
|
189
223
|
return;
|
|
190
224
|
}
|
|
191
|
-
answers.set(ask, enumeration === null ? UNCERTAIN_READ :
|
|
225
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
192
226
|
});
|
|
193
227
|
open = [];
|
|
194
228
|
}
|
|
@@ -286,6 +320,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
286
320
|
const entries = trackedFrom(document);
|
|
287
321
|
tracked.clear();
|
|
288
322
|
for (const entry of entries)tracked.set(entry.locator, entry);
|
|
323
|
+
for (const locator of handed.keys())if (!tracked.has(locator)) handed.delete(locator);
|
|
289
324
|
notifications.track(entries);
|
|
290
325
|
const acquired = await acquireModels(entries);
|
|
291
326
|
models.keep(entries.map((entry)=>entry.locator));
|
|
@@ -315,8 +350,8 @@ export function createAgentsHouseAdapter(options) {
|
|
|
315
350
|
if (from === null) return {
|
|
316
351
|
kind: 'beyond-horizon'
|
|
317
352
|
};
|
|
318
|
-
const
|
|
319
|
-
if (
|
|
353
|
+
const answered = streamed(entry, request, from);
|
|
354
|
+
if (answered !== null) return answered;
|
|
320
355
|
const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
|
|
321
356
|
return enumerateTogether({
|
|
322
357
|
entry,
|
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 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 bootstrapFrom,\n contentPrefixes,\n parseEnumeration,\n parseEnvelope,\n parseGrant,\n refreshFrom,\n schemaFrom,\n schemaPath,\n} from './read.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 models = modelShelf();\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 const own = schemaPath(entry.handle, entry.schema);\n return entry.locator === PRIVATE_LOCATOR ? [own, schemaPath(undefined, HOUSE_SCHEMA)] : [own];\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 (authority.roomHandle !== null) {\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 : bootstrapFrom(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\n ? UNCERTAIN_READ\n : refreshFrom(enumeration, ask.entry, ask.fromRoomVersion),\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 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 streamed = notifications.advance(entry, from);\n if (\n streamed !== null &&\n (request.minPosition === undefined ||\n reachedVersion(streamed.roomVersion, request.minPosition, entry.logEpoch))\n )\n return streamed;\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","bootstrapFrom","contentPrefixes","parseEnumeration","parseEnvelope","parseGrant","refreshFrom","schemaFrom","schemaPath","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","models","held","entry","schema","failure","handle","modelPrefixes","own","locator","undefined","acquireModels","entries","acquired","part","length","privateEntry","find","answer","door","prefixes","flatMap","status","body","bundled","set","roomOf","authority","key","collection","retain","get","roomHandle","identity","selection","authorityFor","withAt","result","position","log_epoch","logEpoch","values","at","grant","method","transfer","act","url","weight","bootstrapped","answers","map","forEach","index","push","layered","asks","depths","layers","ask","depth","enumerated","parts","layer","open","positions","from","minPosition","min_position","refusal","named","filter","fields","behind","includes","expired","answered","gone","enumeration","fromRoomVersion","bootstrapTogether","enumerateTogether","uploaded","head","changes","delta","bytes","handed","keep","paths","sha256","upload","minted","delivered","operation","holding","submit","prepared","authorize","model","_authorization","request","discover","document","clear","track","authorities","actions","bootstrap","pageToken","refresh","streamed","advance","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,Q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G,YAAY,CAAC,IAAI;oBAAE4G,UAAUjB,QAAQiB,QAAQ;gBAAC,CAAC;gBACxE,GAAIjB,QAAQQ,SAAS,KAAKnG,YAAY,CAAC,IAAI;oBAAEmG,WAAWR,QAAQQ,SAAS;gBAAC,CAAC;YAC7E;YAEF,OAAOvI,eAAe4C,OAAOI,MAAM,EAAEJ,OAAOK,IAAI,EAAEpB,MAAMM,OAAO,EAAE;gBAC/D4G,MAAMhB,QAAQgB,IAAI;gBAClB,GAAIhB,QAAQiB,QAAQ,KAAK5G,YAAY,CAAC,IAAI;oBAAE4G,UAAUjB,QAAQiB,QAAQ;gBAAC,CAAC;YAC1E;QACF;QAEAC,SAAQ9G,OAAe,EAAE+G,OAAe,EAAEC,MAAc;YACtD,OAAO1I,eAAeyI,SAASC,QAAQtF,aAAa1B,UAAU+B;QAChE;QAEA,MAAMkF,QAAOtB,cAA6B,EAAEC,OAAsB;YAChE,OAAOjE,OAAO,MAAM/E,YAAYwC,WAAWwG;QAC7C;QAEAsB,cAAc7H;QACd8H,eAAe9H,cAAc8H,aAAa;QAC1CC,aAAa/H,cAAc+H,WAAW;IACxC;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 const own = schemaPath(entry.handle, entry.schema);\n return entry.locator === PRIVATE_LOCATOR ? [own, schemaPath(undefined, HOUSE_SCHEMA)] : [own];\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 (authority.roomHandle !== null) {\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","own","acquireModels","entries","acquired","part","length","privateEntry","door","prefixes","flatMap","status","body","bundled","roomOf","authority","key","collection","retain","roomHandle","identity","selection","authorityFor","withAt","result","position","log_epoch","values","at","grant","method","transfer","act","url","weight","bootstrapped","answers","map","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,QAAQ,YAAY;AAC9C,SACEC,WAAW,EACXC,eAAe,EACfC,YAAY,EACZC,gBAAgB,EAChBC,aAAa,EACbC,UAAU,EACVC,WAAW,EACXC,UAAU,EACVC,UAAU,EACVC,MAAM,QAGD,YAAY;AACnB,SAASC,eAAe,EAAEC,UAAU,EAAEC,aAAa,QAAwB,aAAa;AACxF,SAASC,WAAW,QAAQ,eAAe;AAC3C,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ,eAAe;AAC3E,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,UAAU,EACVC,iBAAiB,EACjBC,cAAc,EACdC,aAAa,EACbC,cAAc,EACdC,cAAc,EACdC,kBAAkB,EAClBC,eAAe,QAGV,iBAAiB;AACxB,SACEC,UAAU,EACVC,SAAS,EACTC,UAAU,EACVC,WAAW,EACXC,cAAc,EACdC,YAAY,EACZC,eAAe,EACfC,aAAa,EACbC,eAAe,EACfC,YAAY,EACZC,UAAU,QA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1E;QACF;QAEAC,SAAQ1H,OAAe,EAAE2H,OAAe,EAAEC,MAAc;YACtD,OAAOvJ,eAAesJ,SAASC,QAAQ/E,aAAa7C,UAAUiB;QAChE;QAEA,MAAM4G,QAAOtB,cAA6B,EAAE7F,OAAsB;YAChE,OAAOoC,OAAO,MAAMnG,YAAYwC,WAAWuB;QAC7C;QAEAoH,cAAc1I;QACd2I,eAAe3I,cAAc2I,aAAa;QAC1CC,aAAa5I,cAAc4I,WAAW;IACxC;AACF"}
|
package/dist/links.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { HouseScope, HouseView } from './read.js';
|
|
2
|
+
import type { StreamedAdvancement } from './stream.js';
|
|
3
|
+
export type RoomLinks = {
|
|
4
|
+
roomVersion: string;
|
|
5
|
+
handed: ReadonlySet<string>;
|
|
6
|
+
paths: ReadonlyMap<string, ReadonlySet<string>>;
|
|
7
|
+
};
|
|
8
|
+
export declare function scopeLinks(scope: HouseScope): RoomLinks;
|
|
9
|
+
export declare function enumeratedLinks(view: HouseView, earlier: RoomLinks | undefined): RoomLinks;
|
|
10
|
+
export declare function streamedLinks(held: RoomLinks, advanced: StreamedAdvancement): RoomLinks | null;
|
|
11
|
+
//# sourceMappingURL=links.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAOvD,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5B,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;CACjD,CAAC;AAYF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAMvD;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAM1F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAkB9F"}
|
package/dist/links.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { roomVersion } from './version.js';
|
|
2
|
+
const ATTACHMENT_REFERENCE = /at_[1-9a-hjkmnp-tv-z][0-9a-hjkmnp-tv-z]*\.[0-9a-hjkmnp-tv-z]/g;
|
|
3
|
+
const NONE = new Set();
|
|
4
|
+
function linkedBy(text) {
|
|
5
|
+
if (text === null) return NONE;
|
|
6
|
+
const references = new Set(Array.from(text.matchAll(ATTACHMENT_REFERENCE), ([found])=>found));
|
|
7
|
+
return references.size === 0 ? NONE : references;
|
|
8
|
+
}
|
|
9
|
+
function handedOf(attachments) {
|
|
10
|
+
return new Set((attachments ?? []).map((attachment)=>attachment.reference));
|
|
11
|
+
}
|
|
12
|
+
export function scopeLinks(scope) {
|
|
13
|
+
return {
|
|
14
|
+
roomVersion: roomVersion(scope),
|
|
15
|
+
handed: handedOf(scope.attachments),
|
|
16
|
+
paths: new Map(scope.contents.map(({ path, content })=>[
|
|
17
|
+
path,
|
|
18
|
+
linkedBy(content)
|
|
19
|
+
]))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function enumeratedLinks(view, earlier) {
|
|
23
|
+
const paths = new Map(earlier?.paths);
|
|
24
|
+
for (const change of view.changes){
|
|
25
|
+
paths.set(change.path, linkedBy('content' in change ? change.content : null));
|
|
26
|
+
}
|
|
27
|
+
return {
|
|
28
|
+
roomVersion: roomVersion(view),
|
|
29
|
+
handed: handedOf(view.attachments),
|
|
30
|
+
paths
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
export function streamedLinks(held, advanced) {
|
|
34
|
+
const paths = new Map(held.paths);
|
|
35
|
+
const dropped = new Set();
|
|
36
|
+
for (const entry of advanced.entries){
|
|
37
|
+
const text = entry.kind === 'removed' ? null : entry.text;
|
|
38
|
+
if (text === undefined) return null;
|
|
39
|
+
const linked = linkedBy(text);
|
|
40
|
+
for (const reference of linked)if (!held.handed.has(reference)) return null;
|
|
41
|
+
for (const reference of paths.get(entry.path) ?? held.handed){
|
|
42
|
+
if (held.handed.has(reference) && !linked.has(reference)) dropped.add(reference);
|
|
43
|
+
}
|
|
44
|
+
paths.set(entry.path, linked);
|
|
45
|
+
}
|
|
46
|
+
for (const references of paths.values()){
|
|
47
|
+
for (const reference of references)dropped.delete(reference);
|
|
48
|
+
}
|
|
49
|
+
if (dropped.size > 0) return null;
|
|
50
|
+
return {
|
|
51
|
+
roomVersion: advanced.page.roomVersion,
|
|
52
|
+
handed: held.handed,
|
|
53
|
+
paths
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=links.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/links.ts"],"sourcesContent":["import type { RoomAttachment } from '@agentshouse/mdruntime';\nimport type { HouseScope, HouseView } from './read.js';\nimport type { StreamedAdvancement } from './stream.js';\nimport { roomVersion } from './version.js';\n\nconst ATTACHMENT_REFERENCE = /at_[1-9a-hjkmnp-tv-z][0-9a-hjkmnp-tv-z]*\\.[0-9a-hjkmnp-tv-z]/g;\n\nconst NONE: ReadonlySet<string> = new Set();\n\nexport type RoomLinks = {\n roomVersion: string;\n handed: ReadonlySet<string>;\n paths: ReadonlyMap<string, ReadonlySet<string>>;\n};\n\nfunction linkedBy(text: string | null): ReadonlySet<string> {\n if (text === null) return NONE;\n const references = new Set(Array.from(text.matchAll(ATTACHMENT_REFERENCE), ([found]) => found));\n return references.size === 0 ? NONE : references;\n}\n\nfunction handedOf(attachments: readonly RoomAttachment[] | undefined): ReadonlySet<string> {\n return new Set((attachments ?? []).map((attachment) => attachment.reference));\n}\n\nexport function scopeLinks(scope: HouseScope): RoomLinks {\n return {\n roomVersion: roomVersion(scope),\n handed: handedOf(scope.attachments),\n paths: new Map(scope.contents.map(({ path, content }) => [path, linkedBy(content)])),\n };\n}\n\nexport function enumeratedLinks(view: HouseView, earlier: RoomLinks | undefined): RoomLinks {\n const paths = new Map(earlier?.paths);\n for (const change of view.changes) {\n paths.set(change.path, linkedBy('content' in change ? change.content : null));\n }\n return { roomVersion: roomVersion(view), handed: handedOf(view.attachments), paths };\n}\n\nexport function streamedLinks(held: RoomLinks, advanced: StreamedAdvancement): RoomLinks | null {\n const paths = new Map(held.paths);\n const dropped = new Set<string>();\n for (const entry of advanced.entries) {\n const text = entry.kind === 'removed' ? null : entry.text;\n if (text === undefined) return null;\n const linked = linkedBy(text);\n for (const reference of linked) if (!held.handed.has(reference)) return null;\n for (const reference of paths.get(entry.path) ?? held.handed) {\n if (held.handed.has(reference) && !linked.has(reference)) dropped.add(reference);\n }\n paths.set(entry.path, linked);\n }\n for (const references of paths.values()) {\n for (const reference of references) dropped.delete(reference);\n }\n if (dropped.size > 0) return null;\n return { roomVersion: advanced.page.roomVersion, handed: held.handed, paths };\n}\n"],"names":["roomVersion","ATTACHMENT_REFERENCE","NONE","Set","linkedBy","text","references","Array","from","matchAll","found","size","handedOf","attachments","map","attachment","reference","scopeLinks","scope","handed","paths","Map","contents","path","content","enumeratedLinks","view","earlier","change","changes","set","streamedLinks","held","advanced","dropped","entry","entries","kind","undefined","linked","has","get","add","values","delete","page"],"mappings":"AAGA,SAASA,WAAW,QAAQ,eAAe;AAE3C,MAAMC,uBAAuB;AAE7B,MAAMC,OAA4B,IAAIC;AAQtC,SAASC,SAASC,IAAmB;IACnC,IAAIA,SAAS,MAAM,OAAOH;IAC1B,MAAMI,aAAa,IAAIH,IAAII,MAAMC,IAAI,CAACH,KAAKI,QAAQ,CAACR,uBAAuB,CAAC,CAACS,MAAM,GAA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;YAC5D,IAAIa,KAAKb,MAAM,CAACqB,GAAG,CAACxB,cAAc,CAACuB,OAAOC,GAAG,CAACxB,YAAYkB,QAAQQ,GAAG,CAAC1B;QACxE;QACAI,MAAMU,GAAG,CAACK,MAAMZ,IAAI,EAAEgB;IACxB;IACA,KAAK,MAAMjC,cAAcc,MAAMuB,MAAM,GAAI;QACvC,KAAK,MAAM3B,aAAaV,WAAY4B,QAAQU,MAAM,CAAC5B;IACrD;IACA,IAAIkB,QAAQvB,IAAI,GAAG,GAAG,OAAO;IAC7B,OAAO;QAAEX,aAAaiC,SAASY,IAAI,CAAC7C,WAAW;QAAEmB,QAAQa,KAAKb,MAAM;QAAEC;IAAM;AAC9E"}
|
package/dist/read.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BootstrapPage,
|
|
1
|
+
import type { BootstrapPage, RefreshResult, RoomAttachment } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseMode } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
@@ -17,6 +17,7 @@ export type HouseScope = LogPosition & {
|
|
|
17
17
|
anchor: string;
|
|
18
18
|
files: readonly HouseManifestFile[];
|
|
19
19
|
contents: readonly HouseContent[];
|
|
20
|
+
attachments?: readonly RoomAttachment[];
|
|
20
21
|
};
|
|
21
22
|
export type HouseEnvelope = {
|
|
22
23
|
scopes: readonly HouseScope[];
|
|
@@ -44,11 +45,13 @@ export type HouseChange = {
|
|
|
44
45
|
revision: string;
|
|
45
46
|
};
|
|
46
47
|
};
|
|
48
|
+
export type HouseView = LogPosition & {
|
|
49
|
+
authority: string;
|
|
50
|
+
changes: readonly HouseChange[];
|
|
51
|
+
attachments?: readonly RoomAttachment[];
|
|
52
|
+
};
|
|
47
53
|
export type HouseEnumeration = {
|
|
48
|
-
authorities: readonly
|
|
49
|
-
authority: string;
|
|
50
|
-
changes: readonly HouseChange[];
|
|
51
|
-
})[];
|
|
54
|
+
authorities: readonly HouseView[];
|
|
52
55
|
};
|
|
53
56
|
export declare function authorityRoot(handle: string | undefined): string;
|
|
54
57
|
export declare function contentPrefixes(tracked: TrackedAuthority): readonly string[];
|
|
@@ -61,10 +64,9 @@ export declare function headChange(held: {
|
|
|
61
64
|
export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
|
|
62
65
|
export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
|
|
63
66
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
|
64
|
-
export declare function advancedScope(scope: HouseScope, view:
|
|
67
|
+
export declare function advancedScope(scope: HouseScope, view: HouseView): HouseScope;
|
|
65
68
|
export declare function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean;
|
|
66
69
|
export declare function selects(tracked: TrackedAuthority, path: string): boolean;
|
|
67
|
-
export declare function bootstrapFrom(envelope: HouseEnvelope, tracked: TrackedAuthority): BootstrapResult;
|
|
68
70
|
export declare function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage;
|
|
69
71
|
export type HouseSchema = {
|
|
70
72
|
schema: string | null;
|
|
@@ -72,5 +74,6 @@ export type HouseSchema = {
|
|
|
72
74
|
};
|
|
73
75
|
export declare function schemaFrom(envelope: HouseEnvelope, tracked: TrackedAuthority, schema: string): HouseSchema | null;
|
|
74
76
|
export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
|
|
75
|
-
export declare function
|
|
77
|
+
export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
|
|
78
|
+
export declare function refreshFrom(view: HouseView, tracked: TrackedAuthority, fromRoomVersion: string): RefreshResult;
|
|
76
79
|
//# sourceMappingURL=read.d.ts.map
|
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,EACV,aAAa,
|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== 'object' || value === null) return null;
|
|
65
|
+
const { attachment, name, bytes, media_type: mediaType } = value;
|
|
66
|
+
if (typeof attachment !== 'string' || typeof name !== 'string') return null;
|
|
67
|
+
if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0) return null;
|
|
68
|
+
if (mediaType !== null && typeof mediaType !== 'string') return null;
|
|
69
|
+
return {
|
|
70
|
+
reference: attachment,
|
|
71
|
+
name,
|
|
72
|
+
byteLength: bytes,
|
|
73
|
+
mediaType,
|
|
74
|
+
entry: value
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function parseOriginals(value) {
|
|
78
|
+
if (!Array.isArray(value)) return null;
|
|
79
|
+
const attachments = [];
|
|
80
|
+
for (const entry of value){
|
|
81
|
+
const attachment = parseOriginal(entry);
|
|
82
|
+
if (attachment === null) return null;
|
|
83
|
+
attachments.push(attachment);
|
|
84
|
+
}
|
|
85
|
+
return attachments;
|
|
86
|
+
}
|
|
87
|
+
function declared(attachments) {
|
|
88
|
+
return attachments === undefined ? {} : {
|
|
89
|
+
attachments
|
|
90
|
+
};
|
|
91
|
+
}
|
|
63
92
|
function parseFile(value, mode) {
|
|
64
93
|
if (typeof value !== 'object' || value === null) return null;
|
|
65
94
|
const file = value;
|
|
@@ -110,12 +139,21 @@ function parseScope(value, mode) {
|
|
|
110
139
|
content: content.content
|
|
111
140
|
});
|
|
112
141
|
}
|
|
113
|
-
return {
|
|
142
|
+
if (mode === 'site') return {
|
|
114
143
|
anchor: manifest.anchor,
|
|
115
144
|
...at,
|
|
116
145
|
files,
|
|
117
146
|
contents
|
|
118
147
|
};
|
|
148
|
+
const attachments = parseOriginals(held.originals);
|
|
149
|
+
if (attachments === null) return null;
|
|
150
|
+
return {
|
|
151
|
+
anchor: manifest.anchor,
|
|
152
|
+
...at,
|
|
153
|
+
files,
|
|
154
|
+
contents,
|
|
155
|
+
attachments
|
|
156
|
+
};
|
|
119
157
|
}
|
|
120
158
|
export function parseEnvelope(body) {
|
|
121
159
|
if (typeof body !== 'object' || body === null) return null;
|
|
@@ -190,10 +228,21 @@ export function parseEnumeration(body, mode) {
|
|
|
190
228
|
if (mapped === null) return null;
|
|
191
229
|
changes.push(mapped);
|
|
192
230
|
}
|
|
231
|
+
if (mode === 'site') {
|
|
232
|
+
authorities.push({
|
|
233
|
+
authority: held.authority,
|
|
234
|
+
...at,
|
|
235
|
+
changes
|
|
236
|
+
});
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const attachments = parseOriginals(held.originals);
|
|
240
|
+
if (attachments === null) return null;
|
|
193
241
|
authorities.push({
|
|
194
242
|
authority: held.authority,
|
|
195
243
|
...at,
|
|
196
|
-
changes
|
|
244
|
+
changes,
|
|
245
|
+
attachments
|
|
197
246
|
});
|
|
198
247
|
}
|
|
199
248
|
return {
|
|
@@ -266,14 +315,6 @@ export function selects(tracked, path) {
|
|
|
266
315
|
const first = path.split('/', 1)[0].toLowerCase();
|
|
267
316
|
return !RESERVED_NAMES.some((name)=>name.toLowerCase() === first) || homes(tracked).some((home)=>path === home || path.startsWith(`${home}/`));
|
|
268
317
|
}
|
|
269
|
-
export function bootstrapFrom(envelope, tracked) {
|
|
270
|
-
const scope = envelope.scopes.find((entry)=>matchesScope(entry, tracked));
|
|
271
|
-
if (scope === undefined) return {
|
|
272
|
-
kind: 'room-not-readable',
|
|
273
|
-
locator: tracked.locator
|
|
274
|
-
};
|
|
275
|
-
return bootstrapOf(scope, tracked);
|
|
276
|
-
}
|
|
277
318
|
export function bootstrapOf(scope, tracked) {
|
|
278
319
|
const contents = new Map(scope.contents.map((entry)=>[
|
|
279
320
|
entry.path,
|
|
@@ -297,7 +338,8 @@ export function bootstrapOf(scope, tracked) {
|
|
|
297
338
|
documents,
|
|
298
339
|
revisions,
|
|
299
340
|
changes,
|
|
300
|
-
binaryTargets: binaryTargets.sort()
|
|
341
|
+
binaryTargets: binaryTargets.sort(),
|
|
342
|
+
...declared(scope.attachments)
|
|
301
343
|
};
|
|
302
344
|
}
|
|
303
345
|
export function schemaFrom(envelope, tracked, schema) {
|
|
@@ -317,12 +359,10 @@ export function schemaOf(scope, schema) {
|
|
|
317
359
|
version: file.version
|
|
318
360
|
};
|
|
319
361
|
}
|
|
320
|
-
export function
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
locator: tracked.locator
|
|
325
|
-
};
|
|
362
|
+
export function viewOf(enumeration, tracked) {
|
|
363
|
+
return enumeration.authorities.find((entry)=>entry.authority === tracked.authority);
|
|
364
|
+
}
|
|
365
|
+
export function refreshFrom(view, tracked, fromRoomVersion) {
|
|
326
366
|
if (roomVersion(view) === fromRoomVersion) return {
|
|
327
367
|
kind: 'still-current'
|
|
328
368
|
};
|
|
@@ -353,7 +393,8 @@ export function refreshFrom(enumeration, tracked, fromRoomVersion) {
|
|
|
353
393
|
revisions,
|
|
354
394
|
changes,
|
|
355
395
|
binaryTargets: binaryTargets.sort(),
|
|
356
|
-
removals: removals.sort()
|
|
396
|
+
removals: removals.sort(),
|
|
397
|
+
...declared(view.attachments)
|
|
357
398
|
};
|
|
358
399
|
}
|
|
359
400
|
|
package/dist/read.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/read.ts"],"sourcesContent":["import type {\n BootstrapPage,\n BootstrapResult,\n ChangeAuthor,\n RefreshResult,\n} from '@agentshouse/mdruntime';\nimport {\n UNTYPED_FOLDERS,\n PROVIDER_SELECTION_ROOTS,\n RESERVED_NAMES,\n type TrackedAuthority,\n} from './discovery.js';\nimport type { HouseMode } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport type HeadChange = BootstrapPage['changes'][string];\n\nexport type HouseManifestFile = {\n path: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\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'; url: string }\n | { method: 'POST'; operation: string; url: string };\n\nexport type HouseChange =\n | { path: string; removed: true }\n | {\n path: string;\n content: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\n }\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 function contentPrefixes(tracked: TrackedAuthority): readonly string[] {\n return [authorityRoot(tracked.handle)];\n}\n\nexport function schemaPath(handle: string | undefined, schema: string): string {\n return `${authorityRoot(handle)}/${schema}`;\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 (typeof transfer.url !== 'string') return null;\n if (transfer.method === 'GET') return { method: 'GET', url: transfer.url };\n if (transfer.method !== 'POST' || typeof transfer.operation !== 'string') return null;\n return { method: 'POST', operation: transfer.operation, url: transfer.url };\n}\n\nfunction changeAuthor(value: unknown): ChangeAuthor | null {\n if (typeof value !== 'object' || value === null) return null;\n const { user, site, name } = value as Record<string, unknown>;\n if (typeof name !== 'string') return null;\n if (typeof user === 'string' && site === undefined) return { kind: 'user', id: user, name };\n if (typeof site === 'string' && user === undefined) return { kind: 'site', id: site, name };\n return null;\n}\n\nexport function headChange(held: {\n readonly author?: unknown;\n readonly created_at?: unknown;\n}): HeadChange | undefined | null {\n const author = held.author === undefined ? null : changeAuthor(held.author);\n if (held.author !== undefined && author === null) return null;\n if (held.created_at === undefined) return undefined;\n if (typeof held.created_at !== 'string') return null;\n return { author, time: held.created_at };\n}\n\nfunction headed(head: HeadChange | undefined) {\n return head === undefined ? {} : { head };\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 const head = headChange(file);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof file.sha256 !== 'string') return null;\n return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };\n }\n if (typeof file.revision !== 'string') return null;\n return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };\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 const head = headChange(held);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;\n return {\n path: held.path,\n content: held.content,\n revision: undefined,\n version: held.sha256,\n ...headed(head),\n };\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 ...headed(head),\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 ...headed(change.head),\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\nconst ROOM_HOMES: readonly string[] = ['ROOM.md', 'collaboration'];\n\nfunction homes(tracked: TrackedAuthority): readonly string[] {\n return tracked.handle === undefined\n ? [...UNTYPED_FOLDERS, ...PROVIDER_SELECTION_ROOTS]\n : [...ROOM_HOMES, ...UNTYPED_FOLDERS];\n}\n\nexport function selects(tracked: TrackedAuthority, path: string): boolean {\n if (tracked.schemas.includes(path)) return false;\n const first = path.split('/', 1)[0].toLowerCase();\n return (\n !RESERVED_NAMES.some((name) => name.toLowerCase() === first) ||\n homes(tracked).some((home) => path === home || path.startsWith(`${home}/`))\n );\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 changes: Record<string, HeadChange> = {};\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 if (file.head !== undefined) changes[file.path] = file.head;\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 changes,\n binaryTargets: binaryTargets.sort(),\n };\n}\n\nexport type HouseSchema = {\n schema: string | null;\n version: string | null;\n};\n\nexport function schemaFrom(\n envelope: HouseEnvelope,\n tracked: TrackedAuthority,\n schema: string,\n): HouseSchema | null {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return null;\n return schemaOf(scope, schema);\n}\n\nexport function schemaOf(scope: HouseScope, schema: string): HouseSchema | null {\n const file = scope.files.find((entry) => entry.path === schema);\n if (file === undefined) return { schema: null, version: null };\n const content = scope.contents.find((entry) => entry.path === schema);\n return content === undefined ? null : { schema: content.content, version: file.version };\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 changes: Record<string, HeadChange> = {};\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 if (change.head !== undefined) changes[change.path] = change.head;\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 changes,\n binaryTargets: binaryTargets.sort(),\n removals: removals.sort(),\n };\n}\n"],"names":["UNTYPED_FOLDERS","PROVIDER_SELECTION_ROOTS","RESERVED_NAMES","readPosition","roomVersion","authorityRoot","handle","undefined","contentPrefixes","tracked","schemaPath","schema","parseGrant","body","transfer","url","method","operation","changeAuthor","value","user","site","name","kind","id","headChange","held","author","created_at","time","headed","head","parseFile","mode","file","path","sha256","revision","version","parseScope","manifest","Array","isArray","contents","scope","at","anchor","length","room_handle","files","entry","push","content","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","reference","parseEnumeration","authorities","authority","changes","change","mapped","advancedScope","view","Map","map","delete","set","position","logEpoch","values","matchesScope","ROOM_HOMES","homes","selects","schemas","includes","first","split","toLowerCase","some","home","startsWith","bootstrapFrom","envelope","find","locator","bootstrapOf","documents","revisions","binaryTargets","get","sort","schemaFrom","schemaOf","refreshFrom","enumeration","fromRoomVersion","removals"],"mappings":"AAMA,SACEA,eAAe,EACfC,wBAAwB,EACxBC,cAAc,QAET,iBAAiB;AAExB,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAgD3E,OAAO,SAASC,cAAcC,MAA0B;IACtD,OAAOA,WAAWC,YAAY,aAAa,CAAC,OAAO,EAAED,QAAQ;AAC/D;AAEA,OAAO,SAASE,gBAAgBC,OAAyB;IACvD,OAAO;QAACJ,cAAcI,QAAQH,MAAM;KAAE;AACxC;AAEA,OAAO,SAASI,WAAWJ,MAA0B,EAAEK,MAAc;IACnE,OAAO,GAAGN,cAAcC,QAAQ,CAAC,EAAEK,QAAQ;AAC7C;AAEA,OAAO,SAASC,WAAWC,IAAa;IACtC,IAAI,OAAOA,SAAS,YAAYA,SAAS,MAAM,OAAO;IACtD,IAAI,CAAE,CAAA,cAAcA,IAAG,KAAM,OAAOA,KAAKC,QAAQ,KAAK,YAAYD,KAAKC,QAAQ,KAAK,MAAM;QACxF,OAAO;IACT;IACA,MAAMA,WAAWD,KAAKC,QAAQ;IAC9B,IAAI,OAAOA,SAASC,GAAG,KAAK,UAAU,OAAO;IAC7C,IAAID,SAASE,MAAM,KAAK,OAAO,OAAO;QAAEA,QAAQ;QAAOD,KAAKD,SAASC,GAAG;IAAC;IACzE,IAAID,SAASE,MAAM,KAAK,UAAU,OAAOF,SAASG,SAAS,KAAK,UAAU,OAAO;IACjF,OAAO;QAAED,QAAQ;QAAQC,WAAWH,SAASG,SAAS;QAAEF,KAAKD,SAASC,GAAG;IAAC;AAC5E;AAEA,SAASG,aAAaC,KAAc;IAClC,IAAI,OAAOA,UAAU,YA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sourcesContent":["import type {\n BootstrapPage,\n ChangeAuthor,\n RefreshResult,\n RoomAttachment,\n} from '@agentshouse/mdruntime';\nimport {\n UNTYPED_FOLDERS,\n PROVIDER_SELECTION_ROOTS,\n RESERVED_NAMES,\n type TrackedAuthority,\n} from './discovery.js';\nimport type { HouseMode } from './transport.js';\nimport { readPosition, roomVersion, type LogPosition } from './version.js';\n\nexport type HeadChange = BootstrapPage['changes'][string];\n\nexport type HouseManifestFile = {\n path: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\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 attachments?: readonly RoomAttachment[];\n};\n\nexport type HouseEnvelope = {\n scopes: readonly HouseScope[];\n};\n\nexport type HouseGrant =\n | { method: 'GET'; url: string }\n | { method: 'POST'; operation: string; url: string };\n\nexport type HouseChange =\n | { path: string; removed: true }\n | {\n path: string;\n content: string;\n revision: string | undefined;\n version: string;\n head?: HeadChange;\n }\n | { path: string; reference: { revision: string } };\n\nexport type HouseView = LogPosition & {\n authority: string;\n changes: readonly HouseChange[];\n attachments?: readonly RoomAttachment[];\n};\n\nexport type HouseEnumeration = {\n authorities: readonly HouseView[];\n};\n\nexport function authorityRoot(handle: string | undefined): string {\n return handle === undefined ? '/private' : `/rooms/${handle}`;\n}\n\nexport function contentPrefixes(tracked: TrackedAuthority): readonly string[] {\n return [authorityRoot(tracked.handle)];\n}\n\nexport function schemaPath(handle: string | undefined, schema: string): string {\n return `${authorityRoot(handle)}/${schema}`;\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 (typeof transfer.url !== 'string') return null;\n if (transfer.method === 'GET') return { method: 'GET', url: transfer.url };\n if (transfer.method !== 'POST' || typeof transfer.operation !== 'string') return null;\n return { method: 'POST', operation: transfer.operation, url: transfer.url };\n}\n\nfunction changeAuthor(value: unknown): ChangeAuthor | null {\n if (typeof value !== 'object' || value === null) return null;\n const { user, site, name } = value as Record<string, unknown>;\n if (typeof name !== 'string') return null;\n if (typeof user === 'string' && site === undefined) return { kind: 'user', id: user, name };\n if (typeof site === 'string' && user === undefined) return { kind: 'site', id: site, name };\n return null;\n}\n\nexport function headChange(held: {\n readonly author?: unknown;\n readonly created_at?: unknown;\n}): HeadChange | undefined | null {\n const author = held.author === undefined ? null : changeAuthor(held.author);\n if (held.author !== undefined && author === null) return null;\n if (held.created_at === undefined) return undefined;\n if (typeof held.created_at !== 'string') return null;\n return { author, time: held.created_at };\n}\n\nfunction headed(head: HeadChange | undefined) {\n return head === undefined ? {} : { head };\n}\n\nfunction parseOriginal(value: unknown): RoomAttachment | null {\n if (typeof value !== 'object' || value === null) return null;\n const { attachment, name, bytes, media_type: mediaType } = value as Record<string, unknown>;\n if (typeof attachment !== 'string' || typeof name !== 'string') return null;\n if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0) return null;\n if (mediaType !== null && typeof mediaType !== 'string') return null;\n return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };\n}\n\nfunction parseOriginals(value: unknown): readonly RoomAttachment[] | null {\n if (!Array.isArray(value)) return null;\n const attachments: RoomAttachment[] = [];\n for (const entry of value) {\n const attachment = parseOriginal(entry);\n if (attachment === null) return null;\n attachments.push(attachment);\n }\n return attachments;\n}\n\nfunction declared(attachments: readonly RoomAttachment[] | undefined) {\n return attachments === undefined ? {} : { attachments };\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 const head = headChange(file);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof file.sha256 !== 'string') return null;\n return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };\n }\n if (typeof file.revision !== 'string') return null;\n return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };\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 if (mode === 'site') return { anchor: manifest.anchor, ...at, files, contents };\n const attachments = parseOriginals(held.originals);\n if (attachments === null) return null;\n return { anchor: manifest.anchor, ...at, files, contents, attachments };\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 const head = headChange(held);\n if (head === null) return null;\n if (mode === 'site') {\n if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;\n return {\n path: held.path,\n content: held.content,\n revision: undefined,\n version: held.sha256,\n ...headed(head),\n };\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 ...headed(head),\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: HouseView[] = [];\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 if (mode === 'site') {\n authorities.push({ authority: held.authority, ...at, changes });\n continue;\n }\n const attachments = parseOriginals(held.originals);\n if (attachments === null) return null;\n authorities.push({ authority: held.authority, ...at, changes, attachments });\n }\n return { authorities };\n}\n\nexport function advancedScope(scope: HouseScope, view: HouseView): 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 ...headed(change.head),\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\nconst ROOM_HOMES: readonly string[] = ['ROOM.md', 'collaboration'];\n\nfunction homes(tracked: TrackedAuthority): readonly string[] {\n return tracked.handle === undefined\n ? [...UNTYPED_FOLDERS, ...PROVIDER_SELECTION_ROOTS]\n : [...ROOM_HOMES, ...UNTYPED_FOLDERS];\n}\n\nexport function selects(tracked: TrackedAuthority, path: string): boolean {\n if (tracked.schemas.includes(path)) return false;\n const first = path.split('/', 1)[0].toLowerCase();\n return (\n !RESERVED_NAMES.some((name) => name.toLowerCase() === first) ||\n homes(tracked).some((home) => path === home || path.startsWith(`${home}/`))\n );\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 changes: Record<string, HeadChange> = {};\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 if (file.head !== undefined) changes[file.path] = file.head;\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 changes,\n binaryTargets: binaryTargets.sort(),\n ...declared(scope.attachments),\n };\n}\n\nexport type HouseSchema = {\n schema: string | null;\n version: string | null;\n};\n\nexport function schemaFrom(\n envelope: HouseEnvelope,\n tracked: TrackedAuthority,\n schema: string,\n): HouseSchema | null {\n const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));\n if (scope === undefined) return null;\n return schemaOf(scope, schema);\n}\n\nexport function schemaOf(scope: HouseScope, schema: string): HouseSchema | null {\n const file = scope.files.find((entry) => entry.path === schema);\n if (file === undefined) return { schema: null, version: null };\n const content = scope.contents.find((entry) => entry.path === schema);\n return content === undefined ? null : { schema: content.content, version: file.version };\n}\n\nexport function viewOf(\n enumeration: HouseEnumeration,\n tracked: TrackedAuthority,\n): HouseView | undefined {\n return enumeration.authorities.find((entry) => entry.authority === tracked.authority);\n}\n\nexport function refreshFrom(\n view: HouseView,\n tracked: TrackedAuthority,\n fromRoomVersion: string,\n): RefreshResult {\n if (roomVersion(view) === fromRoomVersion) return { kind: 'still-current' };\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\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 if (change.head !== undefined) changes[change.path] = change.head;\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 changes,\n binaryTargets: binaryTargets.sort(),\n removals: removals.sort(),\n ...declared(view.attachments),\n };\n}\n"],"names":["UNTYPED_FOLDERS","PROVIDER_SELECTION_ROOTS","RESERVED_NAMES","readPosition","roomVersion","authorityRoot","handle","undefined","contentPrefixes","tracked","schemaPath","schema","parseGrant","body","transfer","url","method","operation","changeAuthor","value","user","site","name","kind","id","headChange","held","author","created_at","time","headed","head","parseOriginal","attachment","bytes","media_type","mediaType","Number","isSafeInteger","reference","byteLength","entry","parseOriginals","Array","isArray","attachments","push","declared","parseFile","mode","file","path","sha256","revision","version","parseScope","manifest","contents","scope","at","anchor","length","room_handle","files","content","originals","parseEnvelope","scopes","parseSiteBootstrap","parseChange","removed","parseEnumeration","authorities","authority","changes","change","mapped","advancedScope","view","Map","map","delete","set","position","logEpoch","values","matchesScope","ROOM_HOMES","homes","selects","schemas","includes","first","split","toLowerCase","some","home","startsWith","bootstrapOf","documents","revisions","binaryTargets","get","sort","schemaFrom","envelope","find","schemaOf","viewOf","enumeration","refreshFrom","fromRoomVersion","removals"],"mappings":"AAMA,SACEA,eAAe,EACfC,wBAAwB,EACxBC,cAAc,QAET,iBAAiB;AAExB,SAASC,YAAY,EAAEC,WAAW,QAA0B,eAAe;AAoD3E,OAAO,SAASC,cAAcC,MAA0B;IACtD,OAAOA,WAAWC,YAAY,aAAa,CAAC,OAAO,EAAED,QAAQ;AAC/D;AAEA,OAAO,SAASE,gBAAgBC,OAAyB;IACvD,OAAO;QAACJ,cAAcI,QAAQH,MAAM;KAAE;AACxC;AAEA,OAAO,SAASI,WAAWJ,MAA0B,EAAEK,MAAc;IACnE,OAAO,GAAGN,cAAcC,QAAQ,CAAC,EAAEK,QAAQ;AAC7C;AAEA,OAAO,SAASC,WAAWC,IAAa;IACtC,IAAI,OAAOA,SAAS,YAAYA,SAAS,MAAM,OAAO;IACtD,IAAI,CAAE,CAAA,cAAcA,IAAG,KAAM,OAAOA,KAAKC,QAAQ,KAAK,YAAYD,KAAKC,QAAQ,KAAK,MAAM;QACxF,OAAO;IACT;IACA,MAAMA,WAAWD,KAAKC,QAAQ;IAC9B,IAAI,OAAOA,SAASC,GAAG,KAAK,UAAU,OAAO;IAC7C,IAAID,SAASE,MAAM,KAAK,OAAO,OAAO;QAAEA,QAAQ;QAAOD,KAAKD,SAASC,GAAG;IAAC;IACzE,IAAID,SAASE,MAAM,KAAK,UAAU,OAAOF,SAASG,SAAS,KAAK,UAAU,OAAO;IACjF,OAAO;QAAED,QAAQ;QAAQC,WAAWH,SAASG,SAAS;QAAEF,KAAKD,SAASC,GAAG;IAAC;AAC5E;AAEA,SAASG,aAAaC,KAAc;IAClC,IAAI,OAAOA,UAAU,YAAYA,UAAU,MAAM,OAAO;IACxD,MAAM,EAAEC,IAAI,EAAEC,IAAI,EAAEC,IAAI,EAAE,GAAGH;IAC7B,IAAI,OAAOG,SAAS,UAAU,OAAO;IACrC,IAAI,OAAOF,SAAS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,EAAE;IAC7B,KAAK,MAAMrC,UAAUG,KAAKJ,OAAO,CAAE;QACjC,IAAI,CAACe,QAAQhF,SAASkE,OAAOxB,IAAI,GAAG;QACpC,IAAI,aAAawB,QAAQ;YACvBqC,SAASlE,IAAI,CAAC6B,OAAOxB,IAAI;YACzB;QACF;QACA,IAAI,aAAawB,QAAQ;YACvBwB,SAAS,CAACxB,OAAOxB,IAAI,CAAC,GAAGwB,OAAOX,OAAO;YACvC,IAAIW,OAAOtB,QAAQ,KAAK9C,WAAW6F,SAAS,CAACzB,OAAOxB,IAAI,CAAC,GAAGwB,OAAOtB,QAAQ;YAC3E,IAAIsB,OAAO5C,IAAI,KAAKxB,WAAWmE,OAAO,CAACC,OAAOxB,IAAI,CAAC,GAAGwB,OAAO5C,IAAI;YACjE;QACF;QACAsE,cAAcvD,IAAI,CAAC6B,OAAOxB,IAAI;QAC9BiD,SAAS,CAACzB,OAAOxB,IAAI,CAAC,GAAGwB,OAAOpC,SAAS,CAACc,QAAQ;IACpD;IACA,OAAO;QACL9B,MAAM;QACNnB,aAAaA,YAAY0E;QACzBqB;QACAC;QACA1B;QACA2B,eAAeA,cAAcE,IAAI;QACjCS,UAAUA,SAAST,IAAI;QACvB,GAAGxD,SAAS+B,KAAKjC,WAAW,CAAC;IAC/B;AACF"}
|
package/dist/site.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AAiChC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAgKxE"}
|
package/dist/site.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { actionOutcome } from './actions.js';
|
|
2
2
|
import { UNTYPED_FOLDERS, mapDiscovery, parseSiteDiscovery, siteCapabilities, siteSlots, siteTracked } from './discovery.js';
|
|
3
3
|
import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf } from './model.js';
|
|
4
|
-
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, schemaOf, schemaPath } from './read.js';
|
|
4
|
+
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, schemaOf, schemaPath, viewOf } from './read.js';
|
|
5
5
|
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
6
6
|
import { houseNotifications } from './stream.js';
|
|
7
7
|
import { PRIVATE_LOCATOR, SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT } from './transport.js';
|
|
@@ -76,7 +76,7 @@ export function createSiteAdapter(transport) {
|
|
|
76
76
|
if ('kind' in found) return {
|
|
77
77
|
failure: settled(found)
|
|
78
78
|
};
|
|
79
|
-
const view = found
|
|
79
|
+
const view = viewOf(found, entry);
|
|
80
80
|
if (view === undefined) return {
|
|
81
81
|
failure: {
|
|
82
82
|
kind: 'room-not-readable',
|
|
@@ -93,10 +93,15 @@ export function createSiteAdapter(transport) {
|
|
|
93
93
|
kind: 'beyond-horizon'
|
|
94
94
|
};
|
|
95
95
|
const streamed = notifications.advance(entry, from);
|
|
96
|
-
if (streamed !== null) return streamed;
|
|
96
|
+
if (streamed !== null) return streamed.page;
|
|
97
97
|
const found = await enumeration(entry, from);
|
|
98
98
|
if ('kind' in found) return found;
|
|
99
|
-
|
|
99
|
+
const view = viewOf(found, entry);
|
|
100
|
+
if (view === undefined) return {
|
|
101
|
+
kind: 'room-not-readable',
|
|
102
|
+
locator: entry.locator
|
|
103
|
+
};
|
|
104
|
+
return refreshFrom(view, entry, fromRoomVersion);
|
|
100
105
|
}
|
|
101
106
|
async function acquire(entry, held) {
|
|
102
107
|
if ('failure' in held) return {
|
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 RetryableRefusal,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\n UNTYPED_FOLDERS,\n mapDiscovery,\n parseSiteDiscovery,\n siteCapabilities,\n siteSlots,\n siteTracked,\n type SiteTracked,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport {\n advancedScope,\n bootstrapOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\n schemaOf,\n schemaPath,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } 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 {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\ntype Refused = AdapterFailure | RetryableRefusal | { 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 return {\n name: tracked.handle,\n locator: tracked.locator,\n roomVersion: roomVersion(tracked),\n operations: { read: [''], sync: [''], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n untypedFolders: [...UNTYPED_FOLDERS],\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' || refused.kind === 'retryable-refusal'\n ? UNCERTAIN\n : 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 behind = doorRefusal(answer.body);\n if (behind?.code === 'replica_behind') return { kind: 'retryable-refusal', ...behind };\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return classified;\n return parseEnumeration(answer.body, 'site') ?? UNCERTAIN;\n }\n\n async function caughtUp(entry: SiteTracked): Promise<CaughtUp> {\n const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}`);\n const classified = classifyDoor(answer.status, answer.body, entry.locator);\n if (classified !== null) return { failure: settled(classified) };\n const scope = parseSiteBootstrap(answer.body);\n if (scope === null) return { failure: UNCERTAIN };\n if (roomVersion(scope) === roomVersion(entry)) return { scope };\n const found = await enumeration(entry, scope);\n if ('kind' in found) return { failure: settled(found) };\n const view = found.authorities.find((held) => held.authority === entry.authority);\n if (view === undefined)\n return { failure: { kind: 'room-not-readable', locator: entry.locator } };\n return { scope: advancedScope(scope, view) };\n }\n\n async function refreshed(entry: SiteTracked, fromRoomVersion: string): Promise<RefreshResult> {\n const from = logPosition(fromRoomVersion);\n if (from === null) return { kind: 'beyond-horizon' };\n const streamed = notifications.advance(entry, from);\n if (streamed !== null) return streamed;\n const found = await enumeration(entry, from);\n if ('kind' in found) return found;\n return refreshFrom(found, entry, fromRoomVersion);\n }\n\n async function acquire(entry: SiteTracked, held: CaughtUp): Promise<HeldModel> {\n if ('failure' in held) return { snapshot: failedModel(held.failure), identity: null };\n const model = await heldModel(\n schemaOf(held.scope, entry.schema),\n schemaPath(entry.handle, entry.schema),\n MODEL_ABSENT,\n );\n acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });\n return model;\n }\n\n return {\n async authorize() {\n return {};\n },\n\n async model(_authorization, request): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(): Promise<DiscoverResult> {\n const answer = await transport.read(SITE_DOOR_DISCOVER);\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseSiteDiscovery(answer.body);\n if (document === null) return UNCERTAIN;\n const entries = siteTracked(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const published = new Set(entries.map((entry) => entry.authority));\n for (const authority of [...acquired.keys()]) {\n if (!published.has(authority)) acquired.delete(authority);\n }\n const fresh = new Map<string, CaughtUp>();\n const current = new Map<string, HeldModel>();\n for (const entry of entries) {\n const kept = acquired.get(entry.authority);\n if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {\n current.set(entry.authority, kept.model);\n continue;\n }\n const held = await caughtUp(entry);\n fresh.set(entry.authority, held);\n current.set(entry.authority, await acquire(entry, held));\n }\n caught = fresh;\n const rooms = entries.map((entry) => {\n const shelved = models.retain(\n modelKey(entry.locator, 'collection'),\n current.get(entry.authority),\n );\n return siteRoom(entry, shelved?.identity ?? null);\n });\n models.keep(entries.map((entry) => entry.locator));\n return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };\n },\n\n async bootstrap(_authorization, request): Promise<BootstrapResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const held = caught.get(entry.authority) ?? (await caughtUp(entry));\n if ('failure' in held) return held.failure;\n return bootstrapOf(held.scope, entry);\n },\n\n async refresh(_authorization, request): Promise<RefreshResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const result = await refreshed(entry, request.fromRoomVersion);\n if (result.kind === 'beyond-horizon') caught.delete(entry.authority);\n const answered =\n result.kind === 'net-advancement'\n ? result.roomVersion\n : result.kind === 'still-current'\n ? request.fromRoomVersion\n : null;\n if (\n request.minPosition !== undefined &&\n answered !== null &&\n !reachedVersion(answered, request.minPosition, entry.logEpoch)\n ) {\n return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };\n }\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 reached(locator, version, target) {\n return reachedVersion(version, target, tracked.get(locator)?.logEpoch);\n },\n\n async action(_authorization, request) {\n if (request.name !== 'submit') {\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };\n }\n if (!transport.online()) return UNCERTAIN;\n return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');\n },\n\n roomVersions: notifications,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["actionOutcome","UNTYPED_FOLDERS","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","bootstrapOf","parseEnumeration","parseSiteBootstrap","refreshFrom","schemaOf","schemaPath","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","name","handle","locator","operations","read","sync","write","delete","replica","selection","admission","untypedFolders","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","behind","body","code","classified","status","caughtUp","failure","scope","found","view","authorities","find","held","undefined","refreshed","fromRoomVersion","streamed","advance","acquire","snapshot","identity","model","schema","set","authorize","_authorization","request","discover","document","entries","clear","track","published","Set","map","keys","has","fresh","current","kept","get","rooms","shelved","retain","keep","slots","bootstrap","pageToken","refresh","result","answered","minPosition","logEpoch","fields","mutate","affected","history","reached","version","target","action","online","input","roomVersions","serviceMode"],"mappings":"AAUA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACEC,eAAe,EACfC,YAAY,EACZC,kBAAkB,EAClBC,gBAAgB,EAChBC,SAAS,EACTC,WAAW,QAEN,iBAAiB;AACxB,SACEC,YAAY,EACZC,WAAW,EACXC,SAAS,EACTC,QAAQ,EACRC,UAAU,QAEL,aAAa;AACpB,SACEC,aAAa,EACbC,WAAW,EACXC,gBAAgB,EAChBC,kBAAkB,EAClBC,WAAW,EACXC,QAAQ,EACRC,UAAU,QAGL,YAAY;AACnB,SAASC,YAAY,EAAEC,gBAAgB,EAAEC,WAAW,QAAQ,eAAe;AAC3E,SAASC,kBAAkB,QAAQ,cAAc;AACjD,SACEC,eAAe,EACfC,mBAAmB,EACnBC,kBAAkB,EAClBC,mBAAmB,EACnBC,gBAAgB,QAEX,iBAAiB;AACxB,SACEC,WAAW,EACXC,SAAS,EACTC,cAAc,EACdC,WAAW,QAEN,eAAe;AAQtB,MAAMC,YAAY;IAAEC,MAAM;AAAwB;AAElD,SAASC,SACPC,OAAoB,EACpBC,aAA8C;IAE9C,OAAO;QACLC,MAAMF,QAAQG,MAAM;QACpBC,SAASJ,QAAQI,OAAO;QACxBR,aAAaA,YAAYI;QACzBK,YAAY;YAAEC,MAAM;gBAAC;aAAG;YAAEC,MAAM;gBAAC;aAAG;YAAEC,OAAO,EAAE;YAAEC,QAAQ,EAAE;QAAC;QAC5DC,SAAS;YAAEC,WAA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2D,QAAQX,eAAe,GACvB;YACR,IACEW,QAAQyB,WAAW,KAAKtC,aACxBqC,aAAa,QACb,CAACtF,eAAesF,UAAUxB,QAAQyB,WAAW,EAAEzD,MAAM0D,QAAQ,GAC7D;gBACA,OAAO;oBAAErF,MAAM;oBAAqBmC,MAAM;oBAAkBmD,QAAQ,CAAC;gBAAE;YACzE;YACA,OAAOJ;QACT;QAEA,MAAMK;YACJ,OAAO;gBAAEvF,MAAM;gBAAYwF,UAAU,CAAC;gBAAGrD,MAAM;gBAAemD,QAAQ,CAAC;YAAE;QAC3E;QAEA,MAAMG;YACJ,OAAO;gBAAEzF,MAAM;YAAa;QAC9B;QAEA0F,SAAQpF,OAAO,EAAEqF,OAAO,EAAEC,MAAM;YAC9B,OAAO/F,eAAe8F,SAASC,QAAQ1F,QAAQuE,GAAG,CAACnE,UAAU+E;QAC/D;QAEA,MAAMQ,QAAOnC,cAAc,EAAEC,OAAO;YAClC,IAAIA,QAAQvD,IAAI,KAAK,UAAU;gBAC7B,OAAO;oBAAEJ,MAAM;oBAAYmC,MAAM;oBAAwBmD,QAAQ;wBAAElF,MAAMuD,QAAQvD,IAAI;oBAAC;gBAAE;YAC1F;YACA,IAAI,CAACgB,UAAU0E,MAAM,IAAI,OAAO/F;YAChC,OAAOhC,cAAc,MAAMqD,UAAUU,IAAI,CAACpC,kBAAkBiE,QAAQoC,KAAK,GAAG;QAC9E;QAEAC,cAAc3E;QACd4E,aAAa5E,cAAc4E,WAAW;IACxC;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 RetryableRefusal,\n} from '@agentshouse/mdruntime';\nimport { actionOutcome } from './actions.js';\nimport {\n UNTYPED_FOLDERS,\n mapDiscovery,\n parseSiteDiscovery,\n siteCapabilities,\n siteSlots,\n siteTracked,\n type SiteTracked,\n} from './discovery.js';\nimport {\n MODEL_ABSENT,\n failedModel,\n heldModel,\n modelKey,\n modelShelf,\n type HeldModel,\n} from './model.js';\nimport {\n advancedScope,\n bootstrapOf,\n parseEnumeration,\n parseSiteBootstrap,\n refreshFrom,\n schemaOf,\n schemaPath,\n viewOf,\n type HouseEnumeration,\n type HouseScope,\n} from './read.js';\nimport { classifyDoor, discoveryFailure, doorRefusal } 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 {\n logPosition,\n presented,\n reachedVersion,\n roomVersion,\n type LogPosition,\n} from './version.js';\n\ntype Refused = AdapterFailure | RetryableRefusal | { 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 return {\n name: tracked.handle,\n locator: tracked.locator,\n roomVersion: roomVersion(tracked),\n operations: { read: [''], sync: [''], write: [], delete: [] },\n replica: { selection: tracked.locator, admission: 'admitted' },\n attachedModel,\n untypedFolders: [...UNTYPED_FOLDERS],\n providerOwnedPaths: [],\n };\n}\n\nfunction settled(refused: Refused): AdapterFailure {\n return refused.kind === 'beyond-horizon' || refused.kind === 'retryable-refusal'\n ? UNCERTAIN\n : 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 behind = doorRefusal(answer.body);\n if (behind?.code === 'replica_behind') return { kind: 'retryable-refusal', ...behind };\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 = viewOf(found, entry);\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.page;\n const found = await enumeration(entry, from);\n if ('kind' in found) return found;\n const view = viewOf(found, entry);\n if (view === undefined) return { kind: 'room-not-readable', locator: entry.locator };\n return refreshFrom(view, entry, fromRoomVersion);\n }\n\n async function acquire(entry: SiteTracked, held: CaughtUp): Promise<HeldModel> {\n if ('failure' in held) return { snapshot: failedModel(held.failure), identity: null };\n const model = await heldModel(\n schemaOf(held.scope, entry.schema),\n schemaPath(entry.handle, entry.schema),\n MODEL_ABSENT,\n );\n acquired.set(entry.authority, { roomVersion: roomVersion(held.scope), model });\n return model;\n }\n\n return {\n async authorize() {\n return {};\n },\n\n async model(_authorization, request): Promise<ModelResult> {\n return models.answer(request);\n },\n\n async discover(): Promise<DiscoverResult> {\n const answer = await transport.read(SITE_DOOR_DISCOVER);\n const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);\n if (classified !== null) return discoveryFailure(classified);\n const document = parseSiteDiscovery(answer.body);\n if (document === null) return UNCERTAIN;\n const entries = siteTracked(document);\n tracked.clear();\n for (const entry of entries) tracked.set(entry.locator, entry);\n notifications.track(entries);\n const published = new Set(entries.map((entry) => entry.authority));\n for (const authority of [...acquired.keys()]) {\n if (!published.has(authority)) acquired.delete(authority);\n }\n const fresh = new Map<string, CaughtUp>();\n const current = new Map<string, HeldModel>();\n for (const entry of entries) {\n const kept = acquired.get(entry.authority);\n if (kept !== undefined && kept.roomVersion === roomVersion(entry)) {\n current.set(entry.authority, kept.model);\n continue;\n }\n const held = await caughtUp(entry);\n fresh.set(entry.authority, held);\n current.set(entry.authority, await acquire(entry, held));\n }\n caught = fresh;\n const rooms = entries.map((entry) => {\n const shelved = models.retain(\n modelKey(entry.locator, 'collection'),\n current.get(entry.authority),\n );\n return siteRoom(entry, shelved?.identity ?? null);\n });\n models.keep(entries.map((entry) => entry.locator));\n return { ...mapDiscovery(document, rooms, siteCapabilities()), slots: siteSlots(document) };\n },\n\n async bootstrap(_authorization, request): Promise<BootstrapResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const held = caught.get(entry.authority) ?? (await caughtUp(entry));\n if ('failure' in held) return held.failure;\n return bootstrapOf(held.scope, entry);\n },\n\n async refresh(_authorization, request): Promise<RefreshResult> {\n const entry = tracked.get(request.locator);\n if (entry === undefined) return { kind: 'room-not-readable', locator: request.locator };\n if (request.pageToken !== undefined) return UNCERTAIN;\n const result = await refreshed(entry, request.fromRoomVersion);\n if (result.kind === 'beyond-horizon') caught.delete(entry.authority);\n const answered =\n result.kind === 'net-advancement'\n ? result.roomVersion\n : result.kind === 'still-current'\n ? request.fromRoomVersion\n : null;\n if (\n request.minPosition !== undefined &&\n answered !== null &&\n !reachedVersion(answered, request.minPosition, entry.logEpoch)\n ) {\n return { kind: 'retryable-refusal', code: 'replica_behind', fields: {} };\n }\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 reached(locator, version, target) {\n return reachedVersion(version, target, tracked.get(locator)?.logEpoch);\n },\n\n async action(_authorization, request) {\n if (request.name !== 'submit') {\n return { kind: 'rejected', code: 'action-unimplemented', fields: { name: request.name } };\n }\n if (!transport.online()) return UNCERTAIN;\n return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), 'submit');\n },\n\n roomVersions: notifications,\n serviceMode: notifications.serviceMode,\n };\n}\n"],"names":["actionOutcome","UNTYPED_FOLDERS","mapDiscovery","parseSiteDiscovery","siteCapabilities","siteSlots","siteTracked","MODEL_ABSENT","failedModel","heldModel","modelKey","modelShelf","advancedScope","bootstrapOf","parseEnumeration","parseSiteBootstrap","refreshFrom","schemaOf","schemaPath","viewOf","classifyDoor","discoveryFailure","doorRefusal","houseNotifications","PRIVATE_LOCATOR","SITE_DOOR_BOOTSTRAP","SITE_DOOR_DISCOVER","SITE_DOOR_ENUMERATE","SITE_DOOR_SUBMIT","logPosition","presented","reachedVersion","roomVersion","UNCERTAIN","kind","siteRoom","tracked","attachedModel","name","handle","locator","operations","read","sync","write","delete","replica","selection","admission","untypedFolders","providerOwnedPaths","settled","refused","createSiteAdapter","transport","notifications","Map","models","acquired","caught","enumeration","entry","from","answer","door","positions","authority","behind","body","code","classified","status","caughtUp","failure","scope","found","view","undefined","refreshed","fromRoomVersion","streamed","advance","page","acquire","held","snapshot","identity","model","schema","set","authorize","_authorization","request","discover","document","entries","clear","track","published","Set","map","keys","has","fresh","current","kept","get","rooms","shelved","retain","keep","slots","bootstrap","pageToken","refresh","result","answered","minPosition","logEpoch","fields","mutate","affected","history","reached","version","target","action","online","input","roomVersions","serviceMode"],"mappings":"AAUA,SAASA,aAAa,QAAQ,eAAe;AAC7C,SACE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U,CAAC;gBAAGpD,MAAM;gBAAekD,QAAQ,CAAC;YAAE;QAC3E;QAEA,MAAMG;YACJ,OAAO;gBAAExF,MAAM;YAAa;QAC9B;QAEAyF,SAAQnF,OAAO,EAAEoF,OAAO,EAAEC,MAAM;YAC9B,OAAO9F,eAAe6F,SAASC,QAAQzF,QAAQsE,GAAG,CAAClE,UAAU8E;QAC/D;QAEA,MAAMQ,QAAOnC,cAAc,EAAEC,OAAO;YAClC,IAAIA,QAAQtD,IAAI,KAAK,UAAU;gBAC7B,OAAO;oBAAEJ,MAAM;oBAAYmC,MAAM;oBAAwBkD,QAAQ;wBAAEjF,MAAMsD,QAAQtD,IAAI;oBAAC;gBAAE;YAC1F;YACA,IAAI,CAACgB,UAAUyE,MAAM,IAAI,OAAO9F;YAChC,OAAOjC,cAAc,MAAMsD,UAAUU,IAAI,CAACpC,kBAAkBgE,QAAQoC,KAAK,GAAG;QAC9E;QAEAC,cAAc1E;QACd2E,aAAa3E,cAAc2E,WAAW;IACxC;AACF"}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import type { ConversationStream, RefreshPage, SelectedRooms, ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
-
import type { HouseDoor, HouseMode } from './transport.js';
|
|
3
|
+
import type { HouseDoor, HouseMode, HouseStreamEntry } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
5
|
+
export type StreamedAdvancement = {
|
|
6
|
+
page: RefreshPage;
|
|
7
|
+
entries: readonly HouseStreamEntry[];
|
|
8
|
+
};
|
|
5
9
|
export type HouseNotifications = SelectedRooms & {
|
|
6
10
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
7
|
-
advance(tracked: TrackedAuthority, from: LogPosition):
|
|
11
|
+
advance(tracked: TrackedAuthority, from: LogPosition): StreamedAdvancement | null;
|
|
8
12
|
conversations: ConversationStream;
|
|
9
13
|
serviceMode: ServiceModeSignal;
|
|
10
14
|
};
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAEV,kBAAkB,EAClB,WAAW,EAEX,aAAa,EAEb,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,gBAAgB,EAAoB,MAAM,gBAAgB,CAAC;AAC/F,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAc7D,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACtC,CAAC;AAEF,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,mBAAmB,GAAG,IAAI,CAAC;IAClF,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAOF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CAsQ5F"}
|
package/dist/stream.js
CHANGED
|
@@ -296,16 +296,19 @@ export function houseNotifications(transport, mode) {
|
|
|
296
296
|
frames: pending
|
|
297
297
|
});
|
|
298
298
|
return {
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
299
|
+
page: {
|
|
300
|
+
kind: 'net-advancement',
|
|
301
|
+
roomVersion: roomVersion({
|
|
302
|
+
position: last.position.toString(),
|
|
303
|
+
logEpoch: line.logEpoch
|
|
304
|
+
}),
|
|
305
|
+
documents,
|
|
306
|
+
revisions,
|
|
307
|
+
changes,
|
|
308
|
+
binaryTargets: [],
|
|
309
|
+
removals: removals.sort()
|
|
310
|
+
},
|
|
311
|
+
entries: pending.flatMap((frame)=>frame.entries)
|
|
309
312
|
};
|
|
310
313
|
}
|
|
311
314
|
};
|
package/dist/stream.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n ConversationStream,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ServiceMode,\n ServiceModeSignal,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { headChange, selects, type HeadChange } from './read.js';\nimport type { HouseDoor, HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): RefreshPage | null;\n conversations: ConversationStream;\n serviceMode: ServiceModeSignal;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const schemas = new Map<string, readonly string[]>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const modeObservers = new Set<(mode: ServiceMode) => void>();\n let replicated: readonly string[] = [];\n const live = new Set<string>();\n const noted = new Set<string>();\n let listening = false;\n let catching = false;\n\n function listen() {\n if (listening) return;\n listening = true;\n stream.observe(receive);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (event.kind !== 'gap' && event.kind !== 'accepted-message') live.add(event.conversation);\n for (const observer of conversationObservers) observer(event);\n }\n\n function unnote(conversation: string) {\n if (!noted.delete(conversation)) return;\n emitConversation({ kind: 'working-note', conversation, note: null });\n }\n\n function reopened() {\n const gapped = new Set([...replicated, ...live]);\n live.clear();\n noted.clear();\n for (const conversation of gapped) emitConversation({ kind: 'gap', conversation });\n }\n\n function converse(frame: Exclude<HouseStreamFrame, { type: 'entries' | 'signal' }>) {\n const conversation = frame.conversation_id;\n if (frame.type === 'draft') {\n unnote(conversation);\n emitConversation({\n kind: 'growing-text',\n conversation,\n turn: frame.turn_id,\n text: frame.text,\n });\n emitConversation({\n kind: 'plan',\n conversation,\n turn: frame.turn_id,\n plan: structuredClone(frame.steps),\n });\n return;\n }\n if (frame.type === 'working-note') {\n noted.add(conversation);\n emitConversation({\n kind: 'working-note',\n conversation,\n note: { noteId: frame.note_id, text: frame.text },\n });\n return;\n }\n if (frame.type === 'process') {\n emitConversation({ kind: 'process', conversation, running: frame.running });\n if (frame.running) return;\n emitConversation({ kind: 'commands', conversation, commands: [] });\n emitConversation({ kind: 'options', conversation, options: [] });\n unnote(conversation);\n return;\n }\n if (frame.type === 'commands') {\n emitConversation({\n kind: 'commands',\n conversation,\n commands: structuredClone(frame.commands),\n });\n return;\n }\n if (frame.type === 'options') {\n emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });\n return;\n }\n if (frame.type === 'interactions') {\n emitConversation({\n kind: 'questions',\n conversation,\n questions: structuredClone(frame.interactions),\n });\n return;\n }\n const message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation, message });\n if ((frame.message as { role?: unknown }).role === 'user') return;\n unnote(conversation);\n }\n\n function announce(authority: string, at: LogPosition, modelChanged: boolean) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) {\n observer(\n modelChanged\n ? { locator, roomVersion: version, modelChanged: true }\n : { locator, roomVersion: version },\n );\n }\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'signal') {\n const mode = frame.service_mode;\n if (mode !== 'open' && mode !== 'write-halted') return;\n for (const observer of modeObservers) observer(mode);\n return;\n }\n if (\n frame.type === 'draft' ||\n frame.type === 'working-note' ||\n frame.type === 'process' ||\n frame.type === 'commands' ||\n frame.type === 'options' ||\n frame.type === 'interactions' ||\n frame.type === 'message'\n ) {\n converse(frame);\n return;\n }\n if (frame.type !== 'entries') return;\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n const addresses = schemas.get(frame.authority) ?? [];\n announce(\n frame.authority,\n { position: frame.position, logEpoch: frame.log_epoch },\n frame.entries.some((entry) => addresses.includes(entry.path)),\n );\n }\n\n return {\n serviceMode: {\n observe(notify) {\n modeObservers.add(notify);\n listen();\n return () => {\n modeObservers.delete(notify);\n };\n },\n },\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n observe(notify) {\n conversationObservers.add(notify);\n listen();\n if (!catching) {\n catching = true;\n stream.opened(reopened);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n schemas.clear();\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n schemas.set(entry.authority, entry.schemas);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select() {},\n observe(notify) {\n observers.add(notify);\n listen();\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n delete changes[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n const head = headChange(entry);\n if (head === null) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n if (head === undefined) delete changes[entry.path];\n else changes[entry.path] = head;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n kind: 'net-advancement',\n roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),\n documents,\n revisions,\n changes,\n binaryTargets: [],\n removals: removals.sort(),\n };\n },\n };\n}\n"],"names":["acceptedMessage","headChange","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","schemas","observers","Set","conversationObservers","modeObservers","replicated","live","noted","listening","catching","listen","observe","receive","emitConversation","event","kind","add","conversation","observer","unnote","delete","note","reopened","gapped","clear","converse","frame","conversation_id","type","turn","turn_id","text","plan","structuredClone","steps","noteId","note_id","running","commands","options","questions","interactions","message","role","announce","authority","at","modelChanged","version","locator","get","interrupt","line","undefined","set","logEpoch","frames","service_mode","log_epoch","last","continued","next","entries","length","addresses","some","entry","includes","path","serviceMode","notify","conversations","replicate","opened","track","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","changes","removals","push","revision","head","removed","indexOf","splice","toString","binaryTargets","sort"],"mappings":"AASA,SAASA,eAAe,QAAQ,eAAe;AAE/C,SAASC,UAAU,EAAEC,OAAO,QAAyB,YAAY;AAEjE,SAASC,WAAW,QAA0B,eAAe;AAE7D,MAAMC,qBAAqB;AAmB3B,SAASC,SAASC,KAAa;IAC7B,IAAI,CAAC,sBAAsBC,IAAI,CAACD,QAAQ,OAAO;IAC/C,OAAOE,OAAOF;AAChB;AAEA,OAAO,SAASG,mBAAmBC,SAAoB,EAAEC,IAAe;IACtE,MAAMC,SAASF,UAAUE,MAAM;IAC/B,MAAMC,QAAQ,IAAIC;IAClB,MAAMC,WAAW,IAAID;IACrB,MAAME,UAAU,IAAIF;IACpB,MAAMG,YAAY,IAAIC;IACtB,MAAMC,wBAAwB,IAAID;IAClC,MAAME,gBAAgB,IAAIF;IAC1B,IAAIG,aAAgC,EAAE;IACtC,MAAMC,OAAO,IAAIJ;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BAC5D;oBACF;oBACA,IAAIF,MAAMnC,IAAI,KAAKsB,WAAW,OAAO;oBACrC,IAAI1D,SAAS,gBAAgBuE,MAAMwB,QAAQ,KAAKrC,WAAW,OAAO;oBAClE,MAAMsC,OAAO1G,WAAWiF;oBACxB,IAAIyB,SAAS,MAAM,OAAO;oBAC1BN,SAAS,CAACnB,MAAME,IAAI,CAAC,GAAGF,MAAMnC,IAAI;oBAClC,IAAImC,MAAMwB,QAAQ,KAAKrC,WAAWiC,SAAS,CAACpB,MAAME,IAAI,CAAC,GAAGF,MAAMwB,QAAQ;oBACxE,IAAIC,SAAStC,WAAW,OAAOkC,OAAO,CAACrB,MAAME,IAAI,CAAC;yBAC7CmB,OAAO,CAACrB,MAAME,IAAI,CAAC,GAAGuB;oBAC3B,MAAMC,UAAUJ,SAASK,OAAO,CAAC3B,MAAME,IAAI;oBAC3C,IAAIwB,YAAY,CAAC,GAAGJ,SAASM,MAAM,CAACF,SAAS;gBAC/C;YACF;YACA,MAAMjC,OAAOwB,QAAQrC,EAAE,CAAC,CAAC;YACzB,IAAIa,SAASN,WAAW,OAAO;YAC/BxD,MAAMyD,GAAG,CAACyB,QAAQlC,SAAS,EAAE;gBAAEU,UAAUH,KAAKG,QAAQ;gBAAEC,QAAQ2B;YAAQ;YACxE,OAAO;gBACLpE,MAAM;gBACN5B,aAAaA,YAAY;oBAAEE,UAAUsE,KAAKtE,QAAQ,CAAC0G,QAAQ;oBAAIxC,UAAUH,KAAKG,QAAQ;gBAAC;gBACvF8B;gBACAC;gBACAC;gBACAS,eAAe,EAAE;gBACjBR,UAAUA,SAASS,IAAI;YACzB;QACF;IACF;AACF"}
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime-adapter/src/stream.ts"],"sourcesContent":["import type {\n ConversationEvent,\n ConversationStream,\n RefreshPage,\n RoomVersionNotification,\n SelectedRooms,\n ServiceMode,\n ServiceModeSignal,\n} from '@agentshouse/mdruntime';\nimport { acceptedMessage } from './actions.js';\nimport type { TrackedAuthority } from './discovery.js';\nimport { headChange, selects, type HeadChange } from './read.js';\nimport type { HouseDoor, HouseMode, HouseStreamEntry, HouseStreamFrame } from './transport.js';\nimport { roomVersion, type LogPosition } from './version.js';\n\nconst HELD_POSITIONS_MAX = 256;\n\ntype HeldFrame = {\n position: bigint;\n entries: readonly HouseStreamEntry[];\n};\n\ntype HeldLine = {\n logEpoch: string;\n frames: readonly HeldFrame[];\n};\n\nexport type StreamedAdvancement = {\n page: RefreshPage;\n entries: readonly HouseStreamEntry[];\n};\n\nexport type HouseNotifications = SelectedRooms & {\n track(authorities: readonly TrackedAuthority[]): void;\n advance(tracked: TrackedAuthority, from: LogPosition): StreamedAdvancement | null;\n conversations: ConversationStream;\n serviceMode: ServiceModeSignal;\n};\n\nfunction position(value: string): bigint | null {\n if (!/^(?:0|[1-9][0-9]*)$/.test(value)) return null;\n return BigInt(value);\n}\n\nexport function houseNotifications(transport: HouseDoor, mode: HouseMode): HouseNotifications {\n const stream = transport.stream;\n const lines = new Map<string, HeldLine>();\n const locators = new Map<string, string[]>();\n const schemas = new Map<string, readonly string[]>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const conversationObservers = new Set<(event: ConversationEvent) => void>();\n const modeObservers = new Set<(mode: ServiceMode) => void>();\n let replicated: readonly string[] = [];\n const live = new Set<string>();\n const noted = new Set<string>();\n let listening = false;\n let catching = false;\n\n function listen() {\n if (listening) return;\n listening = true;\n stream.observe(receive);\n }\n\n function emitConversation(event: ConversationEvent) {\n if (event.kind !== 'gap' && event.kind !== 'accepted-message') live.add(event.conversation);\n for (const observer of conversationObservers) observer(event);\n }\n\n function unnote(conversation: string) {\n if (!noted.delete(conversation)) return;\n emitConversation({ kind: 'working-note', conversation, note: null });\n }\n\n function reopened() {\n const gapped = new Set([...replicated, ...live]);\n live.clear();\n noted.clear();\n for (const conversation of gapped) emitConversation({ kind: 'gap', conversation });\n }\n\n function converse(frame: Exclude<HouseStreamFrame, { type: 'entries' | 'signal' }>) {\n const conversation = frame.conversation_id;\n if (frame.type === 'draft') {\n unnote(conversation);\n emitConversation({\n kind: 'growing-text',\n conversation,\n turn: frame.turn_id,\n text: frame.text,\n });\n emitConversation({\n kind: 'plan',\n conversation,\n turn: frame.turn_id,\n plan: structuredClone(frame.steps),\n });\n return;\n }\n if (frame.type === 'working-note') {\n noted.add(conversation);\n emitConversation({\n kind: 'working-note',\n conversation,\n note: { noteId: frame.note_id, text: frame.text },\n });\n return;\n }\n if (frame.type === 'process') {\n emitConversation({ kind: 'process', conversation, running: frame.running });\n if (frame.running) return;\n emitConversation({ kind: 'commands', conversation, commands: [] });\n emitConversation({ kind: 'options', conversation, options: [] });\n unnote(conversation);\n return;\n }\n if (frame.type === 'commands') {\n emitConversation({\n kind: 'commands',\n conversation,\n commands: structuredClone(frame.commands),\n });\n return;\n }\n if (frame.type === 'options') {\n emitConversation({ kind: 'options', conversation, options: structuredClone(frame.options) });\n return;\n }\n if (frame.type === 'interactions') {\n emitConversation({\n kind: 'questions',\n conversation,\n questions: structuredClone(frame.interactions),\n });\n return;\n }\n const message = acceptedMessage(frame.message);\n if (message === null) return;\n emitConversation({ kind: 'accepted-message', conversation, message });\n if ((frame.message as { role?: unknown }).role === 'user') return;\n unnote(conversation);\n }\n\n function announce(authority: string, at: LogPosition, modelChanged: boolean) {\n const version = roomVersion(at);\n for (const locator of locators.get(authority) ?? []) {\n for (const observer of observers) {\n observer(\n modelChanged\n ? { locator, roomVersion: version, modelChanged: true }\n : { locator, roomVersion: version },\n );\n }\n }\n }\n\n function interrupt(authority: string) {\n const line = lines.get(authority);\n if (line !== undefined) lines.set(authority, { logEpoch: line.logEpoch, frames: [] });\n }\n\n function receive(frame: HouseStreamFrame) {\n if (frame.type === 'signal') {\n const mode = frame.service_mode;\n if (mode !== 'open' && mode !== 'write-halted') return;\n for (const observer of modeObservers) observer(mode);\n return;\n }\n if (\n frame.type === 'draft' ||\n frame.type === 'working-note' ||\n frame.type === 'process' ||\n frame.type === 'commands' ||\n frame.type === 'options' ||\n frame.type === 'interactions' ||\n frame.type === 'message'\n ) {\n converse(frame);\n return;\n }\n if (frame.type !== 'entries') return;\n const at = position(frame.position);\n if (at === null) {\n interrupt(frame.authority);\n return;\n }\n const line = lines.get(frame.authority);\n if (line?.logEpoch === frame.log_epoch) {\n const last = line.frames.at(-1);\n const continued = last !== undefined && last.position + 1n === at;\n const next = continued\n ? [...line.frames, { position: at, entries: frame.entries }]\n : [{ position: at, entries: frame.entries }];\n lines.set(frame.authority, {\n logEpoch: line.logEpoch,\n frames: next.length > HELD_POSITIONS_MAX ? [] : next,\n });\n } else {\n interrupt(frame.authority);\n }\n const addresses = schemas.get(frame.authority) ?? [];\n announce(\n frame.authority,\n { position: frame.position, logEpoch: frame.log_epoch },\n frame.entries.some((entry) => addresses.includes(entry.path)),\n );\n }\n\n return {\n serviceMode: {\n observe(notify) {\n modeObservers.add(notify);\n listen();\n return () => {\n modeObservers.delete(notify);\n };\n },\n },\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n observe(notify) {\n conversationObservers.add(notify);\n listen();\n if (!catching) {\n catching = true;\n stream.opened(reopened);\n }\n return () => {\n conversationObservers.delete(notify);\n };\n },\n },\n track(entries) {\n locators.clear();\n schemas.clear();\n for (const entry of entries) {\n locators.set(entry.authority, [...(locators.get(entry.authority) ?? []), entry.locator]);\n schemas.set(entry.authority, entry.schemas);\n if (lines.get(entry.authority)?.logEpoch !== entry.logEpoch) {\n lines.set(entry.authority, { logEpoch: entry.logEpoch, frames: [] });\n }\n }\n for (const authority of lines.keys()) {\n if (!locators.has(authority)) lines.delete(authority);\n }\n },\n select() {},\n observe(notify) {\n observers.add(notify);\n listen();\n return () => {\n observers.delete(notify);\n };\n },\n advance(tracked, from) {\n const line = lines.get(tracked.authority);\n const start = position(from.position);\n if (line === undefined || start === null || line.logEpoch !== from.logEpoch) return null;\n const at = line.frames.findIndex((frame) => frame.position === start + 1n);\n if (at === -1) return null;\n const pending = line.frames.slice(at);\n const documents: Record<string, string> = {};\n const revisions: Record<string, string> = {};\n const changes: Record<string, HeadChange> = {};\n const removals: string[] = [];\n for (const frame of pending) {\n for (const entry of frame.entries) {\n if (!selects(tracked, entry.path)) continue;\n if (entry.kind === 'removed') {\n delete documents[entry.path];\n delete revisions[entry.path];\n delete changes[entry.path];\n if (!removals.includes(entry.path)) removals.push(entry.path);\n continue;\n }\n if (entry.text === undefined) return null;\n if (mode === 'credential' && entry.revision === undefined) return null;\n const head = headChange(entry);\n if (head === null) return null;\n documents[entry.path] = entry.text;\n if (entry.revision !== undefined) revisions[entry.path] = entry.revision;\n if (head === undefined) delete changes[entry.path];\n else changes[entry.path] = head;\n const removed = removals.indexOf(entry.path);\n if (removed !== -1) removals.splice(removed, 1);\n }\n }\n const last = pending.at(-1);\n if (last === undefined) return null;\n lines.set(tracked.authority, { logEpoch: line.logEpoch, frames: pending });\n return {\n page: {\n kind: 'net-advancement',\n roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),\n documents,\n revisions,\n changes,\n binaryTargets: [],\n removals: removals.sort(),\n },\n entries: pending.flatMap((frame) => frame.entries),\n };\n },\n };\n}\n"],"names":["acceptedMessage","headChange","selects","roomVersion","HELD_POSITIONS_MAX","position","value","test","BigInt","houseNotifications","transport","mode","stream","lines","Map","locators","schemas","observers","Set","conversationObservers","modeObservers","replicated","live","noted","listening","catching","listen","observe","receive","emitConversation","event","kind","add","conversation","observer","unnote","delete","note","reopened","gapped","clear","converse","frame","conversation_id","type","turn","turn_id","text","plan","structuredClone","steps","noteId","note_id","running","commands","options","questions","interactions","message","role","announce","authority","at","modelChanged","version","locator","get","interrupt","line","undefined","set","logEpoch","frames","service_mode","log_epoch","last","continued","next","entries","length","addresses","some","entry","includes","path","serviceMode","notify","conversations","replicate","opened","track","keys","has","select","advance","tracked","from","start","findIndex","pending","slice","documents","revisions","changes","removals","push","revision","head","removed","indexOf","splice","page","toString","binaryTargets","sort","flatMap"],"mappings":"AASA,SAASA,eAAe,QAAQ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B,QAAQlC,SAAS,EAAE;gBAAEU,UAAUH,KAAKG,QAAQ;gBAAEC,QAAQ2B;YAAQ;YACxE,OAAO;gBACLY,MAAM;oBACJhF,MAAM;oBACN5B,aAAaA,YAAY;wBAAEE,UAAUsE,KAAKtE,QAAQ,CAAC2G,QAAQ;wBAAIzC,UAAUH,KAAKG,QAAQ;oBAAC;oBACvF8B;oBACAC;oBACAC;oBACAU,eAAe,EAAE;oBACjBT,UAAUA,SAASU,IAAI;gBACzB;gBACApC,SAASqB,QAAQgB,OAAO,CAAC,CAACzE,QAAUA,MAAMoC,OAAO;YACnD;QACF;IACF;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.48",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -26,6 +26,6 @@
|
|
|
26
26
|
],
|
|
27
27
|
"dependencies": {
|
|
28
28
|
"@agentshouse/mdmodel": "0.1.0-alpha.19",
|
|
29
|
-
"@agentshouse/mdruntime": "0.1.0-alpha.
|
|
29
|
+
"@agentshouse/mdruntime": "0.1.0-alpha.49"
|
|
30
30
|
}
|
|
31
31
|
}
|