@agentshouse/mdruntime-adapter 0.1.0-c3bd45bca89d3 → 0.1.0-c3c5582303db5
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 +3 -3
- package/dist/actions.d.ts +6 -7
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +45 -345
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +301 -252
- package/dist/authored-path.d.ts +61 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +166 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +45 -18
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +254 -65
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -1
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -7
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +30 -50
- package/dist/read.d.ts +54 -53
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +209 -278
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -10
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +20 -0
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +63 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +20 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +54 -0
- package/dist/session-content/turn.d.ts +147 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +153 -107
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +15 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +344 -153
- package/dist/transport.d.ts +152 -31
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +93 -9
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +17 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +106 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +14 -12
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +197 -137
- package/package.json +11 -7
- package/AGENTS.md +0 -269
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/README.md
CHANGED
|
@@ -20,12 +20,12 @@ import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
|
|
|
20
20
|
|
|
21
21
|
const adapter = createAgentsHouseAdapter({ transport, authorize });
|
|
22
22
|
const host = serveMdRuntime({ adapter, shell });
|
|
23
|
-
host.attach(port, 'my-app');
|
|
23
|
+
host.attach(port, { app: '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` tool opens.
|
|
29
29
|
|
|
30
30
|
## License
|
|
31
31
|
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
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
|
|
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[];
|
|
5
6
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
6
|
-
export declare function houseAction(transport:
|
|
7
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
8
|
-
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
9
|
-
//# sourceMappingURL=actions.d.ts.map
|
|
7
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
8
|
+
export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
|
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;AAI7F,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,EAI/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAcF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAOvF;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,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'
|
|
24
|
-
|
|
25
|
-
'conversation.create': mapped('conversations/create', createBody),
|
|
26
|
-
'conversation.delete': mapped('conversations/delete', controlBody),
|
|
27
|
-
'conversation.history': carried('conversations/history', historyAction),
|
|
28
|
-
'conversation.interrupt': mapped('conversations/interrupt', controlBody),
|
|
29
|
-
'conversation.kill': mapped('conversations/kill', controlBody),
|
|
30
|
-
'conversation.markDone': mapped('conversations/done'),
|
|
31
|
-
'conversation.rename': mapped('conversations/rename'),
|
|
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': mapped('records/read'),
|
|
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
|
-
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' };
|
|
54
|
-
}
|
|
1
|
+
import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
import { movedPaths, renamedHandle } from './renamed.js';
|
|
3
|
+
import { refusedFor } from './uncertain.js';
|
|
4
|
+
export const HOUSE_UNKEPT_READS = [
|
|
5
|
+
'account.read security',
|
|
6
|
+
'account.billing',
|
|
7
|
+
'account.clients',
|
|
8
|
+
];
|
|
9
|
+
export const HOUSE_LEADING_READS = [
|
|
10
|
+
'app.list',
|
|
11
|
+
'apps/list',
|
|
12
|
+
'sites/list',
|
|
13
|
+
'rooms/members/list',
|
|
14
|
+
'sharing.members',
|
|
15
|
+
];
|
|
16
|
+
const ROOM_SELECTORS = new Map([
|
|
17
|
+
['update', { room: 'changes.room', roomPaths: ['changes.path', 'changes.to', 'paths', 'mount'] }],
|
|
18
|
+
['sharing', { room: 'room' }],
|
|
19
|
+
['sharing_update', { room: 'room' }],
|
|
20
|
+
['inbox_update', { room: 'room', roomPaths: ['path'] }],
|
|
21
|
+
['agent', { room: 'room' }],
|
|
22
|
+
['agent_update', { room: 'room' }],
|
|
23
|
+
['environment', { room: 'room' }],
|
|
24
|
+
]);
|
|
55
25
|
export function declaredActions(routes) {
|
|
56
|
-
return routes.map((
|
|
57
|
-
name
|
|
26
|
+
return routes.map((name) => ({
|
|
27
|
+
name,
|
|
58
28
|
inputShape: {},
|
|
59
29
|
resultKind: 'house',
|
|
30
|
+
...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
|
|
60
31
|
}));
|
|
61
32
|
}
|
|
62
33
|
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
34
|
const route = routeOf(request.name);
|
|
69
35
|
if (route === null)
|
|
70
36
|
return Promise.resolve(malformed());
|
|
@@ -81,303 +47,37 @@ function routeOf(name) {
|
|
|
81
47
|
return null;
|
|
82
48
|
}
|
|
83
49
|
}
|
|
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
50
|
function malformed() {
|
|
95
51
|
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
96
52
|
}
|
|
97
53
|
function unimplemented(name) {
|
|
98
54
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
99
55
|
}
|
|
100
|
-
function
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
function controlBody(input) {
|
|
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
|
-
function withTurn(body) {
|
|
116
|
-
const held = record(body);
|
|
117
|
-
const turn = text(held, 'message_id');
|
|
118
|
-
return turn === undefined ? body : { ...held, turn };
|
|
56
|
+
function numbered(input) {
|
|
57
|
+
return typeof input?.operation_id === 'string';
|
|
119
58
|
}
|
|
120
|
-
export function actionOutcome(answer, name) {
|
|
59
|
+
export function actionOutcome(answer, name, input) {
|
|
121
60
|
if (answer.status === 401)
|
|
122
61
|
return { kind: 'revoked-authorization' };
|
|
123
62
|
const refusal = doorRefusal(answer.body);
|
|
124
|
-
if (refusal
|
|
125
|
-
return
|
|
63
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
64
|
+
return refusedFor(refusal);
|
|
65
|
+
if (refusal !== null) {
|
|
66
|
+
const reset = resetOf(refusal);
|
|
67
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
68
|
+
}
|
|
126
69
|
if (answer.status === 404)
|
|
127
70
|
return unimplemented(name);
|
|
128
|
-
if (answer.status === 0 || answer.status >= 400)
|
|
129
|
-
return
|
|
71
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
72
|
+
return answeredFailure(answer.status, answer.body);
|
|
73
|
+
}
|
|
130
74
|
return { kind: 'action', result: answer.body };
|
|
131
75
|
}
|
|
132
76
|
async function carry(transport, route, name, input) {
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
const
|
|
138
|
-
|
|
139
|
-
const sha256 = text(file, 'contentHash');
|
|
140
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
|
|
141
|
-
return null;
|
|
142
|
-
const mediaType = text(file, 'mediaType');
|
|
143
|
-
const width = file.width;
|
|
144
|
-
const height = file.height;
|
|
145
|
-
return {
|
|
146
|
-
name,
|
|
147
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
148
|
-
bytes,
|
|
149
|
-
sha256,
|
|
150
|
-
...(typeof width === 'number' && typeof height === 'number'
|
|
151
|
-
? { dimensions: { width, height } }
|
|
152
|
-
: {}),
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
function sendFiles(input) {
|
|
156
|
-
const files = record(input).files;
|
|
157
|
-
if (files === undefined)
|
|
158
|
-
return [];
|
|
159
|
-
if (!Array.isArray(files))
|
|
160
|
-
return null;
|
|
161
|
-
const declared = [];
|
|
162
|
-
for (const entry of files) {
|
|
163
|
-
const file = sendFile(entry);
|
|
164
|
-
if (file === null)
|
|
165
|
-
return null;
|
|
166
|
-
declared.push(file);
|
|
167
|
-
}
|
|
168
|
-
return declared;
|
|
169
|
-
}
|
|
170
|
-
function sendBody(input) {
|
|
171
|
-
const files = sendFiles(input);
|
|
172
|
-
if (files === null)
|
|
173
|
-
return null;
|
|
174
|
-
const textValue = text(input, 'text');
|
|
175
|
-
return {
|
|
176
|
-
conversation_id: text(input, 'conversation'),
|
|
177
|
-
operation_id: operationId(input),
|
|
178
|
-
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
179
|
-
...(files.length === 0 ? {} : { files }),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
async function fileBytes(file) {
|
|
183
|
-
const blob = record(file).blob;
|
|
184
|
-
if (blob === undefined || typeof blob !== 'object' || blob === null)
|
|
185
|
-
return null;
|
|
186
|
-
if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
|
|
187
|
-
return null;
|
|
188
|
-
return new Uint8Array(await blob.arrayBuffer());
|
|
189
|
-
}
|
|
190
|
-
function delivered(answer, name) {
|
|
191
|
-
return answer.status === 200 ? null : actionOutcome(answer, name);
|
|
192
|
-
}
|
|
193
|
-
function uploadGrant(entry) {
|
|
194
|
-
if (!('upload' in record(entry)))
|
|
195
|
-
return 'absent';
|
|
196
|
-
const upload = record(record(entry).upload);
|
|
197
|
-
if (upload.method !== 'POST')
|
|
198
|
-
return null;
|
|
199
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
|
|
200
|
-
return null;
|
|
201
|
-
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
202
|
-
}
|
|
203
|
-
async function uploadOriginals(transport, input, result, name) {
|
|
204
|
-
const originals = record(result).originals;
|
|
205
|
-
if (!Array.isArray(originals) || originals.length === 0)
|
|
206
|
-
return null;
|
|
207
|
-
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
208
|
-
for (const [index, entry] of originals.entries()) {
|
|
209
|
-
const grant = uploadGrant(entry);
|
|
210
|
-
if (grant === 'absent')
|
|
211
|
-
continue;
|
|
212
|
-
if (grant === null)
|
|
213
|
-
return malformed();
|
|
214
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
215
|
-
if (bytes === null) {
|
|
216
|
-
return {
|
|
217
|
-
kind: 'rejected',
|
|
218
|
-
code: 'conversation_original_descriptor_required',
|
|
219
|
-
fields: {},
|
|
220
|
-
retryable: false,
|
|
221
|
-
};
|
|
222
|
-
}
|
|
223
|
-
const failed = delivered(await transport.transfer({
|
|
224
|
-
act: 'conversation_original_upload',
|
|
225
|
-
method: 'POST',
|
|
226
|
-
url: grant.url,
|
|
227
|
-
answer: 'json',
|
|
228
|
-
body: bytes,
|
|
229
|
-
operation: grant.operation,
|
|
230
|
-
}), name);
|
|
231
|
-
if (failed !== null)
|
|
232
|
-
return failed;
|
|
233
|
-
}
|
|
234
|
-
return null;
|
|
235
|
-
}
|
|
236
|
-
async function attachAction(transport, route, input, name) {
|
|
237
|
-
const { blob, ...descriptor } = record(input);
|
|
238
|
-
const bytes = await fileBytes({ blob });
|
|
239
|
-
if (bytes === null)
|
|
240
|
-
return malformed();
|
|
241
|
-
const outcome = actionOutcome(await transport.door(route, descriptor), name);
|
|
242
|
-
if (outcome.kind !== 'action')
|
|
243
|
-
return outcome;
|
|
244
|
-
const grant = uploadGrant(outcome.result);
|
|
245
|
-
if (grant === 'absent')
|
|
246
|
-
return outcome;
|
|
247
|
-
if (grant === null)
|
|
248
|
-
return malformed();
|
|
249
|
-
const stored = await transport.transfer({
|
|
250
|
-
act: 'original_upload',
|
|
251
|
-
method: 'POST',
|
|
252
|
-
url: grant.url,
|
|
253
|
-
answer: 'json',
|
|
254
|
-
body: bytes,
|
|
255
|
-
operation: grant.operation,
|
|
256
|
-
});
|
|
257
|
-
return delivered(stored, name) ?? { kind: 'action', result: stored.body };
|
|
258
|
-
}
|
|
259
|
-
async function openAction(transport, route, input, name) {
|
|
260
|
-
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
261
|
-
if (outcome.kind !== 'action')
|
|
262
|
-
return outcome;
|
|
263
|
-
const { download, ...opened } = record(outcome.result);
|
|
264
|
-
if (download === undefined)
|
|
265
|
-
return outcome;
|
|
266
|
-
const grant = record(download);
|
|
267
|
-
if (grant.method !== 'GET' || typeof grant.url !== 'string')
|
|
268
|
-
return malformed();
|
|
269
|
-
const read = await transport.transfer({
|
|
270
|
-
act: 'original_download',
|
|
271
|
-
method: 'GET',
|
|
272
|
-
url: grant.url,
|
|
273
|
-
answer: 'bytes',
|
|
274
|
-
});
|
|
275
|
-
const failed = delivered(read, name);
|
|
276
|
-
if (failed !== null)
|
|
277
|
-
return failed;
|
|
278
|
-
if (!(read.body instanceof Blob))
|
|
279
|
-
return { kind: 'transport-uncertainty' };
|
|
280
|
-
return { kind: 'action', result: { ...opened, blob: read.body } };
|
|
281
|
-
}
|
|
282
|
-
async function sendAction(transport, route, input, name) {
|
|
283
|
-
const body = sendBody(input);
|
|
284
|
-
if (body === null)
|
|
285
|
-
return malformed();
|
|
286
|
-
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
287
|
-
if (outcome.kind !== 'action')
|
|
288
|
-
return outcome;
|
|
289
|
-
const uploaded = await uploadOriginals(transport, input, outcome.result, name);
|
|
290
|
-
if (uploaded !== null)
|
|
291
|
-
return uploaded;
|
|
292
|
-
return { ...outcome, result: withTurn(outcome.result) };
|
|
293
|
-
}
|
|
294
|
-
function historyCursor(value) {
|
|
295
|
-
const acceptedAt = text(value, 'accepted_at');
|
|
296
|
-
const messageId = text(value, 'message_id');
|
|
297
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
298
|
-
return null;
|
|
299
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
300
|
-
}
|
|
301
|
-
function position(cursor) {
|
|
302
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
303
|
-
}
|
|
304
|
-
function positionCursor(value) {
|
|
305
|
-
try {
|
|
306
|
-
return historyCursor(JSON.parse(value));
|
|
307
|
-
}
|
|
308
|
-
catch {
|
|
309
|
-
return null;
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
export function acceptedMessage(entry) {
|
|
313
|
-
const cursor = historyCursor(entry);
|
|
314
|
-
if (cursor === null)
|
|
315
|
-
return null;
|
|
316
|
-
return {
|
|
317
|
-
identity: cursor.message_id,
|
|
318
|
-
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
319
|
-
position: position(cursor),
|
|
320
|
-
text: text(entry, 'text') ?? '',
|
|
321
|
-
message: structuredClone(entry),
|
|
322
|
-
};
|
|
323
|
-
}
|
|
324
|
-
function historyPage(entry) {
|
|
325
|
-
const held = record(entry);
|
|
326
|
-
const conversation = text(held, 'conversation_id');
|
|
327
|
-
if (conversation === undefined || !Array.isArray(held.messages))
|
|
328
|
-
return null;
|
|
329
|
-
const messages = [];
|
|
330
|
-
for (const one of held.messages) {
|
|
331
|
-
const message = acceptedMessage(one);
|
|
332
|
-
if (message === null)
|
|
333
|
-
return null;
|
|
334
|
-
messages.push(message);
|
|
335
|
-
}
|
|
336
|
-
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
337
|
-
if (next === null)
|
|
338
|
-
return null;
|
|
339
|
-
return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
|
|
340
|
-
}
|
|
341
|
-
function historyAsks(input) {
|
|
342
|
-
const asked = record(input).conversations;
|
|
343
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
344
|
-
return null;
|
|
345
|
-
const asks = [];
|
|
346
|
-
for (const entry of asked) {
|
|
347
|
-
const conversationId = text(entry, 'conversation');
|
|
348
|
-
if (conversationId === undefined)
|
|
349
|
-
return null;
|
|
350
|
-
const afterValue = text(entry, 'after');
|
|
351
|
-
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
352
|
-
if (after === null)
|
|
353
|
-
return null;
|
|
354
|
-
asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
|
|
355
|
-
}
|
|
356
|
-
return asks;
|
|
357
|
-
}
|
|
358
|
-
async function historyAction(transport, route, input, name) {
|
|
359
|
-
const asks = historyAsks(input);
|
|
360
|
-
if (asks === null)
|
|
361
|
-
return malformed();
|
|
362
|
-
const histories = [];
|
|
363
|
-
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
364
|
-
const answer = await transport.door(route, {
|
|
365
|
-
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
366
|
-
limit: HISTORY_PAGE,
|
|
367
|
-
});
|
|
368
|
-
const outcome = actionOutcome(answer, name);
|
|
369
|
-
if (outcome.kind !== 'action')
|
|
370
|
-
return outcome;
|
|
371
|
-
const answered = record(outcome.result).histories;
|
|
372
|
-
if (!Array.isArray(answered))
|
|
373
|
-
return { kind: 'transport-uncertainty' };
|
|
374
|
-
for (const entry of answered) {
|
|
375
|
-
const page = historyPage(entry);
|
|
376
|
-
if (page === null)
|
|
377
|
-
return { kind: 'transport-uncertainty' };
|
|
378
|
-
histories.push(page);
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
const result = { histories };
|
|
382
|
-
return { kind: 'action', result };
|
|
77
|
+
const answered = actionOutcome(await transport.door(route, input), name, input);
|
|
78
|
+
const renamed = renamedHandle(answered);
|
|
79
|
+
if (renamed === null)
|
|
80
|
+
return answered;
|
|
81
|
+
const moved = movedPaths(input, ROOM_SELECTORS.get(name)?.roomPaths ?? [], renamed);
|
|
82
|
+
return actionOutcome(await transport.door(route, moved), name, moved);
|
|
383
83
|
}
|
package/dist/adapter.d.ts
CHANGED
|
@@ -5,6 +5,6 @@ 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
|
-
//# 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":"
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AA0BhC,OAAO,EAIL,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;AAcrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA0cpF"}
|