@agentshouse/mdruntime-adapter 0.1.0-ccda1a2da11c3 → 0.1.0-ccdfb41af2abb
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 +3 -71
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -317
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +171 -336
- 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 +12 -12
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +44 -51
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +91 -0
- package/dist/house-model.d.ts +892 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +482 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/model.d.ts +5 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -29
- package/dist/part.d.ts +12 -11
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +66 -56
- package/dist/read.d.ts +19 -56
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +138 -297
- 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 +19 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +57 -0
- package/dist/room-types.d.ts +2 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +62 -3
- 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 +79 -177
- package/dist/stream.d.ts +13 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +168 -426
- package/dist/transport.d.ts +48 -38
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +55 -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 +6 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +19 -32
- package/package.json +8 -4
- package/AGENTS.md +0 -309
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -35
- package/dist/referrer.d.ts +0 -9
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -41
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,75 +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
|
-
export type AppInputs = {
|
|
10
|
-
readonly 'conversation.attach': FileDeclaration & {
|
|
11
|
-
readonly room: string;
|
|
12
|
-
readonly blob: Blob;
|
|
13
|
-
};
|
|
14
|
-
readonly 'conversation.answer': ConversationControl & {
|
|
15
|
-
readonly answer: {
|
|
16
|
-
readonly interaction_id: string;
|
|
17
|
-
readonly response: unknown;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
readonly 'conversation.create': Operated & {
|
|
21
|
-
readonly agent_id: string;
|
|
22
|
-
};
|
|
23
|
-
readonly 'conversation.delete': ConversationControl;
|
|
24
|
-
readonly 'conversation.history': ConversationHistoryRequest;
|
|
25
|
-
readonly 'conversation.interrupt': ConversationControl;
|
|
26
|
-
readonly 'conversation.kill': ConversationControl;
|
|
27
|
-
readonly 'conversation.send': ConversationControl & {
|
|
28
|
-
readonly operation_id: string;
|
|
29
|
-
readonly text: string;
|
|
30
|
-
};
|
|
31
|
-
readonly 'trigger.list': {
|
|
32
|
-
readonly room_refs: readonly string[];
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export type AppAnswers = {
|
|
36
|
-
readonly 'conversation.attach': {
|
|
37
|
-
readonly path: string;
|
|
38
|
-
};
|
|
39
|
-
readonly 'conversation.history': ConversationHistories;
|
|
40
|
-
};
|
|
41
|
-
export type AppAnswerAdditions = {
|
|
42
|
-
readonly 'conversation.create': {
|
|
43
|
-
readonly conversation: string;
|
|
44
|
-
};
|
|
45
|
-
readonly 'conversation.send': {
|
|
46
|
-
readonly turn: string;
|
|
47
|
-
};
|
|
48
|
-
readonly 'record.list': {
|
|
49
|
-
readonly attachments: readonly {
|
|
50
|
-
readonly referrer: {
|
|
51
|
-
readonly room_ref: string;
|
|
52
|
-
readonly record: string;
|
|
53
|
-
};
|
|
54
|
-
}[];
|
|
55
|
-
readonly records: readonly {
|
|
56
|
-
readonly attachments: readonly {
|
|
57
|
-
readonly referrer: {
|
|
58
|
-
readonly room_ref: string;
|
|
59
|
-
readonly record: string;
|
|
60
|
-
};
|
|
61
|
-
}[];
|
|
62
|
-
}[];
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
|
|
66
|
-
export declare const SITE_SUBMIT = "submit";
|
|
67
|
-
export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
|
|
68
|
-
export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
|
|
69
|
-
export declare function houseConversationAgents(locator: string): ConversationAgents;
|
|
3
|
+
export type HouseActDoor = Pick<HouseTransport, 'door'>;
|
|
70
4
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
71
|
-
export declare function houseAction(transport:
|
|
5
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
72
6
|
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
73
|
-
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
74
|
-
export {};
|
|
75
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;AAoBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF"}
|
package/dist/actions.js
CHANGED
|
@@ -1,78 +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 TRIGGER_ROOMS = 100;
|
|
6
|
-
const OCTET_STREAM = 'application/octet-stream';
|
|
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.attach': carried('conversations/attach', attachAction, undefined, 'room'),
|
|
27
|
-
'conversation.create': carried('conversations/create', createAction),
|
|
28
|
-
'conversation.delete': mapped('conversations/delete', controlBody),
|
|
29
|
-
'conversation.history': carried('conversations/history', historyAction, ['conversations']),
|
|
30
|
-
'conversation.interrupt': mapped('conversations/interrupt', controlBody),
|
|
31
|
-
'conversation.kill': mapped('conversations/kill', controlBody),
|
|
32
|
-
'conversation.markDone': mapped('conversations/done'),
|
|
33
|
-
'conversation.rename': mapped('conversations/rename'),
|
|
34
|
-
'conversation.retry': mapped('conversations/retry'),
|
|
35
|
-
'conversation.send': carried('conversations/send', sendAction),
|
|
36
|
-
'conversation.setOption': mapped('conversations/option'),
|
|
37
|
-
'feature.list': mapped('apps/features/read'),
|
|
38
|
-
'holder.list': mapped('apps/holders'),
|
|
39
|
-
'holder.ring': mapped('apps/ring'),
|
|
40
|
-
'member.list': mapped('rooms/members'),
|
|
41
|
-
'message.send': mapped('apps/messages/send'),
|
|
42
|
-
'processing.read': mapped('rooms/settings/processing/read'),
|
|
43
|
-
'record.list': carried('records/read', recordsAction),
|
|
44
|
-
'relay.read': mapped('apps/relay'),
|
|
45
|
-
'routine.list': mapped('routines/access'),
|
|
46
|
-
'routineAccess.list': mapped('routines/granted'),
|
|
47
|
-
'routineAllowance.list': mapped('routines/allowance'),
|
|
48
|
-
'routineRequest.list': mapped('routines/requests'),
|
|
49
|
-
'storage.read': mapped('storage/inventory'),
|
|
50
|
-
'trigger.list': carried('triggers/read', triggersAction, ['room_refs'], 'room_refs'),
|
|
51
|
-
'triggerOccurrence.list': mapped('triggers/fired'),
|
|
52
|
-
};
|
|
53
|
-
export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
|
|
54
|
-
export const SITE_SUBMIT = 'submit';
|
|
55
|
-
export const HOUSE_SITE_ACTS = {
|
|
56
|
-
[SITE_SUBMIT]: 'site/submission',
|
|
57
|
-
};
|
|
58
|
-
export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
|
|
59
|
-
const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
|
|
60
|
-
const APP_ROOMS = new Map(Object.entries(APP_ACTS).flatMap(([name, act]) => act.room === undefined ? [] : [[name, act.room]]));
|
|
61
|
-
export function houseConversationAgents(locator) {
|
|
62
|
-
return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
|
|
63
|
-
}
|
|
64
2
|
export function declaredActions(routes) {
|
|
65
|
-
return routes.map((
|
|
66
|
-
const name = APP_NAMES.get(route) ?? route;
|
|
67
|
-
return { name, inputShape: {}, resultKind: 'house', room: APP_ROOMS.get(name) ?? 'room_ref' };
|
|
68
|
-
});
|
|
3
|
+
return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
|
|
69
4
|
}
|
|
70
5
|
export function houseAction(transport, request) {
|
|
71
|
-
if (Object.hasOwn(APP_ACTS, request.name)) {
|
|
72
|
-
return APP_ACTS[request.name].carry(transport, request.input, request.name);
|
|
73
|
-
}
|
|
74
|
-
if (APP_NAMES.has(request.name))
|
|
75
|
-
return Promise.resolve(unimplemented(request.name));
|
|
76
6
|
const route = routeOf(request.name);
|
|
77
7
|
if (route === null)
|
|
78
8
|
return Promise.resolve(malformed());
|
|
@@ -89,57 +19,12 @@ function routeOf(name) {
|
|
|
89
19
|
return null;
|
|
90
20
|
}
|
|
91
21
|
}
|
|
92
|
-
function record(value) {
|
|
93
|
-
return typeof value === 'object' && value !== null ? value : {};
|
|
94
|
-
}
|
|
95
|
-
function text(value, name) {
|
|
96
|
-
const held = record(value)[name];
|
|
97
|
-
return typeof held === 'string' ? held : undefined;
|
|
98
|
-
}
|
|
99
|
-
function operationId(input) {
|
|
100
|
-
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
101
|
-
}
|
|
102
22
|
function malformed() {
|
|
103
23
|
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
104
24
|
}
|
|
105
25
|
function unimplemented(name) {
|
|
106
26
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
107
27
|
}
|
|
108
|
-
function createBody(input) {
|
|
109
|
-
return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
|
|
110
|
-
}
|
|
111
|
-
function controlBody(input) {
|
|
112
|
-
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
113
|
-
}
|
|
114
|
-
function answerBody(input) {
|
|
115
|
-
const nested = record(record(input).answer);
|
|
116
|
-
return {
|
|
117
|
-
conversation_id: text(input, 'conversation'),
|
|
118
|
-
operation_id: operationId(input),
|
|
119
|
-
interaction_id: text(nested, 'interaction_id'),
|
|
120
|
-
response: nested.response,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
async function createAction(transport, route, input, name) {
|
|
124
|
-
const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
|
|
125
|
-
if (outcome.kind !== 'action')
|
|
126
|
-
return outcome;
|
|
127
|
-
const held = record(outcome.result);
|
|
128
|
-
const conversation = text(held, 'conversation_id');
|
|
129
|
-
return conversation === undefined
|
|
130
|
-
? outcome
|
|
131
|
-
: {
|
|
132
|
-
...outcome,
|
|
133
|
-
result: { ...held, conversation },
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
function withTurn(body) {
|
|
137
|
-
const held = record(body);
|
|
138
|
-
const turn = text(held, 'message_id');
|
|
139
|
-
return turn === undefined
|
|
140
|
-
? body
|
|
141
|
-
: { ...held, turn };
|
|
142
|
-
}
|
|
143
28
|
export function actionOutcome(answer, name) {
|
|
144
29
|
if (answer.status === 401)
|
|
145
30
|
return { kind: 'revoked-authorization' };
|
|
@@ -154,207 +39,6 @@ export function actionOutcome(answer, name) {
|
|
|
154
39
|
return { kind: 'transport-uncertainty' };
|
|
155
40
|
return { kind: 'action', result: answer.body };
|
|
156
41
|
}
|
|
157
|
-
function referredRecord(view, roomRef) {
|
|
158
|
-
const held = record(view);
|
|
159
|
-
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
160
|
-
return view;
|
|
161
|
-
const referrer = {
|
|
162
|
-
room_ref: roomRef,
|
|
163
|
-
record: held.record,
|
|
164
|
-
};
|
|
165
|
-
return {
|
|
166
|
-
...held,
|
|
167
|
-
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
168
|
-
};
|
|
169
|
-
}
|
|
170
|
-
async function recordsAction(transport, route, input, name) {
|
|
171
|
-
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
172
|
-
if (outcome.kind !== 'action')
|
|
173
|
-
return outcome;
|
|
174
|
-
const roomRef = text(input, 'room_ref');
|
|
175
|
-
const read = record(outcome.result);
|
|
176
|
-
return {
|
|
177
|
-
...outcome,
|
|
178
|
-
result: Array.isArray(read.records)
|
|
179
|
-
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
180
|
-
: referredRecord(outcome.result, roomRef),
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
42
|
async function carry(transport, route, name, input) {
|
|
184
43
|
return actionOutcome(await transport.door(route, input), name);
|
|
185
44
|
}
|
|
186
|
-
function sendBody(input) {
|
|
187
|
-
const operation = text(input, 'operation_id');
|
|
188
|
-
const said = text(input, 'text');
|
|
189
|
-
if (operation === undefined || said === undefined)
|
|
190
|
-
return null;
|
|
191
|
-
return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
|
|
192
|
-
}
|
|
193
|
-
async function sendAction(transport, route, input, name) {
|
|
194
|
-
const body = sendBody(input);
|
|
195
|
-
if (body === null)
|
|
196
|
-
return malformed();
|
|
197
|
-
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
198
|
-
if (outcome.kind !== 'action')
|
|
199
|
-
return outcome;
|
|
200
|
-
return { ...outcome, result: withTurn(outcome.result) };
|
|
201
|
-
}
|
|
202
|
-
function attachBody(input) {
|
|
203
|
-
const room = text(input, 'room');
|
|
204
|
-
const name = text(input, 'name');
|
|
205
|
-
const sha256 = text(input, 'contentHash');
|
|
206
|
-
const bytes = record(input).byteLength;
|
|
207
|
-
if (room === undefined || name === undefined || sha256 === undefined)
|
|
208
|
-
return null;
|
|
209
|
-
if (typeof bytes !== 'number')
|
|
210
|
-
return null;
|
|
211
|
-
const mediaType = text(input, 'mediaType');
|
|
212
|
-
return {
|
|
213
|
-
room_ref: room,
|
|
214
|
-
name,
|
|
215
|
-
bytes,
|
|
216
|
-
sha256,
|
|
217
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
218
|
-
};
|
|
219
|
-
}
|
|
220
|
-
function uploadGrant(answer) {
|
|
221
|
-
const upload = record(record(answer).upload);
|
|
222
|
-
if (upload.method !== 'POST')
|
|
223
|
-
return null;
|
|
224
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
|
|
225
|
-
return null;
|
|
226
|
-
return { operation: upload.operation, url: upload.url };
|
|
227
|
-
}
|
|
228
|
-
async function attachAction(transport, route, input, name) {
|
|
229
|
-
const body = attachBody(input);
|
|
230
|
-
const blob = record(input).blob;
|
|
231
|
-
if (body === null || !(blob instanceof Blob))
|
|
232
|
-
return malformed();
|
|
233
|
-
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
234
|
-
if (outcome.kind !== 'action')
|
|
235
|
-
return outcome;
|
|
236
|
-
const grant = uploadGrant(outcome.result);
|
|
237
|
-
if (grant === null)
|
|
238
|
-
return { kind: 'transport-uncertainty' };
|
|
239
|
-
const sent = await transport.transfer({
|
|
240
|
-
act: 'file_upload',
|
|
241
|
-
url: grant.url,
|
|
242
|
-
body: new Uint8Array(await blob.arrayBuffer()),
|
|
243
|
-
operation: grant.operation,
|
|
244
|
-
});
|
|
245
|
-
if (sent.status !== 200) {
|
|
246
|
-
const refusal = doorRefusal(sent.body);
|
|
247
|
-
return refusal === null ? { kind: 'transport-uncertainty' } : { kind: 'rejected', ...refusal };
|
|
248
|
-
}
|
|
249
|
-
const path = text(sent.body, 'path');
|
|
250
|
-
if (path === undefined)
|
|
251
|
-
return { kind: 'transport-uncertainty' };
|
|
252
|
-
const result = { path };
|
|
253
|
-
return { kind: 'action', result };
|
|
254
|
-
}
|
|
255
|
-
function historyCursor(value) {
|
|
256
|
-
const acceptedAt = text(value, 'accepted_at');
|
|
257
|
-
const messageId = text(value, 'message_id');
|
|
258
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
259
|
-
return null;
|
|
260
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
261
|
-
}
|
|
262
|
-
function position(cursor) {
|
|
263
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
264
|
-
}
|
|
265
|
-
function positionCursor(value) {
|
|
266
|
-
try {
|
|
267
|
-
return historyCursor(JSON.parse(value));
|
|
268
|
-
}
|
|
269
|
-
catch {
|
|
270
|
-
return null;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
export function acceptedMessage(entry) {
|
|
274
|
-
const cursor = historyCursor(entry);
|
|
275
|
-
if (cursor === null)
|
|
276
|
-
return null;
|
|
277
|
-
return {
|
|
278
|
-
identity: cursor.message_id,
|
|
279
|
-
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
280
|
-
position: position(cursor),
|
|
281
|
-
text: text(entry, 'text') ?? '',
|
|
282
|
-
message: structuredClone(record(entry)),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
285
|
-
function historyPage(entry) {
|
|
286
|
-
const held = record(entry);
|
|
287
|
-
const conversation = text(held, 'conversation_id');
|
|
288
|
-
if (conversation === undefined || !Array.isArray(held.messages))
|
|
289
|
-
return null;
|
|
290
|
-
const messages = [];
|
|
291
|
-
for (const one of held.messages) {
|
|
292
|
-
const message = acceptedMessage(one);
|
|
293
|
-
if (message === null)
|
|
294
|
-
return null;
|
|
295
|
-
messages.push(message);
|
|
296
|
-
}
|
|
297
|
-
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
298
|
-
if (next === null)
|
|
299
|
-
return null;
|
|
300
|
-
return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
|
|
301
|
-
}
|
|
302
|
-
function historyAsks(input) {
|
|
303
|
-
const asked = record(input).conversations;
|
|
304
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
305
|
-
return null;
|
|
306
|
-
const asks = [];
|
|
307
|
-
for (const entry of asked) {
|
|
308
|
-
const conversationId = text(entry, 'conversation');
|
|
309
|
-
if (conversationId === undefined)
|
|
310
|
-
return null;
|
|
311
|
-
const afterValue = text(entry, 'after');
|
|
312
|
-
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
313
|
-
if (after === null)
|
|
314
|
-
return null;
|
|
315
|
-
asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
|
|
316
|
-
}
|
|
317
|
-
return asks;
|
|
318
|
-
}
|
|
319
|
-
async function triggersAction(transport, route, input, name) {
|
|
320
|
-
const asked = record(input).room_refs;
|
|
321
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
322
|
-
return malformed();
|
|
323
|
-
const rooms = [];
|
|
324
|
-
for (let at = 0; at < asked.length; at += TRIGGER_ROOMS) {
|
|
325
|
-
const outcome = actionOutcome(await transport.door(route, { room_refs: asked.slice(at, at + TRIGGER_ROOMS) }), name);
|
|
326
|
-
if (outcome.kind !== 'action')
|
|
327
|
-
return outcome;
|
|
328
|
-
const answered = record(outcome.result).rooms;
|
|
329
|
-
if (!Array.isArray(answered))
|
|
330
|
-
return { kind: 'transport-uncertainty' };
|
|
331
|
-
rooms.push(...answered);
|
|
332
|
-
}
|
|
333
|
-
return { kind: 'action', result: { rooms } };
|
|
334
|
-
}
|
|
335
|
-
async function historyAction(transport, route, input, name) {
|
|
336
|
-
const asks = historyAsks(input);
|
|
337
|
-
if (asks === null)
|
|
338
|
-
return malformed();
|
|
339
|
-
const histories = [];
|
|
340
|
-
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
341
|
-
const answer = await transport.door(route, {
|
|
342
|
-
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
343
|
-
limit: HISTORY_PAGE,
|
|
344
|
-
});
|
|
345
|
-
const outcome = actionOutcome(answer, name);
|
|
346
|
-
if (outcome.kind !== 'action')
|
|
347
|
-
return outcome;
|
|
348
|
-
const answered = record(outcome.result).histories;
|
|
349
|
-
if (!Array.isArray(answered))
|
|
350
|
-
return { kind: 'transport-uncertainty' };
|
|
351
|
-
for (const entry of answered) {
|
|
352
|
-
const page = historyPage(entry);
|
|
353
|
-
if (page === null)
|
|
354
|
-
return { kind: 'transport-uncertainty' };
|
|
355
|
-
histories.push(page);
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
const result = { histories };
|
|
359
|
-
return { kind: 'action', result };
|
|
360
|
-
}
|
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;AAgChC,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAmBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AA+DrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA4bpF"}
|