@agentshouse/mdruntime-adapter 0.1.0-cca5d676bc88e → 0.1.0-cd59fd8945dcb
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 +88 -29
- package/dist/actions.d.ts +40 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +104 -122
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +77 -52
- package/dist/discovery.d.ts +3 -4
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +22 -12
- package/dist/gather.d.ts +1 -0
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +11 -6
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- 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 +6 -1
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +17 -34
- package/dist/refusal.d.ts +5 -9
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +30 -17
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +17 -9
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +5 -0
- package/dist/transport.d.ts +3 -6
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +0 -1
- package/dist/write.d.ts +1 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +39 -15
- package/package.json +4 -4
package/AGENTS.md
CHANGED
|
@@ -10,13 +10,14 @@ 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
|
|
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
|
-
answers within it: a Room outside it answers as one the replica does not hold,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
conversation members, the chat draft and the
|
|
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.
|
|
20
21
|
A change of the reach reaches every open observation as its new value, a query
|
|
21
22
|
keeping every unchanged Document the same object.
|
|
22
23
|
|
|
@@ -26,6 +27,8 @@ value whole and returns its unsubscribe, and `close()` ends the observation.
|
|
|
26
27
|
Closing the port ends every handle and rejects every pending call and
|
|
27
28
|
observation; a client that reconnects observes again.
|
|
28
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.
|
|
29
32
|
Each conversation the Provider's conversation list names is held complete in the
|
|
30
33
|
browser. `conversation.list()` and `observe('conversations')` answer each with its
|
|
31
34
|
Agent's identity and name, its name, created and finished times, last outcome and live
|
|
@@ -50,21 +53,42 @@ open one through the Provider Action that serves it.
|
|
|
50
53
|
|
|
51
54
|
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
52
55
|
touch the network.
|
|
53
|
-
History and Call go to the Provider through the Adapter.
|
|
56
|
+
History and Call go to the Provider through the Adapter. Call takes the Action names
|
|
57
|
+
the Adapter declares; any other name answers `undeclared` without reaching the
|
|
58
|
+
Provider. A Call result whose
|
|
54
59
|
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
55
60
|
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
56
61
|
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
57
62
|
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
58
63
|
that document was written at a later Room Version. Each History revision
|
|
59
|
-
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
64
|
+
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
65
|
+
History of a Path no current document holds answers the removed document's
|
|
66
|
+
revisions with `deleted: true`, newest first; that revision is what a link to
|
|
67
|
+
the Path opens. Every
|
|
60
68
|
member of the
|
|
61
69
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
62
70
|
surface returns the authorization, performs a request the App's code
|
|
63
71
|
composes, or exposes the browser store.
|
|
64
72
|
|
|
73
|
+
Every refusal and failure carries `code` and `retryable`: each Call and History answer
|
|
74
|
+
other than its result, a refused Save or Room Draft write, a returned Room Draft's
|
|
75
|
+
reason, a Room's refusal and the Connection Refusal, and every error a member rejects
|
|
76
|
+
with, beside its message. A Provider refusal carries the Provider's own `retryable`.
|
|
77
|
+
Every code and every value the API answers is open: handle one you do not know by its
|
|
78
|
+
`code` and `retryable`.
|
|
79
|
+
|
|
65
80
|
Read the deployment facts with `observe('deployment-facts')`. Interpret the
|
|
66
81
|
opaque value using the host's contract.
|
|
67
82
|
|
|
83
|
+
`observe('member')` answers who uses the App: the User the Provider signed in,
|
|
84
|
+
`{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
|
|
85
|
+
whose `change.author.id` equals its `id` is that User's own. It is `null` until
|
|
86
|
+
the Provider first names one, and where it names none, such as a Site. The
|
|
87
|
+
MD Runtime keeps it with the Local Replicas, so it answers offline once known,
|
|
88
|
+
and every port hears the next member the Provider names; signing out answers
|
|
89
|
+
`null`, then ends the observation with the authorization. It is the only way App code learns who
|
|
90
|
+
uses it.
|
|
91
|
+
|
|
68
92
|
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
69
93
|
ships in no bundle.
|
|
70
94
|
|
|
@@ -78,22 +102,28 @@ data:
|
|
|
78
102
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
79
103
|
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
80
104
|
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
81
|
-
- **Fields.**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
105
|
+
- **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
|
|
106
|
+
`/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
|
|
107
|
+
meets a list applies to every item and a number names one item. `where` names
|
|
108
|
+
pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
|
|
109
|
+
when any item satisfies it. A bare value is equality; the operators are `$eq`,
|
|
110
|
+
`$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
|
|
111
|
+
`$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
|
|
85
112
|
`$exists: false` keeps a missing field, `null` an explicit null, `''` empty
|
|
86
113
|
text and `$size: 0` an empty list. A date compares in calendar order and never
|
|
87
114
|
with a date-time. A reference compares by the Room Path it resolves to.
|
|
88
|
-
Untyped frontmatter
|
|
115
|
+
Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
|
|
116
|
+
values. There is no text containment or regular
|
|
89
117
|
expression.
|
|
90
118
|
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
91
|
-
reference `field
|
|
92
|
-
`backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
119
|
+
reference at pointer `field`, at any depth, points to a matching Document of the
|
|
120
|
+
same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
93
121
|
matching Document of the same Room references. Each keeps a Document once.
|
|
94
122
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
95
|
-
`preamble`, `markdown`, `backlinks` and `change`, where `fields`
|
|
96
|
-
|
|
123
|
+
`preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
|
|
124
|
+
list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
125
|
+
return the frontmatter holding only them, nested as written. A backlink names
|
|
126
|
+
the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
|
|
97
127
|
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
98
128
|
target returns only Room and Path. An unselected part is absent. Select only
|
|
99
129
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
@@ -102,17 +132,17 @@ data:
|
|
|
102
132
|
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
103
133
|
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
104
134
|
a Site. An unsent edit or move keeps it, an unsent creation has none, and a
|
|
105
|
-
saved write takes the Provider's own once it is Accepted
|
|
135
|
+
saved write takes the Provider's own once it is Accepted. A
|
|
106
136
|
Room's last change is its Document with the latest `time`.
|
|
107
137
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
108
138
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
109
139
|
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
110
|
-
over every match and ordered by `count` or a key.
|
|
111
|
-
or the groups.
|
|
140
|
+
over every match and ordered by `count` or a key. A sort or group takes only a
|
|
141
|
+
pointer that holds one value. `limit` bounds the Documents or the groups.
|
|
112
142
|
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
113
|
-
Rooms and Sync Status. An invalid query fails with `
|
|
114
|
-
`unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
115
|
-
answers an empty result in its place.
|
|
143
|
+
Rooms and Sync Status. An invalid query fails with the `code`
|
|
144
|
+
`invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
145
|
+
and never answers an empty result in its place.
|
|
116
146
|
|
|
117
147
|
## Local Search rules
|
|
118
148
|
|
|
@@ -150,9 +180,9 @@ the current Room Draft; read it and write again.
|
|
|
150
180
|
|
|
151
181
|
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
152
182
|
validates locally, and on success appends one Change Batch to that Room's
|
|
153
|
-
queue and removes those Room Drafts. It is refused
|
|
183
|
+
queue and removes those Room Drafts. It is refused with the `code` `stale`,
|
|
154
184
|
`changed-underneath` naming each part whose base no longer matches the visible
|
|
155
|
-
state, or
|
|
185
|
+
state, or a local validation rule, and then creates nothing and leaves every
|
|
156
186
|
Room Draft in place. A directory move or removal is a move or removal part on
|
|
157
187
|
each Document and binary link target beneath it, saved together.
|
|
158
188
|
|
|
@@ -172,6 +202,13 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
|
172
202
|
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
173
203
|
combines, reorders, or rebases.
|
|
174
204
|
|
|
205
|
+
On a Site, every Save stays in the visitor's browser. Write grants and
|
|
206
|
+
revisions do not refuse it, and its Pending Change shows in every query and
|
|
207
|
+
across reloads until the browser's storage is cleared. It is never sent:
|
|
208
|
+
`observe('queue', room)` shows it `local`, and Sync Status never waits on it.
|
|
209
|
+
Once the Room changes so that it no longer applies, it leaves the queue and
|
|
210
|
+
returns no Room Draft.
|
|
211
|
+
|
|
175
212
|
`observe('service-mode')` answers the Provider's Service
|
|
176
213
|
Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
|
|
177
214
|
its Change Batch waits unsent, and the queue is submitted in order once the
|
|
@@ -208,7 +245,7 @@ the network. Data lives only in the App Creator's browser and with the Provider.
|
|
|
208
245
|
## App code takes the client its host hands it and never constructs a Runtime
|
|
209
246
|
|
|
210
247
|
App code takes the client its host hands it: in House,
|
|
211
|
-
`
|
|
248
|
+
`houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
|
|
212
249
|
client House built into the page. It never constructs a Runtime or a client.
|
|
213
250
|
It imports only types from `@agentshouse/mdruntime/client`, does not call
|
|
214
251
|
`connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
|
|
@@ -217,13 +254,35 @@ served App does not.
|
|
|
217
254
|
|
|
218
255
|
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
219
256
|
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
220
|
-
the arguments of `observe` and returns the topic's
|
|
221
|
-
|
|
222
|
-
nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
|
|
257
|
+
the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
|
|
258
|
+
first value arrives, then `{ state: 'ready', value }`, re-rendering on each
|
|
259
|
+
change; a `null` client observes nothing and stays loading. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
|
|
223
260
|
`save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
|
|
224
261
|
already there, keeping the bases its parts have, or onto a new one, and saves
|
|
225
262
|
them together. A refused Save leaves the Room Drafts for the App to save again
|
|
226
|
-
or discard; a failure is recorded and rejects.
|
|
263
|
+
or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
|
|
264
|
+
roomDrafts)` is that save outside a component. A react-admin or Refine App
|
|
265
|
+
reads and writes its Rooms through the data providers of
|
|
266
|
+
`@agentshouse/mdruntime-families`.
|
|
267
|
+
|
|
268
|
+
## The Chat
|
|
269
|
+
|
|
270
|
+
`@agentshouse/mdruntime/chat` holds the Chat: one data layer over the
|
|
271
|
+
conversations, the same for every App. React and `@assistant-ui/react` are
|
|
272
|
+
required peers of this entry, so every App that uses it adds React as a
|
|
273
|
+
dependency, also an App not written in React. Wrap your own assistant-ui
|
|
274
|
+
primitives in `<ChatProvider client={runtime} conversation={id} agent={agent}>`:
|
|
275
|
+
`conversation` is the one it opens, `null` for a new chat, `agent` the Agent a
|
|
276
|
+
new chat goes to, and `onOpen` hears each conversation it opens. Thread, Messages,
|
|
277
|
+
Composer, its attachments and the thread list run on it: sending with files, a
|
|
278
|
+
message sent mid-turn waiting in the queue, Stop, rename, Done as archive and
|
|
279
|
+
delete. `useChat()` gives the rest: `send`, through the same queue, the
|
|
280
|
+
conversations, the Agents, the open
|
|
281
|
+
questions to `answer`, the CLI's `options` to `choose` and `commands`, the queue
|
|
282
|
+
to `edit` or `unqueue`, `kill`, and each act's outcome. A sent message shows at
|
|
283
|
+
once until House keeps it, and the unsent text stays in the chat draft, the same
|
|
284
|
+
in every composer over that conversation. A secret
|
|
285
|
+
question is never answered here. Never replace its messages, sending or store.
|
|
227
286
|
|
|
228
287
|
## What an agent must never do
|
|
229
288
|
|
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
|
-
|
|
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>>;
|
|
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;AAqJD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
|
package/dist/actions.js
CHANGED
|
@@ -1,50 +1,74 @@
|
|
|
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
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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': 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'),
|
|
21
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]));
|
|
50
|
+
export function houseConversationAgents(locator) {
|
|
51
|
+
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
52
|
+
}
|
|
22
53
|
export function declaredActions(routes) {
|
|
23
|
-
const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
|
|
24
54
|
return routes.map((route) => ({
|
|
25
|
-
name:
|
|
55
|
+
name: APP_NAMES.get(route) ?? route,
|
|
26
56
|
inputShape: {},
|
|
27
57
|
resultKind: 'house',
|
|
28
58
|
}));
|
|
29
59
|
}
|
|
30
60
|
export function houseAction(transport, request) {
|
|
31
|
-
if (request.name
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return attachAction(transport, request.input);
|
|
37
|
-
if (request.name === 'attachments/get')
|
|
38
|
-
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));
|
|
39
66
|
const route = routeOf(request.name);
|
|
40
67
|
if (route === null)
|
|
41
68
|
return Promise.resolve(malformed());
|
|
42
69
|
return carry(transport, route, request.name, request.input);
|
|
43
70
|
}
|
|
44
71
|
function routeOf(name) {
|
|
45
|
-
const mapped = CONVERSATION_ROUTES.get(name);
|
|
46
|
-
if (mapped !== undefined)
|
|
47
|
-
return mapped;
|
|
48
72
|
const parts = name.split('/');
|
|
49
73
|
if (parts.some((part) => part === '.' || part === '..'))
|
|
50
74
|
return null;
|
|
@@ -66,51 +90,55 @@ function operationId(input) {
|
|
|
66
90
|
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
67
91
|
}
|
|
68
92
|
function malformed() {
|
|
69
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {} };
|
|
93
|
+
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
70
94
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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 } };
|
|
90
120
|
}
|
|
91
121
|
function withTurn(body) {
|
|
92
122
|
const held = record(body);
|
|
93
123
|
const turn = text(held, 'message_id');
|
|
94
|
-
return turn === undefined
|
|
124
|
+
return turn === undefined
|
|
125
|
+
? body
|
|
126
|
+
: { ...held, turn };
|
|
95
127
|
}
|
|
96
128
|
export function actionOutcome(answer, name) {
|
|
97
129
|
if (answer.status === 401)
|
|
98
130
|
return { kind: 'revoked-authorization' };
|
|
99
131
|
const refusal = doorRefusal(answer.body);
|
|
100
|
-
if (refusal !== null)
|
|
101
|
-
return { kind: 'rejected',
|
|
102
|
-
}
|
|
132
|
+
if (refusal !== null)
|
|
133
|
+
return { kind: 'rejected', ...refusal };
|
|
103
134
|
if (answer.status === 404)
|
|
104
|
-
return
|
|
135
|
+
return unimplemented(name);
|
|
105
136
|
if (answer.status === 0 || answer.status >= 400)
|
|
106
137
|
return { kind: 'transport-uncertainty' };
|
|
107
|
-
if (name === 'conversation.send')
|
|
108
|
-
return { kind: 'action', result: withTurn(answer.body) };
|
|
109
138
|
return { kind: 'action', result: answer.body };
|
|
110
139
|
}
|
|
111
140
|
async function carry(transport, route, name, input) {
|
|
112
|
-
|
|
113
|
-
return actionOutcome(answer, name);
|
|
141
|
+
return actionOutcome(await transport.door(route, input), name);
|
|
114
142
|
}
|
|
115
143
|
function sendFile(entry) {
|
|
116
144
|
const file = record(entry);
|
|
@@ -180,12 +208,12 @@ function uploadGrant(entry) {
|
|
|
180
208
|
return null;
|
|
181
209
|
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
182
210
|
}
|
|
183
|
-
async function
|
|
184
|
-
const
|
|
185
|
-
if (!Array.isArray(
|
|
211
|
+
async function uploadFiles(transport, input, result, name) {
|
|
212
|
+
const sent = record(result).files;
|
|
213
|
+
if (!Array.isArray(sent) || sent.length === 0)
|
|
186
214
|
return null;
|
|
187
215
|
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
188
|
-
for (const [index, entry] of
|
|
216
|
+
for (const [index, entry] of sent.entries()) {
|
|
189
217
|
const grant = uploadGrant(entry);
|
|
190
218
|
if (grant === 'absent')
|
|
191
219
|
continue;
|
|
@@ -193,81 +221,35 @@ async function uploadOriginals(transport, input, result) {
|
|
|
193
221
|
return malformed();
|
|
194
222
|
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
195
223
|
if (bytes === null) {
|
|
196
|
-
return {
|
|
224
|
+
return {
|
|
225
|
+
kind: 'rejected',
|
|
226
|
+
code: 'conversation_file_descriptor_required',
|
|
227
|
+
fields: {},
|
|
228
|
+
retryable: false,
|
|
229
|
+
};
|
|
197
230
|
}
|
|
198
231
|
const failed = delivered(await transport.transfer({
|
|
199
|
-
act: '
|
|
200
|
-
method: 'POST',
|
|
232
|
+
act: 'conversation_file_upload',
|
|
201
233
|
url: grant.url,
|
|
202
|
-
answer: 'json',
|
|
203
234
|
body: bytes,
|
|
204
235
|
operation: grant.operation,
|
|
205
|
-
}),
|
|
236
|
+
}), name);
|
|
206
237
|
if (failed !== null)
|
|
207
238
|
return failed;
|
|
208
239
|
}
|
|
209
240
|
return null;
|
|
210
241
|
}
|
|
211
|
-
async function
|
|
212
|
-
const { blob, ...descriptor } = record(input);
|
|
213
|
-
const bytes = await fileBytes({ blob });
|
|
214
|
-
if (bytes === null)
|
|
215
|
-
return malformed();
|
|
216
|
-
const answer = await transport.door('/door/attachments/upload', descriptor);
|
|
217
|
-
const outcome = actionOutcome(answer, 'attachments/upload');
|
|
218
|
-
if (outcome.kind !== 'action')
|
|
219
|
-
return outcome;
|
|
220
|
-
const grant = uploadGrant(outcome.result);
|
|
221
|
-
if (grant === 'absent')
|
|
222
|
-
return outcome;
|
|
223
|
-
if (grant === null)
|
|
224
|
-
return malformed();
|
|
225
|
-
const stored = await transport.transfer({
|
|
226
|
-
act: 'original_upload',
|
|
227
|
-
method: 'POST',
|
|
228
|
-
url: grant.url,
|
|
229
|
-
answer: 'json',
|
|
230
|
-
body: bytes,
|
|
231
|
-
operation: grant.operation,
|
|
232
|
-
});
|
|
233
|
-
return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };
|
|
234
|
-
}
|
|
235
|
-
async function openAction(transport, input) {
|
|
236
|
-
const answer = await transport.door('/door/attachments/get', input);
|
|
237
|
-
const outcome = actionOutcome(answer, 'attachments/get');
|
|
238
|
-
if (outcome.kind !== 'action')
|
|
239
|
-
return outcome;
|
|
240
|
-
const { download, ...opened } = record(outcome.result);
|
|
241
|
-
if (download === undefined)
|
|
242
|
-
return outcome;
|
|
243
|
-
const grant = record(download);
|
|
244
|
-
if (grant.method !== 'GET' || typeof grant.url !== 'string')
|
|
245
|
-
return malformed();
|
|
246
|
-
const read = await transport.transfer({
|
|
247
|
-
act: 'original_download',
|
|
248
|
-
method: 'GET',
|
|
249
|
-
url: grant.url,
|
|
250
|
-
answer: 'bytes',
|
|
251
|
-
});
|
|
252
|
-
const failed = delivered(read, 'attachments/get');
|
|
253
|
-
if (failed !== null)
|
|
254
|
-
return failed;
|
|
255
|
-
if (!(read.body instanceof Blob))
|
|
256
|
-
return { kind: 'transport-uncertainty' };
|
|
257
|
-
return { kind: 'action', result: { ...opened, blob: read.body } };
|
|
258
|
-
}
|
|
259
|
-
async function sendAction(transport, input) {
|
|
242
|
+
async function sendAction(transport, route, input, name) {
|
|
260
243
|
const body = sendBody(input);
|
|
261
244
|
if (body === null)
|
|
262
245
|
return malformed();
|
|
263
|
-
const
|
|
264
|
-
const outcome = actionOutcome(answer, 'conversation.send');
|
|
246
|
+
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
265
247
|
if (outcome.kind !== 'action')
|
|
266
248
|
return outcome;
|
|
267
|
-
const uploaded = await
|
|
249
|
+
const uploaded = await uploadFiles(transport, input, outcome.result, name);
|
|
268
250
|
if (uploaded !== null)
|
|
269
251
|
return uploaded;
|
|
270
|
-
return outcome;
|
|
252
|
+
return { ...outcome, result: withTurn(outcome.result) };
|
|
271
253
|
}
|
|
272
254
|
function historyCursor(value) {
|
|
273
255
|
const acceptedAt = text(value, 'accepted_at');
|
|
@@ -333,17 +315,17 @@ function historyAsks(input) {
|
|
|
333
315
|
}
|
|
334
316
|
return asks;
|
|
335
317
|
}
|
|
336
|
-
async function historyAction(transport, input) {
|
|
318
|
+
async function historyAction(transport, route, input, name) {
|
|
337
319
|
const asks = historyAsks(input);
|
|
338
320
|
if (asks === null)
|
|
339
321
|
return malformed();
|
|
340
322
|
const histories = [];
|
|
341
323
|
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
342
|
-
const answer = await transport.door(
|
|
324
|
+
const answer = await transport.door(route, {
|
|
343
325
|
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
344
326
|
limit: HISTORY_PAGE,
|
|
345
327
|
});
|
|
346
|
-
const outcome = actionOutcome(answer,
|
|
328
|
+
const outcome = actionOutcome(answer, name);
|
|
347
329
|
if (outcome.kind !== 'action')
|
|
348
330
|
return outcome;
|
|
349
331
|
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,EAWd,MAAM,wBAAwB,CAAC;
|
|
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"}
|