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