@agentshouse/mdruntime 0.1.0-cacb4c3f6734e → 0.1.0-cb0eb0d87ff49
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 +164 -99
- package/README.md +13 -3
- package/dist/adapter.d.ts +72 -16
- 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 +70 -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 +109 -37
- package/dist/change-set.d.ts +2 -0
- package/dist/change-set.d.ts.map +1 -1
- package/dist/change-set.js +48 -16
- 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 +33 -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 +620 -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 +20 -11
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +66 -16
- package/dist/collection.d.ts +21 -12
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +271 -23
- package/dist/connection.d.ts +29 -14
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +1262 -377
- package/dist/conversation.d.ts +23 -10
- package/dist/conversation.d.ts.map +1 -1
- package/dist/conversation.js +304 -136
- package/dist/entry.d.ts +17 -0
- package/dist/entry.d.ts.map +1 -0
- package/dist/entry.js +156 -0
- 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/fence.d.ts +6 -0
- package/dist/fence.d.ts.map +1 -0
- package/dist/fence.js +10 -0
- package/dist/host.d.ts +4 -1
- package/dist/host.d.ts.map +1 -1
- package/dist/host.js +17 -12
- package/dist/identity.d.ts +5 -0
- package/dist/identity.d.ts.map +1 -1
- package/dist/identity.js +19 -1
- package/dist/index.d.ts +12 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/memory.d.ts +5 -3
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +70 -21
- package/dist/model.d.ts +11 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -0
- package/dist/observation.d.ts +5 -2
- package/dist/observation.d.ts.map +1 -1
- package/dist/observation.js +22 -11
- 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 +32 -3
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +42 -1
- package/dist/overlay.d.ts +15 -3
- package/dist/overlay.d.ts.map +1 -1
- package/dist/overlay.js +94 -77
- package/dist/query.d.ts +32 -3
- package/dist/query.d.ts.map +1 -1
- package/dist/query.js +5 -31
- package/dist/reach.d.ts +2 -0
- package/dist/reach.d.ts.map +1 -1
- package/dist/reach.js +45 -21
- package/dist/react.d.ts +26 -17
- package/dist/react.d.ts.map +1 -1
- package/dist/react.js +8 -6
- package/dist/read-side.d.ts +13 -6
- package/dist/read-side.d.ts.map +1 -1
- package/dist/read-side.js +291 -85
- package/dist/recovery.d.ts +25 -0
- package/dist/recovery.d.ts.map +1 -0
- package/dist/recovery.js +197 -0
- package/dist/refresh.d.ts +10 -0
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +43 -38
- package/dist/replica.d.ts +9 -6
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +116 -68
- 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 +8 -13
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +12 -14
- package/dist/save.d.ts +31 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +376 -45
- package/dist/search.d.ts +31 -8
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +109 -44
- package/dist/shared.d.ts +11 -0
- package/dist/shared.d.ts.map +1 -0
- package/dist/shared.js +368 -0
- 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 +66 -17
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +506 -196
- package/dist/turn.d.ts +7 -0
- package/dist/turn.d.ts.map +1 -0
- package/dist/turn.js +45 -0
- package/dist/wire.d.ts +7 -3
- package/dist/wire.d.ts.map +1 -1
- package/dist/wire.js +15 -2
- package/package.json +26 -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,31 +26,45 @@ 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 a window of its latest
|
|
37
|
+
`limit` 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;
|
|
@@ -60,24 +73,37 @@ that document was written at a later Room Version. Each History revision
|
|
|
60
73
|
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
61
74
|
History of a Path no current document holds answers the removed document's
|
|
62
75
|
revisions with `deleted: true`, newest first; that revision is what a link to
|
|
63
|
-
the Path opens. Every
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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.
|
|
74
96
|
|
|
75
97
|
## Local Query rules
|
|
76
98
|
|
|
77
99
|
`query(q)` answers once from local state; `observe('query', q)` holds the whole
|
|
78
100
|
result and hears it again only when it changes, keeping every unchanged Document
|
|
79
|
-
the same object, so a component can tell what changed by identity.
|
|
80
|
-
|
|
101
|
+
the same object, so a component can tell what changed by identity. An answer is
|
|
102
|
+
complete or pending: `{ documents, coverage }` or `{ groups, coverage }` is
|
|
103
|
+
complete for the Rooms its `coverage` names, and `{ pending }` names each Room
|
|
104
|
+
not yet acquired or prepared, `[{ room, awaits }]`. Never read a pending answer as
|
|
105
|
+
empty: draw it as loading, and observe the query to hear the complete one. A
|
|
106
|
+
query is data:
|
|
81
107
|
|
|
82
108
|
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
83
109
|
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
@@ -88,13 +114,12 @@ data:
|
|
|
88
114
|
pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
|
|
89
115
|
when any item satisfies it. A bare value is equality; the operators are `$eq`,
|
|
90
116
|
`$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
|
|
91
|
-
`$exists`. Equality on a list asks whether it contains the value. Missing,
|
|
92
|
-
`$exists: false` keeps a missing field, `null` an
|
|
93
|
-
text and `$size: 0` an empty list. A date compares
|
|
94
|
-
with a date-time. A reference compares by the Room
|
|
95
|
-
Untyped frontmatter, and a value under `oneOf` or a
|
|
96
|
-
values. There is no text containment or regular
|
|
97
|
-
expression.
|
|
117
|
+
`$exists`. Equality on a list asks whether it contains the value. Missing,
|
|
118
|
+
null and empty differ: `$exists: false` keeps a missing field, `null` an
|
|
119
|
+
explicit null, `''` empty text and `$size: 0` an empty list. A date compares
|
|
120
|
+
in calendar order and never with a date-time. A reference compares by the Room
|
|
121
|
+
Path it resolves to. Untyped frontmatter, and a value under `oneOf` or a
|
|
122
|
+
conditional, is plain values. There is no text containment or regular expression.
|
|
98
123
|
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
99
124
|
reference at pointer `field`, at any depth, points to a matching Document of the
|
|
100
125
|
same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
@@ -104,15 +129,16 @@ data:
|
|
|
104
129
|
list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
105
130
|
return the frontmatter holding only them, nested as written. A backlink names
|
|
106
131
|
the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
|
|
107
|
-
Document also returns its MD Type. A non-Markdown Document
|
|
108
|
-
|
|
132
|
+
Document also returns its MD Type. A non-Markdown Document returns only Room
|
|
133
|
+
and Path, and a binary Path entry Room, Path and its `binaryFile` record,
|
|
134
|
+
whatever is selected. An unselected part is absent. Select only
|
|
109
135
|
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
110
136
|
- **Change.** `change` is `{ author, time }` of the Document's head revision as
|
|
111
137
|
the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
|
|
112
138
|
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
113
139
|
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
114
140
|
a Site. An unsent edit or move keeps it, an unsent creation has none, and a
|
|
115
|
-
saved write takes the Provider's own once it is Accepted
|
|
141
|
+
saved write takes the Provider's own once it is Accepted. A
|
|
116
142
|
Room's last change is its Document with the latest `time`.
|
|
117
143
|
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
118
144
|
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
@@ -120,15 +146,17 @@ data:
|
|
|
120
146
|
over every match and ordered by `count` or a key. A sort or group takes only a
|
|
121
147
|
pointer that holds one value. `limit` bounds the Documents or the groups.
|
|
122
148
|
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
123
|
-
Rooms and Sync Status.
|
|
124
|
-
|
|
125
|
-
|
|
149
|
+
Rooms and Sync Status. `coverage` names each Room read as `{ room, generation,
|
|
150
|
+
current }`, `current` false while a newer copy of that Room is being fetched,
|
|
151
|
+
and the queued changes it includes as `overlay`; a Save in a Room changes the
|
|
152
|
+
`overlay` of every query over it. An invalid query fails with the `code`
|
|
153
|
+
`invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
|
|
154
|
+
and never answers an empty result in its place.
|
|
126
155
|
|
|
127
156
|
## Local Search rules
|
|
128
157
|
|
|
129
158
|
`search({ text, documents, conversations, limit })` answers once, by words, from
|
|
130
|
-
local state, with MiniSearch
|
|
131
|
-
search.
|
|
159
|
+
local state, with MiniSearch's defaults. There is no observed search.
|
|
132
160
|
|
|
133
161
|
- **What is found.** A Document by its field values, its sections' headings and
|
|
134
162
|
text, its preamble and its Path; a message by its text. Frontmatter keys, Room
|
|
@@ -137,7 +165,10 @@ search.
|
|
|
137
165
|
- **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
|
|
138
166
|
`pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
|
|
139
167
|
apply before `limit`, which bounds each list; without it every hit returns.
|
|
140
|
-
- **Results.** `{ documents, messages }`,
|
|
168
|
+
- **Results.** `{ documents, messages, coverage }`, or `{ pending }` naming each
|
|
169
|
+
Room or conversation the search waits for while its index is prepared: ask
|
|
170
|
+
again, and never read pending as no hits. `coverage` names the Rooms and
|
|
171
|
+
conversations searched. Each list is ranked by `score`, which compares
|
|
141
172
|
hits of one list of one search. A Document hit names its `room`, `path` and
|
|
142
173
|
`type`, a message hit its `conversation` and `identity`, and `matches` maps each
|
|
143
174
|
matched word to the parts it matched in: `fields`, `sections`, `preamble` or
|
|
@@ -146,25 +177,24 @@ search.
|
|
|
146
177
|
|
|
147
178
|
## Room Draft, Save, and outcome rules
|
|
148
179
|
|
|
149
|
-
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
base. A
|
|
158
|
-
`
|
|
159
|
-
the current Room Draft; read it and write again.
|
|
180
|
+
The MD Runtime owns one Room Draft per Room and Path, shared by every App and tab.
|
|
181
|
+
It is durable: it survives reload and navigation. A Room that Discovery stops
|
|
182
|
+
listing takes its Room Drafts and its queue with it. Write a Room Draft with
|
|
183
|
+
`roomDraft.write(room, path, revision, parts)`, naming the revision you read, or
|
|
184
|
+
`null` when there was none, and every part it should now change: fields, sections
|
|
185
|
+
and the preamble, or the whole Markdown, a creation, a move, or a removal. A part
|
|
186
|
+
new to the Room Draft names its base, the value you showed when it was opened; the
|
|
187
|
+
MD Runtime keeps a part's first base; a binary Path entry's move or removal takes
|
|
188
|
+
`null` as its base. A write or a discard from an older revision is refused as
|
|
189
|
+
`stale` with the current Room Draft; read it and write again.
|
|
160
190
|
|
|
161
191
|
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
162
192
|
validates locally, and on success appends one Change Batch to that Room's
|
|
163
|
-
queue and removes those Room Drafts. It is refused
|
|
193
|
+
queue and removes those Room Drafts. It is refused with the `code` `stale`,
|
|
164
194
|
`changed-underneath` naming each part whose base no longer matches the visible
|
|
165
|
-
state, or
|
|
195
|
+
state, or a local validation rule, and then creates nothing and leaves every
|
|
166
196
|
Room Draft in place. A directory move or removal is a move or removal part on
|
|
167
|
-
each Document and binary
|
|
197
|
+
each Document and binary Path entry beneath it, saved together.
|
|
168
198
|
|
|
169
199
|
Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
|
|
170
200
|
queue, drawn over the confirmed layer, until the confirmed layer reaches the
|
|
@@ -182,12 +212,17 @@ it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
|
182
212
|
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
183
213
|
combines, reorders, or rebases.
|
|
184
214
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
215
|
+
On a Site, every Save stays in the visitor's browser. Write grants and revisions
|
|
216
|
+
do not refuse it, and its Pending Change shows in every query and across reloads
|
|
217
|
+
until the browser's storage is cleared. It is never sent: `observe('queue', room)`
|
|
218
|
+
shows it `local`, and Sync Status never waits on it. Once the Room changes so that
|
|
219
|
+
it no longer applies, it leaves the queue and returns no Room Draft.
|
|
220
|
+
|
|
221
|
+
`observe('service-mode')` answers the Provider's Service Mode, `open` or
|
|
222
|
+
`write-halted`. While writes are halted, Save still succeeds, its Change Batch
|
|
223
|
+
waits unsent, and the queue is submitted in order once the Provider reopens
|
|
224
|
+
writes. An Action is never held: a write the Provider refuses for the halt returns
|
|
225
|
+
that refusal to its caller. Show the Provider as read-only instead of retrying.
|
|
191
226
|
|
|
192
227
|
## The neutrality rule
|
|
193
228
|
|
|
@@ -217,26 +252,56 @@ the network. Data lives only in the App Creator's browser and with the Provider.
|
|
|
217
252
|
|
|
218
253
|
## App code takes the client its host hands it and never constructs a Runtime
|
|
219
254
|
|
|
220
|
-
App code takes the client its host hands it: in House,
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
255
|
+
App code takes the client its host hands it: in House, `houseBridge().runtime`
|
|
256
|
+
from `@agentshouse/app-bridge` resolves to the client House built into the page.
|
|
257
|
+
It imports only types from `@agentshouse/mdruntime/client`, never calls
|
|
258
|
+
`connectMdRuntime` or `serveMdRuntime`, and never imports the package main, the
|
|
259
|
+
host entry or the Adapter package, which hosts and tests use. The in-memory
|
|
260
|
+
Adapter at `@agentshouse/mdruntime/memory` is for tests and ships in no bundle.
|
|
261
|
+
A Site's page fills its Entry Data Contract's `{"$param": name}` arguments with
|
|
262
|
+
`boundQuery` from `@agentshouse/mdruntime/entry`, as House did for its HTML.
|
|
227
263
|
|
|
228
264
|
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
229
265
|
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
230
|
-
the arguments of `observe` and returns the topic's
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
`
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
or discard; a failure is
|
|
237
|
-
roomDrafts)` is that save
|
|
238
|
-
reads and writes its Rooms
|
|
239
|
-
`@agentshouse/mdruntime-families`.
|
|
266
|
+
the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
|
|
267
|
+
first value arrives, then `{ state: 'ready', value }`, re-rendering on each
|
|
268
|
+
change; a `null` client observes nothing and stays loading. `useSave(client)`
|
|
269
|
+
returns `busy`, the last `outcome` or `failure`, and `save(room, roomDrafts)`,
|
|
270
|
+
which writes each Path's parts onto the Room Draft already there, keeping the
|
|
271
|
+
bases its parts have, or onto a new one, and saves them together. A refused
|
|
272
|
+
Save leaves the Room Drafts for the App to save again or discard; a failure is
|
|
273
|
+
recorded and rejects. `saveRoomDrafts(client, room, roomDrafts)` is that save
|
|
274
|
+
outside a component. A react-admin or Refine App reads and writes its Rooms
|
|
275
|
+
through the data providers of `@agentshouse/mdruntime-families`.
|
|
276
|
+
|
|
277
|
+
## The Chat
|
|
278
|
+
|
|
279
|
+
`@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App; add
|
|
280
|
+
React as a dependency in any App, with React DOM and `@assistant-ui/react`.
|
|
281
|
+
|
|
282
|
+
Place the ready chat with `<Chat client={runtime} conversation={id}
|
|
283
|
+
agent={agent} width="1/3" showChats />`: `conversation` opens one, `null` for a
|
|
284
|
+
new chat, `agent` is the Agent a new chat goes to, `onOpen` hears each one it
|
|
285
|
+
opens, and `width` is `full` (the place you give it), or `3/4`, `1/2` or `1/3`
|
|
286
|
+
of the window docked at its right edge, whole on a narrow window. `showChats`
|
|
287
|
+
adds its conversation list; or draw your own inside a `ChatProvider` around a
|
|
288
|
+
`<Chat />` with no `client`. It carries its own styles; theme it with CSS custom
|
|
289
|
+
properties on it or an ancestor: `--chat-background`, `--chat-surface`,
|
|
290
|
+
`--chat-text`, `--chat-text-muted`, `--chat-accent`, `--chat-line`,
|
|
291
|
+
`--chat-attention`, `--chat-danger`, `--chat-font`, `--chat-font-mono`,
|
|
292
|
+
`--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for spacing);
|
|
293
|
+
an unset one keeps House's light or dark look. `mountChat(element, { client })`
|
|
294
|
+
places it outside React and returns `update(props)` and `unmount()`.
|
|
295
|
+
|
|
296
|
+
Mix `ChatMessageList` (`components` takes your `UserMessage` and
|
|
297
|
+
`AssistantMessage`), `ChatInput` and `ChatQuestionCard` with your own design
|
|
298
|
+
inside a `ChatProvider`, or compose assistant-ui's primitives there; `useChat()`
|
|
299
|
+
gives `send`, the conversations, the Agents, questions to `answer`, `options`
|
|
300
|
+
to `choose`, `commands`, the queue to `edit` or `unqueue`, `stop`, `kill` and
|
|
301
|
+
outcomes; never replace its messages, sending or store. A secret question is
|
|
302
|
+
never answered here; typed answers live in Presentation State's `typed` key:
|
|
303
|
+
keep it, and change Presentation State only inside `inTurn(client, work)` from
|
|
304
|
+
`@agentshouse/mdruntime/client`. `Markdown` draws Markdown safely.
|
|
240
305
|
|
|
241
306
|
## What an agent must never do
|
|
242
307
|
|
package/README.md
CHANGED
|
@@ -19,15 +19,16 @@ npm install @agentshouse/mdruntime
|
|
|
19
19
|
| `@agentshouse/mdruntime` | Shared types |
|
|
20
20
|
| `@agentshouse/mdruntime/memory` | Tests: `createMemoryAdapter`, an in-memory Adapter |
|
|
21
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,21 +246,28 @@ 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;
|
|
261
|
+
};
|
|
262
|
+
export type HeldContent = {
|
|
263
|
+
documents: Readonly<Record<string, string>>;
|
|
264
|
+
revisions: Readonly<Record<string, string>>;
|
|
255
265
|
};
|
|
256
266
|
export type BootstrapRequest = {
|
|
257
267
|
locator: string;
|
|
258
268
|
selection: string;
|
|
259
269
|
pageToken?: PageToken;
|
|
270
|
+
held?: HeldContent;
|
|
260
271
|
};
|
|
261
272
|
export type RoomModels = {
|
|
262
273
|
collection?: ModelResult;
|
|
@@ -269,11 +280,12 @@ export type BootstrapPage = {
|
|
|
269
280
|
documents: Readonly<Record<string, string>>;
|
|
270
281
|
revisions: Readonly<Record<string, string>>;
|
|
271
282
|
changes: Readonly<Record<string, HeadChange>>;
|
|
272
|
-
|
|
273
|
-
attachments?: readonly RoomAttachment[];
|
|
283
|
+
binaryFiles: Readonly<Record<string, BinaryFile>>;
|
|
274
284
|
pageToken?: PageToken;
|
|
275
285
|
};
|
|
276
|
-
export type BootstrapResult = BootstrapPage |
|
|
286
|
+
export type BootstrapResult = BootstrapPage | {
|
|
287
|
+
kind: 'beyond-horizon';
|
|
288
|
+
} | AdapterFailure;
|
|
277
289
|
export type RefreshRequest = {
|
|
278
290
|
locator: string;
|
|
279
291
|
selection: string;
|
|
@@ -287,9 +299,8 @@ export type RefreshPage = {
|
|
|
287
299
|
documents: Readonly<Record<string, string>>;
|
|
288
300
|
revisions: Readonly<Record<string, string>>;
|
|
289
301
|
changes: Readonly<Record<string, HeadChange>>;
|
|
290
|
-
|
|
302
|
+
binaryFiles: Readonly<Record<string, BinaryFile>>;
|
|
291
303
|
removals: readonly string[];
|
|
292
|
-
attachments?: readonly RoomAttachment[];
|
|
293
304
|
pageToken?: PageToken;
|
|
294
305
|
};
|
|
295
306
|
export type RefreshResult = {
|
|
@@ -306,7 +317,7 @@ export type RetryableRefusal = ProviderRefusal & {
|
|
|
306
317
|
kind: 'retryable-refusal';
|
|
307
318
|
reset?: string;
|
|
308
319
|
};
|
|
309
|
-
export type ServiceMode = 'open' | 'write-halted'
|
|
320
|
+
export type ServiceMode = Open<'open' | 'write-halted'>;
|
|
310
321
|
export type ServiceModeSignal = {
|
|
311
322
|
observe(notify: (mode: ServiceMode) => void): () => void;
|
|
312
323
|
};
|
|
@@ -315,8 +326,9 @@ export type MutationResult = {
|
|
|
315
326
|
roomVersion: string;
|
|
316
327
|
documents: Readonly<Record<string, string>>;
|
|
317
328
|
revisions: Readonly<Record<string, string>>;
|
|
329
|
+
changes: Readonly<Record<string, HeadChange>>;
|
|
318
330
|
removals: readonly string[];
|
|
319
|
-
|
|
331
|
+
binaryFiles?: Readonly<Record<string, BinaryFile>>;
|
|
320
332
|
author?: string;
|
|
321
333
|
time?: string;
|
|
322
334
|
} | (ProviderRefusal & {
|
|
@@ -330,6 +342,7 @@ export type MutationResult = {
|
|
|
330
342
|
kind: 'write-halted';
|
|
331
343
|
} | {
|
|
332
344
|
kind: 'expired';
|
|
345
|
+
restored?: true;
|
|
333
346
|
} | AdapterFailure;
|
|
334
347
|
export type HistoryAuthor = {
|
|
335
348
|
kind: 'user';
|
|
@@ -343,6 +356,7 @@ export type HistoryRevision = {
|
|
|
343
356
|
revision: string;
|
|
344
357
|
author: HistoryAuthor;
|
|
345
358
|
time: string;
|
|
359
|
+
binaryFile?: BinaryFile;
|
|
346
360
|
};
|
|
347
361
|
export type HistoryRequest = {
|
|
348
362
|
locator: string;
|
|
@@ -361,6 +375,30 @@ export type HistoryResult = {
|
|
|
361
375
|
} | {
|
|
362
376
|
kind: 'no-history';
|
|
363
377
|
} | AdapterFailure;
|
|
378
|
+
export type BinaryRequest = {
|
|
379
|
+
kind: 'path';
|
|
380
|
+
locator: string;
|
|
381
|
+
path: string;
|
|
382
|
+
revision: string;
|
|
383
|
+
fileRef?: string;
|
|
384
|
+
} | {
|
|
385
|
+
kind: 'reference';
|
|
386
|
+
fileRef: string;
|
|
387
|
+
referrer: unknown;
|
|
388
|
+
};
|
|
389
|
+
export type ReferrerScope = {
|
|
390
|
+
kind: 'room';
|
|
391
|
+
locator: string;
|
|
392
|
+
path?: string;
|
|
393
|
+
} | {
|
|
394
|
+
kind: 'conversations';
|
|
395
|
+
};
|
|
396
|
+
export type BinaryResult = {
|
|
397
|
+
kind: 'binary';
|
|
398
|
+
blob: Blob;
|
|
399
|
+
} | (ProviderRefusal & {
|
|
400
|
+
kind: 'rejected';
|
|
401
|
+
}) | AdapterFailure;
|
|
364
402
|
export type ActionRequest = {
|
|
365
403
|
name: string;
|
|
366
404
|
input: unknown;
|
|
@@ -381,7 +419,6 @@ export type HeldRoom = {
|
|
|
381
419
|
roomVersion: string;
|
|
382
420
|
documents: Readonly<Record<string, string>>;
|
|
383
421
|
revisions: Readonly<Record<string, string>>;
|
|
384
|
-
attachments: readonly RoomAttachment[];
|
|
385
422
|
};
|
|
386
423
|
export type RoomStreamEvent = {
|
|
387
424
|
kind: 'opened';
|
|
@@ -396,17 +433,36 @@ export type RoomStreamEvent = {
|
|
|
396
433
|
locator: string;
|
|
397
434
|
roomVersion: string;
|
|
398
435
|
};
|
|
436
|
+
export type KeptReceipt = {
|
|
437
|
+
key: string;
|
|
438
|
+
head: unknown;
|
|
439
|
+
};
|
|
440
|
+
export type StreamReceipts = {
|
|
441
|
+
heads(): Promise<readonly KeptReceipt[]>;
|
|
442
|
+
parts(key: string, count: number): Promise<readonly unknown[]>;
|
|
443
|
+
keep(key: string, head: unknown, part?: {
|
|
444
|
+
index: number;
|
|
445
|
+
value: unknown;
|
|
446
|
+
}): Promise<void>;
|
|
447
|
+
drop(keys: readonly string[]): Promise<void>;
|
|
448
|
+
};
|
|
399
449
|
export type RoomStream = {
|
|
400
450
|
hold(rooms: readonly HeldRoom[]): void;
|
|
401
|
-
|
|
451
|
+
reopen(): void;
|
|
452
|
+
published(locator: string, roomVersion: string): void;
|
|
453
|
+
observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts): () => void;
|
|
402
454
|
};
|
|
403
455
|
export type Adapter = {
|
|
456
|
+
readonly localSaves?: true;
|
|
457
|
+
readonly exhaustiveDiscovery?: true;
|
|
404
458
|
authorize(): Promise<Authorization>;
|
|
405
459
|
discover(authorization: Authorization): Promise<DiscoverResult>;
|
|
406
460
|
bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
|
|
407
461
|
refresh(authorization: Authorization, request: RefreshRequest): Promise<RefreshResult>;
|
|
408
462
|
mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
|
|
409
463
|
history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
|
|
464
|
+
binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
|
|
465
|
+
referrerScope(referrer: unknown): ReferrerScope | null;
|
|
410
466
|
action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
|
|
411
467
|
reached(locator: string, roomVersion: string, target: string): boolean;
|
|
412
468
|
follows(locator: string, roomVersion: string, next: string): boolean;
|