@agentshouse/mdruntime-adapter 0.1.0-c617f778a54ad → 0.1.0-c61811d76cd3c

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 (79) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +15 -6
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +197 -319
  5. package/dist/adapter.d.ts +1 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +308 -225
  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 +46 -18
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +264 -64
  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 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -0
  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 -44
  28. package/dist/read.d.ts +54 -48
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +209 -267
  31. package/dist/refusal.d.ts +8 -10
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +31 -18
  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 +1 -2
  49. package/dist/site.d.ts.map +1 -1
  50. package/dist/site.js +161 -108
  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 +14 -13
  55. package/dist/stream.d.ts.map +1 -1
  56. package/dist/stream.js +281 -149
  57. package/dist/transport.d.ts +131 -30
  58. package/dist/transport.d.ts.map +1 -1
  59. package/dist/transport.js +90 -9
  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 +1 -1
  67. package/dist/version.d.ts.map +1 -1
  68. package/dist/version.js +1 -1
  69. package/dist/write.d.ts +15 -12
  70. package/dist/write.d.ts.map +1 -1
  71. package/dist/write.js +222 -134
  72. package/package.json +11 -7
  73. package/AGENTS.md +0 -244
  74. package/dist/gather.d.ts +0 -3
  75. package/dist/gather.d.ts.map +0 -1
  76. package/dist/gather.js +0 -40
  77. package/dist/links.d.ts +0 -20
  78. package/dist/links.d.ts.map +0 -1
  79. 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 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,8 +1,17 @@
1
- import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents } from '@agentshouse/mdruntime';
1
+ import type { ActionDeclaration, ActionRequest, ActionResult } from '@agentshouse/mdruntime';
2
2
  import type { HouseDoorAnswer, HouseTransport } from './transport.js';
3
- 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 const HOUSE_RENAMED_UNTIL_2026_12_22: ReadonlyMap<string, string>;
12
+ export declare const HOUSE_REWRITTEN_UNTIL_2026_12_22: Rewrites;
13
+ export declare function rewrittenInTurn(...rewrites: readonly Rewrites[]): Rewrites;
4
14
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
5
- export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
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
15
+ export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
16
+ export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
17
+ export {};
@@ -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,EAGxB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAkBtE,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CASvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA4DD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAWjF;AAuLD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
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;AAEF,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAErE,CAAC;AAgCH,KAAK,QAAQ,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,OAAO,CAAC,CAAC;AAEjE,eAAO,MAAM,gCAAgC,EAAE,QAAgD,CAAC;AAEhG,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAkBrE,CAAC;AAsDH,eAAO,MAAM,gCAAgC,EAAE,QAmB7C,CAAC;AAEH,eAAO,MAAM,8BAA8B,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAYrE,CAAC;AAEH,eAAO,MAAM,gCAAgC,EAAE,QAe7C,CAAC;AAEH,wBAAgB,eAAe,CAAC,GAAG,QAAQ,EAAE,SAAS,QAAQ,EAAE,GAAG,QAAQ,CAQ1E;AAcD,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,46 +1,194 @@
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
- const CONVERSATION_ROUTES = new Map([
7
- ['conversation.create', '/door/conversations/create'],
8
- ['conversation.send', '/door/conversations/send'],
9
- ['conversation.answer', '/door/conversations/interaction/answer'],
10
- ['conversation.interrupt', '/door/conversations/interrupt'],
11
- ['conversation.kill', '/door/conversations/kill'],
12
- ['conversation.delete', '/door/conversations/delete'],
13
- ['conversation.history', '/door/conversations/history'],
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
+ export const HOUSE_RENAMED_UNTIL_2026_12_18 = new Map([
17
+ ['files/batch', 'update'],
14
18
  ]);
15
- export function houseConversationAgents(locator) {
16
- return { locator, type: 'house-agent', identity: 'agent', name: 'name' };
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;
40
+ return {
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
+ }),
48
+ };
49
+ }
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
+ ['agents/standing-answer/set', 'agent_update'],
63
+ ['agents/ask-afk/set', 'agent_update'],
64
+ ['environments/sign-in', 'environment_update'],
65
+ ['environments/rooms/set', 'environment_update'],
66
+ ['environments/login-code/create', 'environment_update'],
67
+ ['environments/login-code/create-reusable', 'environment_update'],
68
+ ['environments/login-code/cancel', 'environment_update'],
69
+ ]);
70
+ function held(input) {
71
+ return typeof input === 'object' && input !== null
72
+ ? { ...input }
73
+ : {};
74
+ }
75
+ function created(input) {
76
+ return { op: 'create', ...held(input) };
77
+ }
78
+ function uploaded(input) {
79
+ const { app_ref: app, ...files } = held(input);
80
+ return { op: 'publish', app, ...files };
81
+ }
82
+ function decided(op) {
83
+ return (input) => ({ op, ...held(input) });
84
+ }
85
+ function reusable(input) {
86
+ return { op: 'login_code_create', reusable: true, ...held(input) };
87
+ }
88
+ function zoned(input) {
89
+ const { browser, ...named } = held(input);
90
+ return { op: 'set', ...named, ...(browser === undefined ? {} : { if_unset: browser }) };
17
91
  }
92
+ function exported(input) {
93
+ const { room_refs: rooms, ...named } = held(input);
94
+ return { op: 'export', ...named, ...(rooms === undefined ? {} : { rooms }) };
95
+ }
96
+ function roomNamed(op) {
97
+ return (input) => {
98
+ const { room_ref: room, ...named } = held(input);
99
+ return { op, room, ...named };
100
+ };
101
+ }
102
+ function appNamed(op) {
103
+ return (input) => {
104
+ const { app_ref: app, ...named } = held(input);
105
+ return { op, app, ...named };
106
+ };
107
+ }
108
+ function askedAway(input) {
109
+ const { room_ref: room, afk, ...named } = held(input);
110
+ return { op: 'set', ...named, room, ask_afk: afk };
111
+ }
112
+ export const HOUSE_REWRITTEN_UNTIL_2026_12_21 = new Map([
113
+ ['apps/create', created],
114
+ ['apps/upload', uploaded],
115
+ ['shares/accept', decided('share_accept')],
116
+ ['shares/decline', decided('share_decline')],
117
+ ['shares/join-requests/approve', decided('join_request_approve')],
118
+ ['shares/join-requests/decline', decided('join_request_decline')],
119
+ ['rooms/ownership/offer', roomNamed('ownership_offer')],
120
+ ['rooms/ownership/accept', decided('ownership_accept')],
121
+ ['rooms/ownership/decline', decided('ownership_decline')],
122
+ ['rooms/instructions/follow', roomNamed('instructions_follow')],
123
+ ['agents/standing-answer/set', roomNamed('standing_answer_set')],
124
+ ['agents/ask-afk/set', askedAway],
125
+ ['environments/sign-in', decided('sign_in')],
126
+ ['environments/rooms/set', decided('set')],
127
+ ['environments/login-code/create', decided('login_code_create')],
128
+ ['environments/login-code/create-reusable', reusable],
129
+ ['environments/login-code/cancel', decided('login_code_cancel')],
130
+ ['update', withCurrentOps],
131
+ ]);
132
+ export const HOUSE_RENAMED_UNTIL_2026_12_22 = new Map([
133
+ ['account/security/browsers/revoke', 'account_update'],
134
+ ['account/security/browsers/revoke-others', 'account_update'],
135
+ ['account/time-zone/set', 'account_update'],
136
+ ['account/who-can-add-me/set', 'account_update'],
137
+ ['clients/revoke', 'account_update'],
138
+ ['clients/rooms/set', 'account_update'],
139
+ ['storage/archive', 'account_update'],
140
+ ['billing/subscribe', 'account_update'],
141
+ ['billing/top-up', 'account_update'],
142
+ ['billing/manage', 'account_update'],
143
+ ['apps/features/set', 'app_update'],
144
+ ]);
145
+ export const HOUSE_REWRITTEN_UNTIL_2026_12_22 = new Map([
146
+ ['account/security/browsers/revoke', decided('browser_revoke')],
147
+ [
148
+ 'account/security/browsers/revoke-others',
149
+ (input) => ({ op: 'browser_revoke', ...held(input), others: true }),
150
+ ],
151
+ ['account/time-zone/set', zoned],
152
+ ['account/who-can-add-me/set', decided('set')],
153
+ ['clients/revoke', decided('client_revoke')],
154
+ ['clients/rooms/set', decided('client_rooms_set')],
155
+ ['storage/archive', exported],
156
+ ['billing/subscribe', decided('subscribe')],
157
+ ['billing/top-up', decided('top_up')],
158
+ ['billing/manage', decided('billing_manage')],
159
+ ['apps/features/set', appNamed('feature_set')],
160
+ ]);
161
+ export function rewrittenInTurn(...rewrites) {
162
+ const names = new Set(rewrites.flatMap((each) => [...each.keys()]));
163
+ return new Map([...names].map((name) => [
164
+ name,
165
+ (input) => rewrites.reduce((held, each) => each.get(name)?.(held) ?? held, input),
166
+ ]));
167
+ }
168
+ const ROOM_SELECTORS = new Map([
169
+ ['update', { room: 'changes.room', roomPaths: ['changes.path', 'changes.to', 'paths', 'mount'] }],
170
+ ['sharing', { room: 'room' }],
171
+ ['sharing_update', { room: 'room' }],
172
+ ['inbox_update', { room: 'room', roomPaths: ['path'] }],
173
+ ['agent', { room: 'room' }],
174
+ ['agent_update', { room: 'room' }],
175
+ ['environment', { room: 'room' }],
176
+ ]);
18
177
  export function declaredActions(routes) {
19
- const mapped = new Map([...CONVERSATION_ROUTES].map(([name, route]) => [route.slice('/door/'.length), name]));
20
- return routes.map((route) => ({
21
- name: mapped.get(route) ?? route,
178
+ return routes.map((name) => ({
179
+ name,
22
180
  inputShape: {},
23
181
  resultKind: 'house',
182
+ ...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
24
183
  }));
25
184
  }
26
185
  export function houseAction(transport, request) {
27
- if (request.name === 'conversation.send')
28
- return sendAction(transport, request.input);
29
- if (request.name === 'conversation.history')
30
- return historyAction(transport, request.input);
31
- if (request.name === 'attachments/upload')
32
- return attachAction(transport, request.input);
33
- if (request.name === 'attachments/get')
34
- return openAction(transport, request.input);
35
186
  const route = routeOf(request.name);
36
187
  if (route === null)
37
188
  return Promise.resolve(malformed());
38
189
  return carry(transport, route, request.name, request.input);
39
190
  }
40
191
  function routeOf(name) {
41
- const mapped = CONVERSATION_ROUTES.get(name);
42
- if (mapped !== undefined)
43
- return mapped;
44
192
  const parts = name.split('/');
45
193
  if (parts.some((part) => part === '.' || part === '..'))
46
194
  return null;
@@ -51,307 +199,37 @@ function routeOf(name) {
51
199
  return null;
52
200
  }
53
201
  }
54
- function record(value) {
55
- return typeof value === 'object' && value !== null ? value : {};
56
- }
57
- function text(value, name) {
58
- const held = record(value)[name];
59
- return typeof held === 'string' ? held : undefined;
60
- }
61
- function operationId(input) {
62
- return text(input, 'operation_id') ?? changeBatchIdentity();
63
- }
64
202
  function malformed() {
65
- return { kind: 'rejected', code: 'invalid_request', fields: {} };
203
+ return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
66
204
  }
67
- function bodyOf(name, input) {
68
- if (name === 'conversation.create') {
69
- return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
70
- }
71
- if (name === 'conversation.interrupt' ||
72
- name === 'conversation.kill' ||
73
- name === 'conversation.delete') {
74
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
75
- }
76
- if (name === 'conversation.answer') {
77
- const nested = record(record(input).answer);
78
- return {
79
- conversation_id: text(input, 'conversation'),
80
- operation_id: operationId(input),
81
- interaction_id: text(nested, 'interaction_id'),
82
- response: nested.response,
83
- };
84
- }
85
- return input;
205
+ function unimplemented(name) {
206
+ return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
86
207
  }
87
- function withTurn(body) {
88
- const held = record(body);
89
- const turn = text(held, 'message_id');
90
- return turn === undefined ? body : { ...held, turn };
208
+ function numbered(input) {
209
+ return typeof input?.operation_id === 'string';
91
210
  }
92
- export function actionOutcome(answer, name) {
211
+ export function actionOutcome(answer, name, input) {
93
212
  if (answer.status === 401)
94
213
  return { kind: 'revoked-authorization' };
95
214
  const refusal = doorRefusal(answer.body);
215
+ if (refusal?.code === 'operation_contended' && numbered(input))
216
+ return refusedFor(refusal);
96
217
  if (refusal !== null) {
97
- return { kind: 'rejected', code: refusal.code, fields: refusal.fields };
218
+ const reset = resetOf(refusal);
219
+ return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
98
220
  }
99
221
  if (answer.status === 404)
100
- return { kind: 'rejected', code: 'action-unimplemented', fields: { name } };
101
- if (answer.status === 0 || answer.status >= 400)
102
- return { kind: 'transport-uncertainty' };
103
- if (name === 'conversation.send')
104
- return { kind: 'action', result: withTurn(answer.body) };
222
+ return unimplemented(name);
223
+ if (answer.status === 0 || answer.status >= 400) {
224
+ return answeredFailure(answer.status, answer.body);
225
+ }
105
226
  return { kind: 'action', result: answer.body };
106
227
  }
107
228
  async function carry(transport, route, name, input) {
108
- const answer = await transport.door(route, bodyOf(name, input));
109
- return actionOutcome(answer, name);
110
- }
111
- function sendFile(entry) {
112
- const file = record(entry);
113
- const name = text(file, 'name');
114
- const bytes = file.byteLength;
115
- const sha256 = text(file, 'contentHash');
116
- if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
117
- return null;
118
- const mediaType = text(file, 'mediaType');
119
- const width = file.width;
120
- const height = file.height;
121
- return {
122
- name,
123
- media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
124
- bytes,
125
- sha256,
126
- ...(typeof width === 'number' && typeof height === 'number'
127
- ? { dimensions: { width, height } }
128
- : {}),
129
- };
130
- }
131
- function sendFiles(input) {
132
- const files = record(input).files;
133
- if (files === undefined)
134
- return [];
135
- if (!Array.isArray(files))
136
- return null;
137
- const declared = [];
138
- for (const entry of files) {
139
- const file = sendFile(entry);
140
- if (file === null)
141
- return null;
142
- declared.push(file);
143
- }
144
- return declared;
145
- }
146
- function sendBody(input) {
147
- const files = sendFiles(input);
148
- if (files === null)
149
- return null;
150
- const textValue = text(input, 'text');
151
- return {
152
- conversation_id: text(input, 'conversation'),
153
- operation_id: operationId(input),
154
- ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
155
- ...(files.length === 0 ? {} : { files }),
156
- };
157
- }
158
- async function fileBytes(file) {
159
- const blob = record(file).blob;
160
- if (blob === undefined || typeof blob !== 'object' || blob === null)
161
- return null;
162
- if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
163
- return null;
164
- return new Uint8Array(await blob.arrayBuffer());
165
- }
166
- function delivered(answer, name) {
167
- return answer.status === 200 ? null : actionOutcome(answer, name);
168
- }
169
- function uploadGrant(entry) {
170
- if (!('upload' in record(entry)))
171
- return 'absent';
172
- const upload = record(record(entry).upload);
173
- if (upload.method !== 'POST')
174
- return null;
175
- if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
176
- return null;
177
- return { method: 'POST', operation: upload.operation, url: upload.url };
178
- }
179
- async function uploadOriginals(transport, input, result) {
180
- const originals = record(result).originals;
181
- if (!Array.isArray(originals) || originals.length === 0)
182
- return null;
183
- const files = Array.isArray(record(input).files) ? record(input).files : [];
184
- for (const [index, entry] of originals.entries()) {
185
- const grant = uploadGrant(entry);
186
- if (grant === 'absent')
187
- continue;
188
- if (grant === null)
189
- return malformed();
190
- const bytes = index < files.length ? await fileBytes(files[index]) : null;
191
- if (bytes === null) {
192
- return { kind: 'rejected', code: 'conversation_original_descriptor_required', fields: {} };
193
- }
194
- const failed = delivered(await transport.transfer({
195
- act: 'conversation_original_upload',
196
- method: 'POST',
197
- url: grant.url,
198
- answer: 'json',
199
- body: bytes,
200
- operation: grant.operation,
201
- }), 'conversation.send');
202
- if (failed !== null)
203
- return failed;
204
- }
205
- return null;
206
- }
207
- async function attachAction(transport, input) {
208
- const { blob, ...descriptor } = record(input);
209
- const bytes = await fileBytes({ blob });
210
- if (bytes === null)
211
- return malformed();
212
- const answer = await transport.door('/door/attachments/upload', descriptor);
213
- const outcome = actionOutcome(answer, 'attachments/upload');
214
- if (outcome.kind !== 'action')
215
- return outcome;
216
- const grant = uploadGrant(outcome.result);
217
- if (grant === 'absent')
218
- return outcome;
219
- if (grant === null)
220
- return malformed();
221
- const stored = await transport.transfer({
222
- act: 'original_upload',
223
- method: 'POST',
224
- url: grant.url,
225
- answer: 'json',
226
- body: bytes,
227
- operation: grant.operation,
228
- });
229
- return delivered(stored, 'attachments/upload') ?? { kind: 'action', result: stored.body };
230
- }
231
- async function openAction(transport, input) {
232
- const answer = await transport.door('/door/attachments/get', input);
233
- const outcome = actionOutcome(answer, 'attachments/get');
234
- if (outcome.kind !== 'action')
235
- return outcome;
236
- const { download, ...opened } = record(outcome.result);
237
- if (download === undefined)
238
- return outcome;
239
- const grant = record(download);
240
- if (grant.method !== 'GET' || typeof grant.url !== 'string')
241
- return malformed();
242
- const read = await transport.transfer({
243
- act: 'original_download',
244
- method: 'GET',
245
- url: grant.url,
246
- answer: 'bytes',
247
- });
248
- const failed = delivered(read, 'attachments/get');
249
- if (failed !== null)
250
- return failed;
251
- if (!(read.body instanceof Blob))
252
- return { kind: 'transport-uncertainty' };
253
- return { kind: 'action', result: { ...opened, blob: read.body } };
254
- }
255
- async function sendAction(transport, input) {
256
- const body = sendBody(input);
257
- if (body === null)
258
- return malformed();
259
- const answer = await transport.door('/door/conversations/send', body);
260
- const outcome = actionOutcome(answer, 'conversation.send');
261
- if (outcome.kind !== 'action')
262
- return outcome;
263
- const uploaded = await uploadOriginals(transport, input, outcome.result);
264
- if (uploaded !== null)
265
- return uploaded;
266
- return outcome;
267
- }
268
- function historyCursor(value) {
269
- const acceptedAt = text(value, 'accepted_at');
270
- const messageId = text(value, 'message_id');
271
- if (acceptedAt === undefined || messageId === undefined)
272
- return null;
273
- return { accepted_at: acceptedAt, message_id: messageId };
274
- }
275
- function position(cursor) {
276
- return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
277
- }
278
- function positionCursor(value) {
279
- try {
280
- return historyCursor(JSON.parse(value));
281
- }
282
- catch {
283
- return null;
284
- }
285
- }
286
- export function acceptedMessage(entry) {
287
- const cursor = historyCursor(entry);
288
- if (cursor === null)
289
- return null;
290
- return {
291
- identity: cursor.message_id,
292
- turn: text(entry, 'turn_id') ?? cursor.message_id,
293
- position: position(cursor),
294
- text: text(entry, 'text') ?? '',
295
- message: structuredClone(entry),
296
- };
297
- }
298
- function historyPage(entry) {
299
- const held = record(entry);
300
- const conversation = text(held, 'conversation_id');
301
- if (conversation === undefined || !Array.isArray(held.messages))
302
- return null;
303
- const messages = [];
304
- for (const one of held.messages) {
305
- const message = acceptedMessage(one);
306
- if (message === null)
307
- return null;
308
- messages.push(message);
309
- }
310
- const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
311
- if (next === null)
312
- return null;
313
- return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
314
- }
315
- function historyAsks(input) {
316
- const asked = record(input).conversations;
317
- if (!Array.isArray(asked) || asked.length === 0)
318
- return null;
319
- const asks = [];
320
- for (const entry of asked) {
321
- const conversationId = text(entry, 'conversation');
322
- if (conversationId === undefined)
323
- return null;
324
- const afterValue = text(entry, 'after');
325
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
326
- if (after === null)
327
- return null;
328
- asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
329
- }
330
- return asks;
331
- }
332
- async function historyAction(transport, input) {
333
- const asks = historyAsks(input);
334
- if (asks === null)
335
- return malformed();
336
- const histories = [];
337
- for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
338
- const answer = await transport.door('/door/conversations/history', {
339
- conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
340
- limit: HISTORY_PAGE,
341
- });
342
- const outcome = actionOutcome(answer, 'conversation.history');
343
- if (outcome.kind !== 'action')
344
- return outcome;
345
- const answered = record(outcome.result).histories;
346
- if (!Array.isArray(answered))
347
- return { kind: 'transport-uncertainty' };
348
- for (const entry of answered) {
349
- const page = historyPage(entry);
350
- if (page === null)
351
- return { kind: 'transport-uncertainty' };
352
- histories.push(page);
353
- }
354
- }
355
- const result = { histories };
356
- return { kind: 'action', result };
229
+ const answered = actionOutcome(await transport.door(route, input), name, input);
230
+ const renamed = renamedHandle(answered);
231
+ if (renamed === null)
232
+ return answered;
233
+ const moved = movedPaths(input, ROOM_SELECTORS.get(name)?.roomPaths ?? [], renamed);
234
+ return actionOutcome(await transport.door(route, moved), name, moved);
357
235
  }
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
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,OAAO,EACP,aAAa,EAWd,MAAM,wBAAwB,CAAC;AAqChC,OAAO,EAOL,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,CAAA;CAAE,CAAC;AAsBjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAuWpF"}
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;AAqChC,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,CAmdpF"}