@agentshouse/mdruntime-adapter 0.1.0-c506c7d6e6199 → 0.1.0-c5b15f4efd6f3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -12,6 +12,14 @@ the reported persistence answer, reauthorization, conversation, the chat draft,
12
12
  and Presentation State. Sync Status, the Service Mode, the storage-loss
13
13
  statement and the deployment facts are observations only.
14
14
 
15
+ The host attaches each port with its reach, and every member and observation
16
+ answers within it: a Room outside it answers as one the replica does not hold, a
17
+ Room reached for single Documents shows only those Documents, the Types of the
18
+ models that govern them and no attachments, and without conversations the
19
+ conversation members, the chat draft and the conversation observation hold none.
20
+ A change of the reach reaches every open observation as its new value, a query
21
+ keeping every unchanged Document the same object.
22
+
15
23
  Every `observe` resolves, once its first value has arrived, to a handle:
16
24
  `current()` is the latest complete value, `subscribe(listener)` hears each later
17
25
  value whole and returns its unsubscribe, and `close()` ends the observation.
@@ -22,11 +30,10 @@ Each conversation a Provider card names is held complete in the browser.
22
30
  Observe one with `observe('conversation', id, { limit })`: the view
23
31
  holds its latest `limit` messages, or all of them, oldest first, its chat
24
32
  draft, and what the Provider streams for it whether or not anything views it:
25
- the growing text and plan of the running turn, the open questions, the process
26
- state, the CLI's commands and options, and the latest `workingNote`. These live
27
- only in memory: the turn's accepted message replaces its growing text and plan,
28
- a working note is never part of a message, and none of them is stored or
29
- searchable.
33
+ the running `turn` with its message parts and its context in use and window, the
34
+ open questions, the process state, and the CLI's commands and options. These live
35
+ only in memory: the message accepted under the turn's id replaces the running turn,
36
+ and none of them is stored or searchable.
30
37
  `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
31
38
  sending it is a Provider Action that needs the Provider reachable and is never
32
39
  queued.
@@ -111,7 +118,7 @@ search.
111
118
 
112
119
  - **What is found.** A Document by its field values, its sections' headings and
113
120
  text, its preamble and its Path; a message by its text. Frontmatter keys, Room
114
- Drafts, chat drafts and growing text are never found. There are no phrases,
121
+ Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
115
122
  word forms, typo tolerance or prefix matching.
116
123
  - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
117
124
  `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
@@ -194,13 +201,15 @@ an App's override respected. What an App Creator's agent adds carries none
194
201
  of these promises by itself. Reading, querying and searching never wait for
195
202
  the network. Data lives only in the App Creator's browser and with the Provider.
196
203
 
197
- ## App code imports only the client entry and never constructs a Runtime
204
+ ## App code takes the client its host hands it and never constructs a Runtime
198
205
 
199
- App code imports only `@agentshouse/mdruntime/client` and calls
200
- `connectMdRuntime` on the port the host hands it. It never constructs a
201
- Runtime. It does not import the package main, the host entry, or the Adapter
202
- package, and it does not call `serveMdRuntime`. Hosts
203
- and tests use those entries; the served App does not.
206
+ App code takes the client its host hands it: in House,
207
+ `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
208
+ client House built into the page. It never constructs a Runtime or a client.
209
+ It imports only types from `@agentshouse/mdruntime/client`, does not call
210
+ `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
211
+ the host entry, or the Adapter package. Hosts and tests use those entries; the
212
+ served App does not.
204
213
 
205
214
  ## What an agent must never do
206
215
 
package/README.md CHANGED
@@ -19,12 +19,12 @@ import { serveMdRuntime } from '@agentshouse/mdruntime/host';
19
19
  import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
20
20
 
21
21
  const adapter = createAgentsHouseAdapter({ transport, authorize });
22
- const host = serveMdRuntime({ adapter, shell, requiredGuarantees: [] });
22
+ const host = serveMdRuntime({ adapter, shell });
23
23
  host.attach(port, 'my-app');
24
24
  ```
25
25
 
26
- App code never imports this package; it reaches the Runtime only through
27
- `@agentshouse/mdruntime/client`. The rules an App's agent follows are in the
26
+ App code never imports this package; it reaches the Runtime only through the
27
+ client its host hands it. The rules an App's agent follows are in the
28
28
  package's `AGENTS.md`.
29
29
 
30
30
  ## License
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAad,MAAM,wBAAwB,CAAC;AAyChC,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA2ZpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAWd,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAyBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAsBjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0WpF"}
package/dist/adapter.js CHANGED
@@ -1,26 +1,20 @@
1
- import { DISCOVER_PREFIXES, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
2
- import { MODEL_ABSENT, failedModel, heldModel, modelKey, modelShelf, } from './model.js';
1
+ import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
2
+ import { scopeModels, streamedModels, viewModels } from './model.js';
3
3
  import { gathered, selections } from './gather.js';
4
4
  import { createSiteAdapter } from './site.js';
5
- import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, schemaFrom, schemaPath, viewOf, } from './read.js';
6
- import { enumeratedLinks, scopeLinks, streamedLinks } from './links.js';
5
+ import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, } from './read.js';
6
+ import { acceptedLinks, enumeratedLinks, heldLinks, scopeLinks, streamedLinks, } from './links.js';
7
7
  import { houseAction } from './actions.js';
8
8
  import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
9
9
  import { houseNotifications } from './stream.js';
10
10
  import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, PRIVATE_LOCATOR, } from './transport.js';
11
11
  import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
12
- import { logPosition, presented, reachedVersion, roomVersion, } from './version.js';
12
+ import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
13
13
  const UNCERTAIN = { kind: 'transport-uncertainty' };
14
14
  const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
15
15
  function lapsedGrant(outcome) {
16
16
  return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
17
17
  }
18
- function modelFailure(classified, envelope) {
19
- if (classified === null) {
20
- return envelope === null ? { kind: 'transport-uncertainty' } : MODEL_ABSENT;
21
- }
22
- return failedModel(classified);
23
- }
24
18
  export function createAgentsHouseAdapter(options) {
25
19
  if ('site' in options)
26
20
  return createSiteAdapter(options.site);
@@ -28,80 +22,75 @@ export function createAgentsHouseAdapter(options) {
28
22
  const notifications = houseNotifications(transport, 'credential');
29
23
  const tracked = new Map();
30
24
  const handed = new Map();
31
- const models = modelShelf();
32
25
  let bounds;
33
26
  function declared() {
34
27
  if (bounds === undefined)
35
28
  throw new Error('no Discovery declared the bounds');
36
29
  return bounds;
37
30
  }
38
- function bootstrappedRoom(envelope, entry) {
31
+ async function bootstrappedRoom(envelope, entry) {
39
32
  const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
40
33
  if (scope === undefined)
41
34
  return { kind: 'room-not-readable', locator: entry.locator };
42
35
  handed.set(entry.locator, scopeLinks(scope));
43
- notifications.hold(entry.authority, scope);
44
- return bootstrapOf(scope);
36
+ notifications.reach(entry.authority, scope);
37
+ const models = await scopeModels(scope, entry);
38
+ return { ...bootstrapOf(scope), ...(models === undefined ? {} : { models }) };
45
39
  }
46
- function enumeratedRoom(enumeration, ask) {
40
+ async function enumeratedRoom(enumeration, ask) {
47
41
  const view = viewOf(enumeration, ask.entry);
48
42
  if (view === undefined)
49
43
  return { kind: 'room-not-readable', locator: ask.entry.locator };
50
- notifications.hold(ask.entry.authority, view);
44
+ notifications.reach(ask.entry.authority, view);
51
45
  const answer = refreshFrom(view, ask.fromRoomVersion);
52
- if (answer.kind === 'net-advancement') {
53
- handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
54
- }
55
- return answer;
46
+ if (answer.kind !== 'net-advancement')
47
+ return answer;
48
+ handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
49
+ const models = await viewModels(view, ask.entry);
50
+ return models === undefined ? answer : { ...answer, models };
56
51
  }
57
- function streamed(entry, request, from) {
52
+ async function streamed(entry, request, from) {
58
53
  const links = handed.get(entry.locator);
59
54
  if (links?.roomVersion !== request.fromRoomVersion)
60
55
  return null;
61
56
  const advanced = notifications.advance(entry, from, (path, revision) => links.revisions.get(path) === revision);
62
57
  if (advanced === null)
63
58
  return null;
64
- if (request.minPosition !== undefined &&
65
- !reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch))
66
- return null;
67
59
  const relinked = streamedLinks(links, advanced);
68
60
  if (relinked === null)
69
61
  return null;
70
62
  handed.set(entry.locator, relinked);
71
- return advanced.page;
63
+ const models = await streamedModels(advanced.schemas, entry, 'credential');
64
+ return models === undefined ? advanced.page : { ...advanced.page, models };
72
65
  }
73
- function held(envelope, entry, schema, failure) {
74
- return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
75
- }
76
- function modelPrefixes(entry) {
77
- return entry.schemas.map((schema) => schemaPath(entry.handle, schema));
78
- }
79
- async function acquireModels(entries) {
80
- const acquired = new Map();
81
- for (const part of selections(entries, (entry) => modelPrefixes(entry).length, declared().max_prefixes)) {
82
- const answer = await transport.door(DOOR_BOOTSTRAP, {
83
- prefixes: part.flatMap((entry) => modelPrefixes(entry)),
84
- });
85
- const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
86
- const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
87
- const failure = modelFailure(classified, envelope);
88
- for (const entry of part) {
89
- acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
90
- if (entry.houseModel === null)
91
- continue;
92
- acquired.set(modelKey(entry.locator, 'typed-selection'), await held(envelope, entry, entry.houseModel.root, failure));
93
- }
94
- }
95
- return acquired;
66
+ function held(rooms) {
67
+ const kept = rooms.flatMap((room) => {
68
+ const entry = tracked.get(room.locator);
69
+ const at = logPosition(room.roomVersion);
70
+ if (entry === undefined || at === null)
71
+ return [];
72
+ handed.set(room.locator, heldLinks(room));
73
+ notifications.reach(entry.authority, at);
74
+ return [presented(entry.authority, at)];
75
+ });
76
+ notifications.send(kept);
96
77
  }
97
- function roomOf(authority, acquired) {
98
- const locator = locatorOf(authority);
99
- const key = modelKey(locator, 'collection');
100
- const collection = models.retain(key, acquired.get(key));
101
- const selection = authority.houseModel === null
102
- ? undefined
103
- : models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
104
- return discoveredRoom(authority, collection?.identity ?? null, selection?.identity ?? null);
78
+ function adopted(entry, outcome) {
79
+ if (outcome.kind !== 'accepted')
80
+ return outcome;
81
+ const { originals, ...accepted } = outcome;
82
+ const links = handed.get(entry.locator);
83
+ if (links === undefined)
84
+ return accepted;
85
+ const follows = followsVersion(links.roomVersion, accepted.roomVersion);
86
+ const relinked = acceptedLinks(links, accepted, follows ? accepted.roomVersion : links.roomVersion, originals);
87
+ handed.set(entry.locator, relinked.links);
88
+ const at = logPosition(accepted.roomVersion);
89
+ if (follows && at !== null)
90
+ notifications.reach(entry.authority, at);
91
+ return relinked.attachments === undefined
92
+ ? accepted
93
+ : { ...accepted, attachments: relinked.attachments };
105
94
  }
106
95
  function authorityFor(locator) {
107
96
  return tracked.get(locator);
@@ -147,14 +136,14 @@ export function createAgentsHouseAdapter(options) {
147
136
  });
148
137
  const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
149
138
  const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
150
- part.forEach((entry, index) => {
139
+ for (const [index, entry] of part.entries()) {
151
140
  const failure = classified[index];
152
141
  if (failure === null || failure === undefined) {
153
- answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
154
- return;
142
+ answers.push(envelope === null ? UNCERTAIN_READ : await bootstrappedRoom(envelope, entry));
143
+ continue;
155
144
  }
156
145
  answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
157
- });
146
+ }
158
147
  }
159
148
  return answers;
160
149
  }
@@ -176,23 +165,8 @@ export function createAgentsHouseAdapter(options) {
176
165
  while (open.length > 0) {
177
166
  const answer = await transport.door(DOOR_ENUMERATE, {
178
167
  prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
179
- positions: open.map((ask) => ({
180
- ...presented(ask.entry.authority, ask.from),
181
- ...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
182
- })),
168
+ positions: open.map((ask) => presented(ask.entry.authority, ask.from)),
183
169
  });
184
- const refusal = doorRefusal(answer.body);
185
- if (refusal?.code === 'replica_behind') {
186
- const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
187
- const behind = named.length === 0 ? open : named;
188
- for (const ask of behind) {
189
- answers.set(ask, refusal.retryable
190
- ? { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields }
191
- : (classifyDoor(answer.status, answer.body, ask.entry.locator) ?? UNCERTAIN_READ));
192
- }
193
- open = open.filter((ask) => !behind.includes(ask));
194
- continue;
195
- }
196
170
  const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
197
171
  if (classified[0]?.kind === 'beyond-horizon') {
198
172
  const named = doorRefusal(answer.body)?.fields.authority;
@@ -205,14 +179,14 @@ export function createAgentsHouseAdapter(options) {
205
179
  continue;
206
180
  }
207
181
  const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
208
- open.forEach((ask, index) => {
182
+ for (const [index, ask] of open.entries()) {
209
183
  const failure = classified[index];
210
184
  if (failure !== null && failure !== undefined) {
211
185
  answers.set(ask, failure);
212
- return;
186
+ continue;
213
187
  }
214
- answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
215
- });
188
+ answers.set(ask, enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask));
189
+ }
216
190
  open = [];
217
191
  }
218
192
  }
@@ -263,9 +237,6 @@ export function createAgentsHouseAdapter(options) {
263
237
  async authorize() {
264
238
  return options.authorize();
265
239
  },
266
- async model(_authorization, request) {
267
- return models.answer(request);
268
- },
269
240
  async discover(_authorization) {
270
241
  const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
271
242
  const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
@@ -283,9 +254,7 @@ export function createAgentsHouseAdapter(options) {
283
254
  if (!tracked.has(locator))
284
255
  handed.delete(locator);
285
256
  notifications.track(entries);
286
- const acquired = await acquireModels(entries);
287
- models.keep(entries.map((entry) => entry.locator));
288
- return mapDiscovery(document, document.authorities.map((authority) => roomOf(authority, acquired)), capabilities(document.actions));
257
+ return mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document.actions));
289
258
  },
290
259
  async bootstrap(_authorization, request) {
291
260
  const entry = authorityFor(request.locator);
@@ -304,16 +273,10 @@ export function createAgentsHouseAdapter(options) {
304
273
  const from = logPosition(request.fromRoomVersion);
305
274
  if (from === null)
306
275
  return { kind: 'beyond-horizon' };
307
- const answered = streamed(entry, request, from);
276
+ const answered = await streamed(entry, request, from);
308
277
  if (answered !== null)
309
278
  return answered;
310
- const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
311
- return enumerateTogether({
312
- entry,
313
- from,
314
- fromRoomVersion: request.fromRoomVersion,
315
- ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
316
- });
279
+ return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
317
280
  },
318
281
  async mutate(_authorization, request, keep) {
319
282
  const entry = authorityFor(request.locator);
@@ -328,8 +291,8 @@ export function createAgentsHouseAdapter(options) {
328
291
  const handed = request.upload;
329
292
  const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
330
293
  if (handed === undefined || !lapsedGrant(outcome))
331
- return outcome;
332
- return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);
294
+ return adopted(entry, outcome);
295
+ return adopted(entry, await submit(head, mapped.changes, delta, bytes, entry, undefined, keep));
333
296
  },
334
297
  async history(_authorization, request) {
335
298
  const entry = authorityFor(request.locator);
@@ -349,10 +312,13 @@ export function createAgentsHouseAdapter(options) {
349
312
  reached(locator, version, target) {
350
313
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
351
314
  },
315
+ follows(_locator, version, next) {
316
+ return followsVersion(version, next);
317
+ },
352
318
  async action(_authorization, request) {
353
319
  return withAt(await houseAction(transport, request));
354
320
  },
355
- roomVersions: notifications,
321
+ roomStream: { hold: held, observe: notifications.observe },
356
322
  conversations: notifications.conversations,
357
323
  serviceMode: notifications.serviceMode,
358
324
  };
@@ -1,10 +1,6 @@
1
- import type { Capability, DiscoveredRoom, Discovery, ModelIdentity, ProviderLimit, Retention } from '@agentshouse/mdruntime';
1
+ import type { Capability, DiscoveredRoom, Discovery, ProviderLimit, Retention } from '@agentshouse/mdruntime';
2
2
  import { type LogPosition } from './version.js';
3
- export declare const ROOM_CONTRACT_VERSION = 1;
4
- export declare const MD_MODEL_IDENTITY = "@agentshouse/mdmodel";
5
- export declare const ROOM_VERSION_NOTIFICATIONS = "room-version-notifications";
6
3
  export declare const PROVIDER_ACTIONS = "provider-actions";
7
- export declare const MOVE_REFERENCE_REWRITES = "move-reference-rewrites";
8
4
  export declare const DISCOVER_PREFIXES: readonly string[];
9
5
  export declare const PRIVATE_HANDLE = "private";
10
6
  export type HouseBounds = {
@@ -43,7 +39,6 @@ export type HouseAuthority = LogPosition & {
43
39
  };
44
40
  export type HouseDiscoveryDocument = {
45
41
  bounds: HouseBounds;
46
- mdModelVersion: string;
47
42
  authorities: readonly HouseAuthority[];
48
43
  actions: readonly string[];
49
44
  };
@@ -62,7 +57,6 @@ export type HouseSiteAuthority = LogPosition & {
62
57
  };
63
58
  export type HouseSiteDiscovery = {
64
59
  bounds: HouseBounds;
65
- mdModelVersion: string;
66
60
  authorities: readonly HouseSiteAuthority[];
67
61
  };
68
62
  export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
@@ -74,6 +68,6 @@ export declare function providerLimits(bounds: HouseBounds): readonly ProviderLi
74
68
  export declare function declaredRetention(bounds: HouseBounds): Retention;
75
69
  export declare function capabilities(actions: readonly string[]): readonly Capability[];
76
70
  export declare function siteCapabilities(): readonly Capability[];
77
- export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], selectionModel: ModelIdentity | null): DiscoveredRoom;
78
- export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds' | 'mdModelVersion'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
71
+ export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
72
+ export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
79
73
  //# sourceMappingURL=discovery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,aAAa,EACb,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,qBAAqB,IAAI,CAAC;AAEvC,eAAO,MAAM,iBAAiB,yBAAyB,CAAC;AAExD,eAAO,MAAM,0BAA0B,+BAA+B,CAAC;AAEvE,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,eAAO,MAAM,uBAAuB,4BAA4B,CAAC;AAEjE,eAAO,MAAM,iBAAiB,EAAE,SAAS,MAAM,EAAU,CAAC;AAE1D,eAAO,MAAM,cAAc,YAAY,CAAC;AAExC,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB,EAAE,MAAM,CAAC;IACjC,2BAA2B,EAAE,MAAM,CAAC;CACrC,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,SAAS,MAAM,EAAE,CAAC;IACxB,IAAI,EAAE,SAAS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AAE,WAAW,GAAG,SAAS,CAMhE;AAED,wBAAgB,YAAY,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,UAAU,EAAE,CAQ9E;AAED,wBAAgB,gBAAgB,IAAI,SAAS,UAAU,EAAE,CAIxD;AAED,wBAAgB,cAAc,CAAC,SAAS,EAAE,cAAc,GAAG,cAAc,CAkBxE;AAED,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,IAAI,CAAC,sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
package/dist/discovery.js CHANGED
@@ -1,11 +1,7 @@
1
1
  import { declaredActions, HOUSE_CONVERSATION_CARDS } from './actions.js';
2
2
  import { PRIVATE_LOCATOR } from './transport.js';
3
3
  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
4
  export const PROVIDER_ACTIONS = 'provider-actions';
8
- export const MOVE_REFERENCE_REWRITES = 'move-reference-rewrites';
9
5
  export const DISCOVER_PREFIXES = ['/'];
10
6
  export const PRIVATE_HANDLE = 'private';
11
7
  const BOUND_KEYS = [
@@ -107,8 +103,6 @@ export function parseDiscovery(body) {
107
103
  const bounds = parseBounds(held.bounds);
108
104
  if (bounds === null)
109
105
  return null;
110
- if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0)
111
- return null;
112
106
  const actions = stringList(held.actions);
113
107
  if (actions === null ||
114
108
  new Set(actions).size !== actions.length ||
@@ -123,7 +117,7 @@ export function parseDiscovery(body) {
123
117
  return null;
124
118
  authorities.push(authority);
125
119
  }
126
- return { bounds, mdModelVersion: held.md_model_version, authorities, actions };
120
+ return { bounds, authorities, actions };
127
121
  }
128
122
  function parseSiteAuthority(value) {
129
123
  if (typeof value !== 'object' || value === null)
@@ -154,8 +148,6 @@ export function parseSiteDiscovery(body) {
154
148
  const bounds = parseBounds(held.bounds);
155
149
  if (bounds === null)
156
150
  return null;
157
- if (typeof held.md_model_version !== 'string' || held.md_model_version.length === 0)
158
- return null;
159
151
  if (!Array.isArray(held.authorities))
160
152
  return null;
161
153
  const authorities = [];
@@ -165,7 +157,7 @@ export function parseSiteDiscovery(body) {
165
157
  return null;
166
158
  authorities.push(authority);
167
159
  }
168
- return { bounds, mdModelVersion: held.md_model_version, authorities };
160
+ return { bounds, authorities };
169
161
  }
170
162
  export function siteTracked(document) {
171
163
  return document.authorities.map((authority) => ({
@@ -219,25 +211,23 @@ export function declaredRetention(bounds) {
219
211
  }
220
212
  export function capabilities(actions) {
221
213
  return [
222
- { name: ROOM_VERSION_NOTIFICATIONS },
223
214
  {
224
215
  name: PROVIDER_ACTIONS,
225
216
  actions: declaredActions(actions),
226
217
  conversationCards: HOUSE_CONVERSATION_CARDS,
227
218
  },
228
- { name: MOVE_REFERENCE_REWRITES },
229
219
  ];
230
220
  }
231
221
  export function siteCapabilities() {
232
222
  return [
233
- { name: ROOM_VERSION_NOTIFICATIONS },
234
223
  { name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },
235
224
  ];
236
225
  }
237
- export function discoveredRoom(authority, attachedModel, selectionModel) {
226
+ export function discoveredRoom(authority) {
227
+ const locator = locatorOf(authority);
238
228
  return {
239
229
  name: authority.name,
240
- locator: locatorOf(authority),
230
+ locator,
241
231
  roomVersion: roomVersion(authority),
242
232
  operations: {
243
233
  read: [...authority.operations.read],
@@ -245,24 +235,16 @@ export function discoveredRoom(authority, attachedModel, selectionModel) {
245
235
  write: [...authority.operations.write],
246
236
  delete: [...authority.operations.delete],
247
237
  },
248
- replica: { selection: locatorOf(authority), admission: authority.managedReplication },
249
- attachedModel,
238
+ replica: { selection: locator, admission: authority.managedReplication },
250
239
  ...(authority.houseModel === null
251
240
  ? {}
252
- : {
253
- typedSelection: {
254
- roots: [...authority.houseModel.paths],
255
- attachedModel: selectionModel,
256
- },
257
- }),
241
+ : { typedSelection: { roots: [...authority.houseModel.paths] } }),
258
242
  providerOwnedPaths: [...authority.protectedPaths, ...schemasOf(authority)],
259
243
  };
260
244
  }
261
245
  export function mapDiscovery(document, rooms, declared) {
262
246
  return {
263
247
  kind: 'discovery',
264
- supportedVersions: [ROOM_CONTRACT_VERSION],
265
- mdModel: { identity: MD_MODEL_IDENTITY, version: document.mdModelVersion },
266
248
  rooms,
267
249
  capabilities: declared,
268
250
  providerLimits: providerLimits(document.bounds),
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { createAgentsHouseAdapter, type AgentsHouseAdapterOptions } from './adapter.js';
2
- export type { HouseByteAct, HouseByteAnswer, HouseByteTransfer, HouseDoorAnswer, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
2
+ export { PRIVATE_LOCATOR } from './transport.js';
3
+ export type { HouseByteAct, HouseByteAnswer, HouseByteTransfer, HouseDoorAnswer, HouseHeldRoom, HouseOpening, HouseStream, HouseStreamEntry, HouseStreamFrame, HouseSiteTransport, HouseTransport, } from './transport.js';
3
4
  //# 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,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,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,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 +1,2 @@
1
1
  export { createAgentsHouseAdapter } from './adapter.js';
2
+ export { PRIVATE_LOCATOR } from './transport.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,M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,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
  }