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