@agentshouse/mdruntime-adapter 0.1.0-c86c633e372c4 → 0.1.0-c87013e8a4dd8

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