@agentshouse/mdruntime-adapter 0.1.0-cf22c8563f9f4 → 0.1.0-cf6a7cf003c4b

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
@@ -10,7 +10,7 @@ App code reaches the MD Runtime through the remote client. The surfaces are
10
10
  Rooms, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
11
  the reported persistence answer, reauthorization, conversation, the chat draft,
12
12
  and Presentation State. Sync Status, the Service Mode, the storage-loss
13
- statement and the deployment facts are observations only.
13
+ statement, the deployment facts and the signed-in member are observations only.
14
14
 
15
15
  The host attaches each port with its reach, and every member and observation
16
16
  answers within it: a Room outside it answers as one the replica does not hold,
@@ -51,7 +51,9 @@ open one through the Provider Action that serves it.
51
51
 
52
52
  Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
53
53
  touch the network.
54
- History and Call go to the Provider through the Adapter. A Call result whose
54
+ History and Call go to the Provider through the Adapter. Call takes the Action names
55
+ the Adapter declares; any other name answers `undeclared` without reaching the
56
+ Provider. A Call result whose
55
57
  effect the Provider places in a Room carries `at`, that Room and Room Version;
56
58
  `reached(room, roomVersion)` answers whether the Room's confirmed state has
57
59
  reached it, and the MD Runtime keeps refreshing that Room until it has;
@@ -66,9 +68,25 @@ client is asynchronous. Results are detached snapshots. Nothing in this
66
68
  surface returns the authorization, performs a request the App's code
67
69
  composes, or exposes the browser store.
68
70
 
71
+ Every refusal and failure carries `code` and `retryable`: each Call and History answer
72
+ other than its result, a refused Save or Room Draft write, a returned Room Draft's
73
+ reason, a Room's refusal and the Connection Refusal, and every error a member rejects
74
+ with, beside its message. A Provider refusal carries the Provider's own `retryable`.
75
+ Every code and every value the API answers is open: handle one you do not know by its
76
+ `code` and `retryable`.
77
+
69
78
  Read the deployment facts with `observe('deployment-facts')`. Interpret the
70
79
  opaque value using the host's contract.
71
80
 
81
+ `observe('member')` answers who uses the App: the User the Provider signed in,
82
+ `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
83
+ whose `change.author.id` equals its `id` is that User's own. It is `null` until
84
+ the Provider first names one, and where it names none, such as a Site. The
85
+ MD Runtime keeps it with the Local Replicas, so it answers offline once known,
86
+ and every port hears the next member the Provider names; signing out answers
87
+ `null`, then ends the observation with the authorization. It is the only way App code learns who
88
+ uses it.
89
+
72
90
  The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
73
91
  ships in no bundle.
74
92
 
@@ -112,7 +130,7 @@ data:
112
130
  or `null` for a write the Provider made itself, and `time` is the Provider's
113
131
  ISO 8601 change time. It is `null` where the Provider delivered no time, as at
114
132
  a Site. An unsent edit or move keeps it, an unsent creation has none, and a
115
- saved write takes the Provider's own once it is Accepted and refreshed. A
133
+ saved write takes the Provider's own once it is Accepted. A
116
134
  Room's last change is its Document with the latest `time`.
117
135
  - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
118
136
  with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
@@ -120,9 +138,9 @@ data:
120
138
  over every match and ordered by `count` or a key. A sort or group takes only a
121
139
  pointer that holds one value. `limit` bounds the Documents or the groups.
122
140
  - **Results and errors.** A result carries no Room Version: read freshness from
123
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
124
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
125
- answers an empty result in its place.
141
+ Rooms and Sync Status. An invalid query fails with the `code`
142
+ `invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
143
+ and never answers an empty result in its place.
126
144
 
127
145
  ## Local Search rules
128
146
 
@@ -160,9 +178,9 @@ the current Room Draft; read it and write again.
160
178
 
161
179
  Save takes one Room and the Room Drafts of it to save, each with its revision,
162
180
  validates locally, and on success appends one Change Batch to that Room's
163
- queue and removes those Room Drafts. It is refused as `stale`, as
181
+ queue and removes those Room Drafts. It is refused with the `code` `stale`,
164
182
  `changed-underneath` naming each part whose base no longer matches the visible
165
- state, or by a local validation rule, and then creates nothing and leaves every
183
+ state, or a local validation rule, and then creates nothing and leaves every
166
184
  Room Draft in place. A directory move or removal is a move or removal part on
167
185
  each Document and binary link target beneath it, saved together.
168
186
 
@@ -182,6 +200,13 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
182
200
  never infers an outcome from transport uncertainty. The MD Runtime never
183
201
  combines, reorders, or rebases.
184
202
 
203
+ On a Site, every Save stays in the visitor's browser. Write grants and
204
+ revisions do not refuse it, and its Pending Change shows in every query and
205
+ across reloads until the browser's storage is cleared. It is never sent:
206
+ `observe('queue', room)` shows it `local`, and Sync Status never waits on it.
207
+ Once the Room changes so that it no longer applies, it leaves the queue and
208
+ returns no Room Draft.
209
+
185
210
  `observe('service-mode')` answers the Provider's Service
186
211
  Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
187
212
  its Change Batch waits unsent, and the queue is submitted in order once the
@@ -218,7 +243,7 @@ the network. Data lives only in the App Creator's browser and with the Provider.
218
243
  ## App code takes the client its host hands it and never constructs a Runtime
219
244
 
220
245
  App code takes the client its host hands it: in House,
221
- `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
246
+ `houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
222
247
  client House built into the page. It never constructs a Runtime or a client.
223
248
  It imports only types from `@agentshouse/mdruntime/client`, does not call
224
249
  `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
@@ -227,9 +252,9 @@ served App does not.
227
252
 
228
253
  A React App may observe and save through `@agentshouse/mdruntime/react`, which
229
254
  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
255
+ the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
256
+ first value arrives, then `{ state: 'ready', value }`, re-rendering on each
257
+ change; a `null` client observes nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
233
258
  `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
234
259
  already there, keeping the bases its parts have, or onto a new one, and saves
235
260
  them together. A refused Save leaves the Room Drafts for the App to save again
package/dist/actions.d.ts CHANGED
@@ -1,8 +1,46 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents } from '@agentshouse/mdruntime';
1
+ import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents, type ConversationHistories, type ConversationHistoryRequest, type FileDeclaration } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
+ type Operated = {
4
+ readonly operation_id?: string;
5
+ };
6
+ type ConversationControl = Operated & {
7
+ readonly conversation: string;
8
+ };
9
+ type SentFile = FileDeclaration & {
10
+ readonly blob: Blob;
11
+ };
12
+ export type AppInputs = {
13
+ readonly 'conversation.answer': ConversationControl & {
14
+ readonly answer: {
15
+ readonly interaction_id: string;
16
+ readonly response: unknown;
17
+ };
18
+ };
19
+ readonly 'conversation.create': Operated & {
20
+ readonly agent_id: string;
21
+ };
22
+ readonly 'conversation.delete': ConversationControl;
23
+ readonly 'conversation.history': ConversationHistoryRequest;
24
+ readonly 'conversation.interrupt': ConversationControl;
25
+ readonly 'conversation.kill': ConversationControl;
26
+ readonly 'conversation.send': ConversationControl & {
27
+ readonly text?: string;
28
+ readonly files?: readonly SentFile[];
29
+ };
30
+ };
31
+ export type AppAnswers = {
32
+ readonly 'conversation.history': ConversationHistories;
33
+ };
34
+ export type AppAnswerAdditions = {
35
+ readonly 'conversation.send': {
36
+ readonly turn: string;
37
+ };
38
+ };
39
+ export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
3
40
  export declare function houseConversationAgents(locator: string): ConversationAgents;
4
41
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
5
42
  export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
6
43
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
7
44
  export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
45
+ export {};
8
46
  //# sourceMappingURL=actions.d.ts.map
@@ -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,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"}
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,EACvB,KAAK,qBAAqB,EAE1B,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQtE,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,KAAK,mBAAmB,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,KAAK,QAAQ,GAAG,eAAe,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC;AAE1D,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,GAAG;QACpD,QAAQ,CAAC,MAAM,EAAE;YAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;SAAE,CAAC;KAClF,CAAC;IACF,QAAQ,CAAC,qBAAqB,EAAE,QAAQ,GAAG;QAAE,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IACzE,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,CAAC;IACpD,QAAQ,CAAC,sBAAsB,EAAE,0BAA0B,CAAC;IAC5D,QAAQ,CAAC,wBAAwB,EAAE,mBAAmB,CAAC;IACvD,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAClD,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,GAAG;QAClD,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QACvB,QAAQ,CAAC,KAAK,CAAC,EAAE,SAAS,QAAQ,EAAE,CAAC;KACtC,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,mBAAmB,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACzD,CAAC;AAkEF,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3D,CAAC;AAMF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAMvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA2DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAOjF;AAqJD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
package/dist/actions.js CHANGED
@@ -3,44 +3,72 @@ import { doorRefusal } from './refusal.js';
3
3
  const HISTORY_PAGE = 100;
4
4
  const HISTORY_CONVERSATIONS = 64;
5
5
  const OCTET_STREAM = 'application/octet-stream';
6
- const CONVERSATION_ROUTES = new Map([
7
- ['conversation.create', '/door/conversations/create'],
8
- ['conversation.send', '/door/conversations/send'],
9
- ['conversation.answer', '/door/conversations/interaction/answer'],
10
- ['conversation.interrupt', '/door/conversations/interrupt'],
11
- ['conversation.kill', '/door/conversations/kill'],
12
- ['conversation.delete', '/door/conversations/delete'],
13
- ['conversation.history', '/door/conversations/history'],
14
- ]);
6
+ function mapped(door, input = (given) => given) {
7
+ return {
8
+ door,
9
+ async carry(transport, given, name) {
10
+ return actionOutcome(await transport.door(`/door/${door}`, input(given)), name);
11
+ },
12
+ };
13
+ }
14
+ function carried(door, carry) {
15
+ return {
16
+ door,
17
+ carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
18
+ };
19
+ }
20
+ const APP_ACTS = {
21
+ 'access.read': mapped('rooms/access/read'),
22
+ 'conversation.answer': mapped('conversations/interaction/answer', answerBody),
23
+ 'conversation.create': mapped('conversations/create', createBody),
24
+ 'conversation.delete': mapped('conversations/delete', controlBody),
25
+ 'conversation.history': carried('conversations/history', historyAction),
26
+ 'conversation.interrupt': mapped('conversations/interrupt', controlBody),
27
+ 'conversation.kill': mapped('conversations/kill', controlBody),
28
+ 'conversation.markDone': mapped('conversations/done'),
29
+ 'conversation.rename': mapped('conversations/rename'),
30
+ 'conversation.send': carried('conversations/send', sendAction),
31
+ 'conversation.setOption': mapped('conversations/option'),
32
+ 'feature.list': mapped('apps/features/read'),
33
+ 'holder.list': mapped('apps/holders'),
34
+ 'holder.ring': mapped('apps/ring'),
35
+ 'member.list': mapped('rooms/members'),
36
+ 'message.send': mapped('apps/messages/send'),
37
+ 'processing.read': mapped('rooms/settings/processing/read'),
38
+ 'record.list': mapped('records/read'),
39
+ 'relay.read': mapped('apps/relay'),
40
+ 'routine.list': mapped('routines/access'),
41
+ 'routineAccess.list': mapped('routines/granted'),
42
+ 'routineAllowance.list': mapped('routines/allowance'),
43
+ 'routineRequest.list': mapped('routines/requests'),
44
+ 'storage.read': mapped('storage/inventory'),
45
+ 'trigger.list': mapped('triggers/read'),
46
+ 'triggerOccurrence.list': mapped('triggers/fired'),
47
+ };
48
+ export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
49
+ const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
15
50
  export function houseConversationAgents(locator) {
16
51
  return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
17
52
  }
18
53
  export function declaredActions(routes) {
19
- const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
20
54
  return routes.map((route) => ({
21
- name: mapped.get(route) ?? route,
55
+ name: APP_NAMES.get(route) ?? route,
22
56
  inputShape: {},
23
57
  resultKind: 'house',
24
58
  }));
25
59
  }
26
60
  export function houseAction(transport, request) {
27
- if (request.name === 'conversation.send')
28
- return sendAction(transport, request.input);
29
- if (request.name === 'conversation.history')
30
- return historyAction(transport, request.input);
31
- if (request.name === 'attachments/upload')
32
- return attachAction(transport, request.input);
33
- if (request.name === 'attachments/get')
34
- return openAction(transport, request.input);
61
+ if (Object.hasOwn(APP_ACTS, request.name)) {
62
+ return APP_ACTS[request.name].carry(transport, request.input, request.name);
63
+ }
64
+ if (APP_NAMES.has(request.name))
65
+ return Promise.resolve(unimplemented(request.name));
35
66
  const route = routeOf(request.name);
36
67
  if (route === null)
37
68
  return Promise.resolve(malformed());
38
69
  return carry(transport, route, request.name, request.input);
39
70
  }
40
71
  function routeOf(name) {
41
- const mapped = CONVERSATION_ROUTES.get(name);
42
- if (mapped !== undefined)
43
- return mapped;
44
72
  const parts = name.split('/');
45
73
  if (parts.some((part) => part === '.' || part === '..'))
46
74
  return null;
@@ -62,51 +90,47 @@ function operationId(input) {
62
90
  return text(input, 'operation_id') ?? changeBatchIdentity();
63
91
  }
64
92
  function malformed() {
65
- return { kind: 'rejected', code: 'invalid_request', fields: {} };
93
+ return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
66
94
  }
67
- function bodyOf(name, input) {
68
- if (name === 'conversation.create') {
69
- return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
70
- }
71
- if (name === 'conversation.interrupt' ||
72
- name === 'conversation.kill' ||
73
- name === 'conversation.delete') {
74
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
75
- }
76
- if (name === 'conversation.answer') {
77
- const nested = record(record(input).answer);
78
- return {
79
- conversation_id: text(input, 'conversation'),
80
- operation_id: operationId(input),
81
- interaction_id: text(nested, 'interaction_id'),
82
- response: nested.response,
83
- };
84
- }
85
- return input;
95
+ function unimplemented(name) {
96
+ return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
97
+ }
98
+ function createBody(input) {
99
+ return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
100
+ }
101
+ function controlBody(input) {
102
+ return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
103
+ }
104
+ function answerBody(input) {
105
+ const nested = record(record(input).answer);
106
+ return {
107
+ conversation_id: text(input, 'conversation'),
108
+ operation_id: operationId(input),
109
+ interaction_id: text(nested, 'interaction_id'),
110
+ response: nested.response,
111
+ };
86
112
  }
87
113
  function withTurn(body) {
88
114
  const held = record(body);
89
115
  const turn = text(held, 'message_id');
90
- return turn === undefined ? body : { ...held, turn };
116
+ return turn === undefined
117
+ ? body
118
+ : { ...held, turn };
91
119
  }
92
120
  export function actionOutcome(answer, name) {
93
121
  if (answer.status === 401)
94
122
  return { kind: 'revoked-authorization' };
95
123
  const refusal = doorRefusal(answer.body);
96
- if (refusal !== null) {
97
- return { kind: 'rejected', code: refusal.code, fields: refusal.fields };
98
- }
124
+ if (refusal !== null)
125
+ return { kind: 'rejected', ...refusal };
99
126
  if (answer.status === 404)
100
- return { kind: 'rejected', code: 'action-unimplemented', fields: { name } };
127
+ return unimplemented(name);
101
128
  if (answer.status === 0 || answer.status >= 400)
102
129
  return { kind: 'transport-uncertainty' };
103
- if (name === 'conversation.send')
104
- return { kind: 'action', result: withTurn(answer.body) };
105
130
  return { kind: 'action', result: answer.body };
106
131
  }
107
132
  async function carry(transport, route, name, input) {
108
- const answer = await transport.door(route, bodyOf(name, input));
109
- return actionOutcome(answer, name);
133
+ return actionOutcome(await transport.door(route, input), name);
110
134
  }
111
135
  function sendFile(entry) {
112
136
  const file = record(entry);
@@ -176,12 +200,12 @@ function uploadGrant(entry) {
176
200
  return null;
177
201
  return { method: 'POST', operation: upload.operation, url: upload.url };
178
202
  }
179
- async function uploadOriginals(transport, input, result) {
180
- const originals = record(result).originals;
181
- if (!Array.isArray(originals) || originals.length === 0)
203
+ async function uploadFiles(transport, input, result, name) {
204
+ const sent = record(result).files;
205
+ if (!Array.isArray(sent) || sent.length === 0)
182
206
  return null;
183
207
  const files = Array.isArray(record(input).files) ? record(input).files : [];
184
- for (const [index, entry] of originals.entries()) {
208
+ for (const [index, entry] of sent.entries()) {
185
209
  const grant = uploadGrant(entry);
186
210
  if (grant === 'absent')
187
211
  continue;
@@ -189,81 +213,35 @@ async function uploadOriginals(transport, input, result) {
189
213
  return malformed();
190
214
  const bytes = index < files.length ? await fileBytes(files[index]) : null;
191
215
  if (bytes === null) {
192
- return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };
216
+ return {
217
+ kind: 'rejected',
218
+ code: 'conversation_file_descriptor_required',
219
+ fields: {},
220
+ retryable: false,
221
+ };
193
222
  }
194
223
  const failed = delivered(await transport.transfer({
195
- act: 'conversation_original_upload',
196
- method: 'POST',
224
+ act: 'conversation_file_upload',
197
225
  url: grant.url,
198
- answer: 'json',
199
226
  body: bytes,
200
227
  operation: grant.operation,
201
- }), 'conversation.send');
228
+ }), name);
202
229
  if (failed !== null)
203
230
  return failed;
204
231
  }
205
232
  return null;
206
233
  }
207
- async function attachAction(transport, input) {
208
- const { blob, ...descriptor } = record(input);
209
- const bytes = await fileBytes({ blob });
210
- if (bytes === null)
211
- return malformed();
212
- const answer = await transport.door('/door/attachments/upload', descriptor);
213
- const outcome = actionOutcome(answer, 'attachments/upload');
214
- if (outcome.kind !== 'action')
215
- return outcome;
216
- const grant = uploadGrant(outcome.result);
217
- if (grant === 'absent')
218
- return outcome;
219
- if (grant === null)
220
- return malformed();
221
- const stored = await transport.transfer({
222
- act: 'original_upload',
223
- method: 'POST',
224
- url: grant.url,
225
- answer: 'json',
226
- body: bytes,
227
- operation: grant.operation,
228
- });
229
- return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };
230
- }
231
- async function openAction(transport, input) {
232
- const answer = await transport.door('/door/attachments/get', input);
233
- const outcome = actionOutcome(answer, 'attachments/get');
234
- if (outcome.kind !== 'action')
235
- return outcome;
236
- const { download, ...opened } = record(outcome.result);
237
- if (download === undefined)
238
- return outcome;
239
- const grant = record(download);
240
- if (grant.method !== 'GET' || typeof grant.url !== 'string')
241
- return malformed();
242
- const read = await transport.transfer({
243
- act: 'original_download',
244
- method: 'GET',
245
- url: grant.url,
246
- answer: 'bytes',
247
- });
248
- const failed = delivered(read, 'attachments/get');
249
- if (failed !== null)
250
- return failed;
251
- if (!(read.body instanceof Blob))
252
- return { kind: 'transport-uncertainty' };
253
- return { kind: 'action', result: { ...opened, blob: read.body } };
254
- }
255
- async function sendAction(transport, input) {
234
+ async function sendAction(transport, route, input, name) {
256
235
  const body = sendBody(input);
257
236
  if (body === null)
258
237
  return malformed();
259
- const answer = await transport.door('/door/conversations/send', body);
260
- const outcome = actionOutcome(answer, 'conversation.send');
238
+ const outcome = actionOutcome(await transport.door(route, body), name);
261
239
  if (outcome.kind !== 'action')
262
240
  return outcome;
263
- const uploaded = await uploadOriginals(transport, input, outcome.result);
241
+ const uploaded = await uploadFiles(transport, input, outcome.result, name);
264
242
  if (uploaded !== null)
265
243
  return uploaded;
266
- return outcome;
244
+ return { ...outcome, result: withTurn(outcome.result) };
267
245
  }
268
246
  function historyCursor(value) {
269
247
  const acceptedAt = text(value, 'accepted_at');
@@ -329,17 +307,17 @@ function historyAsks(input) {
329
307
  }
330
308
  return asks;
331
309
  }
332
- async function historyAction(transport, input) {
310
+ async function historyAction(transport, route, input, name) {
333
311
  const asks = historyAsks(input);
334
312
  if (asks === null)
335
313
  return malformed();
336
314
  const histories = [];
337
315
  for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
338
- const answer = await transport.door('/door/conversations/history', {
316
+ const answer = await transport.door(route, {
339
317
  conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
340
318
  limit: HISTORY_PAGE,
341
319
  });
342
- const outcome = actionOutcome(answer, 'conversation.history');
320
+ const outcome = actionOutcome(answer, name);
343
321
  if (outcome.kind !== 'action')
344
322
  return outcome;
345
323
  const answered = record(outcome.result).histories;
@@ -1 +1 @@
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"}
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;AAuChC,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;AAwBjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAuYpF"}
package/dist/adapter.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { DISCOVER_PREFIXES, capabilities, discoveredRoom, mapDiscovery, parseDiscovery, trackedFrom, } from './discovery.js';
2
- import { scopeModels, streamedModels, viewModels } from './model.js';
3
- import { gathered, selections } from './gather.js';
2
+ import { partModels, streamedModels, viewModels } from './model.js';
3
+ import { gathered, gatheredEach, selections } from './gather.js';
4
4
  import { createSiteAdapter } from './site.js';
5
5
  import { bootstrapOf, contentPrefixes, matchesScope, parseEnumeration, parseEnvelope, parseGrant, refreshFrom, viewOf, } from './read.js';
6
6
  import { acceptedLinks, enumeratedLinks, heldLinks, scopeLinks, streamedLinks, } from './links.js';
@@ -28,14 +28,26 @@ export function createAgentsHouseAdapter(options) {
28
28
  throw new Error('no Discovery declared the bounds');
29
29
  return bounds;
30
30
  }
31
- async function bootstrappedRoom(envelope, entry) {
32
- const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
31
+ async function bootstrappedRoom(envelope, scope, entry, continued) {
33
32
  if (scope === undefined)
34
33
  return { kind: 'room-not-readable', locator: entry.locator };
35
- handed.set(entry.locator, scopeLinks(scope));
34
+ const next = envelope.next?.room === entry.authority ? envelope.next.path : null;
35
+ if (continued === null && next === null)
36
+ handed.set(entry.locator, scopeLinks(scope));
37
+ else
38
+ handed.delete(entry.locator);
36
39
  notifications.reach(entry.authority, scope);
37
- const models = await scopeModels(scope, entry);
38
- return { ...bootstrapOf(scope), ...(models === undefined ? {} : { models }) };
40
+ const seen = [
41
+ ...(continued?.seen ?? []),
42
+ ...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
43
+ ];
44
+ const models = await partModels(scope, entry, new Set(seen), next === null);
45
+ const continuation = next === null ? null : { after: next, seen };
46
+ return {
47
+ ...bootstrapOf(scope),
48
+ ...(models === undefined ? {} : { models }),
49
+ ...(continuation === null ? {} : { pageToken: JSON.stringify(continuation) }),
50
+ };
39
51
  }
40
52
  async function enumeratedRoom(enumeration, ask) {
41
53
  const view = viewOf(enumeration, ask.entry);
@@ -109,41 +121,54 @@ export function createAgentsHouseAdapter(options) {
109
121
  return result;
110
122
  return { ...result, at: { locator, roomVersion: roomVersion({ position, logEpoch }) } };
111
123
  }
112
- async function bundled(body) {
113
- const grant = parseGrant(body);
114
- if (grant === null)
115
- return body;
116
- if (grant.method !== 'GET')
117
- return null;
118
- const answer = await transport.transfer({
119
- act: 'local_copy_bundle',
120
- method: 'GET',
121
- url: grant.url,
122
- answer: 'json',
123
- });
124
- return answer.status === 200 ? answer.body : null;
125
- }
126
124
  function weight(entry) {
127
125
  return contentPrefixes(entry).length;
128
126
  }
129
- async function bootstrapped(entries) {
130
- const answers = [];
131
- for (const part of selections(entries, weight, declared().max_prefixes)) {
132
- const answer = await transport.door(DOOR_BOOTSTRAP, {
133
- prefixes: part.flatMap((entry) => contentPrefixes(entry)),
134
- });
135
- const classified = part.map((entry) => classifyDoor(answer.status, answer.body, entry.locator));
136
- const envelope = classified[0] === null ? parseEnvelope(await bundled(answer.body)) : null;
137
- for (const [index, entry] of part.entries()) {
138
- const failure = classified[index];
139
- if (failure === null || failure === undefined) {
140
- answers.push(envelope === null ? UNCERTAIN_READ : await bootstrappedRoom(envelope, entry));
141
- continue;
127
+ async function bootstrapped(entries, answer) {
128
+ let open = entries.map((entry, ask) => ({ entry, ask }));
129
+ while (open.length > 0) {
130
+ const unreached = [];
131
+ for (const part of selections(open, ({ entry }) => weight(entry), declared().max_prefixes)) {
132
+ const answered = await transport.door(DOOR_BOOTSTRAP, {
133
+ prefixes: part.flatMap(({ entry }) => contentPrefixes(entry)),
134
+ });
135
+ const classified = part.map(({ entry }) => classifyDoor(answered.status, answered.body, entry.locator));
136
+ const envelope = classified[0] === null ? parseEnvelope(answered.body) : null;
137
+ for (const [index, asked] of part.entries()) {
138
+ const failure = classified[index];
139
+ if (failure !== null && failure !== undefined) {
140
+ answer(asked.ask, failure);
141
+ continue;
142
+ }
143
+ if (envelope === null) {
144
+ answer(asked.ask, UNCERTAIN_READ);
145
+ continue;
146
+ }
147
+ const scope = envelope.scopes.find((candidate) => matchesScope(candidate, asked.entry));
148
+ if (scope === undefined && envelope.next !== undefined) {
149
+ unreached.push(asked);
150
+ continue;
151
+ }
152
+ answer(asked.ask, await bootstrappedRoom(envelope, scope, asked.entry, null));
142
153
  }
143
- answers.push(failure);
144
154
  }
155
+ open = unreached;
145
156
  }
146
- return answers;
157
+ }
158
+ async function continuedBootstrap(entry, continued) {
159
+ const after = { room: entry.authority, path: continued.after };
160
+ const answered = await transport.door(DOOR_BOOTSTRAP, {
161
+ prefixes: contentPrefixes(entry),
162
+ after,
163
+ });
164
+ const failure = classifyDoor(answered.status, answered.body, entry.locator);
165
+ if (failure !== null)
166
+ return failure;
167
+ const envelope = parseEnvelope(answered.body);
168
+ if (envelope === null)
169
+ return UNCERTAIN_READ;
170
+ const scope = envelope.scopes.find((candidate) => matchesScope(candidate, entry));
171
+ return bootstrappedRoom(envelope, scope, entry, continued);
147
172
  }
148
173
  function layered(asks) {
149
174
  const depths = new Map();
@@ -190,7 +215,7 @@ export function createAgentsHouseAdapter(options) {
190
215
  }
191
216
  return asks.map((ask) => answers.get(ask) ?? UNCERTAIN_READ);
192
217
  }
193
- const bootstrapTogether = gathered(bootstrapped);
218
+ const bootstrapTogether = gatheredEach(bootstrapped);
194
219
  const enumerateTogether = gathered(enumerated);
195
220
  async function uploaded(head, changes, delta, bytes, entry, handed, keep) {
196
221
  const paths = batchPaths(changes);
@@ -207,9 +232,7 @@ export function createAgentsHouseAdapter(options) {
207
232
  return { outcome: UNCERTAIN };
208
233
  const delivered = await transport.transfer({
209
234
  act: 'authored_batch_upload',
210
- method: 'POST',
211
235
  url: grant.url,
212
- answer: 'json',
213
236
  body: `${grant.operation}\n${delta}`,
214
237
  });
215
238
  if (delivered.status !== 200)
@@ -252,14 +275,18 @@ export function createAgentsHouseAdapter(options) {
252
275
  if (!tracked.has(locator))
253
276
  handed.delete(locator);
254
277
  notifications.track(entries);
255
- return mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document));
278
+ return {
279
+ ...mapDiscovery(document, document.authorities.map((authority) => discoveredRoom(authority)), capabilities(document)),
280
+ member: document.member,
281
+ };
256
282
  },
257
283
  async bootstrap(_authorization, request) {
258
284
  const entry = authorityFor(request.locator);
259
285
  if (entry === undefined)
260
286
  return { kind: 'room-not-readable', locator: request.locator };
261
- if (request.pageToken !== undefined)
262
- return { kind: 'transport-uncertainty' };
287
+ if (request.pageToken !== undefined) {
288
+ return continuedBootstrap(entry, JSON.parse(request.pageToken));
289
+ }
263
290
  return bootstrapTogether(entry);
264
291
  },
265
292
  async refresh(_authorization, request) {
@@ -316,7 +343,7 @@ export function createAgentsHouseAdapter(options) {
316
343
  async action(_authorization, request) {
317
344
  return withAt(await houseAction(transport, request));
318
345
  },
319
- roomStream: { hold: held, observe: notifications.observe },
346
+ roomStream: { hold: held, reopen: notifications.reopen, observe: notifications.observe },
320
347
  conversations: notifications.conversations,
321
348
  serviceMode: notifications.serviceMode,
322
349
  };