@agentshouse/mdruntime-adapter 0.1.0-cad6a4aeee9e8 → 0.1.0-cadc6f4d88eda
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 +2 -2
- package/dist/actions.d.ts +6 -44
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +23 -338
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +248 -278
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/chunks.d.ts +38 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +247 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/discovery.d.ts +23 -14
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +94 -53
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +92 -0
- package/dist/house-model.d.ts +682 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +396 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/model.d.ts +5 -5
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +33 -43
- package/dist/read.d.ts +59 -44
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +158 -236
- package/dist/refusal.d.ts +1 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +6 -6
- package/dist/room-types.d.ts +5 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +120 -0
- package/dist/search.d.ts +5 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +107 -130
- package/dist/space-schema.d.ts +7 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +15 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +275 -159
- package/dist/transport.d.ts +81 -25
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -11
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -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 +18 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +108 -76
- package/package.json +8 -5
- package/AGENTS.md +0 -318
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/README.md
CHANGED
|
@@ -24,8 +24,8 @@ host.attach(port, 'my-app');
|
|
|
24
24
|
```
|
|
25
25
|
|
|
26
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
|
|
28
|
-
|
|
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
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,47 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
type ConversationControl = Operated & {
|
|
7
|
-
readonly conversation: string;
|
|
8
|
-
};
|
|
9
|
-
type SentFile = FileDeclaration & {
|
|
10
|
-
readonly blob: Blob;
|
|
11
|
-
};
|
|
12
|
-
export type AppInputs = {
|
|
13
|
-
readonly 'conversation.answer': ConversationControl & {
|
|
14
|
-
readonly answer: {
|
|
15
|
-
readonly interaction_id: string;
|
|
16
|
-
readonly response: unknown;
|
|
17
|
-
};
|
|
18
|
-
};
|
|
19
|
-
readonly 'conversation.create': Operated & {
|
|
20
|
-
readonly agent_id: string;
|
|
21
|
-
};
|
|
22
|
-
readonly 'conversation.delete': ConversationControl;
|
|
23
|
-
readonly 'conversation.history': ConversationHistoryRequest;
|
|
24
|
-
readonly 'conversation.interrupt': ConversationControl;
|
|
25
|
-
readonly 'conversation.kill': ConversationControl;
|
|
26
|
-
readonly 'conversation.send': ConversationControl & {
|
|
27
|
-
readonly text?: string;
|
|
28
|
-
readonly files?: readonly SentFile[];
|
|
29
|
-
};
|
|
30
|
-
};
|
|
31
|
-
export type AppAnswers = {
|
|
32
|
-
readonly 'conversation.history': ConversationHistories;
|
|
33
|
-
};
|
|
34
|
-
export type AppAnswerAdditions = {
|
|
35
|
-
readonly 'conversation.send': {
|
|
36
|
-
readonly turn: string;
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
|
|
40
|
-
export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
|
|
41
|
-
export declare function houseConversationAgents(locator: string): ConversationAgents;
|
|
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[];
|
|
42
6
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
43
|
-
export declare function houseAction(transport:
|
|
44
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
45
|
-
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
46
|
-
export {};
|
|
7
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
8
|
+
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
|
47
9
|
//# 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,
|
|
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;AAE7F,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,EAG/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAKhD,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,70 +1,18 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
|
|
51
|
-
const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
|
|
52
|
-
export function houseConversationAgents(locator) {
|
|
53
|
-
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
54
|
-
}
|
|
1
|
+
import { doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
export const HOUSE_UNKEPT_READS = [
|
|
3
|
+
'account/security/read',
|
|
4
|
+
'clients/last-use/list',
|
|
5
|
+
];
|
|
6
|
+
export const HOUSE_LEADING_READS = [
|
|
7
|
+
'rooms/list',
|
|
8
|
+
'apps/list',
|
|
9
|
+
'sites/list',
|
|
10
|
+
'rooms/members/list',
|
|
11
|
+
];
|
|
55
12
|
export function declaredActions(routes) {
|
|
56
|
-
return routes.map((
|
|
57
|
-
name: APP_NAMES.get(route) ?? route,
|
|
58
|
-
inputShape: {},
|
|
59
|
-
resultKind: 'house',
|
|
60
|
-
}));
|
|
13
|
+
return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
|
|
61
14
|
}
|
|
62
15
|
export function houseAction(transport, request) {
|
|
63
|
-
if (Object.hasOwn(APP_ACTS, request.name)) {
|
|
64
|
-
return APP_ACTS[request.name].carry(transport, request.input, request.name);
|
|
65
|
-
}
|
|
66
|
-
if (APP_NAMES.has(request.name))
|
|
67
|
-
return Promise.resolve(unimplemented(request.name));
|
|
68
16
|
const route = routeOf(request.name);
|
|
69
17
|
if (route === null)
|
|
70
18
|
return Promise.resolve(malformed());
|
|
@@ -81,295 +29,32 @@ function routeOf(name) {
|
|
|
81
29
|
return null;
|
|
82
30
|
}
|
|
83
31
|
}
|
|
84
|
-
function record(value) {
|
|
85
|
-
return typeof value === 'object' && value !== null ? value : {};
|
|
86
|
-
}
|
|
87
|
-
function text(value, name) {
|
|
88
|
-
const held = record(value)[name];
|
|
89
|
-
return typeof held === 'string' ? held : undefined;
|
|
90
|
-
}
|
|
91
|
-
function operationId(input) {
|
|
92
|
-
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
93
|
-
}
|
|
94
32
|
function malformed() {
|
|
95
33
|
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
96
34
|
}
|
|
97
35
|
function unimplemented(name) {
|
|
98
36
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
99
37
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
38
|
+
function numbered(input) {
|
|
39
|
+
return typeof input?.operation_id === 'string';
|
|
102
40
|
}
|
|
103
|
-
function
|
|
104
|
-
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
105
|
-
}
|
|
106
|
-
function answerBody(input) {
|
|
107
|
-
const nested = record(record(input).answer);
|
|
108
|
-
return {
|
|
109
|
-
conversation_id: text(input, 'conversation'),
|
|
110
|
-
operation_id: operationId(input),
|
|
111
|
-
interaction_id: text(nested, 'interaction_id'),
|
|
112
|
-
response: nested.response,
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
async function createAction(transport, route, input, name) {
|
|
116
|
-
const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
|
|
117
|
-
if (outcome.kind !== 'action')
|
|
118
|
-
return outcome;
|
|
119
|
-
const held = record(outcome.result);
|
|
120
|
-
const conversation = text(held, 'conversation_id');
|
|
121
|
-
return conversation === undefined ? outcome : { ...outcome, result: { ...held, conversation } };
|
|
122
|
-
}
|
|
123
|
-
function withTurn(body) {
|
|
124
|
-
const held = record(body);
|
|
125
|
-
const turn = text(held, 'message_id');
|
|
126
|
-
return turn === undefined
|
|
127
|
-
? body
|
|
128
|
-
: { ...held, turn };
|
|
129
|
-
}
|
|
130
|
-
export function actionOutcome(answer, name) {
|
|
41
|
+
export function actionOutcome(answer, name, input) {
|
|
131
42
|
if (answer.status === 401)
|
|
132
43
|
return { kind: 'revoked-authorization' };
|
|
133
44
|
const refusal = doorRefusal(answer.body);
|
|
134
|
-
if (refusal
|
|
135
|
-
return { kind: '
|
|
45
|
+
if (refusal?.code === 'operation_contended' && numbered(input)) {
|
|
46
|
+
return { kind: 'transport-uncertainty' };
|
|
47
|
+
}
|
|
48
|
+
if (refusal !== null) {
|
|
49
|
+
const reset = resetOf(refusal);
|
|
50
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
51
|
+
}
|
|
136
52
|
if (answer.status === 404)
|
|
137
53
|
return unimplemented(name);
|
|
138
54
|
if (answer.status === 0 || answer.status >= 400)
|
|
139
55
|
return { kind: 'transport-uncertainty' };
|
|
140
56
|
return { kind: 'action', result: answer.body };
|
|
141
57
|
}
|
|
142
|
-
function referredRecord(view, roomRef) {
|
|
143
|
-
const held = record(view);
|
|
144
|
-
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
145
|
-
return view;
|
|
146
|
-
const referrer = { room_ref: roomRef, record: held.record };
|
|
147
|
-
return {
|
|
148
|
-
...held,
|
|
149
|
-
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
150
|
-
};
|
|
151
|
-
}
|
|
152
|
-
async function recordsAction(transport, route, input, name) {
|
|
153
|
-
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
154
|
-
if (outcome.kind !== 'action')
|
|
155
|
-
return outcome;
|
|
156
|
-
const roomRef = text(input, 'room_ref');
|
|
157
|
-
const read = record(outcome.result);
|
|
158
|
-
return {
|
|
159
|
-
...outcome,
|
|
160
|
-
result: Array.isArray(read.records)
|
|
161
|
-
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
162
|
-
: referredRecord(outcome.result, roomRef),
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
58
|
async function carry(transport, route, name, input) {
|
|
166
|
-
return actionOutcome(await transport.door(route, input), name);
|
|
167
|
-
}
|
|
168
|
-
function sendFile(entry) {
|
|
169
|
-
const file = record(entry);
|
|
170
|
-
const name = text(file, 'name');
|
|
171
|
-
const bytes = file.byteLength;
|
|
172
|
-
const sha256 = text(file, 'contentHash');
|
|
173
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
|
|
174
|
-
return null;
|
|
175
|
-
const mediaType = text(file, 'mediaType');
|
|
176
|
-
const width = file.width;
|
|
177
|
-
const height = file.height;
|
|
178
|
-
return {
|
|
179
|
-
name,
|
|
180
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
181
|
-
bytes,
|
|
182
|
-
sha256,
|
|
183
|
-
...(typeof width === 'number' && typeof height === 'number'
|
|
184
|
-
? { dimensions: { width, height } }
|
|
185
|
-
: {}),
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
function sendFiles(input) {
|
|
189
|
-
const files = record(input).files;
|
|
190
|
-
if (files === undefined)
|
|
191
|
-
return [];
|
|
192
|
-
if (!Array.isArray(files))
|
|
193
|
-
return null;
|
|
194
|
-
const declared = [];
|
|
195
|
-
for (const entry of files) {
|
|
196
|
-
const file = sendFile(entry);
|
|
197
|
-
if (file === null)
|
|
198
|
-
return null;
|
|
199
|
-
declared.push(file);
|
|
200
|
-
}
|
|
201
|
-
return declared;
|
|
202
|
-
}
|
|
203
|
-
function sendBody(input) {
|
|
204
|
-
const files = sendFiles(input);
|
|
205
|
-
if (files === null)
|
|
206
|
-
return null;
|
|
207
|
-
const textValue = text(input, 'text');
|
|
208
|
-
return {
|
|
209
|
-
conversation_id: text(input, 'conversation'),
|
|
210
|
-
operation_id: operationId(input),
|
|
211
|
-
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
212
|
-
...(files.length === 0 ? {} : { files }),
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
async function fileBytes(file) {
|
|
216
|
-
const blob = record(file).blob;
|
|
217
|
-
if (blob === undefined || typeof blob !== 'object' || blob === null)
|
|
218
|
-
return null;
|
|
219
|
-
if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
|
|
220
|
-
return null;
|
|
221
|
-
return new Uint8Array(await blob.arrayBuffer());
|
|
222
|
-
}
|
|
223
|
-
function delivered(answer, name) {
|
|
224
|
-
return answer.status === 200 ? null : actionOutcome(answer, name);
|
|
225
|
-
}
|
|
226
|
-
function uploadGrant(entry) {
|
|
227
|
-
if (!('upload' in record(entry)))
|
|
228
|
-
return 'absent';
|
|
229
|
-
const upload = record(record(entry).upload);
|
|
230
|
-
if (upload.method !== 'POST')
|
|
231
|
-
return null;
|
|
232
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
|
|
233
|
-
return null;
|
|
234
|
-
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
235
|
-
}
|
|
236
|
-
async function uploadFiles(transport, input, result, name) {
|
|
237
|
-
const sent = record(result).files;
|
|
238
|
-
if (!Array.isArray(sent) || sent.length === 0)
|
|
239
|
-
return null;
|
|
240
|
-
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
241
|
-
for (const [index, entry] of sent.entries()) {
|
|
242
|
-
const grant = uploadGrant(entry);
|
|
243
|
-
if (grant === 'absent')
|
|
244
|
-
continue;
|
|
245
|
-
if (grant === null)
|
|
246
|
-
return malformed();
|
|
247
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
248
|
-
if (bytes === null) {
|
|
249
|
-
return {
|
|
250
|
-
kind: 'rejected',
|
|
251
|
-
code: 'conversation_file_descriptor_required',
|
|
252
|
-
fields: {},
|
|
253
|
-
retryable: false,
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
const failed = delivered(await transport.transfer({
|
|
257
|
-
act: 'conversation_file_upload',
|
|
258
|
-
url: grant.url,
|
|
259
|
-
body: bytes,
|
|
260
|
-
operation: grant.operation,
|
|
261
|
-
}), name);
|
|
262
|
-
if (failed !== null)
|
|
263
|
-
return failed;
|
|
264
|
-
}
|
|
265
|
-
return null;
|
|
266
|
-
}
|
|
267
|
-
async function sendAction(transport, route, input, name) {
|
|
268
|
-
const body = sendBody(input);
|
|
269
|
-
if (body === null)
|
|
270
|
-
return malformed();
|
|
271
|
-
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
272
|
-
if (outcome.kind !== 'action')
|
|
273
|
-
return outcome;
|
|
274
|
-
const uploaded = await uploadFiles(transport, input, outcome.result, name);
|
|
275
|
-
if (uploaded !== null)
|
|
276
|
-
return uploaded;
|
|
277
|
-
return { ...outcome, result: withTurn(outcome.result) };
|
|
278
|
-
}
|
|
279
|
-
function historyCursor(value) {
|
|
280
|
-
const acceptedAt = text(value, 'accepted_at');
|
|
281
|
-
const messageId = text(value, 'message_id');
|
|
282
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
283
|
-
return null;
|
|
284
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
285
|
-
}
|
|
286
|
-
function position(cursor) {
|
|
287
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
288
|
-
}
|
|
289
|
-
function positionCursor(value) {
|
|
290
|
-
try {
|
|
291
|
-
return historyCursor(JSON.parse(value));
|
|
292
|
-
}
|
|
293
|
-
catch {
|
|
294
|
-
return null;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
export function acceptedMessage(entry) {
|
|
298
|
-
const cursor = historyCursor(entry);
|
|
299
|
-
if (cursor === null)
|
|
300
|
-
return null;
|
|
301
|
-
const message = structuredClone(record(entry));
|
|
302
|
-
const referrer = { message: cursor.message_id };
|
|
303
|
-
return {
|
|
304
|
-
identity: cursor.message_id,
|
|
305
|
-
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
306
|
-
position: position(cursor),
|
|
307
|
-
text: text(entry, 'text') ?? '',
|
|
308
|
-
message: Array.isArray(message.files)
|
|
309
|
-
? {
|
|
310
|
-
...message,
|
|
311
|
-
files: message.files.map((file) => ({ ...record(file), referrer })),
|
|
312
|
-
}
|
|
313
|
-
: message,
|
|
314
|
-
};
|
|
315
|
-
}
|
|
316
|
-
function historyPage(entry) {
|
|
317
|
-
const held = record(entry);
|
|
318
|
-
const conversation = text(held, 'conversation_id');
|
|
319
|
-
if (conversation === undefined || !Array.isArray(held.messages))
|
|
320
|
-
return null;
|
|
321
|
-
const messages = [];
|
|
322
|
-
for (const one of held.messages) {
|
|
323
|
-
const message = acceptedMessage(one);
|
|
324
|
-
if (message === null)
|
|
325
|
-
return null;
|
|
326
|
-
messages.push(message);
|
|
327
|
-
}
|
|
328
|
-
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
329
|
-
if (next === null)
|
|
330
|
-
return null;
|
|
331
|
-
return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
|
|
332
|
-
}
|
|
333
|
-
function historyAsks(input) {
|
|
334
|
-
const asked = record(input).conversations;
|
|
335
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
336
|
-
return null;
|
|
337
|
-
const asks = [];
|
|
338
|
-
for (const entry of asked) {
|
|
339
|
-
const conversationId = text(entry, 'conversation');
|
|
340
|
-
if (conversationId === undefined)
|
|
341
|
-
return null;
|
|
342
|
-
const afterValue = text(entry, 'after');
|
|
343
|
-
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
344
|
-
if (after === null)
|
|
345
|
-
return null;
|
|
346
|
-
asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
|
|
347
|
-
}
|
|
348
|
-
return asks;
|
|
349
|
-
}
|
|
350
|
-
async function historyAction(transport, route, input, name) {
|
|
351
|
-
const asks = historyAsks(input);
|
|
352
|
-
if (asks === null)
|
|
353
|
-
return malformed();
|
|
354
|
-
const histories = [];
|
|
355
|
-
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
356
|
-
const answer = await transport.door(route, {
|
|
357
|
-
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
358
|
-
limit: HISTORY_PAGE,
|
|
359
|
-
});
|
|
360
|
-
const outcome = actionOutcome(answer, name);
|
|
361
|
-
if (outcome.kind !== 'action')
|
|
362
|
-
return outcome;
|
|
363
|
-
const answered = record(outcome.result).histories;
|
|
364
|
-
if (!Array.isArray(answered))
|
|
365
|
-
return { kind: 'transport-uncertainty' };
|
|
366
|
-
for (const entry of answered) {
|
|
367
|
-
const page = historyPage(entry);
|
|
368
|
-
if (page === null)
|
|
369
|
-
return { kind: 'transport-uncertainty' };
|
|
370
|
-
histories.push(page);
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
const result = { histories };
|
|
374
|
-
return { kind: 'action', result };
|
|
59
|
+
return actionOutcome(await transport.door(route, input), name, input);
|
|
375
60
|
}
|
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,EAIP,aAAa,EAed,MAAM,wBAAwB,CAAC;AAyBhC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAoBxB,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;AAoBrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkbpF"}
|