@agentshouse/mdruntime-adapter 0.1.0-c8654c2657ee5 → 0.1.0-c8f4fd4801441
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 +109 -35
- package/dist/actions.d.ts +39 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +134 -118
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +171 -69
- package/dist/discovery.d.ts +2 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +12 -1
- package/dist/gather.d.ts +1 -0
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +11 -6
- package/dist/handed.d.ts +15 -0
- package/dist/handed.d.ts.map +1 -0
- package/dist/handed.js +38 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/model.d.ts +1 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +23 -6
- package/dist/read.d.ts +13 -7
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +74 -79
- package/dist/referrer.d.ts +7 -0
- package/dist/referrer.d.ts.map +1 -0
- package/dist/referrer.js +35 -0
- package/dist/refusal.d.ts +2 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +4 -8
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +41 -3
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +18 -6
- package/dist/transport.d.ts +16 -6
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -0
- package/dist/write.d.ts +3 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +85 -11
- package/package.json +4 -4
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/AGENTS.md
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
# Instructions for the App Creator's agent
|
|
2
2
|
|
|
3
3
|
These instructions address an agent in an environment with Git. Obtain the
|
|
4
|
-
App Repository, change it, build, and push. They are documentation, not
|
|
5
|
-
enforcement.
|
|
4
|
+
App Repository, change it, build, and push. They are documentation, not enforcement.
|
|
6
5
|
|
|
7
6
|
## The MD Runtime API
|
|
8
7
|
|
|
9
8
|
App code reaches the MD Runtime through the remote client. The surfaces are
|
|
10
|
-
Rooms, Query, Search, Observe, Types, Room Draft, Save, History,
|
|
9
|
+
Rooms, Query, Search, Observe, Types, Room Draft, Save, History, the binary file
|
|
10
|
+
reads, 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
|
|
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,
|
|
@@ -27,6 +27,8 @@ value whole and returns its unsubscribe, and `close()` ends the observation.
|
|
|
27
27
|
Closing the port ends every handle and rejects every pending call and
|
|
28
28
|
observation; a client that reconnects observes again.
|
|
29
29
|
|
|
30
|
+
`observe('agents')` answers every Agent a new conversation can go to, each
|
|
31
|
+
`{ identity, name }`, whether or not it has a conversation yet.
|
|
30
32
|
Each conversation the Provider's conversation list names is held complete in the
|
|
31
33
|
browser. `conversation.list()` and `observe('conversations')` answer each with its
|
|
32
34
|
Agent's identity and name, its name, created and finished times, last outcome and live
|
|
@@ -43,15 +45,34 @@ and none of them is stored or searchable.
|
|
|
43
45
|
sending it is a Provider Action that needs the Provider reachable and is never
|
|
44
46
|
queued.
|
|
45
47
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
A binary file at a Path of a Room is a binary Path entry. Query lists it by
|
|
49
|
+
`path` with its `binaryFile` record and never its bytes: `{ state: 'accepted',
|
|
50
|
+
revision, path, fileRef, byteLength, mediaType, sha256 }`, or, from a Save until
|
|
51
|
+
the Provider accepts it, `{ state: 'pending', localId, path, byteLength,
|
|
52
|
+
mediaType, sha256 }` with no revision. Write one with a Room Draft whose only part
|
|
53
|
+
is `file: { blob }`, a `Blob` whose `type` is its media type; Save keeps the bytes
|
|
54
|
+
in its Pending Change, works offline, and the record turns accepted with the
|
|
55
|
+
Provider's revision once the Pending Change is accepted. Move or remove an
|
|
56
|
+
accepted one as a Document. Move or remove a pending one the same way, before or
|
|
57
|
+
after Save: the Room Draft or its queued Pending Change carries the bytes to the
|
|
58
|
+
new Path or drops them, and once that Pending Change has gone to the Provider
|
|
59
|
+
Save refuses it as `unknown-revision` until it is accepted. Read the bytes with
|
|
60
|
+
`binaryFile.read(room, path)`: a pending record answers its saved bytes, and
|
|
61
|
+
every read of an accepted one asks the Provider again and keeps nothing. Pass a
|
|
62
|
+
History revision as `binaryFile.read(room, path, revision)` to open that
|
|
63
|
+
revision, a removed file's last one included. Text, a Record attachment or a conversation
|
|
64
|
+
message may name a file directly by its `fileRef`; read that file with
|
|
65
|
+
`binaryFile.readReference({ fileRef, referrer })`, where the referrer is the
|
|
66
|
+
`referrer` the Provider gave beside the reference, or `{ room, path }` of the
|
|
67
|
+
document whose text names it. Both answer `{ kind: 'binary', blob }` or a
|
|
68
|
+
refusal or failure. History of a binary Path lists each revision's
|
|
69
|
+
`binaryFile` metadata without bytes.
|
|
51
70
|
|
|
52
71
|
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
53
72
|
touch the network.
|
|
54
|
-
History and Call go to the Provider through the Adapter.
|
|
73
|
+
History, the binary file reads and Call go to the Provider through the Adapter. Call takes the Action names
|
|
74
|
+
the Adapter declares; any other name answers `undeclared` without reaching the
|
|
75
|
+
Provider. A Call result whose
|
|
55
76
|
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
56
77
|
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
57
78
|
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
@@ -66,9 +87,25 @@ client is asynchronous. Results are detached snapshots. Nothing in this
|
|
|
66
87
|
surface returns the authorization, performs a request the App's code
|
|
67
88
|
composes, or exposes the browser store.
|
|
68
89
|
|
|
90
|
+
Every refusal and failure carries `code` and `retryable`: each Call and History answer
|
|
91
|
+
other than its result, a refused Save or Room Draft write, a returned Room Draft's
|
|
92
|
+
reason, a Room's refusal and the Connection Refusal, and every error a member rejects
|
|
93
|
+
with, beside its message. A Provider refusal carries the Provider's own `retryable`.
|
|
94
|
+
Every code and every value the API answers is open: handle one you do not know by its
|
|
95
|
+
`code` and `retryable`.
|
|
96
|
+
|
|
69
97
|
Read the deployment facts with `observe('deployment-facts')`. Interpret the
|
|
70
98
|
opaque value using the host's contract.
|
|
71
99
|
|
|
100
|
+
`observe('member')` answers who uses the App: the User the Provider signed in,
|
|
101
|
+
`{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
|
|
102
|
+
whose `change.author.id` equals its `id` is that User's own. It is `null` until
|
|
103
|
+
the Provider first names one, and where it names none, such as a Site. The
|
|
104
|
+
MD Runtime keeps it with the Local Replicas, so it answers offline once known,
|
|
105
|
+
and every port hears the next member the Provider names; signing out answers
|
|
106
|
+
`null`, then ends the observation with the authorization. It is the only way App code learns who
|
|
107
|
+
uses it.
|
|
108
|
+
|
|
72
109
|
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
73
110
|
ships in no bundle.
|
|
74
111
|
|
|
@@ -104,15 +141,16 @@ data:
|
|
|
104
141
|
list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
105
142
|
return the frontmatter holding only them, nested as written. A backlink names
|
|
106
143
|
the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
|
|
107
|
-
Document also returns its MD Type. A non-Markdown Document
|
|
108
|
-
|
|
144
|
+
Document also returns its MD Type. A non-Markdown Document returns only Room
|
|
145
|
+
and Path, and a binary Path entry Room, Path and its `binaryFile` record,
|
|
146
|
+
whatever is selected. An unselected part is absent. Select only
|
|
109
147
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
110
148
|
- **Change.** `change` is `{ author, time }` of the Document's head revision as
|
|
111
149
|
the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
|
|
112
150
|
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
113
151
|
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
114
152
|
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
|
|
153
|
+
saved write takes the Provider's own once it is Accepted. A
|
|
116
154
|
Room's last change is its Document with the latest `time`.
|
|
117
155
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
118
156
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
@@ -120,9 +158,9 @@ data:
|
|
|
120
158
|
over every match and ordered by `count` or a key. A sort or group takes only a
|
|
121
159
|
pointer that holds one value. `limit` bounds the Documents or the groups.
|
|
122
160
|
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
123
|
-
Rooms and Sync Status. An invalid query fails with `
|
|
124
|
-
`unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
125
|
-
answers an empty result in its place.
|
|
161
|
+
Rooms and Sync Status. An invalid query fails with the `code`
|
|
162
|
+
`invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
163
|
+
and never answers an empty result in its place.
|
|
126
164
|
|
|
127
165
|
## Local Search rules
|
|
128
166
|
|
|
@@ -160,9 +198,9 @@ the current Room Draft; read it and write again.
|
|
|
160
198
|
|
|
161
199
|
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
162
200
|
validates locally, and on success appends one Change Batch to that Room's
|
|
163
|
-
queue and removes those Room Drafts. It is refused
|
|
201
|
+
queue and removes those Room Drafts. It is refused with the `code` `stale`,
|
|
164
202
|
`changed-underneath` naming each part whose base no longer matches the visible
|
|
165
|
-
state, or
|
|
203
|
+
state, or a local validation rule, and then creates nothing and leaves every
|
|
166
204
|
Room Draft in place. A directory move or removal is a move or removal part on
|
|
167
205
|
each Document and binary link target beneath it, saved together.
|
|
168
206
|
|
|
@@ -182,6 +220,13 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
|
182
220
|
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
183
221
|
combines, reorders, or rebases.
|
|
184
222
|
|
|
223
|
+
On a Site, every Save stays in the visitor's browser. Write grants and
|
|
224
|
+
revisions do not refuse it, and its Pending Change shows in every query and
|
|
225
|
+
across reloads until the browser's storage is cleared. It is never sent:
|
|
226
|
+
`observe('queue', room)` shows it `local`, and Sync Status never waits on it.
|
|
227
|
+
Once the Room changes so that it no longer applies, it leaves the queue and
|
|
228
|
+
returns no Room Draft.
|
|
229
|
+
|
|
185
230
|
`observe('service-mode')` answers the Provider's Service
|
|
186
231
|
Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
|
|
187
232
|
its Change Batch waits unsent, and the queue is submitted in order once the
|
|
@@ -217,26 +262,55 @@ the network. Data lives only in the App Creator's browser and with the Provider.
|
|
|
217
262
|
|
|
218
263
|
## App code takes the client its host hands it and never constructs a Runtime
|
|
219
264
|
|
|
220
|
-
App code takes the client its host hands it: in House,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
`
|
|
225
|
-
|
|
226
|
-
served App does not.
|
|
265
|
+
App code takes the client its host hands it: in House, `houseBridge().runtime`
|
|
266
|
+
from `@agentshouse/app-bridge` resolves to the client House built into the page.
|
|
267
|
+
It never constructs a Runtime or a client. It imports only types from
|
|
268
|
+
`@agentshouse/mdruntime/client`, does not call `connectMdRuntime` or
|
|
269
|
+
`serveMdRuntime`, and does not import the package main, the host entry, or the
|
|
270
|
+
Adapter package. Hosts and tests use those entries; the served App does not.
|
|
227
271
|
|
|
228
272
|
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
229
273
|
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
230
|
-
the arguments of `observe` and returns the topic's
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
`
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
or discard; a failure is
|
|
237
|
-
roomDrafts)` is that save
|
|
238
|
-
reads and writes its Rooms
|
|
239
|
-
`@agentshouse/mdruntime-families`.
|
|
274
|
+
the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
|
|
275
|
+
first value arrives, then `{ state: 'ready', value }`, re-rendering on each
|
|
276
|
+
change; a `null` client observes nothing and stays loading. `useSave(client)`
|
|
277
|
+
returns `busy`, the last `outcome` or `failure`, and `save(room, roomDrafts)`,
|
|
278
|
+
which writes each Path's parts onto the Room Draft already there, keeping the
|
|
279
|
+
bases its parts have, or onto a new one, and saves them together. A refused
|
|
280
|
+
Save leaves the Room Drafts for the App to save again or discard; a failure is
|
|
281
|
+
recorded and rejects. `saveRoomDrafts(client, room, roomDrafts)` is that save
|
|
282
|
+
outside a component. A react-admin or Refine App reads and writes its Rooms
|
|
283
|
+
through the data providers of `@agentshouse/mdruntime-families`.
|
|
284
|
+
|
|
285
|
+
## The Chat
|
|
286
|
+
|
|
287
|
+
`@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App.
|
|
288
|
+
Its required peers are React, React DOM and `@assistant-ui/react`: add React as
|
|
289
|
+
a dependency, also in an App not written in React.
|
|
290
|
+
|
|
291
|
+
Place the ready chat with `<Chat client={runtime} conversation={id}
|
|
292
|
+
agent={agent} width="1/3" showChats />`: `conversation` opens one, `null` for a
|
|
293
|
+
new chat, `agent` is the Agent a new chat goes to, `onOpen` hears each one it
|
|
294
|
+
opens, and `width` is `full` (the place you give it), or `3/4`, `1/2` or `1/3`
|
|
295
|
+
of the window docked at its right edge, whole on a narrow window. `showChats`
|
|
296
|
+
adds its conversation list; or draw your own inside a `ChatProvider` around a
|
|
297
|
+
`<Chat />` with no `client`. It carries its own styles; theme it with CSS custom
|
|
298
|
+
properties on it or an ancestor: `--chat-background`, `--chat-surface`,
|
|
299
|
+
`--chat-text`, `--chat-text-muted`, `--chat-accent`, `--chat-line`,
|
|
300
|
+
`--chat-attention`, `--chat-danger`, `--chat-font`, `--chat-font-mono`,
|
|
301
|
+
`--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for spacing);
|
|
302
|
+
an unset one keeps House's light or dark look. `mountChat(element, { client })`
|
|
303
|
+
places it outside React and returns `update(props)` and `unmount()`.
|
|
304
|
+
|
|
305
|
+
Mix `ChatMessageList` (`components` takes your `UserMessage` and
|
|
306
|
+
`AssistantMessage`), `ChatInput` and `ChatQuestionCard` with your own design
|
|
307
|
+
inside a `ChatProvider`, or compose assistant-ui's primitives there; `useChat()`
|
|
308
|
+
gives `send`, the conversations, the Agents, questions to `answer`, `options`
|
|
309
|
+
to `choose`, `commands`, the queue to `edit` or `unqueue`, `stop`, `kill` and
|
|
310
|
+
outcomes; never replace its messages, sending or store. A secret question is
|
|
311
|
+
never answered here; typed answers live in Presentation State's `typed` key:
|
|
312
|
+
keep it, and change Presentation State only inside `inTurn(client, work)` from
|
|
313
|
+
`@agentshouse/mdruntime/client`. `Markdown` draws Markdown safely.
|
|
240
314
|
|
|
241
315
|
## What an agent must never do
|
|
242
316
|
|
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
|
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,kBAAkB,
|
|
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;AAwED,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAOjF;AAkLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiBtE"}
|
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
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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': carried('conversations/create', createAction),
|
|
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': carried('records/read', recordsAction),
|
|
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
|
-
return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
|
|
51
|
+
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
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:
|
|
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
|
|
28
|
-
return
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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,78 @@ 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
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
+
};
|
|
112
|
+
}
|
|
113
|
+
async function createAction(transport, route, input, name) {
|
|
114
|
+
const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
|
|
115
|
+
if (outcome.kind !== 'action')
|
|
116
|
+
return outcome;
|
|
117
|
+
const held = record(outcome.result);
|
|
118
|
+
const conversation = text(held, 'conversation_id');
|
|
119
|
+
return conversation === undefined ? outcome : { ...outcome, result: { ...held, conversation } };
|
|
86
120
|
}
|
|
87
121
|
function withTurn(body) {
|
|
88
122
|
const held = record(body);
|
|
89
123
|
const turn = text(held, 'message_id');
|
|
90
|
-
return turn === undefined
|
|
124
|
+
return turn === undefined
|
|
125
|
+
? body
|
|
126
|
+
: { ...held, turn };
|
|
91
127
|
}
|
|
92
128
|
export function actionOutcome(answer, name) {
|
|
93
129
|
if (answer.status === 401)
|
|
94
130
|
return { kind: 'revoked-authorization' };
|
|
95
131
|
const refusal = doorRefusal(answer.body);
|
|
96
|
-
if (refusal !== null)
|
|
97
|
-
return { kind: 'rejected',
|
|
98
|
-
}
|
|
132
|
+
if (refusal !== null)
|
|
133
|
+
return { kind: 'rejected', ...refusal };
|
|
99
134
|
if (answer.status === 404)
|
|
100
|
-
return
|
|
135
|
+
return unimplemented(name);
|
|
101
136
|
if (answer.status === 0 || answer.status >= 400)
|
|
102
137
|
return { kind: 'transport-uncertainty' };
|
|
103
|
-
if (name === 'conversation.send')
|
|
104
|
-
return { kind: 'action', result: withTurn(answer.body) };
|
|
105
138
|
return { kind: 'action', result: answer.body };
|
|
106
139
|
}
|
|
140
|
+
function referredRecord(view, roomRef) {
|
|
141
|
+
const held = record(view);
|
|
142
|
+
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
143
|
+
return view;
|
|
144
|
+
const referrer = { room_ref: roomRef, record: held.record };
|
|
145
|
+
return {
|
|
146
|
+
...held,
|
|
147
|
+
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
async function recordsAction(transport, route, input, name) {
|
|
151
|
+
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
152
|
+
if (outcome.kind !== 'action')
|
|
153
|
+
return outcome;
|
|
154
|
+
const roomRef = text(input, 'room_ref');
|
|
155
|
+
const read = record(outcome.result);
|
|
156
|
+
return {
|
|
157
|
+
...outcome,
|
|
158
|
+
result: Array.isArray(read.records)
|
|
159
|
+
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
160
|
+
: referredRecord(outcome.result, roomRef),
|
|
161
|
+
};
|
|
162
|
+
}
|
|
107
163
|
async function carry(transport, route, name, input) {
|
|
108
|
-
|
|
109
|
-
return actionOutcome(answer, name);
|
|
164
|
+
return actionOutcome(await transport.door(route, input), name);
|
|
110
165
|
}
|
|
111
166
|
function sendFile(entry) {
|
|
112
167
|
const file = record(entry);
|
|
@@ -176,12 +231,12 @@ function uploadGrant(entry) {
|
|
|
176
231
|
return null;
|
|
177
232
|
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
178
233
|
}
|
|
179
|
-
async function
|
|
180
|
-
const
|
|
181
|
-
if (!Array.isArray(
|
|
234
|
+
async function uploadFiles(transport, input, result, name) {
|
|
235
|
+
const sent = record(result).files;
|
|
236
|
+
if (!Array.isArray(sent) || sent.length === 0)
|
|
182
237
|
return null;
|
|
183
238
|
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
184
|
-
for (const [index, entry] of
|
|
239
|
+
for (const [index, entry] of sent.entries()) {
|
|
185
240
|
const grant = uploadGrant(entry);
|
|
186
241
|
if (grant === 'absent')
|
|
187
242
|
continue;
|
|
@@ -189,81 +244,35 @@ async function uploadOriginals(transport, input, result) {
|
|
|
189
244
|
return malformed();
|
|
190
245
|
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
191
246
|
if (bytes === null) {
|
|
192
|
-
return {
|
|
247
|
+
return {
|
|
248
|
+
kind: 'rejected',
|
|
249
|
+
code: 'conversation_file_descriptor_required',
|
|
250
|
+
fields: {},
|
|
251
|
+
retryable: false,
|
|
252
|
+
};
|
|
193
253
|
}
|
|
194
254
|
const failed = delivered(await transport.transfer({
|
|
195
|
-
act: '
|
|
196
|
-
method: 'POST',
|
|
255
|
+
act: 'conversation_file_upload',
|
|
197
256
|
url: grant.url,
|
|
198
|
-
answer: 'json',
|
|
199
257
|
body: bytes,
|
|
200
258
|
operation: grant.operation,
|
|
201
|
-
}),
|
|
259
|
+
}), name);
|
|
202
260
|
if (failed !== null)
|
|
203
261
|
return failed;
|
|
204
262
|
}
|
|
205
263
|
return null;
|
|
206
264
|
}
|
|
207
|
-
async function
|
|
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) {
|
|
265
|
+
async function sendAction(transport, route, input, name) {
|
|
256
266
|
const body = sendBody(input);
|
|
257
267
|
if (body === null)
|
|
258
268
|
return malformed();
|
|
259
|
-
const
|
|
260
|
-
const outcome = actionOutcome(answer, 'conversation.send');
|
|
269
|
+
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
261
270
|
if (outcome.kind !== 'action')
|
|
262
271
|
return outcome;
|
|
263
|
-
const uploaded = await
|
|
272
|
+
const uploaded = await uploadFiles(transport, input, outcome.result, name);
|
|
264
273
|
if (uploaded !== null)
|
|
265
274
|
return uploaded;
|
|
266
|
-
return outcome;
|
|
275
|
+
return { ...outcome, result: withTurn(outcome.result) };
|
|
267
276
|
}
|
|
268
277
|
function historyCursor(value) {
|
|
269
278
|
const acceptedAt = text(value, 'accepted_at');
|
|
@@ -287,12 +296,19 @@ export function acceptedMessage(entry) {
|
|
|
287
296
|
const cursor = historyCursor(entry);
|
|
288
297
|
if (cursor === null)
|
|
289
298
|
return null;
|
|
299
|
+
const message = structuredClone(record(entry));
|
|
300
|
+
const referrer = { message: cursor.message_id };
|
|
290
301
|
return {
|
|
291
302
|
identity: cursor.message_id,
|
|
292
303
|
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
293
304
|
position: position(cursor),
|
|
294
305
|
text: text(entry, 'text') ?? '',
|
|
295
|
-
message:
|
|
306
|
+
message: Array.isArray(message.files)
|
|
307
|
+
? {
|
|
308
|
+
...message,
|
|
309
|
+
files: message.files.map((file) => ({ ...record(file), referrer })),
|
|
310
|
+
}
|
|
311
|
+
: message,
|
|
296
312
|
};
|
|
297
313
|
}
|
|
298
314
|
function historyPage(entry) {
|
|
@@ -329,17 +345,17 @@ function historyAsks(input) {
|
|
|
329
345
|
}
|
|
330
346
|
return asks;
|
|
331
347
|
}
|
|
332
|
-
async function historyAction(transport, input) {
|
|
348
|
+
async function historyAction(transport, route, input, name) {
|
|
333
349
|
const asks = historyAsks(input);
|
|
334
350
|
if (asks === null)
|
|
335
351
|
return malformed();
|
|
336
352
|
const histories = [];
|
|
337
353
|
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
338
|
-
const answer = await transport.door(
|
|
354
|
+
const answer = await transport.door(route, {
|
|
339
355
|
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
340
356
|
limit: HISTORY_PAGE,
|
|
341
357
|
});
|
|
342
|
-
const outcome = actionOutcome(answer,
|
|
358
|
+
const outcome = actionOutcome(answer, name);
|
|
343
359
|
if (outcome.kind !== 'action')
|
|
344
360
|
return outcome;
|
|
345
361
|
const answered = record(outcome.result).histories;
|
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,EAgBd,MAAM,wBAAwB,CAAC;AAuChC,OAAO,EASL,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,CA8cpF"}
|