@agentshouse/mdruntime-adapter 0.1.0-ceda7e87cc6e8 → 0.1.0-cedb8e57837a7

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.
package/dist/actions.d.ts CHANGED
@@ -24,17 +24,40 @@ export type AppInputs = {
24
24
  readonly 'conversation.interrupt': ConversationControl;
25
25
  readonly 'conversation.kill': ConversationControl;
26
26
  readonly 'conversation.send': ConversationControl & {
27
+ readonly operation_id: string;
27
28
  readonly text?: string;
28
29
  readonly files?: readonly SentFile[];
29
30
  };
31
+ readonly 'trigger.list': {
32
+ readonly room_refs: readonly string[];
33
+ };
30
34
  };
31
35
  export type AppAnswers = {
32
36
  readonly 'conversation.history': ConversationHistories;
33
37
  };
34
38
  export type AppAnswerAdditions = {
39
+ readonly 'conversation.create': {
40
+ readonly conversation: string;
41
+ };
35
42
  readonly 'conversation.send': {
36
43
  readonly turn: string;
37
44
  };
45
+ readonly 'record.list': {
46
+ readonly attachments: readonly {
47
+ readonly referrer: {
48
+ readonly room_ref: string;
49
+ readonly record: string;
50
+ };
51
+ }[];
52
+ readonly records: readonly {
53
+ readonly attachments: readonly {
54
+ readonly referrer: {
55
+ readonly room_ref: string;
56
+ readonly record: string;
57
+ };
58
+ }[];
59
+ }[];
60
+ };
38
61
  };
39
62
  export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
40
63
  export declare const SITE_SUBMIT = "submit";
@@ -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,gBA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AAG,YAAY,CAQjF;AAuKD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiBtE"}
package/dist/actions.js CHANGED
@@ -2,6 +2,7 @@ import { changeBatchIdentity, } from '@agentshouse/mdruntime';
2
2
  import { doorRefusal } from './refusal.js';
3
3
  const HISTORY_PAGE = 100;
4
4
  const HISTORY_CONVERSATIONS = 64;
5
+ const TRIGGER_ROOMS = 100;
5
6
  const OCTET_STREAM = 'application/octet-stream';
6
7
  function mapped(door, input = (given) => given) {
7
8
  return {
@@ -11,10 +12,11 @@ function mapped(door, input = (given) => given) {
11
12
  },
12
13
  };
13
14
  }
14
- function carried(door, carry, batched) {
15
+ function carried(door, carry, batched, room) {
15
16
  return {
16
17
  door,
17
18
  ...(batched === undefined ? {} : { batched }),
19
+ ...(room === undefined ? {} : { room }),
18
20
  carry: (transport, input, name) => carry(transport, `/door/${door}`, input, name),
19
21
  };
20
22
  }
@@ -28,6 +30,7 @@ const APP_ACTS = {
28
30
  'conversation.kill': mapped('conversations/kill', controlBody),
29
31
  'conversation.markDone': mapped('conversations/done'),
30
32
  'conversation.rename': mapped('conversations/rename'),
33
+ 'conversation.retry': mapped('conversations/retry'),
31
34
  'conversation.send': carried('conversations/send', sendAction),
32
35
  'conversation.setOption': mapped('conversations/option'),
33
36
  'feature.list': mapped('apps/features/read'),
@@ -43,7 +46,7 @@ const APP_ACTS = {
43
46
  'routineAllowance.list': mapped('routines/allowance'),
44
47
  'routineRequest.list': mapped('routines/requests'),
45
48
  'storage.read': mapped('storage/inventory'),
46
- 'trigger.list': mapped('triggers/read'),
49
+ 'trigger.list': carried('triggers/read', triggersAction, ['room_refs'], 'room_refs'),
47
50
  'triggerOccurrence.list': mapped('triggers/fired'),
48
51
  };
49
52
  export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
@@ -53,15 +56,15 @@ export const HOUSE_SITE_ACTS = {
53
56
  };
54
57
  export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
55
58
  const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
59
+ const APP_ROOMS = new Map(Object.entries(APP_ACTS).flatMap(([name, act]) => act.room === undefined ? [] : [[name, act.room]]));
56
60
  export function houseConversationAgents(locator) {
57
61
  return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
58
62
  }
59
63
  export function declaredActions(routes) {
60
- return routes.map((route) => ({
61
- name: APP_NAMES.get(route) ?? route,
62
- inputShape: {},
63
- resultKind: 'house',
64
- }));
64
+ return routes.map((route) => {
65
+ const name = APP_NAMES.get(route) ?? route;
66
+ return { name, inputShape: {}, resultKind: 'house', room: APP_ROOMS.get(name) ?? 'room_ref' };
67
+ });
65
68
  }
66
69
  export function houseAction(transport, request) {
67
70
  if (Object.hasOwn(APP_ACTS, request.name)) {
@@ -122,7 +125,12 @@ async function createAction(transport, route, input, name) {
122
125
  return outcome;
123
126
  const held = record(outcome.result);
124
127
  const conversation = text(held, 'conversation_id');
125
- return conversation === undefined ? outcome : { ...outcome, result: { ...held, conversation } };
128
+ return conversation === undefined
129
+ ? outcome
130
+ : {
131
+ ...outcome,
132
+ result: { ...held, conversation },
133
+ };
126
134
  }
127
135
  function withTurn(body) {
128
136
  const held = record(body);
@@ -135,6 +143,8 @@ export function actionOutcome(answer, name) {
135
143
  if (answer.status === 401)
136
144
  return { kind: 'revoked-authorization' };
137
145
  const refusal = doorRefusal(answer.body);
146
+ if (refusal?.code === 'operation_contended')
147
+ return { kind: 'transport-uncertainty' };
138
148
  if (refusal !== null)
139
149
  return { kind: 'rejected', ...refusal };
140
150
  if (answer.status === 404)
@@ -147,7 +157,10 @@ function referredRecord(view, roomRef) {
147
157
  const held = record(view);
148
158
  if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
149
159
  return view;
150
- const referrer = { room_ref: roomRef, record: held.record };
160
+ const referrer = {
161
+ room_ref: roomRef,
162
+ record: held.record,
163
+ };
151
164
  return {
152
165
  ...held,
153
166
  attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
@@ -206,12 +219,13 @@ function sendFiles(input) {
206
219
  }
207
220
  function sendBody(input) {
208
221
  const files = sendFiles(input);
209
- if (files === null)
222
+ const operation = text(input, 'operation_id');
223
+ if (files === null || operation === undefined)
210
224
  return null;
211
225
  const textValue = text(input, 'text');
212
226
  return {
213
227
  conversation_id: text(input, 'conversation'),
214
- operation_id: operationId(input),
228
+ operation_id: operation,
215
229
  ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
216
230
  ...(files.length === 0 ? {} : { files }),
217
231
  };
@@ -224,9 +238,6 @@ async function fileBytes(file) {
224
238
  return null;
225
239
  return new Uint8Array(await blob.arrayBuffer());
226
240
  }
227
- function delivered(answer, name) {
228
- return answer.status === 200 ? null : actionOutcome(answer, name);
229
- }
230
241
  function uploadGrant(entry) {
231
242
  if (!('upload' in record(entry)))
232
243
  return 'absent';
@@ -237,36 +248,28 @@ function uploadGrant(entry) {
237
248
  return null;
238
249
  return { method: 'POST', operation: upload.operation, url: upload.url };
239
250
  }
240
- async function uploadFiles(transport, input, result, name) {
251
+ async function uploadFiles(transport, input, result) {
241
252
  const sent = record(result).files;
242
- if (!Array.isArray(sent) || sent.length === 0)
243
- return null;
253
+ if (!Array.isArray(sent))
254
+ return true;
244
255
  const files = Array.isArray(record(input).files) ? record(input).files : [];
245
256
  for (const [index, entry] of sent.entries()) {
246
257
  const grant = uploadGrant(entry);
247
258
  if (grant === 'absent')
248
259
  continue;
249
- if (grant === null)
250
- return malformed();
251
260
  const bytes = index < files.length ? await fileBytes(files[index]) : null;
252
- if (bytes === null) {
253
- return {
254
- kind: 'rejected',
255
- code: 'conversation_file_descriptor_required',
256
- fields: {},
257
- retryable: false,
258
- };
259
- }
260
- const failed = delivered(await transport.transfer({
261
+ if (grant === null || bytes === null)
262
+ return false;
263
+ const answer = await transport.transfer({
261
264
  act: 'conversation_file_upload',
262
265
  url: grant.url,
263
266
  body: bytes,
264
267
  operation: grant.operation,
265
- }), name);
266
- if (failed !== null)
267
- return failed;
268
+ });
269
+ if (answer.status !== 200)
270
+ return false;
268
271
  }
269
- return null;
272
+ return true;
270
273
  }
271
274
  async function sendAction(transport, route, input, name) {
272
275
  const body = sendBody(input);
@@ -275,9 +278,9 @@ async function sendAction(transport, route, input, name) {
275
278
  const outcome = actionOutcome(await transport.door(route, body), name);
276
279
  if (outcome.kind !== 'action')
277
280
  return outcome;
278
- const uploaded = await uploadFiles(transport, input, outcome.result, name);
279
- if (uploaded !== null)
280
- return uploaded;
281
+ if (!(await uploadFiles(transport, input, outcome.result))) {
282
+ return { kind: 'transport-uncertainty' };
283
+ }
281
284
  return { ...outcome, result: withTurn(outcome.result) };
282
285
  }
283
286
  function historyCursor(value) {
@@ -351,6 +354,22 @@ function historyAsks(input) {
351
354
  }
352
355
  return asks;
353
356
  }
357
+ async function triggersAction(transport, route, input, name) {
358
+ const asked = record(input).room_refs;
359
+ if (!Array.isArray(asked) || asked.length === 0)
360
+ return malformed();
361
+ const rooms = [];
362
+ for (let at = 0; at < asked.length; at += TRIGGER_ROOMS) {
363
+ const outcome = actionOutcome(await transport.door(route, { room_refs: asked.slice(at, at + TRIGGER_ROOMS) }), name);
364
+ if (outcome.kind !== 'action')
365
+ return outcome;
366
+ const answered = record(outcome.result).rooms;
367
+ if (!Array.isArray(answered))
368
+ return { kind: 'transport-uncertainty' };
369
+ rooms.push(...answered);
370
+ }
371
+ return { kind: 'action', result: { rooms } };
372
+ }
354
373
  async function historyAction(transport, route, input, name) {
355
374
  const asks = historyAsks(input);
356
375
  if (asks === null)
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,EAgBd,MAAM,wBAAwB,CAAC;AAuChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAyBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAA;CAAE,CAAC;AAwBjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA8cpF"}
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;AA6ChC,OAAO,EASL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AA0BxB,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;AAyFrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA8mBpF"}