@agentshouse/mdruntime-adapter 0.1.0-c13e5bc38b145 → 0.1.0-c14f4ba3ce8c5
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 +83 -75
- package/dist/actions.d.ts +11 -21
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +59 -127
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +160 -175
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/model.d.ts +5 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/part.d.ts +15 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +82 -0
- package/dist/read.d.ts +37 -21
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +205 -121
- package/dist/room-types.d.ts +6 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +83 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +72 -100
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +16 -1
- package/dist/transport.d.ts +10 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -1
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +13 -17
- package/package.json +3 -3
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -45
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/AGENTS.md
CHANGED
|
@@ -52,28 +52,30 @@ change, and no tab sees it then.
|
|
|
52
52
|
|
|
53
53
|
A binary file at a Path is a binary Path entry. Query lists it by `path`, and History each
|
|
54
54
|
of its revisions, with its `binaryFile` record and never its bytes: `{ state: 'accepted',
|
|
55
|
-
revision, path,
|
|
55
|
+
revision, path, byteLength, mediaType, sha256 }`, or, from a Save until the
|
|
56
56
|
Provider accepts it, `{ state: 'pending', localId, path, byteLength, mediaType, sha256 }`.
|
|
57
57
|
Write one with a Room Draft whose only part is `file: { blob }`, the `Blob`'s `type` its
|
|
58
58
|
media type: Save keeps the bytes in its Pending Change, offline too, and acceptance gives
|
|
59
59
|
the record the Provider's revision. Move or remove one as a Document, a pending one too,
|
|
60
60
|
its bytes following; once its Pending Change has gone to the Provider, Save refuses that
|
|
61
61
|
as `unknown-revision` until it is accepted. `binaryFile.read(room, path, revision?)`
|
|
62
|
-
answers a pending record's saved bytes, or
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
answers a pending record's saved bytes, or an accepted one's or a History revision's, a
|
|
63
|
+
removed file's last included: the first read asks the Provider and the browser keeps the
|
|
64
|
+
bytes, and every later read of that revision, offline too, answers them from the browser.
|
|
65
|
+
Text names a file only by a link to its Path. A read answers
|
|
66
|
+
`{ kind: 'binary', stream, byteLength, mediaType }`, the bytes a `ReadableStream`
|
|
67
|
+
of parts of at most a mebibyte, or a refusal or failure; read the stream to its end, or
|
|
68
|
+
take it whole with `new Response(stream).blob()` where a screen needs one `Blob`.
|
|
68
69
|
|
|
69
70
|
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never touch the
|
|
70
|
-
network; History,
|
|
71
|
+
network; History, a binary file read the browser does not keep yet and Call go to the
|
|
72
|
+
Provider through the Adapter.
|
|
71
73
|
Call takes the Action names the Adapter declares, any other answering `undeclared`. A Call
|
|
72
74
|
result whose effect the Provider places in a Room carries `at`, that Room and Room
|
|
73
75
|
Version: `reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
74
76
|
reached it, refreshing the Room until it has, and `reached(room, roomVersion, path)`
|
|
75
77
|
whether the held copy of that document was written later. A History revision names its
|
|
76
|
-
author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`; History of a Path no
|
|
78
|
+
author, `{ kind: 'user', id }` or `{ kind: 'site' | 'inbox', id, name }`; History of a Path no
|
|
77
79
|
document holds answers the removed document's revisions, newest first, with `deleted:
|
|
78
80
|
true`, which a link to the Path opens. Every member is asynchronous and every result a
|
|
79
81
|
detached snapshot; nothing returns the authorization, performs a request the App's code
|
|
@@ -122,36 +124,38 @@ draw it as loading and observe the query to hear the complete answer. A query is
|
|
|
122
124
|
- **Relations.** Within one Room, `hop: { field, types, where, pathPrefix }` keeps Documents
|
|
123
125
|
whose reference at pointer `field`, at any depth, points to a matching Document, and
|
|
124
126
|
`backlinks` with the same keys those a matching Document references, each once. A body
|
|
125
|
-
link
|
|
126
|
-
|
|
127
|
-
`
|
|
128
|
-
locked.
|
|
127
|
+
link or a `cross_room` reference may name another Room's `/rooms/<handle>/<path>`:
|
|
128
|
+
`resolve(room, path, destination)` answers its `document`, the `deleted` one's last
|
|
129
|
+
`revision`, or `unreadable` where the App does not bind it or it is locked.
|
|
129
130
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
130
|
-
`preamble`, `markdown`, `backlinks`, `change` and `
|
|
131
|
+
`preamble`, `markdown`, `backlinks`, `change`, `fileId` and `revision`, where `fields` is `'all'`
|
|
131
132
|
or a list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
132
133
|
return the frontmatter holding only them, nested as written. A backlink names the
|
|
133
134
|
referring Path, MD Type and the pointer it came from as `field`. Room and Path always
|
|
134
135
|
return; a Markdown Document also returns its MD Type, and at most its first 1,000
|
|
135
136
|
backlinks: a query on the referring field reads the rest. A non-Markdown Document
|
|
136
|
-
returns only Room, Path and a selected `fileId
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
returns only Room, Path and a selected `fileId` and `revision`, a binary Path entry its `binaryFile`
|
|
138
|
+
record too, and a YAML file under `settings/` its text as a selected `markdown`, kept
|
|
139
|
+
out of Search. An unselected part is absent. Select only what a screen shows: a list
|
|
140
|
+
that selects the Markdown hears every edit of it.
|
|
141
|
+
- **Change, file ID and revision.** `change` is `{ author, time }` of the Document's head revision
|
|
142
|
+
as the Provider last delivered it: `author` is `{ kind: 'user' | 'site' | 'inbox', id, name }`, or
|
|
141
143
|
`null` for a write the Provider made itself, and `time` its ISO 8601 change time, or the
|
|
142
144
|
whole change `null` where it delivered no time, as at a Site. `fileId` is the Provider's
|
|
143
145
|
Stable File ID of the file at the Path, or `null`. An unsent edit keeps both, an unsent
|
|
144
146
|
move keeps the change and carries the file ID to the new Path, so a file ID that leaves
|
|
145
147
|
one Path for another is the same file moved, and an unsent creation has neither until it
|
|
146
|
-
is Accepted.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
`
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
148
|
+
is Accepted. `revision` is the Provider's head revision, `null` for an unsent creation or edit,
|
|
149
|
+
and moves with an unsent move. A Room's last change is its Document with the latest `time`.
|
|
150
|
+
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type`, `folder` or `{ field }`: missing
|
|
151
|
+
and null first, last with `nulls: 'last'`, then numbers and booleans, then text by `locale` or
|
|
152
|
+
code point with `stringSort: 'lexical'`, then lists item by item; ties end with Room, then Path.
|
|
153
|
+
`groupBy` by `room`, `type`, `folder` or `{ field }` answers `{ groups: [{ key, count }] }`,
|
|
154
|
+
counted over every match and ordered by `count` or a key. A sort or group takes only a
|
|
155
|
+
single-value pointer. `limit`, at most 1,000 whatever a query names, bounds the Documents or the
|
|
156
|
+
groups, and a result it cuts short names `next`: the same query with it as `after` reads the next
|
|
157
|
+
window, in the same order, ties included. `total: true` adds `total`, every match's count. An
|
|
158
|
+
observed window hears rows entering, leaving or changing, and `next`, `total`.
|
|
155
159
|
- **Results and errors.** A result carries no Room Version: read freshness from Rooms and
|
|
156
160
|
Sync Status. `coverage` names each Room read as `{ room, generation, current }`,
|
|
157
161
|
`current` false while a newer copy of that Room is being fetched, and the queued changes
|
|
@@ -161,28 +165,36 @@ draw it as loading and observe the query to hear the complete answer. A query is
|
|
|
161
165
|
## Local Search rules
|
|
162
166
|
|
|
163
167
|
`search({ text, documents, collection, conversations, limit, after, total })` answers
|
|
164
|
-
once, by words, from
|
|
168
|
+
once, by words, from the full-text index the browser keeps with its local state, so it
|
|
169
|
+
answers at once after a reload. There is no observed search.
|
|
165
170
|
|
|
166
|
-
- **Declaration.** Only an App whose release declares Local Search searches
|
|
167
|
-
|
|
168
|
-
`
|
|
171
|
+
- **Declaration.** Only an App whose release declares Local Search searches; any other
|
|
172
|
+
App's `search` answers the never retryable `undeclared` refusal `search-undeclared`, its
|
|
173
|
+
`fields` naming `local_search`.
|
|
169
174
|
- **What is found.** A Document by its field values, its sections' headings and text, its
|
|
170
175
|
preamble and its Path, and a message by its text, never a frontmatter key, a Room Draft,
|
|
171
|
-
a chat draft or a running turn's parts
|
|
172
|
-
|
|
176
|
+
a chat draft or a running turn's parts. Any word found ranks a hit, more found rank it
|
|
177
|
+
higher, and adjacent words higher still; case and the marks of Latin, Greek and
|
|
178
|
+
Cyrillic letters fold, English word forms stem, the last word also matches as the start
|
|
179
|
+
of a word unless the text ends with a space, and Chinese, Japanese, Korean and Thai text
|
|
180
|
+
matches by character pairs. There is no typo tolerance and no operator syntax.
|
|
173
181
|
- **Narrowing.** `documents` is a Local Query filter, and `collection: true` leaves out
|
|
174
182
|
what each Room's `typedSelection` roots hold; `conversations` names conversations. All
|
|
175
183
|
apply before `limit`, which bounds each list, at most 1,000 whatever a search names. A
|
|
176
184
|
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.
|
|
185
|
+
both lists. `total: true` adds `total`, each list's count. A word in very many Documents
|
|
186
|
+
ranks among a bounded set of them, the Documents of a rarer word of the search always
|
|
187
|
+
among them.
|
|
178
188
|
- **Results.** `{ documents, messages, coverage }`, or the same with `pending` naming each
|
|
179
|
-
Room
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
189
|
+
Room the search still waits for: show its hits, ask again, and never read pending as no
|
|
190
|
+
hits. `coverage` names the Rooms and conversations searched. Each list is ranked by
|
|
191
|
+
`score`, comparable only within it; ties come by `room`, then `path`, or by
|
|
192
|
+
`conversation`, then `identity`. A Document hit names its `room`, `path` and `type`, a
|
|
193
|
+
message hit its `conversation` and `identity`; `matches` maps each word of the search
|
|
194
|
+
to the parts it was found in: `fields`, `sections`, `preamble`, `path` or `text`. A hit
|
|
195
|
+
whose words were found carries `snippet: { part, text, at }`: the part's text around
|
|
196
|
+
the first word found, at most 80 characters on either side, and `at` that word's start
|
|
197
|
+
and end in `text`. Mark the words you show. A bad filter fails as a query does.
|
|
186
198
|
|
|
187
199
|
## Room Draft, Save, and outcome rules
|
|
188
200
|
|
|
@@ -219,19 +231,19 @@ Provider unavailability and a refusal marked retryable, until the reset it names
|
|
|
219
231
|
work Pending; the MD Runtime retries the same Change Batch identity and payload, never
|
|
220
232
|
infers an outcome from transport uncertainty, and never combines, reorders, or rebases.
|
|
221
233
|
|
|
222
|
-
On a Site, every Save stays in the visitor's browser: write grants and revisions do not
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
queue and returns no Room Draft.
|
|
234
|
+
On a Site, every Save stays in the visitor's browser: write grants and revisions do not refuse it,
|
|
235
|
+
and its Pending Change shows in every query and across reloads until the browser's storage is
|
|
236
|
+
cleared. It is never sent: `observe('queue', room)` shows it `local`, Sync Status never waits on
|
|
237
|
+
it, and once the Room no longer lets it apply it leaves the queue and returns no Room Draft.
|
|
227
238
|
|
|
228
|
-
`observe('service-mode')` answers the Provider's Service Mode, `open` or `write-halted`.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
`
|
|
233
|
-
(`
|
|
234
|
-
|
|
239
|
+
`observe('service-mode')` answers the Provider's Service Mode, `open` or `write-halted`. While writes
|
|
240
|
+
are halted, Save succeeds, its Change Batch waits unsent and the queue is submitted in order once writes
|
|
241
|
+
reopen; an Action is never held, and one the halt refuses returns that refusal: show the Provider as
|
|
242
|
+
read-only instead of retrying. `observe('readiness')` tells whether code and bound Rooms are held
|
|
243
|
+
locally (`ready`), each Room's state, each refused Room's file and rule, the persistence answer, `space`
|
|
244
|
+
(`full` once the device's storage refused a write, Save and messages refusing as `durable-write` until
|
|
245
|
+
`retry()` or a later test write finds space, or once the origin refused a newer release), and the
|
|
246
|
+
`installation`'s Rooms, parts, bytes, `received`, `step` and `paused`.
|
|
235
247
|
|
|
236
248
|
## Content safety and launch promises
|
|
237
249
|
|
|
@@ -279,26 +291,22 @@ nothing is saved. React-admin and Refine Apps use `@agentshouse/mdruntime-famili
|
|
|
279
291
|
|
|
280
292
|
## The Chat
|
|
281
293
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
`
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
294
|
+
In House the page's bridge places the Chat, one data layer for every App, which House
|
|
295
|
+
serves with the page and keeps current: install, import and bundle nothing for it, and add
|
|
296
|
+
no dependency. `const chat = await houseBridge.chat.mount(element, options)`, on the bridge
|
|
297
|
+
object House hands the page as `window.houseBridge`, which `houseBridge()` of
|
|
298
|
+
`@agentshouse/app-bridge` returns, draws it in `element` over the App's own client and
|
|
299
|
+
resolves to a handle: `chat.update(options)` replaces its options and `chat.unmount()`
|
|
300
|
+
removes it. `conversation` opens one, `null` for a
|
|
301
|
+
new chat, `agent` is the Agent a new chat goes to, `showChats` adds its conversation list,
|
|
302
|
+
`width` is `full` (the element), or `3/4`, `1/2` or `1/3` of the window docked at its right
|
|
303
|
+
edge, whole on a narrow window, `onOpen` hears each conversation it opens as `{
|
|
304
|
+
conversation, agent }`, and `onLink` takes a link without a scheme in place of the browser.
|
|
305
|
+
Theme its own styles with CSS custom properties on the element or an ancestor:
|
|
306
|
+
`--chat-background`, `--chat-surface`, `--chat-text`, `--chat-text-muted`,
|
|
291
307
|
`--chat-accent`, `--chat-line`, `--chat-attention`, `--chat-danger`, `--chat-font`,
|
|
292
308
|
`--chat-font-mono`, `--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for
|
|
293
|
-
spacing); an unset one keeps House's light or dark look.
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
`ChatInput` and `ChatQuestionCard` with your own design inside a `ChatProvider`, or
|
|
298
|
-
compose assistant-ui's primitives there; `useChat()` gives `send`, the conversations, the
|
|
299
|
-
Agents, questions to `answer`, `options` to `choose`, `commands`, the queue to `edit` or
|
|
300
|
-
`unqueue`, `stop`, `kill` and outcomes; never replace its messages, sending or store. It
|
|
301
|
-
shows a conversation's latest 50 messages, and assistant-ui's `loadEarlier()` the 50
|
|
302
|
-
before, which `ChatMessageList` calls as the reader scrolls back. A secret question is
|
|
303
|
-
never answered here; typed answers live in the Presentation State members named `typed:…`:
|
|
304
|
-
leave them. `Markdown` draws Markdown safely.
|
|
309
|
+
spacing); an unset one keeps House's light or dark look. It shows conversations only where
|
|
310
|
+
the release declares them; otherwise it lists no conversation and no Agent. A secret
|
|
311
|
+
question is never answered here; typed answers live in the Presentation State members named
|
|
312
|
+
`typed:…`: leave them.
|
package/dist/actions.d.ts
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type AcceptedMessage, type ActionDeclaration, type ActionRequest, type ActionResult, type ConversationAgents, type ConversationHistories, type ConversationHistoryRequest, type FileDeclaration } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { HouseDoorAnswer, HouseTransport } from './transport.js';
|
|
3
|
+
export declare const HISTORY_PAGE = 100;
|
|
4
|
+
export declare const TRIGGER_ROOMS = 100;
|
|
3
5
|
type Operated = {
|
|
4
6
|
readonly operation_id?: string;
|
|
5
7
|
};
|
|
6
8
|
type ConversationControl = Operated & {
|
|
7
9
|
readonly conversation: string;
|
|
8
10
|
};
|
|
9
|
-
type SentFile = FileDeclaration & {
|
|
10
|
-
readonly blob: Blob;
|
|
11
|
-
};
|
|
12
11
|
export type AppInputs = {
|
|
12
|
+
readonly 'conversation.attach': FileDeclaration & {
|
|
13
|
+
readonly room: string;
|
|
14
|
+
readonly blob: Blob;
|
|
15
|
+
};
|
|
13
16
|
readonly 'conversation.answer': ConversationControl & {
|
|
14
17
|
readonly answer: {
|
|
15
18
|
readonly interaction_id: string;
|
|
@@ -18,6 +21,7 @@ export type AppInputs = {
|
|
|
18
21
|
};
|
|
19
22
|
readonly 'conversation.create': Operated & {
|
|
20
23
|
readonly agent_id: string;
|
|
24
|
+
readonly replaces?: string;
|
|
21
25
|
};
|
|
22
26
|
readonly 'conversation.delete': ConversationControl;
|
|
23
27
|
readonly 'conversation.history': ConversationHistoryRequest;
|
|
@@ -25,14 +29,16 @@ export type AppInputs = {
|
|
|
25
29
|
readonly 'conversation.kill': ConversationControl;
|
|
26
30
|
readonly 'conversation.send': ConversationControl & {
|
|
27
31
|
readonly operation_id: string;
|
|
28
|
-
readonly text
|
|
29
|
-
readonly files?: readonly SentFile[];
|
|
32
|
+
readonly text: string;
|
|
30
33
|
};
|
|
31
34
|
readonly 'trigger.list': {
|
|
32
35
|
readonly room_refs: readonly string[];
|
|
33
36
|
};
|
|
34
37
|
};
|
|
35
38
|
export type AppAnswers = {
|
|
39
|
+
readonly 'conversation.attach': {
|
|
40
|
+
readonly path: string;
|
|
41
|
+
};
|
|
36
42
|
readonly 'conversation.history': ConversationHistories;
|
|
37
43
|
};
|
|
38
44
|
export type AppAnswerAdditions = {
|
|
@@ -42,22 +48,6 @@ export type AppAnswerAdditions = {
|
|
|
42
48
|
readonly 'conversation.send': {
|
|
43
49
|
readonly turn: string;
|
|
44
50
|
};
|
|
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
|
-
};
|
|
61
51
|
};
|
|
62
52
|
export declare const HOUSE_APP_ACTS: Readonly<Record<string, string>>;
|
|
63
53
|
export declare const SITE_SUBMIT = "submit";
|
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,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;AAGhC,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,eAAO,MAAM,YAAY,MAAM,CAAC;AAEhC,eAAO,MAAM,aAAa,MAAM,CAAC;AAIjC,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,MAAM,MAAM,SAAS,GAAG;IACtB,QAAQ,CAAC,qBAAqB,EAAE,eAAe,GAAG;QAChD,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QACtB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;KACrB,CAAC;IACF,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,GAAG;QACpD,QAAQ,CAAC,MAAM,EAAE;YAAE,QAAQ,CAAC,cAAc,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAA;SAAE,CAAC;KAClF,CAAC;IACF,QAAQ,CAAC,qBAAqB,EAAE,QAAQ,GAAG;QACzC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;KAC5B,CAAC;IACF,QAAQ,CAAC,qBAAqB,EAAE,mBAAmB,CAAC;IACpD,QAAQ,CAAC,sBAAsB,EAAE,0BAA0B,CAAC;IAC5D,QAAQ,CAAC,wBAAwB,EAAE,mBAAmB,CAAC;IACvD,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,CAAC;IAClD,QAAQ,CAAC,mBAAmB,EAAE,mBAAmB,GAAG;QAClD,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;QAC9B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;KACvB,CAAC;IACF,QAAQ,CAAC,cAAc,EAAE;QAAE,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,CAAC;CACpE,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,QAAQ,CAAC,qBAAqB,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IAC1D,QAAQ,CAAC,sBAAsB,EAAE,qBAAqB,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,QAAQ,CAAC,qBAAqB,EAAE;QAAE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAA;KAAE,CAAC;IAClE,QAAQ,CAAC,mBAAmB,EAAE;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;CACzD,CAAC;AAgFF,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;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;AAkFD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,GAAG,YAAY,CAQjF;AA4FD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE"}
|
package/dist/actions.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { changeBatchIdentity, } from '@agentshouse/mdruntime';
|
|
1
|
+
import { changeBatchIdentity, HISTORY_CONVERSATIONS, } from '@agentshouse/mdruntime';
|
|
2
2
|
import { doorRefusal } from './refusal.js';
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
const TRIGGER_ROOMS = 100;
|
|
3
|
+
import { finishedUpload, houseUpload } from './upload.js';
|
|
4
|
+
export const HISTORY_PAGE = 100;
|
|
5
|
+
export const TRIGGER_ROOMS = 100;
|
|
6
6
|
const OCTET_STREAM = 'application/octet-stream';
|
|
7
7
|
function mapped(door, input = (given) => given) {
|
|
8
8
|
return {
|
|
@@ -23,6 +23,7 @@ function carried(door, carry, batched, room) {
|
|
|
23
23
|
const APP_ACTS = {
|
|
24
24
|
'access.read': mapped('rooms/access/read'),
|
|
25
25
|
'conversation.answer': mapped('conversations/interaction/answer', answerBody),
|
|
26
|
+
'conversation.attach': carried('conversations/attach', attachAction, undefined, 'room'),
|
|
26
27
|
'conversation.create': carried('conversations/create', createAction),
|
|
27
28
|
'conversation.delete': mapped('conversations/delete', controlBody),
|
|
28
29
|
'conversation.history': carried('conversations/history', historyAction, ['conversations']),
|
|
@@ -36,10 +37,13 @@ const APP_ACTS = {
|
|
|
36
37
|
'feature.list': mapped('apps/features/read'),
|
|
37
38
|
'holder.list': mapped('apps/holders'),
|
|
38
39
|
'holder.ring': mapped('apps/ring'),
|
|
40
|
+
'inboxChat.assign': mapped('chats/assign'),
|
|
41
|
+
'inboxChat.return': mapped('chats/return'),
|
|
42
|
+
'inboxChat.takeControl': mapped('chats/take-control'),
|
|
39
43
|
'member.list': mapped('rooms/members'),
|
|
40
44
|
'message.send': mapped('apps/messages/send'),
|
|
41
45
|
'processing.read': mapped('rooms/settings/processing/read'),
|
|
42
|
-
'record.list':
|
|
46
|
+
'record.list': mapped('records/read'),
|
|
43
47
|
'relay.read': mapped('apps/relay'),
|
|
44
48
|
'routine.list': mapped('routines/access'),
|
|
45
49
|
'routineAccess.list': mapped('routines/granted'),
|
|
@@ -105,7 +109,12 @@ function unimplemented(name) {
|
|
|
105
109
|
return { kind: 'rejected', code: 'action-unimplemented', fields: { name }, retryable: false };
|
|
106
110
|
}
|
|
107
111
|
function createBody(input) {
|
|
108
|
-
|
|
112
|
+
const replaces = text(input, 'replaces');
|
|
113
|
+
return {
|
|
114
|
+
agent_id: text(input, 'agent_id'),
|
|
115
|
+
operation_id: operationId(input),
|
|
116
|
+
...(replaces === undefined ? {} : { replaces }),
|
|
117
|
+
};
|
|
109
118
|
}
|
|
110
119
|
function controlBody(input) {
|
|
111
120
|
return { conversation_id: text(input, 'conversation'), operation_id: operationId(input) };
|
|
@@ -153,135 +162,65 @@ export function actionOutcome(answer, name) {
|
|
|
153
162
|
return { kind: 'transport-uncertainty' };
|
|
154
163
|
return { kind: 'action', result: answer.body };
|
|
155
164
|
}
|
|
156
|
-
function referredRecord(view, roomRef) {
|
|
157
|
-
const held = record(view);
|
|
158
|
-
if (roomRef === undefined || typeof held.record !== 'string' || !Array.isArray(held.attachments))
|
|
159
|
-
return view;
|
|
160
|
-
const referrer = {
|
|
161
|
-
room_ref: roomRef,
|
|
162
|
-
record: held.record,
|
|
163
|
-
};
|
|
164
|
-
return {
|
|
165
|
-
...held,
|
|
166
|
-
attachments: held.attachments.map((attachment) => ({ ...record(attachment), referrer })),
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
async function recordsAction(transport, route, input, name) {
|
|
170
|
-
const outcome = actionOutcome(await transport.door(route, input), name);
|
|
171
|
-
if (outcome.kind !== 'action')
|
|
172
|
-
return outcome;
|
|
173
|
-
const roomRef = text(input, 'room_ref');
|
|
174
|
-
const read = record(outcome.result);
|
|
175
|
-
return {
|
|
176
|
-
...outcome,
|
|
177
|
-
result: Array.isArray(read.records)
|
|
178
|
-
? { ...read, records: read.records.map((view) => referredRecord(view, roomRef)) }
|
|
179
|
-
: referredRecord(outcome.result, roomRef),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
165
|
async function carry(transport, route, name, input) {
|
|
183
166
|
return actionOutcome(await transport.door(route, input), name);
|
|
184
167
|
}
|
|
185
|
-
function sendFile(entry) {
|
|
186
|
-
const file = record(entry);
|
|
187
|
-
const name = text(file, 'name');
|
|
188
|
-
const bytes = file.byteLength;
|
|
189
|
-
const sha256 = text(file, 'contentHash');
|
|
190
|
-
if (name === undefined || typeof bytes !== 'number' || sha256 === undefined)
|
|
191
|
-
return null;
|
|
192
|
-
const mediaType = text(file, 'mediaType');
|
|
193
|
-
const width = file.width;
|
|
194
|
-
const height = file.height;
|
|
195
|
-
return {
|
|
196
|
-
name,
|
|
197
|
-
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
198
|
-
bytes,
|
|
199
|
-
sha256,
|
|
200
|
-
...(typeof width === 'number' && typeof height === 'number'
|
|
201
|
-
? { dimensions: { width, height } }
|
|
202
|
-
: {}),
|
|
203
|
-
};
|
|
204
|
-
}
|
|
205
|
-
function sendFiles(input) {
|
|
206
|
-
const files = record(input).files;
|
|
207
|
-
if (files === undefined)
|
|
208
|
-
return [];
|
|
209
|
-
if (!Array.isArray(files))
|
|
210
|
-
return null;
|
|
211
|
-
const declared = [];
|
|
212
|
-
for (const entry of files) {
|
|
213
|
-
const file = sendFile(entry);
|
|
214
|
-
if (file === null)
|
|
215
|
-
return null;
|
|
216
|
-
declared.push(file);
|
|
217
|
-
}
|
|
218
|
-
return declared;
|
|
219
|
-
}
|
|
220
168
|
function sendBody(input) {
|
|
221
|
-
const files = sendFiles(input);
|
|
222
169
|
const operation = text(input, 'operation_id');
|
|
223
|
-
|
|
170
|
+
const said = text(input, 'text');
|
|
171
|
+
if (operation === undefined || said === undefined)
|
|
224
172
|
return null;
|
|
225
|
-
|
|
226
|
-
return {
|
|
227
|
-
conversation_id: text(input, 'conversation'),
|
|
228
|
-
operation_id: operation,
|
|
229
|
-
...(textValue !== undefined && textValue.length > 0 ? { text: textValue } : {}),
|
|
230
|
-
...(files.length === 0 ? {} : { files }),
|
|
231
|
-
};
|
|
173
|
+
return { conversation_id: text(input, 'conversation'), operation_id: operation, text: said };
|
|
232
174
|
}
|
|
233
|
-
async function
|
|
234
|
-
const
|
|
235
|
-
if (
|
|
236
|
-
return
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
175
|
+
async function sendAction(transport, route, input, name) {
|
|
176
|
+
const body = sendBody(input);
|
|
177
|
+
if (body === null)
|
|
178
|
+
return malformed();
|
|
179
|
+
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
180
|
+
if (outcome.kind !== 'action')
|
|
181
|
+
return outcome;
|
|
182
|
+
return { ...outcome, result: withTurn(outcome.result) };
|
|
240
183
|
}
|
|
241
|
-
function
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
const
|
|
245
|
-
|
|
184
|
+
function attachBody(input) {
|
|
185
|
+
const room = text(input, 'room');
|
|
186
|
+
const name = text(input, 'name');
|
|
187
|
+
const sha256 = text(input, 'contentHash');
|
|
188
|
+
const bytes = record(input).byteLength;
|
|
189
|
+
if (room === undefined || name === undefined || sha256 === undefined)
|
|
246
190
|
return null;
|
|
247
|
-
if (typeof
|
|
191
|
+
if (typeof bytes !== 'number')
|
|
248
192
|
return null;
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
const grant = uploadGrant(entry);
|
|
258
|
-
if (grant === 'absent')
|
|
259
|
-
continue;
|
|
260
|
-
const bytes = index < files.length ? await fileBytes(files[index]) : null;
|
|
261
|
-
if (grant === null || bytes === null)
|
|
262
|
-
return false;
|
|
263
|
-
const answer = await transport.transfer({
|
|
264
|
-
act: 'conversation_file_upload',
|
|
265
|
-
url: grant.url,
|
|
266
|
-
body: bytes,
|
|
267
|
-
operation: grant.operation,
|
|
268
|
-
});
|
|
269
|
-
if (answer.status !== 200)
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
return true;
|
|
193
|
+
const mediaType = text(input, 'mediaType');
|
|
194
|
+
return {
|
|
195
|
+
room_ref: room,
|
|
196
|
+
name,
|
|
197
|
+
bytes,
|
|
198
|
+
sha256,
|
|
199
|
+
media_type: mediaType !== undefined && mediaType.length > 0 ? mediaType : OCTET_STREAM,
|
|
200
|
+
};
|
|
273
201
|
}
|
|
274
|
-
async function
|
|
275
|
-
const body =
|
|
276
|
-
|
|
202
|
+
async function attachAction(transport, route, input, name) {
|
|
203
|
+
const body = attachBody(input);
|
|
204
|
+
const blob = record(input).blob;
|
|
205
|
+
if (body === null || !(blob instanceof Blob))
|
|
277
206
|
return malformed();
|
|
278
207
|
const outcome = actionOutcome(await transport.door(route, body), name);
|
|
279
208
|
if (outcome.kind !== 'action')
|
|
280
209
|
return outcome;
|
|
281
|
-
|
|
210
|
+
const upload = houseUpload(record(outcome.result).upload);
|
|
211
|
+
if (upload === null)
|
|
282
212
|
return { kind: 'transport-uncertainty' };
|
|
283
|
-
|
|
284
|
-
|
|
213
|
+
const finished = await finishedUpload(transport, upload, blob);
|
|
214
|
+
if (finished === null)
|
|
215
|
+
return { kind: 'transport-uncertainty' };
|
|
216
|
+
const settled = actionOutcome(finished, name);
|
|
217
|
+
if (settled.kind !== 'action')
|
|
218
|
+
return settled;
|
|
219
|
+
const path = text(settled.result, 'path');
|
|
220
|
+
if (path === undefined)
|
|
221
|
+
return { kind: 'transport-uncertainty' };
|
|
222
|
+
const result = { path };
|
|
223
|
+
return { kind: 'action', result };
|
|
285
224
|
}
|
|
286
225
|
function historyCursor(value) {
|
|
287
226
|
const acceptedAt = text(value, 'accepted_at');
|
|
@@ -305,19 +244,12 @@ export function acceptedMessage(entry) {
|
|
|
305
244
|
const cursor = historyCursor(entry);
|
|
306
245
|
if (cursor === null)
|
|
307
246
|
return null;
|
|
308
|
-
const message = structuredClone(record(entry));
|
|
309
|
-
const referrer = { message: cursor.message_id };
|
|
310
247
|
return {
|
|
311
248
|
identity: cursor.message_id,
|
|
312
249
|
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
313
250
|
position: position(cursor),
|
|
314
251
|
text: text(entry, 'text') ?? '',
|
|
315
|
-
message:
|
|
316
|
-
? {
|
|
317
|
-
...message,
|
|
318
|
-
files: message.files.map((file) => ({ ...record(file), referrer })),
|
|
319
|
-
}
|
|
320
|
-
: message,
|
|
252
|
+
message: structuredClone(record(entry)),
|
|
321
253
|
};
|
|
322
254
|
}
|
|
323
255
|
function historyPage(entry) {
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EACP,aAAa,
|
|
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;AA0ChC,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;AA8ErD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CAkoBpF"}
|