@agentshouse/mdruntime-adapter 0.1.0-c17fae3d012d0 → 0.1.0-c18e9b633b5bc
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 +5 -5
- package/dist/actions.d.ts +10 -6
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +69 -324
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +310 -264
- 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 +48 -28
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +268 -87
- 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 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +8 -19
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +43 -39
- package/dist/read.d.ts +55 -48
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +208 -267
- package/dist/refusal.d.ts +10 -13
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +54 -24
- package/dist/renamed.d.ts +10 -0
- package/dist/renamed.d.ts.map +1 -0
- package/dist/renamed.js +29 -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 +17 -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 +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +165 -145
- 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 +17 -12
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +327 -145
- package/dist/transport.d.ts +156 -28
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +95 -10
- 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 +2 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +10 -1
- package/dist/write.d.ts +18 -4
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +182 -72
- package/package.json +11 -7
- package/AGENTS.md +0 -207
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -40
- package/dist/links.d.ts +0 -12
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -66
package/README.md
CHANGED
|
@@ -19,13 +19,13 @@ import { serveMdRuntime } from '@agentshouse/mdruntime/host';
|
|
|
19
19
|
import { createAgentsHouseAdapter } from '@agentshouse/mdruntime-adapter';
|
|
20
20
|
|
|
21
21
|
const adapter = createAgentsHouseAdapter({ transport, authorize });
|
|
22
|
-
const host = serveMdRuntime({ adapter, shell
|
|
23
|
-
host.attach(port, 'my-app');
|
|
22
|
+
const host = serveMdRuntime({ adapter, shell });
|
|
23
|
+
host.attach(port, { app: 'my-app' });
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
App code never imports this package; it reaches the Runtime only through
|
|
27
|
-
|
|
28
|
-
|
|
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 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,8 +1,12 @@
|
|
|
1
|
-
import
|
|
1
|
+
import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
3
|
-
export
|
|
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[];
|
|
6
|
+
export declare const HOUSE_RENAMED_UNTIL_2026_12_18: ReadonlyMap<string, string>;
|
|
7
|
+
export declare const HOUSE_REWRITTEN_UNTIL_2026_12_19: ReadonlyMap<string, (input: unknown) => unknown>;
|
|
8
|
+
export declare const HOUSE_RENAMED_UNTIL_2026_12_21: ReadonlyMap<string, string>;
|
|
9
|
+
export declare const HOUSE_REWRITTEN_UNTIL_2026_12_21: ReadonlyMap<string, (input: unknown) => unknown>;
|
|
4
10
|
export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
|
|
5
|
-
export declare function houseAction(transport:
|
|
6
|
-
export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
|
|
7
|
-
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
8
|
-
//# sourceMappingURL=actions.d.ts.map
|
|
11
|
+
export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
|
|
12
|
+
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,EAKhD,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAErE,CAAC;AAQH,eAAO,MAAM,gCAAgC,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CACvD,CAAC;AAExC,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAGrE,CAAC;AAiBH,eAAO,MAAM,gCAAgC,EAAE,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAI1F,CAAC;AAQL,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,50 +1,65 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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/security/read',
|
|
6
|
+
'billing/read',
|
|
7
|
+
'clients/last-use/list',
|
|
8
|
+
];
|
|
9
|
+
export const HOUSE_LEADING_READS = [
|
|
10
|
+
'app.list',
|
|
11
|
+
'apps/list',
|
|
12
|
+
'sites/list',
|
|
13
|
+
'rooms/members/list',
|
|
14
|
+
];
|
|
15
|
+
export const HOUSE_RENAMED_UNTIL_2026_12_18 = new Map([
|
|
16
|
+
['files/batch', 'update'],
|
|
17
|
+
]);
|
|
18
|
+
function withoutRoomRef(input) {
|
|
19
|
+
if (typeof input !== 'object' || input === null || !('room_ref' in input))
|
|
20
|
+
return input;
|
|
21
|
+
const { room_ref: _room, ...paths } = input;
|
|
22
|
+
return paths;
|
|
23
|
+
}
|
|
24
|
+
export const HOUSE_REWRITTEN_UNTIL_2026_12_19 = new Map([['update', withoutRoomRef]]);
|
|
25
|
+
export const HOUSE_RENAMED_UNTIL_2026_12_21 = new Map([
|
|
26
|
+
['apps/create', 'app_update'],
|
|
27
|
+
['apps/upload', 'app_update'],
|
|
28
|
+
]);
|
|
29
|
+
function held(input) {
|
|
30
|
+
return typeof input === 'object' && input !== null
|
|
31
|
+
? { ...input }
|
|
32
|
+
: {};
|
|
33
|
+
}
|
|
34
|
+
function created(input) {
|
|
35
|
+
return { op: 'create', ...held(input) };
|
|
36
|
+
}
|
|
37
|
+
function uploaded(input) {
|
|
38
|
+
const { app_ref: app, ...files } = held(input);
|
|
39
|
+
return { op: 'publish', app, ...files };
|
|
40
|
+
}
|
|
41
|
+
export const HOUSE_REWRITTEN_UNTIL_2026_12_21 = new Map([
|
|
42
|
+
['apps/create', created],
|
|
43
|
+
['apps/upload', uploaded],
|
|
44
|
+
]);
|
|
45
|
+
const ROOM_SELECTORS = new Map([
|
|
46
|
+
['update', { room: 'changes.room', roomPaths: ['changes.path', 'changes.to', 'paths', 'mount'] }],
|
|
15
47
|
]);
|
|
16
|
-
export const HOUSE_CONVERSATION_CARDS = {
|
|
17
|
-
locator: PRIVATE_LOCATOR,
|
|
18
|
-
type: 'house-conversation',
|
|
19
|
-
identity: 'conversation',
|
|
20
|
-
agent: 'agent',
|
|
21
|
-
};
|
|
22
48
|
export function declaredActions(routes) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
name: mapped.get(route) ?? route,
|
|
49
|
+
return routes.map((name) => ({
|
|
50
|
+
name,
|
|
26
51
|
inputShape: {},
|
|
27
52
|
resultKind: 'house',
|
|
53
|
+
...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
|
|
28
54
|
}));
|
|
29
55
|
}
|
|
30
56
|
export function houseAction(transport, request) {
|
|
31
|
-
if (request.name === 'conversation.send')
|
|
32
|
-
return sendAction(transport, request.input);
|
|
33
|
-
if (request.name === 'conversation.history')
|
|
34
|
-
return historyAction(transport, request.input);
|
|
35
|
-
if (request.name === 'attachments/upload')
|
|
36
|
-
return attachAction(transport, request.input);
|
|
37
|
-
if (request.name === 'attachments/get')
|
|
38
|
-
return openAction(transport, request.input);
|
|
39
57
|
const route = routeOf(request.name);
|
|
40
58
|
if (route === null)
|
|
41
59
|
return Promise.resolve(malformed());
|
|
42
60
|
return carry(transport, route, request.name, request.input);
|
|
43
61
|
}
|
|
44
62
|
function routeOf(name) {
|
|
45
|
-
const mapped = CONVERSATION_ROUTES.get(name);
|
|
46
|
-
if (mapped !== undefined)
|
|
47
|
-
return mapped;
|
|
48
63
|
const parts = name.split('/');
|
|
49
64
|
if (parts.some((part) => part === '.' || part === '..'))
|
|
50
65
|
return null;
|
|
@@ -55,307 +70,37 @@ function routeOf(name) {
|
|
|
55
70
|
return null;
|
|
56
71
|
}
|
|
57
72
|
}
|
|
58
|
-
function record(value) {
|
|
59
|
-
return typeof value === 'object' && value !== null ? value : {};
|
|
60
|
-
}
|
|
61
|
-
function text(value, name) {
|
|
62
|
-
const held = record(value)[name];
|
|
63
|
-
return typeof held === 'string' ? held : undefined;
|
|
64
|
-
}
|
|
65
|
-
function operationId(input) {
|
|
66
|
-
return text(input, 'operation_id') ?? changeBatchIdentity();
|
|
67
|
-
}
|
|
68
73
|
function malformed() {
|
|
69
|
-
return { kind: 'rejected', code: 'invalid_request', fields: {} };
|
|
74
|
+
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
70
75
|
}
|
|
71
|
-
function
|
|
72
|
-
|
|
73
|
-
return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
|
|
74
|
-
}
|
|
75
|
-
if (name === 'conversation.interrupt' ||
|
|
76
|
-
name === 'conversation.kill' ||
|
|
77
|
-
name === 'conversation.delete') {
|
|
78
|
-
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
79
|
-
}
|
|
80
|
-
if (name === 'conversation.answer') {
|
|
81
|
-
const nested = record(record(input).answer);
|
|
82
|
-
return {
|
|
83
|
-
conversation_id: text(input, 'conversation'),
|
|
84
|
-
operation_id: operationId(input),
|
|
85
|
-
interaction_id: text(nested, 'interaction_id'),
|
|
86
|
-
response: nested.response,
|
|
87
|
-
};
|
|
88
|
-
}
|
|
89
|
-
return input;
|
|
76
|
+
function unimplemented(name) {
|
|
77
|
+
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
90
78
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
const turn = text(held, 'message_id');
|
|
94
|
-
return turn === undefined ? body : { ...held, turn };
|
|
79
|
+
function numbered(input) {
|
|
80
|
+
return typeof input?.operation_id === 'string';
|
|
95
81
|
}
|
|
96
|
-
export function actionOutcome(answer, name) {
|
|
82
|
+
export function actionOutcome(answer, name, input) {
|
|
97
83
|
if (answer.status === 401)
|
|
98
84
|
return { kind: 'revoked-authorization' };
|
|
99
85
|
const refusal = doorRefusal(answer.body);
|
|
86
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
87
|
+
return refusedFor(refusal);
|
|
100
88
|
if (refusal !== null) {
|
|
101
|
-
|
|
89
|
+
const reset = resetOf(refusal);
|
|
90
|
+
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
102
91
|
}
|
|
103
92
|
if (answer.status === 404)
|
|
104
|
-
return
|
|
105
|
-
if (answer.status === 0 || answer.status >= 400)
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
return { kind: 'action', result: withTurn(answer.body) };
|
|
93
|
+
return unimplemented(name);
|
|
94
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
95
|
+
return answeredFailure(answer.status, answer.body);
|
|
96
|
+
}
|
|
109
97
|
return { kind: 'action', result: answer.body };
|
|
110
98
|
}
|
|
111
99
|
async function carry(transport, route, name, input) {
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
const bytes = file.byteLength;
|
|
119
|
-
const sha256 = text(file, 'contentHash');
|
|
120
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
|
|
121
|
-
return null;
|
|
122
|
-
const mediaType = text(file, 'mediaType');
|
|
123
|
-
const width = file.width;
|
|
124
|
-
const height = file.height;
|
|
125
|
-
return {
|
|
126
|
-
name,
|
|
127
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
128
|
-
bytes,
|
|
129
|
-
sha256,
|
|
130
|
-
...(typeof width === 'number' && typeof height === 'number'
|
|
131
|
-
? { dimensions: { width, height } }
|
|
132
|
-
: {}),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
function sendFiles(input) {
|
|
136
|
-
const files = record(input).files;
|
|
137
|
-
if (files === undefined)
|
|
138
|
-
return [];
|
|
139
|
-
if (!Array.isArray(files))
|
|
140
|
-
return null;
|
|
141
|
-
const declared = [];
|
|
142
|
-
for (const entry of files) {
|
|
143
|
-
const file = sendFile(entry);
|
|
144
|
-
if (file === null)
|
|
145
|
-
return null;
|
|
146
|
-
declared.push(file);
|
|
147
|
-
}
|
|
148
|
-
return declared;
|
|
149
|
-
}
|
|
150
|
-
function sendBody(input) {
|
|
151
|
-
const files = sendFiles(input);
|
|
152
|
-
if (files === null)
|
|
153
|
-
return null;
|
|
154
|
-
const textValue = text(input, 'text');
|
|
155
|
-
return {
|
|
156
|
-
conversation_id: text(input, 'conversation'),
|
|
157
|
-
operation_id: operationId(input),
|
|
158
|
-
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
159
|
-
...(files.length === 0 ? {} : { files }),
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
async function fileBytes(file) {
|
|
163
|
-
const blob = record(file).blob;
|
|
164
|
-
if (blob === undefined || typeof blob !== 'object' || blob === null)
|
|
165
|
-
return null;
|
|
166
|
-
if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
|
|
167
|
-
return null;
|
|
168
|
-
return new Uint8Array(await blob.arrayBuffer());
|
|
169
|
-
}
|
|
170
|
-
function delivered(answer, name) {
|
|
171
|
-
return answer.status === 200 ? null : actionOutcome(answer, name);
|
|
172
|
-
}
|
|
173
|
-
function uploadGrant(entry) {
|
|
174
|
-
if (!('upload' in record(entry)))
|
|
175
|
-
return 'absent';
|
|
176
|
-
const upload = record(record(entry).upload);
|
|
177
|
-
if (upload.method !== 'POST')
|
|
178
|
-
return null;
|
|
179
|
-
if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
|
|
180
|
-
return null;
|
|
181
|
-
return { method: 'POST', operation: upload.operation, url: upload.url };
|
|
182
|
-
}
|
|
183
|
-
async function uploadOriginals(transport, input, result) {
|
|
184
|
-
const originals = record(result).originals;
|
|
185
|
-
if (!Array.isArray(originals) || originals.length === 0)
|
|
186
|
-
return null;
|
|
187
|
-
const files = Array.isArray(record(input).files) ? record(input).files : [];
|
|
188
|
-
for (const [index, entry] of originals.entries()) {
|
|
189
|
-
const grant = uploadGrant(entry);
|
|
190
|
-
if (grant === 'absent')
|
|
191
|
-
continue;
|
|
192
|
-
if (grant === null)
|
|
193
|
-
return malformed();
|
|
194
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
195
|
-
if (bytes === null) {
|
|
196
|
-
return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };
|
|
197
|
-
}
|
|
198
|
-
const failed = delivered(await transport.transfer({
|
|
199
|
-
act: 'conversation_original_upload',
|
|
200
|
-
method: 'POST',
|
|
201
|
-
url: grant.url,
|
|
202
|
-
answer: 'json',
|
|
203
|
-
body: bytes,
|
|
204
|
-
operation: grant.operation,
|
|
205
|
-
}), 'conversation.send');
|
|
206
|
-
if (failed !== null)
|
|
207
|
-
return failed;
|
|
208
|
-
}
|
|
209
|
-
return null;
|
|
210
|
-
}
|
|
211
|
-
async function attachAction(transport, input) {
|
|
212
|
-
const { blob, ...descriptor } = record(input);
|
|
213
|
-
const bytes = await fileBytes({ blob });
|
|
214
|
-
if (bytes === null)
|
|
215
|
-
return malformed();
|
|
216
|
-
const answer = await transport.door('/door/attachments/upload', descriptor);
|
|
217
|
-
const outcome = actionOutcome(answer, 'attachments/upload');
|
|
218
|
-
if (outcome.kind !== 'action')
|
|
219
|
-
return outcome;
|
|
220
|
-
const grant = uploadGrant(outcome.result);
|
|
221
|
-
if (grant === 'absent')
|
|
222
|
-
return outcome;
|
|
223
|
-
if (grant === null)
|
|
224
|
-
return malformed();
|
|
225
|
-
const stored = await transport.transfer({
|
|
226
|
-
act: 'original_upload',
|
|
227
|
-
method: 'POST',
|
|
228
|
-
url: grant.url,
|
|
229
|
-
answer: 'json',
|
|
230
|
-
body: bytes,
|
|
231
|
-
operation: grant.operation,
|
|
232
|
-
});
|
|
233
|
-
return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };
|
|
234
|
-
}
|
|
235
|
-
async function openAction(transport, input) {
|
|
236
|
-
const answer = await transport.door('/door/attachments/get', input);
|
|
237
|
-
const outcome = actionOutcome(answer, 'attachments/get');
|
|
238
|
-
if (outcome.kind !== 'action')
|
|
239
|
-
return outcome;
|
|
240
|
-
const { download, ...opened } = record(outcome.result);
|
|
241
|
-
if (download === undefined)
|
|
242
|
-
return outcome;
|
|
243
|
-
const grant = record(download);
|
|
244
|
-
if (grant.method !== 'GET' || typeof grant.url !== 'string')
|
|
245
|
-
return malformed();
|
|
246
|
-
const read = await transport.transfer({
|
|
247
|
-
act: 'original_download',
|
|
248
|
-
method: 'GET',
|
|
249
|
-
url: grant.url,
|
|
250
|
-
answer: 'bytes',
|
|
251
|
-
});
|
|
252
|
-
const failed = delivered(read, 'attachments/get');
|
|
253
|
-
if (failed !== null)
|
|
254
|
-
return failed;
|
|
255
|
-
if (!(read.body instanceof Blob))
|
|
256
|
-
return { kind: 'transport-uncertainty' };
|
|
257
|
-
return { kind: 'action', result: { ...opened, blob: read.body } };
|
|
258
|
-
}
|
|
259
|
-
async function sendAction(transport, input) {
|
|
260
|
-
const body = sendBody(input);
|
|
261
|
-
if (body === null)
|
|
262
|
-
return malformed();
|
|
263
|
-
const answer = await transport.door('/door/conversations/send', body);
|
|
264
|
-
const outcome = actionOutcome(answer, 'conversation.send');
|
|
265
|
-
if (outcome.kind !== 'action')
|
|
266
|
-
return outcome;
|
|
267
|
-
const uploaded = await uploadOriginals(transport, input, outcome.result);
|
|
268
|
-
if (uploaded !== null)
|
|
269
|
-
return uploaded;
|
|
270
|
-
return outcome;
|
|
271
|
-
}
|
|
272
|
-
function historyCursor(value) {
|
|
273
|
-
const acceptedAt = text(value, 'accepted_at');
|
|
274
|
-
const messageId = text(value, 'message_id');
|
|
275
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
276
|
-
return null;
|
|
277
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
278
|
-
}
|
|
279
|
-
function position(cursor) {
|
|
280
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
281
|
-
}
|
|
282
|
-
function positionCursor(value) {
|
|
283
|
-
try {
|
|
284
|
-
return historyCursor(JSON.parse(value));
|
|
285
|
-
}
|
|
286
|
-
catch {
|
|
287
|
-
return null;
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
export function acceptedMessage(entry) {
|
|
291
|
-
const cursor = historyCursor(entry);
|
|
292
|
-
if (cursor === null)
|
|
293
|
-
return null;
|
|
294
|
-
return {
|
|
295
|
-
identity: cursor.message_id,
|
|
296
|
-
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
297
|
-
position: position(cursor),
|
|
298
|
-
text: text(entry, 'text') ?? '',
|
|
299
|
-
message: structuredClone(entry),
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
function historyPage(entry) {
|
|
303
|
-
const held = record(entry);
|
|
304
|
-
const conversation = text(held, 'conversation_id');
|
|
305
|
-
if (conversation === undefined || !Array.isArray(held.messages))
|
|
306
|
-
return null;
|
|
307
|
-
const messages = [];
|
|
308
|
-
for (const one of held.messages) {
|
|
309
|
-
const message = acceptedMessage(one);
|
|
310
|
-
if (message === null)
|
|
311
|
-
return null;
|
|
312
|
-
messages.push(message);
|
|
313
|
-
}
|
|
314
|
-
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
315
|
-
if (next === null)
|
|
316
|
-
return null;
|
|
317
|
-
return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
|
|
318
|
-
}
|
|
319
|
-
function historyAsks(input) {
|
|
320
|
-
const asked = record(input).conversations;
|
|
321
|
-
if (!Array.isArray(asked) || asked.length === 0)
|
|
322
|
-
return null;
|
|
323
|
-
const asks = [];
|
|
324
|
-
for (const entry of asked) {
|
|
325
|
-
const conversationId = text(entry, 'conversation');
|
|
326
|
-
if (conversationId === undefined)
|
|
327
|
-
return null;
|
|
328
|
-
const afterValue = text(entry, 'after');
|
|
329
|
-
const after = afterValue === undefined ? undefined : positionCursor(afterValue);
|
|
330
|
-
if (after === null)
|
|
331
|
-
return null;
|
|
332
|
-
asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
|
|
333
|
-
}
|
|
334
|
-
return asks;
|
|
335
|
-
}
|
|
336
|
-
async function historyAction(transport, input) {
|
|
337
|
-
const asks = historyAsks(input);
|
|
338
|
-
if (asks === null)
|
|
339
|
-
return malformed();
|
|
340
|
-
const histories = [];
|
|
341
|
-
for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
|
|
342
|
-
const answer = await transport.door('/door/conversations/history', {
|
|
343
|
-
conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
|
|
344
|
-
limit: HISTORY_PAGE,
|
|
345
|
-
});
|
|
346
|
-
const outcome = actionOutcome(answer, 'conversation.history');
|
|
347
|
-
if (outcome.kind !== 'action')
|
|
348
|
-
return outcome;
|
|
349
|
-
const answered = record(outcome.result).histories;
|
|
350
|
-
if (!Array.isArray(answered))
|
|
351
|
-
return { kind: 'transport-uncertainty' };
|
|
352
|
-
for (const entry of answered) {
|
|
353
|
-
const page = historyPage(entry);
|
|
354
|
-
if (page === null)
|
|
355
|
-
return { kind: 'transport-uncertainty' };
|
|
356
|
-
histories.push(page);
|
|
357
|
-
}
|
|
358
|
-
}
|
|
359
|
-
const result = { histories };
|
|
360
|
-
return { kind: 'action', result };
|
|
100
|
+
const answered = actionOutcome(await transport.door(route, input), name, input);
|
|
101
|
+
const renamed = renamedHandle(answered);
|
|
102
|
+
if (renamed === null)
|
|
103
|
+
return answered;
|
|
104
|
+
const moved = movedPaths(input, renamed);
|
|
105
|
+
return actionOutcome(await transport.door(route, moved), name, moved);
|
|
361
106
|
}
|
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;AAkChC,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,CA2cpF"}
|