@agentshouse/mdruntime-adapter 0.1.0-cc7fa1e066844 → 0.1.0-cf22c8563f9f4
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 +57 -20
- package/README.md +3 -3
- package/dist/actions.d.ts +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +3 -7
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +75 -111
- package/dist/discovery.d.ts +4 -12
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +16 -35
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/links.d.ts +9 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +40 -2
- package/dist/model.d.ts +7 -18
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +48 -41
- package/dist/read.d.ts +1 -1
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +5 -8
- package/dist/refusal.d.ts +3 -4
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -14
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +45 -78
- package/dist/stream.d.ts +8 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +89 -37
- package/dist/transport.d.ts +31 -2
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +0 -1
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +9 -0
- package/dist/write.d.ts +9 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +11 -7
- package/package.json +3 -3
package/AGENTS.md
CHANGED
|
@@ -12,13 +12,26 @@ 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,
|
|
17
|
+
Rooms lists only the Rooms reached whole, a Room reached for single Documents
|
|
18
|
+
shows only those Documents and the Types of the models that govern them, and
|
|
19
|
+
without conversations the conversation members, the chat draft and the
|
|
20
|
+
conversation observation hold none.
|
|
21
|
+
A change of the reach reaches every open observation as its new value, a query
|
|
22
|
+
keeping every unchanged Document the same object.
|
|
23
|
+
|
|
15
24
|
Every `observe` resolves, once its first value has arrived, to a handle:
|
|
16
25
|
`current()` is the latest complete value, `subscribe(listener)` hears each later
|
|
17
26
|
value whole and returns its unsubscribe, and `close()` ends the observation.
|
|
18
27
|
Closing the port ends every handle and rejects every pending call and
|
|
19
28
|
observation; a client that reconnects observes again.
|
|
20
29
|
|
|
21
|
-
Each conversation
|
|
30
|
+
Each conversation the Provider's conversation list names is held complete in the
|
|
31
|
+
browser. `conversation.list()` and `observe('conversations')` answer each with its
|
|
32
|
+
Agent's identity and name, its name, created and finished times, last outcome and live
|
|
33
|
+
`state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
|
|
34
|
+
and `started`, when the running turn began, or `null`.
|
|
22
35
|
Observe one with `observe('conversation', id, { limit })`: the view
|
|
23
36
|
holds its latest `limit` messages, or all of them, oldest first, its chat
|
|
24
37
|
draft, and what the Provider streams for it whether or not anything views it:
|
|
@@ -44,7 +57,10 @@ effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
|
44
57
|
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
45
58
|
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
46
59
|
that document was written at a later Room Version. Each History revision
|
|
47
|
-
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
60
|
+
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
61
|
+
History of a Path no current document holds answers the removed document's
|
|
62
|
+
revisions with `deleted: true`, newest first; that revision is what a link to
|
|
63
|
+
the Path opens. Every
|
|
48
64
|
member of the
|
|
49
65
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
50
66
|
surface returns the authorization, performs a request the App's code
|
|
@@ -66,22 +82,28 @@ data:
|
|
|
66
82
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
67
83
|
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
68
84
|
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
69
|
-
- **Fields.**
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
85
|
+
- **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
|
|
86
|
+
`/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
|
|
87
|
+
meets a list applies to every item and a number names one item. `where` names
|
|
88
|
+
pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
|
|
89
|
+
when any item satisfies it. A bare value is equality; the operators are `$eq`,
|
|
90
|
+
`$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
|
|
91
|
+
`$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
|
|
73
92
|
`$exists: false` keeps a missing field, `null` an explicit null, `''` empty
|
|
74
93
|
text and `$size: 0` an empty list. A date compares in calendar order and never
|
|
75
94
|
with a date-time. A reference compares by the Room Path it resolves to.
|
|
76
|
-
Untyped frontmatter
|
|
95
|
+
Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
|
|
96
|
+
values. There is no text containment or regular
|
|
77
97
|
expression.
|
|
78
98
|
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
79
|
-
reference `field
|
|
80
|
-
`backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
99
|
+
reference at pointer `field`, at any depth, points to a matching Document of the
|
|
100
|
+
same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
81
101
|
matching Document of the same Room references. Each keeps a Document once.
|
|
82
102
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
83
|
-
`preamble`, `markdown`, `backlinks` and `change`, where `fields`
|
|
84
|
-
|
|
103
|
+
`preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
|
|
104
|
+
list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
105
|
+
return the frontmatter holding only them, nested as written. A backlink names
|
|
106
|
+
the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
|
|
85
107
|
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
86
108
|
target returns only Room and Path. An unselected part is absent. Select only
|
|
87
109
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
@@ -95,8 +117,8 @@ data:
|
|
|
95
117
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
96
118
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
97
119
|
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
98
|
-
over every match and ordered by `count` or a key.
|
|
99
|
-
or the groups.
|
|
120
|
+
over every match and ordered by `count` or a key. A sort or group takes only a
|
|
121
|
+
pointer that holds one value. `limit` bounds the Documents or the groups.
|
|
100
122
|
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
101
123
|
Rooms and Sync Status. An invalid query fails with `invalid-query`,
|
|
102
124
|
`unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
|
|
@@ -193,13 +215,28 @@ an App's override respected. What an App Creator's agent adds carries none
|
|
|
193
215
|
of these promises by itself. Reading, querying and searching never wait for
|
|
194
216
|
the network. Data lives only in the App Creator's browser and with the Provider.
|
|
195
217
|
|
|
196
|
-
## App code
|
|
197
|
-
|
|
198
|
-
App code
|
|
199
|
-
`
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
218
|
+
## App code takes the client its host hands it and never constructs a Runtime
|
|
219
|
+
|
|
220
|
+
App code takes the client its host hands it: in House,
|
|
221
|
+
`connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
|
|
222
|
+
client House built into the page. It never constructs a Runtime or a client.
|
|
223
|
+
It imports only types from `@agentshouse/mdruntime/client`, does not call
|
|
224
|
+
`connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
|
|
225
|
+
the host entry, or the Adapter package. Hosts and tests use those entries; the
|
|
226
|
+
served App does not.
|
|
227
|
+
|
|
228
|
+
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
229
|
+
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
230
|
+
the arguments of `observe` and returns the topic's current value, `undefined`
|
|
231
|
+
until it arrives, re-rendering on each change; a `null` client observes
|
|
232
|
+
nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
|
|
233
|
+
`save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
|
|
234
|
+
already there, keeping the bases its parts have, or onto a new one, and saves
|
|
235
|
+
them together. A refused Save leaves the Room Drafts for the App to save again
|
|
236
|
+
or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
|
|
237
|
+
roomDrafts)` is that save outside a component. A react-admin or Refine App
|
|
238
|
+
reads and writes its Rooms through the data providers of
|
|
239
|
+
`@agentshouse/mdruntime-families`.
|
|
203
240
|
|
|
204
241
|
## What an agent must never do
|
|
205
242
|
|
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
|
|
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
|
-
|
|
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
|
|
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
|
|
3
|
+
export declare function houseConversationAgents(locator: string): 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;
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -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,
|
|
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;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,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
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { changeBatchIdentity, } from '@agentshouse/mdruntime';
|
|
2
2
|
import { doorRefusal } from './refusal.js';
|
|
3
|
-
import { PRIVATE_LOCATOR } from './transport.js';
|
|
4
3
|
const HISTORY_PAGE = 100;
|
|
5
4
|
const HISTORY_CONVERSATIONS = 64;
|
|
6
5
|
const OCTET_STREAM = 'application/octet-stream';
|
|
@@ -13,12 +12,9 @@ const CONVERSATION_ROUTES = new Map([
|
|
|
13
12
|
['conversation.delete', '/door/conversations/delete'],
|
|
14
13
|
['conversation.history', '/door/conversations/history'],
|
|
15
14
|
]);
|
|
16
|
-
export
|
|
17
|
-
locator:
|
|
18
|
-
|
|
19
|
-
identity: 'conversation',
|
|
20
|
-
agent: 'agent',
|
|
21
|
-
};
|
|
15
|
+
export function houseConversationAgents(locator) {
|
|
16
|
+
return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
|
|
17
|
+
}
|
|
22
18
|
export function declaredActions(routes) {
|
|
23
19
|
const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
|
|
24
20
|
return routes.map((route) => ({
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,
|
|
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,EAOL,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,CAuWpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -1,26 +1,20 @@
|
|
|
1
|
-
import { DISCOVER_PREFIXES, capabilities, discoveredRoom,
|
|
2
|
-
import {
|
|
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,
|
|
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
|
-
import { classifyDoor, discoveryFailure, doorRefusal } from './refusal.js';
|
|
8
|
+
import { classifyDoor, classifyRead, 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,
|
|
10
|
+
import { DOOR_BATCH, DOOR_BATCH_UPLOAD, DOOR_BOOTSTRAP, DOOR_DISCOVER, DOOR_ENUMERATE, DOOR_REVISIONS, } 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.
|
|
44
|
-
|
|
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.
|
|
44
|
+
notifications.reach(ask.entry.authority, view);
|
|
51
45
|
const answer = refreshFrom(view, ask.fromRoomVersion);
|
|
52
|
-
if (answer.kind
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
72
|
-
|
|
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));
|
|
63
|
+
const models = await streamedModels(advanced.schemas, entry, 'credential');
|
|
64
|
+
return models === undefined ? advanced.page : { ...advanced.page, models };
|
|
78
65
|
}
|
|
79
|
-
|
|
80
|
-
const
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
const
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
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);
|
|
@@ -115,9 +104,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
115
104
|
const { authority, position, log_epoch: logEpoch } = body;
|
|
116
105
|
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
117
106
|
return result;
|
|
118
|
-
const locator = authority ===
|
|
119
|
-
? PRIVATE_LOCATOR
|
|
120
|
-
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
107
|
+
const locator = [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
121
108
|
if (locator === undefined)
|
|
122
109
|
return result;
|
|
123
110
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
@@ -147,14 +134,14 @@ export function createAgentsHouseAdapter(options) {
|
|
|
147
134
|
});
|
|
148
135
|
const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
|
|
149
136
|
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
150
|
-
part.
|
|
137
|
+
for (const [index, entry] of part.entries()) {
|
|
151
138
|
const failure = classified[index];
|
|
152
139
|
if (failure === null || failure === undefined) {
|
|
153
|
-
answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
|
|
154
|
-
|
|
140
|
+
answers.push(envelope === null ? UNCERTAIN_READ : await bootstrappedRoom(envelope, entry));
|
|
141
|
+
continue;
|
|
155
142
|
}
|
|
156
|
-
answers.push(failure
|
|
157
|
-
}
|
|
143
|
+
answers.push(failure);
|
|
144
|
+
}
|
|
158
145
|
}
|
|
159
146
|
return answers;
|
|
160
147
|
}
|
|
@@ -176,24 +163,9 @@ export function createAgentsHouseAdapter(options) {
|
|
|
176
163
|
while (open.length > 0) {
|
|
177
164
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
178
165
|
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
|
-
})),
|
|
166
|
+
positions: open.map((ask) => presented(ask.entry.authority, ask.from)),
|
|
183
167
|
});
|
|
184
|
-
const
|
|
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
|
-
const classified = open.map((ask) => classifyDoor(answer.status, answer.body, ask.entry.locator));
|
|
168
|
+
const classified = open.map((ask) => classifyRead(answer.status, answer.body, ask.entry.locator));
|
|
197
169
|
if (classified[0]?.kind === 'beyond-horizon') {
|
|
198
170
|
const named = doorRefusal(answer.body)?.fields.authority;
|
|
199
171
|
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
@@ -205,14 +177,14 @@ export function createAgentsHouseAdapter(options) {
|
|
|
205
177
|
continue;
|
|
206
178
|
}
|
|
207
179
|
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
208
|
-
open.
|
|
180
|
+
for (const [index, ask] of open.entries()) {
|
|
209
181
|
const failure = classified[index];
|
|
210
182
|
if (failure !== null && failure !== undefined) {
|
|
211
183
|
answers.set(ask, failure);
|
|
212
|
-
|
|
184
|
+
continue;
|
|
213
185
|
}
|
|
214
|
-
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
215
|
-
}
|
|
186
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask));
|
|
187
|
+
}
|
|
216
188
|
open = [];
|
|
217
189
|
}
|
|
218
190
|
}
|
|
@@ -224,7 +196,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
224
196
|
const paths = batchPaths(changes);
|
|
225
197
|
const sha256 = await deltaDigest(delta);
|
|
226
198
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
227
|
-
return { body: { ...head, paths, upload: handed } };
|
|
199
|
+
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
228
200
|
}
|
|
229
201
|
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
230
202
|
if (minted.status !== 200) {
|
|
@@ -247,10 +219,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
247
219
|
return { outcome: UNCERTAIN };
|
|
248
220
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
249
221
|
await keep(upload);
|
|
250
|
-
return { body: { ...head, paths, upload } };
|
|
222
|
+
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
251
223
|
}
|
|
252
224
|
async function submit(head, changes, delta, bytes, entry, handed, keep) {
|
|
253
|
-
const inline = { ...head, changes };
|
|
225
|
+
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
254
226
|
const prepared = uploadable(inline, bytes, declared())
|
|
255
227
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
256
228
|
: { body: inline };
|
|
@@ -263,14 +235,11 @@ export function createAgentsHouseAdapter(options) {
|
|
|
263
235
|
async authorize() {
|
|
264
236
|
return options.authorize();
|
|
265
237
|
},
|
|
266
|
-
async model(_authorization, request) {
|
|
267
|
-
return models.answer(request);
|
|
268
|
-
},
|
|
269
238
|
async discover(_authorization) {
|
|
270
239
|
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
271
|
-
const
|
|
272
|
-
if (
|
|
273
|
-
return
|
|
240
|
+
const failed = discoveryFailure(answer.status, answer.body);
|
|
241
|
+
if (failed !== null)
|
|
242
|
+
return failed;
|
|
274
243
|
const document = parseDiscovery(answer.body);
|
|
275
244
|
if (document === null)
|
|
276
245
|
return { kind: 'transport-uncertainty' };
|
|
@@ -283,9 +252,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
283
252
|
if (!tracked.has(locator))
|
|
284
253
|
handed.delete(locator);
|
|
285
254
|
notifications.track(entries);
|
|
286
|
-
|
|
287
|
-
models.keep(entries.map((entry) => entry.locator));
|
|
288
|
-
return mapDiscovery(document, document.authorities.map((authority) => roomOf(authority, acquired)), capabilities(document.actions));
|
|
255
|
+
return mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document));
|
|
289
256
|
},
|
|
290
257
|
async bootstrap(_authorization, request) {
|
|
291
258
|
const entry = authorityFor(request.locator);
|
|
@@ -304,16 +271,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
304
271
|
const from = logPosition(request.fromRoomVersion);
|
|
305
272
|
if (from === null)
|
|
306
273
|
return { kind: 'beyond-horizon' };
|
|
307
|
-
const answered = streamed(entry, request, from);
|
|
274
|
+
const answered = await streamed(entry, request, from);
|
|
308
275
|
if (answered !== null)
|
|
309
276
|
return answered;
|
|
310
|
-
|
|
311
|
-
return enumerateTogether({
|
|
312
|
-
entry,
|
|
313
|
-
from,
|
|
314
|
-
fromRoomVersion: request.fromRoomVersion,
|
|
315
|
-
...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
|
|
316
|
-
});
|
|
277
|
+
return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
|
|
317
278
|
},
|
|
318
279
|
async mutate(_authorization, request, keep) {
|
|
319
280
|
const entry = authorityFor(request.locator);
|
|
@@ -328,8 +289,8 @@ export function createAgentsHouseAdapter(options) {
|
|
|
328
289
|
const handed = request.upload;
|
|
329
290
|
const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
330
291
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
331
|
-
return outcome;
|
|
332
|
-
return submit(head, mapped.changes, delta, bytes, entry, undefined, keep);
|
|
292
|
+
return adopted(entry, outcome);
|
|
293
|
+
return adopted(entry, await submit(head, mapped.changes, delta, bytes, entry, undefined, keep));
|
|
333
294
|
},
|
|
334
295
|
async history(_authorization, request) {
|
|
335
296
|
const entry = authorityFor(request.locator);
|
|
@@ -349,10 +310,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
349
310
|
reached(locator, version, target) {
|
|
350
311
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
351
312
|
},
|
|
313
|
+
follows(_locator, version, next) {
|
|
314
|
+
return followsVersion(version, next);
|
|
315
|
+
},
|
|
352
316
|
async action(_authorization, request) {
|
|
353
317
|
return withAt(await houseAction(transport, request));
|
|
354
318
|
},
|
|
355
|
-
|
|
319
|
+
roomStream: { hold: held, observe: notifications.observe },
|
|
356
320
|
conversations: notifications.conversations,
|
|
357
321
|
serviceMode: notifications.serviceMode,
|
|
358
322
|
};
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
import type { Capability, DiscoveredRoom, Discovery,
|
|
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 PRIVATE_HANDLE = "private";
|
|
10
5
|
export type HouseBounds = {
|
|
11
6
|
max_authored_file_bytes: number;
|
|
12
7
|
max_batch_operations: number;
|
|
@@ -43,7 +38,6 @@ export type HouseAuthority = LogPosition & {
|
|
|
43
38
|
};
|
|
44
39
|
export type HouseDiscoveryDocument = {
|
|
45
40
|
bounds: HouseBounds;
|
|
46
|
-
mdModelVersion: string;
|
|
47
41
|
authorities: readonly HouseAuthority[];
|
|
48
42
|
actions: readonly string[];
|
|
49
43
|
};
|
|
@@ -62,18 +56,16 @@ export type HouseSiteAuthority = LogPosition & {
|
|
|
62
56
|
};
|
|
63
57
|
export type HouseSiteDiscovery = {
|
|
64
58
|
bounds: HouseBounds;
|
|
65
|
-
mdModelVersion: string;
|
|
66
59
|
authorities: readonly HouseSiteAuthority[];
|
|
67
60
|
};
|
|
68
61
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
69
62
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
70
63
|
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
71
|
-
export declare function locatorOf(authority: HouseAuthority): string;
|
|
72
64
|
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
73
65
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
74
66
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
75
|
-
export declare function capabilities(
|
|
67
|
+
export declare function capabilities(document: HouseDiscoveryDocument): readonly Capability[];
|
|
76
68
|
export declare function siteCapabilities(): readonly Capability[];
|
|
77
|
-
export declare function discoveredRoom(authority: HouseAuthority
|
|
78
|
-
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'
|
|
69
|
+
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
70
|
+
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
|
79
71
|
//# sourceMappingURL=discovery.d.ts.map
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"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"}
|