@agentshouse/mdruntime-adapter 0.1.0-c6e64cd278293 → 0.1.0-c6eb3c1455065

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/AGENTS.md CHANGED
@@ -5,8 +5,8 @@ change it, build, and push. They are documentation, not enforcement.
5
5
 
6
6
  ## The MD Runtime API
7
7
 
8
- App code reaches the MD Runtime through the remote client. The surfaces are Rooms,
9
- Query, Search, Observe, Types, Room Draft, Save, History, the binary file reads, Call,
8
+ App code reaches the MD Runtime through the remote client. The surfaces are Rooms, Query,
9
+ Search, Observe, Types, Room Draft, Save, History, Resolve, the binary file reads, Call,
10
10
  Reached, Log, the reported persistence answer, reauthorization, conversation, the chat
11
11
  draft, and Presentation State. Sync Status, readiness, the Service Mode, the storage-loss
12
12
  statement, the deployment facts and the signed-in member are observations only.
@@ -28,14 +28,15 @@ complete in the browser. `conversation.list()` and `observe('conversations')` an
28
28
  with its Agent's identity and name, its name, created and finished times, last outcome,
29
29
  live `state` (`asking` while a question waits, `working` while a turn runs, else `idle`)
30
30
  and `started`, when the running turn began, or `null`. `observe('conversation', id, {
31
- limit, total: true })` holds its latest `limit` messages, or all, oldest first, `total`
32
- their count, and `next` while older ones exist, which `after` takes, there or in
31
+ limit, total: true })` holds its latest `limit` messages, at most 1,000, oldest first,
32
+ `total` their count, and `next` while older ones exist, which `after` takes, there or in
33
33
  `conversation.read(id, { limit, after })`, for the window before; its chat draft; and,
34
34
  only in memory, what the Provider streams whether or not anything views it: the running
35
35
  `turn` with its parts and its context in use and window, which the message accepted under
36
36
  the turn's id replaces, the open questions, the process state, and the CLI's commands and
37
37
  options, none stored or searchable. `chatDraft.write` and `chatDraft.discard` keep what
38
- the App Creator composes; sending it is a Provider Action that needs the Provider
38
+ the App Creator composes, and `chatDraft.prepend(conversation, draft)` puts a returned
39
+ message ahead of it as it stands. Sending it is a Provider Action that needs the Provider
39
40
  reachable and is never queued. A new conversation's chat draft is keyed `new:<Agent
40
41
  identity>`: no conversation list removes it, a retired Agent's goes, and the first answer
41
42
  to `conversation.create({ agent_id, operation_id })` moves it to the created conversation,
@@ -72,11 +73,11 @@ result whose effect the Provider places in a Room carries `at`, that Room and Ro
72
73
  Version: `reached(room, roomVersion)` answers whether the Room's confirmed state has
73
74
  reached it, refreshing the Room until it has, and `reached(room, roomVersion, path)`
74
75
  whether the held copy of that document was written later. A History revision names its
75
- author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`; History of a Path no
76
+ author, `{ kind: 'user', id }` or `{ kind: 'site' | 'inbox', id, name }`; History of a Path no
76
77
  document holds answers the removed document's revisions, newest first, with `deleted:
77
78
  true`, which a link to the Path opens. Every member is asynchronous and every result a
78
79
  detached snapshot; nothing returns the authorization, performs a request the App's code
79
- composes, or exposes the browser store.
80
+ composes, or exposes the browser store. A Room `rooms` names `locked` shows only online.
80
81
 
81
82
  Every refusal and failure carries `code` and `retryable`: each Call and History answer
82
83
  other than its result, a refused Save or Room Draft write, a returned Room Draft's reason,
@@ -100,13 +101,13 @@ named; signing out answers `null`, then ends the observation with the authorizat
100
101
  hears it again only when it changes, keeping every unchanged Document the same object, so
101
102
  a component can tell what changed by identity. `{ documents, coverage }` or `{ groups,
102
103
  coverage }` is complete for the Rooms its `coverage` names, and `{ pending }` names each
103
- Room not yet acquired or prepared, `[{ room, awaits }]`: never read it as empty, draw it
104
- as loading and observe the query to hear the complete answer. A query is data:
104
+ Room not yet acquired, prepared or unlocked, `[{ room, awaits }]`: never read it as empty,
105
+ draw it as loading and observe the query to hear the complete answer. A query is data:
105
106
 
106
107
  - **Filter.** `rooms` names Room locators and defaults to every Room. `types` names MD
107
108
  Types, and `any` names untyped Markdown Documents. `pathPrefix` is a directory: `notes`
108
- keeps `notes/a.md` and not `notes2/a.md`. `paths` keeps only the Paths it names: read
109
- named Documents so, never by looking for them in a list.
109
+ keeps `notes/a.md` and not `notes2/a.md`; `folder` keeps only what lies directly in it.
110
+ `paths` keeps only the Paths it names: read named Documents so, never from a list.
110
111
  - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
111
112
  `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that meets a
112
113
  list applies to every item and a number names one item. `where` names pointers, ANDs
@@ -118,10 +119,13 @@ as loading and observe the query to hear the complete answer. A query is data:
118
119
  compares in calendar order and never with a date-time. A reference compares by the
119
120
  Room Path it resolves to. Untyped frontmatter, and a value under `oneOf` or a
120
121
  conditional, is plain values. There is no text containment or regular expression.
121
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
122
- reference at pointer `field`, at any depth, points to a matching Document of the same
123
- Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a matching
124
- Document of the same Room references. Each keeps a Document once.
122
+ - **Relations.** Within one Room, `hop: { field, types, where, pathPrefix }` keeps Documents
123
+ whose reference at pointer `field`, at any depth, points to a matching Document, and
124
+ `backlinks` with the same keys those a matching Document references, each once. A body
125
+ link, or a reference declaring `cross_room`, may name another Room's
126
+ `/rooms/<handle>/<path>`: `resolve(room, path, destination)` answers its `document`, the
127
+ `deleted` one's last `revision`, or `unreadable` where the App does not bind it or it is
128
+ locked.
125
129
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
126
130
  `preamble`, `markdown`, `backlinks`, `change` and `fileId`, where `fields` is `'all'`
127
131
  or a list of pointers and `sections` `'all'` or a list of names. Selected pointers
@@ -133,21 +137,21 @@ as loading and observe the query to hear the complete answer. A query is data:
133
137
  `binaryFile` record too. An unselected part is absent. Select only what a screen shows:
134
138
  a list that selects the Markdown hears every edit of it.
135
139
  - **Change and file ID.** `change` is `{ author, time }` of the Document's head revision
136
- as the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`, or
140
+ as the Provider last delivered it: `author` is `{ kind: 'user' | 'site' | 'inbox', id, name }`, or
137
141
  `null` for a write the Provider made itself, and `time` its ISO 8601 change time, or the
138
142
  whole change `null` where it delivered no time, as at a Site. `fileId` is the Provider's
139
143
  Stable File ID of the file at the Path, or `null`. An unsent edit keeps both, an unsent
140
144
  move keeps the change and carries the file ID to the new Path, so a file ID that leaves
141
145
  one Path for another is the same file moved, and an unsent creation has neither until it
142
146
  is Accepted. A Room's last change is its Document with the latest `time`.
143
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }` with
144
- TanStack DB's own options, and ties end with Room, then Path. `groupBy` by `room`,
145
- `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted over every match
146
- and ordered by `count` or a key. A sort or group takes only a pointer that holds one
147
- value. `limit` bounds the Documents or the groups, and a result it cuts short names
148
- `next`: the same query with it as `after` reads the next window, in the same order,
149
- ties included. `total: true` adds `total`, every match's count. An observed window
150
- hears rows entering, leaving or changing, and its `next` and `total`.
147
+ - **Order and groups.** `orderBy` sorts by `room`, `path`, `type`, `folder` or `{ field }`
148
+ with TanStack DB's own options; ties end with Room, then Path. `groupBy` by `room`,
149
+ `type`, `folder` or `{ field }` answers `{ groups: [{ key, count }] }`, counted over every
150
+ match and ordered by `count` or a key. A sort or group takes only a single-value pointer.
151
+ `limit`, at most 1,000 whatever a query names, bounds the Documents or the groups, and a
152
+ result it cuts short names `next`: the same query with it as `after` reads the next
153
+ window, in the same order, ties included. `total: true` adds `total`, every match's
154
+ count. An observed window hears rows entering, leaving or changing, and `next`, `total`.
151
155
  - **Results and errors.** A result carries no Room Version: read freshness from Rooms and
152
156
  Sync Status. `coverage` names each Room read as `{ room, generation, current }`,
153
157
  `current` false while a newer copy of that Room is being fetched, and the queued changes
@@ -168,9 +172,9 @@ once, by words, from local state, with MiniSearch's defaults. There is no observ
168
172
  prefix matching.
169
173
  - **Narrowing.** `documents` is a Local Query filter, and `collection: true` leaves out
170
174
  what each Room's `typedSelection` roots hold; `conversations` names conversations. All
171
- apply before `limit`, which bounds each list; without it every hit returns. A complete
172
- answer it cuts short names `next`, which `after` takes for the next window of both
173
- lists. `total: true` adds `total`, each list's count.
175
+ apply before `limit`, which bounds each list, at most 1,000 whatever a search names. A
176
+ complete answer it cuts short names `next`, which `after` takes for the next window of
177
+ both lists. `total: true` adds `total`, each list's count.
174
178
  - **Results.** `{ documents, messages, coverage }`, or the same with `pending` naming each
175
179
  Room or conversation the search still waits for: show its hits, ask again, and never
176
180
  read pending as no hits. `coverage` names the Rooms and conversations searched. Each
@@ -184,19 +188,24 @@ once, by words, from local state, with MiniSearch's defaults. There is no observ
184
188
 
185
189
  The MD Runtime owns one durable Room Draft per Room and Path, shared by every App and tab
186
190
  across reloads; a Room the Provider reports lost takes its Room Drafts and queue with it.
187
- Write one with `roomDraft.write(room, path, revision, parts)`, naming the revision you
188
- read or `null`, and every part it now changes: fields, sections and the preamble, or the
189
- whole Markdown, a creation, a move or a removal. A new part names its base, the value you
190
- showed when it was opened, a field's as `{ value }` or `null` for no such field, and keeps
191
- its first base; a binary Path entry's move or removal takes `null`. A write or discard
192
- from an older revision is refused as `stale` with the current Room Draft.
191
+ Write one with `roomDraft.write(room, path, revision, parts)`, naming the revision you read
192
+ or `null`, and every part it now changes: fields, sections and the preamble, or the whole
193
+ Markdown, a creation, a move, into another Room when it names `room`, or a removal. A new
194
+ part names its base, the value you showed when it was opened, a field's as `{ value }` or
195
+ `null` for no such field, and keeps its first base; a binary Path entry's move or removal
196
+ takes `null`. A write or discard from an older revision is refused as `stale` with the
197
+ current Room Draft.
193
198
 
194
199
  Save takes one Room and the Room Drafts of it to save, each with its revision, validates
195
- locally, and on success appends one Change Batch to that Room's queue and removes those
196
- Room Drafts. Refused as `stale`, `changed-underneath` naming each part whose base no
197
- longer matches the visible state, or a local validation rule, it creates nothing and
198
- leaves every Room Draft. A directory move or removal is that part on each Document and
199
- binary Path entry beneath it, saved together.
200
+ locally, and on success appends one Change Batch to that Room's queue and removes those Room
201
+ Drafts. Refused as `stale`, `changed-underneath` naming each part whose base no longer
202
+ matches the visible state, or a local validation rule, it creates nothing and leaves every
203
+ Room Draft. A directory move or removal is that part on each Document and binary Path entry
204
+ beneath it, saved together; moves into another Room, saved alone, are one Change Batch in
205
+ both Rooms' queues. `saveParts(room, [{ path, parts }])` saves parts, each Path once and
206
+ each new part with its base, the same way but writes no Room Draft: one held at a saved Path
207
+ stays, one at a moved Path moves with it to a destination that holds none. Never save by
208
+ writing back a Room Draft read before.
200
209
 
201
210
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the queue, drawn
202
211
  over the confirmed layer, until that layer reaches the Room Version it was accepted at.
@@ -206,10 +215,9 @@ Provider's structured refusal code and fields as returned, not known to have app
206
215
  withdrawn locally. The rest of the queue keeps synchronizing, and Sync Status requires
207
216
  attention until each returned Room Draft is saved or discarded. `observe('queue', room)`
208
217
  shows each Pending Change Batch, which keeps no outcome once it leaves. Transport failure,
209
- Provider unavailability and a refusal the Provider marks retryable, until the reset it
210
- names, keep work Pending; the MD Runtime retries the same Change Batch identity and
211
- payload, never infers an outcome from transport uncertainty, and never combines,
212
- reorders, or rebases.
218
+ Provider unavailability and a refusal marked retryable, until the reset it names, keep
219
+ work Pending; the MD Runtime retries the same Change Batch identity and payload, never
220
+ infers an outcome from transport uncertainty, and never combines, reorders, or rebases.
213
221
 
214
222
  On a Site, every Save stays in the visitor's browser: write grants and revisions do not
215
223
  refuse it, and its Pending Change shows in every query and across reloads until the
@@ -264,13 +272,10 @@ peer dependency. `useObserve(client, topic, ...input)` takes the arguments of `o
264
272
  and returns `{ state: 'loading' }` until the topic's first value arrives, then `{ state:
265
273
  'ready', value }`, re-rendering on each change; a `null` client stays loading.
266
274
  `useSave(client)` returns `busy`, the last `outcome` or `failure`, and `save(room,
267
- roomDrafts)`, which writes each Path's parts onto its Room Draft, keeping their bases, and
268
- saves them together: a refused Save leaves the Room Drafts to save again or discard, and a
269
- failure is recorded and rejects; `saveRoomDrafts(client, room, roomDrafts)` is that save
270
- outside a component. `saveWritten(room, roomDrafts)` saves Room Drafts the App wrote
271
- itself, each named with the revision its last write returned: one another tab wrote since
272
- is refused as `stale`, and nothing is saved. A react-admin or Refine App uses the data
273
- providers of `@agentshouse/mdruntime-families`.
275
+ parts)`, which saves through `saveParts` and rejects with a recorded failure.
276
+ `saveWritten(room, roomDrafts)` saves Room Drafts the App wrote, each named with the
277
+ revision its last write returned: one another tab wrote since is refused as `stale`, and
278
+ nothing is saved. React-admin and Refine Apps use `@agentshouse/mdruntime-families`.
274
279
 
275
280
  ## The Chat
276
281
 
package/dist/actions.d.ts CHANGED
@@ -6,10 +6,11 @@ type Operated = {
6
6
  type ConversationControl = Operated & {
7
7
  readonly conversation: string;
8
8
  };
9
- type SentFile = FileDeclaration & {
10
- readonly blob: Blob;
11
- };
12
9
  export type AppInputs = {
10
+ readonly 'conversation.attach': FileDeclaration & {
11
+ readonly room: string;
12
+ readonly blob: Blob;
13
+ };
13
14
  readonly 'conversation.answer': ConversationControl & {
14
15
  readonly answer: {
15
16
  readonly interaction_id: string;
@@ -25,11 +26,16 @@ export type AppInputs = {
25
26
  readonly 'conversation.kill': ConversationControl;
26
27
  readonly 'conversation.send': ConversationControl & {
27
28
  readonly operation_id: string;
28
- readonly text?: string;
29
- readonly files?: readonly SentFile[];
29
+ readonly text: string;
30
+ };
31
+ readonly 'trigger.list': {
32
+ readonly room_refs: readonly string[];
30
33
  };
31
34
  };
32
35
  export type AppAnswers = {
36
+ readonly 'conversation.attach': {
37
+ readonly path: string;
38
+ };
33
39
  readonly 'conversation.history': ConversationHistories;
34
40
  };
35
41
  export type AppAnswerAdditions = {
@@ -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,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MAAM,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE3D,CAAC;AAEF,eAAO,MAAM,WAAW,WAAW,CAAC;AAEpC,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAE5D,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC,CAAC,CAKhF,CAAC;AAYJ,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,MAAM,GAAG,kBAAkB,CAE3E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAKvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAQvB;AA6ED,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF;AAyID,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
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,16 +12,18 @@ 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
  }
21
23
  const APP_ACTS = {
22
24
  'access.read': mapped('rooms/access/read'),
23
25
  'conversation.answer': mapped('conversations/interaction/answer', answerBody),
26
+ 'conversation.attach': carried('conversations/attach', attachAction, undefined, 'room'),
24
27
  'conversation.create': carried('conversations/create', createAction),
25
28
  'conversation.delete': mapped('conversations/delete', controlBody),
26
29
  'conversation.history': carried('conversations/history', historyAction, ['conversations']),
@@ -28,6 +31,7 @@ const APP_ACTS = {
28
31
  'conversation.kill': mapped('conversations/kill', controlBody),
29
32
  'conversation.markDone': mapped('conversations/done'),
30
33
  'conversation.rename': mapped('conversations/rename'),
34
+ 'conversation.retry': mapped('conversations/retry'),
31
35
  'conversation.send': carried('conversations/send', sendAction),
32
36
  'conversation.setOption': mapped('conversations/option'),
33
37
  'feature.list': mapped('apps/features/read'),
@@ -43,7 +47,7 @@ const APP_ACTS = {
43
47
  'routineAllowance.list': mapped('routines/allowance'),
44
48
  'routineRequest.list': mapped('routines/requests'),
45
49
  'storage.read': mapped('storage/inventory'),
46
- 'trigger.list': mapped('triggers/read'),
50
+ 'trigger.list': carried('triggers/read', triggersAction, ['room_refs'], 'room_refs'),
47
51
  'triggerOccurrence.list': mapped('triggers/fired'),
48
52
  };
49
53
  export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
@@ -53,15 +57,15 @@ export const HOUSE_SITE_ACTS = {
53
57
  };
54
58
  export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
55
59
  const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
60
+ const APP_ROOMS = new Map(Object.entries(APP_ACTS).flatMap(([name, act]) => act.room === undefined ? [] : [[name, act.room]]));
56
61
  export function houseConversationAgents(locator) {
57
62
  return { locator, type: 'house-agent', identity: 'agent', name: 'name', retired: 'retired' };
58
63
  }
59
64
  export function declaredActions(routes) {
60
- return routes.map((route) => ({
61
- name: APP_NAMES.get(route) ?? route,
62
- inputShape: {},
63
- resultKind: 'house',
64
- }));
65
+ return routes.map((route) => {
66
+ const name = APP_NAMES.get(route) ?? route;
67
+ return { name, inputShape: {}, resultKind: 'house', room: APP_ROOMS.get(name) ?? 'room_ref' };
68
+ });
65
69
  }
66
70
  export function houseAction(transport, request) {
67
71
  if (Object.hasOwn(APP_ACTS, request.name)) {
@@ -179,106 +183,74 @@ async function recordsAction(transport, route, input, name) {
179
183
  async function carry(transport, route, name, input) {
180
184
  return actionOutcome(await transport.door(route, input), name);
181
185
  }
182
- function sendFile(entry) {
183
- const file = record(entry);
184
- const name = text(file, 'name');
185
- const bytes = file.byteLength;
186
- const sha256 = text(file, 'contentHash');
187
- if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
188
- return null;
189
- const mediaType = text(file, 'mediaType');
190
- const width = file.width;
191
- const height = file.height;
192
- return {
193
- name,
194
- media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
195
- bytes,
196
- sha256,
197
- ...(typeof width === 'number' && typeof height === 'number'
198
- ? { dimensions: { width, height } }
199
- : {}),
200
- };
201
- }
202
- function sendFiles(input) {
203
- const files = record(input).files;
204
- if (files === undefined)
205
- return [];
206
- if (!Array.isArray(files))
207
- return null;
208
- const declared = [];
209
- for (const entry of files) {
210
- const file = sendFile(entry);
211
- if (file === null)
212
- return null;
213
- declared.push(file);
214
- }
215
- return declared;
216
- }
217
186
  function sendBody(input) {
218
- const files = sendFiles(input);
219
187
  const operation = text(input, 'operation_id');
220
- if (files === null || operation === undefined)
188
+ const said = text(input, 'text');
189
+ if (operation === undefined || said === undefined)
221
190
  return null;
222
- const textValue = text(input, 'text');
223
- return {
224
- conversation_id: text(input, 'conversation'),
225
- operation_id: operation,
226
- ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
227
- ...(files.length === 0 ? {} : { files }),
228
- };
191
+ return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
192
+ }
193
+ async function sendAction(transport, route, input, name) {
194
+ const body = sendBody(input);
195
+ if (body === null)
196
+ return malformed();
197
+ const outcome = actionOutcome(await transport.door(route, body), name);
198
+ if (outcome.kind !== 'action')
199
+ return outcome;
200
+ return { ...outcome, result: withTurn(outcome.result) };
229
201
  }
230
- async function fileBytes(file) {
231
- const blob = record(file).blob;
232
- if (blob === undefined || typeof blob !== 'object' || blob === null)
202
+ function attachBody(input) {
203
+ const room = text(input, 'room');
204
+ const name = text(input, 'name');
205
+ const sha256 = text(input, 'contentHash');
206
+ const bytes = record(input).byteLength;
207
+ if (room === undefined || name === undefined || sha256 === undefined)
233
208
  return null;
234
- if (!('arrayBuffer' in blob) || typeof blob.arrayBuffer !== 'function')
209
+ if (typeof bytes !== 'number')
235
210
  return null;
236
- return new Uint8Array(await blob.arrayBuffer());
211
+ const mediaType = text(input, 'mediaType');
212
+ return {
213
+ room_ref: room,
214
+ name,
215
+ bytes,
216
+ sha256,
217
+ media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
218
+ };
237
219
  }
238
- function uploadGrant(entry) {
239
- if (!('upload' in record(entry)))
240
- return 'absent';
241
- const upload = record(record(entry).upload);
220
+ function uploadGrant(answer) {
221
+ const upload = record(record(answer).upload);
242
222
  if (upload.method !== 'POST')
243
223
  return null;
244
224
  if (typeof upload.operation !== 'string' || typeof upload.url !== 'string')
245
225
  return null;
246
- return { method: 'POST', operation: upload.operation, url: upload.url };
247
- }
248
- async function uploadFiles(transport, input, result) {
249
- const sent = record(result).files;
250
- if (!Array.isArray(sent))
251
- return true;
252
- const files = Array.isArray(record(input).files) ? record(input).files : [];
253
- for (const [index, entry] of sent.entries()) {
254
- const grant = uploadGrant(entry);
255
- if (grant === 'absent')
256
- continue;
257
- const bytes = index < files.length ? await fileBytes(files[index]) : null;
258
- if (grant === null || bytes === null)
259
- return false;
260
- const answer = await transport.transfer({
261
- act: 'conversation_file_upload',
262
- url: grant.url,
263
- body: bytes,
264
- operation: grant.operation,
265
- });
266
- if (answer.status !== 200)
267
- return false;
268
- }
269
- return true;
226
+ return { operation: upload.operation, url: upload.url };
270
227
  }
271
- async function sendAction(transport, route, input, name) {
272
- const body = sendBody(input);
273
- if (body === null)
228
+ async function attachAction(transport, route, input, name) {
229
+ const body = attachBody(input);
230
+ const blob = record(input).blob;
231
+ if (body === null || !(blob instanceof Blob))
274
232
  return malformed();
275
233
  const outcome = actionOutcome(await transport.door(route, body), name);
276
234
  if (outcome.kind !== 'action')
277
235
  return outcome;
278
- if (!(await uploadFiles(transport, input, outcome.result))) {
236
+ const grant = uploadGrant(outcome.result);
237
+ if (grant === null)
279
238
  return { kind: 'transport-uncertainty' };
239
+ const sent = await transport.transfer({
240
+ act: 'file_upload',
241
+ url: grant.url,
242
+ body: new Uint8Array(await blob.arrayBuffer()),
243
+ operation: grant.operation,
244
+ });
245
+ if (sent.status !== 200) {
246
+ const refusal = doorRefusal(sent.body);
247
+ return refusal === null ? { kind: 'transport-uncertainty' } : { kind: 'rejected', ...refusal };
280
248
  }
281
- return { ...outcome, result: withTurn(outcome.result) };
249
+ const path = text(sent.body, 'path');
250
+ if (path === undefined)
251
+ return { kind: 'transport-uncertainty' };
252
+ const result = { path };
253
+ return { kind: 'action', result };
282
254
  }
283
255
  function historyCursor(value) {
284
256
  const acceptedAt = text(value, 'accepted_at');
@@ -302,19 +274,12 @@ export function acceptedMessage(entry) {
302
274
  const cursor = historyCursor(entry);
303
275
  if (cursor === null)
304
276
  return null;
305
- const message = structuredClone(record(entry));
306
- const referrer = { message: cursor.message_id };
307
277
  return {
308
278
  identity: cursor.message_id,
309
279
  turn: text(entry, 'turn_id') ?? cursor.message_id,
310
280
  position: position(cursor),
311
281
  text: text(entry, 'text') ?? '',
312
- message: Array.isArray(message.files)
313
- ? {
314
- ...message,
315
- files: message.files.map((file) => ({ ...record(file), referrer })),
316
- }
317
- : message,
282
+ message: structuredClone(record(entry)),
318
283
  };
319
284
  }
320
285
  function historyPage(entry) {
@@ -351,6 +316,22 @@ function historyAsks(input) {
351
316
  }
352
317
  return asks;
353
318
  }
319
+ async function triggersAction(transport, route, input, name) {
320
+ const asked = record(input).room_refs;
321
+ if (!Array.isArray(asked) || asked.length === 0)
322
+ return malformed();
323
+ const rooms = [];
324
+ for (let at = 0; at < asked.length; at += TRIGGER_ROOMS) {
325
+ const outcome = actionOutcome(await transport.door(route, { room_refs: asked.slice(at, at + TRIGGER_ROOMS) }), name);
326
+ if (outcome.kind !== 'action')
327
+ return outcome;
328
+ const answered = record(outcome.result).rooms;
329
+ if (!Array.isArray(answered))
330
+ return { kind: 'transport-uncertainty' };
331
+ rooms.push(...answered);
332
+ }
333
+ return { kind: 'action', result: { rooms } };
334
+ }
354
335
  async function historyAction(transport, route, input, name) {
355
336
  const asks = historyAsks(input);
356
337
  if (asks === null)
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAKV,OAAO,EACP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AA4ChC,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,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAsErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAyiBpF"}
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,EAkBd,MAAM,wBAAwB,CAAC;AA+ChC,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;AAyFrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA+nBpF"}