@agentshouse/mdruntime-adapter 0.1.0-cea44707d3919 → 0.1.0-cedab65f24a09
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 +275 -229
- package/dist/actions.d.ts +62 -1
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +155 -133
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +314 -93
- package/dist/discovery.d.ts +2 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +10 -6
- 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 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +6 -2
- package/dist/read.d.ts +34 -7
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +156 -77
- 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 +6 -9
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +182 -49
- package/dist/stream.d.ts +3 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +306 -15
- package/dist/transport.d.ts +51 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +3 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +3 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +92 -14
- package/package.json +3 -4
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/actions.d.ts
CHANGED
|
@@ -1,8 +1,69 @@
|
|
|
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 operation_id: string;
|
|
28
|
+
readonly text?: string;
|
|
29
|
+
readonly files?: readonly SentFile[];
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
export type AppAnswers = {
|
|
33
|
+
readonly 'conversation.history': ConversationHistories;
|
|
34
|
+
};
|
|
35
|
+
export type AppAnswerAdditions = {
|
|
36
|
+
readonly 'conversation.create': {
|
|
37
|
+
readonly conversation: string;
|
|
38
|
+
};
|
|
39
|
+
readonly 'conversation.send': {
|
|
40
|
+
readonly turn: string;
|
|
41
|
+
};
|
|
42
|
+
readonly 'record.list': {
|
|
43
|
+
readonly attachments: readonly {
|
|
44
|
+
readonly referrer: {
|
|
45
|
+
readonly room_ref: string;
|
|
46
|
+
readonly record: string;
|
|
47
|
+
};
|
|
48
|
+
}[];
|
|
49
|
+
readonly records: readonly {
|
|
50
|
+
readonly attachments: readonly {
|
|
51
|
+
readonly referrer: {
|
|
52
|
+
readonly room_ref: string;
|
|
53
|
+
readonly record: string;
|
|
54
|
+
};
|
|
55
|
+
}[];
|
|
56
|
+
}[];
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
|
|
60
|
+
export declare const SITE_SUBMIT = "submit";
|
|
61
|
+
export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
|
|
62
|
+
export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
|
|
3
63
|
export declare function houseConversationAgents(locator: string): ConversationAgents;
|
|
4
64
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
5
65
|
export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
|
|
6
66
|
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
7
67
|
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
68
|
+
export {};
|
|
8
69
|
//# 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,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AAE,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;AA6ED,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF;AAuKD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiBtE"}
|
package/dist/actions.js
CHANGED
|
@@ -3,44 +3,78 @@ 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, batched) {
|
|
15
|
+
return {
|
|
16
|
+
door,
|
|
17
|
+
...(batched === undefined ? {} : { batched }),
|
|
18
|
+
carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
const APP_ACTS = {
|
|
22
|
+
'access.read': mapped('rooms/access/read'),
|
|
23
|
+
'conversation.answer': mapped('conversations/interaction/answer', answerBody),
|
|
24
|
+
'conversation.create': carried('conversations/create', createAction),
|
|
25
|
+
'conversation.delete': mapped('conversations/delete', controlBody),
|
|
26
|
+
'conversation.history': carried('conversations/history', historyAction, ['conversations']),
|
|
27
|
+
'conversation.interrupt': mapped('conversations/interrupt', controlBody),
|
|
28
|
+
'conversation.kill': mapped('conversations/kill', controlBody),
|
|
29
|
+
'conversation.markDone': mapped('conversations/done'),
|
|
30
|
+
'conversation.rename': mapped('conversations/rename'),
|
|
31
|
+
'conversation.send': carried('conversations/send', sendAction),
|
|
32
|
+
'conversation.setOption': mapped('conversations/option'),
|
|
33
|
+
'feature.list': mapped('apps/features/read'),
|
|
34
|
+
'holder.list': mapped('apps/holders'),
|
|
35
|
+
'holder.ring': mapped('apps/ring'),
|
|
36
|
+
'member.list': mapped('rooms/members'),
|
|
37
|
+
'message.send': mapped('apps/messages/send'),
|
|
38
|
+
'processing.read': mapped('rooms/settings/processing/read'),
|
|
39
|
+
'record.list': carried('records/read', recordsAction),
|
|
40
|
+
'relay.read': mapped('apps/relay'),
|
|
41
|
+
'routine.list': mapped('routines/access'),
|
|
42
|
+
'routineAccess.list': mapped('routines/granted'),
|
|
43
|
+
'routineAllowance.list': mapped('routines/allowance'),
|
|
44
|
+
'routineRequest.list': mapped('routines/requests'),
|
|
45
|
+
'storage.read': mapped('storage/inventory'),
|
|
46
|
+
'trigger.list': mapped('triggers/read'),
|
|
47
|
+
'triggerOccurrence.list': mapped('triggers/fired'),
|
|
48
|
+
};
|
|
49
|
+
export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
|
|
50
|
+
export const SITE_SUBMIT = 'submit';
|
|
51
|
+
export const HOUSE_SITE_ACTS = {
|
|
52
|
+
[SITE_SUBMIT]: 'site/submission',
|
|
53
|
+
};
|
|
54
|
+
export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
|
|
55
|
+
const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
|
|
15
56
|
export function houseConversationAgents(locator) {
|
|
16
|
-
return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
|
|
57
|
+
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
17
58
|
}
|
|
18
59
|
export function declaredActions(routes) {
|
|
19
|
-
const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
|
|
20
60
|
return routes.map((route) => ({
|
|
21
|
-
name:
|
|
61
|
+
name: APP_NAMES.get(route) ?? route,
|
|
22
62
|
inputShape: {},
|
|
23
63
|
resultKind: 'house',
|
|
24
64
|
}));
|
|
25
65
|
}
|
|
26
66
|
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);
|
|
67
|
+
if (Object.hasOwn(APP_ACTS, request.name)) {
|
|
68
|
+
return APP_ACTS[request.name].carry(transport, request.input, request.name);
|
|
69
|
+
}
|
|
70
|
+
if (APP_NAMES.has(request.name))
|
|
71
|
+
return Promise.resolve(unimplemented(request.name));
|
|
35
72
|
const route = routeOf(request.name);
|
|
36
73
|
if (route === null)
|
|
37
74
|
return Promise.resolve(malformed());
|
|
38
75
|
return carry(transport, route, request.name, request.input);
|
|
39
76
|
}
|
|
40
77
|
function routeOf(name) {
|
|
41
|
-
const mapped = CONVERSATION_ROUTES.get(name);
|
|
42
|
-
if (mapped !== undefined)
|
|
43
|
-
return mapped;
|
|
44
78
|
const parts = name.split('/');
|
|
45
79
|
if (parts.some((part) => part === '.' || part === '..'))
|
|
46
80
|
return null;
|
|
@@ -62,51 +96,88 @@ function operationId(input) {
|
|
|
62
96
|
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
63
97
|
}
|
|
64
98
|
function malformed() {
|
|
65
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {} };
|
|
99
|
+
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
66
100
|
}
|
|
67
|
-
function
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
101
|
+
function unimplemented(name) {
|
|
102
|
+
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
103
|
+
}
|
|
104
|
+
function createBody(input) {
|
|
105
|
+
return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
|
|
106
|
+
}
|
|
107
|
+
function controlBody(input) {
|
|
108
|
+
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
109
|
+
}
|
|
110
|
+
function answerBody(input) {
|
|
111
|
+
const nested = record(record(input).answer);
|
|
112
|
+
return {
|
|
113
|
+
conversation_id: text(input, 'conversation'),
|
|
114
|
+
operation_id: operationId(input),
|
|
115
|
+
interaction_id: text(nested, 'interaction_id'),
|
|
116
|
+
response: nested.response,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
async function createAction(transport, route, input, name) {
|
|
120
|
+
const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
|
|
121
|
+
if (outcome.kind !== 'action')
|
|
122
|
+
return outcome;
|
|
123
|
+
const held = record(outcome.result);
|
|
124
|
+
const conversation = text(held, 'conversation_id');
|
|
125
|
+
return conversation === undefined
|
|
126
|
+
? outcome
|
|
127
|
+
: {
|
|
128
|
+
...outcome,
|
|
129
|
+
result: { ...held, conversation },
|
|
83
130
|
};
|
|
84
|
-
}
|
|
85
|
-
return input;
|
|
86
131
|
}
|
|
87
132
|
function withTurn(body) {
|
|
88
133
|
const held = record(body);
|
|
89
134
|
const turn = text(held, 'message_id');
|
|
90
|
-
return turn === undefined
|
|
135
|
+
return turn === undefined
|
|
136
|
+
? body
|
|
137
|
+
: { ...held, turn };
|
|
91
138
|
}
|
|
92
139
|
export function actionOutcome(answer, name) {
|
|
93
140
|
if (answer.status === 401)
|
|
94
141
|
return { kind: 'revoked-authorization' };
|
|
95
142
|
const refusal = doorRefusal(answer.body);
|
|
96
|
-
if (refusal
|
|
97
|
-
return { kind: '
|
|
98
|
-
|
|
143
|
+
if (refusal?.code === 'operation_contended')
|
|
144
|
+
return { kind: 'transport-uncertainty' };
|
|
145
|
+
if (refusal !== null)
|
|
146
|
+
return { kind: 'rejected', ...refusal };
|
|
99
147
|
if (answer.status === 404)
|
|
100
|
-
return
|
|
148
|
+
return unimplemented(name);
|
|
101
149
|
if (answer.status === 0 || answer.status >= 400)
|
|
102
150
|
return { kind: 'transport-uncertainty' };
|
|
103
|
-
if (name === 'conversation.send')
|
|
104
|
-
return { kind: 'action', result: withTurn(answer.body) };
|
|
105
151
|
return { kind: 'action', result: answer.body };
|
|
106
152
|
}
|
|
153
|
+
function referredRecord(view, roomRef) {
|
|
154
|
+
const held = record(view);
|
|
155
|
+
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
156
|
+
return view;
|
|
157
|
+
const referrer = {
|
|
158
|
+
room_ref: roomRef,
|
|
159
|
+
record: held.record,
|
|
160
|
+
};
|
|
161
|
+
return {
|
|
162
|
+
...held,
|
|
163
|
+
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
async function recordsAction(transport, route, input, name) {
|
|
167
|
+
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
168
|
+
if (outcome.kind !== 'action')
|
|
169
|
+
return outcome;
|
|
170
|
+
const roomRef = text(input, 'room_ref');
|
|
171
|
+
const read = record(outcome.result);
|
|
172
|
+
return {
|
|
173
|
+
...outcome,
|
|
174
|
+
result: Array.isArray(read.records)
|
|
175
|
+
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
176
|
+
: referredRecord(outcome.result, roomRef),
|
|
177
|
+
};
|
|
178
|
+
}
|
|
107
179
|
async function carry(transport, route, name, input) {
|
|
108
|
-
|
|
109
|
-
return actionOutcome(answer, name);
|
|
180
|
+
return actionOutcome(await transport.door(route, input), name);
|
|
110
181
|
}
|
|
111
182
|
function sendFile(entry) {
|
|
112
183
|
const file = record(entry);
|
|
@@ -145,12 +216,13 @@ function sendFiles(input) {
|
|
|
145
216
|
}
|
|
146
217
|
function sendBody(input) {
|
|
147
218
|
const files = sendFiles(input);
|
|
148
|
-
|
|
219
|
+
const operation = text(input, 'operation_id');
|
|
220
|
+
if (files === null || operation === undefined)
|
|
149
221
|
return null;
|
|
150
222
|
const textValue = text(input, 'text');
|
|
151
223
|
return {
|
|
152
224
|
conversation_id: text(input, 'conversation'),
|
|
153
|
-
operation_id:
|
|
225
|
+
operation_id: operation,
|
|
154
226
|
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
155
227
|
...(files.length === 0 ? {} : { files }),
|
|
156
228
|
};
|
|
@@ -163,9 +235,6 @@ async function fileBytes(file) {
|
|
|
163
235
|
return null;
|
|
164
236
|
return new Uint8Array(await blob.arrayBuffer());
|
|
165
237
|
}
|
|
166
|
-
function delivered(answer, name) {
|
|
167
|
-
return answer.status === 200 ? null : actionOutcome(answer, name);
|
|
168
|
-
}
|
|
169
238
|
function uploadGrant(entry) {
|
|
170
239
|
if (!('upload' in record(entry)))
|
|
171
240
|
return 'absent';
|
|
@@ -176,94 +245,40 @@ function uploadGrant(entry) {
|
|
|
176
245
|
return null;
|
|
177
246
|
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
178
247
|
}
|
|
179
|
-
async function
|
|
180
|
-
const
|
|
181
|
-
if (!Array.isArray(
|
|
182
|
-
return
|
|
248
|
+
async function uploadFiles(transport, input, result) {
|
|
249
|
+
const sent = record(result).files;
|
|
250
|
+
if (!Array.isArray(sent))
|
|
251
|
+
return true;
|
|
183
252
|
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
184
|
-
for (const [index, entry] of
|
|
253
|
+
for (const [index, entry] of sent.entries()) {
|
|
185
254
|
const grant = uploadGrant(entry);
|
|
186
255
|
if (grant === 'absent')
|
|
187
256
|
continue;
|
|
188
|
-
if (grant === null)
|
|
189
|
-
return malformed();
|
|
190
257
|
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
191
|
-
if (bytes === null)
|
|
192
|
-
return
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
act: 'conversation_original_upload',
|
|
196
|
-
method: 'POST',
|
|
258
|
+
if (grant === null || bytes === null)
|
|
259
|
+
return false;
|
|
260
|
+
const answer = await transport.transfer({
|
|
261
|
+
act: 'conversation_file_upload',
|
|
197
262
|
url: grant.url,
|
|
198
|
-
answer: 'json',
|
|
199
263
|
body: bytes,
|
|
200
264
|
operation: grant.operation,
|
|
201
|
-
})
|
|
202
|
-
if (
|
|
203
|
-
return
|
|
265
|
+
});
|
|
266
|
+
if (answer.status !== 200)
|
|
267
|
+
return false;
|
|
204
268
|
}
|
|
205
|
-
return
|
|
269
|
+
return true;
|
|
206
270
|
}
|
|
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) {
|
|
271
|
+
async function sendAction(transport, route, input, name) {
|
|
256
272
|
const body = sendBody(input);
|
|
257
273
|
if (body === null)
|
|
258
274
|
return malformed();
|
|
259
|
-
const
|
|
260
|
-
const outcome = actionOutcome(answer, 'conversation.send');
|
|
275
|
+
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
261
276
|
if (outcome.kind !== 'action')
|
|
262
277
|
return outcome;
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
return outcome;
|
|
278
|
+
if (!(await uploadFiles(transport, input, outcome.result))) {
|
|
279
|
+
return { kind: 'transport-uncertainty' };
|
|
280
|
+
}
|
|
281
|
+
return { ...outcome, result: withTurn(outcome.result) };
|
|
267
282
|
}
|
|
268
283
|
function historyCursor(value) {
|
|
269
284
|
const acceptedAt = text(value, 'accepted_at');
|
|
@@ -287,12 +302,19 @@ export function acceptedMessage(entry) {
|
|
|
287
302
|
const cursor = historyCursor(entry);
|
|
288
303
|
if (cursor === null)
|
|
289
304
|
return null;
|
|
305
|
+
const message = structuredClone(record(entry));
|
|
306
|
+
const referrer = { message: cursor.message_id };
|
|
290
307
|
return {
|
|
291
308
|
identity: cursor.message_id,
|
|
292
309
|
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
293
310
|
position: position(cursor),
|
|
294
311
|
text: text(entry, 'text') ?? '',
|
|
295
|
-
message:
|
|
312
|
+
message: Array.isArray(message.files)
|
|
313
|
+
? {
|
|
314
|
+
...message,
|
|
315
|
+
files: message.files.map((file) => ({ ...record(file), referrer })),
|
|
316
|
+
}
|
|
317
|
+
: message,
|
|
296
318
|
};
|
|
297
319
|
}
|
|
298
320
|
function historyPage(entry) {
|
|
@@ -329,17 +351,17 @@ function historyAsks(input) {
|
|
|
329
351
|
}
|
|
330
352
|
return asks;
|
|
331
353
|
}
|
|
332
|
-
async function historyAction(transport, input) {
|
|
354
|
+
async function historyAction(transport, route, input, name) {
|
|
333
355
|
const asks = historyAsks(input);
|
|
334
356
|
if (asks === null)
|
|
335
357
|
return malformed();
|
|
336
358
|
const histories = [];
|
|
337
359
|
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
338
|
-
const answer = await transport.door(
|
|
360
|
+
const answer = await transport.door(route, {
|
|
339
361
|
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
340
362
|
limit: HISTORY_PAGE,
|
|
341
363
|
});
|
|
342
|
-
const outcome = actionOutcome(answer,
|
|
364
|
+
const outcome = actionOutcome(answer, name);
|
|
343
365
|
if (outcome.kind !== 'action')
|
|
344
366
|
return outcome;
|
|
345
367
|
const answered = record(outcome.result).histories;
|
package/dist/adapter.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ 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
11
|
//# 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":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAmBd,MAAM,wBAAwB,CAAC;AA4ChC,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,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAsErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAsjBpF"}
|