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