@agentshouse/mdruntime 0.1.0-alpha.1 → 0.1.0-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/adapter.d.ts CHANGED
@@ -58,11 +58,14 @@ export type BootstrapRequest = {
58
58
  locator: string;
59
59
  pageToken?: PageToken;
60
60
  };
61
- export type BootstrapResult = {
61
+ export type BootstrapPage = {
62
62
  kind: 'bootstrap';
63
63
  roomVersion: string;
64
+ documents: Readonly<Record<string, string>>;
65
+ binaryTargets: readonly string[];
64
66
  pageToken?: PageToken;
65
- } | AdapterFailure;
67
+ };
68
+ export type BootstrapResult = BootstrapPage | AdapterFailure;
66
69
  export type RefreshRequest = {
67
70
  locator: string;
68
71
  fromRoomVersion: string;
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC;AAEnC,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,sBAAsB,YACjC,iBAAiB,EACjB,wBAAwB,EACxB,4BAA4B,EAC5B,cAAc,EACd,kBAAkB,CACV,CAAC;AAEX,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAClC,OAAO,CAAC,EAAE,SAAS,iBAAiB,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,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,MAAM,EAAE,OAAO,CAAA;CAAE,GACnC;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAClC,cAAc,CAAC;AAEnB,MAAM,MAAM,OAAO,GAAG;IACpB,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;IACpC,QAAQ,CAAC,aAAa,EAAE,aAAa,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IAChE,SAAS,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,gBAAgB,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAC7F,OAAO,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACvF,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;IACxF,OAAO,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;IACvF,MAAM,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CACrF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/adapter.ts"],"sourcesContent":["export type Authorization = object;\n\nexport const ROOM_CONTRACT_VERSION = 1;\n\nexport const VERSION_1_CAPABILITIES = [\n 'stable-file-ids',\n 'ranked-provider-search',\n 'room-version-notifications',\n 'room-history',\n 'provider-actions',\n] as const;\n\nexport type MdModelIdentity = {\n identity: string;\n version: string;\n};\n\nexport type DiscoveredRoom = {\n name: string;\n locator: string;\n roomVersion: string;\n writeGrants: readonly string[];\n providerOwnedPaths: readonly string[];\n};\n\nexport type Capability = {\n name: string;\n limits?: readonly ProviderLimit[];\n actions?: readonly ActionDeclaration[];\n};\n\nexport type ActionDeclaration = {\n name: string;\n inputShape: unknown;\n resultKind: unknown;\n};\n\nexport type ProviderLimit = {\n name: string;\n value?: number | string;\n};\n\nexport type Retention = {\n history: number;\n outcome: number;\n refreshHorizon: number;\n};\n\nexport type Discovery = {\n kind: 'discovery';\n supportedVersions: readonly number[];\n mdModel: MdModelIdentity;\n rooms: readonly DiscoveredRoom[];\n capabilities: readonly Capability[];\n providerLimits: readonly ProviderLimit[];\n retention: Retention;\n origins: readonly string[];\n};\n\nexport type TransportUncertainty = { kind: 'transport-uncertainty' };\nexport type RoomNotReadable = { kind: 'room-not-readable'; locator: string };\nexport type RevokedAuthorization = { kind: 'revoked-authorization' };\n\nexport type AdapterFailure = TransportUncertainty | RoomNotReadable | RevokedAuthorization;\n\nexport type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization;\n\nexport type PageToken = string;\n\nexport type BootstrapRequest = {\n locator: string;\n pageToken?: PageToken;\n};\n\nexport type BootstrapResult =\n | { kind: 'bootstrap'; roomVersion: string; pageToken?: PageToken }\n | AdapterFailure;\n\nexport type RefreshRequest = {\n locator: string;\n fromRoomVersion: string;\n pageToken?: PageToken;\n};\n\nexport type RefreshResult =\n | { kind: 'still-current' }\n | { kind: 'net-advancement'; roomVersion: string; pageToken?: PageToken }\n | { kind: 'beyond-horizon' }\n | AdapterFailure;\n\nexport type MutationRequest = {\n locator: string;\n changeBatch: {\n id: string;\n baseRoomVersion: string;\n changes: readonly unknown[];\n preconditions: readonly unknown[];\n };\n};\n\nexport type MutationResult =\n | { kind: 'accepted'; roomVersion: string }\n | { kind: 'conflicted'; roomVersion: string; text: string }\n | { kind: 'rejected'; text: string }\n | AdapterFailure;\n\nexport type HistoryRequest = {\n locator: string;\n path: string;\n pageToken?: PageToken;\n};\n\nexport type HistoryResult =\n | {\n kind: 'history';\n revisions: readonly { author: string; time: string }[];\n pageToken?: PageToken;\n }\n | AdapterFailure;\n\nexport type ActionRequest = {\n name: string;\n input: unknown;\n};\n\nexport type ActionResult =\n | { kind: 'action'; result: unknown }\n | { kind: 'rejected'; text: string }\n | AdapterFailure;\n\nexport type Adapter = {\n authorize(): Promise<Authorization>;\n discover(authorization: Authorization): Promise<DiscoverResult>;\n bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;\n refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;\n mutate(authorization: Authorization, request: MutationRequest): Promise<MutationResult>;\n history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;\n action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;\n};\n"],"names":["ROOM_CONTRACT_VERSION","VERSION_1_CAPABILITIES"],"mappings":"AAEA,OAAO,MAAMA,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,yBAAyB;IACpC;IACA;IACA;IACA;IACA;CACD,CAAU"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/adapter.ts"],"sourcesContent":["export type Authorization = object;\n\nexport const ROOM_CONTRACT_VERSION = 1;\n\nexport const VERSION_1_CAPABILITIES = [\n 'stable-file-ids',\n 'ranked-provider-search',\n 'room-version-notifications',\n 'room-history',\n 'provider-actions',\n] as const;\n\nexport type MdModelIdentity = {\n identity: string;\n version: string;\n};\n\nexport type DiscoveredRoom = {\n name: string;\n locator: string;\n roomVersion: string;\n writeGrants: readonly string[];\n providerOwnedPaths: readonly string[];\n};\n\nexport type Capability = {\n name: string;\n limits?: readonly ProviderLimit[];\n actions?: readonly ActionDeclaration[];\n};\n\nexport type ActionDeclaration = {\n name: string;\n inputShape: unknown;\n resultKind: unknown;\n};\n\nexport type ProviderLimit = {\n name: string;\n value?: number | string;\n};\n\nexport type Retention = {\n history: number;\n outcome: number;\n refreshHorizon: number;\n};\n\nexport type Discovery = {\n kind: 'discovery';\n supportedVersions: readonly number[];\n mdModel: MdModelIdentity;\n rooms: readonly DiscoveredRoom[];\n capabilities: readonly Capability[];\n providerLimits: readonly ProviderLimit[];\n retention: Retention;\n origins: readonly string[];\n};\n\nexport type TransportUncertainty = { kind: 'transport-uncertainty' };\nexport type RoomNotReadable = { kind: 'room-not-readable'; locator: string };\nexport type RevokedAuthorization = { kind: 'revoked-authorization' };\n\nexport type AdapterFailure = TransportUncertainty | RoomNotReadable | RevokedAuthorization;\n\nexport type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization;\n\nexport type PageToken = string;\n\nexport type BootstrapRequest = {\n locator: string;\n pageToken?: PageToken;\n};\n\nexport type BootstrapPage = {\n kind: 'bootstrap';\n roomVersion: string;\n documents: Readonly<Record<string, string>>;\n binaryTargets: readonly string[];\n pageToken?: PageToken;\n};\n\nexport type BootstrapResult = BootstrapPage | AdapterFailure;\n\nexport type RefreshRequest = {\n locator: string;\n fromRoomVersion: string;\n pageToken?: PageToken;\n};\n\nexport type RefreshResult =\n | { kind: 'still-current' }\n | { kind: 'net-advancement'; roomVersion: string; pageToken?: PageToken }\n | { kind: 'beyond-horizon' }\n | AdapterFailure;\n\nexport type MutationRequest = {\n locator: string;\n changeBatch: {\n id: string;\n baseRoomVersion: string;\n changes: readonly unknown[];\n preconditions: readonly unknown[];\n };\n};\n\nexport type MutationResult =\n | { kind: 'accepted'; roomVersion: string }\n | { kind: 'conflicted'; roomVersion: string; text: string }\n | { kind: 'rejected'; text: string }\n | AdapterFailure;\n\nexport type HistoryRequest = {\n locator: string;\n path: string;\n pageToken?: PageToken;\n};\n\nexport type HistoryResult =\n | {\n kind: 'history';\n revisions: readonly { author: string; time: string }[];\n pageToken?: PageToken;\n }\n | AdapterFailure;\n\nexport type ActionRequest = {\n name: string;\n input: unknown;\n};\n\nexport type ActionResult =\n | { kind: 'action'; result: unknown }\n | { kind: 'rejected'; text: string }\n | AdapterFailure;\n\nexport type Adapter = {\n authorize(): Promise<Authorization>;\n discover(authorization: Authorization): Promise<DiscoverResult>;\n bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;\n refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;\n mutate(authorization: Authorization, request: MutationRequest): Promise<MutationResult>;\n history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;\n action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;\n};\n"],"names":["ROOM_CONTRACT_VERSION","VERSION_1_CAPABILITIES"],"mappings":"AAEA,OAAO,MAAMA,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,yBAAyB;IACpC;IACA;IACA;IACA;IACA;CACD,CAAU"}
@@ -0,0 +1,16 @@
1
+ import type { Adapter, Authorization, DiscoveredRoom, RevokedAuthorization, RoomNotReadable } from './adapter.js';
2
+ import { type Collection } from './collection.js';
3
+ import type { ReplicaRecord } from './store.js';
4
+ export type StagedReplica = {
5
+ record: ReplicaRecord;
6
+ collection: Collection;
7
+ };
8
+ export type BootstrapOutcome = {
9
+ kind: 'staged';
10
+ replica: StagedReplica;
11
+ } | {
12
+ kind: 'unconfirmed';
13
+ } | RoomNotReadable | RevokedAuthorization;
14
+ export declare function adoptReplica(record: ReplicaRecord): StagedReplica | null;
15
+ export declare function bootstrapRoom(adapter: Adapter, authorization: Authorization, room: DiscoveredRoom): Promise<BootstrapOutcome>;
16
+ //# sourceMappingURL=bootstrap.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAEP,aAAa,EACb,cAAc,EACd,oBAAoB,EACpB,eAAe,EAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAkB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,MAAM,MAAM,aAAa,GAAG;IAC1B,MAAM,EAAE,aAAa,CAAC;IACtB,UAAU,EAAE,UAAU,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,gBAAgB,GACxB;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,OAAO,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,aAAa,CAAA;CAAE,GACvB,eAAe,GACf,oBAAoB,CAAC;AAQzB,wBAAgB,YAAY,CAAC,MAAM,EAAE,aAAa,GAAG,aAAa,GAAG,IAAI,CAGxE;AAED,wBAAsB,aAAa,CACjC,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,IAAI,EAAE,cAAc,GACnB,OAAO,CAAC,gBAAgB,CAAC,CAyB3B"}
@@ -0,0 +1,54 @@
1
+ import { readCollection } from './collection.js';
2
+ const unconfirmed = {
3
+ kind: 'unconfirmed'
4
+ };
5
+ function received(failure) {
6
+ return failure.kind === 'transport-uncertainty' ? unconfirmed : failure;
7
+ }
8
+ export function adoptReplica(record) {
9
+ const collection = readCollection(record.documents, record.binaryTargets);
10
+ return collection === null ? null : {
11
+ record,
12
+ collection
13
+ };
14
+ }
15
+ export async function bootstrapRoom(adapter, authorization, room) {
16
+ const first = await adapter.bootstrap(authorization, {
17
+ locator: room.locator
18
+ });
19
+ if (first.kind !== 'bootstrap') return received(first);
20
+ const roomVersion = first.roomVersion;
21
+ const documents = {
22
+ ...first.documents
23
+ };
24
+ const binaryTargets = new Set(first.binaryTargets);
25
+ let pageToken = first.pageToken;
26
+ while(pageToken !== undefined){
27
+ const page = await adapter.bootstrap(authorization, {
28
+ locator: room.locator,
29
+ pageToken
30
+ });
31
+ if (page.kind !== 'bootstrap') return received(page);
32
+ if (page.roomVersion !== roomVersion) return unconfirmed;
33
+ Object.assign(documents, page.documents);
34
+ for (const target of page.binaryTargets)binaryTargets.add(target);
35
+ pageToken = page.pageToken;
36
+ }
37
+ const replica = adoptReplica({
38
+ locator: room.locator,
39
+ name: room.name,
40
+ writeGrants: room.writeGrants,
41
+ providerOwnedPaths: room.providerOwnedPaths,
42
+ roomVersion,
43
+ documents,
44
+ binaryTargets: [
45
+ ...binaryTargets
46
+ ].sort()
47
+ });
48
+ return replica === null ? unconfirmed : {
49
+ kind: 'staged',
50
+ replica
51
+ };
52
+ }
53
+
54
+ //# sourceMappingURL=bootstrap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/bootstrap.ts"],"sourcesContent":["import type {\n Adapter,\n AdapterFailure,\n Authorization,\n DiscoveredRoom,\n RevokedAuthorization,\n RoomNotReadable,\n} from './adapter.js';\nimport { readCollection, type Collection } from './collection.js';\nimport type { ReplicaRecord } from './store.js';\n\nexport type StagedReplica = {\n record: ReplicaRecord;\n collection: Collection;\n};\n\nexport type BootstrapOutcome =\n | { kind: 'staged'; replica: StagedReplica }\n | { kind: 'unconfirmed' }\n | RoomNotReadable\n | RevokedAuthorization;\n\nconst unconfirmed = { kind: 'unconfirmed' } as const;\n\nfunction received(failure: AdapterFailure): BootstrapOutcome {\n return failure.kind === 'transport-uncertainty' ? unconfirmed : failure;\n}\n\nexport function adoptReplica(record: ReplicaRecord): StagedReplica | null {\n const collection = readCollection(record.documents, record.binaryTargets);\n return collection === null ? null : { record, collection };\n}\n\nexport async function bootstrapRoom(\n adapter: Adapter,\n authorization: Authorization,\n room: DiscoveredRoom,\n): Promise<BootstrapOutcome> {\n const first = await adapter.bootstrap(authorization, { locator: room.locator });\n if (first.kind !== 'bootstrap') return received(first);\n const roomVersion = first.roomVersion;\n const documents: Record<string, string> = { ...first.documents };\n const binaryTargets = new Set(first.binaryTargets);\n let pageToken = first.pageToken;\n while (pageToken !== undefined) {\n const page = await adapter.bootstrap(authorization, { locator: room.locator, pageToken });\n if (page.kind !== 'bootstrap') return received(page);\n if (page.roomVersion !== roomVersion) return unconfirmed;\n Object.assign(documents, page.documents);\n for (const target of page.binaryTargets) binaryTargets.add(target);\n pageToken = page.pageToken;\n }\n const replica = adoptReplica({\n locator: room.locator,\n name: room.name,\n writeGrants: room.writeGrants,\n providerOwnedPaths: room.providerOwnedPaths,\n roomVersion,\n documents,\n binaryTargets: [...binaryTargets].sort(),\n });\n return replica === null ? unconfirmed : { kind: 'staged', replica };\n}\n"],"names":["readCollection","unconfirmed","kind","received","failure","adoptReplica","record","collection","documents","binaryTargets","bootstrapRoom","adapter","authorization","room","first","bootstrap","locator","roomVersion","Set","pageToken","undefined","page","Object","assign","target","add","replica","name","writeGrants","providerOwnedPaths","sort"],"mappings":"AAQA,SAASA,cAAc,QAAyB,kBAAkB;AAclE,MAAMC,cAAc;IAAEC,MAAM;AAAc;AAE1C,SAASC,SAASC,OAAuB;IACvC,OAAOA,QAAQF,IAAI,KAAK,0BAA0BD,cAAcG;AAClE;AAEA,OAAO,SAASC,aAAaC,MAAqB;IAChD,MAAMC,aAAaP,eAAeM,OAAOE,SAAS,EAAEF,OAAOG,aAAa;IACxE,OAAOF,eAAe,OAAO,OAAO;QAAED;QAAQC;IAAW;AAC3D;AAEA,OAAO,eAAeG,cACpBC,OAAgB,EAChBC,aAA4B,EAC5BC,IAAoB;IAEpB,MAAMC,QAAQ,MAAMH,QAAQI,SAAS,CAACH,eAAe;QAAEI,SAASH,KAAKG,OAAO;IAAC;IAC7E,IAAIF,MAAMZ,IAAI,KAAK,aAAa,OAAOC,SAASW;IAChD,MAAMG,cAAcH,MAAMG,WAAW;IACrC,MAAMT,YAAoC;QAAE,GAAGM,MAAMN,SAAS;IAAC;IAC/D,MAAMC,gBAAgB,IAAIS,IAAIJ,MAAML,aAAa;IACjD,IAAIU,YAAYL,MAAMK,SAAS;IAC/B,MAAOA,cAAcC,UAAW;QAC9B,MAAMC,OAAO,MAAMV,QAAQI,SAAS,CAACH,eAAe;YAAEI,SAASH,KAAKG,OAAO;YAAEG;QAAU;QACvF,IAAIE,KAAKnB,IAAI,KAAK,aAAa,OAAOC,SAASkB;QAC/C,IAAIA,KAAKJ,WAAW,KAAKA,aAAa,OAAOhB;QAC7CqB,OAAOC,MAAM,CAACf,WAAWa,KAAKb,SAAS;QACvC,KAAK,MAAMgB,UAAUH,KAAKZ,aAAa,CAAEA,cAAcgB,GAAG,CAACD;QAC3DL,YAAYE,KAAKF,SAAS;IAC5B;IACA,MAAMO,UAAUrB,aAAa;QAC3BW,SAASH,KAAKG,OAAO;QACrBW,MAAMd,KAAKc,IAAI;QACfC,aAAaf,KAAKe,WAAW;QAC7BC,oBAAoBhB,KAAKgB,kBAAkB;QAC3CZ;QACAT;QACAC,eAAe;eAAIA;SAAc,CAACqB,IAAI;IACxC;IACA,OAAOJ,YAAY,OAAOzB,cAAc;QAAEC,MAAM;QAAUwB;IAAQ;AACpE"}
@@ -0,0 +1,17 @@
1
+ import { type Document } from '@agentshouse/mdmodel';
2
+ import type { Selector } from '@agentshouse/query';
3
+ import type { MdModelIdentity } from './adapter.js';
4
+ export declare const MD_MODEL: MdModelIdentity;
5
+ export declare const PRESENTED: Selector;
6
+ export type MdType = {
7
+ name: string;
8
+ path: string;
9
+ fields: Readonly<Record<string, unknown>>;
10
+ sections: Readonly<Record<string, unknown>>;
11
+ };
12
+ export type Collection = {
13
+ documents: Readonly<Record<string, Document>>;
14
+ types: readonly MdType[];
15
+ };
16
+ export declare function readCollection(text: Readonly<Record<string, string>>, binaryTargets: readonly string[]): Collection | null;
17
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../src/collection.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4B,KAAK,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAC/E,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAKpD,eAAO,MAAM,QAAQ,EAAE,eAAwE,CAAC;AAEhG,eAAO,MAAM,SAAS,EAAE,QAAyC,CAAC;AAElE,MAAM,MAAM,MAAM,GAAG;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC;AAmBF,wBAAgB,cAAc,CAC5B,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EACtC,aAAa,EAAE,SAAS,MAAM,EAAE,GAC/B,UAAU,GAAG,IAAI,CAcnB"}
@@ -0,0 +1,48 @@
1
+ import { parse, validate, VERSION } from '@agentshouse/mdmodel';
2
+ const MARKDOWN = '.md';
3
+ const DEFINITION = 'definition';
4
+ export const MD_MODEL = {
5
+ identity: '@agentshouse/mdmodel',
6
+ version: VERSION
7
+ };
8
+ export const PRESENTED = {
9
+ path: {
10
+ $regex: '\\.md$'
11
+ }
12
+ };
13
+ function isMarkdown(path) {
14
+ return path.endsWith(MARKDOWN);
15
+ }
16
+ function declaredIn(document, part) {
17
+ return document.fields[part] ?? {};
18
+ }
19
+ function mdType(path, document) {
20
+ return {
21
+ name: path.slice(path.lastIndexOf('/') + 1, -MARKDOWN.length),
22
+ path,
23
+ fields: declaredIn(document, 'fields'),
24
+ sections: declaredIn(document, 'sections')
25
+ };
26
+ }
27
+ export function readCollection(text, binaryTargets) {
28
+ const documents = {};
29
+ for (const path of Object.keys(text).sort()){
30
+ const parsed = parse(text[path], path);
31
+ if (!parsed.ok) return null;
32
+ documents[path] = parsed.document;
33
+ }
34
+ if (validate(text, {
35
+ binaryTargets
36
+ }).verdict === 'refuse') return null;
37
+ const types = [];
38
+ for (const [path, document] of Object.entries(documents)){
39
+ if (!isMarkdown(path) || document.type !== DEFINITION) continue;
40
+ types.push(mdType(path, document));
41
+ }
42
+ return {
43
+ documents,
44
+ types
45
+ };
46
+ }
47
+
48
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/collection.ts"],"sourcesContent":["import { parse, validate, VERSION, type Document } from '@agentshouse/mdmodel';\nimport type { Selector } from '@agentshouse/query';\nimport type { MdModelIdentity } from './adapter.js';\n\nconst MARKDOWN = '.md';\nconst DEFINITION = 'definition';\n\nexport const MD_MODEL: MdModelIdentity = { identity: '@agentshouse/mdmodel', version: VERSION };\n\nexport const PRESENTED: Selector = { path: { $regex: '\\\\.md$' } };\n\nexport type MdType = {\n name: string;\n path: string;\n fields: Readonly<Record<string, unknown>>;\n sections: Readonly<Record<string, unknown>>;\n};\n\nexport type Collection = {\n documents: Readonly<Record<string, Document>>;\n types: readonly MdType[];\n};\n\nfunction isMarkdown(path: string) {\n return path.endsWith(MARKDOWN);\n}\n\nfunction declaredIn(document: Document, part: 'fields' | 'sections') {\n return (document.fields[part] ?? {}) as Readonly<Record<string, unknown>>;\n}\n\nfunction mdType(path: string, document: Document): MdType {\n return {\n name: path.slice(path.lastIndexOf('/') + 1, -MARKDOWN.length),\n path,\n fields: declaredIn(document, 'fields'),\n sections: declaredIn(document, 'sections'),\n };\n}\n\nexport function readCollection(\n text: Readonly<Record<string, string>>,\n binaryTargets: readonly string[],\n): Collection | null {\n const documents: Record<string, Document> = {};\n for (const path of Object.keys(text).sort()) {\n const parsed = parse(text[path], path);\n if (!parsed.ok) return null;\n documents[path] = parsed.document;\n }\n if (validate(text, { binaryTargets }).verdict === 'refuse') return null;\n const types: MdType[] = [];\n for (const [path, document] of Object.entries(documents)) {\n if (!isMarkdown(path) || document.type !== DEFINITION) continue;\n types.push(mdType(path, document));\n }\n return { documents, types };\n}\n"],"names":["parse","validate","VERSION","MARKDOWN","DEFINITION","MD_MODEL","identity","version","PRESENTED","path","$regex","isMarkdown","endsWith","declaredIn","document","part","fields","mdType","name","slice","lastIndexOf","length","sections","readCollection","text","binaryTargets","documents","Object","keys","sort","parsed","ok","verdict","types","entries","type","push"],"mappings":"AAAA,SAASA,KAAK,EAAEC,QAAQ,EAAEC,OAAO,QAAuB,uBAAuB;AAI/E,MAAMC,WAAW;AACjB,MAAMC,aAAa;AAEnB,OAAO,MAAMC,WAA4B;IAAEC,UAAU;IAAwBC,SAASL;AAAQ,EAAE;AAEhG,OAAO,MAAMM,YAAsB;IAAEC,MAAM;QAAEC,QAAQ;IAAS;AAAE,EAAE;AAclE,SAASC,WAAWF,IAAY;IAC9B,OAAOA,KAAKG,QAAQ,CAACT;AACvB;AAEA,SAASU,WAAWC,QAAkB,EAAEC,IAA2B;IACjE,OAAQD,SAASE,MAAM,CAACD,KAAK,IAAI,CAAC;AACpC;AAEA,SAASE,OAAOR,IAAY,EAAEK,QAAkB;IAC9C,OAAO;QACLI,MAAMT,KAAKU,KAAK,CAACV,KAAKW,WAAW,CAAC,OAAO,GAAG,CAACjB,SAASkB,MAAM;QAC5DZ;QACAO,QAAQH,WAAWC,UAAU;QAC7BQ,UAAUT,WAAWC,UAAU;IACjC;AACF;AAEA,OAAO,SAASS,eACdC,IAAsC,EACtCC,aAAgC;IAEhC,MAAMC,YAAsC,CAAC;IAC7C,KAAK,MAAMjB,QAAQkB,OAAOC,IAAI,CAACJ,MAAMK,IAAI,GAAI;QAC3C,MAAMC,SAAS9B,MAAMwB,IAAI,CAACf,KAAK,EAAEA;QACjC,IAAI,CAACqB,OAAOC,EAAE,EAAE,OAAO;QACvBL,SAAS,CAACjB,KAAK,GAAGqB,OAAOhB,QAAQ;IACnC;IACA,IAAIb,SAASuB,MAAM;QAAEC;IAAc,GAAGO,OAAO,KAAK,UAAU,OAAO;IACnE,MAAMC,QAAkB,EAAE;IAC1B,KAAK,MAAM,CAACxB,MAAMK,SAAS,IAAIa,OAAOO,OAAO,CAACR,WAAY;QACxD,IAAI,CAACf,WAAWF,SAASK,SAASqB,IAAI,KAAK/B,YAAY;QACvD6B,MAAMG,IAAI,CAACnB,OAAOR,MAAMK;IAC1B;IACA,OAAO;QAAEY;QAAWO;IAAM;AAC5B"}
@@ -1,9 +1,12 @@
1
- import { type Adapter, type Authorization, type MdModelIdentity } from './adapter.js';
1
+ import { type QueryOptions, type QueryResult } from '@agentshouse/query';
2
+ import { type Adapter, type Authorization } from './adapter.js';
3
+ import { type MdType } from './collection.js';
2
4
  export type AppRoom = {
3
5
  name: string;
4
6
  locator: string;
5
7
  writeGrants: readonly string[];
6
8
  providerOwnedPaths: readonly string[];
9
+ roomVersion: string | null;
7
10
  synchronizationAvailable: boolean;
8
11
  };
9
12
  export type ConnectionRefusalReason = 'no-matching-version' | 'missing-required-guarantee' | 'md-model-version-mismatch' | 'revoked-authorization';
@@ -14,16 +17,19 @@ export type ConnectionRefusal = {
14
17
  export type MdRuntimeOptions = {
15
18
  adapter: Adapter;
16
19
  requiredGuarantees: readonly string[];
17
- mdModel: MdModelIdentity;
18
20
  authorization?: Authorization;
19
- rooms?: readonly AppRoom[];
20
21
  discoveryIntervalMs?: number;
21
22
  signal?: AbortSignal;
22
23
  };
23
24
  export type MdRuntime = {
24
25
  rooms(): readonly AppRoom[];
25
- observe(topic: 'rooms', listener: (rooms: readonly AppRoom[]) => void): () => void;
26
- observe(topic: 'connection-refusal', listener: (refusal: ConnectionRefusal | null) => void): () => void;
26
+ query(options?: QueryOptions): QueryResult;
27
+ types(locator: string): readonly MdType[];
28
+ observe: {
29
+ (topic: 'rooms', listener: (rooms: readonly AppRoom[]) => void): () => void;
30
+ (topic: 'connection-refusal', listener: (refusal: ConnectionRefusal | null) => void): () => void;
31
+ (topic: 'query', query: QueryOptions, listener: (result: QueryResult) => void): () => void;
32
+ };
27
33
  reauthorize(): Promise<void>;
28
34
  };
29
35
  export declare function createMdRuntime(options: MdRuntimeOptions): MdRuntime;
@@ -1 +1 @@
1
- {"version":3,"file":"connection.d.ts","sourceRoot":"","sources":["../src/connection.ts"],"names":[],"mappings":"AAAA,OAAO,EA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IAC1C,OAAO,EAAE;QACP,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;QAC5E,CACE,KAAK,EAAE,oBAAoB,EAC3B,QAAQ,EAAE,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,KAAK,IAAI,GACpD,MAAM,IAAI,CAAC;QACd,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;KAC5F,CAAC;IACF,WAAW,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC9B,CAAC;AAOF,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAyRpE"}
@@ -1,28 +1,17 @@
1
+ import { query as evaluate } from '@agentshouse/query';
1
2
  import { ROOM_CONTRACT_VERSION, VERSION_1_CAPABILITIES } from './adapter.js';
3
+ import { adoptReplica, bootstrapRoom } from './bootstrap.js';
4
+ import { MD_MODEL, PRESENTED } from './collection.js';
5
+ import { openReplicaStore } from './store.js';
2
6
  const DEFAULT_DISCOVERY_INTERVAL_MS = 60_000;
3
7
  const knownCapabilities = new Set(VERSION_1_CAPABILITIES);
4
- function asAppRoom(room) {
5
- return {
6
- name: room.name,
7
- locator: room.locator,
8
- writeGrants: room.writeGrants,
9
- providerOwnedPaths: room.providerOwnedPaths,
10
- synchronizationAvailable: true
11
- };
12
- }
13
- function heldRoom(room) {
14
- return {
15
- name: room.name,
16
- locator: room.locator,
17
- writeGrants: room.writeGrants,
18
- providerOwnedPaths: room.providerOwnedPaths,
19
- synchronizationAvailable: false
20
- };
21
- }
22
8
  export function createMdRuntime(options) {
23
9
  const period = options.discoveryIntervalMs ?? DEFAULT_DISCOVERY_INTERVAL_MS;
24
10
  let authorization = options.authorization;
25
- let rooms = (options.rooms ?? []).map(heldRoom);
11
+ let store;
12
+ const replicas = new Map();
13
+ const rooms = new Map();
14
+ const unreadable = new Set();
26
15
  let refusal = null;
27
16
  let discoveryPaused = false;
28
17
  let timer;
@@ -32,12 +21,44 @@ export function createMdRuntime(options) {
32
21
  let queued = false;
33
22
  const roomListeners = new Set();
34
23
  const refusalListeners = new Set();
24
+ const querySubscriptions = new Set();
25
+ function listed() {
26
+ return [
27
+ ...rooms.values()
28
+ ];
29
+ }
30
+ function queryRooms() {
31
+ return [
32
+ ...replicas.values()
33
+ ].map((replica)=>({
34
+ room: replica.record.locator,
35
+ roomVersion: replica.record.roomVersion,
36
+ documents: replica.collection.documents
37
+ }));
38
+ }
35
39
  function emitRooms() {
36
- for (const listener of roomListeners)listener(rooms);
40
+ const value = listed();
41
+ for (const listener of roomListeners)listener(value);
37
42
  }
38
43
  function emitRefusal() {
39
44
  for (const listener of refusalListeners)listener(refusal);
40
45
  }
46
+ function visible(request) {
47
+ return evaluate(queryRooms(), {
48
+ ...request,
49
+ selector: {
50
+ $and: [
51
+ PRESENTED,
52
+ request.selector ?? {}
53
+ ]
54
+ }
55
+ });
56
+ }
57
+ function emitVisible() {
58
+ for (const subscription of querySubscriptions){
59
+ subscription.notify(visible(subscription.query));
60
+ }
61
+ }
41
62
  function stopTimer() {
42
63
  if (timer === undefined) return;
43
64
  clearInterval(timer);
@@ -58,17 +79,73 @@ export function createMdRuntime(options) {
58
79
  };
59
80
  emitRefusal();
60
81
  }
82
+ function list(room, synchronizationAvailable) {
83
+ rooms.set(room.locator, {
84
+ name: room.name,
85
+ locator: room.locator,
86
+ writeGrants: room.writeGrants,
87
+ providerOwnedPaths: room.providerOwnedPaths,
88
+ roomVersion: replicas.get(room.locator)?.record.roomVersion ?? null,
89
+ synchronizationAvailable
90
+ });
91
+ }
61
92
  function applyDiscovery(discovered) {
62
- const next = discovered.map(asAppRoom);
63
- const listed = new Set(discovered.map((room)=>room.locator));
64
- for (const room of rooms){
65
- if (listed.has(room.locator)) continue;
66
- next.push(heldRoom(room));
93
+ const listedLocators = new Set(discovered.map((room)=>room.locator));
94
+ for (const room of discovered){
95
+ list(room, !unreadable.has(room.locator));
96
+ }
97
+ for (const [locator, room] of rooms){
98
+ if (listedLocators.has(locator)) continue;
99
+ rooms.set(locator, {
100
+ ...room,
101
+ synchronizationAvailable: false
102
+ });
67
103
  }
68
- rooms = next;
69
104
  emitRooms();
70
105
  }
71
- async function cycle() {
106
+ async function openLocal() {
107
+ if (store !== undefined) return store;
108
+ const opened = await openReplicaStore();
109
+ const records = await opened.all();
110
+ store = opened;
111
+ for (const record of records){
112
+ const staged = adoptReplica(record);
113
+ if (staged === null) continue;
114
+ replicas.set(record.locator, staged);
115
+ list(record, false);
116
+ }
117
+ if (replicas.size > 0) {
118
+ emitRooms();
119
+ emitVisible();
120
+ }
121
+ return opened;
122
+ }
123
+ async function bootstrapMissing(discovered, local) {
124
+ for (const room of discovered){
125
+ if (closed || authorization === undefined) return;
126
+ if (replicas.has(room.locator)) continue;
127
+ const outcome = await bootstrapRoom(options.adapter, authorization, room);
128
+ if (outcome.kind === 'revoked-authorization') {
129
+ refuse('revoked-authorization');
130
+ return;
131
+ }
132
+ if (outcome.kind === 'room-not-readable') {
133
+ unreadable.add(room.locator);
134
+ list(room, false);
135
+ emitRooms();
136
+ continue;
137
+ }
138
+ if (outcome.kind === 'unconfirmed') continue;
139
+ if (closed) return;
140
+ await local.publish(outcome.replica.record);
141
+ unreadable.delete(room.locator);
142
+ replicas.set(room.locator, outcome.replica);
143
+ list(room, true);
144
+ emitRooms();
145
+ emitVisible();
146
+ }
147
+ }
148
+ async function cycle(local) {
72
149
  if (closed || authorization === undefined) return;
73
150
  const result = await options.adapter.discover(authorization);
74
151
  if (closed) return;
@@ -81,7 +158,7 @@ export function createMdRuntime(options) {
81
158
  refuse('no-matching-version');
82
159
  return;
83
160
  }
84
- if (result.mdModel.identity !== options.mdModel.identity || result.mdModel.version !== options.mdModel.version) {
161
+ if (result.mdModel.identity !== MD_MODEL.identity || result.mdModel.version !== MD_MODEL.version) {
85
162
  refuse('md-model-version-mismatch');
86
163
  return;
87
164
  }
@@ -97,6 +174,7 @@ export function createMdRuntime(options) {
97
174
  emitRefusal();
98
175
  }
99
176
  applyDiscovery(result.rooms);
177
+ await bootstrapMissing(result.rooms, local);
100
178
  }
101
179
  async function ensureAuthorization() {
102
180
  if (authorization !== undefined) return;
@@ -104,14 +182,15 @@ export function createMdRuntime(options) {
104
182
  }
105
183
  async function connect() {
106
184
  if (closed || discoveryPaused) return;
185
+ startTimer();
107
186
  try {
187
+ const local = await openLocal();
188
+ if (closed) return;
108
189
  await ensureAuthorization();
109
190
  if (closed) return;
110
- await cycle();
191
+ await cycle(local);
111
192
  } catch {
112
193
  return;
113
- } finally{
114
- if (!closed && !discoveryPaused) startTimer();
115
194
  }
116
195
  }
117
196
  async function run() {
@@ -137,8 +216,10 @@ export function createMdRuntime(options) {
137
216
  function close() {
138
217
  closed = true;
139
218
  stopTimer();
219
+ store?.close();
140
220
  roomListeners.clear();
141
221
  refusalListeners.clear();
222
+ querySubscriptions.clear();
142
223
  }
143
224
  options.signal?.addEventListener('abort', close, {
144
225
  once: true
@@ -147,22 +228,40 @@ export function createMdRuntime(options) {
147
228
  void enqueue();
148
229
  return {
149
230
  rooms () {
150
- return rooms;
231
+ return listed();
232
+ },
233
+ query (request = {}) {
234
+ return visible(request);
151
235
  },
152
- observe (topic, listener) {
236
+ types (locator) {
237
+ return replicas.get(locator)?.collection.types ?? [];
238
+ },
239
+ observe (topic, second, third) {
153
240
  if (topic === 'rooms') {
154
- const notify = listener;
241
+ const notify = second;
155
242
  roomListeners.add(notify);
156
- notify(rooms);
243
+ notify(listed());
157
244
  return ()=>{
158
245
  roomListeners.delete(notify);
159
246
  };
160
247
  }
161
- const notify = listener;
162
- refusalListeners.add(notify);
163
- notify(refusal);
248
+ if (topic === 'connection-refusal') {
249
+ const notify = second;
250
+ refusalListeners.add(notify);
251
+ notify(refusal);
252
+ return ()=>{
253
+ refusalListeners.delete(notify);
254
+ };
255
+ }
256
+ const subscription = {
257
+ query: second,
258
+ notify: third
259
+ };
260
+ const first = visible(subscription.query);
261
+ querySubscriptions.add(subscription);
262
+ subscription.notify(first);
164
263
  return ()=>{
165
- refusalListeners.delete(notify);
264
+ querySubscriptions.delete(subscription);
166
265
  };
167
266
  },
168
267
  async reauthorize () {
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/connection.ts"],"sourcesContent":["import {\n ROOM_CONTRACT_VERSION,\n VERSION_1_CAPABILITIES,\n type Adapter,\n type Authorization,\n type DiscoveredRoom,\n type MdModelIdentity,\n} from './adapter.js';\n\nconst DEFAULT_DISCOVERY_INTERVAL_MS = 60_000;\n\nconst knownCapabilities = new Set<string>(VERSION_1_CAPABILITIES);\n\nexport type AppRoom = {\n name: string;\n locator: string;\n writeGrants: readonly string[];\n providerOwnedPaths: readonly string[];\n synchronizationAvailable: boolean;\n};\n\nexport type ConnectionRefusalReason =\n | 'no-matching-version'\n | 'missing-required-guarantee'\n | 'md-model-version-mismatch'\n | 'revoked-authorization';\n\nexport type ConnectionRefusal = {\n reason: ConnectionRefusalReason;\n reauthorizationOffered: boolean;\n};\n\nexport type MdRuntimeOptions = {\n adapter: Adapter;\n requiredGuarantees: readonly string[];\n mdModel: MdModelIdentity;\n authorization?: Authorization;\n rooms?: readonly AppRoom[];\n discoveryIntervalMs?: number;\n signal?: AbortSignal;\n};\n\nexport type MdRuntime = {\n rooms(): readonly AppRoom[];\n observe(topic: 'rooms', listener: (rooms: readonly AppRoom[]) => void): () => void;\n observe(\n topic: 'connection-refusal',\n listener: (refusal: ConnectionRefusal | null) => void,\n ): () => void;\n reauthorize(): Promise<void>;\n};\n\nfunction asAppRoom(room: DiscoveredRoom): AppRoom {\n return {\n name: room.name,\n locator: room.locator,\n writeGrants: room.writeGrants,\n providerOwnedPaths: room.providerOwnedPaths,\n synchronizationAvailable: true,\n };\n}\n\nfunction heldRoom(room: AppRoom): AppRoom {\n return {\n name: room.name,\n locator: room.locator,\n writeGrants: room.writeGrants,\n providerOwnedPaths: room.providerOwnedPaths,\n synchronizationAvailable: false,\n };\n}\n\nexport function createMdRuntime(options: MdRuntimeOptions): MdRuntime {\n const period = options.discoveryIntervalMs ?? DEFAULT_DISCOVERY_INTERVAL_MS;\n let authorization: Authorization | undefined = options.authorization;\n let rooms: AppRoom[] = (options.rooms ?? []).map(heldRoom);\n let refusal: ConnectionRefusal | null = null;\n let discoveryPaused = false;\n let timer: ReturnType<typeof setInterval> | undefined;\n let closed = false;\n let chain: Promise<void> = Promise.resolve();\n let inflight = false;\n let queued = false;\n const roomListeners = new Set<(rooms: readonly AppRoom[]) => void>();\n const refusalListeners = new Set<(refusal: ConnectionRefusal | null) => void>();\n\n function emitRooms() {\n for (const listener of roomListeners) listener(rooms);\n }\n\n function emitRefusal() {\n for (const listener of refusalListeners) listener(refusal);\n }\n\n function stopTimer() {\n if (timer === undefined) return;\n clearInterval(timer);\n timer = undefined;\n }\n\n function startTimer() {\n if (timer !== undefined) return;\n timer = setInterval(() => {\n void enqueue();\n }, period);\n }\n\n function refuse(reason: ConnectionRefusalReason) {\n stopTimer();\n discoveryPaused = true;\n refusal = {\n reason,\n reauthorizationOffered: reason === 'revoked-authorization',\n };\n emitRefusal();\n }\n\n function applyDiscovery(discovered: readonly DiscoveredRoom[]) {\n const next = discovered.map(asAppRoom);\n const listed = new Set(discovered.map((room) => room.locator));\n for (const room of rooms) {\n if (listed.has(room.locator)) continue;\n next.push(heldRoom(room));\n }\n rooms = next;\n emitRooms();\n }\n\n async function cycle() {\n if (closed || authorization === undefined) return;\n const result = await options.adapter.discover(authorization);\n if (closed) return;\n if (result.kind === 'transport-uncertainty') return;\n if (result.kind === 'revoked-authorization') {\n refuse('revoked-authorization');\n return;\n }\n if (!result.supportedVersions.includes(ROOM_CONTRACT_VERSION)) {\n refuse('no-matching-version');\n return;\n }\n if (\n result.mdModel.identity !== options.mdModel.identity ||\n result.mdModel.version !== options.mdModel.version\n ) {\n refuse('md-model-version-mismatch');\n return;\n }\n const declared = new Set(result.capabilities.map((capability) => capability.name));\n for (const required of options.requiredGuarantees) {\n if (!knownCapabilities.has(required) || !declared.has(required)) {\n refuse('missing-required-guarantee');\n return;\n }\n }\n if (refusal !== null) {\n refusal = null;\n emitRefusal();\n }\n applyDiscovery(result.rooms);\n }\n\n async function ensureAuthorization() {\n if (authorization !== undefined) return;\n authorization = await options.adapter.authorize();\n }\n\n async function connect() {\n if (closed || discoveryPaused) return;\n try {\n await ensureAuthorization();\n if (closed) return;\n await cycle();\n } catch {\n return;\n } finally {\n if (!closed && !discoveryPaused) startTimer();\n }\n }\n\n async function run() {\n try {\n await connect();\n } finally {\n inflight = false;\n if (queued && !closed) {\n queued = false;\n void enqueue();\n }\n }\n }\n\n function enqueue() {\n if (inflight) {\n queued = true;\n return chain;\n }\n inflight = true;\n chain = chain.then(run, run);\n return chain;\n }\n\n function close() {\n closed = true;\n stopTimer();\n roomListeners.clear();\n refusalListeners.clear();\n }\n\n options.signal?.addEventListener('abort', close, { once: true });\n if (options.signal?.aborted) close();\n\n void enqueue();\n\n return {\n rooms() {\n return rooms;\n },\n observe(topic: 'rooms' | 'connection-refusal', listener: (value: never) => void) {\n if (topic === 'rooms') {\n const notify = listener as (value: readonly AppRoom[]) => void;\n roomListeners.add(notify);\n notify(rooms);\n return () => {\n roomListeners.delete(notify);\n };\n }\n const notify = listener as (value: ConnectionRefusal | null) => void;\n refusalListeners.add(notify);\n notify(refusal);\n return () => {\n refusalListeners.delete(notify);\n };\n },\n async reauthorize() {\n if (refusal === null || !refusal.reauthorizationOffered) return;\n authorization = undefined;\n discoveryPaused = false;\n await enqueue();\n },\n };\n}\n"],"names":["ROOM_CONTRACT_VERSION","VERSION_1_CAPABILITIES","DEFAULT_DISCOVERY_INTERVAL_MS","knownCapabilities","Set","asAppRoom","room","name","locator","writeGrants","providerOwnedPaths","synchronizationAvailable","heldRoom","createMdRuntime","options","period","discoveryIntervalMs","authorization","rooms","map","refusal","discoveryPaused","timer","closed","chain","Promise","resolve","inflight","queued","roomListeners","refusalListeners","emitRooms","listener","emitRefusal","stopTimer","undefined","clearInterval","startTimer","setInterval","enqueue","refuse","reason","reauthorizationOffered","applyDiscovery","discovered","next","listed","has","push","cycle","result","adapter","discover","kind","supportedVersions","includes","mdModel","identity","version","declared","capabilities","capability","required","requiredGuarantees","ensureAuthorization","authorize","connect","run","then","close","clear","signal","addEventListener","once","aborted","observe","topic","notify","add","delete","reauthorize"],"mappings":"AAAA,SACEA,qBAAqB,EACrBC,sBAAsB,QAKjB,eAAe;AAEtB,MAAMC,gCAAgC;AAEtC,MAAMC,oBAAoB,IAAIC,IAAYH;AAyC1C,SAASI,UAAUC,IAAoB;IACrC,OAAO;QACLC,MAAMD,KAAKC,IAAI;QACfC,SAASF,KAAKE,OAAO;QACrBC,aAAaH,KAAKG,WAAW;QAC7BC,oBAAoBJ,KAAKI,kBAAkB;QAC3CC,0BAA0B;IAC5B;AACF;AAEA,SAASC,SAASN,IAAa;IAC7B,OAAO;QACLC,MAAMD,KAAKC,IAAI;QACfC,SAASF,KAAKE,OAAO;QACrBC,aAAaH,KAAKG,WAAW;QAC7BC,oBAAoBJ,KAAKI,kBAAkB;QAC3CC,0BAA0B;IAC5B;AACF;AAEA,OAAO,SAASE,gBAAgBC,OAAyB;IACvD,MAAMC,SAASD,QAAQE,mBAAmB,IAAId;IAC9C,IAAIe,gBAA2CH,QAAQG,aAAa;IACpE,IAAIC,QAAmB,AAACJ,CAAAA,QAAQI,KAAK,IAAI,EAAE,AAAD,EAAGC,GAAG,CAACP;IACjD,IAAIQ,UAAoC;IACxC,IAAIC,kBAAkB;IACtB,IAAIC;IACJ,IAAIC,SAAS;IACb,IAAIC,QAAuBC,QAAQC,OAAO;IAC1C,IAAIC,WAAW;IACf,IAAIC,SAAS;IACb,MAAMC,gBAAgB,IAAIzB;IAC1B,MAAM0B,mBAAmB,IAAI1B;IAE7B,SAAS2B;QACP,KAA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D;gBACP,OAAO;oBACLW,cAAckD,MAAM,CAACF;gBACvB;YACF;YACA,MAAMA,SAAS7C;YACfF,iBAAiBgD,GAAG,CAACD;YACrBA,OAAOzD;YACP,OAAO;gBACLU,iBAAiBiD,MAAM,CAACF;YAC1B;QACF;QACA,MAAMG;YACJ,IAAI5D,YAAY,QAAQ,CAACA,QAAQsB,sBAAsB,EAAE;YACzDzB,gBAAgBkB;YAChBd,kBAAkB;YAClB,MAAMkB;QACR;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/connection.ts"],"sourcesContent":["import {\n query as evaluate,\n type QueryOptions,\n type QueryResult,\n type QueryRoom,\n} from '@agentshouse/query';\nimport {\n ROOM_CONTRACT_VERSION,\n VERSION_1_CAPABILITIES,\n type Adapter,\n type Authorization,\n type DiscoveredRoom,\n} from './adapter.js';\nimport { adoptReplica, bootstrapRoom, type StagedReplica } from './bootstrap.js';\nimport { MD_MODEL, PRESENTED, type MdType } from './collection.js';\nimport { openReplicaStore, type ReplicaRecord, type ReplicaStore } from './store.js';\n\nconst DEFAULT_DISCOVERY_INTERVAL_MS = 60_000;\n\nconst knownCapabilities = new Set<string>(VERSION_1_CAPABILITIES);\n\nexport type AppRoom = {\n name: string;\n locator: string;\n writeGrants: readonly string[];\n providerOwnedPaths: readonly string[];\n roomVersion: string | null;\n synchronizationAvailable: boolean;\n};\n\nexport type ConnectionRefusalReason =\n | 'no-matching-version'\n | 'missing-required-guarantee'\n | 'md-model-version-mismatch'\n | 'revoked-authorization';\n\nexport type ConnectionRefusal = {\n reason: ConnectionRefusalReason;\n reauthorizationOffered: boolean;\n};\n\nexport type MdRuntimeOptions = {\n adapter: Adapter;\n requiredGuarantees: readonly string[];\n authorization?: Authorization;\n discoveryIntervalMs?: number;\n signal?: AbortSignal;\n};\n\nexport type MdRuntime = {\n rooms(): readonly AppRoom[];\n query(options?: QueryOptions): QueryResult;\n types(locator: string): readonly MdType[];\n observe: {\n (topic: 'rooms', listener: (rooms: readonly AppRoom[]) => void): () => void;\n (\n topic: 'connection-refusal',\n listener: (refusal: ConnectionRefusal | null) => void,\n ): () => void;\n (topic: 'query', query: QueryOptions, listener: (result: QueryResult) => void): () => void;\n };\n reauthorize(): Promise<void>;\n};\n\ntype QuerySubscription = {\n query: QueryOptions;\n notify: (result: QueryResult) => void;\n};\n\nexport function createMdRuntime(options: MdRuntimeOptions): MdRuntime {\n const period = options.discoveryIntervalMs ?? DEFAULT_DISCOVERY_INTERVAL_MS;\n let authorization: Authorization | undefined = options.authorization;\n let store: ReplicaStore | undefined;\n const replicas = new Map<string, StagedReplica>();\n const rooms = new Map<string, AppRoom>();\n const unreadable = new Set<string>();\n let refusal: ConnectionRefusal | null = null;\n let discoveryPaused = false;\n let timer: ReturnType<typeof setInterval> | undefined;\n let closed = false;\n let chain: Promise<void> = Promise.resolve();\n let inflight = false;\n let queued = false;\n const roomListeners = new Set<(rooms: readonly AppRoom[]) => void>();\n const refusalListeners = new Set<(refusal: ConnectionRefusal | null) => void>();\n const querySubscriptions = new Set<QuerySubscription>();\n\n function listed(): readonly AppRoom[] {\n return [...rooms.values()];\n }\n\n function queryRooms(): readonly QueryRoom[] {\n return [...replicas.values()].map((replica) => ({\n room: replica.record.locator,\n roomVersion: replica.record.roomVersion,\n documents: replica.collection.documents,\n }));\n }\n\n function emitRooms() {\n const value = listed();\n for (const listener of roomListeners) listener(value);\n }\n\n function emitRefusal() {\n for (const listener of refusalListeners) listener(refusal);\n }\n\n function visible(request: QueryOptions): QueryResult {\n return evaluate(queryRooms(), {\n ...request,\n selector: { $and: [PRESENTED, request.selector ?? {}] },\n });\n }\n\n function emitVisible() {\n for (const subscription of querySubscriptions) {\n subscription.notify(visible(subscription.query));\n }\n }\n\n function stopTimer() {\n if (timer === undefined) return;\n clearInterval(timer);\n timer = undefined;\n }\n\n function startTimer() {\n if (timer !== undefined) return;\n timer = setInterval(() => {\n void enqueue();\n }, period);\n }\n\n function refuse(reason: ConnectionRefusalReason) {\n stopTimer();\n discoveryPaused = true;\n refusal = {\n reason,\n reauthorizationOffered: reason === 'revoked-authorization',\n };\n emitRefusal();\n }\n\n function list(room: DiscoveredRoom, synchronizationAvailable: boolean) {\n rooms.set(room.locator, {\n name: room.name,\n locator: room.locator,\n writeGrants: room.writeGrants,\n providerOwnedPaths: room.providerOwnedPaths,\n roomVersion: replicas.get(room.locator)?.record.roomVersion ?? null,\n synchronizationAvailable,\n });\n }\n\n function applyDiscovery(discovered: readonly DiscoveredRoom[]) {\n const listedLocators = new Set(discovered.map((room) => room.locator));\n for (const room of discovered) {\n list(room, !unreadable.has(room.locator));\n }\n for (const [locator, room] of rooms) {\n if (listedLocators.has(locator)) continue;\n rooms.set(locator, { ...room, synchronizationAvailable: false });\n }\n emitRooms();\n }\n\n async function openLocal(): Promise<ReplicaStore> {\n if (store !== undefined) return store;\n const opened = await openReplicaStore();\n const records = await opened.all();\n store = opened;\n for (const record of records) {\n const staged = adoptReplica(record);\n if (staged === null) continue;\n replicas.set(record.locator, staged);\n list(record, false);\n }\n if (replicas.size > 0) {\n emitRooms();\n emitVisible();\n }\n return opened;\n }\n\n async function bootstrapMissing(discovered: readonly DiscoveredRoom[], local: ReplicaStore) {\n for (const room of discovered) {\n if (closed || authorization === undefined) return;\n if (replicas.has(room.locator)) continue;\n const outcome = await bootstrapRoom(options.adapter, authorization, room);\n if (outcome.kind === 'revoked-authorization') {\n refuse('revoked-authorization');\n return;\n }\n if (outcome.kind === 'room-not-readable') {\n unreadable.add(room.locator);\n list(room, false);\n emitRooms();\n continue;\n }\n if (outcome.kind === 'unconfirmed') continue;\n if (closed) return;\n await local.publish(outcome.replica.record);\n unreadable.delete(room.locator);\n replicas.set(room.locator, outcome.replica);\n list(room, true);\n emitRooms();\n emitVisible();\n }\n }\n\n async function cycle(local: ReplicaStore) {\n if (closed || authorization === undefined) return;\n const result = await options.adapter.discover(authorization);\n if (closed) return;\n if (result.kind === 'transport-uncertainty') return;\n if (result.kind === 'revoked-authorization') {\n refuse('revoked-authorization');\n return;\n }\n if (!result.supportedVersions.includes(ROOM_CONTRACT_VERSION)) {\n refuse('no-matching-version');\n return;\n }\n if (\n result.mdModel.identity !== MD_MODEL.identity ||\n result.mdModel.version !== MD_MODEL.version\n ) {\n refuse('md-model-version-mismatch');\n return;\n }\n const declared = new Set(result.capabilities.map((capability) => capability.name));\n for (const required of options.requiredGuarantees) {\n if (!knownCapabilities.has(required) || !declared.has(required)) {\n refuse('missing-required-guarantee');\n return;\n }\n }\n if (refusal !== null) {\n refusal = null;\n emitRefusal();\n }\n applyDiscovery(result.rooms);\n await bootstrapMissing(result.rooms, local);\n }\n\n async function ensureAuthorization() {\n if (authorization !== undefined) return;\n authorization = await options.adapter.authorize();\n }\n\n async function connect() {\n if (closed || discoveryPaused) return;\n startTimer();\n try {\n const local = await openLocal();\n if (closed) return;\n await ensureAuthorization();\n if (closed) return;\n await cycle(local);\n } catch {\n return;\n }\n }\n\n async function run() {\n try {\n await connect();\n } finally {\n inflight = false;\n if (queued && !closed) {\n queued = false;\n void enqueue();\n }\n }\n }\n\n function enqueue() {\n if (inflight) {\n queued = true;\n return chain;\n }\n inflight = true;\n chain = chain.then(run, run);\n return chain;\n }\n\n function close() {\n closed = true;\n stopTimer();\n store?.close();\n roomListeners.clear();\n refusalListeners.clear();\n querySubscriptions.clear();\n }\n\n options.signal?.addEventListener('abort', close, { once: true });\n if (options.signal?.aborted) close();\n\n void enqueue();\n\n return {\n rooms() {\n return listed();\n },\n query(request: QueryOptions = {}) {\n return visible(request);\n },\n types(locator: string) {\n return replicas.get(locator)?.collection.types ?? [];\n },\n observe(\n topic: 'rooms' | 'connection-refusal' | 'query',\n second: QueryOptions | ((value: never) => void),\n third?: (value: never) => void,\n ) {\n if (topic === 'rooms') {\n const notify = second as (value: readonly AppRoom[]) => void;\n roomListeners.add(notify);\n notify(listed());\n return () => {\n roomListeners.delete(notify);\n };\n }\n if (topic === 'connection-refusal') {\n const notify = second as (value: ConnectionRefusal | null) => void;\n refusalListeners.add(notify);\n notify(refusal);\n return () => {\n refusalListeners.delete(notify);\n };\n }\n const subscription: QuerySubscription = {\n query: second as QueryOptions,\n notify: third as (result: QueryResult) => void,\n };\n const first = visible(subscription.query);\n querySubscriptions.add(subscription);\n subscription.notify(first);\n return () => {\n querySubscriptions.delete(subscription);\n };\n },\n async reauthorize() {\n if (refusal === null || !refusal.reauthorizationOffered) return;\n authorization = undefined;\n discoveryPaused = false;\n await enqueue();\n },\n };\n}\n"],"names":["query","evaluate","ROOM_CONTRACT_VERSION","VERSION_1_CAPABILITIES","adoptReplica","bootstrapRoom","MD_MODEL","PRESENTED","openReplicaStore","DEFAULT_DISCOVERY_INTERVAL_MS","knownCapabilities","Set","createMdRuntime","options","period","discoveryIntervalMs","authorization","store","replicas","Map","rooms","unreadable","refusal","discoveryPaused","timer","closed","chain","Promise","resolve","inflight","queued","roomListeners","refusalListeners","querySubscriptions","listed","values","queryRooms","map","replica","room","record","locator","roomVersion","documents","collection","emitRooms","value","listener","emitRefusal","visible","request","selector","$and","emitVisible","subscription","notify","stopTimer","undefined","clearInterval","startTimer","setInterval","enqueue","refuse","reason","reauthorizationOffered","list","synchronizationAvailable","set","name","writeGrants","providerOwnedPaths","get","applyDiscovery","discovered","listedLocators","has","openLocal","opened","records","all","staged","size","bootstrapMissing","local","outcome","adapter","kind","add","publish","delete","cycle","result","discover","supportedVersions","includes","mdModel","identity","version","declared","capabilities","capability","required","requiredGuarantees","ensureAuthorization","authorize","connect","run","then","close","clear","signal","addEventListener","once","aborted","types","observe","topic","second","third","first","reauthorize"],"mappings":"AAAA,SACEA,SAASC,QAAQ,QAIZ,qBAAqB;AAC5B,SACEC,qBAAqB,EACrBC,sBAAsB,QAIjB,eAAe;AACtB,SAASC,YAAY,EAAEC,aAAa,QAA4B,iBAAiB;AACjF,SAASC,QAAQ,EAAEC,SAAS,QAAqB,kBAAkB;AACnE,SAASC,gBAAgB,QAA+C,aAAa;AAErF,MAAMC,gCAAgC;AAEtC,MAAMC,o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AASH,OAAO;QAAEI,MAAM;IAAK;IAC9D,IAAInG,QAAQiG,MAAM,EAAEG,SAASL;IAE7B,KAAK/C;IAEL,OAAO;QACLzC;YACE,OAAOc;QACT;QACAlC,OAAMkD,UAAwB,CAAC,CAAC;YAC9B,OAAOD,QAAQC;QACjB;QACAgE,OAAMzE,OAAe;YACnB,OAAOvB,SAASqD,GAAG,CAAC9B,UAAUG,WAAWsE,SAAS,EAAE;QACtD;QACAC,SACEC,KAA+C,EAC/CC,MAA+C,EAC/CC,KAA8B;YAE9B,IAAIF,UAAU,SAAS;gBACrB,MAAM7D,SAAS8D;gBACftF,cAAcwD,GAAG,CAAChC;gBAClBA,OAAOrB;gBACP,OAAO;oBACLH,cAAc0D,MAAM,CAAClC;gBACvB;YACF;YACA,IAAI6D,UAAU,sBAAsB;gBAClC,MAAM7D,SAAS8D;gBACfrF,iBAAiBuD,GAAG,CAAChC;gBACrBA,OAAOjC;gBACP,OAAO;oBACLU,iBAAiByD,MAAM,CAAClC;gBAC1B;YACF;YACA,MAAMD,eAAkC;gBACtCtD,OAAOqH;gBACP9D,QAAQ+D;YACV;YACA,MAAMC,QAAQtE,QAAQK,aAAatD,KAAK;YACxCiC,mBAAmBsD,GAAG,CAACjC;YACvBA,aAAaC,MAAM,CAACgE;YACpB,OAAO;gBACLtF,mBAAmBwD,MAAM,CAACnC;YAC5B;QACF;QACA,MAAMkE;YACJ,IAAIlG,YAAY,QAAQ,CAACA,QAAQ0C,sBAAsB,EAAE;YACzDhD,gBAAgByC;YAChBlC,kBAAkB;YAClB,MAAMsC;QACR;IACF;AACF"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,6 @@
1
- export type { ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, Authorization, BootstrapRequest, BootstrapResult, Capability, DiscoverResult, DiscoveredRoom, Discovery, HistoryRequest, HistoryResult, MdModelIdentity, MutationRequest, MutationResult, PageToken, ProviderLimit, RefreshRequest, RefreshResult, Retention, RevokedAuthorization, RoomNotReadable, TransportUncertainty, } from './adapter.js';
1
+ export type { ActionDeclaration, ActionRequest, ActionResult, Adapter, AdapterFailure, Authorization, BootstrapPage, BootstrapRequest, BootstrapResult, Capability, DiscoverResult, DiscoveredRoom, Discovery, HistoryRequest, HistoryResult, MdModelIdentity, MutationRequest, MutationResult, PageToken, ProviderLimit, RefreshRequest, RefreshResult, Retention, RevokedAuthorization, RoomNotReadable, TransportUncertainty, } from './adapter.js';
2
+ export type { MdType } from './collection.js';
2
3
  export type { AppRoom, ConnectionRefusal, ConnectionRefusalReason, MdRuntime, MdRuntimeOptions, } from './connection.js';
3
4
  export { createMdRuntime } from './connection.js';
5
+ export type { Backlink, QueryDocument, QueryGroup, QueryOptions, QueryResult, Selector, } from '@agentshouse/query';
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,EACb,eAAe,EACf,eAAe,EACf,cAAc,EACd,SAAS,EACT,aAAa,EACb,cAAc,EACd,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,YAAY,EACV,OAAO,EACP,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,EACT,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,iBAAiB,EACjB,aAAa,EACb,YAAY,EACZ,OAAO,EACP,cAAc,EACd,aAAa,EACb,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,UAAU,EACV,cAAc,EACd,cAAc,EACd,SAAS,EACT,cAAc,EACd,aAAa,EACb,eAAe,EACf,eAAe,EACf,cAAc,EACd,SAAS,EACT,aAAa,EACb,cAAc,EACd,aAAa,EACb,SAAS,EACT,oBAAoB,EACpB,eAAe,EACf,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,YAAY,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC9C,YAAY,EACV,OAAO,EACP,iBAAiB,EACjB,uBAAuB,EACvB,SAAS,EACT,gBAAgB,GACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,YAAY,EACV,QAAQ,EACR,aAAa,EACb,UAAU,EACV,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,MAAM,oBAAoB,CAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/index.ts"],"sourcesContent":["export type {\n ActionDeclaration,\n ActionRequest,\n ActionResult,\n Adapter,\n AdapterFailure,\n Authorization,\n BootstrapRequest,\n BootstrapResult,\n Capability,\n DiscoverResult,\n DiscoveredRoom,\n Discovery,\n HistoryRequest,\n HistoryResult,\n MdModelIdentity,\n MutationRequest,\n MutationResult,\n PageToken,\n ProviderLimit,\n RefreshRequest,\n RefreshResult,\n Retention,\n RevokedAuthorization,\n RoomNotReadable,\n TransportUncertainty,\n} from './adapter.js';\nexport type {\n AppRoom,\n ConnectionRefusal,\n ConnectionRefusalReason,\n MdRuntime,\n MdRuntimeOptions,\n} from './connection.js';\nexport { createMdRuntime } from './connection.js';\n"],"names":["createMdRuntime"],"mappings":"AAkCA,SAASA,eAAe,QAAQ,kBAAkB"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/index.ts"],"sourcesContent":["export type {\n ActionDeclaration,\n ActionRequest,\n ActionResult,\n Adapter,\n AdapterFailure,\n Authorization,\n BootstrapPage,\n BootstrapRequest,\n BootstrapResult,\n Capability,\n DiscoverResult,\n DiscoveredRoom,\n Discovery,\n HistoryRequest,\n HistoryResult,\n MdModelIdentity,\n MutationRequest,\n MutationResult,\n PageToken,\n ProviderLimit,\n RefreshRequest,\n RefreshResult,\n Retention,\n RevokedAuthorization,\n RoomNotReadable,\n TransportUncertainty,\n} from './adapter.js';\nexport type { MdType } from './collection.js';\nexport type {\n AppRoom,\n ConnectionRefusal,\n ConnectionRefusalReason,\n MdRuntime,\n MdRuntimeOptions,\n} from './connection.js';\nexport { createMdRuntime } from './connection.js';\nexport type {\n Backlink,\n QueryDocument,\n QueryGroup,\n QueryOptions,\n QueryResult,\n Selector,\n} from '@agentshouse/query';\n"],"names":["createMdRuntime"],"mappings":"AAoCA,SAASA,eAAe,QAAQ,kBAAkB"}
package/dist/memory.d.ts CHANGED
@@ -1,6 +1,11 @@
1
1
  import { type Adapter, type Capability, type DiscoveredRoom, type MdModelIdentity, type ProviderLimit, type Retention } from './adapter.js';
2
+ export type MemoryRoom = DiscoveredRoom & {
3
+ documents?: Readonly<Record<string, string>>;
4
+ binaryTargets?: readonly string[];
5
+ };
2
6
  export type MemoryAdapterOptions = {
3
- rooms?: readonly DiscoveredRoom[];
7
+ rooms?: readonly MemoryRoom[];
8
+ pageSize?: number;
4
9
  mdModel?: MdModelIdentity;
5
10
  supportedVersions?: readonly number[];
6
11
  capabilities?: readonly Capability[];
@@ -9,7 +14,7 @@ export type MemoryAdapterOptions = {
9
14
  origins?: readonly string[];
10
15
  };
11
16
  export type MemoryAdapter = Adapter & {
12
- setRooms(rooms: readonly DiscoveredRoom[]): void;
17
+ setRooms(rooms: readonly MemoryRoom[]): void;
13
18
  script(operation: keyof Adapter, answer: unknown): void;
14
19
  };
15
20
  export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,EA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AAE,SAAS,UAAU,EAAE,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,iBAAiB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,YAAY,CAAC,EAAE,SAAS,UAAU,EAAE,CAAC;IACrC,cAAc,CAAC,EAAE,SAAS,aAAa,EAAE,CAAC;IAC1C,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,OAAO,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG;IACpC,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,IAAI,CAAC;IAC7C,MAAM,CAAC,SAAS,EAAE,MAAM,OAAO,EAAE,MAAM,EAAE,OAAO,GAAG,IAAI,CAAC;CACzD,CAAC;AAaF,wBAAgB,mBAAmB,CAAC,OAAO,GAAE,oBAAyB,GAAG,aAAa,CA6IrF"}
package/dist/memory.js CHANGED
@@ -1,16 +1,14 @@
1
1
  import { ROOM_CONTRACT_VERSION } from './adapter.js';
2
- async function resolveScript(answer, fallback) {
2
+ import { MD_MODEL } from './collection.js';
3
+ async function resolveScript(answer, fallback, request) {
3
4
  if (answer === undefined) return fallback();
4
- return typeof answer === 'function' ? answer() : answer;
5
+ return typeof answer === 'function' ? answer(request) : answer;
5
6
  }
6
7
  export function createMemoryAdapter(options = {}) {
7
8
  let rooms = options.rooms === undefined ? [] : [
8
9
  ...options.rooms
9
10
  ];
10
- const mdModel = options.mdModel ?? {
11
- identity: 'mdmodel',
12
- version: '1.0.0'
13
- };
11
+ const mdModel = options.mdModel ?? MD_MODEL;
14
12
  const supportedVersions = options.supportedVersions ?? [
15
13
  ROOM_CONTRACT_VERSION
16
14
  ];
@@ -24,15 +22,40 @@ export function createMemoryAdapter(options = {}) {
24
22
  const origins = options.origins ?? [
25
23
  'https://origin.example'
26
24
  ];
25
+ const pageSize = options.pageSize;
27
26
  const scripts = {};
27
+ function declared(room) {
28
+ return {
29
+ name: room.name,
30
+ locator: room.locator,
31
+ roomVersion: room.roomVersion,
32
+ writeGrants: room.writeGrants,
33
+ providerOwnedPaths: room.providerOwnedPaths
34
+ };
35
+ }
36
+ function page(room, from) {
37
+ const paths = Object.keys(room.documents ?? {}).sort();
38
+ const size = pageSize ?? paths.length;
39
+ const taken = paths.slice(from, from + size);
40
+ const documents = {};
41
+ for (const path of taken)documents[path] = (room.documents ?? {})[path];
42
+ const next = from + taken.length;
43
+ return {
44
+ kind: 'bootstrap',
45
+ roomVersion: room.roomVersion,
46
+ documents,
47
+ binaryTargets: from === 0 ? room.binaryTargets ?? [] : [],
48
+ ...next < paths.length ? {
49
+ pageToken: String(next)
50
+ } : {}
51
+ };
52
+ }
28
53
  function discovery() {
29
54
  return {
30
55
  kind: 'discovery',
31
56
  supportedVersions,
32
57
  mdModel,
33
- rooms: [
34
- ...rooms
35
- ],
58
+ rooms: rooms.map(declared),
36
59
  capabilities,
37
60
  providerLimits,
38
61
  retention,
@@ -50,10 +73,10 @@ export function createMemoryAdapter(options = {}) {
50
73
  else scripts[operation] = answer;
51
74
  },
52
75
  async authorize () {
53
- return resolveScript(scripts.authorize, ()=>({}));
76
+ return resolveScript(scripts.authorize, ()=>({}), undefined);
54
77
  },
55
78
  async discover (_authorization) {
56
- return resolveScript(scripts.discover, discovery);
79
+ return resolveScript(scripts.discover, discovery, undefined);
57
80
  },
58
81
  async bootstrap (_authorization, request) {
59
82
  return resolveScript(scripts.bootstrap, ()=>{
@@ -64,11 +87,8 @@ export function createMemoryAdapter(options = {}) {
64
87
  locator: request.locator
65
88
  };
66
89
  }
67
- return {
68
- kind: 'bootstrap',
69
- roomVersion: room.roomVersion
70
- };
71
- });
90
+ return page(room, request.pageToken === undefined ? 0 : Number(request.pageToken));
91
+ }, request);
72
92
  },
73
93
  async refresh (_authorization, request) {
74
94
  return resolveScript(scripts.refresh, ()=>{
@@ -88,7 +108,7 @@ export function createMemoryAdapter(options = {}) {
88
108
  kind: 'net-advancement',
89
109
  roomVersion: room.roomVersion
90
110
  };
91
- });
111
+ }, request);
92
112
  },
93
113
  async mutate (_authorization, request) {
94
114
  return resolveScript(scripts.mutate, ()=>{
@@ -103,7 +123,7 @@ export function createMemoryAdapter(options = {}) {
103
123
  kind: 'rejected',
104
124
  text: ''
105
125
  };
106
- });
126
+ }, request);
107
127
  },
108
128
  async history (_authorization, request) {
109
129
  return resolveScript(scripts.history, ()=>{
@@ -118,13 +138,13 @@ export function createMemoryAdapter(options = {}) {
118
138
  kind: 'history',
119
139
  revisions: []
120
140
  };
121
- });
141
+ }, request);
122
142
  },
123
- async action (_authorization, _request) {
143
+ async action (_authorization, request) {
124
144
  return resolveScript(scripts.action, ()=>({
125
145
  kind: 'rejected',
126
146
  text: ''
127
- }));
147
+ }), request);
128
148
  }
129
149
  };
130
150
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/memory.ts"],"sourcesContent":["import {\n ROOM_CONTRACT_VERSION,\n type ActionRequest,\n type ActionResult,\n type Adapter,\n type Authorization,\n type BootstrapRequest,\n type BootstrapResult,\n type Capability,\n type DiscoverResult,\n type DiscoveredRoom,\n type HistoryRequest,\n type HistoryResult,\n type MdModelIdentity,\n type MutationRequest,\n type MutationResult,\n type ProviderLimit,\n type RefreshRequest,\n type RefreshResult,\n type Retention,\n} from './adapter.js';\n\nexport type MemoryAdapterOptions = {\n rooms?: readonly DiscoveredRoom[];\n mdModel?: MdModelIdentity;\n supportedVersions?: readonly number[];\n capabilities?: readonly Capability[];\n providerLimits?: readonly ProviderLimit[];\n retention?: Retention;\n origins?: readonly string[];\n};\n\nexport type MemoryAdapter = Adapter & {\n setRooms(rooms: readonly DiscoveredRoom[]): void;\n script(operation: keyof Adapter, answer: unknown): void;\n};\n\ntype Script<T> = T | (() => T | Promise<T>);\n\nasync function resolveScript<T>(answer: Script<T> | undefined, fallback: () => T | Promise<T>) {\n if (answer === undefined) return fallback();\n return typeof answer === 'function' ? (answer as () => T | Promise<T>)() : answer;\n}\n\nexport function createMemoryAdapter(options: MemoryAdapterOptions = {}): MemoryAdapter {\n let rooms = options.rooms === undefined ? [] : [...options.rooms];\n const mdModel = options.mdModel ?? { identity: 'mdmodel', version: '1.0.0' };\n const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];\n const capabilities = options.capabilities ?? [];\n const providerLimits = options.providerLimits ?? [];\n const retention = options.retention ?? { history: 1, outcome: 1, refreshHorizon: 1 };\n const origins = options.origins ?? ['https://origin.example'];\n const scripts: Partial<Record<keyof Adapter, unknown>> = {};\n\n function discovery(): DiscoverResult {\n return {\n kind: 'discovery',\n supportedVersions,\n mdModel,\n rooms: [...rooms],\n capabilities,\n providerLimits,\n retention,\n origins,\n };\n }\n\n return {\n setRooms(next) {\n rooms = [...next];\n },\n script(operation, answer) {\n if (answer === undefined) delete scripts[operation];\n else scripts[operation] = answer;\n },\n async authorize() {\n return resolveScript<Authorization>(\n scripts.authorize as Script<Authorization> | undefined,\n () => ({}),\n );\n },\n async discover(_authorization: Authorization) {\n return resolveScript<DiscoverResult>(\n scripts.discover as Script<DiscoverResult> | undefined,\n discovery,\n );\n },\n async bootstrap(_authorization: Authorization, request: BootstrapRequest) {\n return resolveScript<BootstrapResult>(\n scripts.bootstrap as Script<BootstrapResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return { kind: 'bootstrap', roomVersion: room.roomVersion };\n },\n );\n },\n async refresh(_authorization: Authorization, request: RefreshRequest) {\n return resolveScript<RefreshResult>(\n scripts.refresh as Script<RefreshResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n if (request.fromRoomVersion === room.roomVersion) {\n return { kind: 'still-current' };\n }\n return { kind: 'net-advancement', roomVersion: room.roomVersion };\n },\n );\n },\n async mutate(_authorization: Authorization, request: MutationRequest) {\n return resolveScript<MutationResult>(\n scripts.mutate as Script<MutationResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return { kind: 'rejected', text: '' };\n },\n );\n },\n async history(_authorization: Authorization, request: HistoryRequest) {\n return resolveScript<HistoryResult>(\n scripts.history as Script<HistoryResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return {\n kind: 'history',\n revisions: [],\n };\n },\n );\n },\n async action(_authorization: Authorization, _request: ActionRequest) {\n return resolveScript<ActionResult>(\n scripts.action as Script<ActionResult> | undefined,\n () => ({\n kind: 'rejected',\n text: '',\n }),\n );\n },\n };\n}\n"],"names":["ROOM_CONTRACT_VERSION","resolveScript","answer","fallback","undefined","createMemoryAdapter","options","rooms","mdModel","identity","version","supportedVersions","capabilities","providerLimits","retention","history","outcome","refreshHorizon","origins","scripts","discovery","kind","setRooms","next","script","operation","authorize","discover","_authorization","bootstrap","request","room","find","entry","locator","roomVersion","refresh","fromRoomVersion","mutate","text","revisions","action","_request"],"mappings":"AAAA,SACEA,qBAAqB,QAmBhB,eAAe;AAmBtB,eAAeC,cAAiBC,MAA6B,EAAEC,QAA8B;IAC3F,IAAID,WAAWE,WAAW,OAAOD;IACjC,OAAO,OAAOD,WAAW,aAAa,AAACA,WAAoCA;AAC7E;AAEA,OAAO,SAASG,oBAAoBC,UAAgC,CAAC,CAAC;IACpE,IAAIC,QAAQD,QAAQC,KAAK,KAAKH,YAAY,EAAE,GAAG;WAAIE,QAAQC,KAAK;KAAC;IACjE,MAAMC,UAAUF,QAAQE,OAAO,IAAI;QAAEC,UAAU;QAAWC,SAAS;IAAQ;IAC3E,MAAMC,oBAAoBL,QAAQK,iBAAiB,IAAI;QAACX;KAAsB;IAC9E,MAAMY,eAAeN,QAAQ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BACpE,IAAIH,SAAS3B,WAAW;oBACtB,OAAO;wBAAEiB,MAAM;wBAAqBa,SAASJ,QAAQI,OAAO;oBAAC;gBAC/D;gBACA,IAAIJ,QAAQO,eAAe,KAAKN,KAAKI,WAAW,EAAE;oBAChD,OAAO;wBAAEd,MAAM;oBAAgB;gBACjC;gBACA,OAAO;oBAAEA,MAAM;oBAAmBc,aAAaJ,KAAKI,WAAW;gBAAC;YAClE;QAEJ;QACA,MAAMG,QAAOV,cAA6B,EAAEE,OAAwB;YAClE,OAAO7B,cACLkB,QAAQmB,MAAM,EACd;gBACE,MAAMP,OAAOxB,MAAMyB,IAAI,CAAC,CAACC,QAAUA,MAAMC,OAAO,KAAKJ,QAAQI,OAAO;gBACpE,IAAIH,SAAS3B,WAAW;oBACtB,OAAO;wBAAEiB,MAAM;wBAAqBa,SAASJ,QAAQI,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBAAEb,MAAM;oBAAYkB,MAAM;gBAAG;YACtC;QAEJ;QACA,MAAMxB,SAAQa,cAA6B,EAAEE,OAAuB;YAClE,OAAO7B,cACLkB,QAAQJ,OAAO,EACf;gBACE,MAAMgB,OAAOxB,MAAMyB,IAAI,CAAC,CAACC,QAAUA,MAAMC,OAAO,KAAKJ,QAAQI,OAAO;gBACpE,IAAIH,SAAS3B,WAAW;oBACtB,OAAO;wBAAEiB,MAAM;wBAAqBa,SAASJ,QAAQI,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBACLb,MAAM;oBACNmB,WAAW,EAAE;gBACf;YACF;QAEJ;QACA,MAAMC,QAAOb,cAA6B,EAAEc,QAAuB;YACjE,OAAOzC,cACLkB,QAAQsB,MAAM,EACd,IAAO,CAAA;oBACLpB,MAAM;oBACNkB,MAAM;gBACR,CAAA;QAEJ;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/memory.ts"],"sourcesContent":["import {\n ROOM_CONTRACT_VERSION,\n type ActionRequest,\n type ActionResult,\n type Adapter,\n type Authorization,\n type BootstrapRequest,\n type BootstrapResult,\n type Capability,\n type DiscoverResult,\n type DiscoveredRoom,\n type HistoryRequest,\n type HistoryResult,\n type MdModelIdentity,\n type MutationRequest,\n type MutationResult,\n type ProviderLimit,\n type RefreshRequest,\n type RefreshResult,\n type Retention,\n} from './adapter.js';\nimport { MD_MODEL } from './collection.js';\n\nexport type MemoryRoom = DiscoveredRoom & {\n documents?: Readonly<Record<string, string>>;\n binaryTargets?: readonly string[];\n};\n\nexport type MemoryAdapterOptions = {\n rooms?: readonly MemoryRoom[];\n pageSize?: number;\n mdModel?: MdModelIdentity;\n supportedVersions?: readonly number[];\n capabilities?: readonly Capability[];\n providerLimits?: readonly ProviderLimit[];\n retention?: Retention;\n origins?: readonly string[];\n};\n\nexport type MemoryAdapter = Adapter & {\n setRooms(rooms: readonly MemoryRoom[]): void;\n script(operation: keyof Adapter, answer: unknown): void;\n};\n\ntype Script<T, R> = T | ((request: R) => T | Promise<T>);\n\nasync function resolveScript<T, R>(\n answer: Script<T, R> | undefined,\n fallback: () => T | Promise<T>,\n request: R,\n) {\n if (answer === undefined) return fallback();\n return typeof answer === 'function' ? (answer as (value: R) => T | Promise<T>)(request) : answer;\n}\n\nexport function createMemoryAdapter(options: MemoryAdapterOptions = {}): MemoryAdapter {\n let rooms = options.rooms === undefined ? [] : [...options.rooms];\n const mdModel = options.mdModel ?? MD_MODEL;\n const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];\n const capabilities = options.capabilities ?? [];\n const providerLimits = options.providerLimits ?? [];\n const retention = options.retention ?? { history: 1, outcome: 1, refreshHorizon: 1 };\n const origins = options.origins ?? ['https://origin.example'];\n const pageSize = options.pageSize;\n const scripts: Partial<Record<keyof Adapter, unknown>> = {};\n\n function declared(room: MemoryRoom): DiscoveredRoom {\n return {\n name: room.name,\n locator: room.locator,\n roomVersion: room.roomVersion,\n writeGrants: room.writeGrants,\n providerOwnedPaths: room.providerOwnedPaths,\n };\n }\n\n function page(room: MemoryRoom, from: number): BootstrapResult {\n const paths = Object.keys(room.documents ?? {}).sort();\n const size = pageSize ?? paths.length;\n const taken = paths.slice(from, from + size);\n const documents: Record<string, string> = {};\n for (const path of taken) documents[path] = (room.documents ?? {})[path];\n const next = from + taken.length;\n return {\n kind: 'bootstrap',\n roomVersion: room.roomVersion,\n documents,\n binaryTargets: from === 0 ? (room.binaryTargets ?? []) : [],\n ...(next < paths.length ? { pageToken: String(next) } : {}),\n };\n }\n\n function discovery(): DiscoverResult {\n return {\n kind: 'discovery',\n supportedVersions,\n mdModel,\n rooms: rooms.map(declared),\n capabilities,\n providerLimits,\n retention,\n origins,\n };\n }\n\n return {\n setRooms(next) {\n rooms = [...next];\n },\n script(operation, answer) {\n if (answer === undefined) delete scripts[operation];\n else scripts[operation] = answer;\n },\n async authorize() {\n return resolveScript<Authorization, void>(\n scripts.authorize as Script<Authorization, void> | undefined,\n () => ({}),\n undefined,\n );\n },\n async discover(_authorization: Authorization) {\n return resolveScript<DiscoverResult, void>(\n scripts.discover as Script<DiscoverResult, void> | undefined,\n discovery,\n undefined,\n );\n },\n async bootstrap(_authorization: Authorization, request: BootstrapRequest) {\n return resolveScript<BootstrapResult, BootstrapRequest>(\n scripts.bootstrap as Script<BootstrapResult, BootstrapRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return page(room, request.pageToken === undefined ? 0 : Number(request.pageToken));\n },\n request,\n );\n },\n async refresh(_authorization: Authorization, request: RefreshRequest) {\n return resolveScript<RefreshResult, RefreshRequest>(\n scripts.refresh as Script<RefreshResult, RefreshRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n if (request.fromRoomVersion === room.roomVersion) {\n return { kind: 'still-current' };\n }\n return { kind: 'net-advancement', roomVersion: room.roomVersion };\n },\n request,\n );\n },\n async mutate(_authorization: Authorization, request: MutationRequest) {\n return resolveScript<MutationResult, MutationRequest>(\n scripts.mutate as Script<MutationResult, MutationRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return { kind: 'rejected', text: '' };\n },\n request,\n );\n },\n async history(_authorization: Authorization, request: HistoryRequest) {\n return resolveScript<HistoryResult, HistoryRequest>(\n scripts.history as Script<HistoryResult, HistoryRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return {\n kind: 'history',\n revisions: [],\n };\n },\n request,\n );\n },\n async action(_authorization: Authorization, request: ActionRequest) {\n return resolveScript<ActionResult, ActionRequest>(\n scripts.action as Script<ActionResult, ActionRequest> | undefined,\n () => ({\n kind: 'rejected',\n text: '',\n }),\n request,\n );\n },\n };\n}\n"],"names":["ROOM_CONTRACT_VERSION","MD_MODEL","resolveScript","answer","fallback","request","undefined","createMemoryAdapter","options","rooms","mdModel","supportedVersions","capabilities","providerLimits","retention","history","outcome","refreshHorizon","origins","pageSize","scripts","declared","room","name","locator","roomVersion","writeGrants","providerOwnedPaths","page","from","paths","Object","keys","documents","sort","size","length","taken","slice","path","next","kind","binaryTargets","pageToken","String","discovery","map","setRooms","script","operation","authorize","discover","_authorization","bootstrap","find","entry","Number","refresh","fromRoomVersion","mutate","text","revisions","action"],"mappings":"AAAA,SACEA,qBAAqB,QAmBhB,eAAe;AACtB,SAASC,QAAQ,QAAQ,kBAAkB;AAyB3C,eAAeC,cACbC,MAAgC,EAChCC,QAA8B,EAC9BC,OAAU;IAEV,IAAIF,WAAWG,WAAW,OAAOF;IACjC,OAAO,OAAOD,WAAW,aAAa,AAACA,OAAwCE,WAAWF;AAC5F;AAEA,OAAO,SAASI,oBAAoBC,UAAgC,CAAC,CAAC;IACpE,IAAIC,QAAQD,QAAQC,KAAK,KAAKH,YAAY,EAAE,GAAG;W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pC,KAAKG,WAAW,EAAE;oBAChD,OAAO;wBAAEgB,MAAM;oBAAgB;gBACjC;gBACA,OAAO;oBAAEA,MAAM;oBAAmBhB,aAAaH,KAAKG,WAAW;gBAAC;YAClE,GACApB;QAEJ;QACA,MAAMsD,QAAOP,cAA6B,EAAE/C,OAAwB;YAClE,OAAOH,cACLkB,QAAQuC,MAAM,EACd;gBACE,MAAMrC,OAAOb,MAAM6C,IAAI,CAAC,CAACC,QAAUA,MAAM/B,OAAO,KAAKnB,QAAQmB,OAAO;gBACpE,IAAIF,SAAShB,WAAW;oBACtB,OAAO;wBAAEmC,MAAM;wBAAqBjB,SAASnB,QAAQmB,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBAAEiB,MAAM;oBAAYmB,MAAM;gBAAG;YACtC,GACAvD;QAEJ;QACA,MAAMU,SAAQqC,cAA6B,EAAE/C,OAAuB;YAClE,OAAOH,cACLkB,QAAQL,OAAO,EACf;gBACE,MAAMO,OAAOb,MAAM6C,IAAI,CAAC,CAACC,QAAUA,MAAM/B,OAAO,KAAKnB,QAAQmB,OAAO;gBACpE,IAAIF,SAAShB,WAAW;oBACtB,OAAO;wBAAEmC,MAAM;wBAAqBjB,SAASnB,QAAQmB,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBACLiB,MAAM;oBACNoB,WAAW,EAAE;gBACf;YACF,GACAxD;QAEJ;QACA,MAAMyD,QAAOV,cAA6B,EAAE/C,OAAsB;YAChE,OAAOH,cACLkB,QAAQ0C,MAAM,EACd,IAAO,CAAA;oBACLrB,MAAM;oBACNmB,MAAM;gBACR,CAAA,GACAvD;QAEJ;IACF;AACF"}
@@ -0,0 +1,16 @@
1
+ export type ReplicaRecord = {
2
+ locator: string;
3
+ name: string;
4
+ writeGrants: readonly string[];
5
+ providerOwnedPaths: readonly string[];
6
+ roomVersion: string;
7
+ documents: Readonly<Record<string, string>>;
8
+ binaryTargets: readonly string[];
9
+ };
10
+ export type ReplicaStore = {
11
+ all(): Promise<readonly ReplicaRecord[]>;
12
+ publish(record: ReplicaRecord): Promise<void>;
13
+ close(): void;
14
+ };
15
+ export declare function openReplicaStore(): Promise<ReplicaStore>;
16
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../src/store.ts"],"names":[],"mappings":"AAIA,MAAM,MAAM,aAAa,GAAG;IAC1B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,SAAS,MAAM,EAAE,CAAC;IAC/B,kBAAkB,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5C,aAAa,EAAE,SAAS,MAAM,EAAE,CAAC;CAClC,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,GAAG,IAAI,OAAO,CAAC,SAAS,aAAa,EAAE,CAAC,CAAC;IACzC,OAAO,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9C,KAAK,IAAI,IAAI,CAAC;CACf,CAAC;AAiBF,wBAAsB,gBAAgB,IAAI,OAAO,CAAC,YAAY,CAAC,CAoB9D"}
package/dist/store.js ADDED
@@ -0,0 +1,41 @@
1
+ const DATABASE = 'mdruntime';
2
+ const REPLICAS = 'replicas';
3
+ const SCHEMA = 1;
4
+ function settled(request) {
5
+ return new Promise((resolve, reject)=>{
6
+ request.onsuccess = ()=>resolve(request.result);
7
+ request.onerror = ()=>reject(request.error);
8
+ });
9
+ }
10
+ function completed(transaction) {
11
+ return new Promise((resolve, reject)=>{
12
+ transaction.oncomplete = ()=>resolve();
13
+ transaction.onerror = ()=>reject(transaction.error);
14
+ transaction.onabort = ()=>reject(transaction.error);
15
+ });
16
+ }
17
+ export async function openReplicaStore() {
18
+ const opening = indexedDB.open(DATABASE, SCHEMA);
19
+ opening.onupgradeneeded = ()=>{
20
+ opening.result.createObjectStore(REPLICAS, {
21
+ keyPath: 'locator'
22
+ });
23
+ };
24
+ const database = await settled(opening);
25
+ return {
26
+ async all () {
27
+ const transaction = database.transaction(REPLICAS, 'readonly');
28
+ return settled(transaction.objectStore(REPLICAS).getAll());
29
+ },
30
+ async publish (record) {
31
+ const transaction = database.transaction(REPLICAS, 'readwrite');
32
+ transaction.objectStore(REPLICAS).put(record);
33
+ await completed(transaction);
34
+ },
35
+ close () {
36
+ database.close();
37
+ }
38
+ };
39
+ }
40
+
41
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/store.ts"],"sourcesContent":["const DATABASE = 'mdruntime';\nconst REPLICAS = 'replicas';\nconst SCHEMA = 1;\n\nexport type ReplicaRecord = {\n locator: string;\n name: string;\n writeGrants: readonly string[];\n providerOwnedPaths: readonly string[];\n roomVersion: string;\n documents: Readonly<Record<string, string>>;\n binaryTargets: readonly string[];\n};\n\nexport type ReplicaStore = {\n all(): Promise<readonly ReplicaRecord[]>;\n publish(record: ReplicaRecord): Promise<void>;\n close(): void;\n};\n\nfunction settled<T>(request: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n}\n\nfunction completed(transaction: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error);\n transaction.onabort = () => reject(transaction.error);\n });\n}\n\nexport async function openReplicaStore(): Promise<ReplicaStore> {\n const opening = indexedDB.open(DATABASE, SCHEMA);\n opening.onupgradeneeded = () => {\n opening.result.createObjectStore(REPLICAS, { keyPath: 'locator' });\n };\n const database = await settled(opening);\n return {\n async all() {\n const transaction = database.transaction(REPLICAS, 'readonly');\n return settled<ReplicaRecord[]>(transaction.objectStore(REPLICAS).getAll());\n },\n async publish(record) {\n const transaction = database.transaction(REPLICAS, 'readwrite');\n transaction.objectStore(REPLICAS).put(record);\n await completed(transaction);\n },\n close() {\n database.close();\n },\n };\n}\n"],"names":["DATABASE","REPLICAS","SCHEMA","settled","request","Promise","resolve","reject","onsuccess","result","onerror","error","completed","transaction","oncomplete","onabort","openReplicaStore","opening","indexedDB","open","onupgradeneeded","createObjectStore","keyPath","database","all","objectStore","getAll","publish","record","put","close"],"mappings":"AAAA,MAAMA,WAAW;AACjB,MAAMC,WAAW;AACjB,MAAMC,SAAS;AAkBf,SAASC,QAAWC,OAAsB;IACxC,OAAO,IAAIC,QAAQ,CAACC,SAASC;QAC3BH,QAAQI,SAAS,GAAG,IAAMF,QAAQF,QAAQK,MAAM;QAChDL,QAAQM,OAAO,GAAG,IAAMH,OAAOH,QAAQO,KAAK;IAC9C;AACF;AAEA,SAASC,UAAUC,WAA2B;IAC5C,OAAO,IAAIR,QAAQ,CAACC,SAASC;QAC3BM,YAAYC,UAAU,GAAG,IAAMR;QAC/BO,YAAYH,OAAO,GAAG,IAAMH,OAAOM,YAAYF,KAAK;QACpDE,YAAYE,OAAO,GAAG,IAAMR,OAAOM,YAAYF,KAAK;IACtD;AACF;AAEA,OAAO,eAAeK;IACpB,MAAMC,UAAUC,UAAUC,IAAI,CAACnB,UAAUE;IACzCe,QAAQG,eAAe,GAAG;QACxBH,QAAQR,MAAM,CAACY,iBAAiB,CAACpB,UAAU;YAAEqB,SAAS;QAAU;IAClE;IACA,MAAMC,WAAW,MAAMpB,QAAQc;IAC/B,OAAO;QACL,MAAMO;YACJ,MAAMX,cAAcU,SAASV,WAAW,CAACZ,UAAU;YACnD,OAAOE,QAAyBU,YAAYY,WAAW,CAACxB,UAAUyB,MAAM;QAC1E;QACA,MAAMC,SAAQC,MAAM;YAClB,MAAMf,cAAcU,SAASV,WAAW,CAACZ,UAAU;YACnDY,YAAYY,WAAW,CAACxB,UAAU4B,GAAG,CAACD;YACtC,MAAMhB,UAAUC;QAClB;QACAiB;YACEP,SAASO,KAAK;QAChB;IACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.2",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -34,5 +34,9 @@
34
34
  "homepage": "https://github.com/agentshouse/mdruntime#readme",
35
35
  "bugs": {
36
36
  "url": "https://github.com/agentshouse/mdruntime/issues"
37
+ },
38
+ "dependencies": {
39
+ "@agentshouse/mdmodel": "0.1.0-alpha.3",
40
+ "@agentshouse/query": "0.1.0-alpha.1"
37
41
  }
38
42
  }