@agentshouse/mdruntime-adapter 0.1.0-c9f1e531ad7c8 → 0.1.0-cacce09fc82c6

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/discovery.js CHANGED
@@ -1,35 +1,7 @@
1
- import { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';
2
- import { PRIVATE_LOCATOR } from './transport.js';
1
+ import { declaredActions, houseConversationAgents } from './actions.js';
3
2
  import { readPosition, roomVersion } from './version.js';
4
- export const ROOM_CONTRACT_VERSION = 1;
5
- export const MD_MODEL_IDENTITY = '@agentshouse/mdmodel';
6
- export const ROOM_VERSION_NOTIFICATIONS = 'room-version-notifications';
7
3
  export const PROVIDER_ACTIONS = 'provider-actions';
8
- export const MOVE_REFERENCE_REWRITES = 'move-reference-rewrites';
9
4
  export const DISCOVER_PREFIXES = ['/'];
10
- export const PROVIDER_SELECTION_ROOTS = [
11
- 'agents',
12
- 'collaboration/routines',
13
- 'house',
14
- 'settings/apps',
15
- 'settings/panel.md',
16
- ];
17
- export const UNTYPED_FOLDERS = ['capture'];
18
- export const RESERVED_NAMES = [
19
- 'ROOM.md',
20
- 'capture',
21
- 'settings',
22
- 'collaboration',
23
- 'rooms',
24
- 'agents',
25
- 'house',
26
- 'work',
27
- 'entities',
28
- 'schema',
29
- 'commitments',
30
- ];
31
- export const HOUSE_SCHEMA = 'house/schema.yaml';
32
- export const PRIVATE_HANDLE = 'private';
33
5
  const BOUND_KEYS = [
34
6
  'max_authored_file_bytes',
35
7
  'max_batch_operations',
@@ -38,6 +10,9 @@ const BOUND_KEYS = [
38
10
  'max_path_depth',
39
11
  'max_mount_files',
40
12
  'max_mount_bytes',
13
+ 'max_inline_body_bytes',
14
+ 'max_upload_bytes',
15
+ 'max_prefixes',
41
16
  'change_retention_seconds',
42
17
  'operation_retention_seconds',
43
18
  ];
@@ -60,6 +35,25 @@ function parseBounds(value) {
60
35
  }
61
36
  return bounds;
62
37
  }
38
+ function parseHouseModel(value) {
39
+ if (value === undefined)
40
+ return null;
41
+ if (typeof value !== 'object' || value === null)
42
+ return undefined;
43
+ const held = value;
44
+ const paths = stringList(held.paths);
45
+ if (typeof held.root !== 'string' || held.root.length === 0 || paths === null)
46
+ return undefined;
47
+ return { root: held.root, paths };
48
+ }
49
+ function parseMember(value) {
50
+ if (typeof value !== 'object' || value === null)
51
+ return null;
52
+ const { user, name } = value;
53
+ if (typeof user !== 'string' || typeof name !== 'string')
54
+ return null;
55
+ return { kind: 'user', id: user, name };
56
+ }
63
57
  function parseOperations(value) {
64
58
  if (typeof value !== 'object' || value === null)
65
59
  return null;
@@ -87,9 +81,10 @@ function parseAuthority(value) {
87
81
  return null;
88
82
  }
89
83
  const at = readPosition(held);
84
+ const houseModel = parseHouseModel(held.house_model);
90
85
  const protectedPaths = stringList(held.protected_paths);
91
86
  const operations = parseOperations(held.operations);
92
- if (at === null || protectedPaths === null || operations === null)
87
+ if (at === null || houseModel === undefined || protectedPaths === null || operations === null)
93
88
  return null;
94
89
  if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
95
90
  return null;
@@ -100,6 +95,7 @@ function parseAuthority(value) {
100
95
  roomHandle: held.room_handle,
101
96
  name: held.name,
102
97
  schema: held.model_root,
98
+ houseModel,
103
99
  managedReplication: held.managed_replication,
104
100
  protectedPaths,
105
101
  operations,
@@ -110,11 +106,12 @@ export function parseDiscovery(body) {
110
106
  if (typeof body !== 'object' || body === null)
111
107
  return null;
112
108
  const held = body;
109
+ const member = parseMember(held.member);
110
+ if (member === null)
111
+ return null;
113
112
  const bounds = parseBounds(held.bounds);
114
113
  if (bounds === null)
115
114
  return null;
116
- if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0)
117
- return null;
118
115
  const actions = stringList(held.actions);
119
116
  if (actions === null ||
120
117
  new Set(actions).size !== actions.length ||
@@ -129,34 +126,7 @@ export function parseDiscovery(body) {
129
126
  return null;
130
127
  authorities.push(authority);
131
128
  }
132
- return { bounds, mdModelVersion: held.md_model_version, authorities, actions };
133
- }
134
- function parseSiteEntry(value) {
135
- if (typeof value !== 'object' || value === null)
136
- return null;
137
- const held = value;
138
- if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
139
- return null;
140
- if (typeof held.segment !== 'string' || held.segment.length === 0)
141
- return null;
142
- return { roomRef: held.room_ref, segment: held.segment };
143
- }
144
- function parseSiteSlot(value) {
145
- if (typeof value !== 'object' || value === null)
146
- return null;
147
- const held = value;
148
- if (typeof held.slot !== 'string' || held.slot.length === 0)
149
- return null;
150
- if (!Array.isArray(held.entries))
151
- return null;
152
- const entries = [];
153
- for (const entry of held.entries) {
154
- const parsed = parseSiteEntry(entry);
155
- if (parsed === null)
156
- return null;
157
- entries.push(parsed);
158
- }
159
- return { slot: held.slot, entries };
129
+ return { member, bounds, authorities, actions };
160
130
  }
161
131
  function parseSiteAuthority(value) {
162
132
  if (typeof value !== 'object' || value === null)
@@ -187,17 +157,8 @@ export function parseSiteDiscovery(body) {
187
157
  const bounds = parseBounds(held.bounds);
188
158
  if (bounds === null)
189
159
  return null;
190
- if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0)
191
- return null;
192
- if (!Array.isArray(held.slots) || !Array.isArray(held.authorities))
160
+ if (!Array.isArray(held.authorities))
193
161
  return null;
194
- const slots = [];
195
- for (const entry of held.slots) {
196
- const slot = parseSiteSlot(entry);
197
- if (slot === null)
198
- return null;
199
- slots.push(slot);
200
- }
201
162
  const authorities = [];
202
163
  for (const entry of held.authorities) {
203
164
  const authority = parseSiteAuthority(entry);
@@ -205,7 +166,7 @@ export function parseSiteDiscovery(body) {
205
166
  return null;
206
167
  authorities.push(authority);
207
168
  }
208
- return { bounds, mdModelVersion: held.md_model_version, slots, authorities };
169
+ return { bounds, authorities };
209
170
  }
210
171
  export function siteTracked(document) {
211
172
  return document.authorities.map((authority) => ({
@@ -213,31 +174,24 @@ export function siteTracked(document) {
213
174
  authority: authority.roomRef,
214
175
  handle: authority.roomHandle,
215
176
  schema: authority.schema,
177
+ houseModel: null,
216
178
  schemas: [authority.schema],
217
179
  position: authority.position,
218
180
  logEpoch: authority.logEpoch,
219
181
  }));
220
182
  }
221
- export function siteSlots(document) {
222
- return document.slots.map(({ slot, entries }) => ({
223
- slot,
224
- entries: entries.map(({ roomRef, segment }) => ({ locator: roomRef, segment })),
225
- }));
226
- }
227
- export function locatorOf(authority) {
228
- return authority.roomHandle === PRIVATE_HANDLE ? PRIVATE_LOCATOR : authority.roomRef;
229
- }
230
183
  function schemasOf(authority) {
231
- return authority.roomHandle === PRIVATE_HANDLE
232
- ? [authority.schema, HOUSE_SCHEMA]
233
- : [authority.schema];
184
+ return authority.houseModel === null
185
+ ? [authority.schema]
186
+ : [authority.schema, authority.houseModel.root];
234
187
  }
235
188
  export function trackedFrom(document) {
236
189
  return document.authorities.map((authority) => ({
237
- locator: locatorOf(authority),
190
+ locator: authority.roomRef,
238
191
  authority: authority.roomRef,
239
192
  handle: authority.roomHandle,
240
193
  schema: authority.schema,
194
+ houseModel: authority.houseModel,
241
195
  schemas: schemasOf(authority),
242
196
  position: authority.position,
243
197
  logEpoch: authority.logEpoch,
@@ -261,30 +215,29 @@ export function declaredRetention(bounds) {
261
215
  refreshHorizon: bounds.change_retention_seconds,
262
216
  };
263
217
  }
264
- export function capabilities(actions) {
218
+ export function capabilities(document) {
219
+ const house = document.authorities.find((authority) => authority.houseModel !== null);
265
220
  return [
266
- { name: ROOM_VERSION_NOTIFICATIONS },
267
221
  {
268
222
  name: PROVIDER_ACTIONS,
269
- actions: declaredActions(actions),
270
- conversationCards: HOUSE_CONVERSATION_CARDS,
223
+ actions: declaredActions(document.actions),
224
+ ...(house === undefined
225
+ ? {}
226
+ : { conversationAgents: houseConversationAgents(house.roomRef) }),
271
227
  },
272
- { name: MOVE_REFERENCE_REWRITES },
273
228
  ];
274
229
  }
275
230
  export function siteCapabilities() {
276
231
  return [
277
- { name: ROOM_VERSION_NOTIFICATIONS },
278
232
  { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },
279
233
  ];
280
234
  }
281
- export function providerSelection(attachedModel) {
282
- return { roots: [...PROVIDER_SELECTION_ROOTS], attachedModel };
283
- }
284
- export function discoveredRoom(authority, attachedModel, typedSelection) {
235
+ export function discoveredRoom(authority) {
236
+ const locator = authority.roomRef;
285
237
  return {
286
238
  name: authority.name,
287
- locator: locatorOf(authority),
239
+ locator,
240
+ handle: authority.roomHandle,
288
241
  roomVersion: roomVersion(authority),
289
242
  operations: {
290
243
  read: [...authority.operations.read],
@@ -292,18 +245,16 @@ export function discoveredRoom(authority, attachedModel, typedSelection) {
292
245
  write: [...authority.operations.write],
293
246
  delete: [...authority.operations.delete],
294
247
  },
295
- replica: { selection: locatorOf(authority), admission: authority.managedReplication },
296
- attachedModel,
297
- ...(typedSelection === undefined ? {} : { typedSelection }),
298
- untypedFolders: [...UNTYPED_FOLDERS],
248
+ replica: { selection: locator, admission: authority.managedReplication },
249
+ ...(authority.houseModel === null
250
+ ? {}
251
+ : { typedSelection: { roots: [...authority.houseModel.paths] } }),
299
252
  providerOwnedPaths: [...authority.protectedPaths, ...schemasOf(authority)],
300
253
  };
301
254
  }
302
255
  export function mapDiscovery(document, rooms, declared) {
303
256
  return {
304
257
  kind: 'discovery',
305
- supportedVersions: [ROOM_CONTRACT_VERSION],
306
- mdModel: { identity: MD_MODEL_IDENTITY, version: document.mdModelVersion },
307
258
  rooms,
308
259
  capabilities: declared,
309
260
  providerLimits: providerLimits(document.bounds),
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
1
  export { createAgentsHouseAdapter, type AgentsHouseAdapterOptions } from './adapter.js';
2
- export { nativePath, roomLocalPath } from './map.js';
3
- export type { HouseByteAct, HouseByteAnswer, HouseByteTransfer, HouseDoorAnswer, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
2
+ export type { HouseByteAct, HouseByteAnswer, HouseByteTransfer, HouseDoorAnswer, HouseHeldRoom, HouseOpening, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
4
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACrD,YAAY,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,KAAK,yBAAyB,EAAE,MAAM,cAAc,CAAC;AACxF,YAAY,EACV,YAAY,EACZ,eAAe,EACf,iBAAiB,EACjB,eAAe,EACf,aAAa,EACb,YAAY,EACZ,WAAW,EACX,gBAAgB,EAChB,gBAAgB,EAChB,kBAAkB,EAClB,cAAc,GACf,MAAM,gBAAgB,CAAC"}
package/dist/index.js CHANGED
@@ -1,2 +1 @@
1
1
  export { createAgentsHouseAdapter } from './adapter.js';
2
- export { nativePath, roomLocalPath } from './map.js';
package/dist/links.d.ts CHANGED
@@ -1,12 +1,20 @@
1
+ import type { HeldRoom, MutationResult, RoomAttachment } from '@agentshouse/mdruntime';
1
2
  import type { HouseScope, HouseView } from './read.js';
2
3
  import type { StreamedAdvancement } from './stream.js';
3
4
  export type RoomLinks = {
4
5
  roomVersion: string;
5
- handed: ReadonlySet<string>;
6
+ handed: ReadonlyMap<string, RoomAttachment>;
6
7
  paths: ReadonlyMap<string, ReadonlySet<string>>;
7
8
  revisions: ReadonlyMap<string, string>;
8
9
  };
9
10
  export declare function scopeLinks(scope: HouseScope): RoomLinks;
11
+ export declare function heldLinks(held: HeldRoom): RoomLinks;
12
+ export declare function acceptedLinks(held: RoomLinks, accepted: Extract<MutationResult, {
13
+ kind: 'accepted';
14
+ }>, roomVersion: string, originals: readonly RoomAttachment[]): {
15
+ links: RoomLinks;
16
+ attachments?: readonly RoomAttachment[];
17
+ };
10
18
  export declare function enumeratedLinks(view: HouseView, earlier: RoomLinks | undefined): RoomLinks;
11
19
  export declare function streamedLinks(held: RoomLinks, advanced: StreamedAdvancement): RoomLinks | null;
12
20
  //# sourceMappingURL=links.d.ts.map
@@ -1 +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;IAChD,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAYF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAWvD;AAOD,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAgB1F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAoB9F"}
1
+ {"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvF,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,EAAE,cAAc,CAAC,CAAC;IAC5C,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAcF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAWvD;AAOD,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAOnD;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACvD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,SAAS,cAAc,EAAE,GACnC;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,CA2B/D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAgB1F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAoB9F"}
package/dist/links.js CHANGED
@@ -8,7 +8,7 @@ function linkedBy(text) {
8
8
  return references.size === 0 ? NONE : references;
9
9
  }
10
10
  function handedOf(attachments) {
11
- return new Set((attachments ?? []).map((attachment) => attachment.reference));
11
+ return new Map((attachments ?? []).map((attachment) => [attachment.reference, attachment]));
12
12
  }
13
13
  export function scopeLinks(scope) {
14
14
  return {
@@ -24,6 +24,44 @@ function revised(revisions, path, revision) {
24
24
  else
25
25
  revisions.set(path, revision);
26
26
  }
27
+ export function heldLinks(held) {
28
+ return {
29
+ roomVersion: held.roomVersion,
30
+ handed: handedOf(held.attachments),
31
+ paths: new Map(Object.entries(held.documents).map(([path, text]) => [path, linkedBy(text)])),
32
+ revisions: new Map(Object.entries(held.revisions)),
33
+ };
34
+ }
35
+ export function acceptedLinks(held, accepted, roomVersion, originals) {
36
+ const paths = new Map(held.paths);
37
+ const revisions = new Map(held.revisions);
38
+ const handed = new Map(held.handed);
39
+ const answered = handedOf(originals);
40
+ for (const [path, text] of Object.entries(accepted.documents)) {
41
+ const linked = linkedBy(text);
42
+ for (const reference of linked) {
43
+ const original = answered.get(reference);
44
+ if (!handed.has(reference) && original !== undefined)
45
+ handed.set(reference, original);
46
+ }
47
+ paths.set(path, linked);
48
+ }
49
+ for (const [path, revision] of Object.entries(accepted.revisions))
50
+ revisions.set(path, revision);
51
+ for (const path of accepted.removals) {
52
+ paths.delete(path);
53
+ revisions.delete(path);
54
+ }
55
+ const linked = new Set([...paths.values()].flatMap((references) => [...references]));
56
+ for (const reference of held.handed.keys()) {
57
+ const before = [...held.paths.values()].some((references) => references.has(reference));
58
+ if (before && !linked.has(reference))
59
+ handed.delete(reference);
60
+ }
61
+ const links = { roomVersion, handed, paths, revisions };
62
+ const changed = handed.size !== held.handed.size || [...handed.keys()].some((key) => !held.handed.has(key));
63
+ return changed ? { links, attachments: [...handed.values()] } : { links };
64
+ }
27
65
  export function enumeratedLinks(view, earlier) {
28
66
  const paths = new Map(earlier?.paths);
29
67
  const revisions = new Map(earlier?.revisions);
@@ -50,7 +88,7 @@ export function streamedLinks(held, advanced) {
50
88
  for (const reference of linked)
51
89
  if (!held.handed.has(reference))
52
90
  return null;
53
- for (const reference of paths.get(entry.path) ?? held.handed) {
91
+ for (const reference of paths.get(entry.path) ?? held.handed.keys()) {
54
92
  if (held.handed.has(reference) && !linked.has(reference))
55
93
  dropped.add(reference);
56
94
  }
package/dist/model.d.ts CHANGED
@@ -1,19 +1,8 @@
1
- import type { AdapterFailure, ModelIdentity, ModelRequest, ModelResult } from '@agentshouse/mdruntime';
2
- import type { HouseSchema } from './read.js';
3
- export type HeldModel = {
4
- snapshot: ModelResult;
5
- identity: ModelIdentity | null;
6
- };
7
- export declare const MODEL_ABSENT: ModelResult;
8
- export declare function failedModel(failure: AdapterFailure | {
9
- kind: 'beyond-horizon';
10
- }): ModelResult;
11
- export declare function modelKey(locator: string, attached: ModelRequest['attached']): string;
12
- export declare function heldModel(read: HouseSchema | null, identity: string, failure: ModelResult): Promise<HeldModel>;
13
- export type ModelShelf = {
14
- retain(key: string, acquired: HeldModel | undefined): HeldModel | undefined;
15
- answer(request: ModelRequest): ModelResult;
16
- keep(locators: readonly string[]): void;
17
- };
18
- export declare function modelShelf(): ModelShelf;
1
+ import type { RoomModels } from '@agentshouse/mdruntime';
2
+ import type { TrackedAuthority } from './discovery.js';
3
+ import { type HouseScope, type HouseView } from './read.js';
4
+ import type { HouseMode, HouseStreamEntry } from './transport.js';
5
+ export declare function scopeModels(scope: HouseScope, tracked: TrackedAuthority): Promise<RoomModels | undefined>;
6
+ export declare function viewModels(view: HouseView, tracked: TrackedAuthority): Promise<RoomModels | undefined>;
7
+ export declare function streamedModels(schemas: ReadonlyMap<string, HouseStreamEntry>, tracked: TrackedAuthority, mode: HouseMode): Promise<RoomModels | undefined>;
19
8
  //# sourceMappingURL=model.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,YAAY,EACZ,WAAW,EACZ,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAE7C,MAAM,MAAM,SAAS,GAAG;IAAE,QAAQ,EAAE,WAAW,CAAC;IAAC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CACxB,IAAI,EAAE,SAAS,EACf,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAcjC;AAED,wBAAgB,cAAc,CAC5B,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,EAC9C,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,SAAS,GACd,OAAO,CAAC,UAAU,GAAG,SAAS,CAAC,CAWjC"}
package/dist/model.js CHANGED
@@ -1,46 +1,63 @@
1
1
  import { sha256Hex } from './digest.js';
2
- export const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
3
- export function failedModel(failure) {
4
- if (failure.kind === 'revoked-authorization')
5
- return { kind: 'revoked-authorization' };
6
- if (failure.kind === 'transport-uncertainty')
7
- return { kind: 'transport-uncertainty' };
8
- return MODEL_ABSENT;
9
- }
10
- export function modelKey(locator, attached) {
11
- return `${locator} ${attached}`;
12
- }
13
- export async function heldModel(read, identity, failure) {
2
+ import { schemaOf, schemaPath } from './read.js';
3
+ const MODEL_ABSENT = { kind: 'model-unavailable', reason: 'not-readable' };
4
+ const ABSENT_SCHEMA = { schema: null, version: null, revision: null };
5
+ async function heldModel(read, identity) {
14
6
  if (read === null)
15
- return { snapshot: failure, identity: null };
7
+ return MODEL_ABSENT;
16
8
  const version = await sha256Hex(JSON.stringify(read.version));
17
9
  return {
18
- snapshot: { kind: 'model', snapshot: { identity, version, schema: read.schema } },
19
- identity: { identity, version },
10
+ kind: 'model',
11
+ snapshot: { identity, version, schema: read.schema, revision: read.revision },
20
12
  };
21
13
  }
22
- export function modelShelf() {
23
- const models = new Map();
24
- return {
25
- retain(key, acquired) {
26
- if (acquired === undefined)
27
- return models.get(key);
28
- if (acquired.snapshot.kind === 'transport-uncertainty') {
29
- const previous = models.get(key);
30
- if (previous !== undefined && previous.identity !== null)
31
- return previous;
32
- }
33
- models.set(key, acquired);
34
- return acquired;
35
- },
36
- answer(request) {
37
- return models.get(modelKey(request.locator, request.attached))?.snapshot ?? MODEL_ABSENT;
38
- },
39
- keep(locators) {
40
- for (const key of [...models.keys()]) {
41
- if (!locators.some((locator) => key.startsWith(`${locator} `)))
42
- models.delete(key);
43
- }
44
- },
45
- };
14
+ async function modelsOf(tracked, read) {
15
+ const models = {};
16
+ const collection = read(tracked.schema);
17
+ if (collection !== undefined) {
18
+ models.collection = await heldModel(collection, schemaPath(tracked.handle, tracked.schema));
19
+ }
20
+ if (tracked.houseModel !== null) {
21
+ const root = tracked.houseModel.root;
22
+ const selection = read(root);
23
+ if (selection !== undefined) {
24
+ models.selection = await heldModel(selection, schemaPath(tracked.handle, root));
25
+ }
26
+ }
27
+ return models.collection === undefined && models.selection === undefined ? undefined : models;
28
+ }
29
+ export function scopeModels(scope, tracked) {
30
+ return modelsOf(tracked, (schema) => schemaOf(scope, schema));
31
+ }
32
+ export function viewModels(view, tracked) {
33
+ return modelsOf(tracked, (schema) => {
34
+ const change = view.changes.find((candidate) => candidate.path === schema);
35
+ if (change === undefined)
36
+ return undefined;
37
+ if ('removed' in change)
38
+ return ABSENT_SCHEMA;
39
+ if ('content' in change) {
40
+ return {
41
+ schema: change.content,
42
+ version: change.version,
43
+ revision: change.revision ?? null,
44
+ };
45
+ }
46
+ return null;
47
+ });
48
+ }
49
+ export function streamedModels(schemas, tracked, mode) {
50
+ return modelsOf(tracked, (schema) => {
51
+ const entry = schemas.get(schema);
52
+ if (entry === undefined)
53
+ return undefined;
54
+ if (entry.kind === 'removed')
55
+ return ABSENT_SCHEMA;
56
+ if (entry.text === undefined)
57
+ return null;
58
+ const version = mode === 'site' ? entry.sha256 : entry.revision;
59
+ return version === undefined
60
+ ? null
61
+ : { schema: entry.text, version, revision: mode === 'site' ? null : version };
62
+ });
46
63
  }
package/dist/read.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { BootstrapPage, RefreshResult, RoomAttachment } from '@agentshouse/mdruntime';
2
- import { type TrackedAuthority } from './discovery.js';
2
+ import type { TrackedAuthority } from './discovery.js';
3
3
  import type { HouseMode } from './transport.js';
4
4
  import { type LogPosition } from './version.js';
5
5
  export type HeadChange = BootstrapPage['changes'][string];
@@ -61,19 +61,19 @@ export declare function headChange(held: {
61
61
  readonly author?: unknown;
62
62
  readonly created_at?: unknown;
63
63
  }): HeadChange | undefined | null;
64
+ export declare function parseOriginals(value: unknown): readonly RoomAttachment[] | null;
64
65
  export declare function parseEnvelope(body: unknown): HouseEnvelope | null;
65
66
  export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
66
67
  export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
67
68
  export declare function advancedScope(scope: HouseScope, view: HouseView): HouseScope;
68
69
  export declare function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean;
69
- export declare function selects(tracked: TrackedAuthority, path: string): boolean;
70
- export declare function bootstrapOf(scope: HouseScope, tracked: TrackedAuthority): BootstrapPage;
70
+ export declare function bootstrapOf(scope: HouseScope): BootstrapPage;
71
71
  export type HouseSchema = {
72
72
  schema: string | null;
73
73
  version: string | null;
74
+ revision: string | null;
74
75
  };
75
- export declare function schemaFrom(envelope: HouseEnvelope, tracked: TrackedAuthority, schema: string): HouseSchema | null;
76
76
  export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
77
77
  export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
78
- export declare function refreshFrom(view: HouseView, tracked: TrackedAuthority, fromRoomVersion: string): RefreshResult;
78
+ export declare function refreshFrom(view: HouseView, fromRoomVersion: string): RefreshResult;
79
79
  //# sourceMappingURL=read.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EAEb,aAAa,EACb,cAAc,EACf,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAKL,KAAK,gBAAgB,EACtB,MAAM,gBAAgB,CAAC;AACxB,OAAO,KAAK,EAAE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