@agentshouse/mdruntime 0.1.0-alpha.9 → 0.1.0-c037654ea7e04
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 +232 -0
- package/README.md +44 -0
- package/dist/adapter.d.ts +207 -36
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +1 -10
- package/dist/attached-model.d.ts +11 -0
- package/dist/attached-model.d.ts.map +1 -0
- package/dist/attached-model.js +34 -0
- package/dist/attachment.d.ts +3 -0
- package/dist/attachment.d.ts.map +1 -0
- package/dist/attachment.js +8 -0
- package/dist/bootstrap.d.ts +7 -9
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +30 -28
- package/dist/change-set.d.ts +33 -0
- package/dist/change-set.d.ts.map +1 -0
- package/dist/change-set.js +83 -0
- package/dist/change.d.ts +9 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +6 -5
- package/dist/client.d.ts +39 -32
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +114 -183
- package/dist/collection.d.ts +13 -16
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +45 -88
- package/dist/connection.d.ts +51 -46
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1551 -1161
- package/dist/conversation.d.ts +57 -24
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +631 -330
- package/dist/durability.js +6 -6
- package/dist/file.d.ts +2 -2
- package/dist/file.d.ts.map +1 -1
- package/dist/file.js +48 -71
- package/dist/host.d.ts +12 -2
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +97 -119
- package/dist/identity.d.ts +1 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +10 -9
- package/dist/index.d.ts +12 -11
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/dist/log.js +5 -6
- package/dist/memory.d.ts +16 -7
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +267 -220
- package/dist/model.d.ts +7 -29
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +19 -21
- package/dist/observation.d.ts +27 -0
- package/dist/observation.d.ts.map +1 -0
- package/dist/observation.js +95 -0
- package/dist/outcome.d.ts +10 -29
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +1 -23
- package/dist/overlay.d.ts +9 -2
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +187 -43
- package/dist/paths.d.ts +0 -2
- package/dist/paths.d.ts.map +1 -1
- package/dist/paths.js +6 -29
- package/dist/query.d.ts +215 -10
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +429 -15
- package/dist/reach.d.ts +40 -0
- package/dist/reach.d.ts.map +1 -0
- package/dist/reach.js +270 -0
- package/dist/react.d.ts +31 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +62 -0
- package/dist/read-side.d.ts +18 -0
- package/dist/read-side.d.ts.map +1 -0
- package/dist/read-side.js +377 -0
- package/dist/refresh.d.ts +5 -5
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +49 -30
- package/dist/replica.d.ts +25 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +227 -38
- package/dist/room-draft.d.ts +127 -0
- package/dist/room-draft.d.ts.map +1 -0
- package/dist/room-draft.js +329 -0
- package/dist/rows.d.ts +41 -0
- package/dist/rows.d.ts.map +1 -0
- package/dist/rows.js +97 -0
- package/dist/save.d.ts +7 -4
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +314 -356
- package/dist/search.d.ts +61 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +125 -0
- package/dist/status.d.ts +4 -6
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +9 -13
- package/dist/store.d.ts +60 -32
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +338 -134
- package/dist/transfer.d.ts +5 -0
- package/dist/transfer.d.ts.map +1 -1
- package/dist/transfer.js +1 -5
- package/dist/wire.d.ts +52 -16
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +78 -108
- package/package.json +17 -11
- package/dist/adapter.js.map +0 -1
- package/dist/bootstrap.js.map +0 -1
- package/dist/change.js.map +0 -1
- package/dist/client.js.map +0 -1
- package/dist/collection.js.map +0 -1
- package/dist/connection.js.map +0 -1
- package/dist/conversation.js.map +0 -1
- package/dist/durability.js.map +0 -1
- package/dist/file.js.map +0 -1
- package/dist/host.js.map +0 -1
- package/dist/identity.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/log.js.map +0 -1
- package/dist/memory.js.map +0 -1
- package/dist/model.js.map +0 -1
- package/dist/outcome.js.map +0 -1
- package/dist/overlay.js.map +0 -1
- package/dist/paths.js.map +0 -1
- package/dist/query.js.map +0 -1
- package/dist/refresh.js.map +0 -1
- package/dist/replica.js.map +0 -1
- package/dist/save.js.map +0 -1
- package/dist/status.js.map +0 -1
- package/dist/store.js.map +0 -1
- package/dist/transfer.js.map +0 -1
- package/dist/wire.js.map +0 -1
package/AGENTS.md
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
# Instructions for the App Creator's agent
|
|
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
|
|
5
|
+
enforcement.
|
|
6
|
+
|
|
7
|
+
## The MD Runtime API
|
|
8
|
+
|
|
9
|
+
App code reaches the MD Runtime through the remote client. The surfaces are
|
|
10
|
+
Rooms, Query, Search, Observe, Types, Room Draft, Save, History, 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 and the deployment facts are observations only.
|
|
14
|
+
|
|
15
|
+
The host attaches each port with its reach, and every member and observation
|
|
16
|
+
answers within it: a Room outside it answers as one the replica does not hold,
|
|
17
|
+
Rooms lists only the Rooms reached whole, a Room reached for single Documents
|
|
18
|
+
shows only those Documents and the Types of the models that govern them, and
|
|
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.
|
|
23
|
+
|
|
24
|
+
Every `observe` resolves, once its first value has arrived, to a handle:
|
|
25
|
+
`current()` is the latest complete value, `subscribe(listener)` hears each later
|
|
26
|
+
value whole and returns its unsubscribe, and `close()` ends the observation.
|
|
27
|
+
Closing the port ends every handle and rejects every pending call and
|
|
28
|
+
observation; a client that reconnects observes again.
|
|
29
|
+
|
|
30
|
+
Each conversation the Provider's conversation list names is held complete in the
|
|
31
|
+
browser. `conversation.list()` and `observe('conversations')` answer each with its
|
|
32
|
+
Agent's identity and name, its name, created and finished times, last outcome and live
|
|
33
|
+
`state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
|
|
34
|
+
and `started`, when the running turn began, or `null`.
|
|
35
|
+
Observe one with `observe('conversation', id, { limit })`: the view
|
|
36
|
+
holds its latest `limit` messages, or all of them, oldest first, its chat
|
|
37
|
+
draft, and what the Provider streams for it whether or not anything views it:
|
|
38
|
+
the running `turn` with its message parts and its context in use and window, the
|
|
39
|
+
open questions, the process state, and the CLI's commands and options. These live
|
|
40
|
+
only in memory: the message accepted under the turn's id replaces the running turn,
|
|
41
|
+
and none of them is stored or searchable.
|
|
42
|
+
`chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
|
|
43
|
+
sending it is a Provider Action that needs the Provider reachable and is never
|
|
44
|
+
queued.
|
|
45
|
+
|
|
46
|
+
Each Room in Rooms lists its `attachments`, the files the Provider holds for it
|
|
47
|
+
that its Documents link by the Provider's reference, ordered by `reference`,
|
|
48
|
+
each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
|
|
49
|
+
`entry`. They are as the Provider last declared them and hold no bytes;
|
|
50
|
+
open one through the Provider Action that serves it.
|
|
51
|
+
|
|
52
|
+
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
53
|
+
touch the network.
|
|
54
|
+
History and Call go to the Provider through the Adapter. A Call result whose
|
|
55
|
+
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
56
|
+
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
57
|
+
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
58
|
+
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
59
|
+
that document was written at a later Room Version. Each History revision
|
|
60
|
+
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
|
|
61
|
+
member of the
|
|
62
|
+
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
63
|
+
surface returns the authorization, performs a request the App's code
|
|
64
|
+
composes, or exposes the browser store.
|
|
65
|
+
|
|
66
|
+
Read the deployment facts with `observe('deployment-facts')`. Interpret the
|
|
67
|
+
opaque value using the host's contract.
|
|
68
|
+
|
|
69
|
+
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
70
|
+
ships in no bundle.
|
|
71
|
+
|
|
72
|
+
## Local Query rules
|
|
73
|
+
|
|
74
|
+
`query(q)` answers once from local state; `observe('query', q)` holds the whole
|
|
75
|
+
result and hears it again only when it changes, keeping every unchanged Document
|
|
76
|
+
the same object, so a component can tell what changed by identity. A query is
|
|
77
|
+
data:
|
|
78
|
+
|
|
79
|
+
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
80
|
+
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
81
|
+
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
82
|
+
- **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
|
|
83
|
+
`$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
|
|
84
|
+
`$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
|
|
85
|
+
asks whether it contains the value. Missing, null and empty differ:
|
|
86
|
+
`$exists: false` keeps a missing field, `null` an explicit null, `''` empty
|
|
87
|
+
text and `$size: 0` an empty list. A date compares in calendar order and never
|
|
88
|
+
with a date-time. A reference compares by the Room Path it resolves to.
|
|
89
|
+
Untyped frontmatter is plain values. There is no text containment or regular
|
|
90
|
+
expression.
|
|
91
|
+
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
92
|
+
reference `field` points to a matching Document of the same Room.
|
|
93
|
+
`backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
94
|
+
matching Document of the same Room references. Each keeps a Document once.
|
|
95
|
+
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
96
|
+
`preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
|
|
97
|
+
are `'all'` or a list of names. Room and Path always return; a Markdown
|
|
98
|
+
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
99
|
+
target returns only Room and Path. An unselected part is absent. Select only
|
|
100
|
+
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
101
|
+
- **Change.** `change` is `{ author, time }` of the Document's head revision as
|
|
102
|
+
the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
|
|
103
|
+
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
104
|
+
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
105
|
+
a Site. An unsent edit or move keeps it, an unsent creation has none, and a
|
|
106
|
+
saved write takes the Provider's own once it is Accepted and refreshed. A
|
|
107
|
+
Room's last change is its Document with the latest `time`.
|
|
108
|
+
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
109
|
+
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
110
|
+
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
111
|
+
over every match and ordered by `count` or a key. `limit` bounds the Documents
|
|
112
|
+
or the groups.
|
|
113
|
+
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
114
|
+
Rooms and Sync Status. An invalid query fails with `invalid-query`,
|
|
115
|
+
`unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
|
|
116
|
+
answers an empty result in its place.
|
|
117
|
+
|
|
118
|
+
## Local Search rules
|
|
119
|
+
|
|
120
|
+
`search({ text, documents, conversations, limit })` answers once, by words, from
|
|
121
|
+
local state, with MiniSearch at its default configuration. There is no observed
|
|
122
|
+
search.
|
|
123
|
+
|
|
124
|
+
- **What is found.** A Document by its field values, its sections' headings and
|
|
125
|
+
text, its preamble and its Path; a message by its text. Frontmatter keys, Room
|
|
126
|
+
Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
|
|
127
|
+
word forms, typo tolerance or prefix matching.
|
|
128
|
+
- **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
|
|
129
|
+
`pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
|
|
130
|
+
apply before `limit`, which bounds each list; without it every hit returns.
|
|
131
|
+
- **Results.** `{ documents, messages }`, each ranked by `score`, which compares
|
|
132
|
+
hits of one list of one search. A Document hit names its `room`, `path` and
|
|
133
|
+
`type`, a message hit its `conversation` and `identity`, and `matches` maps each
|
|
134
|
+
matched word to the parts it matched in: `fields`, `sections`, `preamble` or
|
|
135
|
+
`path`, or `text`. A hit carries no position; mark the words in the text you
|
|
136
|
+
show. An invalid filter fails with its Local Query error.
|
|
137
|
+
|
|
138
|
+
## Room Draft, Save, and outcome rules
|
|
139
|
+
|
|
140
|
+
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
141
|
+
tab. It is durable: it survives reload and navigation. A Room that Discovery
|
|
142
|
+
stops listing takes its Room Drafts and its queue with it.
|
|
143
|
+
Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
|
|
144
|
+
the revision you read, or `null` when there was none, and every part it should
|
|
145
|
+
now change: fields, sections and the preamble, or the whole Markdown, a
|
|
146
|
+
creation, a move, or a removal. A part new to the Room Draft names its base,
|
|
147
|
+
the value you showed when it was opened; the MD Runtime keeps a part's first
|
|
148
|
+
base. A binary link target has a Room Draft too, for a move or a removal, with
|
|
149
|
+
`null` as its base. A write or a discard from an older revision is refused as `stale` with
|
|
150
|
+
the current Room Draft; read it and write again.
|
|
151
|
+
|
|
152
|
+
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
153
|
+
validates locally, and on success appends one Change Batch to that Room's
|
|
154
|
+
queue and removes those Room Drafts. It is refused as `stale`, as
|
|
155
|
+
`changed-underneath` naming each part whose base no longer matches the visible
|
|
156
|
+
state, or by a local validation rule, and then creates nothing and leaves every
|
|
157
|
+
Room Draft in place. A directory move or removal is a move or removal part on
|
|
158
|
+
each Document and binary link target beneath it, saved together.
|
|
159
|
+
|
|
160
|
+
Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
|
|
161
|
+
queue, drawn over the confirmed layer, until the confirmed layer reaches the
|
|
162
|
+
Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
|
|
163
|
+
longer applies over the Room each leave the queue and return as Room Drafts on
|
|
164
|
+
the Documents they changed, marked with why: the Provider's structured refusal
|
|
165
|
+
code and fields as returned, not known to have applied, or withdrawn locally.
|
|
166
|
+
The rest of the queue keeps synchronizing, and Sync Status requires attention
|
|
167
|
+
until each returned Room Draft is saved again or discarded. A Change Batch
|
|
168
|
+
keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
|
|
169
|
+
Pending one, and a returned Room Draft says why it returned. Transport
|
|
170
|
+
failure and Provider unavailability keep work Pending and do not infer a
|
|
171
|
+
rejection. A refusal the Provider marks retryable stays Pending until the reset
|
|
172
|
+
it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
173
|
+
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
174
|
+
combines, reorders, or rebases.
|
|
175
|
+
|
|
176
|
+
`observe('service-mode')` answers the Provider's Service
|
|
177
|
+
Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
|
|
178
|
+
its Change Batch waits unsent, and the queue is submitted in order once the
|
|
179
|
+
Provider reopens writes. An Action is never held: a write the Provider refuses
|
|
180
|
+
for the halt returns that refusal to its caller. Show the Provider as read-only
|
|
181
|
+
instead of retrying.
|
|
182
|
+
|
|
183
|
+
## The neutrality rule
|
|
184
|
+
|
|
185
|
+
No module outside an Adapter package imports, names, or special-cases a
|
|
186
|
+
Provider. MD UI and every App reach data only through the client entry.
|
|
187
|
+
|
|
188
|
+
## Content-safety rules
|
|
189
|
+
|
|
190
|
+
The Provider authorization belongs to the Runtime host and is never readable
|
|
191
|
+
by the App's code. The App's code reaches the network only at the external
|
|
192
|
+
origins its manifest declares, empty by default, and the Provider enforces
|
|
193
|
+
that set. Every request to the Provider itself goes through the MD Runtime.
|
|
194
|
+
Rendered Markdown never executes scripts, renders raw HTML only for the
|
|
195
|
+
details and summary elements, and loads images and other resources only from
|
|
196
|
+
origins the Provider's policy allows.
|
|
197
|
+
|
|
198
|
+
## Launch promises MD UI keeps
|
|
199
|
+
|
|
200
|
+
MD UI uses semantic HTML, is fully operable from a keyboard with visible
|
|
201
|
+
focus and labelled controls, and lays out from a 360 pixel wide viewport to
|
|
202
|
+
a desktop. Its strings are English only, dates and numbers follow the
|
|
203
|
+
browser locale, and content is never translated. Light and dark themes come
|
|
204
|
+
from CSS custom properties with the browser's preference as the default and
|
|
205
|
+
an App's override respected. What an App Creator's agent adds carries none
|
|
206
|
+
of these promises by itself. Reading, querying and searching never wait for
|
|
207
|
+
the network. Data lives only in the App Creator's browser and with the Provider.
|
|
208
|
+
|
|
209
|
+
## App code takes the client its host hands it and never constructs a Runtime
|
|
210
|
+
|
|
211
|
+
App code takes the client its host hands it: in House,
|
|
212
|
+
`connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
|
|
213
|
+
client House built into the page. It never constructs a Runtime or a client.
|
|
214
|
+
It imports only types from `@agentshouse/mdruntime/client`, does not call
|
|
215
|
+
`connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
|
|
216
|
+
the host entry, or the Adapter package. Hosts and tests use those entries; the
|
|
217
|
+
served App does not.
|
|
218
|
+
|
|
219
|
+
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
220
|
+
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
221
|
+
the arguments of `observe` and returns the topic's current value, `undefined`
|
|
222
|
+
until it arrives, re-rendering on each change; a `null` client observes
|
|
223
|
+
nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
|
|
224
|
+
`save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
|
|
225
|
+
already there, keeping the bases its parts have, or onto a new one, and saves
|
|
226
|
+
them together. A refused Save leaves the Room Drafts for the App to save again
|
|
227
|
+
or discard; a failure is recorded and rejects.
|
|
228
|
+
|
|
229
|
+
## What an agent must never do
|
|
230
|
+
|
|
231
|
+
An agent must never read the authorization, load code from a Room, call the
|
|
232
|
+
Provider directly, or rebase a refused Change Batch.
|
package/README.md
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# `@agentshouse/mdruntime`
|
|
2
|
+
|
|
3
|
+
The headless core of MD App: local Rooms of typed Markdown Documents with
|
|
4
|
+
query, search, observation, Room Drafts, and queued saves that synchronize
|
|
5
|
+
with a Provider through an Adapter.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @agentshouse/mdruntime
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Entries
|
|
14
|
+
|
|
15
|
+
| Entry | For |
|
|
16
|
+
| ------------------------------- | ---------------------------------------------------- |
|
|
17
|
+
| `@agentshouse/mdruntime/client` | The host's client: `connectMdRuntime(port)` |
|
|
18
|
+
| `@agentshouse/mdruntime/host` | The host that serves a Runtime: `serveMdRuntime` |
|
|
19
|
+
| `@agentshouse/mdruntime` | Shared types |
|
|
20
|
+
| `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
|
|
21
|
+
| `@agentshouse/mdruntime/react` | React hooks over the client: `useObserve`, `useSave` |
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
App code takes the client its host hands it; in House the App bridge hands it:
|
|
26
|
+
|
|
27
|
+
```ts
|
|
28
|
+
import { connectHouseBridge } from '@agentshouse/app-bridge';
|
|
29
|
+
|
|
30
|
+
const runtime = await connectHouseBridge().runtime;
|
|
31
|
+
const rooms = await runtime.rooms();
|
|
32
|
+
const notes = await runtime.query({ types: ['note'], select: 'all', limit: 20 });
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
`observe('storage-loss')` reports `null` or the stable code
|
|
36
|
+
`storage-loss` when unsynchronized Room Drafts and Pending Changes were lost.
|
|
37
|
+
The host supplies the user-facing wording.
|
|
38
|
+
|
|
39
|
+
The rules an App's agent follows, including Local Query, Local Search, Room
|
|
40
|
+
Draft and Save, are in [`AGENTS.md`](AGENTS.md).
|
|
41
|
+
|
|
42
|
+
## License
|
|
43
|
+
|
|
44
|
+
MIT
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ModelResult } from './model.js';
|
|
2
2
|
import type { ChangeBatch } from './change.js';
|
|
3
3
|
export type Authorization = object;
|
|
4
|
-
export declare const ROOM_CONTRACT_VERSION = 1;
|
|
5
|
-
export declare const VERSION_1_CAPABILITIES: readonly ['stable-file-ids', 'ranked-provider-search', 'room-version-notifications', 'room-history', 'provider-actions'];
|
|
6
4
|
export type MdModelIdentity = {
|
|
7
5
|
identity: string;
|
|
8
6
|
version: string;
|
|
9
7
|
};
|
|
10
8
|
export type TypedSelection = {
|
|
11
9
|
roots: readonly string[];
|
|
12
|
-
attachedModel: ModelIdentity | null;
|
|
13
10
|
};
|
|
14
11
|
export type OperationScopes = {
|
|
15
12
|
read: readonly string[];
|
|
@@ -22,13 +19,12 @@ export type ReplicaAdmission = {
|
|
|
22
19
|
admission: 'admitted' | 'unavailable';
|
|
23
20
|
};
|
|
24
21
|
export type DiscoveredRoom = {
|
|
25
|
-
collectionRoot: string;
|
|
26
22
|
name: string;
|
|
27
23
|
locator: string;
|
|
24
|
+
handle: string;
|
|
28
25
|
roomVersion: string;
|
|
29
26
|
operations: OperationScopes;
|
|
30
27
|
replica: ReplicaAdmission;
|
|
31
|
-
attachedModel: ModelIdentity | null;
|
|
32
28
|
typedSelection?: TypedSelection;
|
|
33
29
|
providerOwnedPaths: readonly string[];
|
|
34
30
|
};
|
|
@@ -36,35 +32,153 @@ export type Capability = {
|
|
|
36
32
|
name: string;
|
|
37
33
|
limits?: readonly ProviderLimit[];
|
|
38
34
|
actions?: readonly ActionDeclaration[];
|
|
39
|
-
|
|
35
|
+
conversationAgents?: ConversationAgents;
|
|
40
36
|
};
|
|
41
|
-
export type
|
|
37
|
+
export type ConversationAgents = {
|
|
42
38
|
locator: string;
|
|
43
39
|
type: string;
|
|
44
40
|
identity: string;
|
|
41
|
+
name: string;
|
|
42
|
+
};
|
|
43
|
+
export type ListedConversation = {
|
|
44
|
+
conversation: string;
|
|
45
45
|
agent: string;
|
|
46
|
+
name: string;
|
|
47
|
+
created: string;
|
|
48
|
+
finished: string | null;
|
|
49
|
+
outcome: string | null;
|
|
46
50
|
};
|
|
47
51
|
export type ConversationAction = 'conversation.create' | 'conversation.send' | 'conversation.answer' | 'conversation.interrupt' | 'conversation.kill' | 'conversation.cancel' | 'conversation.delete' | 'conversation.history';
|
|
48
52
|
export type ConversationMessage = {
|
|
53
|
+
identity: string;
|
|
49
54
|
turn: string;
|
|
55
|
+
text: string;
|
|
50
56
|
message: unknown;
|
|
51
57
|
};
|
|
58
|
+
export type AcceptedMessage = ConversationMessage & {
|
|
59
|
+
position: string;
|
|
60
|
+
};
|
|
61
|
+
export type ConversationHistoryRequest = {
|
|
62
|
+
conversations: readonly {
|
|
63
|
+
conversation: string;
|
|
64
|
+
after?: string;
|
|
65
|
+
}[];
|
|
66
|
+
};
|
|
67
|
+
export type ConversationHistoryPage = {
|
|
68
|
+
conversation: string;
|
|
69
|
+
messages: readonly AcceptedMessage[];
|
|
70
|
+
next?: string;
|
|
71
|
+
};
|
|
72
|
+
export type ConversationHistories = {
|
|
73
|
+
histories: readonly ConversationHistoryPage[];
|
|
74
|
+
};
|
|
75
|
+
export type TurnContext = {
|
|
76
|
+
used: number;
|
|
77
|
+
window: number;
|
|
78
|
+
};
|
|
79
|
+
export type TurnOperation = {
|
|
80
|
+
op: 'begin';
|
|
81
|
+
at: string;
|
|
82
|
+
} | {
|
|
83
|
+
op: 'start';
|
|
84
|
+
index: number;
|
|
85
|
+
part: unknown;
|
|
86
|
+
} | {
|
|
87
|
+
op: 'append';
|
|
88
|
+
index: number;
|
|
89
|
+
text: string;
|
|
90
|
+
} | {
|
|
91
|
+
op: 'status';
|
|
92
|
+
index: number;
|
|
93
|
+
status: string;
|
|
94
|
+
result: unknown;
|
|
95
|
+
} | {
|
|
96
|
+
op: 'count';
|
|
97
|
+
index: number;
|
|
98
|
+
count: number;
|
|
99
|
+
} | {
|
|
100
|
+
op: 'plan';
|
|
101
|
+
index: number;
|
|
102
|
+
entries: readonly unknown[];
|
|
103
|
+
} | ({
|
|
104
|
+
op: 'context';
|
|
105
|
+
} & TurnContext);
|
|
106
|
+
export type ProcessCommand = {
|
|
107
|
+
[field: string]: unknown;
|
|
108
|
+
name: string;
|
|
109
|
+
description: string;
|
|
110
|
+
input?: {
|
|
111
|
+
[field: string]: unknown;
|
|
112
|
+
hint: string;
|
|
113
|
+
} | null;
|
|
114
|
+
};
|
|
115
|
+
type SelectValue = {
|
|
116
|
+
[field: string]: unknown;
|
|
117
|
+
value: string;
|
|
118
|
+
name: string;
|
|
119
|
+
description?: string | null;
|
|
120
|
+
};
|
|
121
|
+
type SelectGroup = {
|
|
122
|
+
[field: string]: unknown;
|
|
123
|
+
group: string;
|
|
124
|
+
name: string;
|
|
125
|
+
options: readonly SelectValue[];
|
|
126
|
+
};
|
|
127
|
+
type SessionOptionNaming = {
|
|
128
|
+
[field: string]: unknown;
|
|
129
|
+
id: string;
|
|
130
|
+
name: string;
|
|
131
|
+
description?: string | null;
|
|
132
|
+
category?: string | null;
|
|
133
|
+
};
|
|
134
|
+
export type SessionOption = (SessionOptionNaming & {
|
|
135
|
+
type: 'select';
|
|
136
|
+
currentValue: string;
|
|
137
|
+
options: readonly SelectValue[] | readonly SelectGroup[];
|
|
138
|
+
}) | (SessionOptionNaming & {
|
|
139
|
+
type: 'boolean';
|
|
140
|
+
currentValue: boolean;
|
|
141
|
+
});
|
|
52
142
|
export type ConversationEvent = {
|
|
53
|
-
kind: '
|
|
143
|
+
kind: 'turn';
|
|
54
144
|
conversation: string;
|
|
55
145
|
turn: string;
|
|
56
|
-
|
|
146
|
+
operation: TurnOperation;
|
|
147
|
+
} | {
|
|
148
|
+
kind: 'questions';
|
|
149
|
+
conversation: string;
|
|
150
|
+
questions: readonly unknown[];
|
|
151
|
+
} | {
|
|
152
|
+
kind: 'process';
|
|
153
|
+
conversation: string;
|
|
154
|
+
running: boolean;
|
|
155
|
+
} | {
|
|
156
|
+
kind: 'commands';
|
|
157
|
+
conversation: string;
|
|
158
|
+
commands: readonly ProcessCommand[];
|
|
159
|
+
} | {
|
|
160
|
+
kind: 'options';
|
|
161
|
+
conversation: string;
|
|
162
|
+
options: readonly SessionOption[];
|
|
57
163
|
} | {
|
|
58
164
|
kind: 'accepted-message';
|
|
59
165
|
conversation: string;
|
|
60
|
-
message:
|
|
166
|
+
message: AcceptedMessage;
|
|
167
|
+
} | {
|
|
168
|
+
kind: 'gap';
|
|
169
|
+
conversation: string;
|
|
170
|
+
} | {
|
|
171
|
+
kind: 'list';
|
|
172
|
+
entries: readonly ListedConversation[];
|
|
61
173
|
} | {
|
|
62
|
-
kind: '
|
|
174
|
+
kind: 'listed';
|
|
175
|
+
entry: ListedConversation;
|
|
176
|
+
} | {
|
|
177
|
+
kind: 'unlisted';
|
|
63
178
|
conversation: string;
|
|
64
|
-
summary: unknown;
|
|
65
179
|
};
|
|
66
|
-
export type
|
|
67
|
-
|
|
180
|
+
export type ConversationStream = {
|
|
181
|
+
replicate(conversations: readonly string[]): void;
|
|
68
182
|
observe(notify: (event: ConversationEvent) => void): () => void;
|
|
69
183
|
};
|
|
70
184
|
export type ActionDeclaration = {
|
|
@@ -89,8 +203,6 @@ export type Retention = {
|
|
|
89
203
|
};
|
|
90
204
|
export type Discovery = {
|
|
91
205
|
kind: 'discovery';
|
|
92
|
-
supportedVersions: readonly number[];
|
|
93
|
-
mdModel: MdModelIdentity;
|
|
94
206
|
rooms: readonly DiscoveredRoom[];
|
|
95
207
|
capabilities: readonly Capability[];
|
|
96
208
|
providerLimits: readonly ProviderLimit[];
|
|
@@ -121,17 +233,44 @@ export type ContractUnavailable = ProviderRefusal & {
|
|
|
121
233
|
};
|
|
122
234
|
export type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization | ContractUnavailable;
|
|
123
235
|
export type PageToken = string;
|
|
236
|
+
export type ChangeAuthor = {
|
|
237
|
+
kind: 'user';
|
|
238
|
+
id: string;
|
|
239
|
+
name: string;
|
|
240
|
+
} | {
|
|
241
|
+
kind: 'site';
|
|
242
|
+
id: string;
|
|
243
|
+
name: string;
|
|
244
|
+
};
|
|
245
|
+
export type HeadChange = {
|
|
246
|
+
author: ChangeAuthor | null;
|
|
247
|
+
time: string;
|
|
248
|
+
};
|
|
249
|
+
export type RoomAttachment = {
|
|
250
|
+
reference: string;
|
|
251
|
+
name: string;
|
|
252
|
+
byteLength: number;
|
|
253
|
+
mediaType: string | null;
|
|
254
|
+
entry: unknown;
|
|
255
|
+
};
|
|
124
256
|
export type BootstrapRequest = {
|
|
125
257
|
locator: string;
|
|
126
258
|
selection: string;
|
|
127
259
|
pageToken?: PageToken;
|
|
128
260
|
};
|
|
261
|
+
export type RoomModels = {
|
|
262
|
+
collection?: ModelResult;
|
|
263
|
+
selection?: ModelResult;
|
|
264
|
+
};
|
|
129
265
|
export type BootstrapPage = {
|
|
130
266
|
kind: 'bootstrap';
|
|
131
267
|
roomVersion: string;
|
|
268
|
+
models?: RoomModels;
|
|
132
269
|
documents: Readonly<Record<string, string>>;
|
|
133
270
|
revisions: Readonly<Record<string, string>>;
|
|
271
|
+
changes: Readonly<Record<string, HeadChange>>;
|
|
134
272
|
binaryTargets: readonly string[];
|
|
273
|
+
attachments?: readonly RoomAttachment[];
|
|
135
274
|
pageToken?: PageToken;
|
|
136
275
|
};
|
|
137
276
|
export type BootstrapResult = BootstrapPage | AdapterFailure;
|
|
@@ -144,31 +283,40 @@ export type RefreshRequest = {
|
|
|
144
283
|
export type RefreshPage = {
|
|
145
284
|
kind: 'net-advancement';
|
|
146
285
|
roomVersion: string;
|
|
286
|
+
models?: RoomModels;
|
|
147
287
|
documents: Readonly<Record<string, string>>;
|
|
148
288
|
revisions: Readonly<Record<string, string>>;
|
|
289
|
+
changes: Readonly<Record<string, HeadChange>>;
|
|
149
290
|
binaryTargets: readonly string[];
|
|
150
291
|
removals: readonly string[];
|
|
292
|
+
attachments?: readonly RoomAttachment[];
|
|
151
293
|
pageToken?: PageToken;
|
|
152
294
|
};
|
|
153
295
|
export type RefreshResult = {
|
|
154
296
|
kind: 'still-current';
|
|
155
297
|
} | RefreshPage | {
|
|
156
298
|
kind: 'beyond-horizon';
|
|
157
|
-
} | AdapterFailure;
|
|
299
|
+
} | RetryableRefusal | AdapterFailure;
|
|
158
300
|
export type MutationRequest = {
|
|
159
301
|
locator: string;
|
|
160
302
|
changeBatch: ChangeBatch;
|
|
303
|
+
upload?: unknown;
|
|
161
304
|
};
|
|
162
305
|
export type RetryableRefusal = ProviderRefusal & {
|
|
163
306
|
kind: 'retryable-refusal';
|
|
164
307
|
reset?: string;
|
|
165
308
|
};
|
|
309
|
+
export type ServiceMode = 'open' | 'write-halted';
|
|
310
|
+
export type ServiceModeSignal = {
|
|
311
|
+
observe(notify: (mode: ServiceMode) => void): () => void;
|
|
312
|
+
};
|
|
166
313
|
export type MutationResult = {
|
|
167
314
|
kind: 'accepted';
|
|
168
315
|
roomVersion: string;
|
|
169
316
|
documents: Readonly<Record<string, string>>;
|
|
170
317
|
revisions: Readonly<Record<string, string>>;
|
|
171
318
|
removals: readonly string[];
|
|
319
|
+
attachments?: readonly RoomAttachment[];
|
|
172
320
|
author?: string;
|
|
173
321
|
time?: string;
|
|
174
322
|
} | (ProviderRefusal & {
|
|
@@ -179,11 +327,21 @@ export type MutationResult = {
|
|
|
179
327
|
kind: 'rejected';
|
|
180
328
|
affected: Readonly<Record<string, string>>;
|
|
181
329
|
}) | RetryableRefusal | {
|
|
330
|
+
kind: 'write-halted';
|
|
331
|
+
} | {
|
|
182
332
|
kind: 'expired';
|
|
183
333
|
} | AdapterFailure;
|
|
334
|
+
export type HistoryAuthor = {
|
|
335
|
+
kind: 'user';
|
|
336
|
+
id: string;
|
|
337
|
+
} | {
|
|
338
|
+
kind: 'site';
|
|
339
|
+
id: string;
|
|
340
|
+
name: string;
|
|
341
|
+
};
|
|
184
342
|
export type HistoryRevision = {
|
|
185
343
|
revision: string;
|
|
186
|
-
author:
|
|
344
|
+
author: HistoryAuthor;
|
|
187
345
|
time: string;
|
|
188
346
|
};
|
|
189
347
|
export type HistoryRequest = {
|
|
@@ -206,41 +364,54 @@ export type ActionRequest = {
|
|
|
206
364
|
name: string;
|
|
207
365
|
input: unknown;
|
|
208
366
|
};
|
|
367
|
+
export type RoomVersionAt = {
|
|
368
|
+
locator: string;
|
|
369
|
+
roomVersion: string;
|
|
370
|
+
};
|
|
209
371
|
export type ActionResult = {
|
|
210
372
|
kind: 'action';
|
|
211
373
|
result: unknown;
|
|
374
|
+
at?: RoomVersionAt;
|
|
212
375
|
} | (ProviderRefusal & {
|
|
213
376
|
kind: 'rejected';
|
|
214
377
|
}) | AdapterFailure;
|
|
215
|
-
export type
|
|
216
|
-
locator: string;
|
|
217
|
-
attached: 'collection';
|
|
218
|
-
collectionRoot: string;
|
|
219
|
-
model: ModelIdentity | null;
|
|
220
|
-
} | {
|
|
378
|
+
export type HeldRoom = {
|
|
221
379
|
locator: string;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
380
|
+
roomVersion: string;
|
|
381
|
+
documents: Readonly<Record<string, string>>;
|
|
382
|
+
revisions: Readonly<Record<string, string>>;
|
|
383
|
+
attachments: readonly RoomAttachment[];
|
|
225
384
|
};
|
|
226
|
-
export type
|
|
385
|
+
export type RoomStreamEvent = {
|
|
386
|
+
kind: 'opened';
|
|
387
|
+
} | {
|
|
388
|
+
kind: 'closed';
|
|
389
|
+
revoked: boolean;
|
|
390
|
+
} | {
|
|
391
|
+
kind: 'opening';
|
|
392
|
+
expired: readonly string[];
|
|
393
|
+
} | {
|
|
394
|
+
kind: 'room-version';
|
|
227
395
|
locator: string;
|
|
228
396
|
roomVersion: string;
|
|
229
397
|
};
|
|
230
|
-
export type
|
|
231
|
-
|
|
232
|
-
observe(notify: (
|
|
398
|
+
export type RoomStream = {
|
|
399
|
+
hold(rooms: readonly HeldRoom[]): void;
|
|
400
|
+
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
233
401
|
};
|
|
234
402
|
export type Adapter = {
|
|
235
|
-
model(authorization: Authorization, request: ModelRequest): Promise<ModelResult>;
|
|
236
403
|
authorize(): Promise<Authorization>;
|
|
237
404
|
discover(authorization: Authorization): Promise<DiscoverResult>;
|
|
238
405
|
bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
|
|
239
406
|
refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
|
|
240
|
-
mutate(authorization: Authorization, request: MutationRequest): Promise<MutationResult>;
|
|
407
|
+
mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
|
|
241
408
|
history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
|
|
242
409
|
action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
|
|
243
|
-
|
|
244
|
-
|
|
410
|
+
reached(locator: string, roomVersion: string, target: string): boolean;
|
|
411
|
+
follows(locator: string, roomVersion: string, next: string): boolean;
|
|
412
|
+
roomStream?: RoomStream;
|
|
413
|
+
conversations?: ConversationStream;
|
|
414
|
+
serviceMode?: ServiceModeSignal;
|
|
245
415
|
};
|
|
416
|
+
export {};
|
|
246
417
|
//# sourceMappingURL=adapter.d.ts.map
|