@agentshouse/mdruntime-adapter 0.1.0-ce4626067e686 → 0.1.0-ce752a56d9714

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 (72) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +4 -6
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +8 -293
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +291 -230
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +23 -12
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +94 -50
  17. package/dist/history.d.ts +12 -0
  18. package/dist/history.d.ts.map +1 -0
  19. package/dist/history.js +92 -0
  20. package/dist/house-model.d.ts +911 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +496 -0
  23. package/dist/index.d.ts +11 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +10 -1
  26. package/dist/model.d.ts +5 -3
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +10 -32
  29. package/dist/part.d.ts +14 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +90 -0
  32. package/dist/read.d.ts +54 -44
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +271 -214
  35. package/dist/refusal.d.ts +0 -3
  36. package/dist/refusal.d.ts.map +1 -1
  37. package/dist/refusal.js +2 -6
  38. package/dist/room-stream.d.ts +20 -0
  39. package/dist/room-stream.d.ts.map +1 -0
  40. package/dist/room-stream.js +78 -0
  41. package/dist/room-types.d.ts +7 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +125 -0
  44. package/dist/search.d.ts +5 -0
  45. package/dist/search.d.ts.map +1 -0
  46. package/dist/search.js +47 -0
  47. package/dist/site.d.ts +1 -1
  48. package/dist/site.d.ts.map +1 -1
  49. package/dist/site.js +130 -104
  50. package/dist/stream.d.ts +12 -12
  51. package/dist/stream.d.ts.map +1 -1
  52. package/dist/stream.js +207 -151
  53. package/dist/transport.d.ts +91 -20
  54. package/dist/transport.d.ts.map +1 -1
  55. package/dist/transport.js +55 -9
  56. package/dist/upload.d.ts +12 -0
  57. package/dist/upload.d.ts.map +1 -0
  58. package/dist/upload.js +63 -0
  59. package/dist/version.d.ts +1 -0
  60. package/dist/version.d.ts.map +1 -1
  61. package/dist/version.js +1 -1
  62. package/dist/write.d.ts +19 -10
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +142 -54
  65. package/package.json +8 -5
  66. package/AGENTS.md +0 -269
  67. package/dist/gather.d.ts +0 -4
  68. package/dist/gather.d.ts.map +0 -1
  69. package/dist/gather.js +0 -45
  70. package/dist/links.d.ts +0 -20
  71. package/dist/links.d.ts.map +0 -1
  72. package/dist/links.js +0 -104
package/README.md CHANGED
@@ -24,8 +24,8 @@ host.attach(port, '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 `open_guide` opens.
29
29
 
30
30
  ## License
31
31
 
package/dist/actions.d.ts CHANGED
@@ -1,9 +1,7 @@
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 const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
4
- export declare function houseConversationAgents(locator: string): ConversationAgents;
3
+ export type HouseActDoor = Pick<HouseTransport, 'door'>;
5
4
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
6
- export declare function houseAction(transport: HouseTransport, request: ActionRequest): Promise<ActionResult>;
7
- export declare function actionOutcome(answer: HouseDoorAnswer, name: string): ActionResult;
8
- export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
5
+ export declare function houseAction(transport: HouseActDoor, request: ActionRequest): Promise<ActionResult>;
6
+ export declare function actionOutcome(answer: HouseDoorAnswer, name: string, input: unknown): ActionResult;
9
7
  //# 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,EAGxB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAiEtE,eAAO,MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3D,CAAC;AAMF,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAMvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AAyDD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAOjF;AAqJD,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;AAE7F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAExD,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAEvF;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,CAUjG"}
package/dist/actions.js CHANGED
@@ -1,68 +1,8 @@
1
- import { changeBatchIdentity, } from '@agentshouse/mdruntime';
2
1
  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) {
7
- return {
8
- door,
9
- async carry(transport, given, name) {
10
- return actionOutcome(await transport.door(`/door/${door}`, input(given)), name);
11
- },
12
- };
13
- }
14
- function carried(door, carry) {
15
- return {
16
- door,
17
- carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
18
- };
19
- }
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
- }
53
2
  export function declaredActions(routes) {
54
- return routes.map((route) => ({
55
- name: APP_NAMES.get(route) ?? route,
56
- inputShape: {},
57
- resultKind: 'house',
58
- }));
3
+ return routes.map((name) => ({ name, inputShape: {}, resultKind: 'house', room: 'room_ref' }));
59
4
  }
60
5
  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
6
  const route = routeOf(request.name);
67
7
  if (route === null)
68
8
  return Promise.resolve(malformed());
@@ -79,46 +19,22 @@ function routeOf(name) {
79
19
  return null;
80
20
  }
81
21
  }
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
22
  function malformed() {
93
23
  return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
94
24
  }
95
25
  function unimplemented(name) {
96
26
  return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
97
27
  }
98
- function createBody(input) {
99
- return { agent_id: text(input, 'agent_id'), operation_id: operationId(input) };
28
+ function numbered(input) {
29
+ return typeof input?.operation_id === 'string';
100
30
  }
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 ? body : { ...held, turn };
117
- }
118
- export function actionOutcome(answer, name) {
31
+ export function actionOutcome(answer, name, input) {
119
32
  if (answer.status === 401)
120
33
  return { kind: 'revoked-authorization' };
121
34
  const refusal = doorRefusal(answer.body);
35
+ if (refusal?.code === 'operation_contended' && numbered(input)) {
36
+ return { kind: 'transport-uncertainty' };
37
+ }
122
38
  if (refusal !== null)
123
39
  return { kind: 'rejected', ...refusal };
124
40
  if (answer.status === 404)
@@ -128,206 +44,5 @@ export function actionOutcome(answer, name) {
128
44
  return { kind: 'action', result: answer.body };
129
45
  }
130
46
  async function carry(transport, route, name, input) {
131
- return actionOutcome(await transport.door(route, input), name);
132
- }
133
- function sendFile(entry) {
134
- const file = record(entry);
135
- const name = text(file, 'name');
136
- const bytes = file.byteLength;
137
- const sha256 = text(file, 'contentHash');
138
- if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
139
- return null;
140
- const mediaType = text(file, 'mediaType');
141
- const width = file.width;
142
- const height = file.height;
143
- return {
144
- name,
145
- media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
146
- bytes,
147
- sha256,
148
- ...(typeof width === 'number' && typeof height === 'number'
149
- ? { dimensions: { width, height } }
150
- : {}),
151
- };
152
- }
153
- function sendFiles(input) {
154
- const files = record(input).files;
155
- if (files === undefined)
156
- return [];
157
- if (!Array.isArray(files))
158
- return null;
159
- const declared = [];
160
- for (const entry of files) {
161
- const file = sendFile(entry);
162
- if (file === null)
163
- return null;
164
- declared.push(file);
165
- }
166
- return declared;
167
- }
168
- function sendBody(input) {
169
- const files = sendFiles(input);
170
- if (files === null)
171
- return null;
172
- const textValue = text(input, 'text');
173
- return {
174
- conversation_id: text(input, 'conversation'),
175
- operation_id: operationId(input),
176
- ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
177
- ...(files.length === 0 ? {} : { files }),
178
- };
179
- }
180
- async function fileBytes(file) {
181
- const blob = record(file).blob;
182
- if (blob === undefined || typeof blob !== 'object' || blob === null)
183
- return null;
184
- if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
185
- return null;
186
- return new Uint8Array(await blob.arrayBuffer());
187
- }
188
- function delivered(answer, name) {
189
- return answer.status === 200 ? null : actionOutcome(answer, name);
190
- }
191
- function uploadGrant(entry) {
192
- if (!('upload' in record(entry)))
193
- return 'absent';
194
- const upload = record(record(entry).upload);
195
- if (upload.method !== 'POST')
196
- return null;
197
- if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
198
- return null;
199
- return { method: 'POST', operation: upload.operation, url: upload.url };
200
- }
201
- async function uploadFiles(transport, input, result, name) {
202
- const sent = record(result).files;
203
- if (!Array.isArray(sent) || sent.length === 0)
204
- return null;
205
- const files = Array.isArray(record(input).files) ? record(input).files : [];
206
- for (const [index, entry] of sent.entries()) {
207
- const grant = uploadGrant(entry);
208
- if (grant === 'absent')
209
- continue;
210
- if (grant === null)
211
- return malformed();
212
- const bytes = index < files.length ? await fileBytes(files[index]) : null;
213
- if (bytes === null) {
214
- return {
215
- kind: 'rejected',
216
- code: 'conversation_file_descriptor_required',
217
- fields: {},
218
- retryable: false,
219
- };
220
- }
221
- const failed = delivered(await transport.transfer({
222
- act: 'conversation_file_upload',
223
- url: grant.url,
224
- body: bytes,
225
- operation: grant.operation,
226
- }), name);
227
- if (failed !== null)
228
- return failed;
229
- }
230
- return null;
231
- }
232
- async function sendAction(transport, route, input, name) {
233
- const body = sendBody(input);
234
- if (body === null)
235
- return malformed();
236
- const outcome = actionOutcome(await transport.door(route, body), name);
237
- if (outcome.kind !== 'action')
238
- return outcome;
239
- const uploaded = await uploadFiles(transport, input, outcome.result, name);
240
- if (uploaded !== null)
241
- return uploaded;
242
- return { ...outcome, result: withTurn(outcome.result) };
243
- }
244
- function historyCursor(value) {
245
- const acceptedAt = text(value, 'accepted_at');
246
- const messageId = text(value, 'message_id');
247
- if (acceptedAt === undefined || messageId === undefined)
248
- return null;
249
- return { accepted_at: acceptedAt, message_id: messageId };
250
- }
251
- function position(cursor) {
252
- return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
253
- }
254
- function positionCursor(value) {
255
- try {
256
- return historyCursor(JSON.parse(value));
257
- }
258
- catch {
259
- return null;
260
- }
261
- }
262
- export function acceptedMessage(entry) {
263
- const cursor = historyCursor(entry);
264
- if (cursor === null)
265
- return null;
266
- return {
267
- identity: cursor.message_id,
268
- turn: text(entry, 'turn_id') ?? cursor.message_id,
269
- position: position(cursor),
270
- text: text(entry, 'text') ?? '',
271
- message: structuredClone(entry),
272
- };
273
- }
274
- function historyPage(entry) {
275
- const held = record(entry);
276
- const conversation = text(held, 'conversation_id');
277
- if (conversation === undefined || !Array.isArray(held.messages))
278
- return null;
279
- const messages = [];
280
- for (const one of held.messages) {
281
- const message = acceptedMessage(one);
282
- if (message === null)
283
- return null;
284
- messages.push(message);
285
- }
286
- const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
287
- if (next === null)
288
- return null;
289
- return { conversation, messages, ...(next === undefined ? {} : { next: position(next) }) };
290
- }
291
- function historyAsks(input) {
292
- const asked = record(input).conversations;
293
- if (!Array.isArray(asked) || asked.length === 0)
294
- return null;
295
- const asks = [];
296
- for (const entry of asked) {
297
- const conversationId = text(entry, 'conversation');
298
- if (conversationId === undefined)
299
- return null;
300
- const afterValue = text(entry, 'after');
301
- const after = afterValue === undefined ? undefined : positionCursor(afterValue);
302
- if (after === null)
303
- return null;
304
- asks.push({ conversation_id: conversationId, ...(after === undefined ? {} : { after }) });
305
- }
306
- return asks;
307
- }
308
- async function historyAction(transport, route, input, name) {
309
- const asks = historyAsks(input);
310
- if (asks === null)
311
- return malformed();
312
- const histories = [];
313
- for (let at = 0; at < asks.length; at += HISTORY_CONVERSATIONS) {
314
- const answer = await transport.door(route, {
315
- conversations: asks.slice(at, at + HISTORY_CONVERSATIONS),
316
- limit: HISTORY_PAGE,
317
- });
318
- const outcome = actionOutcome(answer, name);
319
- if (outcome.kind !== 'action')
320
- return outcome;
321
- const answered = record(outcome.result).histories;
322
- if (!Array.isArray(answered))
323
- return { kind: 'transport-uncertainty' };
324
- for (const entry of answered) {
325
- const page = historyPage(entry);
326
- if (page === null)
327
- return { kind: 'transport-uncertainty' };
328
- histories.push(page);
329
- }
330
- }
331
- const result = { histories };
332
- return { kind: 'action', result };
47
+ return actionOutcome(await transport.door(route, input), name, input);
333
48
  }
package/dist/adapter.d.ts CHANGED
@@ -5,6 +5,7 @@ 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
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,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":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAgBd,MAAM,wBAAwB,CAAC;AAgChC,OAAO,EAGL,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;AA+DrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA+apF"}