@agentshouse/mdruntime-adapter 0.1.0-cca5d676bc88e → 0.1.0-ce4626067e686
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 +67 -29
- package/dist/actions.d.ts +2 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +93 -121
- 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
|
|
|
@@ -50,21 +51,42 @@ open one through the Provider Action that serves it.
|
|
|
50
51
|
|
|
51
52
|
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
52
53
|
touch the network.
|
|
53
|
-
History and Call go to the Provider through the Adapter.
|
|
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
|
|
54
57
|
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
55
58
|
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
56
59
|
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
57
60
|
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
58
61
|
that document was written at a later Room Version. Each History revision
|
|
59
|
-
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
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
|
|
60
66
|
member of the
|
|
61
67
|
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
62
68
|
surface returns the authorization, performs a request the App's code
|
|
63
69
|
composes, or exposes the browser store.
|
|
64
70
|
|
|
71
|
+
Every refusal and failure carries `code` and `retryable`: each Call and History answer
|
|
72
|
+
other than its result, a refused Save or Room Draft write, a returned Room Draft's
|
|
73
|
+
reason, a Room's refusal and the Connection Refusal, and every error a member rejects
|
|
74
|
+
with, beside its message. A Provider refusal carries the Provider's own `retryable`.
|
|
75
|
+
Every code and every value the API answers is open: handle one you do not know by its
|
|
76
|
+
`code` and `retryable`.
|
|
77
|
+
|
|
65
78
|
Read the deployment facts with `observe('deployment-facts')`. Interpret the
|
|
66
79
|
opaque value using the host's contract.
|
|
67
80
|
|
|
81
|
+
`observe('member')` answers who uses the App: the User the Provider signed in,
|
|
82
|
+
`{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
|
|
83
|
+
whose `change.author.id` equals its `id` is that User's own. It is `null` until
|
|
84
|
+
the Provider first names one, and where it names none, such as a Site. The
|
|
85
|
+
MD Runtime keeps it with the Local Replicas, so it answers offline once known,
|
|
86
|
+
and every port hears the next member the Provider names; signing out answers
|
|
87
|
+
`null`, then ends the observation with the authorization. It is the only way App code learns who
|
|
88
|
+
uses it.
|
|
89
|
+
|
|
68
90
|
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
69
91
|
ships in no bundle.
|
|
70
92
|
|
|
@@ -78,22 +100,28 @@ data:
|
|
|
78
100
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
79
101
|
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
80
102
|
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
81
|
-
- **Fields.**
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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:
|
|
85
110
|
`$exists: false` keeps a missing field, `null` an explicit null, `''` empty
|
|
86
111
|
text and `$size: 0` an empty list. A date compares in calendar order and never
|
|
87
112
|
with a date-time. A reference compares by the Room Path it resolves to.
|
|
88
|
-
Untyped frontmatter
|
|
113
|
+
Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
|
|
114
|
+
values. There is no text containment or regular
|
|
89
115
|
expression.
|
|
90
116
|
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
91
|
-
reference `field
|
|
92
|
-
`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
|
|
93
119
|
matching Document of the same Room references. Each keeps a Document once.
|
|
94
120
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
95
|
-
`preamble`, `markdown`, `backlinks` and `change`, where `fields`
|
|
96
|
-
|
|
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
|
|
97
125
|
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
98
126
|
target returns only Room and Path. An unselected part is absent. Select only
|
|
99
127
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
@@ -102,17 +130,17 @@ data:
|
|
|
102
130
|
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
103
131
|
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
104
132
|
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
|
|
133
|
+
saved write takes the Provider's own once it is Accepted. A
|
|
106
134
|
Room's last change is its Document with the latest `time`.
|
|
107
135
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
108
136
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
109
137
|
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
110
|
-
over every match and ordered by `count` or a key.
|
|
111
|
-
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.
|
|
112
140
|
- **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.
|
|
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.
|
|
116
144
|
|
|
117
145
|
## Local Search rules
|
|
118
146
|
|
|
@@ -150,9 +178,9 @@ the current Room Draft; read it and write again.
|
|
|
150
178
|
|
|
151
179
|
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
152
180
|
validates locally, and on success appends one Change Batch to that Room's
|
|
153
|
-
queue and removes those Room Drafts. It is refused
|
|
181
|
+
queue and removes those Room Drafts. It is refused with the `code` `stale`,
|
|
154
182
|
`changed-underneath` naming each part whose base no longer matches the visible
|
|
155
|
-
state, or
|
|
183
|
+
state, or a local validation rule, and then creates nothing and leaves every
|
|
156
184
|
Room Draft in place. A directory move or removal is a move or removal part on
|
|
157
185
|
each Document and binary link target beneath it, saved together.
|
|
158
186
|
|
|
@@ -172,6 +200,13 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
|
172
200
|
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
173
201
|
combines, reorders, or rebases.
|
|
174
202
|
|
|
203
|
+
On a Site, every Save stays in the visitor's browser. Write grants and
|
|
204
|
+
revisions do not refuse it, and its Pending Change shows in every query and
|
|
205
|
+
across reloads until the browser's storage is cleared. It is never sent:
|
|
206
|
+
`observe('queue', room)` shows it `local`, and Sync Status never waits on it.
|
|
207
|
+
Once the Room changes so that it no longer applies, it leaves the queue and
|
|
208
|
+
returns no Room Draft.
|
|
209
|
+
|
|
175
210
|
`observe('service-mode')` answers the Provider's Service
|
|
176
211
|
Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
|
|
177
212
|
its Change Batch waits unsent, and the queue is submitted in order once the
|
|
@@ -208,7 +243,7 @@ the network. Data lives only in the App Creator's browser and with the Provider.
|
|
|
208
243
|
## App code takes the client its host hands it and never constructs a Runtime
|
|
209
244
|
|
|
210
245
|
App code takes the client its host hands it: in House,
|
|
211
|
-
`
|
|
246
|
+
`houseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
|
|
212
247
|
client House built into the page. It never constructs a Runtime or a client.
|
|
213
248
|
It imports only types from `@agentshouse/mdruntime/client`, does not call
|
|
214
249
|
`connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
|
|
@@ -217,13 +252,16 @@ served App does not.
|
|
|
217
252
|
|
|
218
253
|
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
219
254
|
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
|
|
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
|
|
223
258
|
`save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
|
|
224
259
|
already there, keeping the bases its parts have, or onto a new one, and saves
|
|
225
260
|
them together. A refused Save leaves the Room Drafts for the App to save again
|
|
226
|
-
or discard; a failure is recorded and rejects.
|
|
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`.
|
|
227
265
|
|
|
228
266
|
## What an agent must never do
|
|
229
267
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
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
|
|
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;
|
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,EAGxB,MAAM,wBAAwB,CAAC;
|
|
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;AAiEtE,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;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': mapped('conversations/create', createBody),
|
|
24
|
+
'conversation.delete': mapped('conversations/delete', controlBody),
|
|
25
|
+
'conversation.history': carried('conversations/history', historyAction),
|
|
26
|
+
'conversation.interrupt': mapped('conversations/interrupt', controlBody),
|
|
27
|
+
'conversation.kill': mapped('conversations/kill', controlBody),
|
|
28
|
+
'conversation.markDone': mapped('conversations/done'),
|
|
29
|
+
'conversation.rename': mapped('conversations/rename'),
|
|
30
|
+
'conversation.send': carried('conversations/send', sendAction),
|
|
31
|
+
'conversation.setOption': mapped('conversations/option'),
|
|
32
|
+
'feature.list': mapped('apps/features/read'),
|
|
33
|
+
'holder.list': mapped('apps/holders'),
|
|
34
|
+
'holder.ring': mapped('apps/ring'),
|
|
35
|
+
'member.list': mapped('rooms/members'),
|
|
36
|
+
'message.send': mapped('apps/messages/send'),
|
|
37
|
+
'processing.read': mapped('rooms/settings/processing/read'),
|
|
38
|
+
'record.list': mapped('records/read'),
|
|
39
|
+
'relay.read': mapped('apps/relay'),
|
|
40
|
+
'routine.list': mapped('routines/access'),
|
|
41
|
+
'routineAccess.list': mapped('routines/granted'),
|
|
42
|
+
'routineAllowance.list': mapped('routines/allowance'),
|
|
43
|
+
'routineRequest.list': mapped('routines/requests'),
|
|
44
|
+
'storage.read': mapped('storage/inventory'),
|
|
45
|
+
'trigger.list': mapped('triggers/read'),
|
|
46
|
+
'triggerOccurrence.list': mapped('triggers/fired'),
|
|
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' };
|
|
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,27 +90,25 @@ 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
|
-
return input;
|
|
95
|
+
function unimplemented(name) {
|
|
96
|
+
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
97
|
+
}
|
|
98
|
+
function createBody(input) {
|
|
99
|
+
return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
|
|
100
|
+
}
|
|
101
|
+
function controlBody(input) {
|
|
102
|
+
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
103
|
+
}
|
|
104
|
+
function answerBody(input) {
|
|
105
|
+
const nested = record(record(input).answer);
|
|
106
|
+
return {
|
|
107
|
+
conversation_id: text(input, 'conversation'),
|
|
108
|
+
operation_id: operationId(input),
|
|
109
|
+
interaction_id: text(nested, 'interaction_id'),
|
|
110
|
+
response: nested.response,
|
|
111
|
+
};
|
|
90
112
|
}
|
|
91
113
|
function withTurn(body) {
|
|
92
114
|
const held = record(body);
|
|
@@ -97,20 +119,16 @@ export function actionOutcome(answer, name) {
|
|
|
97
119
|
if (answer.status === 401)
|
|
98
120
|
return { kind: 'revoked-authorization' };
|
|
99
121
|
const refusal = doorRefusal(answer.body);
|
|
100
|
-
if (refusal !== null)
|
|
101
|
-
return { kind: 'rejected',
|
|
102
|
-
}
|
|
122
|
+
if (refusal !== null)
|
|
123
|
+
return { kind: 'rejected', ...refusal };
|
|
103
124
|
if (answer.status === 404)
|
|
104
|
-
return
|
|
125
|
+
return unimplemented(name);
|
|
105
126
|
if (answer.status === 0 || answer.status >= 400)
|
|
106
127
|
return { kind: 'transport-uncertainty' };
|
|
107
|
-
if (name === 'conversation.send')
|
|
108
|
-
return { kind: 'action', result: withTurn(answer.body) };
|
|
109
128
|
return { kind: 'action', result: answer.body };
|
|
110
129
|
}
|
|
111
130
|
async function carry(transport, route, name, input) {
|
|
112
|
-
|
|
113
|
-
return actionOutcome(answer, name);
|
|
131
|
+
return actionOutcome(await transport.door(route, input), name);
|
|
114
132
|
}
|
|
115
133
|
function sendFile(entry) {
|
|
116
134
|
const file = record(entry);
|
|
@@ -180,12 +198,12 @@ function uploadGrant(entry) {
|
|
|
180
198
|
return null;
|
|
181
199
|
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
182
200
|
}
|
|
183
|
-
async function
|
|
184
|
-
const
|
|
185
|
-
if (!Array.isArray(
|
|
201
|
+
async function uploadFiles(transport, input, result, name) {
|
|
202
|
+
const sent = record(result).files;
|
|
203
|
+
if (!Array.isArray(sent) || sent.length === 0)
|
|
186
204
|
return null;
|
|
187
205
|
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
188
|
-
for (const [index, entry] of
|
|
206
|
+
for (const [index, entry] of sent.entries()) {
|
|
189
207
|
const grant = uploadGrant(entry);
|
|
190
208
|
if (grant === 'absent')
|
|
191
209
|
continue;
|
|
@@ -193,81 +211,35 @@ async function uploadOriginals(transport, input, result) {
|
|
|
193
211
|
return malformed();
|
|
194
212
|
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
195
213
|
if (bytes === null) {
|
|
196
|
-
return {
|
|
214
|
+
return {
|
|
215
|
+
kind: 'rejected',
|
|
216
|
+
code: 'conversation_file_descriptor_required',
|
|
217
|
+
fields: {},
|
|
218
|
+
retryable: false,
|
|
219
|
+
};
|
|
197
220
|
}
|
|
198
221
|
const failed = delivered(await transport.transfer({
|
|
199
|
-
act: '
|
|
200
|
-
method: 'POST',
|
|
222
|
+
act: 'conversation_file_upload',
|
|
201
223
|
url: grant.url,
|
|
202
|
-
answer: 'json',
|
|
203
224
|
body: bytes,
|
|
204
225
|
operation: grant.operation,
|
|
205
|
-
}),
|
|
226
|
+
}), name);
|
|
206
227
|
if (failed !== null)
|
|
207
228
|
return failed;
|
|
208
229
|
}
|
|
209
230
|
return null;
|
|
210
231
|
}
|
|
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) {
|
|
232
|
+
async function sendAction(transport, route, input, name) {
|
|
260
233
|
const body = sendBody(input);
|
|
261
234
|
if (body === null)
|
|
262
235
|
return malformed();
|
|
263
|
-
const
|
|
264
|
-
const outcome = actionOutcome(answer, 'conversation.send');
|
|
236
|
+
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
265
237
|
if (outcome.kind !== 'action')
|
|
266
238
|
return outcome;
|
|
267
|
-
const uploaded = await
|
|
239
|
+
const uploaded = await uploadFiles(transport, input, outcome.result, name);
|
|
268
240
|
if (uploaded !== null)
|
|
269
241
|
return uploaded;
|
|
270
|
-
return outcome;
|
|
242
|
+
return { ...outcome, result: withTurn(outcome.result) };
|
|
271
243
|
}
|
|
272
244
|
function historyCursor(value) {
|
|
273
245
|
const acceptedAt = text(value, 'accepted_at');
|
|
@@ -333,17 +305,17 @@ function historyAsks(input) {
|
|
|
333
305
|
}
|
|
334
306
|
return asks;
|
|
335
307
|
}
|
|
336
|
-
async function historyAction(transport, input) {
|
|
308
|
+
async function historyAction(transport, route, input, name) {
|
|
337
309
|
const asks = historyAsks(input);
|
|
338
310
|
if (asks === null)
|
|
339
311
|
return malformed();
|
|
340
312
|
const histories = [];
|
|
341
313
|
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
342
|
-
const answer = await transport.door(
|
|
314
|
+
const answer = await transport.door(route, {
|
|
343
315
|
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
344
316
|
limit: HISTORY_PAGE,
|
|
345
317
|
});
|
|
346
|
-
const outcome = actionOutcome(answer,
|
|
318
|
+
const outcome = actionOutcome(answer, name);
|
|
347
319
|
if (outcome.kind !== 'action')
|
|
348
320
|
return outcome;
|
|
349
321
|
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"}
|