@agentshouse/mdruntime-adapter 0.1.0-c247535b70788 → 0.1.0-c249a3be0107c

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 (83) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +14 -57
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +194 -290
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +237 -435
  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 -5
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -3
  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 +23 -69
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +115 -338
  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 +124 -191
  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 +16 -16
  55. package/dist/stream.d.ts.map +1 -1
  56. package/dist/stream.js +301 -430
  57. package/dist/transport.d.ts +109 -48
  58. package/dist/transport.d.ts.map +1 -1
  59. package/dist/transport.js +91 -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 +7 -2
  64. package/dist/upload.d.ts.map +1 -1
  65. package/dist/upload.js +73 -19
  66. package/dist/version.d.ts +0 -1
  67. package/dist/write.d.ts +2 -4
  68. package/dist/write.d.ts.map +1 -1
  69. package/dist/write.js +100 -138
  70. package/package.json +10 -5
  71. package/AGENTS.md +0 -319
  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/part.d.ts +0 -15
  76. package/dist/part.d.ts.map +0 -1
  77. package/dist/part.js +0 -85
  78. package/dist/referrer.d.ts +0 -12
  79. package/dist/referrer.d.ts.map +0 -1
  80. package/dist/referrer.js +0 -31
  81. package/dist/room-types.d.ts +0 -6
  82. package/dist/room-types.d.ts.map +0 -1
  83. package/dist/room-types.js +0 -66
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,60 +1,17 @@
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
- export type AppInputs = {
10
- readonly 'conversation.attach': FileDeclaration & {
11
- readonly room: string;
12
- readonly blob: Blob;
13
- };
14
- readonly 'conversation.answer': ConversationControl & {
15
- readonly answer: {
16
- readonly interaction_id: string;
17
- readonly response: unknown;
18
- };
19
- };
20
- readonly 'conversation.create': Operated & {
21
- readonly agent_id: string;
22
- readonly replaces?: string;
23
- };
24
- readonly 'conversation.delete': ConversationControl;
25
- readonly 'conversation.history': ConversationHistoryRequest;
26
- readonly 'conversation.interrupt': ConversationControl;
27
- readonly 'conversation.kill': ConversationControl;
28
- readonly 'conversation.send': ConversationControl & {
29
- readonly operation_id: string;
30
- readonly text: string;
31
- };
32
- readonly 'trigger.list': {
33
- readonly room_refs: readonly string[];
34
- };
35
- };
36
- export type AppAnswers = {
37
- readonly 'conversation.attach': {
38
- readonly path: string;
39
- };
40
- readonly 'conversation.history': ConversationHistories;
41
- };
42
- export type AppAnswerAdditions = {
43
- readonly 'conversation.create': {
44
- readonly conversation: string;
45
- };
46
- readonly 'conversation.send': {
47
- readonly turn: string;
48
- };
49
- };
50
- export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
51
- export declare const SITE_SUBMIT = "submit";
52
- export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
53
- export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
54
- 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;
55
14
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
56
- export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
57
- export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
58
- export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
15
+ export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
16
+ export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
59
17
  export {};
60
- //# 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,EA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E,OAAO,GAAG,YAAY,CAajG"}
package/dist/actions.js CHANGED
@@ -1,82 +1,188 @@
1
- import { changeBatchIdentity, } from '@agentshouse/mdruntime';
2
- import { doorRefusal } from './refusal.js';
3
- import { finishedUpload, houseUpload } from './upload.js';
4
- const HISTORY_PAGE = 100;
5
- const HISTORY_CONVERSATIONS = 64;
6
- const TRIGGER_ROOMS = 100;
7
- const OCTET_STREAM = 'application/octet-stream';
8
- 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.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'],
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;
9
40
  return {
10
- door,
11
- async carry(transport, given, name) {
12
- return actionOutcome(await transport.door(`/door/${door}`, input(given)), name);
13
- },
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
+ }),
14
48
  };
15
49
  }
16
- function carried(door, carry, batched, room) {
17
- return {
18
- door,
19
- ...(batched === undefined ? {} : { batched }),
20
- ...(room === undefined ? {} : { room }),
21
- 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
+ ['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 }) };
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 };
22
100
  };
23
101
  }
24
- const APP_ACTS = {
25
- 'access.read': mapped('rooms/access/read'),
26
- 'conversation.answer': mapped('conversations/interaction/answer', answerBody),
27
- 'conversation.attach': carried('conversations/attach', attachAction, undefined, 'room'),
28
- 'conversation.create': carried('conversations/create', createAction),
29
- 'conversation.delete': mapped('conversations/delete', controlBody),
30
- 'conversation.history': carried('conversations/history', historyAction, ['conversations']),
31
- 'conversation.interrupt': mapped('conversations/interrupt', controlBody),
32
- 'conversation.kill': mapped('conversations/kill', controlBody),
33
- 'conversation.markDone': mapped('conversations/done'),
34
- 'conversation.rename': mapped('conversations/rename'),
35
- 'conversation.retry': mapped('conversations/retry'),
36
- 'conversation.send': carried('conversations/send', sendAction),
37
- 'conversation.setOption': mapped('conversations/option'),
38
- 'feature.list': mapped('apps/features/read'),
39
- 'holder.list': mapped('apps/holders'),
40
- 'holder.ring': mapped('apps/ring'),
41
- 'inboxChat.assign': mapped('chats/assign'),
42
- 'inboxChat.return': mapped('chats/return'),
43
- 'inboxChat.takeControl': mapped('chats/take-control'),
44
- 'member.list': mapped('rooms/members'),
45
- 'message.send': mapped('apps/messages/send'),
46
- 'processing.read': mapped('rooms/settings/processing/read'),
47
- 'record.list': mapped('records/read'),
48
- 'relay.read': mapped('apps/relay'),
49
- 'routine.list': mapped('routines/access'),
50
- 'routineAccess.list': mapped('routines/granted'),
51
- 'routineAllowance.list': mapped('routines/allowance'),
52
- 'routineRequest.list': mapped('routines/requests'),
53
- 'storage.read': mapped('storage/inventory'),
54
- 'trigger.list': carried('triggers/read', triggersAction, ['room_refs'], 'room_refs'),
55
- 'triggerOccurrence.list': mapped('triggers/fired'),
56
- };
57
- export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
58
- export const SITE_SUBMIT = 'submit';
59
- export const HOUSE_SITE_ACTS = {
60
- [SITE_SUBMIT]: 'site/submission',
61
- };
62
- export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
63
- const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
64
- const APP_ROOMS = new Map(Object.entries(APP_ACTS).flatMap(([name, act]) => act.room === undefined ? [] : [[name, act.room]]));
65
- export function houseConversationAgents(locator) {
66
- return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
102
+ function appNamed(op) {
103
+ return (input) => {
104
+ const { app_ref: app, ...named } = held(input);
105
+ return { op, app, ...named };
106
+ };
67
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
+ ]);
68
177
  export function declaredActions(routes) {
69
- return routes.map((route) => {
70
- const name = APP_NAMES.get(route) ?? route;
71
- return { name, inputShape: {}, resultKind: 'house', room: APP_ROOMS.get(name) ?? 'room_ref' };
72
- });
178
+ return routes.map((name) => ({
179
+ name,
180
+ inputShape: {},
181
+ resultKind: 'house',
182
+ ...(ROOM_SELECTORS.get(name) ?? { room: 'room_ref' }),
183
+ }));
73
184
  }
74
185
  export function houseAction(transport, request) {
75
- if (Object.hasOwn(APP_ACTS, request.name)) {
76
- return APP_ACTS[request.name].carry(transport, request.input, request.name);
77
- }
78
- if (APP_NAMES.has(request.name))
79
- return Promise.resolve(unimplemented(request.name));
80
186
  const route = routeOf(request.name);
81
187
  if (route === null)
82
188
  return Promise.resolve(malformed());
@@ -93,239 +199,37 @@ function routeOf(name) {
93
199
  return null;
94
200
  }
95
201
  }
96
- function record(value) {
97
- return typeof value === 'object' && value !== null ? value : {};
98
- }
99
- function text(value, name) {
100
- const held = record(value)[name];
101
- return typeof held === 'string' ? held : undefined;
102
- }
103
- function operationId(input) {
104
- return text(input, 'operation_id') ?? changeBatchIdentity();
105
- }
106
202
  function malformed() {
107
203
  return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
108
204
  }
109
205
  function unimplemented(name) {
110
206
  return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
111
207
  }
112
- function createBody(input) {
113
- const replaces = text(input, 'replaces');
114
- return {
115
- agent_id: text(input, 'agent_id'),
116
- operation_id: operationId(input),
117
- ...(replaces === undefined ? {} : { replaces }),
118
- };
119
- }
120
- function controlBody(input) {
121
- return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
122
- }
123
- function answerBody(input) {
124
- const nested = record(record(input).answer);
125
- return {
126
- conversation_id: text(input, 'conversation'),
127
- operation_id: operationId(input),
128
- interaction_id: text(nested, 'interaction_id'),
129
- response: nested.response,
130
- };
131
- }
132
- async function createAction(transport, route, input, name) {
133
- const outcome = actionOutcome(await transport.door(route, createBody(input)), name);
134
- if (outcome.kind !== 'action')
135
- return outcome;
136
- const held = record(outcome.result);
137
- const conversation = text(held, 'conversation_id');
138
- return conversation === undefined
139
- ? outcome
140
- : {
141
- ...outcome,
142
- result: { ...held, conversation },
143
- };
208
+ function numbered(input) {
209
+ return typeof input?.operation_id === 'string';
144
210
  }
145
- function withTurn(body) {
146
- const held = record(body);
147
- const turn = text(held, 'message_id');
148
- return turn === undefined
149
- ? body
150
- : { ...held, turn };
151
- }
152
- export function actionOutcome(answer, name) {
211
+ export function actionOutcome(answer, name, input) {
153
212
  if (answer.status === 401)
154
213
  return { kind: 'revoked-authorization' };
155
214
  const refusal = doorRefusal(answer.body);
156
- if (refusal?.code === 'operation_contended')
157
- return { kind: 'transport-uncertainty' };
158
- if (refusal !== null)
159
- return { kind: 'rejected', ...refusal };
215
+ if (refusal?.code === 'operation_contended' && numbered(input))
216
+ return refusedFor(refusal);
217
+ if (refusal !== null) {
218
+ const reset = resetOf(refusal);
219
+ return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
220
+ }
160
221
  if (answer.status === 404)
161
222
  return unimplemented(name);
162
- if (answer.status === 0 || answer.status >= 400)
163
- return { kind: 'transport-uncertainty' };
223
+ if (answer.status === 0 || answer.status >= 400) {
224
+ return answeredFailure(answer.status, answer.body);
225
+ }
164
226
  return { kind: 'action', result: answer.body };
165
227
  }
166
228
  async function carry(transport, route, name, input) {
167
- return actionOutcome(await transport.door(route, input), name);
168
- }
169
- function sendBody(input) {
170
- const operation = text(input, 'operation_id');
171
- const said = text(input, 'text');
172
- if (operation === undefined || said === undefined)
173
- return null;
174
- return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
175
- }
176
- async function sendAction(transport, route, input, name) {
177
- const body = sendBody(input);
178
- if (body === null)
179
- return malformed();
180
- const outcome = actionOutcome(await transport.door(route, body), name);
181
- if (outcome.kind !== 'action')
182
- return outcome;
183
- return { ...outcome, result: withTurn(outcome.result) };
184
- }
185
- function attachBody(input) {
186
- const room = text(input, 'room');
187
- const name = text(input, 'name');
188
- const sha256 = text(input, 'contentHash');
189
- const bytes = record(input).byteLength;
190
- if (room === undefined || name === undefined || sha256 === undefined)
191
- return null;
192
- if (typeof bytes !== 'number')
193
- return null;
194
- const mediaType = text(input, 'mediaType');
195
- return {
196
- room_ref: room,
197
- name,
198
- bytes,
199
- sha256,
200
- media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
201
- };
202
- }
203
- async function attachAction(transport, route, input, name) {
204
- const body = attachBody(input);
205
- const blob = record(input).blob;
206
- if (body === null || !(blob instanceof Blob))
207
- return malformed();
208
- const outcome = actionOutcome(await transport.door(route, body), name);
209
- if (outcome.kind !== 'action')
210
- return outcome;
211
- const upload = houseUpload(record(outcome.result).upload);
212
- if (upload === null)
213
- return { kind: 'transport-uncertainty' };
214
- const finished = await finishedUpload(transport, upload, blob);
215
- if (finished === null)
216
- return { kind: 'transport-uncertainty' };
217
- const settled = actionOutcome(finished, name);
218
- if (settled.kind !== 'action')
219
- return settled;
220
- const path = text(settled.result, 'path');
221
- if (path === undefined)
222
- return { kind: 'transport-uncertainty' };
223
- const result = { path };
224
- return { kind: 'action', result };
225
- }
226
- function historyCursor(value) {
227
- const acceptedAt = text(value, 'accepted_at');
228
- const messageId = text(value, 'message_id');
229
- if (acceptedAt === undefined || messageId === undefined)
230
- return null;
231
- return { accepted_at: acceptedAt, message_id: messageId };
232
- }
233
- function position(cursor) {
234
- return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
235
- }
236
- function positionCursor(value) {
237
- try {
238
- return historyCursor(JSON.parse(value));
239
- }
240
- catch {
241
- return null;
242
- }
243
- }
244
- export function acceptedMessage(entry) {
245
- const cursor = historyCursor(entry);
246
- if (cursor === null)
247
- return null;
248
- return {
249
- identity: cursor.message_id,
250
- turn: text(entry, 'turn_id') ?? cursor.message_id,
251
- position: position(cursor),
252
- text: text(entry, 'text') ?? '',
253
- message: structuredClone(record(entry)),
254
- };
255
- }
256
- function historyPage(entry) {
257
- const held = record(entry);
258
- const conversation = text(held, 'conversation_id');
259
- if (conversation === undefined || !Array.isArray(held.messages))
260
- return null;
261
- const messages = [];
262
- for (const one of held.messages) {
263
- const message = acceptedMessage(one);
264
- if (message === null)
265
- return null;
266
- messages.push(message);
267
- }
268
- const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
269
- if (next === null)
270
- return null;
271
- return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
272
- }
273
- function historyAsks(input) {
274
- const asked = record(input).conversations;
275
- if (!Array.isArray(asked) || asked.length === 0)
276
- return null;
277
- const asks = [];
278
- for (const entry of asked) {
279
- const conversationId = text(entry, 'conversation');
280
- if (conversationId === undefined)
281
- return null;
282
- const afterValue = text(entry, 'after');
283
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
284
- if (after === null)
285
- return null;
286
- asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
287
- }
288
- return asks;
289
- }
290
- async function triggersAction(transport, route, input, name) {
291
- const asked = record(input).room_refs;
292
- if (!Array.isArray(asked) || asked.length === 0)
293
- return malformed();
294
- const rooms = [];
295
- for (let at = 0; at < asked.length; at += TRIGGER_ROOMS) {
296
- const outcome = actionOutcome(await transport.door(route, { room_refs: asked.slice(at, at + TRIGGER_ROOMS) }), name);
297
- if (outcome.kind !== 'action')
298
- return outcome;
299
- const answered = record(outcome.result).rooms;
300
- if (!Array.isArray(answered))
301
- return { kind: 'transport-uncertainty' };
302
- rooms.push(...answered);
303
- }
304
- return { kind: 'action', result: { rooms } };
305
- }
306
- async function historyAction(transport, route, input, name) {
307
- const asks = historyAsks(input);
308
- if (asks === null)
309
- return malformed();
310
- const histories = [];
311
- for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
312
- const answer = await transport.door(route, {
313
- conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
314
- limit: HISTORY_PAGE,
315
- });
316
- const outcome = actionOutcome(answer, name);
317
- if (outcome.kind !== 'action')
318
- return outcome;
319
- const answered = record(outcome.result).histories;
320
- if (!Array.isArray(answered))
321
- return { kind: 'transport-uncertainty' };
322
- for (const entry of answered) {
323
- const page = historyPage(entry);
324
- if (page === null)
325
- return { kind: 'transport-uncertainty' };
326
- histories.push(page);
327
- }
328
- }
329
- const result = { histories };
330
- 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);
331
235
  }
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;AA0ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA2BxB,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;AA8ErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAmpBpF"}
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,CAodpF"}