@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c0074032f9909
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/README.md +32 -0
- package/dist/actions.d.ts +8 -16
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +43 -436
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +352 -231
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/digest.js +1 -5
- package/dist/discovery.d.ts +49 -42
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +317 -232
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -3
- package/dist/map.d.ts +2 -3
- package/dist/map.d.ts.map +1 -1
- package/dist/map.js +6 -7
- package/dist/model.d.ts +8 -19
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +43 -57
- package/dist/read.d.ts +65 -54
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +217 -295
- package/dist/refusal.d.ts +7 -11
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +53 -69
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +103 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +142 -172
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +20 -9
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +394 -236
- package/dist/transport.d.ts +172 -47
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +58 -12
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +13 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +65 -0
- package/dist/version.d.ts +3 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +32 -18
- package/dist/write.d.ts +24 -11
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +263 -241
- package/package.json +10 -14
- package/AGENTS.md +0 -79
- package/dist/actions.js.map +0 -1
- package/dist/adapter.js.map +0 -1
- package/dist/digest.js.map +0 -1
- package/dist/discovery.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/map.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/read.js.map +0 -1
- package/dist/refusal.js.map +0 -1
- package/dist/site.js.map +0 -1
- package/dist/stream.js.map +0 -1
- package/dist/transport.js.map +0 -1
- package/dist/version.js.map +0 -1
- package/dist/write.js.map +0 -1
package/README.md
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# `@agentshouse/mdruntime-adapter`
|
|
2
|
+
|
|
3
|
+
The [Agents House](https://agents.house) Adapter for
|
|
4
|
+
[`@agentshouse/mdruntime`](https://www.npmjs.com/package/@agentshouse/mdruntime):
|
|
5
|
+
it connects a Runtime host to Agents House as its Provider.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @agentshouse/mdruntime-adapter @agentshouse/mdruntime
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
A Runtime host creates the Adapter and passes it to the Runtime:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { serveMdRuntime } from '@agentshouse/mdruntime/host';
|
|
19
|
+
import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
|
|
20
|
+
|
|
21
|
+
const adapter = createAgentsHouseAdapter({ transport, authorize });
|
|
22
|
+
const host = serveMdRuntime({ adapter, shell });
|
|
23
|
+
host.attach(port, { app: 'my-app' });
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
App code never imports this package; it reaches the Runtime only through the
|
|
27
|
+
client its host hands it. The rules an App's agent follows are the `apps/` pages
|
|
28
|
+
of House's Guide, which House's `guide/open` opens.
|
|
29
|
+
|
|
30
|
+
## License
|
|
31
|
+
|
|
32
|
+
MIT
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,16 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type {
|
|
3
|
-
export
|
|
4
|
-
export declare const
|
|
5
|
-
export declare const
|
|
6
|
-
export declare
|
|
7
|
-
export declare
|
|
8
|
-
export declare function
|
|
9
|
-
export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
|
|
10
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
11
|
-
export declare function readConversationHistory(transport: HouseDoor, conversationId: string): Promise<{
|
|
12
|
-
messages: unknown[];
|
|
13
|
-
} | {
|
|
14
|
-
outcome: ActionResult;
|
|
15
|
-
}>;
|
|
16
|
-
//# sourceMappingURL=actions.d.ts.map
|
|
1
|
+
import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
3
|
+
export type HouseActDoor = Pick<HouseTransport, 'door'>;
|
|
4
|
+
export declare const HOUSE_UNKEPT_READS: readonly string[];
|
|
5
|
+
export declare const HOUSE_LEADING_READS: readonly string[];
|
|
6
|
+
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
7
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
8
|
+
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG7F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAExD,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAI/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAIhD,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAEvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAwBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,CAajG"}
|
package/dist/actions.js
CHANGED
|
@@ -1,454 +1,61 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import { PRIVATE_AUTHORITY } from './transport.js';
|
|
5
|
-
export const CONVERSATION_ACTIONS = [
|
|
6
|
-
'conversation.create',
|
|
7
|
-
'conversation.send',
|
|
8
|
-
'conversation.answer',
|
|
9
|
-
'conversation.interrupt',
|
|
10
|
-
'conversation.kill',
|
|
11
|
-
'conversation.cancel',
|
|
12
|
-
'conversation.delete',
|
|
13
|
-
'conversation.history'
|
|
14
|
-
];
|
|
15
|
-
export const HOUSE_ACTS = [
|
|
16
|
-
'conversations/interaction/read',
|
|
17
|
-
'conversations/originals/read',
|
|
18
|
-
'apps/read',
|
|
19
|
-
'apps/customize',
|
|
20
|
-
'rooms/read',
|
|
21
|
-
'rooms/access/read',
|
|
22
|
-
'rooms/access/invitations',
|
|
23
|
-
'rooms/access/entries',
|
|
24
|
-
'rooms/access/invite',
|
|
25
|
-
'rooms/access/invitation-cancel',
|
|
26
|
-
'rooms/access/revoke',
|
|
27
|
-
'rooms/access/leave',
|
|
28
|
-
'rooms/roles/define',
|
|
29
|
-
'rooms/roles/remove',
|
|
30
|
-
'rooms/roles/assign',
|
|
31
|
-
'rooms/roles/unassign',
|
|
32
|
-
'rooms/settings/processing/read',
|
|
33
|
-
'rooms/settings/processing/write',
|
|
34
|
-
'profiles/create',
|
|
35
|
-
'profiles/read',
|
|
36
|
-
'profiles/edit',
|
|
37
|
-
'profiles/duplicate',
|
|
38
|
-
'profiles/delegate',
|
|
39
|
-
'agents/create',
|
|
40
|
-
'agents/read',
|
|
41
|
-
'routines/requests',
|
|
42
|
-
'routines/access',
|
|
43
|
-
'routines/owned',
|
|
44
|
-
'routines/granted',
|
|
45
|
-
'routines/grant',
|
|
46
|
-
'routines/send',
|
|
47
|
-
'routines/cancel',
|
|
48
|
-
'routines/start',
|
|
49
|
-
'routines/schedules',
|
|
50
|
-
'routines/schedules/create',
|
|
51
|
-
'routines/schedules/enabled',
|
|
1
|
+
import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
import { refusedFor } from './uncertain.js';
|
|
3
|
+
export const HOUSE_UNKEPT_READS = [
|
|
52
4
|
'account/security/read',
|
|
53
|
-
'
|
|
54
|
-
'
|
|
55
|
-
'usage/statement',
|
|
56
|
-
'storage/blob-store',
|
|
57
|
-
'storage/blob-store/select',
|
|
58
|
-
'storage/connections',
|
|
59
|
-
'storage/archive',
|
|
60
|
-
'storage/archive/status',
|
|
61
|
-
'environments/read',
|
|
62
|
-
'environments/create',
|
|
63
|
-
'environments/start',
|
|
64
|
-
'environments/stop',
|
|
65
|
-
'environments/delete',
|
|
66
|
-
'environments/renewals/read',
|
|
67
|
-
'environments/work/read',
|
|
68
|
-
'nodes/read'
|
|
5
|
+
'billing/read',
|
|
6
|
+
'clients/last-use/list',
|
|
69
7
|
];
|
|
70
|
-
export const
|
|
71
|
-
|
|
72
|
-
|
|
8
|
+
export const HOUSE_LEADING_READS = [
|
|
9
|
+
'apps/list',
|
|
10
|
+
'sites/list',
|
|
11
|
+
'rooms/members/list',
|
|
73
12
|
];
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
77
|
-
const CONVERSATION_ROUTES = {
|
|
78
|
-
'conversation.create': '/door/conversations/create',
|
|
79
|
-
'conversation.send': '/door/conversations/send',
|
|
80
|
-
'conversation.answer': '/door/conversations/interaction/answer',
|
|
81
|
-
'conversation.interrupt': '/door/conversations/interrupt',
|
|
82
|
-
'conversation.kill': '/door/conversations/kill',
|
|
83
|
-
'conversation.cancel': '/door/conversations/cancel',
|
|
84
|
-
'conversation.delete': '/door/conversations/delete',
|
|
85
|
-
'conversation.history': '/door/conversations/history',
|
|
86
|
-
'conversations/interaction/read': '/door/conversations/interaction/read',
|
|
87
|
-
'conversations/originals/read': '/door/conversations/originals/read'
|
|
88
|
-
};
|
|
89
|
-
export const HOUSE_CONVERSATION_CARDS = {
|
|
90
|
-
locator: PRIVATE_AUTHORITY,
|
|
91
|
-
type: 'conversation',
|
|
92
|
-
identity: 'conversation',
|
|
93
|
-
agent: 'agent'
|
|
94
|
-
};
|
|
95
|
-
export function declaredActions() {
|
|
96
|
-
return HOUSE_PROVIDER_ACTIONS.map((name)=>({
|
|
97
|
-
name,
|
|
98
|
-
inputShape: {},
|
|
99
|
-
resultKind: 'house'
|
|
100
|
-
}));
|
|
13
|
+
export function declaredActions(routes) {
|
|
14
|
+
return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
|
|
101
15
|
}
|
|
102
16
|
export function houseAction(transport, request) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
fields: {
|
|
108
|
-
name: request.name,
|
|
109
|
-
mdModel: VERSION
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
if (request.name === 'conversation.send') return sendAction(transport, request.input);
|
|
114
|
-
if (request.name === 'conversation.history') return historyAction(transport, request.input);
|
|
115
|
-
return carry(transport, request.name, request.input);
|
|
17
|
+
const route = routeOf(request.name);
|
|
18
|
+
if (route === null)
|
|
19
|
+
return Promise.resolve(malformed());
|
|
20
|
+
return carry(transport, route, request.name, request.input);
|
|
116
21
|
}
|
|
117
22
|
function routeOf(name) {
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
function operationId(input) {
|
|
128
|
-
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
23
|
+
const parts = name.split('/');
|
|
24
|
+
if (parts.some((part) => part === '.' || part === '..'))
|
|
25
|
+
return null;
|
|
26
|
+
try {
|
|
27
|
+
return `/door/${parts.map(encodeURIComponent).join('/')}`;
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
129
32
|
}
|
|
130
33
|
function malformed() {
|
|
131
|
-
return {
|
|
132
|
-
kind: 'rejected',
|
|
133
|
-
code: 'invalid_request',
|
|
134
|
-
fields: {}
|
|
135
|
-
};
|
|
34
|
+
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
136
35
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
return {
|
|
140
|
-
agent_id: text(input, 'agent_id'),
|
|
141
|
-
operation_id: operationId(input)
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
if (name === 'conversation.interrupt' || name === 'conversation.kill' || name === 'conversation.delete') {
|
|
145
|
-
return {
|
|
146
|
-
conversation_id: text(input, 'conversation'),
|
|
147
|
-
operation_id: operationId(input)
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
if (name === 'conversation.cancel') {
|
|
151
|
-
return {
|
|
152
|
-
conversation_id: text(input, 'conversation'),
|
|
153
|
-
message_id: text(input, 'turn'),
|
|
154
|
-
operation_id: operationId(input)
|
|
155
|
-
};
|
|
156
|
-
}
|
|
157
|
-
if (name === 'conversation.answer') {
|
|
158
|
-
const nested = record(record(input).answer);
|
|
159
|
-
return {
|
|
160
|
-
conversation_id: text(input, 'conversation'),
|
|
161
|
-
operation_id: operationId(input),
|
|
162
|
-
interaction_id: text(nested, 'interaction_id'),
|
|
163
|
-
revision: nested.revision,
|
|
164
|
-
response: nested.response
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
return input;
|
|
36
|
+
function unimplemented(name) {
|
|
37
|
+
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
168
38
|
}
|
|
169
|
-
function
|
|
170
|
-
|
|
171
|
-
const turn = text(held, 'message_id');
|
|
172
|
-
return turn === undefined ? body : {
|
|
173
|
-
...held,
|
|
174
|
-
turn
|
|
175
|
-
};
|
|
39
|
+
function numbered(input) {
|
|
40
|
+
return typeof input?.operation_id === 'string';
|
|
176
41
|
}
|
|
177
|
-
export function actionOutcome(answer, name) {
|
|
178
|
-
if (answer.status === 401)
|
|
179
|
-
kind: 'revoked-authorization'
|
|
180
|
-
};
|
|
42
|
+
export function actionOutcome(answer, name, input) {
|
|
43
|
+
if (answer.status === 401)
|
|
44
|
+
return { kind: 'revoked-authorization' };
|
|
181
45
|
const refusal = doorRefusal(answer.body);
|
|
46
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
47
|
+
return refusedFor(refusal);
|
|
182
48
|
if (refusal !== null) {
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
code: refusal.code,
|
|
186
|
-
fields: refusal.fields
|
|
187
|
-
};
|
|
188
|
-
}
|
|
189
|
-
if (answer.status === 0 || answer.status >= 400) return {
|
|
190
|
-
kind: 'transport-uncertainty'
|
|
191
|
-
};
|
|
192
|
-
if (name === 'conversation.send') return {
|
|
193
|
-
kind: 'action',
|
|
194
|
-
result: withTurn(answer.body)
|
|
195
|
-
};
|
|
196
|
-
return {
|
|
197
|
-
kind: 'action',
|
|
198
|
-
result: answer.body
|
|
199
|
-
};
|
|
200
|
-
}
|
|
201
|
-
async function carry(transport, name, input) {
|
|
202
|
-
const answer = await transport.door(routeOf(name), bodyOf(name, input));
|
|
203
|
-
return actionOutcome(answer, name);
|
|
204
|
-
}
|
|
205
|
-
function sendFile(entry) {
|
|
206
|
-
const file = record(entry);
|
|
207
|
-
const name = text(file, 'name');
|
|
208
|
-
const bytes = file.byteLength;
|
|
209
|
-
const sha256 = text(file, 'contentHash');
|
|
210
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined) return null;
|
|
211
|
-
const mediaType = text(file, 'mediaType');
|
|
212
|
-
const width = file.width;
|
|
213
|
-
const height = file.height;
|
|
214
|
-
return {
|
|
215
|
-
name,
|
|
216
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
217
|
-
bytes,
|
|
218
|
-
sha256,
|
|
219
|
-
...typeof width === 'number' && typeof height === 'number' ? {
|
|
220
|
-
dimensions: {
|
|
221
|
-
width,
|
|
222
|
-
height
|
|
223
|
-
}
|
|
224
|
-
} : {}
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
function sendFiles(input) {
|
|
228
|
-
const files = record(input).files;
|
|
229
|
-
if (files === undefined) return [];
|
|
230
|
-
if (!Array.isArray(files)) return null;
|
|
231
|
-
const declared = [];
|
|
232
|
-
for (const entry of files){
|
|
233
|
-
const file = sendFile(entry);
|
|
234
|
-
if (file === null) return null;
|
|
235
|
-
declared.push(file);
|
|
49
|
+
const reset = resetOf(refusal);
|
|
50
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
236
51
|
}
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
if (files === null) return null;
|
|
242
|
-
const textValue = text(input, 'text');
|
|
243
|
-
return {
|
|
244
|
-
conversation_id: text(input, 'conversation'),
|
|
245
|
-
operation_id: operationId(input),
|
|
246
|
-
...textValue !== undefined && textValue.length > 0 ? {
|
|
247
|
-
text: textValue
|
|
248
|
-
} : {},
|
|
249
|
-
...files.length === 0 ? {} : {
|
|
250
|
-
files
|
|
251
|
-
}
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
async function fileBytes(file) {
|
|
255
|
-
const blob = record(file).blob;
|
|
256
|
-
if (blob === undefined || typeof blob !== 'object' || blob === null) return null;
|
|
257
|
-
if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function') return null;
|
|
258
|
-
return new Uint8Array(await blob.arrayBuffer());
|
|
259
|
-
}
|
|
260
|
-
function uploadGrant(entry) {
|
|
261
|
-
if (!('upload' in record(entry))) return 'absent';
|
|
262
|
-
const upload = record(record(entry).upload);
|
|
263
|
-
if (upload.method !== 'POST') return null;
|
|
264
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string') return null;
|
|
265
|
-
return {
|
|
266
|
-
method: 'POST',
|
|
267
|
-
operation: upload.operation,
|
|
268
|
-
url: upload.url
|
|
269
|
-
};
|
|
270
|
-
}
|
|
271
|
-
async function uploadOriginals(transport, input, result) {
|
|
272
|
-
const originals = record(result).originals;
|
|
273
|
-
if (!Array.isArray(originals) || originals.length === 0) return null;
|
|
274
|
-
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
275
|
-
for (const [index, entry] of originals.entries()){
|
|
276
|
-
const grant = uploadGrant(entry);
|
|
277
|
-
if (grant === 'absent') continue;
|
|
278
|
-
if (grant === null) return malformed();
|
|
279
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
280
|
-
if (bytes === null) {
|
|
281
|
-
return {
|
|
282
|
-
kind: 'rejected',
|
|
283
|
-
code: 'conversation_original_descriptor_required',
|
|
284
|
-
fields: {}
|
|
285
|
-
};
|
|
286
|
-
}
|
|
287
|
-
const delivered = await transport.transfer({
|
|
288
|
-
act: 'conversation_original_upload',
|
|
289
|
-
method: 'POST',
|
|
290
|
-
url: grant.url,
|
|
291
|
-
body: bytes,
|
|
292
|
-
operation: grant.operation
|
|
293
|
-
});
|
|
294
|
-
if (delivered.status === 200) continue;
|
|
295
|
-
return actionOutcome(delivered, 'conversation.send');
|
|
296
|
-
}
|
|
297
|
-
return null;
|
|
298
|
-
}
|
|
299
|
-
async function sendAction(transport, input) {
|
|
300
|
-
const body = sendBody(input);
|
|
301
|
-
if (body === null) return malformed();
|
|
302
|
-
const answer = await transport.door('/door/conversations/send', body);
|
|
303
|
-
const outcome = actionOutcome(answer, 'conversation.send');
|
|
304
|
-
if (outcome.kind !== 'action') return outcome;
|
|
305
|
-
const uploaded = await uploadOriginals(transport, input, outcome.result);
|
|
306
|
-
if (uploaded !== null) return uploaded;
|
|
307
|
-
return outcome;
|
|
308
|
-
}
|
|
309
|
-
function historyCursor(value) {
|
|
310
|
-
let parsed;
|
|
311
|
-
try {
|
|
312
|
-
parsed = JSON.parse(value);
|
|
313
|
-
} catch {
|
|
314
|
-
return null;
|
|
52
|
+
if (answer.status === 404)
|
|
53
|
+
return unimplemented(name);
|
|
54
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
55
|
+
return answeredFailure(answer.status, answer.body);
|
|
315
56
|
}
|
|
316
|
-
|
|
317
|
-
const messageId = text(parsed, 'message_id');
|
|
318
|
-
if (acceptedAt === undefined || messageId === undefined) return null;
|
|
319
|
-
return {
|
|
320
|
-
accepted_at: acceptedAt,
|
|
321
|
-
message_id: messageId
|
|
322
|
-
};
|
|
57
|
+
return { kind: 'action', result: answer.body };
|
|
323
58
|
}
|
|
324
|
-
function
|
|
325
|
-
|
|
326
|
-
if (turn === undefined) return null;
|
|
327
|
-
return {
|
|
328
|
-
turn,
|
|
329
|
-
message: structuredClone(entry)
|
|
330
|
-
};
|
|
331
|
-
}
|
|
332
|
-
function olderCursor(entry) {
|
|
333
|
-
const acceptedAt = text(entry.message, 'accepted_at');
|
|
334
|
-
const messageId = text(entry.message, 'message_id');
|
|
335
|
-
if (acceptedAt === undefined || messageId === undefined) return null;
|
|
336
|
-
return JSON.stringify({
|
|
337
|
-
accepted_at: acceptedAt,
|
|
338
|
-
message_id: messageId
|
|
339
|
-
});
|
|
340
|
-
}
|
|
341
|
-
export async function readConversationHistory(transport, conversationId) {
|
|
342
|
-
const messages = [];
|
|
343
|
-
let after;
|
|
344
|
-
for(;;){
|
|
345
|
-
const answer = await transport.door('/door/conversations/history', {
|
|
346
|
-
conversation_id: conversationId,
|
|
347
|
-
...after === undefined ? {} : {
|
|
348
|
-
after
|
|
349
|
-
},
|
|
350
|
-
limit: HISTORY_PAGE
|
|
351
|
-
});
|
|
352
|
-
const outcome = actionOutcome(answer, 'conversation.history');
|
|
353
|
-
if (outcome.kind !== 'action') return {
|
|
354
|
-
outcome
|
|
355
|
-
};
|
|
356
|
-
const held = record(outcome.result);
|
|
357
|
-
if (!Array.isArray(held.messages)) return {
|
|
358
|
-
outcome: {
|
|
359
|
-
kind: 'transport-uncertainty'
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
for (const entry of held.messages){
|
|
363
|
-
if (text(entry, 'message_id') === undefined) {
|
|
364
|
-
return {
|
|
365
|
-
outcome: {
|
|
366
|
-
kind: 'transport-uncertainty'
|
|
367
|
-
}
|
|
368
|
-
};
|
|
369
|
-
}
|
|
370
|
-
messages.push(entry);
|
|
371
|
-
}
|
|
372
|
-
if (held.next === null || held.next === undefined) return {
|
|
373
|
-
messages
|
|
374
|
-
};
|
|
375
|
-
const next = record(held.next);
|
|
376
|
-
const acceptedAt = text(next, 'accepted_at');
|
|
377
|
-
const messageId = text(next, 'message_id');
|
|
378
|
-
if (acceptedAt === undefined || messageId === undefined) {
|
|
379
|
-
return {
|
|
380
|
-
outcome: {
|
|
381
|
-
kind: 'transport-uncertainty'
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
}
|
|
385
|
-
after = {
|
|
386
|
-
accepted_at: acceptedAt,
|
|
387
|
-
message_id: messageId
|
|
388
|
-
};
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
function historyPage(conversationId, messages, until) {
|
|
392
|
-
const from = Math.max(0, until - HISTORY_PAGE);
|
|
393
|
-
const page = messages.slice(from, until);
|
|
394
|
-
const first = page[0];
|
|
395
|
-
const cursor = from === 0 || first === undefined ? null : olderCursor(first);
|
|
396
|
-
if (from > 0 && cursor === null) return {
|
|
397
|
-
kind: 'transport-uncertainty'
|
|
398
|
-
};
|
|
399
|
-
return {
|
|
400
|
-
kind: 'action',
|
|
401
|
-
result: {
|
|
402
|
-
conversation_id: conversationId,
|
|
403
|
-
messages: page,
|
|
404
|
-
...cursor === null ? {} : {
|
|
405
|
-
cursor
|
|
406
|
-
}
|
|
407
|
-
}
|
|
408
|
-
};
|
|
409
|
-
}
|
|
410
|
-
async function historyAction(transport, input) {
|
|
411
|
-
const conversationId = text(input, 'conversation');
|
|
412
|
-
if (conversationId === undefined) return malformed();
|
|
413
|
-
const cursorValue = text(input, 'cursor');
|
|
414
|
-
let olderThan;
|
|
415
|
-
if (cursorValue !== undefined) {
|
|
416
|
-
const parsed = historyCursor(cursorValue);
|
|
417
|
-
if (parsed === null) {
|
|
418
|
-
return {
|
|
419
|
-
kind: 'rejected',
|
|
420
|
-
code: 'unknown-cursor',
|
|
421
|
-
fields: {
|
|
422
|
-
cursor: cursorValue
|
|
423
|
-
}
|
|
424
|
-
};
|
|
425
|
-
}
|
|
426
|
-
olderThan = parsed;
|
|
427
|
-
}
|
|
428
|
-
const held = await readConversationHistory(transport, conversationId);
|
|
429
|
-
if ('outcome' in held) return held.outcome;
|
|
430
|
-
const messages = [];
|
|
431
|
-
for (const entry of held.messages){
|
|
432
|
-
const mapped = turned(entry);
|
|
433
|
-
if (mapped === null) return {
|
|
434
|
-
kind: 'transport-uncertainty'
|
|
435
|
-
};
|
|
436
|
-
messages.push(mapped);
|
|
437
|
-
}
|
|
438
|
-
if (olderThan === undefined) {
|
|
439
|
-
return historyPage(conversationId, messages, messages.length);
|
|
440
|
-
}
|
|
441
|
-
const at = messages.findIndex((entry)=>text(entry.message, 'accepted_at') === olderThan.accepted_at && text(entry.message, 'message_id') === olderThan.message_id);
|
|
442
|
-
if (at === -1) {
|
|
443
|
-
return {
|
|
444
|
-
kind: 'rejected',
|
|
445
|
-
code: 'unknown-cursor',
|
|
446
|
-
fields: {
|
|
447
|
-
cursor: cursorValue
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
return historyPage(conversationId, messages, at);
|
|
59
|
+
async function carry(transport, route, name, input) {
|
|
60
|
+
return actionOutcome(await transport.door(route, input), name, input);
|
|
452
61
|
}
|
|
453
|
-
|
|
454
|
-
//# sourceMappingURL=actions.js.map
|
package/dist/adapter.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ export type AgentsHouseAdapterOptions = {
|
|
|
5
5
|
authorize(): Promise<Authorization>;
|
|
6
6
|
} | {
|
|
7
7
|
site: HouseSiteTransport;
|
|
8
|
+
snapshot?: boolean;
|
|
8
9
|
};
|
|
9
10
|
export declare function createAgentsHouseAdapter(options: AgentsHouseAdapterOptions): Adapter;
|
|
10
|
-
//# sourceMappingURL=adapter.d.ts.map
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAiBd,MAAM,wBAAwB,CAAC;AAyBhC,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAmBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAmBrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAsbpF"}
|