@agentshouse/mdruntime-adapter 0.1.0-cf6a7cf003c4b → 0.1.0-cf768be36486a

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