@agentshouse/mdruntime-adapter 0.1.0-c7d6f34caf6de → 0.1.0-c7f74135dab7e

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
@@ -1,25 +1,24 @@
1
1
  # Instructions for the App Creator's agent
2
2
 
3
- These instructions address an agent in an environment with Git. Obtain the
4
- App Repository, change it, build, and push. They are documentation, not enforcement.
3
+ These instructions address an agent in an environment with Git. Obtain the App
4
+ Repository, change it, build, and push. They are documentation, not enforcement.
5
5
 
6
6
  ## The MD Runtime API
7
7
 
8
8
  App code reaches the MD Runtime through the remote client. The surfaces are
9
9
  Rooms, Query, Search, Observe, Types, Room Draft, Save, History, the binary file
10
- reads, Call, Reached, Log,
11
- the reported persistence answer, reauthorization, conversation, the chat draft,
12
- and Presentation State. Sync Status, the Service Mode, the storage-loss
13
- statement, the deployment facts and the signed-in member are observations only.
10
+ reads, Call, Reached, Log, the reported persistence answer, reauthorization,
11
+ conversation, the chat draft, and Presentation State. Sync Status, the Service
12
+ Mode, the storage-loss statement, the deployment facts and the signed-in member
13
+ are observations only.
14
14
 
15
15
  The host attaches each port with its reach, and every member and observation
16
16
  answers within it: a Room outside it answers as one the replica does not hold,
17
17
  Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
18
  shows only those Documents and the Types of the models that govern them, and
19
19
  without conversations the conversation members, the chat draft and the
20
- conversation observation hold none.
21
- A change of the reach reaches every open observation as its new value, a query
22
- keeping every unchanged Document the same object.
20
+ conversation observation hold none. A change of the reach reaches every open
21
+ observation as its new value, a query keeping unchanged Documents the same objects.
23
22
 
24
23
  Every `observe` resolves, once its first value has arrived, to a handle:
25
24
  `current()` is the latest complete value, `subscribe(listener)` hears each later
@@ -28,51 +27,44 @@ Closing the port ends every handle and rejects every pending call and
28
27
  observation; a client that reconnects observes again.
29
28
 
30
29
  `observe('agents')` answers every Agent a new conversation can go to, each
31
- `{ identity, name }`, whether or not it has a conversation yet.
32
- Each conversation the Provider's conversation list names is held complete in the
33
- browser. `conversation.list()` and `observe('conversations')` answer each with its
34
- Agent's identity and name, its name, created and finished times, last outcome and live
35
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
36
- and `started`, when the running turn began, or `null`.
37
- Observe one with `observe('conversation', id, { limit })`: the view
38
- holds its latest `limit` messages, or all of them, oldest first, its chat
39
- draft, and what the Provider streams for it whether or not anything views it:
40
- the running `turn` with its message parts and its context in use and window, the
41
- open questions, the process state, and the CLI's commands and options. These live
42
- only in memory: the message accepted under the turn's id replaces the running turn,
43
- and none of them is stored or searchable.
44
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
45
- sending it is a Provider Action that needs the Provider reachable and is never
46
- queued.
47
-
48
- A binary file at a Path of a Room is a binary Path entry. Query lists it by
49
- `path` with its `binaryFile` record and never its bytes: `{ state: 'accepted',
50
- revision, path, fileRef, byteLength, mediaType, sha256 }`, or, from a Save until
51
- the Provider accepts it, `{ state: 'pending', localId, path, byteLength,
52
- mediaType, sha256 }` with no revision. Write one with a Room Draft whose only part
53
- is `file: { blob }`, a `Blob` whose `type` is its media type; Save keeps the bytes
54
- in its Pending Change, works offline, and the record turns accepted with the
55
- Provider's revision once the Pending Change is accepted. Move or remove an
56
- accepted one as a Document. Move or remove a pending one the same way, before or
57
- after Save: the Room Draft or its queued Pending Change carries the bytes to the
58
- new Path or drops them, and once that Pending Change has gone to the Provider
59
- Save refuses it as `unknown-revision` until it is accepted. Read the bytes with
60
- `binaryFile.read(room, path)`: a pending record answers its saved bytes, and
61
- every read of an accepted one asks the Provider again and keeps nothing. Pass a
62
- History revision as `binaryFile.read(room, path, revision)` to open that
63
- revision, a removed file's last one included. Text, a Record attachment or a conversation
64
- message may name a file directly by its `fileRef`; read that file with
65
- `binaryFile.readReference({ fileRef, referrer })`, where the referrer is the
66
- `referrer` the Provider gave beside the reference, or `{ room, path }` of the
67
- document whose text names it. Both answer `{ kind: 'binary', blob }` or a
68
- refusal or failure. History of a binary Path lists each revision's
69
- `binaryFile` metadata without bytes.
30
+ `{ identity, name }`, whether or not it has a conversation yet. Each conversation
31
+ the Provider's conversation list names is held complete in the browser.
32
+ `conversation.list()` and `observe('conversations')` answer each with its Agent's
33
+ identity and name, its name, created and finished times, last outcome and live
34
+ `state`: `asking` while a question waits, `working` while a turn runs, else
35
+ `idle`, and `started`, when the running turn began, or `null`. Observe one with
36
+ `observe('conversation', id, { limit })`: the view holds its latest `limit`
37
+ messages, or all of them, oldest first, its chat draft, and what the Provider
38
+ streams for it whether or not anything views it: the running `turn` with its
39
+ message parts and its context in use and window, the open questions, the process
40
+ state, and the CLI's commands and options. These live only in memory: the
41
+ message accepted under the turn's id replaces the running turn, and none of them
42
+ is stored or searchable. `chatDraft.write` and `chatDraft.discard` keep what the
43
+ App Creator composes; sending it is a Provider Action that needs the Provider
44
+ reachable and is never queued.
45
+
46
+ A binary file at a Path is a binary Path entry. Query lists it by `path`, and
47
+ History each of its revisions, with its `binaryFile` record and never its bytes:
48
+ `{ state: 'accepted', revision, path, fileRef, byteLength, mediaType, sha256 }`,
49
+ or, from a Save until the Provider accepts it, `{ state: 'pending', localId,
50
+ path, byteLength, mediaType, sha256 }`. Write one with a Room Draft whose only
51
+ part is `file: { blob }`, the `Blob`'s `type` its media type: Save keeps the
52
+ bytes in its Pending Change, offline too, and acceptance gives the record the
53
+ Provider's revision. Move or remove one as a Document, a pending one before or
54
+ after Save too, its bytes following; once its Pending Change has gone to the
55
+ Provider, Save refuses that as `unknown-revision` until it is accepted.
56
+ `binaryFile.read(room, path, revision?)` answers a pending record's saved bytes,
57
+ or asks the Provider again on every read of an accepted one or of a History
58
+ revision, a removed file's last included, keeping nothing. Text, a Record
59
+ attachment or a conversation message may name a file by its `fileRef`; read it
60
+ with `binaryFile.readReference({ fileRef, referrer })`, the referrer being the
61
+ `referrer` the Provider gave beside it, or `{ room, path }` of the document whose
62
+ text names it. Both answer `{ kind: 'binary', blob }` or a refusal or failure.
70
63
 
71
64
  Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
72
- touch the network.
73
- History, the binary file reads and Call go to the Provider through the Adapter. Call takes the Action names
74
- the Adapter declares; any other name answers `undeclared` without reaching the
75
- Provider. A Call result whose
65
+ touch the network. History, the binary file reads and Call go to the Provider
66
+ through the Adapter. Call takes the Action names the Adapter declares; any other
67
+ name answers `undeclared` without reaching the Provider. A Call result whose
76
68
  effect the Provider places in a Room carries `at`, that Room and Room Version;
77
69
  `reached(room, roomVersion)` answers whether the Room's confirmed state has
78
70
  reached it, and the MD Runtime keeps refreshing that Room until it has;
@@ -81,33 +73,26 @@ that document was written at a later Room Version. Each History revision
81
73
  names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
82
74
  History of a Path no current document holds answers the removed document's
83
75
  revisions with `deleted: true`, newest first; that revision is what a link to
84
- the Path opens. Every
85
- member of the
86
- client is asynchronous. Results are detached snapshots. Nothing in this
87
- surface returns the authorization, performs a request the App's code
88
- composes, or exposes the browser store.
89
-
90
- Every refusal and failure carries `code` and `retryable`: each Call and History answer
91
- other than its result, a refused Save or Room Draft write, a returned Room Draft's
92
- reason, a Room's refusal and the Connection Refusal, and every error a member rejects
93
- with, beside its message. A Provider refusal carries the Provider's own `retryable`.
94
- Every code and every value the API answers is open: handle one you do not know by its
95
- `code` and `retryable`.
96
-
97
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
98
- opaque value using the host's contract.
99
-
100
- `observe('member')` answers who uses the App: the User the Provider signed in,
101
- `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
102
- whose `change.author.id` equals its `id` is that User's own. It is `null` until
103
- the Provider first names one, and where it names none, such as a Site. The
104
- MD Runtime keeps it with the Local Replicas, so it answers offline once known,
105
- and every port hears the next member the Provider names; signing out answers
106
- `null`, then ends the observation with the authorization. It is the only way App code learns who
107
- uses it.
108
-
109
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
110
- ships in no bundle.
76
+ the Path opens. Every member of the client is asynchronous. Results are
77
+ detached snapshots. Nothing in this surface returns the authorization, performs
78
+ a request the App's code composes, or exposes the browser store.
79
+
80
+ Every refusal and failure carries `code` and `retryable`: each Call and History
81
+ answer other than its result, a refused Save or Room Draft write, a returned Room
82
+ Draft's reason, a Room's refusal and the Connection Refusal, and every error a
83
+ member rejects with, beside its message. A Provider refusal carries the
84
+ Provider's own `retryable`. Every code and every value the API answers is open:
85
+ handle one you do not know by its `code` and `retryable`.
86
+
87
+ Read the deployment facts with `observe('deployment-facts')`, an opaque value
88
+ the host's contract interprets. `observe('member')` answers who uses the App:
89
+ the User the Provider signed in, `{ kind: 'user', id, name }` in the shape of a
90
+ change's `author`, so a Document whose `change.author.id` equals its `id` is that
91
+ User's own. It is `null` until the Provider first names one, and where it names
92
+ none, such as a Site. The MD Runtime keeps it with the Local Replicas, so it
93
+ answers offline once known, and every port hears the next member the Provider
94
+ names; signing out answers `null`, then ends the observation with the
95
+ authorization. It is the only way App code learns who uses it.
111
96
 
112
97
  ## Local Query rules
113
98
 
@@ -125,13 +110,12 @@ data:
125
110
  pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
126
111
  when any item satisfies it. A bare value is equality; the operators are `$eq`,
127
112
  `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
128
- `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
129
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
130
- text and `$size: 0` an empty list. A date compares in calendar order and never
131
- with a date-time. A reference compares by the Room Path it resolves to.
132
- Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
133
- values. There is no text containment or regular
134
- expression.
113
+ `$exists`. Equality on a list asks whether it contains the value. Missing,
114
+ null and empty differ: `$exists: false` keeps a missing field, `null` an
115
+ explicit null, `''` empty text and `$size: 0` an empty list. A date compares
116
+ in calendar order and never with a date-time. A reference compares by the Room
117
+ Path it resolves to. Untyped frontmatter, and a value under `oneOf` or a
118
+ conditional, is plain values. There is no text containment or regular expression.
135
119
  - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
136
120
  reference at pointer `field`, at any depth, points to a matching Document of the
137
121
  same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
@@ -165,8 +149,7 @@ data:
165
149
  ## Local Search rules
166
150
 
167
151
  `search({ text, documents, conversations, limit })` answers once, by words, from
168
- local state, with MiniSearch at its default configuration. There is no observed
169
- search.
152
+ local state, with MiniSearch's defaults. There is no observed search.
170
153
 
171
154
  - **What is found.** A Document by its field values, its sections' headings and
172
155
  text, its preamble and its Path; a message by its text. Frontmatter keys, Room
@@ -184,17 +167,16 @@ search.
184
167
 
185
168
  ## Room Draft, Save, and outcome rules
186
169
 
187
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
188
- tab. It is durable: it survives reload and navigation. A Room that Discovery
189
- stops listing takes its Room Drafts and its queue with it.
190
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
191
- the revision you read, or `null` when there was none, and every part it should
192
- now change: fields, sections and the preamble, or the whole Markdown, a
193
- creation, a move, or a removal. A part new to the Room Draft names its base,
194
- the value you showed when it was opened; the MD Runtime keeps a part's first
195
- base. A binary link target has a Room Draft too, for a move or a removal, with
196
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
197
- the current Room Draft; read it and write again.
170
+ The MD Runtime owns one Room Draft per Room and Path, shared by every App and tab.
171
+ It is durable: it survives reload and navigation. A Room that Discovery stops
172
+ listing takes its Room Drafts and its queue with it. Write a Room Draft with
173
+ `roomDraft.write(room, path, revision, parts)`, naming the revision you read, or
174
+ `null` when there was none, and every part it should now change: fields, sections
175
+ and the preamble, or the whole Markdown, a creation, a move, or a removal. A part
176
+ new to the Room Draft names its base, the value you showed when it was opened; the
177
+ MD Runtime keeps a part's first base; a binary Path entry's move or removal takes
178
+ `null` as its base. A write or a discard from an older revision is refused as
179
+ `stale` with the current Room Draft; read it and write again.
198
180
 
199
181
  Save takes one Room and the Room Drafts of it to save, each with its revision,
200
182
  validates locally, and on success appends one Change Batch to that Room's
@@ -202,7 +184,7 @@ queue and removes those Room Drafts. It is refused with the `code` `stale`,
202
184
  `changed-underneath` naming each part whose base no longer matches the visible
203
185
  state, or a local validation rule, and then creates nothing and leaves every
204
186
  Room Draft in place. A directory move or removal is a move or removal part on
205
- each Document and binary link target beneath it, saved together.
187
+ each Document and binary Path entry beneath it, saved together.
206
188
 
207
189
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
208
190
  queue, drawn over the confirmed layer, until the confirmed layer reaches the
@@ -220,19 +202,17 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
220
202
  never infers an outcome from transport uncertainty. The MD Runtime never
221
203
  combines, reorders, or rebases.
222
204
 
223
- On a Site, every Save stays in the visitor's browser. Write grants and
224
- revisions do not refuse it, and its Pending Change shows in every query and
225
- across reloads until the browser's storage is cleared. It is never sent:
226
- `observe('queue', room)` shows it `local`, and Sync Status never waits on it.
227
- Once the Room changes so that it no longer applies, it leaves the queue and
228
- returns no Room Draft.
205
+ On a Site, every Save stays in the visitor's browser. Write grants and revisions
206
+ do not refuse it, and its Pending Change shows in every query and across reloads
207
+ until the browser's storage is cleared. It is never sent: `observe('queue', room)`
208
+ shows it `local`, and Sync Status never waits on it. Once the Room changes so that
209
+ it no longer applies, it leaves the queue and returns no Room Draft.
229
210
 
230
- `observe('service-mode')` answers the Provider's Service
231
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
232
- its Change Batch waits unsent, and the queue is submitted in order once the
233
- Provider reopens writes. An Action is never held: a write the Provider refuses
234
- for the halt returns that refusal to its caller. Show the Provider as read-only
235
- instead of retrying.
211
+ `observe('service-mode')` answers the Provider's Service Mode, `open` or
212
+ `write-halted`. While writes are halted, Save still succeeds, its Change Batch
213
+ waits unsent, and the queue is submitted in order once the Provider reopens
214
+ writes. An Action is never held: a write the Provider refuses for the halt returns
215
+ that refusal to its caller. Show the Provider as read-only instead of retrying.
236
216
 
237
217
  ## The neutrality rule
238
218
 
@@ -264,10 +244,12 @@ the network. Data lives only in the App Creator's browser and with the Provider.
264
244
 
265
245
  App code takes the client its host hands it: in House, `houseBridge().runtime`
266
246
  from `@agentshouse/app-bridge` resolves to the client House built into the page.
267
- It never constructs a Runtime or a client. It imports only types from
268
- `@agentshouse/mdruntime/client`, does not call `connectMdRuntime` or
269
- `serveMdRuntime`, and does not import the package main, the host entry, or the
270
- Adapter package. Hosts and tests use those entries; the served App does not.
247
+ It imports only types from `@agentshouse/mdruntime/client`, never calls
248
+ `connectMdRuntime` or `serveMdRuntime`, and never imports the package main, the
249
+ host entry or the Adapter package, which hosts and tests use. The in-memory
250
+ Adapter at `@agentshouse/mdruntime/memory` is for tests and ships in no bundle.
251
+ A Site's page fills its Entry Data Contract's `{"$param": name}` arguments with
252
+ `boundQuery` from `@agentshouse/mdruntime/entry`, as House did for its HTML.
271
253
 
272
254
  A React App may observe and save through `@agentshouse/mdruntime/react`, which
273
255
  names React as a peer dependency. `useObserve(client, topic, ...input)` takes
@@ -284,9 +266,8 @@ through the data providers of `@agentshouse/mdruntime-families`.
284
266
 
285
267
  ## The Chat
286
268
 
287
- `@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App.
288
- Its required peers are React, React DOM and `@assistant-ui/react`: add React as
289
- a dependency, also in an App not written in React.
269
+ `@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App; add
270
+ React as a dependency in any App, with React DOM and `@assistant-ui/react`.
290
271
 
291
272
  Place the ready chat with `<Chat client={runtime} conversation={id}
292
273
  agent={agent} width="1/3" showChats />`: `conversation` opens one, `null` for a
package/dist/actions.d.ts CHANGED
@@ -24,6 +24,7 @@ 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
  };
@@ -32,11 +33,32 @@ export type AppAnswers = {
32
33
  readonly 'conversation.history': ConversationHistories;
33
34
  };
34
35
  export type AppAnswerAdditions = {
36
+ readonly 'conversation.create': {
37
+ readonly conversation: string;
38
+ };
35
39
  readonly 'conversation.send': {
36
40
  readonly turn: string;
37
41
  };
42
+ readonly 'record.list': {
43
+ readonly attachments: readonly {
44
+ readonly referrer: {
45
+ readonly room_ref: string;
46
+ readonly record: string;
47
+ };
48
+ }[];
49
+ readonly records: readonly {
50
+ readonly attachments: readonly {
51
+ readonly referrer: {
52
+ readonly room_ref: string;
53
+ readonly record: string;
54
+ };
55
+ }[];
56
+ }[];
57
+ };
38
58
  };
39
59
  export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
60
+ export declare const SITE_SUBMIT = "submit";
61
+ export declare const HOUSE_SITE_ACTS: Readonly<Record<string, string>>;
40
62
  export declare const HOUSE_APP_BATCHES: Readonly<Partial<Record<string, readonly string[]>>>;
41
63
  export declare function houseConversationAgents(locator: string): ConversationAgents;
42
64
  export declare function declaredActions(routes: readonly string[]): readonly ActionDeclaration[];
@@ -1 +1 @@
1
- {"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,kBAAkB,EACvB,KAAK,qBAAqB,EAE1B,KAAK,0BAA0B,EAC/B,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAQtE,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAEnD,KAAK,mBAAmB,GAAG,QAAQ,GAAG;IAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;CAAE,CAAC;AAExE,KAAK,QAAQ,GAAG,eAAe,GAAG;IAAE,QAAQ,CAA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iBAAE,CAAC;aAC3E,EAAE,CAAC;SACL,EAAE,CAAC;KACL,CAAC;CACH,CAAC;AAwEF,eAAO,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;AAMJ,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;AA6ED,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAOjF;AAuKD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAiBtE"}
package/dist/actions.js CHANGED
@@ -47,6 +47,10 @@ const APP_ACTS = {
47
47
  'triggerOccurrence.list': mapped('triggers/fired'),
48
48
  };
49
49
  export const HOUSE_APP_ACTS = Object.fromEntries(Object.entries(APP_ACTS).map(([name, act]) => [name, act.door]));
50
+ export const SITE_SUBMIT = 'submit';
51
+ export const HOUSE_SITE_ACTS = {
52
+ [SITE_SUBMIT]: 'site/submission',
53
+ };
50
54
  export const HOUSE_APP_BATCHES = Object.fromEntries(Object.entries(APP_ACTS).flatMap(([name, act]) => act.batched === undefined ? [] : [[name, act.batched]]));
51
55
  const APP_NAMES = new Map(Object.entries(APP_ACTS).map(([name, act]) => [act.door, name]));
52
56
  export function houseConversationAgents(locator) {
@@ -118,7 +122,12 @@ async function createAction(transport, route, input, name) {
118
122
  return outcome;
119
123
  const held = record(outcome.result);
120
124
  const conversation = text(held, 'conversation_id');
121
- return conversation === undefined ? outcome : { ...outcome, result: { ...held, conversation } };
125
+ return conversation === undefined
126
+ ? outcome
127
+ : {
128
+ ...outcome,
129
+ result: { ...held, conversation },
130
+ };
122
131
  }
123
132
  function withTurn(body) {
124
133
  const held = record(body);
@@ -143,7 +152,10 @@ function referredRecord(view, roomRef) {
143
152
  const held = record(view);
144
153
  if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
145
154
  return view;
146
- const referrer = { room_ref: roomRef, record: held.record };
155
+ const referrer = {
156
+ room_ref: roomRef,
157
+ record: held.record,
158
+ };
147
159
  return {
148
160
  ...held,
149
161
  attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
@@ -202,12 +214,13 @@ function sendFiles(input) {
202
214
  }
203
215
  function sendBody(input) {
204
216
  const files = sendFiles(input);
205
- if (files === null)
217
+ const operation = text(input, 'operation_id');
218
+ if (files === null || operation === undefined)
206
219
  return null;
207
220
  const textValue = text(input, 'text');
208
221
  return {
209
222
  conversation_id: text(input, 'conversation'),
210
- operation_id: operationId(input),
223
+ operation_id: operation,
211
224
  ...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
212
225
  ...(files.length === 0 ? {} : { files }),
213
226
  };
@@ -220,9 +233,6 @@ async function fileBytes(file) {
220
233
  return null;
221
234
  return new Uint8Array(await blob.arrayBuffer());
222
235
  }
223
- function delivered(answer, name) {
224
- return answer.status === 200 ? null : actionOutcome(answer, name);
225
- }
226
236
  function uploadGrant(entry) {
227
237
  if (!('upload' in record(entry)))
228
238
  return 'absent';
@@ -233,36 +243,28 @@ function uploadGrant(entry) {
233
243
  return null;
234
244
  return { method: 'POST', operation: upload.operation, url: upload.url };
235
245
  }
236
- async function uploadFiles(transport, input, result, name) {
246
+ async function uploadFiles(transport, input, result) {
237
247
  const sent = record(result).files;
238
- if (!Array.isArray(sent) || sent.length === 0)
239
- return null;
248
+ if (!Array.isArray(sent))
249
+ return true;
240
250
  const files = Array.isArray(record(input).files) ? record(input).files : [];
241
251
  for (const [index, entry] of sent.entries()) {
242
252
  const grant = uploadGrant(entry);
243
253
  if (grant === 'absent')
244
254
  continue;
245
- if (grant === null)
246
- return malformed();
247
255
  const bytes = index < files.length ? await fileBytes(files[index]) : null;
248
- if (bytes === null) {
249
- return {
250
- kind: 'rejected',
251
- code: 'conversation_file_descriptor_required',
252
- fields: {},
253
- retryable: false,
254
- };
255
- }
256
- const failed = delivered(await transport.transfer({
256
+ if (grant === null || bytes === null)
257
+ return false;
258
+ const answer = await transport.transfer({
257
259
  act: 'conversation_file_upload',
258
260
  url: grant.url,
259
261
  body: bytes,
260
262
  operation: grant.operation,
261
- }), name);
262
- if (failed !== null)
263
- return failed;
263
+ });
264
+ if (answer.status !== 200)
265
+ return false;
264
266
  }
265
- return null;
267
+ return true;
266
268
  }
267
269
  async function sendAction(transport, route, input, name) {
268
270
  const body = sendBody(input);
@@ -271,9 +273,9 @@ async function sendAction(transport, route, input, name) {
271
273
  const outcome = actionOutcome(await transport.door(route, body), name);
272
274
  if (outcome.kind !== 'action')
273
275
  return outcome;
274
- const uploaded = await uploadFiles(transport, input, outcome.result, name);
275
- if (uploaded !== null)
276
- return uploaded;
276
+ if (!(await uploadFiles(transport, input, outcome.result))) {
277
+ return { kind: 'transport-uncertainty' };
278
+ }
277
279
  return { ...outcome, result: withTurn(outcome.result) };
278
280
  }
279
281
  function historyCursor(value) {
@@ -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,EAiBd,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,CAAA;CAAE,CAAC;AAoEjC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA+gBpF"}