@agentshouse/mdruntime-adapter 0.1.0-c9f1e531ad7c8 → 0.1.0-cb89e0425af50

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/AGENTS.md CHANGED
@@ -7,9 +7,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, Slots, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
- storage loss, the reported persistence answer, deployment facts, Sync Status, the Service Mode,
12
- reauthorization, conversation, the chat draft, and Presentation State.
10
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, History, Call, Reached, Log,
11
+ the reported persistence answer, reauthorization, conversation, the chat draft,
12
+ and Presentation State. Sync Status, the Service Mode, the storage-loss
13
+ statement, the deployment facts and the signed-in member 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,45 +27,65 @@ 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 a Provider card names is held complete in the browser.
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 growing text and plan of the running turn, the open questions, the process
25
- state, the CLI's commands and options, and the latest `workingNote`. These live
26
- only in memory: the turn's accepted message replaces its growing text and plan,
27
- a working note is never part of a message, and none of them is stored or
28
- searchable.
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, Slots, Query, Search, Observe, Types, Room Draft, Save, and Reached never
52
+ Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
43
53
  touch the network.
44
- 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
45
57
  effect the Provider places in a Room carries `at`, that Room and Room Version;
46
58
  `reached(room, roomVersion)` answers whether the Room's confirmed state has
47
59
  reached it, and the MD Runtime keeps refreshing that Room until it has;
48
60
  `reached(room, roomVersion, path)` answers whether the held confirmed copy of
49
61
  that document was written at a later Room Version. Each History revision
50
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
62
+ names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
63
+ History of a Path no current document holds answers the removed document's
64
+ revisions with `deleted: true`, newest first; that revision is what a link to
65
+ the Path opens. Every
51
66
  member of the
52
67
  client is asynchronous. Results are detached snapshots. Nothing in this
53
68
  surface returns the authorization, performs a request the App's code
54
69
  composes, or exposes the browser store.
55
70
 
56
- Read deployment facts with `deploymentFacts()` and observe replacements with
57
- `observe('deployment-facts')`. Interpret the opaque value using the
58
- host's contract.
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
+
78
+ Read the deployment facts with `observe('deployment-facts')`. Interpret the
79
+ opaque value using the host's contract.
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.
59
89
 
60
90
  The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
61
91
  ships in no bundle.
@@ -70,22 +100,28 @@ data:
70
100
  - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
71
101
  names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
72
102
  directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
73
- - **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
74
- `$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
75
- `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
76
- asks whether it contains the value. Missing, null and empty differ:
103
+ - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
104
+ `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
105
+ meets a list applies to every item and a number names one item. `where` names
106
+ pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
107
+ when any item satisfies it. A bare value is equality; the operators are `$eq`,
108
+ `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
109
+ `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
77
110
  `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
78
111
  text and `$size: 0` an empty list. A date compares in calendar order and never
79
112
  with a date-time. A reference compares by the Room Path it resolves to.
80
- Untyped frontmatter is plain values. There is no text containment or regular
113
+ Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
114
+ values. There is no text containment or regular
81
115
  expression.
82
116
  - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
83
- reference `field` points to a matching Document of the same Room.
84
- `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
117
+ reference at pointer `field`, at any depth, points to a matching Document of the
118
+ same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
85
119
  matching Document of the same Room references. Each keeps a Document once.
86
120
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
87
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
88
- are `'all'` or a list of names. Room and Path always return; a Markdown
121
+ `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
122
+ list of pointers and `sections` `'all'` or a list of names. Selected pointers
123
+ return the frontmatter holding only them, nested as written. A backlink names
124
+ the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
89
125
  Document also returns its MD Type. A non-Markdown Document or binary link
90
126
  target returns only Room and Path. An unselected part is absent. Select only
91
127
  what a screen shows: a list that selects the Markdown hears every edit of it.
@@ -94,17 +130,17 @@ data:
94
130
  or `null` for a write the Provider made itself, and `time` is the Provider's
95
131
  ISO 8601 change time. It is `null` where the Provider delivered no time, as at
96
132
  a Site. An unsent edit or move keeps it, an unsent creation has none, and a
97
- 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
98
134
  Room's last change is its Document with the latest `time`.
99
135
  - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
100
136
  with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
101
137
  `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
102
- over every match and ordered by `count` or a key. `limit` bounds the Documents
103
- or the groups.
138
+ over every match and ordered by `count` or a key. A sort or group takes only a
139
+ pointer that holds one value. `limit` bounds the Documents or the groups.
104
140
  - **Results and errors.** A result carries no Room Version: read freshness from
105
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
106
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
107
- 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.
108
144
 
109
145
  ## Local Search rules
110
146
 
@@ -114,7 +150,7 @@ search.
114
150
 
115
151
  - **What is found.** A Document by its field values, its sections' headings and
116
152
  text, its preamble and its Path; a message by its text. Frontmatter keys, Room
117
- Drafts, chat drafts and growing text are never found. There are no phrases,
153
+ Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
118
154
  word forms, typo tolerance or prefix matching.
119
155
  - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
120
156
  `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
@@ -130,7 +166,7 @@ search.
130
166
 
131
167
  The MD Runtime owns one Room Draft per Room and Path, shared by every App and
132
168
  tab. It is durable: it survives reload and navigation. A Room that Discovery
133
- stops listing takes its Room Drafts, its queue and their outcomes with it.
169
+ stops listing takes its Room Drafts and its queue with it.
134
170
  Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
135
171
  the revision you read, or `null` when there was none, and every part it should
136
172
  now change: fields, sections and the preamble, or the whole Markdown, a
@@ -142,28 +178,36 @@ the current Room Draft; read it and write again.
142
178
 
143
179
  Save takes one Room and the Room Drafts of it to save, each with its revision,
144
180
  validates locally, and on success appends one Change Batch to that Room's
145
- 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`,
146
182
  `changed-underneath` naming each part whose base no longer matches the visible
147
- 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
148
184
  Room Draft in place. A directory move or removal is a move or removal part on
149
185
  each Document and binary link target beneath it, saved together.
150
186
 
151
187
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
152
188
  queue, drawn over the confirmed layer, until the confirmed layer reaches the
153
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired outcome record, and a change that no
189
+ Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
154
190
  longer applies over the Room each leave the queue and return as Room Drafts on
155
191
  the Documents they changed, marked with why: the Provider's structured refusal
156
192
  code and fields as returned, not known to have applied, or withdrawn locally.
157
193
  The rest of the queue keeps synchronizing, and Sync Status requires attention
158
- until each returned Room Draft is saved again or discarded. `outcome` answers
159
- the saved Change Batch's outcome, and `null` while it is Pending. Transport
194
+ until each returned Room Draft is saved again or discarded. A Change Batch
195
+ keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
196
+ Pending one, and a returned Room Draft says why it returned. Transport
160
197
  failure and Provider unavailability keep work Pending and do not infer a
161
198
  rejection. A refusal the Provider marks retryable stays Pending until the reset
162
199
  it names; the MD Runtime retries the same Change Batch identity and payload and
163
200
  never infers an outcome from transport uncertainty. The MD Runtime never
164
201
  combines, reorders, or rebases.
165
202
 
166
- `serviceMode()` and `observe('service-mode')` answer the Provider's Service
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
+
210
+ `observe('service-mode')` answers the Provider's Service
167
211
  Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
168
212
  its Change Batch waits unsent, and the queue is submitted in order once the
169
213
  Provider reopens writes. An Action is never held: a write the Provider refuses
@@ -196,13 +240,28 @@ an App's override respected. What an App Creator's agent adds carries none
196
240
  of these promises by itself. Reading, querying and searching never wait for
197
241
  the network. Data lives only in the App Creator's browser and with the Provider.
198
242
 
199
- ## App code imports only the client entry and never constructs a Runtime
243
+ ## App code takes the client its host hands it and never constructs a Runtime
244
+
245
+ App code takes the client its host hands it: in House,
246
+ `houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
247
+ client House built into the page. It never constructs a Runtime or a client.
248
+ It imports only types from `@agentshouse/mdruntime/client`, does not call
249
+ `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
250
+ the host entry, or the Adapter package. Hosts and tests use those entries; the
251
+ served App does not.
200
252
 
201
- App code imports only `@agentshouse/mdruntime/client` and calls
202
- `connectMdRuntime` on the port the host hands it. It never constructs a
203
- Runtime. It does not import the package main, the host entry, or the Adapter
204
- package, and it does not call `createMdRuntime` or `serveMdRuntime`. Hosts
205
- and tests use those entries; the served App does not.
253
+ A React App may observe and save through `@agentshouse/mdruntime/react`, which
254
+ names React as a peer dependency. `useObserve(client, topic, ...input)` takes
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
258
+ `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
259
+ already there, keeping the bases its parts have, or onto a new one, and saves
260
+ them together. A refused Save leaves the Room Drafts for the App to save again
261
+ or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
262
+ roomDrafts)` is that save outside a component. A react-admin or Refine App
263
+ reads and writes its Rooms through the data providers of
264
+ `@agentshouse/mdruntime-families`.
206
265
 
207
266
  ## What an agent must never do
208
267
 
package/README.md CHANGED
@@ -19,12 +19,12 @@ import { serveMdRuntime } from '@agentshouse/mdruntime/host';
19
19
  import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
20
20
 
21
21
  const adapter = createAgentsHouseAdapter({ transport, authorize });
22
- const host = serveMdRuntime({ adapter, shell, requiredGuarantees: [] });
22
+ const host = serveMdRuntime({ adapter, shell });
23
23
  host.attach(port, 'my-app');
24
24
  ```
25
25
 
26
- App code never imports this package; it reaches the Runtime only through
27
- `@agentshouse/mdruntime/client`. The rules an App's agent follows are in the
26
+ App code never imports this package; it reaches the Runtime only through the
27
+ client its host hands it. The rules an App's agent follows are in the
28
28
  package's `AGENTS.md`.
29
29
 
30
30
  ## License
package/dist/actions.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationCards } from '@agentshouse/mdruntime';
1
+ import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
- export declare const HOUSE_CONVERSATION_CARDS: ConversationCards;
3
+ export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
4
+ export declare function houseConversationAgents(locator: string): ConversationAgents;
4
5
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
5
6
  export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
6
7
  export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,iBAAiB,EAGvB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,eAAO,MAAM,wBAAwB,EAAE,iBAKtC,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
1
+ {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EAGxB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAmEtE,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;AAyDD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAOjF;AAwMD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
package/dist/actions.js CHANGED
@@ -1,50 +1,76 @@
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';
7
- const CONVERSATION_ROUTES = new Map([
8
- ['conversation.create', '/door/conversations/create'],
9
- ['conversation.send', '/door/conversations/send'],
10
- ['conversation.answer', '/door/conversations/interaction/answer'],
11
- ['conversation.interrupt', '/door/conversations/interrupt'],
12
- ['conversation.kill', '/door/conversations/kill'],
13
- ['conversation.delete', '/door/conversations/delete'],
14
- ['conversation.history', '/door/conversations/history'],
15
- ]);
16
- export const HOUSE_CONVERSATION_CARDS = {
17
- locator: PRIVATE_LOCATOR,
18
- type: 'house-conversation',
19
- identity: 'conversation',
20
- agent: 'agent',
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
+ 'attachment.read': carried('attachments/get', openAction),
23
+ 'attachment.upload': carried('attachments/upload', attachAction),
24
+ 'conversation.answer': mapped('conversations/interaction/answer', answerBody),
25
+ 'conversation.create': mapped('conversations/create', createBody),
26
+ 'conversation.delete': mapped('conversations/delete', controlBody),
27
+ 'conversation.history': carried('conversations/history', historyAction),
28
+ 'conversation.interrupt': mapped('conversations/interrupt', controlBody),
29
+ 'conversation.kill': mapped('conversations/kill', controlBody),
30
+ 'conversation.markDone': mapped('conversations/done'),
31
+ 'conversation.rename': mapped('conversations/rename'),
32
+ 'conversation.send': carried('conversations/send', sendAction),
33
+ 'conversation.setOption': mapped('conversations/option'),
34
+ 'feature.list': mapped('apps/features/read'),
35
+ 'holder.list': mapped('apps/holders'),
36
+ 'holder.ring': mapped('apps/ring'),
37
+ 'member.list': mapped('rooms/members'),
38
+ 'message.send': mapped('apps/messages/send'),
39
+ 'processing.read': mapped('rooms/settings/processing/read'),
40
+ 'record.list': mapped('records/read'),
41
+ 'relay.read': mapped('apps/relay'),
42
+ 'routine.list': mapped('routines/access'),
43
+ 'routineAccess.list': mapped('routines/granted'),
44
+ 'routineAllowance.list': mapped('routines/allowance'),
45
+ 'routineRequest.list': mapped('routines/requests'),
46
+ 'storage.read': mapped('storage/inventory'),
47
+ 'trigger.list': mapped('triggers/read'),
48
+ 'triggerOccurrence.list': mapped('triggers/fired'),
21
49
  };
50
+ export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
51
+ const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
52
+ export function houseConversationAgents(locator) {
53
+ return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
54
+ }
22
55
  export function declaredActions(routes) {
23
- const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
24
56
  return routes.map((route) => ({
25
- name: mapped.get(route) ?? route,
57
+ name: APP_NAMES.get(route) ?? route,
26
58
  inputShape: {},
27
59
  resultKind: 'house',
28
60
  }));
29
61
  }
30
62
  export function houseAction(transport, request) {
31
- if (request.name === 'conversation.send')
32
- return sendAction(transport, request.input);
33
- if (request.name === 'conversation.history')
34
- return historyAction(transport, request.input);
35
- if (request.name === 'attachments/upload')
36
- return attachAction(transport, request.input);
37
- if (request.name === 'attachments/get')
38
- return openAction(transport, request.input);
63
+ if (Object.hasOwn(APP_ACTS, request.name)) {
64
+ return APP_ACTS[request.name].carry(transport, request.input, request.name);
65
+ }
66
+ if (APP_NAMES.has(request.name))
67
+ return Promise.resolve(unimplemented(request.name));
39
68
  const route = routeOf(request.name);
40
69
  if (route === null)
41
70
  return Promise.resolve(malformed());
42
71
  return carry(transport, route, request.name, request.input);
43
72
  }
44
73
  function routeOf(name) {
45
- const mapped = CONVERSATION_ROUTES.get(name);
46
- if (mapped !== undefined)
47
- return mapped;
48
74
  const parts = name.split('/');
49
75
  if (parts.some((part) => part === '.' || part === '..'))
50
76
  return null;
@@ -66,27 +92,25 @@ function operationId(input) {
66
92
  return text(input, 'operation_id') ?? changeBatchIdentity();
67
93
  }
68
94
  function malformed() {
69
- return { kind: 'rejected', code: 'invalid_request', fields: {} };
95
+ return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
70
96
  }
71
- function bodyOf(name, input) {
72
- if (name === 'conversation.create') {
73
- return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
74
- }
75
- if (name === 'conversation.interrupt' ||
76
- name === 'conversation.kill' ||
77
- name === 'conversation.delete') {
78
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
79
- }
80
- if (name === 'conversation.answer') {
81
- const nested = record(record(input).answer);
82
- return {
83
- conversation_id: text(input, 'conversation'),
84
- operation_id: operationId(input),
85
- interaction_id: text(nested, 'interaction_id'),
86
- response: nested.response,
87
- };
88
- }
89
- return input;
97
+ function unimplemented(name) {
98
+ return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
99
+ }
100
+ function createBody(input) {
101
+ return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
102
+ }
103
+ function controlBody(input) {
104
+ return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
105
+ }
106
+ function answerBody(input) {
107
+ const nested = record(record(input).answer);
108
+ return {
109
+ conversation_id: text(input, 'conversation'),
110
+ operation_id: operationId(input),
111
+ interaction_id: text(nested, 'interaction_id'),
112
+ response: nested.response,
113
+ };
90
114
  }
91
115
  function withTurn(body) {
92
116
  const held = record(body);
@@ -97,20 +121,16 @@ export function actionOutcome(answer, name) {
97
121
  if (answer.status === 401)
98
122
  return { kind: 'revoked-authorization' };
99
123
  const refusal = doorRefusal(answer.body);
100
- if (refusal !== null) {
101
- return { kind: 'rejected', code: refusal.code, fields: refusal.fields };
102
- }
124
+ if (refusal !== null)
125
+ return { kind: 'rejected', ...refusal };
103
126
  if (answer.status === 404)
104
- return { kind: 'rejected', code: 'action-unimplemented', fields: { name } };
127
+ return unimplemented(name);
105
128
  if (answer.status === 0 || answer.status >= 400)
106
129
  return { kind: 'transport-uncertainty' };
107
- if (name === 'conversation.send')
108
- return { kind: 'action', result: withTurn(answer.body) };
109
130
  return { kind: 'action', result: answer.body };
110
131
  }
111
132
  async function carry(transport, route, name, input) {
112
- const answer = await transport.door(route, bodyOf(name, input));
113
- return actionOutcome(answer, name);
133
+ return actionOutcome(await transport.door(route, input), name);
114
134
  }
115
135
  function sendFile(entry) {
116
136
  const file = record(entry);
@@ -180,7 +200,7 @@ function uploadGrant(entry) {
180
200
  return null;
181
201
  return { method: 'POST', operation: upload.operation, url: upload.url };
182
202
  }
183
- async function uploadOriginals(transport, input, result) {
203
+ async function uploadOriginals(transport, input, result, name) {
184
204
  const originals = record(result).originals;
185
205
  if (!Array.isArray(originals) || originals.length === 0)
186
206
  return null;
@@ -193,7 +213,12 @@ async function uploadOriginals(transport, input, result) {
193
213
  return malformed();
194
214
  const bytes = index < files.length ? await fileBytes(files[index]) : null;
195
215
  if (bytes === null) {
196
- return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };
216
+ return {
217
+ kind: 'rejected',
218
+ code: 'conversation_original_descriptor_required',
219
+ fields: {},
220
+ retryable: false,
221
+ };
197
222
  }
198
223
  const failed = delivered(await transport.transfer({
199
224
  act: 'conversation_original_upload',
@@ -202,19 +227,18 @@ async function uploadOriginals(transport, input, result) {
202
227
  answer: 'json',
203
228
  body: bytes,
204
229
  operation: grant.operation,
205
- }), 'conversation.send');
230
+ }), name);
206
231
  if (failed !== null)
207
232
  return failed;
208
233
  }
209
234
  return null;
210
235
  }
211
- async function attachAction(transport, input) {
236
+ async function attachAction(transport, route, input, name) {
212
237
  const { blob, ...descriptor } = record(input);
213
238
  const bytes = await fileBytes({ blob });
214
239
  if (bytes === null)
215
240
  return malformed();
216
- const answer = await transport.door('/door/attachments/upload', descriptor);
217
- const outcome = actionOutcome(answer, 'attachments/upload');
241
+ const outcome = actionOutcome(await transport.door(route, descriptor), name);
218
242
  if (outcome.kind !== 'action')
219
243
  return outcome;
220
244
  const grant = uploadGrant(outcome.result);
@@ -230,11 +254,10 @@ async function attachAction(transport, input) {
230
254
  body: bytes,
231
255
  operation: grant.operation,
232
256
  });
233
- return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };
257
+ return delivered(stored, name) ?? { kind: 'action', result: stored.body };
234
258
  }
235
- async function openAction(transport, input) {
236
- const answer = await transport.door('/door/attachments/get', input);
237
- const outcome = actionOutcome(answer, 'attachments/get');
259
+ async function openAction(transport, route, input, name) {
260
+ const outcome = actionOutcome(await transport.door(route, input), name);
238
261
  if (outcome.kind !== 'action')
239
262
  return outcome;
240
263
  const { download, ...opened } = record(outcome.result);
@@ -249,25 +272,24 @@ async function openAction(transport, input) {
249
272
  url: grant.url,
250
273
  answer: 'bytes',
251
274
  });
252
- const failed = delivered(read, 'attachments/get');
275
+ const failed = delivered(read, name);
253
276
  if (failed !== null)
254
277
  return failed;
255
278
  if (!(read.body instanceof Blob))
256
279
  return { kind: 'transport-uncertainty' };
257
280
  return { kind: 'action', result: { ...opened, blob: read.body } };
258
281
  }
259
- async function sendAction(transport, input) {
282
+ async function sendAction(transport, route, input, name) {
260
283
  const body = sendBody(input);
261
284
  if (body === null)
262
285
  return malformed();
263
- const answer = await transport.door('/door/conversations/send', body);
264
- const outcome = actionOutcome(answer, 'conversation.send');
286
+ const outcome = actionOutcome(await transport.door(route, body), name);
265
287
  if (outcome.kind !== 'action')
266
288
  return outcome;
267
- const uploaded = await uploadOriginals(transport, input, outcome.result);
289
+ const uploaded = await uploadOriginals(transport, input, outcome.result, name);
268
290
  if (uploaded !== null)
269
291
  return uploaded;
270
- return outcome;
292
+ return { ...outcome, result: withTurn(outcome.result) };
271
293
  }
272
294
  function historyCursor(value) {
273
295
  const acceptedAt = text(value, 'accepted_at');
@@ -333,17 +355,17 @@ function historyAsks(input) {
333
355
  }
334
356
  return asks;
335
357
  }
336
- async function historyAction(transport, input) {
358
+ async function historyAction(transport, route, input, name) {
337
359
  const asks = historyAsks(input);
338
360
  if (asks === null)
339
361
  return malformed();
340
362
  const histories = [];
341
363
  for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
342
- const answer = await transport.door('/door/conversations/history', {
364
+ const answer = await transport.door(route, {
343
365
  conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
344
366
  limit: HISTORY_PAGE,
345
367
  });
346
- const outcome = actionOutcome(answer, 'conversation.history');
368
+ const outcome = actionOutcome(answer, name);
347
369
  if (outcome.kind !== 'action')
348
370
  return outcome;
349
371
  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,EAad,MAAM,wBAAwB,CAAC;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAuBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAiCjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkZpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAWd,MAAM,wBAAwB,CAAC;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,CAyYpF"}