@agentshouse/mdruntime-adapter 0.1.0-c6229cc476473 → 0.1.0-c89f673dd3f40

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
@@ -7,9 +7,18 @@ enforcement.
7
7
  ## The MD Runtime API
8
8
 
9
9
  App code reaches the MD Runtime through the remote client. The surfaces are
10
- Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
- storage loss, the reported persistence answer, deployment facts, Sync Status, the Service Mode,
12
- reauthorization, conversation, the chat draft, and Presentation State.
10
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
+ the reported persistence answer, reauthorization, conversation, the chat draft,
12
+ and Presentation State. Sync Status, the Service Mode, the storage-loss
13
+ statement and the deployment facts are observations only.
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.
13
22
 
14
23
  Every `observe` resolves, once its first value has arrived, to a handle:
15
24
  `current()` is the latest complete value, `subscribe(listener)` hears each later
@@ -17,29 +26,29 @@ value whole and returns its unsubscribe, and `close()` ends the observation.
17
26
  Closing the port ends every handle and rejects every pending call and
18
27
  observation; a client that reconnects observes again.
19
28
 
20
- Each conversation a Provider card names is held complete in the browser.
29
+ Each conversation the Provider's conversation list names is held complete in the
30
+ browser. `conversation.list()` and `observe('conversations')` answer each with its
31
+ Agent's identity and name, its name, created and finished times, last outcome and live
32
+ `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
33
+ and `started`, when the running turn began, or `null`.
21
34
  Observe one with `observe('conversation', id, { limit })`: the view
22
35
  holds its latest `limit` messages, or all of them, oldest first, its chat
23
36
  draft, and what the Provider streams for it whether or not anything views it:
24
- the growing text and plan of the running turn, the open questions, the process
25
- state, the CLI's commands and options, and the latest `workingNote`. These live
26
- only in memory: the turn's accepted message replaces its growing text and plan,
27
- a working note is never part of a message, and none of them is stored or
28
- searchable.
37
+ the running `turn` with its message parts and its context in use and window, the
38
+ open questions, the process state, and the CLI's commands and options. These live
39
+ only in memory: the message accepted under the turn's id replaces the running turn,
40
+ and none of them is stored or searchable.
29
41
  `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
30
42
  sending it is a Provider Action that needs the Provider reachable and is never
31
43
  queued.
32
44
 
33
- Slots answers each Slot the Provider declares, in its order, with its entries
34
- in order, each a Room and its segment; a Room two Slots list is the same Room.
35
-
36
45
  Each Room in Rooms lists its `attachments`, the files the Provider holds for it
37
46
  that its Documents link by the Provider's reference, ordered by `reference`,
38
47
  each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
39
48
  `entry`. They are as the Provider last declared them and hold no bytes;
40
49
  open one through the Provider Action that serves it.
41
50
 
42
- Rooms, Slots, Query, Search, Observe, Types, Room Draft, Save, and Reached never
51
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
43
52
  touch the network.
44
53
  History and Call go to the Provider through the Adapter. A Call result whose
45
54
  effect the Provider places in a Room carries `at`, that Room and Room Version;
@@ -53,9 +62,8 @@ client is asynchronous. Results are detached snapshots. Nothing in this
53
62
  surface returns the authorization, performs a request the App's code
54
63
  composes, or exposes the browser store.
55
64
 
56
- Read deployment facts with `deploymentFacts()` and observe replacements with
57
- `observe('deployment-facts')`. Interpret the opaque value using the
58
- host's contract.
65
+ Read the deployment facts with `observe('deployment-facts')`. Interpret the
66
+ opaque value using the host's contract.
59
67
 
60
68
  The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
61
69
  ships in no bundle.
@@ -114,7 +122,7 @@ search.
114
122
 
115
123
  - **What is found.** A Document by its field values, its sections' headings and
116
124
  text, its preamble and its Path; a message by its text. Frontmatter keys, Room
117
- Drafts, chat drafts and growing text are never found. There are no phrases,
125
+ Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
118
126
  word forms, typo tolerance or prefix matching.
119
127
  - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
120
128
  `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
@@ -130,7 +138,7 @@ search.
130
138
 
131
139
  The MD Runtime owns one Room Draft per Room and Path, shared by every App and
132
140
  tab. It is durable: it survives reload and navigation. A Room that Discovery
133
- stops listing takes its Room Drafts, its queue and their outcomes with it.
141
+ stops listing takes its Room Drafts and its queue with it.
134
142
  Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
135
143
  the revision you read, or `null` when there was none, and every part it should
136
144
  now change: fields, sections and the preamble, or the whole Markdown, a
@@ -150,20 +158,21 @@ each Document and binary link target beneath it, saved together.
150
158
 
151
159
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
152
160
  queue, drawn over the confirmed layer, until the confirmed layer reaches the
153
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired outcome record, and a change that no
161
+ Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
154
162
  longer applies over the Room each leave the queue and return as Room Drafts on
155
163
  the Documents they changed, marked with why: the Provider's structured refusal
156
164
  code and fields as returned, not known to have applied, or withdrawn locally.
157
165
  The rest of the queue keeps synchronizing, and Sync Status requires attention
158
- until each returned Room Draft is saved again or discarded. `outcome` answers
159
- the saved Change Batch's outcome, and `null` while it is Pending. Transport
166
+ until each returned Room Draft is saved again or discarded. A Change Batch
167
+ keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
168
+ Pending one, and a returned Room Draft says why it returned. Transport
160
169
  failure and Provider unavailability keep work Pending and do not infer a
161
170
  rejection. A refusal the Provider marks retryable stays Pending until the reset
162
171
  it names; the MD Runtime retries the same Change Batch identity and payload and
163
172
  never infers an outcome from transport uncertainty. The MD Runtime never
164
173
  combines, reorders, or rebases.
165
174
 
166
- `serviceMode()` and `observe('service-mode')` answer the Provider's Service
175
+ `observe('service-mode')` answers the Provider's Service
167
176
  Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
168
177
  its Change Batch waits unsent, and the queue is submitted in order once the
169
178
  Provider reopens writes. An Action is never held: a write the Provider refuses
@@ -196,13 +205,25 @@ an App's override respected. What an App Creator's agent adds carries none
196
205
  of these promises by itself. Reading, querying and searching never wait for
197
206
  the network. Data lives only in the App Creator's browser and with the Provider.
198
207
 
199
- ## App code imports only the client entry and never constructs a Runtime
200
-
201
- App code imports only `@agentshouse/mdruntime/client` and calls
202
- `connectMdRuntime` on the port the host hands it. It never constructs a
203
- Runtime. It does not import the package main, the host entry, or the Adapter
204
- package, and it does not call `createMdRuntime` or `serveMdRuntime`. Hosts
205
- and tests use those entries; the served App does not.
208
+ ## App code takes the client its host hands it and never constructs a Runtime
209
+
210
+ App code takes the client its host hands it: in House,
211
+ `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
212
+ client House built into the page. It never constructs a Runtime or a client.
213
+ It imports only types from `@agentshouse/mdruntime/client`, does not call
214
+ `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
215
+ the host entry, or the Adapter package. Hosts and tests use those entries; the
216
+ served App does not.
217
+
218
+ A React App may observe and save through `@agentshouse/mdruntime/react`, which
219
+ names React as a peer dependency. `useObserve(client, topic, ...input)` takes
220
+ the arguments of `observe` and returns the topic's current value, `undefined`
221
+ until it arrives, re-rendering on each change; a `null` client observes
222
+ nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
223
+ `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
224
+ already there, keeping the bases its parts have, or onto a new one, and saves
225
+ them together. A refused Save leaves the Room Drafts for the App to save again
226
+ or discard; a failure is recorded and rejects.
206
227
 
207
228
  ## What an agent must never do
208
229
 
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
package/dist/actions.d.ts CHANGED
@@ -1,6 +1,6 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
1
+ import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
- export declare const HOUSE_CONVERSATION_CARDS: ConversationCards;
3
+ export declare const HOUSE_CONVERSATION_AGENTS: ConversationAgents;
4
4
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
5
5
  export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
6
6
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,eAAO,MAAM,wBAAwB,EAAE,iBAKtC,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAGxB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,eAAO,MAAM,yBAAyB,EAAE,kBAKvC,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
package/dist/actions.js CHANGED
@@ -13,11 +13,11 @@ const CONVERSATION_ROUTES = new Map([
13
13
  ['conversation.delete', '/door/conversations/delete'],
14
14
  ['conversation.history', '/door/conversations/history'],
15
15
  ]);
16
- export const HOUSE_CONVERSATION_CARDS = {
16
+ export const HOUSE_CONVERSATION_AGENTS = {
17
17
  locator: PRIVATE_LOCATOR,
18
- type: 'house-conversation',
19
- identity: 'conversation',
20
- agent: 'agent',
18
+ type: 'house-agent',
19
+ identity: 'agent',
20
+ name: 'name',
21
21
  };
22
22
  export function declaredActions(routes) {
23
23
  const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
@@ -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;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkZpF"}
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, HOUSE_SCHEMA, capabilities, discoveredRoom, locatorOf, mapDiscovery, parseDiscovery, providerSelection, 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
- import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, DOOR_SELECTION_MAX, PRIVATE_LOCATOR, } from './transport.js';
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,76 +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
- function bootstrappedRoom(envelope, entry) {
25
+ let bounds;
26
+ function declared() {
27
+ if (bounds === undefined)
28
+ throw new Error('no Discovery declared the bounds');
29
+ return bounds;
30
+ }
31
+ async function bootstrappedRoom(envelope, entry) {
33
32
  const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
34
33
  if (scope === undefined)
35
34
  return { kind: 'room-not-readable', locator: entry.locator };
36
35
  handed.set(entry.locator, scopeLinks(scope));
37
- notifications.hold(entry.authority, scope);
38
- return bootstrapOf(scope, entry);
36
+ notifications.reach(entry.authority, scope);
37
+ const models = await scopeModels(scope, entry);
38
+ return { ...bootstrapOf(scope), ...(models === undefined ? {} : { models }) };
39
39
  }
40
- function enumeratedRoom(enumeration, ask) {
40
+ async function enumeratedRoom(enumeration, ask) {
41
41
  const view = viewOf(enumeration, ask.entry);
42
42
  if (view === undefined)
43
43
  return { kind: 'room-not-readable', locator: ask.entry.locator };
44
- notifications.hold(ask.entry.authority, view);
45
- const answer = refreshFrom(view, ask.entry, ask.fromRoomVersion);
46
- if (answer.kind === 'net-advancement') {
47
- handed.set(ask.entry.locator, enumeratedLinks(view, handed.get(ask.entry.locator)));
48
- }
49
- return answer;
44
+ notifications.reach(ask.entry.authority, view);
45
+ const answer = refreshFrom(view, ask.fromRoomVersion);
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 };
50
51
  }
51
- function streamed(entry, request, from) {
52
+ async function streamed(entry, request, from) {
52
53
  const links = handed.get(entry.locator);
53
54
  if (links?.roomVersion !== request.fromRoomVersion)
54
55
  return null;
55
56
  const advanced = notifications.advance(entry, from, (path, revision) => links.revisions.get(path) === revision);
56
57
  if (advanced === null)
57
58
  return null;
58
- if (request.minPosition !== undefined &&
59
- !reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch))
60
- return null;
61
59
  const relinked = streamedLinks(links, advanced);
62
60
  if (relinked === null)
63
61
  return null;
64
62
  handed.set(entry.locator, relinked);
65
- return advanced.page;
66
- }
67
- function held(envelope, entry, schema, failure) {
68
- return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
69
- }
70
- function modelPrefixes(entry) {
71
- return entry.schemas.map((schema) => schemaPath(entry.handle, schema));
63
+ const models = await streamedModels(advanced.schemas, entry, 'credential');
64
+ return models === undefined ? advanced.page : { ...advanced.page, models };
72
65
  }
73
- async function acquireModels(entries) {
74
- const acquired = new Map();
75
- for (const part of selections(entries, (entry) => modelPrefixes(entry).length, DOOR_SELECTION_MAX)) {
76
- const privateEntry = part.find((entry) => entry.locator === PRIVATE_LOCATOR);
77
- const answer = await transport.door(DOOR_BOOTSTRAP, {
78
- prefixes: part.flatMap((entry) => modelPrefixes(entry)),
79
- });
80
- const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
81
- const envelope = classified === null ? parseEnvelope(await bundled(answer.body)) : null;
82
- const failure = modelFailure(classified, envelope);
83
- for (const entry of part) {
84
- acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
85
- }
86
- if (privateEntry !== undefined) {
87
- acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
88
- }
89
- }
90
- 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);
91
77
  }
92
- function roomOf(authority, acquired) {
93
- const locator = locatorOf(authority);
94
- const key = modelKey(locator, 'collection');
95
- const collection = models.retain(key, acquired.get(key));
96
- if (locator !== PRIVATE_LOCATOR) {
97
- return discoveredRoom(authority, collection?.identity ?? null, undefined);
98
- }
99
- const selection = models.retain(modelKey(locator, 'typed-selection'), acquired.get(modelKey(locator, 'typed-selection')));
100
- return discoveredRoom(authority, collection?.identity ?? null, providerSelection(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 };
101
94
  }
102
95
  function authorityFor(locator) {
103
96
  return tracked.get(locator);
@@ -137,20 +130,20 @@ export function createAgentsHouseAdapter(options) {
137
130
  }
138
131
  async function bootstrapped(entries) {
139
132
  const answers = [];
140
- for (const part of selections(entries, weight, DOOR_SELECTION_MAX)) {
133
+ for (const part of selections(entries, weight, declared().max_prefixes)) {
141
134
  const answer = await transport.door(DOOR_BOOTSTRAP, {
142
135
  prefixes: part.flatMap((entry) => contentPrefixes(entry)),
143
136
  });
144
137
  const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
145
138
  const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
146
- part.forEach((entry, index) => {
139
+ for (const [index, entry] of part.entries()) {
147
140
  const failure = classified[index];
148
141
  if (failure === null || failure === undefined) {
149
- answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
150
- return;
142
+ answers.push(envelope === null ? UNCERTAIN_READ : await bootstrappedRoom(envelope, entry));
143
+ continue;
151
144
  }
152
145
  answers.push(failure.kind === 'beyond-horizon' ? UNCERTAIN_READ : failure);
153
- });
146
+ }
154
147
  }
155
148
  return answers;
156
149
  }
@@ -166,26 +159,14 @@ export function createAgentsHouseAdapter(options) {
166
159
  }
167
160
  async function enumerated(asks) {
168
161
  const answers = new Map();
169
- const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), DOOR_SELECTION_MAX));
162
+ const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), declared().max_prefixes));
170
163
  for (const part of parts) {
171
164
  let open = [...part];
172
165
  while (open.length > 0) {
173
166
  const answer = await transport.door(DOOR_ENUMERATE, {
174
167
  prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
175
- positions: open.map((ask) => ({
176
- ...presented(ask.entry.authority, ask.from),
177
- ...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
178
- })),
168
+ positions: open.map((ask) => presented(ask.entry.authority, ask.from)),
179
169
  });
180
- const refusal = doorRefusal(answer.body);
181
- if (refusal?.code === 'replica_behind') {
182
- const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
183
- const behind = named.length === 0 ? open : named;
184
- for (const ask of behind)
185
- answers.set(ask, { kind: 'retryable-refusal', ...refusal });
186
- open = open.filter((ask) => !behind.includes(ask));
187
- continue;
188
- }
189
170
  const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
190
171
  if (classified[0]?.kind === 'beyond-horizon') {
191
172
  const named = doorRefusal(answer.body)?.fields.authority;
@@ -198,14 +179,14 @@ export function createAgentsHouseAdapter(options) {
198
179
  continue;
199
180
  }
200
181
  const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
201
- open.forEach((ask, index) => {
182
+ for (const [index, ask] of open.entries()) {
202
183
  const failure = classified[index];
203
184
  if (failure !== null && failure !== undefined) {
204
185
  answers.set(ask, failure);
205
- return;
186
+ continue;
206
187
  }
207
- answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
208
- });
188
+ answers.set(ask, enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask));
189
+ }
209
190
  open = [];
210
191
  }
211
192
  }
@@ -217,7 +198,7 @@ export function createAgentsHouseAdapter(options) {
217
198
  const paths = batchPaths(changes);
218
199
  const sha256 = await deltaDigest(delta);
219
200
  if (handed !== undefined && handed.sha256 === sha256) {
220
- return { body: { ...head, paths, upload: handed } };
201
+ return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
221
202
  }
222
203
  const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
223
204
  if (minted.status !== 200) {
@@ -240,12 +221,13 @@ export function createAgentsHouseAdapter(options) {
240
221
  return { outcome: UNCERTAIN };
241
222
  const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
242
223
  await keep(upload);
243
- return { body: { ...head, paths, upload } };
224
+ return { body: { ...head, paths, upload, runtime: notifications.runtime } };
244
225
  }
245
226
  async function submit(head, changes, delta, bytes, entry, handed, keep) {
246
- const prepared = uploadable(bytes)
227
+ const inline = { ...head, changes, runtime: notifications.runtime };
228
+ const prepared = uploadable(inline, bytes, declared())
247
229
  ? await uploaded(head, changes, delta, bytes, entry, handed, keep)
248
- : { body: { ...head, changes } };
230
+ : { body: inline };
249
231
  if ('outcome' in prepared)
250
232
  return prepared.outcome;
251
233
  const answer = await transport.door(DOOR_BATCH, prepared.body);
@@ -255,9 +237,6 @@ export function createAgentsHouseAdapter(options) {
255
237
  async authorize() {
256
238
  return options.authorize();
257
239
  },
258
- async model(_authorization, request) {
259
- return models.answer(request);
260
- },
261
240
  async discover(_authorization) {
262
241
  const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
263
242
  const classified = classifyDoor(answer.status, answer.body, PRIVATE_LOCATOR);
@@ -266,6 +245,7 @@ export function createAgentsHouseAdapter(options) {
266
245
  const document = parseDiscovery(answer.body);
267
246
  if (document === null)
268
247
  return { kind: 'transport-uncertainty' };
248
+ bounds = document.bounds;
269
249
  const entries = trackedFrom(document);
270
250
  tracked.clear();
271
251
  for (const entry of entries)
@@ -274,9 +254,7 @@ export function createAgentsHouseAdapter(options) {
274
254
  if (!tracked.has(locator))
275
255
  handed.delete(locator);
276
256
  notifications.track(entries);
277
- const acquired = await acquireModels(entries);
278
- models.keep(entries.map((entry) => entry.locator));
279
- 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));
280
258
  },
281
259
  async bootstrap(_authorization, request) {
282
260
  const entry = authorityFor(request.locator);
@@ -295,16 +273,10 @@ export function createAgentsHouseAdapter(options) {
295
273
  const from = logPosition(request.fromRoomVersion);
296
274
  if (from === null)
297
275
  return { kind: 'beyond-horizon' };
298
- const answered = streamed(entry, request, from);
276
+ const answered = await streamed(entry, request, from);
299
277
  if (answered !== null)
300
278
  return answered;
301
- const minPosition = request.minPosition === undefined ? null : logPosition(request.minPosition);
302
- return enumerateTogether({
303
- entry,
304
- from,
305
- fromRoomVersion: request.fromRoomVersion,
306
- ...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
307
- });
279
+ return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
308
280
  },
309
281
  async mutate(_authorization, request, keep) {
310
282
  const entry = authorityFor(request.locator);
@@ -319,8 +291,8 @@ export function createAgentsHouseAdapter(options) {
319
291
  const handed = request.upload;
320
292
  const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
321
293
  if (handed === undefined || !lapsedGrant(outcome))
322
- return outcome;
323
- 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));
324
296
  },
325
297
  async history(_authorization, request) {
326
298
  const entry = authorityFor(request.locator);
@@ -340,10 +312,13 @@ export function createAgentsHouseAdapter(options) {
340
312
  reached(locator, version, target) {
341
313
  return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
342
314
  },
315
+ follows(_locator, version, next) {
316
+ return followsVersion(version, next);
317
+ },
343
318
  async action(_authorization, request) {
344
319
  return withAt(await houseAction(transport, request));
345
320
  },
346
- roomVersions: notifications,
321
+ roomStream: { hold: held, observe: notifications.observe },
347
322
  conversations: notifications.conversations,
348
323
  serviceMode: notifications.serviceMode,
349
324
  };
@@ -1,15 +1,7 @@
1
- import type { Capability, DiscoveredRoom, Discovery, ProviderLimit, Retention, TypedSelection } 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
- export declare const PROVIDER_SELECTION_ROOTS: readonly string[];
10
- export declare const UNTYPED_FOLDERS: readonly string[];
11
- export declare const RESERVED_NAMES: readonly string[];
12
- export declare const HOUSE_SCHEMA = "house/schema.yaml";
13
5
  export declare const PRIVATE_HANDLE = "private";
14
6
  export type HouseBounds = {
15
7
  max_authored_file_bytes: number;
@@ -19,6 +11,9 @@ export type HouseBounds = {
19
11
  max_path_depth: number;
20
12
  max_mount_files: number;
21
13
  max_mount_bytes: number;
14
+ max_inline_body_bytes: number;
15
+ max_upload_bytes: number;
16
+ max_prefixes: number;
22
17
  change_retention_seconds: number;
23
18
  operation_retention_seconds: number;
24
19
  };
@@ -28,18 +23,22 @@ export type HouseOperations = {
28
23
  write: readonly string[];
29
24
  delete: readonly string[];
30
25
  };
26
+ export type HouseModel = {
27
+ root: string;
28
+ paths: readonly string[];
29
+ };
31
30
  export type HouseAuthority = LogPosition & {
32
31
  roomRef: string;
33
32
  roomHandle: string;
34
33
  name: string;
35
34
  schema: string;
35
+ houseModel: HouseModel | null;
36
36
  managedReplication: 'admitted' | 'unavailable';
37
37
  protectedPaths: readonly string[];
38
38
  operations: HouseOperations;
39
39
  };
40
40
  export type HouseDiscoveryDocument = {
41
41
  bounds: HouseBounds;
42
- mdModelVersion: string;
43
42
  authorities: readonly HouseAuthority[];
44
43
  actions: readonly string[];
45
44
  };
@@ -48,16 +47,9 @@ export type TrackedAuthority = LogPosition & {
48
47
  authority: string;
49
48
  handle: string;
50
49
  schema: string;
50
+ houseModel: HouseModel | null;
51
51
  schemas: readonly string[];
52
52
  };
53
- export type HouseSiteEntry = {
54
- roomRef: string;
55
- segment: string;
56
- };
57
- export type HouseSiteSlot = {
58
- slot: string;
59
- entries: readonly HouseSiteEntry[];
60
- };
61
53
  export type HouseSiteAuthority = LogPosition & {
62
54
  roomRef: string;
63
55
  roomHandle: string;
@@ -65,21 +57,17 @@ export type HouseSiteAuthority = LogPosition & {
65
57
  };
66
58
  export type HouseSiteDiscovery = {
67
59
  bounds: HouseBounds;
68
- mdModelVersion: string;
69
- slots: readonly HouseSiteSlot[];
70
60
  authorities: readonly HouseSiteAuthority[];
71
61
  };
72
62
  export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
73
63
  export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
74
64
  export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
75
- export declare function siteSlots(document: HouseSiteDiscovery): Discovery['slots'];
76
65
  export declare function locatorOf(authority: HouseAuthority): string;
77
66
  export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
78
67
  export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
79
68
  export declare function declaredRetention(bounds: HouseBounds): Retention;
80
69
  export declare function capabilities(actions: readonly string[]): readonly Capability[];
81
70
  export declare function siteCapabilities(): readonly Capability[];
82
- export declare function providerSelection(attachedModel: TypedSelection['attachedModel']): TypedSelection;
83
- export declare function discoveredRoom(authority: HouseAuthority, attachedModel: DiscoveredRoom['attachedModel'], typedSelection: TypedSelection | undefined): DiscoveredRoom;
84
- 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;
85
73
  //# sourceMappingURL=discovery.d.ts.map