@agentshouse/mdruntime 0.1.0-c037654ea7e04 → 0.1.0-c0cea65344137
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 +166 -99
- package/README.md +20 -10
- package/dist/adapter.d.ts +48 -14
- package/dist/adapter.d.ts.map +1 -1
- package/dist/attached-model.d.ts.map +1 -1
- package/dist/attached-model.js +15 -2
- package/dist/attempt.d.ts +16 -0
- package/dist/attempt.d.ts.map +1 -0
- package/dist/attempt.js +57 -0
- package/dist/binary.d.ts +23 -0
- package/dist/binary.d.ts.map +1 -0
- package/dist/binary.js +8 -0
- package/dist/bootstrap.d.ts +17 -5
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +88 -38
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +19 -12
- package/dist/change.d.ts +15 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js +26 -1
- package/dist/chat/acts.d.ts +34 -0
- package/dist/chat/acts.d.ts.map +1 -0
- package/dist/chat/acts.js +36 -0
- package/dist/chat/context.d.ts +3 -0
- package/dist/chat/context.d.ts.map +1 -0
- package/dist/chat/context.js +10 -0
- package/dist/chat/input.d.ts +9 -0
- package/dist/chat/input.d.ts.map +1 -0
- package/dist/chat/input.js +99 -0
- package/dist/chat/kit.d.ts +60 -0
- package/dist/chat/kit.d.ts.map +1 -0
- package/dist/chat/kit.js +123 -0
- package/dist/chat/lasting.d.ts +6 -0
- package/dist/chat/lasting.d.ts.map +1 -0
- package/dist/chat/lasting.js +19 -0
- package/dist/chat/list.d.ts +26 -0
- package/dist/chat/list.d.ts.map +1 -0
- package/dist/chat/list.js +62 -0
- package/dist/chat/markdown.d.ts +20 -0
- package/dist/chat/markdown.d.ts.map +1 -0
- package/dist/chat/markdown.js +188 -0
- package/dist/chat/message.d.ts +6 -0
- package/dist/chat/message.d.ts.map +1 -0
- package/dist/chat/message.js +192 -0
- package/dist/chat/messages.d.ts +21 -0
- package/dist/chat/messages.d.ts.map +1 -0
- package/dist/chat/messages.js +151 -0
- package/dist/chat/name.d.ts +6 -0
- package/dist/chat/name.d.ts.map +1 -0
- package/dist/chat/name.js +37 -0
- package/dist/chat/opened.d.ts +11 -0
- package/dist/chat/opened.d.ts.map +1 -0
- package/dist/chat/opened.js +17 -0
- package/dist/chat/overlay.d.ts +31 -0
- package/dist/chat/overlay.d.ts.map +1 -0
- package/dist/chat/overlay.js +97 -0
- package/dist/chat/parts.d.ts +57 -0
- package/dist/chat/parts.d.ts.map +1 -0
- package/dist/chat/parts.js +119 -0
- package/dist/chat/process.d.ts +20 -0
- package/dist/chat/process.d.ts.map +1 -0
- package/dist/chat/process.js +32 -0
- package/dist/chat/provider.d.ts +63 -0
- package/dist/chat/provider.d.ts.map +1 -0
- package/dist/chat/provider.js +645 -0
- package/dist/chat/question.d.ts +9 -0
- package/dist/chat/question.d.ts.map +1 -0
- package/dist/chat/question.js +80 -0
- package/dist/chat/questions.d.ts +31 -0
- package/dist/chat/questions.d.ts.map +1 -0
- package/dist/chat/questions.js +111 -0
- package/dist/chat/read.d.ts +5 -0
- package/dist/chat/read.d.ts.map +1 -0
- package/dist/chat/read.js +13 -0
- package/dist/chat/ready.d.ts +33 -0
- package/dist/chat/ready.d.ts.map +1 -0
- package/dist/chat/ready.js +91 -0
- package/dist/chat/style.d.ts +4 -0
- package/dist/chat/style.d.ts.map +1 -0
- package/dist/chat/style.js +302 -0
- package/dist/chat.d.ts +14 -0
- package/dist/chat.d.ts.map +1 -0
- package/dist/chat.js +8 -0
- package/dist/client.d.ts +14 -5
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +65 -15
- package/dist/collection.d.ts +6 -11
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +56 -19
- package/dist/connection.d.ts +21 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +469 -142
- package/dist/conversation.d.ts +11 -3
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +47 -7
- package/dist/expectation.d.ts +21 -0
- package/dist/expectation.d.ts.map +1 -0
- package/dist/expectation.js +70 -0
- package/dist/failure.d.ts +13 -0
- package/dist/failure.d.ts.map +1 -0
- package/dist/failure.js +19 -0
- package/dist/host.d.ts +2 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +12 -11
- package/dist/identity.d.ts +3 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +13 -1
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/memory.d.ts +4 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +60 -20
- package/dist/model.d.ts +10 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +2 -0
- package/dist/open.d.ts +2 -0
- package/dist/open.d.ts.map +1 -0
- package/dist/open.js +1 -0
- package/dist/outcome.d.ts +28 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +41 -1
- package/dist/overlay.d.ts +14 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +75 -37
- package/dist/query.d.ts +5 -1
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +52 -19
- package/dist/reach.d.ts +2 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +43 -19
- package/dist/react.d.ts +26 -16
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +10 -8
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +111 -48
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +42 -38
- package/dist/replica.d.ts +8 -5
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +76 -56
- package/dist/room-draft.d.ts +26 -9
- package/dist/room-draft.d.ts.map +1 -1
- package/dist/room-draft.js +132 -23
- package/dist/rows.d.ts +7 -2
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +87 -39
- package/dist/save.d.ts +27 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +340 -35
- package/dist/search.d.ts +3 -2
- package/dist/search.d.ts.map +1 -1
- package/dist/status.d.ts +2 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +0 -8
- package/dist/store.d.ts +36 -10
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +310 -164
- package/dist/wire.d.ts +7 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -2
- package/package.json +22 -14
- package/dist/attachment.d.ts +0 -3
- package/dist/attachment.d.ts.map +0 -1
- package/dist/attachment.js +0 -8
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
|
-
|
|
5
|
-
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.
|
|
6
5
|
|
|
7
6
|
## The MD Runtime API
|
|
8
7
|
|
|
9
8
|
App code reaches the MD Runtime through the remote client. The surfaces are
|
|
10
|
-
Rooms, Query, Search, Observe, Types, Room Draft, Save, History,
|
|
11
|
-
the reported persistence answer, reauthorization,
|
|
12
|
-
and Presentation State. Sync Status, the Service
|
|
13
|
-
statement
|
|
9
|
+
Rooms, Query, Search, Observe, Types, Room Draft, Save, History, the binary file
|
|
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
|
-
|
|
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
|
|
@@ -27,47 +26,73 @@ value whole and returns its unsubscribe, and `close()` ends the observation.
|
|
|
27
26
|
Closing the port ends every handle and rejects every pending call and
|
|
28
27
|
observation; a client that reconnects observes again.
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
`
|
|
34
|
-
and
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
and
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
each with
|
|
49
|
-
`
|
|
50
|
-
|
|
29
|
+
`observe('agents')` answers every Agent a new conversation can go to, each
|
|
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.
|
|
51
63
|
|
|
52
64
|
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
53
|
-
touch the network.
|
|
54
|
-
|
|
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
|
|
55
68
|
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
56
69
|
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
57
70
|
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
58
71
|
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
59
72
|
that document was written at a later Room Version. Each History revision
|
|
60
|
-
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
73
|
+
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
74
|
+
History of a Path no current document holds answers the removed document's
|
|
75
|
+
revisions with `deleted: true`, newest first; that revision is what a link to
|
|
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.
|
|
71
96
|
|
|
72
97
|
## Local Query rules
|
|
73
98
|
|
|
@@ -79,41 +104,47 @@ data:
|
|
|
79
104
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
80
105
|
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
81
106
|
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
82
|
-
- **Fields.**
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
107
|
+
- **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
|
|
108
|
+
`/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
|
|
109
|
+
meets a list applies to every item and a number names one item. `where` names
|
|
110
|
+
pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
|
|
111
|
+
when any item satisfies it. A bare value is equality; the operators are `$eq`,
|
|
112
|
+
`$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
|
|
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.
|
|
91
119
|
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
92
|
-
reference `field
|
|
93
|
-
`backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
120
|
+
reference at pointer `field`, at any depth, points to a matching Document of the
|
|
121
|
+
same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
94
122
|
matching Document of the same Room references. Each keeps a Document once.
|
|
95
123
|
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
96
|
-
`preamble`, `markdown`, `backlinks` and `change`, where `fields`
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
124
|
+
`preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
|
|
125
|
+
list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
126
|
+
return the frontmatter holding only them, nested as written. A backlink names
|
|
127
|
+
the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
|
|
128
|
+
Document also returns its MD Type. A non-Markdown Document returns only Room
|
|
129
|
+
and Path, and a binary Path entry Room, Path and its `binaryFile` record,
|
|
130
|
+
whatever is selected. An unselected part is absent. Select only
|
|
100
131
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
101
132
|
- **Change.** `change` is `{ author, time }` of the Document's head revision as
|
|
102
133
|
the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
|
|
103
134
|
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
104
135
|
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
105
136
|
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
|
|
137
|
+
saved write takes the Provider's own once it is Accepted. A
|
|
107
138
|
Room's last change is its Document with the latest `time`.
|
|
108
139
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
109
140
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
110
141
|
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
111
|
-
over every match and ordered by `count` or a key.
|
|
112
|
-
or the groups.
|
|
142
|
+
over every match and ordered by `count` or a key. A sort or group takes only a
|
|
143
|
+
pointer that holds one value. `limit` bounds the Documents or the groups.
|
|
113
144
|
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
114
|
-
Rooms and Sync Status. An invalid query fails with `
|
|
115
|
-
`unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
116
|
-
answers an empty result in its place.
|
|
145
|
+
Rooms and Sync Status. An invalid query fails with the `code`
|
|
146
|
+
`invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
147
|
+
and never answers an empty result in its place.
|
|
117
148
|
|
|
118
149
|
## Local Search rules
|
|
119
150
|
|
|
@@ -137,25 +168,24 @@ search.
|
|
|
137
168
|
|
|
138
169
|
## Room Draft, Save, and outcome rules
|
|
139
170
|
|
|
140
|
-
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
base. A
|
|
149
|
-
`
|
|
150
|
-
the current Room Draft; read it and write again.
|
|
171
|
+
The MD Runtime owns one Room Draft per Room and Path, shared by every App and tab.
|
|
172
|
+
It is durable: it survives reload and navigation. A Room that Discovery stops
|
|
173
|
+
listing takes its Room Drafts and its queue with it. Write a Room Draft with
|
|
174
|
+
`roomDraft.write(room, path, revision, parts)`, naming the revision you read, or
|
|
175
|
+
`null` when there was none, and every part it should now change: fields, sections
|
|
176
|
+
and the preamble, or the whole Markdown, a creation, a move, or a removal. A part
|
|
177
|
+
new to the Room Draft names its base, the value you showed when it was opened; the
|
|
178
|
+
MD Runtime keeps a part's first base; a binary Path entry's move or removal takes
|
|
179
|
+
`null` as its base. A write or a discard from an older revision is refused as
|
|
180
|
+
`stale` with the current Room Draft; read it and write again.
|
|
151
181
|
|
|
152
182
|
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
153
183
|
validates locally, and on success appends one Change Batch to that Room's
|
|
154
|
-
queue and removes those Room Drafts. It is refused
|
|
184
|
+
queue and removes those Room Drafts. It is refused with the `code` `stale`,
|
|
155
185
|
`changed-underneath` naming each part whose base no longer matches the visible
|
|
156
|
-
state, or
|
|
186
|
+
state, or a local validation rule, and then creates nothing and leaves every
|
|
157
187
|
Room Draft in place. A directory move or removal is a move or removal part on
|
|
158
|
-
each Document and binary
|
|
188
|
+
each Document and binary Path entry beneath it, saved together.
|
|
159
189
|
|
|
160
190
|
Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
|
|
161
191
|
queue, drawn over the confirmed layer, until the confirmed layer reaches the
|
|
@@ -173,12 +203,17 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
|
173
203
|
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
174
204
|
combines, reorders, or rebases.
|
|
175
205
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
206
|
+
On a Site, every Save stays in the visitor's browser. Write grants and revisions
|
|
207
|
+
do not refuse it, and its Pending Change shows in every query and across reloads
|
|
208
|
+
until the browser's storage is cleared. It is never sent: `observe('queue', room)`
|
|
209
|
+
shows it `local`, and Sync Status never waits on it. Once the Room changes so that
|
|
210
|
+
it no longer applies, it leaves the queue and returns no Room Draft.
|
|
211
|
+
|
|
212
|
+
`observe('service-mode')` answers the Provider's Service Mode, `open` or
|
|
213
|
+
`write-halted`. While writes are halted, Save still succeeds, its Change Batch
|
|
214
|
+
waits unsent, and the queue is submitted in order once the Provider reopens
|
|
215
|
+
writes. An Action is never held: a write the Provider refuses for the halt returns
|
|
216
|
+
that refusal to its caller. Show the Provider as read-only instead of retrying.
|
|
182
217
|
|
|
183
218
|
## The neutrality rule
|
|
184
219
|
|
|
@@ -208,23 +243,55 @@ the network. Data lives only in the App Creator's browser and with the Provider.
|
|
|
208
243
|
|
|
209
244
|
## App code takes the client its host hands it and never constructs a Runtime
|
|
210
245
|
|
|
211
|
-
App code takes the client its host hands it: in House,
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
served App does not.
|
|
246
|
+
App code takes the client its host hands it: in House, `houseBridge().runtime`
|
|
247
|
+
from `@agentshouse/app-bridge` resolves to the client House built into the page.
|
|
248
|
+
It imports only types from `@agentshouse/mdruntime/client`, never calls
|
|
249
|
+
`connectMdRuntime` or `serveMdRuntime`, and never imports the package main, the
|
|
250
|
+
host entry or the Adapter package, which hosts and tests use. The in-memory
|
|
251
|
+
Adapter at `@agentshouse/mdruntime/memory` is for tests and ships in no bundle.
|
|
218
252
|
|
|
219
253
|
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
220
254
|
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
221
|
-
the arguments of `observe` and returns the topic's
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
`
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
or discard; a failure is
|
|
255
|
+
the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
|
|
256
|
+
first value arrives, then `{ state: 'ready', value }`, re-rendering on each
|
|
257
|
+
change; a `null` client observes nothing and stays loading. `useSave(client)`
|
|
258
|
+
returns `busy`, the last `outcome` or `failure`, and `save(room, roomDrafts)`,
|
|
259
|
+
which writes each Path's parts onto the Room Draft already there, keeping the
|
|
260
|
+
bases its parts have, or onto a new one, and saves them together. A refused
|
|
261
|
+
Save leaves the Room Drafts for the App to save again or discard; a failure is
|
|
262
|
+
recorded and rejects. `saveRoomDrafts(client, room, roomDrafts)` is that save
|
|
263
|
+
outside a component. A react-admin or Refine App reads and writes its Rooms
|
|
264
|
+
through the data providers of `@agentshouse/mdruntime-families`.
|
|
265
|
+
|
|
266
|
+
## The Chat
|
|
267
|
+
|
|
268
|
+
`@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App.
|
|
269
|
+
Its required peers are React, React DOM and `@assistant-ui/react`: add React as
|
|
270
|
+
a dependency, also in an App not written in React.
|
|
271
|
+
|
|
272
|
+
Place the ready chat with `<Chat client={runtime} conversation={id}
|
|
273
|
+
agent={agent} width="1/3" showChats />`: `conversation` opens one, `null` for a
|
|
274
|
+
new chat, `agent` is the Agent a new chat goes to, `onOpen` hears each one it
|
|
275
|
+
opens, and `width` is `full` (the place you give it), or `3/4`, `1/2` or `1/3`
|
|
276
|
+
of the window docked at its right edge, whole on a narrow window. `showChats`
|
|
277
|
+
adds its conversation list; or draw your own inside a `ChatProvider` around a
|
|
278
|
+
`<Chat />` with no `client`. It carries its own styles; theme it with CSS custom
|
|
279
|
+
properties on it or an ancestor: `--chat-background`, `--chat-surface`,
|
|
280
|
+
`--chat-text`, `--chat-text-muted`, `--chat-accent`, `--chat-line`,
|
|
281
|
+
`--chat-attention`, `--chat-danger`, `--chat-font`, `--chat-font-mono`,
|
|
282
|
+
`--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for spacing);
|
|
283
|
+
an unset one keeps House's light or dark look. `mountChat(element, { client })`
|
|
284
|
+
places it outside React and returns `update(props)` and `unmount()`.
|
|
285
|
+
|
|
286
|
+
Mix `ChatMessageList` (`components` takes your `UserMessage` and
|
|
287
|
+
`AssistantMessage`), `ChatInput` and `ChatQuestionCard` with your own design
|
|
288
|
+
inside a `ChatProvider`, or compose assistant-ui's primitives there; `useChat()`
|
|
289
|
+
gives `send`, the conversations, the Agents, questions to `answer`, `options`
|
|
290
|
+
to `choose`, `commands`, the queue to `edit` or `unqueue`, `stop`, `kill` and
|
|
291
|
+
outcomes; never replace its messages, sending or store. A secret question is
|
|
292
|
+
never answered here; typed answers live in Presentation State's `typed` key:
|
|
293
|
+
keep it, and change Presentation State only inside `inTurn(client, work)` from
|
|
294
|
+
`@agentshouse/mdruntime/client`. `Markdown` draws Markdown safely.
|
|
228
295
|
|
|
229
296
|
## What an agent must never do
|
|
230
297
|
|
package/README.md
CHANGED
|
@@ -12,22 +12,23 @@ npm install @agentshouse/mdruntime
|
|
|
12
12
|
|
|
13
13
|
## Entries
|
|
14
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
|
|
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 over the client: `useObserve`, `useSave`, `saveRoomDrafts` |
|
|
22
|
+
| `@agentshouse/mdruntime/chat` | The Chat: `Chat`, `mountChat`, its parts and `ChatProvider` |
|
|
22
23
|
|
|
23
24
|
## Usage
|
|
24
25
|
|
|
25
26
|
App code takes the client its host hands it; in House the App bridge hands it:
|
|
26
27
|
|
|
27
28
|
```ts
|
|
28
|
-
import {
|
|
29
|
+
import { houseBridge } from '@agentshouse/app-bridge';
|
|
29
30
|
|
|
30
|
-
const runtime = await
|
|
31
|
+
const runtime = await houseBridge().runtime;
|
|
31
32
|
const rooms = await runtime.rooms();
|
|
32
33
|
const notes = await runtime.query({ types: ['note'], select: 'all', limit: 20 });
|
|
33
34
|
```
|
|
@@ -36,8 +37,17 @@ const notes = await runtime.query({ types: ['note'], select: 'all', limit: 20 })
|
|
|
36
37
|
`storage-loss` when unsynchronized Room Drafts and Pending Changes were lost.
|
|
37
38
|
The host supplies the user-facing wording.
|
|
38
39
|
|
|
40
|
+
Place the ready chat, themed by CSS custom properties, docked at a third of the
|
|
41
|
+
window; outside React, `mountChat(element, { client: runtime })` places the same:
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
import { Chat } from '@agentshouse/mdruntime/chat';
|
|
45
|
+
|
|
46
|
+
<Chat client={runtime} width="1/3" showChats style={{ '--chat-accent': '#2a6cf0' }} />;
|
|
47
|
+
```
|
|
48
|
+
|
|
39
49
|
The rules an App's agent follows, including Local Query, Local Search, Room
|
|
40
|
-
Draft and
|
|
50
|
+
Draft, Save and the Chat, are in [`AGENTS.md`](AGENTS.md).
|
|
41
51
|
|
|
42
52
|
## License
|
|
43
53
|
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ModelResult } from './model.js';
|
|
2
|
+
import type { Open } from './open.js';
|
|
2
3
|
import type { ChangeBatch } from './change.js';
|
|
3
4
|
export type Authorization = object;
|
|
4
5
|
export type MdModelIdentity = {
|
|
@@ -16,7 +17,7 @@ export type OperationScopes = {
|
|
|
16
17
|
};
|
|
17
18
|
export type ReplicaAdmission = {
|
|
18
19
|
selection: string;
|
|
19
|
-
admission: 'admitted' | 'unavailable'
|
|
20
|
+
admission: Open<'admitted' | 'unavailable'>;
|
|
20
21
|
};
|
|
21
22
|
export type DiscoveredRoom = {
|
|
22
23
|
name: string;
|
|
@@ -39,6 +40,7 @@ export type ConversationAgents = {
|
|
|
39
40
|
type: string;
|
|
40
41
|
identity: string;
|
|
41
42
|
name: string;
|
|
43
|
+
retired?: string;
|
|
42
44
|
};
|
|
43
45
|
export type ListedConversation = {
|
|
44
46
|
conversation: string;
|
|
@@ -207,6 +209,7 @@ export type Discovery = {
|
|
|
207
209
|
capabilities: readonly Capability[];
|
|
208
210
|
providerLimits: readonly ProviderLimit[];
|
|
209
211
|
retention: Retention;
|
|
212
|
+
member?: Member;
|
|
210
213
|
};
|
|
211
214
|
export type TransportUncertainty = {
|
|
212
215
|
kind: 'transport-uncertainty';
|
|
@@ -221,11 +224,12 @@ export type RevokedAuthorization = {
|
|
|
221
224
|
export type ProviderRefusal = {
|
|
222
225
|
code: string;
|
|
223
226
|
fields: Readonly<Record<string, unknown>>;
|
|
227
|
+
retryable: boolean;
|
|
224
228
|
};
|
|
225
229
|
export type ScopedRefusal = ProviderRefusal & {
|
|
226
230
|
kind: 'scoped-refusal';
|
|
227
231
|
locator: string;
|
|
228
|
-
scope: 'content' | 'sync' | 'model' | 'operation' | 'undisclosed'
|
|
232
|
+
scope: Open<'content' | 'sync' | 'model' | 'operation' | 'undisclosed'>;
|
|
229
233
|
};
|
|
230
234
|
export type AdapterFailure = TransportUncertainty | RoomNotReadable | RevokedAuthorization | ScopedRefusal;
|
|
231
235
|
export type ContractUnavailable = ProviderRefusal & {
|
|
@@ -242,16 +246,18 @@ export type ChangeAuthor = {
|
|
|
242
246
|
id: string;
|
|
243
247
|
name: string;
|
|
244
248
|
};
|
|
249
|
+
export type Member = Extract<ChangeAuthor, {
|
|
250
|
+
kind: 'user';
|
|
251
|
+
}>;
|
|
245
252
|
export type HeadChange = {
|
|
246
253
|
author: ChangeAuthor | null;
|
|
247
254
|
time: string;
|
|
248
255
|
};
|
|
249
|
-
export type
|
|
250
|
-
|
|
251
|
-
name: string;
|
|
256
|
+
export type BinaryFile = {
|
|
257
|
+
fileRef: string;
|
|
252
258
|
byteLength: number;
|
|
253
|
-
mediaType: string
|
|
254
|
-
|
|
259
|
+
mediaType: string;
|
|
260
|
+
sha256: string;
|
|
255
261
|
};
|
|
256
262
|
export type BootstrapRequest = {
|
|
257
263
|
locator: string;
|
|
@@ -269,8 +275,7 @@ export type BootstrapPage = {
|
|
|
269
275
|
documents: Readonly<Record<string, string>>;
|
|
270
276
|
revisions: Readonly<Record<string, string>>;
|
|
271
277
|
changes: Readonly<Record<string, HeadChange>>;
|
|
272
|
-
|
|
273
|
-
attachments?: readonly RoomAttachment[];
|
|
278
|
+
binaryFiles: Readonly<Record<string, BinaryFile>>;
|
|
274
279
|
pageToken?: PageToken;
|
|
275
280
|
};
|
|
276
281
|
export type BootstrapResult = BootstrapPage | AdapterFailure;
|
|
@@ -287,9 +292,8 @@ export type RefreshPage = {
|
|
|
287
292
|
documents: Readonly<Record<string, string>>;
|
|
288
293
|
revisions: Readonly<Record<string, string>>;
|
|
289
294
|
changes: Readonly<Record<string, HeadChange>>;
|
|
290
|
-
|
|
295
|
+
binaryFiles: Readonly<Record<string, BinaryFile>>;
|
|
291
296
|
removals: readonly string[];
|
|
292
|
-
attachments?: readonly RoomAttachment[];
|
|
293
297
|
pageToken?: PageToken;
|
|
294
298
|
};
|
|
295
299
|
export type RefreshResult = {
|
|
@@ -306,7 +310,7 @@ export type RetryableRefusal = ProviderRefusal & {
|
|
|
306
310
|
kind: 'retryable-refusal';
|
|
307
311
|
reset?: string;
|
|
308
312
|
};
|
|
309
|
-
export type ServiceMode = 'open' | 'write-halted'
|
|
313
|
+
export type ServiceMode = Open<'open' | 'write-halted'>;
|
|
310
314
|
export type ServiceModeSignal = {
|
|
311
315
|
observe(notify: (mode: ServiceMode) => void): () => void;
|
|
312
316
|
};
|
|
@@ -315,8 +319,9 @@ export type MutationResult = {
|
|
|
315
319
|
roomVersion: string;
|
|
316
320
|
documents: Readonly<Record<string, string>>;
|
|
317
321
|
revisions: Readonly<Record<string, string>>;
|
|
322
|
+
changes: Readonly<Record<string, HeadChange>>;
|
|
318
323
|
removals: readonly string[];
|
|
319
|
-
|
|
324
|
+
binaryFiles?: Readonly<Record<string, BinaryFile>>;
|
|
320
325
|
author?: string;
|
|
321
326
|
time?: string;
|
|
322
327
|
} | (ProviderRefusal & {
|
|
@@ -343,6 +348,7 @@ export type HistoryRevision = {
|
|
|
343
348
|
revision: string;
|
|
344
349
|
author: HistoryAuthor;
|
|
345
350
|
time: string;
|
|
351
|
+
binaryFile?: BinaryFile;
|
|
346
352
|
};
|
|
347
353
|
export type HistoryRequest = {
|
|
348
354
|
locator: string;
|
|
@@ -354,12 +360,37 @@ export type HistoryResult = {
|
|
|
354
360
|
kind: 'history';
|
|
355
361
|
revisions: readonly HistoryRevision[];
|
|
356
362
|
pageToken?: PageToken;
|
|
363
|
+
deleted?: true;
|
|
357
364
|
} | {
|
|
358
365
|
kind: 'revision';
|
|
359
366
|
content: string;
|
|
360
367
|
} | {
|
|
361
368
|
kind: 'no-history';
|
|
362
369
|
} | AdapterFailure;
|
|
370
|
+
export type BinaryRequest = {
|
|
371
|
+
kind: 'path';
|
|
372
|
+
locator: string;
|
|
373
|
+
path: string;
|
|
374
|
+
revision: string;
|
|
375
|
+
fileRef?: string;
|
|
376
|
+
} | {
|
|
377
|
+
kind: 'reference';
|
|
378
|
+
fileRef: string;
|
|
379
|
+
referrer: unknown;
|
|
380
|
+
};
|
|
381
|
+
export type ReferrerScope = {
|
|
382
|
+
kind: 'room';
|
|
383
|
+
locator: string;
|
|
384
|
+
path?: string;
|
|
385
|
+
} | {
|
|
386
|
+
kind: 'conversations';
|
|
387
|
+
};
|
|
388
|
+
export type BinaryResult = {
|
|
389
|
+
kind: 'binary';
|
|
390
|
+
blob: Blob;
|
|
391
|
+
} | (ProviderRefusal & {
|
|
392
|
+
kind: 'rejected';
|
|
393
|
+
}) | AdapterFailure;
|
|
363
394
|
export type ActionRequest = {
|
|
364
395
|
name: string;
|
|
365
396
|
input: unknown;
|
|
@@ -380,7 +411,6 @@ export type HeldRoom = {
|
|
|
380
411
|
roomVersion: string;
|
|
381
412
|
documents: Readonly<Record<string, string>>;
|
|
382
413
|
revisions: Readonly<Record<string, string>>;
|
|
383
|
-
attachments: readonly RoomAttachment[];
|
|
384
414
|
};
|
|
385
415
|
export type RoomStreamEvent = {
|
|
386
416
|
kind: 'opened';
|
|
@@ -397,15 +427,19 @@ export type RoomStreamEvent = {
|
|
|
397
427
|
};
|
|
398
428
|
export type RoomStream = {
|
|
399
429
|
hold(rooms: readonly HeldRoom[]): void;
|
|
430
|
+
reopen(): void;
|
|
400
431
|
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
401
432
|
};
|
|
402
433
|
export type Adapter = {
|
|
434
|
+
readonly localSaves?: true;
|
|
403
435
|
authorize(): Promise<Authorization>;
|
|
404
436
|
discover(authorization: Authorization): Promise<DiscoverResult>;
|
|
405
437
|
bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
|
|
406
438
|
refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
|
|
407
439
|
mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
|
|
408
440
|
history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
|
|
441
|
+
binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
|
|
442
|
+
referrerScope(referrer: unknown): ReferrerScope | null;
|
|
409
443
|
action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
|
|
410
444
|
reached(locator: string, roomVersion: string, target: string): boolean;
|
|
411
445
|
follows(locator: string, roomVersion: string, next: string): boolean;
|