@agentshouse/mdruntime-adapter 0.1.0-c6ddfd288ac81 → 0.1.0-c8654c2657ee5
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 +75 -41
- 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 +88 -113
- package/dist/discovery.d.ts +13 -27
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +41 -101
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/links.d.ts +10 -1
- package/dist/links.d.ts.map +1 -1
- package/dist/links.js +57 -4
- 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 +4 -5
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +7 -28
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +33 -30
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +46 -77
- package/dist/stream.d.ts +10 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +139 -98
- package/dist/transport.d.ts +35 -14
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +0 -2
- 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 +11 -6
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +19 -20
- package/package.json +3 -3
package/AGENTS.md
CHANGED
|
@@ -7,9 +7,19 @@ 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,
|
|
11
|
-
|
|
12
|
-
|
|
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,
|
|
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.
|
|
13
23
|
|
|
14
24
|
Every `observe` resolves, once its first value has arrived, to a handle:
|
|
15
25
|
`current()` is the latest complete value, `subscribe(listener)` hears each later
|
|
@@ -17,29 +27,29 @@ value whole and returns its unsubscribe, and `close()` ends the observation.
|
|
|
17
27
|
Closing the port ends every handle and rejects every pending call and
|
|
18
28
|
observation; a client that reconnects observes again.
|
|
19
29
|
|
|
20
|
-
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`.
|
|
21
35
|
Observe one with `observe('conversation', id, { limit })`: the view
|
|
22
36
|
holds its latest `limit` messages, or all of them, oldest first, its chat
|
|
23
37
|
draft, and what the Provider streams for it whether or not anything views it:
|
|
24
|
-
the
|
|
25
|
-
state, the CLI's commands and options
|
|
26
|
-
only in memory: the turn's
|
|
27
|
-
|
|
28
|
-
searchable.
|
|
38
|
+
the running `turn` with its message parts and its context in use and window, the
|
|
39
|
+
open questions, the process state, and the CLI's commands and options. These live
|
|
40
|
+
only in memory: the message accepted under the turn's id replaces the running turn,
|
|
41
|
+
and none of them is stored or searchable.
|
|
29
42
|
`chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
|
|
30
43
|
sending it is a Provider Action that needs the Provider reachable and is never
|
|
31
44
|
queued.
|
|
32
45
|
|
|
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
46
|
Each Room in Rooms lists its `attachments`, the files the Provider holds for it
|
|
37
47
|
that its Documents link by the Provider's reference, ordered by `reference`,
|
|
38
48
|
each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
|
|
39
49
|
`entry`. They are as the Provider last declared them and hold no bytes;
|
|
40
50
|
open one through the Provider Action that serves it.
|
|
41
51
|
|
|
42
|
-
Rooms,
|
|
52
|
+
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
43
53
|
touch the network.
|
|
44
54
|
History and Call go to the Provider through the Adapter. A Call result whose
|
|
45
55
|
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
@@ -47,15 +57,17 @@ effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
|
47
57
|
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
48
58
|
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
49
59
|
that document was written at a later Room Version. Each History revision
|
|
50
|
-
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
|
|
51
64
|
member of the
|
|
52
65
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
53
66
|
surface returns the authorization, performs a request the App's code
|
|
54
67
|
composes, or exposes the browser store.
|
|
55
68
|
|
|
56
|
-
Read deployment facts with `
|
|
57
|
-
|
|
58
|
-
host's contract.
|
|
69
|
+
Read the deployment facts with `observe('deployment-facts')`. Interpret the
|
|
70
|
+
opaque value using the host's contract.
|
|
59
71
|
|
|
60
72
|
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
61
73
|
ships in no bundle.
|
|
@@ -70,22 +82,28 @@ data:
|
|
|
70
82
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
71
83
|
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
72
84
|
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
73
|
-
- **Fields.**
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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:
|
|
77
92
|
`$exists: false` keeps a missing field, `null` an explicit null, `''` empty
|
|
78
93
|
text and `$size: 0` an empty list. A date compares in calendar order and never
|
|
79
94
|
with a date-time. A reference compares by the Room Path it resolves to.
|
|
80
|
-
Untyped frontmatter
|
|
95
|
+
Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
|
|
96
|
+
values. There is no text containment or regular
|
|
81
97
|
expression.
|
|
82
98
|
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
83
|
-
reference `field
|
|
84
|
-
`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
|
|
85
101
|
matching Document of the same Room references. Each keeps a Document once.
|
|
86
102
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
87
|
-
`preamble`, `markdown`, `backlinks` and `change`, where `fields`
|
|
88
|
-
|
|
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
|
|
89
107
|
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
90
108
|
target returns only Room and Path. An unselected part is absent. Select only
|
|
91
109
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
@@ -99,8 +117,8 @@ data:
|
|
|
99
117
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
100
118
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
101
119
|
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
102
|
-
over every match and ordered by `count` or a key.
|
|
103
|
-
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.
|
|
104
122
|
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
105
123
|
Rooms and Sync Status. An invalid query fails with `invalid-query`,
|
|
106
124
|
`unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
|
|
@@ -114,7 +132,7 @@ search.
|
|
|
114
132
|
|
|
115
133
|
- **What is found.** A Document by its field values, its sections' headings and
|
|
116
134
|
text, its preamble and its Path; a message by its text. Frontmatter keys, Room
|
|
117
|
-
Drafts, chat drafts and
|
|
135
|
+
Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
|
|
118
136
|
word forms, typo tolerance or prefix matching.
|
|
119
137
|
- **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
|
|
120
138
|
`pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
|
|
@@ -130,7 +148,7 @@ search.
|
|
|
130
148
|
|
|
131
149
|
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
132
150
|
tab. It is durable: it survives reload and navigation. A Room that Discovery
|
|
133
|
-
stops listing takes its Room Drafts
|
|
151
|
+
stops listing takes its Room Drafts and its queue with it.
|
|
134
152
|
Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
|
|
135
153
|
the revision you read, or `null` when there was none, and every part it should
|
|
136
154
|
now change: fields, sections and the preamble, or the whole Markdown, a
|
|
@@ -150,20 +168,21 @@ each Document and binary link target beneath it, saved together.
|
|
|
150
168
|
|
|
151
169
|
Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
|
|
152
170
|
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
|
|
171
|
+
Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
|
|
154
172
|
longer applies over the Room each leave the queue and return as Room Drafts on
|
|
155
173
|
the Documents they changed, marked with why: the Provider's structured refusal
|
|
156
174
|
code and fields as returned, not known to have applied, or withdrawn locally.
|
|
157
175
|
The rest of the queue keeps synchronizing, and Sync Status requires attention
|
|
158
|
-
until each returned Room Draft is saved again or discarded.
|
|
159
|
-
|
|
176
|
+
until each returned Room Draft is saved again or discarded. A Change Batch
|
|
177
|
+
keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
|
|
178
|
+
Pending one, and a returned Room Draft says why it returned. Transport
|
|
160
179
|
failure and Provider unavailability keep work Pending and do not infer a
|
|
161
180
|
rejection. A refusal the Provider marks retryable stays Pending until the reset
|
|
162
181
|
it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
163
182
|
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
164
183
|
combines, reorders, or rebases.
|
|
165
184
|
|
|
166
|
-
`
|
|
185
|
+
`observe('service-mode')` answers the Provider's Service
|
|
167
186
|
Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
|
|
168
187
|
its Change Batch waits unsent, and the queue is submitted in order once the
|
|
169
188
|
Provider reopens writes. An Action is never held: a write the Provider refuses
|
|
@@ -196,13 +215,28 @@ an App's override respected. What an App Creator's agent adds carries none
|
|
|
196
215
|
of these promises by itself. Reading, querying and searching never wait for
|
|
197
216
|
the network. Data lives only in the App Creator's browser and with the Provider.
|
|
198
217
|
|
|
199
|
-
## App code
|
|
200
|
-
|
|
201
|
-
App code
|
|
202
|
-
`
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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`.
|
|
206
240
|
|
|
207
241
|
## What an agent must never do
|
|
208
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,
|
|
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,74 +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
|
-
|
|
32
|
-
function
|
|
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
|
-
|
|
36
|
+
notifications.reach(entry.authority, scope);
|
|
37
|
+
const models = await scopeModels(scope, entry);
|
|
38
|
+
return { ...bootstrapOf(scope), ...(models === undefined ? {} : { models }) };
|
|
38
39
|
}
|
|
39
|
-
function enumeratedRoom(enumeration, ask) {
|
|
40
|
+
async function enumeratedRoom(enumeration, ask) {
|
|
40
41
|
const view = viewOf(enumeration, ask.entry);
|
|
41
42
|
if (view === undefined)
|
|
42
43
|
return { kind: 'room-not-readable', locator: ask.entry.locator };
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
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 };
|
|
48
51
|
}
|
|
49
|
-
function streamed(entry, request, from) {
|
|
52
|
+
async function streamed(entry, request, from) {
|
|
50
53
|
const links = handed.get(entry.locator);
|
|
51
54
|
if (links?.roomVersion !== request.fromRoomVersion)
|
|
52
55
|
return null;
|
|
53
|
-
const advanced = notifications.advance(entry, from);
|
|
56
|
+
const advanced = notifications.advance(entry, from, (path, revision) => links.revisions.get(path) === revision);
|
|
54
57
|
if (advanced === null)
|
|
55
58
|
return null;
|
|
56
|
-
if (request.minPosition !== undefined &&
|
|
57
|
-
!reachedVersion(advanced.page.roomVersion, request.minPosition, entry.logEpoch))
|
|
58
|
-
return null;
|
|
59
59
|
const relinked = streamedLinks(links, advanced);
|
|
60
60
|
if (relinked === null)
|
|
61
61
|
return null;
|
|
62
62
|
handed.set(entry.locator, relinked);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
function held(envelope, entry, schema, failure) {
|
|
66
|
-
return heldModel(envelope === null ? null : schemaFrom(envelope, entry, schema), schemaPath(entry.handle, schema), failure);
|
|
67
|
-
}
|
|
68
|
-
function modelPrefixes(entry) {
|
|
69
|
-
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 };
|
|
70
65
|
}
|
|
71
|
-
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
acquired.set(modelKey(entry.locator, 'collection'), await held(envelope, entry, entry.schema, failure));
|
|
83
|
-
}
|
|
84
|
-
if (privateEntry !== undefined) {
|
|
85
|
-
acquired.set(modelKey(privateEntry.locator, 'typed-selection'), await held(envelope, privateEntry, HOUSE_SCHEMA, failure));
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
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);
|
|
89
77
|
}
|
|
90
|
-
function
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const
|
|
98
|
-
|
|
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 };
|
|
99
94
|
}
|
|
100
95
|
function authorityFor(locator) {
|
|
101
96
|
return tracked.get(locator);
|
|
@@ -109,9 +104,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
109
104
|
const { authority, position, log_epoch: logEpoch } = body;
|
|
110
105
|
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
111
106
|
return result;
|
|
112
|
-
const locator = authority ===
|
|
113
|
-
? PRIVATE_LOCATOR
|
|
114
|
-
: [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
107
|
+
const locator = [...tracked.values()].find((entry) => entry.authority === authority)?.locator;
|
|
115
108
|
if (locator === undefined)
|
|
116
109
|
return result;
|
|
117
110
|
return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
|
|
@@ -135,20 +128,20 @@ export function createAgentsHouseAdapter(options) {
|
|
|
135
128
|
}
|
|
136
129
|
async function bootstrapped(entries) {
|
|
137
130
|
const answers = [];
|
|
138
|
-
for (const part of selections(entries, weight,
|
|
131
|
+
for (const part of selections(entries, weight, declared().max_prefixes)) {
|
|
139
132
|
const answer = await transport.door(DOOR_BOOTSTRAP, {
|
|
140
133
|
prefixes: part.flatMap((entry) => contentPrefixes(entry)),
|
|
141
134
|
});
|
|
142
135
|
const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
|
|
143
136
|
const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
|
|
144
|
-
part.
|
|
137
|
+
for (const [index, entry] of part.entries()) {
|
|
145
138
|
const failure = classified[index];
|
|
146
139
|
if (failure === null || failure === undefined) {
|
|
147
|
-
answers.push(envelope === null ? UNCERTAIN_READ : bootstrappedRoom(envelope, entry));
|
|
148
|
-
|
|
140
|
+
answers.push(envelope === null ? UNCERTAIN_READ : await bootstrappedRoom(envelope, entry));
|
|
141
|
+
continue;
|
|
149
142
|
}
|
|
150
|
-
answers.push(failure
|
|
151
|
-
}
|
|
143
|
+
answers.push(failure);
|
|
144
|
+
}
|
|
152
145
|
}
|
|
153
146
|
return answers;
|
|
154
147
|
}
|
|
@@ -164,27 +157,15 @@ export function createAgentsHouseAdapter(options) {
|
|
|
164
157
|
}
|
|
165
158
|
async function enumerated(asks) {
|
|
166
159
|
const answers = new Map();
|
|
167
|
-
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry),
|
|
160
|
+
const parts = layered(asks).flatMap((layer) => selections(layer, (ask) => weight(ask.entry), declared().max_prefixes));
|
|
168
161
|
for (const part of parts) {
|
|
169
162
|
let open = [...part];
|
|
170
163
|
while (open.length > 0) {
|
|
171
164
|
const answer = await transport.door(DOOR_ENUMERATE, {
|
|
172
165
|
prefixes: open.flatMap((ask) => contentPrefixes(ask.entry)),
|
|
173
|
-
positions: open.map((ask) => (
|
|
174
|
-
...presented(ask.entry.authority, ask.from),
|
|
175
|
-
...(ask.minPosition === undefined ? {} : { min_position: ask.minPosition }),
|
|
176
|
-
})),
|
|
166
|
+
positions: open.map((ask) => presented(ask.entry.authority, ask.from)),
|
|
177
167
|
});
|
|
178
|
-
const
|
|
179
|
-
if (refusal?.code === 'replica_behind') {
|
|
180
|
-
const named = open.filter((ask) => ask.entry.authority === refusal.fields.authority);
|
|
181
|
-
const behind = named.length === 0 ? open : named;
|
|
182
|
-
for (const ask of behind)
|
|
183
|
-
answers.set(ask, { kind: 'retryable-refusal', ...refusal });
|
|
184
|
-
open = open.filter((ask) => !behind.includes(ask));
|
|
185
|
-
continue;
|
|
186
|
-
}
|
|
187
|
-
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));
|
|
188
169
|
if (classified[0]?.kind === 'beyond-horizon') {
|
|
189
170
|
const named = doorRefusal(answer.body)?.fields.authority;
|
|
190
171
|
const expired = open.filter((ask) => ask.entry.authority === named);
|
|
@@ -196,14 +177,14 @@ export function createAgentsHouseAdapter(options) {
|
|
|
196
177
|
continue;
|
|
197
178
|
}
|
|
198
179
|
const enumeration = classified[0] === null ? parseEnumeration(answer.body, 'credential') : null;
|
|
199
|
-
open.
|
|
180
|
+
for (const [index, ask] of open.entries()) {
|
|
200
181
|
const failure = classified[index];
|
|
201
182
|
if (failure !== null && failure !== undefined) {
|
|
202
183
|
answers.set(ask, failure);
|
|
203
|
-
|
|
184
|
+
continue;
|
|
204
185
|
}
|
|
205
|
-
answers.set(ask, enumeration === null ? UNCERTAIN_READ : enumeratedRoom(enumeration, ask));
|
|
206
|
-
}
|
|
186
|
+
answers.set(ask, enumeration === null ? UNCERTAIN_READ : await enumeratedRoom(enumeration, ask));
|
|
187
|
+
}
|
|
207
188
|
open = [];
|
|
208
189
|
}
|
|
209
190
|
}
|
|
@@ -215,7 +196,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
215
196
|
const paths = batchPaths(changes);
|
|
216
197
|
const sha256 = await deltaDigest(delta);
|
|
217
198
|
if (handed !== undefined && handed.sha256 === sha256) {
|
|
218
|
-
return { body: { ...head, paths, upload: handed } };
|
|
199
|
+
return { body: { ...head, paths, upload: handed, runtime: notifications.runtime } };
|
|
219
200
|
}
|
|
220
201
|
const minted = await transport.door(DOOR_BATCH_UPLOAD, { ...head, paths, bytes, sha256 });
|
|
221
202
|
if (minted.status !== 200) {
|
|
@@ -238,12 +219,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
238
219
|
return { outcome: UNCERTAIN };
|
|
239
220
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
240
221
|
await keep(upload);
|
|
241
|
-
return { body: { ...head, paths, upload } };
|
|
222
|
+
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
242
223
|
}
|
|
243
224
|
async function submit(head, changes, delta, bytes, entry, handed, keep) {
|
|
244
|
-
const
|
|
225
|
+
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
226
|
+
const prepared = uploadable(inline, bytes, declared())
|
|
245
227
|
? await uploaded(head, changes, delta, bytes, entry, handed, keep)
|
|
246
|
-
: { body:
|
|
228
|
+
: { body: inline };
|
|
247
229
|
if ('outcome' in prepared)
|
|
248
230
|
return prepared.outcome;
|
|
249
231
|
const answer = await transport.door(DOOR_BATCH, prepared.body);
|
|
@@ -253,17 +235,15 @@ export function createAgentsHouseAdapter(options) {
|
|
|
253
235
|
async authorize() {
|
|
254
236
|
return options.authorize();
|
|
255
237
|
},
|
|
256
|
-
async model(_authorization, request) {
|
|
257
|
-
return models.answer(request);
|
|
258
|
-
},
|
|
259
238
|
async discover(_authorization) {
|
|
260
239
|
const answer = await transport.door(DOOR_DISCOVER, { prefixes: [...DISCOVER_PREFIXES] });
|
|
261
|
-
const
|
|
262
|
-
if (
|
|
263
|
-
return
|
|
240
|
+
const failed = discoveryFailure(answer.status, answer.body);
|
|
241
|
+
if (failed !== null)
|
|
242
|
+
return failed;
|
|
264
243
|
const document = parseDiscovery(answer.body);
|
|
265
244
|
if (document === null)
|
|
266
245
|
return { kind: 'transport-uncertainty' };
|
|
246
|
+
bounds = document.bounds;
|
|
267
247
|
const entries = trackedFrom(document);
|
|
268
248
|
tracked.clear();
|
|
269
249
|
for (const entry of entries)
|
|
@@ -272,9 +252,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
272
252
|
if (!tracked.has(locator))
|
|
273
253
|
handed.delete(locator);
|
|
274
254
|
notifications.track(entries);
|
|
275
|
-
|
|
276
|
-
models.keep(entries.map((entry) => entry.locator));
|
|
277
|
-
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));
|
|
278
256
|
},
|
|
279
257
|
async bootstrap(_authorization, request) {
|
|
280
258
|
const entry = authorityFor(request.locator);
|
|
@@ -293,16 +271,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
293
271
|
const from = logPosition(request.fromRoomVersion);
|
|
294
272
|
if (from === null)
|
|
295
273
|
return { kind: 'beyond-horizon' };
|
|
296
|
-
const answered = streamed(entry, request, from);
|
|
274
|
+
const answered = await streamed(entry, request, from);
|
|
297
275
|
if (answered !== null)
|
|
298
276
|
return answered;
|
|
299
|
-
|
|
300
|
-
return enumerateTogether({
|
|
301
|
-
entry,
|
|
302
|
-
from,
|
|
303
|
-
fromRoomVersion: request.fromRoomVersion,
|
|
304
|
-
...(minPosition?.logEpoch === from.logEpoch ? { minPosition: minPosition.position } : {}),
|
|
305
|
-
});
|
|
277
|
+
return enumerateTogether({ entry, from, fromRoomVersion: request.fromRoomVersion });
|
|
306
278
|
},
|
|
307
279
|
async mutate(_authorization, request, keep) {
|
|
308
280
|
const entry = authorityFor(request.locator);
|
|
@@ -317,8 +289,8 @@ export function createAgentsHouseAdapter(options) {
|
|
|
317
289
|
const handed = request.upload;
|
|
318
290
|
const outcome = await submit(head, mapped.changes, delta, bytes, entry, handed, keep);
|
|
319
291
|
if (handed === undefined || !lapsedGrant(outcome))
|
|
320
|
-
return outcome;
|
|
321
|
-
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));
|
|
322
294
|
},
|
|
323
295
|
async history(_authorization, request) {
|
|
324
296
|
const entry = authorityFor(request.locator);
|
|
@@ -338,10 +310,13 @@ export function createAgentsHouseAdapter(options) {
|
|
|
338
310
|
reached(locator, version, target) {
|
|
339
311
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
|
340
312
|
},
|
|
313
|
+
follows(_locator, version, next) {
|
|
314
|
+
return followsVersion(version, next);
|
|
315
|
+
},
|
|
341
316
|
async action(_authorization, request) {
|
|
342
317
|
return withAt(await houseAction(transport, request));
|
|
343
318
|
},
|
|
344
|
-
|
|
319
|
+
roomStream: { hold: held, observe: notifications.observe },
|
|
345
320
|
conversations: notifications.conversations,
|
|
346
321
|
serviceMode: notifications.serviceMode,
|
|
347
322
|
};
|