@agentshouse/mdruntime-adapter 0.1.0-cd61dfca5d699 → 0.1.0-cd75dfaf57319
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 +4 -66
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +7 -339
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +229 -371
- 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/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 +92 -54
- 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 +719 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +393 -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 +8 -3
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +37 -34
- package/dist/part.d.ts +14 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +90 -0
- package/dist/read.d.ts +56 -63
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +240 -285
- package/dist/refusal.d.ts +0 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +0 -5
- package/dist/room-stream.d.ts +20 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +57 -0
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +123 -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.map +1 -1
- package/dist/site.js +88 -195
- 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 +14 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +170 -422
- package/dist/transport.d.ts +55 -40
- 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/write.d.ts +18 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +105 -75
- package/package.json +8 -4
- package/AGENTS.md +0 -299
- 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 `open_guide` opens.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,69 +1,7 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
3
|
-
type
|
|
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[]>>>;
|
|
63
|
-
export declare function houseConversationAgents(locator: string): ConversationAgents;
|
|
3
|
+
export type HouseActDoor = Pick<HouseTransport, 'door'>;
|
|
64
4
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
65
|
-
export declare function houseAction(transport:
|
|
66
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
67
|
-
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
68
|
-
export {};
|
|
5
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
6
|
+
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
|
69
7
|
//# 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,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,CAUjG"}
|
package/dist/actions.js
CHANGED
|
@@ -1,75 +1,8 @@
|
|
|
1
|
-
import { changeBatchIdentity, } from '@agentshouse/mdruntime';
|
|
2
1
|
import { doorRefusal } from './refusal.js';
|
|
3
|
-
const HISTORY_PAGE = 100;
|
|
4
|
-
const HISTORY_CONVERSATIONS = 64;
|
|
5
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
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.retry': mapped('conversations/retry'),
|
|
32
|
-
'conversation.send': carried('conversations/send', sendAction),
|
|
33
|
-
'conversation.setOption': mapped('conversations/option'),
|
|
34
|
-
'feature.list': mapped('apps/features/read'),
|
|
35
|
-
'holder.list': mapped('apps/holders'),
|
|
36
|
-
'holder.ring': mapped('apps/ring'),
|
|
37
|
-
'member.list': mapped('rooms/members'),
|
|
38
|
-
'message.send': mapped('apps/messages/send'),
|
|
39
|
-
'processing.read': mapped('rooms/settings/processing/read'),
|
|
40
|
-
'record.list': carried('records/read', recordsAction),
|
|
41
|
-
'relay.read': mapped('apps/relay'),
|
|
42
|
-
'routine.list': mapped('routines/access'),
|
|
43
|
-
'routineAccess.list': mapped('routines/granted'),
|
|
44
|
-
'routineAllowance.list': mapped('routines/allowance'),
|
|
45
|
-
'routineRequest.list': mapped('routines/requests'),
|
|
46
|
-
'storage.read': mapped('storage/inventory'),
|
|
47
|
-
'trigger.list': mapped('triggers/read'),
|
|
48
|
-
'triggerOccurrence.list': mapped('triggers/fired'),
|
|
49
|
-
};
|
|
50
|
-
export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
|
|
51
|
-
export const SITE_SUBMIT = 'submit';
|
|
52
|
-
export const HOUSE_SITE_ACTS = {
|
|
53
|
-
[SITE_SUBMIT]: 'site/submission',
|
|
54
|
-
};
|
|
55
|
-
export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
|
|
56
|
-
const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
|
|
57
|
-
export function houseConversationAgents(locator) {
|
|
58
|
-
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
59
|
-
}
|
|
60
2
|
export function declaredActions(routes) {
|
|
61
|
-
return routes.map((
|
|
62
|
-
name: APP_NAMES.get(route) ?? route,
|
|
63
|
-
inputShape: {},
|
|
64
|
-
resultKind: 'house',
|
|
65
|
-
}));
|
|
3
|
+
return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
|
|
66
4
|
}
|
|
67
5
|
export function houseAction(transport, request) {
|
|
68
|
-
if (Object.hasOwn(APP_ACTS, request.name)) {
|
|
69
|
-
return APP_ACTS[request.name].carry(transport, request.input, request.name);
|
|
70
|
-
}
|
|
71
|
-
if (APP_NAMES.has(request.name))
|
|
72
|
-
return Promise.resolve(unimplemented(request.name));
|
|
73
6
|
const route = routeOf(request.name);
|
|
74
7
|
if (route === null)
|
|
75
8
|
return Promise.resolve(malformed());
|
|
@@ -86,63 +19,22 @@ function routeOf(name) {
|
|
|
86
19
|
return null;
|
|
87
20
|
}
|
|
88
21
|
}
|
|
89
|
-
function record(value) {
|
|
90
|
-
return typeof value === 'object' && value !== null ? value : {};
|
|
91
|
-
}
|
|
92
|
-
function text(value, name) {
|
|
93
|
-
const held = record(value)[name];
|
|
94
|
-
return typeof held === 'string' ? held : undefined;
|
|
95
|
-
}
|
|
96
|
-
function operationId(input) {
|
|
97
|
-
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
98
|
-
}
|
|
99
22
|
function malformed() {
|
|
100
23
|
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
101
24
|
}
|
|
102
25
|
function unimplemented(name) {
|
|
103
26
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
104
27
|
}
|
|
105
|
-
function
|
|
106
|
-
return
|
|
28
|
+
function numbered(input) {
|
|
29
|
+
return typeof input?.operation_id === 'string';
|
|
107
30
|
}
|
|
108
|
-
function
|
|
109
|
-
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
110
|
-
}
|
|
111
|
-
function answerBody(input) {
|
|
112
|
-
const nested = record(record(input).answer);
|
|
113
|
-
return {
|
|
114
|
-
conversation_id: text(input, 'conversation'),
|
|
115
|
-
operation_id: operationId(input),
|
|
116
|
-
interaction_id: text(nested, 'interaction_id'),
|
|
117
|
-
response: nested.response,
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
async function createAction(transport, route, input, name) {
|
|
121
|
-
const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
|
|
122
|
-
if (outcome.kind !== 'action')
|
|
123
|
-
return outcome;
|
|
124
|
-
const held = record(outcome.result);
|
|
125
|
-
const conversation = text(held, 'conversation_id');
|
|
126
|
-
return conversation === undefined
|
|
127
|
-
? outcome
|
|
128
|
-
: {
|
|
129
|
-
...outcome,
|
|
130
|
-
result: { ...held, conversation },
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function withTurn(body) {
|
|
134
|
-
const held = record(body);
|
|
135
|
-
const turn = text(held, 'message_id');
|
|
136
|
-
return turn === undefined
|
|
137
|
-
? body
|
|
138
|
-
: { ...held, turn };
|
|
139
|
-
}
|
|
140
|
-
export function actionOutcome(answer, name) {
|
|
31
|
+
export function actionOutcome(answer, name, input) {
|
|
141
32
|
if (answer.status === 401)
|
|
142
33
|
return { kind: 'revoked-authorization' };
|
|
143
34
|
const refusal = doorRefusal(answer.body);
|
|
144
|
-
if (refusal?.code === 'operation_contended')
|
|
35
|
+
if (refusal?.code === 'operation_contended' && numbered(input)) {
|
|
145
36
|
return { kind: 'transport-uncertainty' };
|
|
37
|
+
}
|
|
146
38
|
if (refusal !== null)
|
|
147
39
|
return { kind: 'rejected', ...refusal };
|
|
148
40
|
if (answer.status === 404)
|
|
@@ -151,230 +43,6 @@ export function actionOutcome(answer, name) {
|
|
|
151
43
|
return { kind: 'transport-uncertainty' };
|
|
152
44
|
return { kind: 'action', result: answer.body };
|
|
153
45
|
}
|
|
154
|
-
function referredRecord(view, roomRef) {
|
|
155
|
-
const held = record(view);
|
|
156
|
-
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
157
|
-
return view;
|
|
158
|
-
const referrer = {
|
|
159
|
-
room_ref: roomRef,
|
|
160
|
-
record: held.record,
|
|
161
|
-
};
|
|
162
|
-
return {
|
|
163
|
-
...held,
|
|
164
|
-
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
async function recordsAction(transport, route, input, name) {
|
|
168
|
-
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
169
|
-
if (outcome.kind !== 'action')
|
|
170
|
-
return outcome;
|
|
171
|
-
const roomRef = text(input, 'room_ref');
|
|
172
|
-
const read = record(outcome.result);
|
|
173
|
-
return {
|
|
174
|
-
...outcome,
|
|
175
|
-
result: Array.isArray(read.records)
|
|
176
|
-
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
177
|
-
: referredRecord(outcome.result, roomRef),
|
|
178
|
-
};
|
|
179
|
-
}
|
|
180
46
|
async function carry(transport, route, name, input) {
|
|
181
|
-
return actionOutcome(await transport.door(route, input), name);
|
|
182
|
-
}
|
|
183
|
-
function sendFile(entry) {
|
|
184
|
-
const file = record(entry);
|
|
185
|
-
const name = text(file, 'name');
|
|
186
|
-
const bytes = file.byteLength;
|
|
187
|
-
const sha256 = text(file, 'contentHash');
|
|
188
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
|
|
189
|
-
return null;
|
|
190
|
-
const mediaType = text(file, 'mediaType');
|
|
191
|
-
const width = file.width;
|
|
192
|
-
const height = file.height;
|
|
193
|
-
return {
|
|
194
|
-
name,
|
|
195
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
196
|
-
bytes,
|
|
197
|
-
sha256,
|
|
198
|
-
...(typeof width === 'number' && typeof height === 'number'
|
|
199
|
-
? { dimensions: { width, height } }
|
|
200
|
-
: {}),
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function sendFiles(input) {
|
|
204
|
-
const files = record(input).files;
|
|
205
|
-
if (files === undefined)
|
|
206
|
-
return [];
|
|
207
|
-
if (!Array.isArray(files))
|
|
208
|
-
return null;
|
|
209
|
-
const declared = [];
|
|
210
|
-
for (const entry of files) {
|
|
211
|
-
const file = sendFile(entry);
|
|
212
|
-
if (file === null)
|
|
213
|
-
return null;
|
|
214
|
-
declared.push(file);
|
|
215
|
-
}
|
|
216
|
-
return declared;
|
|
217
|
-
}
|
|
218
|
-
function sendBody(input) {
|
|
219
|
-
const files = sendFiles(input);
|
|
220
|
-
const operation = text(input, 'operation_id');
|
|
221
|
-
if (files === null || operation === undefined)
|
|
222
|
-
return null;
|
|
223
|
-
const textValue = text(input, 'text');
|
|
224
|
-
return {
|
|
225
|
-
conversation_id: text(input, 'conversation'),
|
|
226
|
-
operation_id: operation,
|
|
227
|
-
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
228
|
-
...(files.length === 0 ? {} : { files }),
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
async function fileBytes(file) {
|
|
232
|
-
const blob = record(file).blob;
|
|
233
|
-
if (blob === undefined || typeof blob !== 'object' || blob === null)
|
|
234
|
-
return null;
|
|
235
|
-
if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
|
|
236
|
-
return null;
|
|
237
|
-
return new Uint8Array(await blob.arrayBuffer());
|
|
238
|
-
}
|
|
239
|
-
function uploadGrant(entry) {
|
|
240
|
-
if (!('upload' in record(entry)))
|
|
241
|
-
return 'absent';
|
|
242
|
-
const upload = record(record(entry).upload);
|
|
243
|
-
if (upload.method !== 'POST')
|
|
244
|
-
return null;
|
|
245
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
|
|
246
|
-
return null;
|
|
247
|
-
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
248
|
-
}
|
|
249
|
-
async function uploadFiles(transport, input, result) {
|
|
250
|
-
const sent = record(result).files;
|
|
251
|
-
if (!Array.isArray(sent))
|
|
252
|
-
return true;
|
|
253
|
-
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
254
|
-
for (const [index, entry] of sent.entries()) {
|
|
255
|
-
const grant = uploadGrant(entry);
|
|
256
|
-
if (grant === 'absent')
|
|
257
|
-
continue;
|
|
258
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
259
|
-
if (grant === null || bytes === null)
|
|
260
|
-
return false;
|
|
261
|
-
const answer = await transport.transfer({
|
|
262
|
-
act: 'conversation_file_upload',
|
|
263
|
-
url: grant.url,
|
|
264
|
-
body: bytes,
|
|
265
|
-
operation: grant.operation,
|
|
266
|
-
});
|
|
267
|
-
if (answer.status !== 200)
|
|
268
|
-
return false;
|
|
269
|
-
}
|
|
270
|
-
return true;
|
|
271
|
-
}
|
|
272
|
-
async function sendAction(transport, route, input, name) {
|
|
273
|
-
const body = sendBody(input);
|
|
274
|
-
if (body === null)
|
|
275
|
-
return malformed();
|
|
276
|
-
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
277
|
-
if (outcome.kind !== 'action')
|
|
278
|
-
return outcome;
|
|
279
|
-
if (!(await uploadFiles(transport, input, outcome.result))) {
|
|
280
|
-
return { kind: 'transport-uncertainty' };
|
|
281
|
-
}
|
|
282
|
-
return { ...outcome, result: withTurn(outcome.result) };
|
|
283
|
-
}
|
|
284
|
-
function historyCursor(value) {
|
|
285
|
-
const acceptedAt = text(value, 'accepted_at');
|
|
286
|
-
const messageId = text(value, 'message_id');
|
|
287
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
288
|
-
return null;
|
|
289
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
290
|
-
}
|
|
291
|
-
function position(cursor) {
|
|
292
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
293
|
-
}
|
|
294
|
-
function positionCursor(value) {
|
|
295
|
-
try {
|
|
296
|
-
return historyCursor(JSON.parse(value));
|
|
297
|
-
}
|
|
298
|
-
catch {
|
|
299
|
-
return null;
|
|
300
|
-
}
|
|
301
|
-
}
|
|
302
|
-
export function acceptedMessage(entry) {
|
|
303
|
-
const cursor = historyCursor(entry);
|
|
304
|
-
if (cursor === null)
|
|
305
|
-
return null;
|
|
306
|
-
const message = structuredClone(record(entry));
|
|
307
|
-
const referrer = { message: cursor.message_id };
|
|
308
|
-
return {
|
|
309
|
-
identity: cursor.message_id,
|
|
310
|
-
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
311
|
-
position: position(cursor),
|
|
312
|
-
text: text(entry, 'text') ?? '',
|
|
313
|
-
message: Array.isArray(message.files)
|
|
314
|
-
? {
|
|
315
|
-
...message,
|
|
316
|
-
files: message.files.map((file) => ({ ...record(file), referrer })),
|
|
317
|
-
}
|
|
318
|
-
: message,
|
|
319
|
-
};
|
|
320
|
-
}
|
|
321
|
-
function historyPage(entry) {
|
|
322
|
-
const held = record(entry);
|
|
323
|
-
const conversation = text(held, 'conversation_id');
|
|
324
|
-
if (conversation === undefined || !Array.isArray(held.messages))
|
|
325
|
-
return null;
|
|
326
|
-
const messages = [];
|
|
327
|
-
for (const one of held.messages) {
|
|
328
|
-
const message = acceptedMessage(one);
|
|
329
|
-
if (message === null)
|
|
330
|
-
return null;
|
|
331
|
-
messages.push(message);
|
|
332
|
-
}
|
|
333
|
-
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
334
|
-
if (next === null)
|
|
335
|
-
return null;
|
|
336
|
-
return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
|
|
337
|
-
}
|
|
338
|
-
function historyAsks(input) {
|
|
339
|
-
const asked = record(input).conversations;
|
|
340
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
341
|
-
return null;
|
|
342
|
-
const asks = [];
|
|
343
|
-
for (const entry of asked) {
|
|
344
|
-
const conversationId = text(entry, 'conversation');
|
|
345
|
-
if (conversationId === undefined)
|
|
346
|
-
return null;
|
|
347
|
-
const afterValue = text(entry, 'after');
|
|
348
|
-
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
349
|
-
if (after === null)
|
|
350
|
-
return null;
|
|
351
|
-
asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
|
|
352
|
-
}
|
|
353
|
-
return asks;
|
|
354
|
-
}
|
|
355
|
-
async function historyAction(transport, route, input, name) {
|
|
356
|
-
const asks = historyAsks(input);
|
|
357
|
-
if (asks === null)
|
|
358
|
-
return malformed();
|
|
359
|
-
const histories = [];
|
|
360
|
-
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
361
|
-
const answer = await transport.door(route, {
|
|
362
|
-
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
363
|
-
limit: HISTORY_PAGE,
|
|
364
|
-
});
|
|
365
|
-
const outcome = actionOutcome(answer, name);
|
|
366
|
-
if (outcome.kind !== 'action')
|
|
367
|
-
return outcome;
|
|
368
|
-
const answered = record(outcome.result).histories;
|
|
369
|
-
if (!Array.isArray(answered))
|
|
370
|
-
return { kind: 'transport-uncertainty' };
|
|
371
|
-
for (const entry of answered) {
|
|
372
|
-
const page = historyPage(entry);
|
|
373
|
-
if (page === null)
|
|
374
|
-
return { kind: 'transport-uncertainty' };
|
|
375
|
-
histories.push(page);
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
const result = { histories };
|
|
379
|
-
return { kind: 'action', result };
|
|
47
|
+
return actionOutcome(await transport.door(route, input), name, input);
|
|
380
48
|
}
|
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,EAIV,OAAO,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAgBd,MAAM,wBAAwB,CAAC;AAiChC,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;AA6DrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAqapF"}
|