@agentshouse/mdruntime 0.1.0-c104334047dfe → 0.1.0-c12088a8282f7

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.
Files changed (201) hide show
  1. package/AGENTS.md +107 -95
  2. package/README.md +9 -8
  3. package/dist/adapter.d.ts +54 -37
  4. package/dist/adapter.d.ts.map +1 -1
  5. package/dist/attached-model.d.ts +4 -1
  6. package/dist/attached-model.d.ts.map +1 -1
  7. package/dist/attached-model.js +13 -3
  8. package/dist/binary.d.ts +0 -5
  9. package/dist/binary.d.ts.map +1 -1
  10. package/dist/binary.js +1 -1
  11. package/dist/bootstrap.d.ts +24 -6
  12. package/dist/bootstrap.d.ts.map +1 -1
  13. package/dist/bootstrap.js +148 -82
  14. package/dist/chain.d.ts +11 -0
  15. package/dist/chain.d.ts.map +1 -0
  16. package/dist/chain.js +64 -0
  17. package/dist/change-set.d.ts +9 -16
  18. package/dist/change-set.d.ts.map +1 -1
  19. package/dist/change-set.js +11 -89
  20. package/dist/change.d.ts +31 -1
  21. package/dist/change.d.ts.map +1 -1
  22. package/dist/change.js +10 -1
  23. package/dist/chat/house.d.ts +25 -0
  24. package/dist/chat/house.d.ts.map +1 -0
  25. package/dist/chat/house.js +38 -0
  26. package/dist/chat/input.d.ts +3 -1
  27. package/dist/chat/input.d.ts.map +1 -1
  28. package/dist/chat/input.js +11 -18
  29. package/dist/chat/list.d.ts +2 -1
  30. package/dist/chat/list.d.ts.map +1 -1
  31. package/dist/chat/list.js +7 -3
  32. package/dist/chat/markdown.d.ts +2 -2
  33. package/dist/chat/markdown.d.ts.map +1 -1
  34. package/dist/chat/markdown.js +80 -39
  35. package/dist/chat/message.d.ts +1 -0
  36. package/dist/chat/message.d.ts.map +1 -1
  37. package/dist/chat/message.js +73 -11
  38. package/dist/chat/messages.d.ts +14 -1
  39. package/dist/chat/messages.d.ts.map +1 -1
  40. package/dist/chat/messages.js +79 -24
  41. package/dist/chat/name.d.ts +1 -0
  42. package/dist/chat/name.d.ts.map +1 -1
  43. package/dist/chat/name.js +1 -1
  44. package/dist/chat/opened.d.ts +1 -0
  45. package/dist/chat/opened.d.ts.map +1 -1
  46. package/dist/chat/opened.js +2 -0
  47. package/dist/chat/overlay.d.ts +1 -0
  48. package/dist/chat/overlay.d.ts.map +1 -1
  49. package/dist/chat/overlay.js +11 -5
  50. package/dist/chat/parts.d.ts +1 -0
  51. package/dist/chat/parts.d.ts.map +1 -1
  52. package/dist/chat/parts.js +3 -2
  53. package/dist/chat/pieces.d.ts +62 -0
  54. package/dist/chat/pieces.d.ts.map +1 -0
  55. package/dist/chat/pieces.js +1110 -0
  56. package/dist/chat/provider.d.ts +8 -1
  57. package/dist/chat/provider.d.ts.map +1 -1
  58. package/dist/chat/provider.js +90 -83
  59. package/dist/chat/ready.d.ts +5 -2
  60. package/dist/chat/ready.d.ts.map +1 -1
  61. package/dist/chat/ready.js +7 -5
  62. package/dist/chat/room-file.d.ts +8 -0
  63. package/dist/chat/room-file.d.ts.map +1 -0
  64. package/dist/chat/room-file.js +72 -0
  65. package/dist/chat/steady.d.ts +3 -0
  66. package/dist/chat/steady.d.ts.map +1 -0
  67. package/dist/chat/steady.js +26 -0
  68. package/dist/chat/style.d.ts.map +1 -1
  69. package/dist/chat/style.js +5 -0
  70. package/dist/chat.d.ts +3 -2
  71. package/dist/chat.d.ts.map +1 -1
  72. package/dist/chat.js +2 -2
  73. package/dist/client.d.ts +6 -3
  74. package/dist/client.d.ts.map +1 -1
  75. package/dist/client.js +28 -2
  76. package/dist/collection.d.ts +6 -19
  77. package/dist/collection.d.ts.map +1 -1
  78. package/dist/collection.js +30 -287
  79. package/dist/compile.d.ts +16 -0
  80. package/dist/compile.d.ts.map +1 -0
  81. package/dist/compile.js +721 -0
  82. package/dist/connection.d.ts +13 -10
  83. package/dist/connection.d.ts.map +1 -1
  84. package/dist/connection.js +2231 -904
  85. package/dist/conversation.d.ts +11 -3
  86. package/dist/conversation.d.ts.map +1 -1
  87. package/dist/conversation.js +146 -70
  88. package/dist/digest.d.ts +7 -0
  89. package/dist/digest.d.ts.map +1 -0
  90. package/dist/digest.js +113 -0
  91. package/dist/durability.d.ts +3 -5
  92. package/dist/durability.d.ts.map +1 -1
  93. package/dist/durability.js +5 -0
  94. package/dist/entry.d.ts +3 -1
  95. package/dist/entry.d.ts.map +1 -1
  96. package/dist/entry.js +18 -23
  97. package/dist/file.d.ts +2 -10
  98. package/dist/file.d.ts.map +1 -1
  99. package/dist/file.js +3 -120
  100. package/dist/fulltext.d.ts +27 -0
  101. package/dist/fulltext.d.ts.map +1 -0
  102. package/dist/fulltext.js +368 -0
  103. package/dist/host.d.ts +4 -7
  104. package/dist/host.d.ts.map +1 -1
  105. package/dist/host.js +16 -11
  106. package/dist/identity.d.ts +0 -1
  107. package/dist/identity.d.ts.map +1 -1
  108. package/dist/identity.js +0 -3
  109. package/dist/index.d.ts +12 -9
  110. package/dist/index.d.ts.map +1 -1
  111. package/dist/index.js +4 -1
  112. package/dist/live.d.ts +22 -0
  113. package/dist/live.d.ts.map +1 -0
  114. package/dist/live.js +123 -0
  115. package/dist/memory.d.ts +2 -2
  116. package/dist/memory.d.ts.map +1 -1
  117. package/dist/memory.js +21 -21
  118. package/dist/messages.d.ts +28 -0
  119. package/dist/messages.d.ts.map +1 -0
  120. package/dist/messages.js +90 -0
  121. package/dist/name.d.ts +4 -0
  122. package/dist/name.d.ts.map +1 -0
  123. package/dist/name.js +122 -0
  124. package/dist/observation.d.ts +12 -0
  125. package/dist/observation.d.ts.map +1 -1
  126. package/dist/observation.js +84 -0
  127. package/dist/opened.d.ts +22 -0
  128. package/dist/opened.d.ts.map +1 -0
  129. package/dist/opened.js +107 -0
  130. package/dist/outcome.d.ts +28 -4
  131. package/dist/outcome.d.ts.map +1 -1
  132. package/dist/outcome.js +22 -0
  133. package/dist/overlay.d.ts +2 -5
  134. package/dist/overlay.d.ts.map +1 -1
  135. package/dist/overlay.js +87 -172
  136. package/dist/query.d.ts +5 -1
  137. package/dist/query.d.ts.map +1 -1
  138. package/dist/query.js +13 -1
  139. package/dist/reach.d.ts +5 -3
  140. package/dist/reach.d.ts.map +1 -1
  141. package/dist/reach.js +149 -61
  142. package/dist/readiness.d.ts +20 -9
  143. package/dist/readiness.d.ts.map +1 -1
  144. package/dist/readiness.js +6 -6
  145. package/dist/reads.d.ts.map +1 -1
  146. package/dist/reads.js +4 -2
  147. package/dist/recovery.d.ts +2 -2
  148. package/dist/recovery.d.ts.map +1 -1
  149. package/dist/recovery.js +8 -7
  150. package/dist/refresh.d.ts +15 -14
  151. package/dist/refresh.d.ts.map +1 -1
  152. package/dist/refresh.js +112 -51
  153. package/dist/replica.d.ts +56 -36
  154. package/dist/replica.d.ts.map +1 -1
  155. package/dist/replica.js +277 -184
  156. package/dist/room-draft.d.ts +3 -1
  157. package/dist/room-draft.d.ts.map +1 -1
  158. package/dist/room-draft.js +29 -22
  159. package/dist/rows.d.ts +29 -31
  160. package/dist/rows.d.ts.map +1 -1
  161. package/dist/rows.js +113 -69
  162. package/dist/save.d.ts +50 -14
  163. package/dist/save.d.ts.map +1 -1
  164. package/dist/save.js +502 -180
  165. package/dist/search.d.ts +11 -43
  166. package/dist/search.d.ts.map +1 -1
  167. package/dist/search.js +0 -213
  168. package/dist/shared.d.ts +8 -3
  169. package/dist/shared.d.ts.map +1 -1
  170. package/dist/shared.js +129 -66
  171. package/dist/store.d.ts +87 -92
  172. package/dist/store.d.ts.map +1 -1
  173. package/dist/store.js +329 -687
  174. package/dist/stored.d.ts +145 -0
  175. package/dist/stored.d.ts.map +1 -0
  176. package/dist/stored.js +567 -0
  177. package/dist/tables.d.ts +354 -0
  178. package/dist/tables.d.ts.map +1 -0
  179. package/dist/tables.js +624 -0
  180. package/dist/turn.d.ts +5 -3
  181. package/dist/turn.d.ts.map +1 -1
  182. package/dist/turn.js +51 -21
  183. package/dist/validation.d.ts +30 -0
  184. package/dist/validation.d.ts.map +1 -0
  185. package/dist/validation.js +162 -0
  186. package/dist/windows.d.ts +2 -6
  187. package/dist/windows.d.ts.map +1 -1
  188. package/dist/windows.js +30 -34
  189. package/dist/wire.d.ts +13 -1
  190. package/dist/wire.d.ts.map +1 -1
  191. package/dist/wire.js +4 -1
  192. package/dist/words.d.ts +19 -0
  193. package/dist/words.d.ts.map +1 -0
  194. package/dist/words.js +150 -0
  195. package/package.json +11 -5
  196. package/dist/acquisition.d.ts +0 -14
  197. package/dist/acquisition.d.ts.map +0 -1
  198. package/dist/acquisition.js +0 -24
  199. package/dist/read-side.d.ts +0 -25
  200. package/dist/read-side.d.ts.map +0 -1
  201. package/dist/read-side.js +0 -767
package/AGENTS.md CHANGED
@@ -5,8 +5,8 @@ change it, build, and push. They are documentation, not enforcement.
5
5
 
6
6
  ## The MD Runtime API
7
7
 
8
- App code reaches the MD Runtime through the remote client. The surfaces are Rooms,
9
- Query, Search, Observe, Types, Room Draft, Save, History, the binary file reads, Call,
8
+ App code reaches the MD Runtime through the remote client. The surfaces are Rooms, Query,
9
+ Search, Observe, Types, Room Draft, Save, History, Resolve, the binary file reads, Call,
10
10
  Reached, Log, the reported persistence answer, reauthorization, conversation, the chat
11
11
  draft, and Presentation State. Sync Status, readiness, the Service Mode, the storage-loss
12
12
  statement, the deployment facts and the signed-in member are observations only.
@@ -35,9 +35,8 @@ only in memory, what the Provider streams whether or not anything views it: the
35
35
  `turn` with its parts and its context in use and window, which the message accepted under
36
36
  the turn's id replaces, the open questions, the process state, and the CLI's commands and
37
37
  options, none stored or searchable. `chatDraft.write` and `chatDraft.discard` keep what
38
- the App Creator composes, and `chatDraft.prepend(conversation, draft)` puts a message that
39
- came back ahead of the chat draft as it stands, its text on a line before and its files
40
- first, so what another tab typed meanwhile stays: never write back a draft read before; sending it is a Provider Action that needs the Provider
38
+ the App Creator composes, and `chatDraft.prepend(conversation, draft)` puts a returned
39
+ message ahead of it as it stands. Sending it is a Provider Action that needs the Provider
41
40
  reachable and is never queued. A new conversation's chat draft is keyed `new:<Agent
42
41
  identity>`: no conversation list removes it, a retired Agent's goes, and the first answer
43
42
  to `conversation.create({ agent_id, operation_id })` moves it to the created conversation,
@@ -53,32 +52,34 @@ change, and no tab sees it then.
53
52
 
54
53
  A binary file at a Path is a binary Path entry. Query lists it by `path`, and History each
55
54
  of its revisions, with its `binaryFile` record and never its bytes: `{ state: 'accepted',
56
- revision, path, fileRef, byteLength, mediaType, sha256 }`, or, from a Save until the
55
+ revision, path, byteLength, mediaType, sha256 }`, or, from a Save until the
57
56
  Provider accepts it, `{ state: 'pending', localId, path, byteLength, mediaType, sha256 }`.
58
57
  Write one with a Room Draft whose only part is `file: { blob }`, the `Blob`'s `type` its
59
58
  media type: Save keeps the bytes in its Pending Change, offline too, and acceptance gives
60
59
  the record the Provider's revision. Move or remove one as a Document, a pending one too,
61
60
  its bytes following; once its Pending Change has gone to the Provider, Save refuses that
62
61
  as `unknown-revision` until it is accepted. `binaryFile.read(room, path, revision?)`
63
- answers a pending record's saved bytes, or asks the Provider on every read of an accepted
64
- one or a History revision, a removed file's last included, keeping nothing. Text, a Record
65
- attachment or a conversation message may name a file by its `fileRef`; read it with
66
- `binaryFile.readReference({ fileRef, referrer })`, the `referrer` the Provider gave beside
67
- it, or `{ room, path }` of the document whose text names it. Both answer
68
- `{ kind: 'binary', blob }` or a refusal or failure.
62
+ answers a pending record's saved bytes, or an accepted one's or a History revision's, a
63
+ removed file's last included: the first read asks the Provider and the browser keeps the
64
+ bytes, and every later read of that revision, offline too, answers them from the browser.
65
+ Text names a file only by a link to its Path. A read answers
66
+ `{ kind: 'binary', stream, byteLength, mediaType }`, the bytes a `ReadableStream`
67
+ of parts of at most a mebibyte, or a refusal or failure; read the stream to its end, or
68
+ take it whole with `new Response(stream).blob()` where a screen needs one `Blob`.
69
69
 
70
70
  Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never touch the
71
- network; History, the binary file reads and Call go to the Provider through the Adapter.
71
+ network; History, a binary file read the browser does not keep yet and Call go to the
72
+ Provider through the Adapter.
72
73
  Call takes the Action names the Adapter declares, any other answering `undeclared`. A Call
73
74
  result whose effect the Provider places in a Room carries `at`, that Room and Room
74
75
  Version: `reached(room, roomVersion)` answers whether the Room's confirmed state has
75
76
  reached it, refreshing the Room until it has, and `reached(room, roomVersion, path)`
76
77
  whether the held copy of that document was written later. A History revision names its
77
- author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`; History of a Path no
78
+ author, `{ kind: 'user', id }` or `{ kind: 'site' | 'inbox', id, name }`; History of a Path no
78
79
  document holds answers the removed document's revisions, newest first, with `deleted:
79
80
  true`, which a link to the Path opens. Every member is asynchronous and every result a
80
81
  detached snapshot; nothing returns the authorization, performs a request the App's code
81
- composes, or exposes the browser store.
82
+ composes, or exposes the browser store. A Room `rooms` names `locked` shows only online.
82
83
 
83
84
  Every refusal and failure carries `code` and `retryable`: each Call and History answer
84
85
  other than its result, a refused Save or Room Draft write, a returned Room Draft's reason,
@@ -102,8 +103,8 @@ named; signing out answers `null`, then ends the observation with the authorizat
102
103
  hears it again only when it changes, keeping every unchanged Document the same object, so
103
104
  a component can tell what changed by identity. `{ documents, coverage }` or `{ groups,
104
105
  coverage }` is complete for the Rooms its `coverage` names, and `{ pending }` names each
105
- Room not yet acquired or prepared, `[{ room, awaits }]`: never read it as empty, draw it
106
- as loading and observe the query to hear the complete answer. A query is data:
106
+ Room not yet acquired, prepared or unlocked, `[{ room, awaits }]`: never read it as empty,
107
+ draw it as loading and observe the query to hear the complete answer. A query is data:
107
108
 
108
109
  - **Filter.** `rooms` names Room locators and defaults to every Room. `types` names MD
109
110
  Types, and `any` names untyped Markdown Documents. `pathPrefix` is a directory: `notes`
@@ -120,36 +121,41 @@ as loading and observe the query to hear the complete answer. A query is data:
120
121
  compares in calendar order and never with a date-time. A reference compares by the
121
122
  Room Path it resolves to. Untyped frontmatter, and a value under `oneOf` or a
122
123
  conditional, is plain values. There is no text containment or regular expression.
123
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
124
- reference at pointer `field`, at any depth, points to a matching Document of the same
125
- Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a matching
126
- Document of the same Room references. Each keeps a Document once.
124
+ - **Relations.** Within one Room, `hop: { field, types, where, pathPrefix }` keeps Documents
125
+ whose reference at pointer `field`, at any depth, points to a matching Document, and
126
+ `backlinks` with the same keys those a matching Document references, each once. A body
127
+ link or a `cross_room` reference may name another Room's `/rooms/<handle>/<path>`:
128
+ `resolve(room, path, destination)` answers its `document`, the `deleted` one's last
129
+ `revision`, or `unreadable` where the App does not bind it or it is locked.
127
130
  - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
128
- `preamble`, `markdown`, `backlinks`, `change` and `fileId`, where `fields` is `'all'`
131
+ `preamble`, `markdown`, `backlinks`, `change`, `fileId` and `revision`, where `fields` is `'all'`
129
132
  or a list of pointers and `sections` `'all'` or a list of names. Selected pointers
130
133
  return the frontmatter holding only them, nested as written. A backlink names the
131
134
  referring Path, MD Type and the pointer it came from as `field`. Room and Path always
132
135
  return; a Markdown Document also returns its MD Type, and at most its first 1,000
133
136
  backlinks: a query on the referring field reads the rest. A non-Markdown Document
134
- returns only Room, Path and a selected `fileId`, and a binary Path entry its
135
- `binaryFile` record too. An unselected part is absent. Select only what a screen shows:
136
- a list that selects the Markdown hears every edit of it.
137
- - **Change and file ID.** `change` is `{ author, time }` of the Document's head revision
138
- as the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`, or
137
+ returns only Room, Path and a selected `fileId` and `revision`, a binary Path entry its `binaryFile`
138
+ record too, and a YAML file under `settings/` its text as a selected `markdown`, kept
139
+ out of Search. An unselected part is absent. Select only what a screen shows: a list
140
+ that selects the Markdown hears every edit of it.
141
+ - **Change, file ID and revision.** `change` is `{ author, time }` of the Document's head revision
142
+ as the Provider last delivered it: `author` is `{ kind: 'user' | 'site' | 'inbox', id, name }`, or
139
143
  `null` for a write the Provider made itself, and `time` its ISO 8601 change time, or the
140
144
  whole change `null` where it delivered no time, as at a Site. `fileId` is the Provider's
141
145
  Stable File ID of the file at the Path, or `null`. An unsent edit keeps both, an unsent
142
146
  move keeps the change and carries the file ID to the new Path, so a file ID that leaves
143
147
  one Path for another is the same file moved, and an unsent creation has neither until it
144
- is Accepted. A Room's last change is its Document with the latest `time`.
145
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type`, `folder` or `{ field }`
146
- with TanStack DB's own options; ties end with Room, then Path. `groupBy` by `room`,
147
- `type`, `folder` or `{ field }` answers `{ groups: [{ key, count }] }`, counted over every
148
- match and ordered by `count` or a key. A sort or group takes only a single-value pointer.
149
- `limit`, at most 1,000 whatever a query names, bounds the Documents or the groups, and a
150
- result it cuts short names `next`: the same query with it as `after` reads the next
151
- window, in the same order, ties included. `total: true` adds `total`, every match's
152
- count. An observed window hears rows entering, leaving or changing, and `next`, `total`.
148
+ is Accepted. `revision` is the Provider's head revision, `null` for an unsent creation or edit,
149
+ and moves with an unsent move. A Room's last change is its Document with the latest `time`.
150
+ - **Order and groups.** `orderBy` sorts by `room`, `path`, `type`, `folder` or `{ field }`: missing
151
+ and null first, last with `nulls: 'last'`, then numbers and booleans, then text by `locale` or
152
+ code point with `stringSort: 'lexical'`, then lists item by item; ties end with Room, then Path.
153
+ `groupBy` by `room`, `type`, `folder` or `{ field }` answers `{ groups: [{ key, count }] }`,
154
+ counted over every match and ordered by `count` or a key. A sort or group takes only a
155
+ single-value pointer. `limit`, at most 1,000 whatever a query names, bounds the Documents or the
156
+ groups, and a result it cuts short names `next`: the same query with it as `after` reads the next
157
+ window, in the same order, ties included. `total: true` adds `total`, every match's count. An
158
+ observed window hears rows entering, leaving or changing, and `next`, `total`.
153
159
  - **Results and errors.** A result carries no Room Version: read freshness from Rooms and
154
160
  Sync Status. `coverage` names each Room read as `{ room, generation, current }`,
155
161
  `current` false while a newer copy of that Room is being fetched, and the queued changes
@@ -159,50 +165,59 @@ as loading and observe the query to hear the complete answer. A query is data:
159
165
  ## Local Search rules
160
166
 
161
167
  `search({ text, documents, collection, conversations, limit, after, total })` answers
162
- once, by words, from local state, with MiniSearch's defaults. There is no observed search.
168
+ once, by words, from the full-text index the browser keeps with its local state, so it
169
+ answers at once after a reload. There is no observed search.
163
170
 
164
- - **Declaration.** Only an App whose release declares Local Search searches, its first
165
- readiness waiting for its index; any other App's `search` answers the never retryable
166
- `undeclared` refusal `search-undeclared`, its `fields` naming `local_search`.
171
+ - **Declaration.** Only an App whose release declares Local Search searches; any other
172
+ App's `search` answers the never retryable `undeclared` refusal `search-undeclared`, its
173
+ `fields` naming `local_search`.
167
174
  - **What is found.** A Document by its field values, its sections' headings and text, its
168
175
  preamble and its Path, and a message by its text, never a frontmatter key, a Room Draft,
169
- a chat draft or a running turn's parts, with no phrases, word forms, typo tolerance or
170
- prefix matching.
176
+ a chat draft or a running turn's parts. Any word found ranks a hit, more found rank it
177
+ higher, and adjacent words higher still; case and the marks of Latin, Greek and
178
+ Cyrillic letters fold, English word forms stem, the last word also matches as the start
179
+ of a word unless the text ends with a space, and Chinese, Japanese, Korean and Thai text
180
+ matches by character pairs. There is no typo tolerance and no operator syntax.
171
181
  - **Narrowing.** `documents` is a Local Query filter, and `collection: true` leaves out
172
182
  what each Room's `typedSelection` roots hold; `conversations` names conversations. All
173
183
  apply before `limit`, which bounds each list, at most 1,000 whatever a search names. A
174
184
  complete answer it cuts short names `next`, which `after` takes for the next window of
175
- both lists. `total: true` adds `total`, each list's count.
185
+ both lists. `total: true` adds `total`, each list's count. A word in very many Documents
186
+ ranks among a bounded set of them, the Documents of a rarer word of the search always
187
+ among them.
176
188
  - **Results.** `{ documents, messages, coverage }`, or the same with `pending` naming each
177
- Room or conversation the search still waits for: show its hits, ask again, and never
178
- read pending as no hits. `coverage` names the Rooms and conversations searched. Each
179
- list is ranked by `score`, comparable only within it; ties come by `room`, then `path`,
180
- or by `conversation`, then `identity`. A Document hit names its `room`, `path` and
181
- `type`, a message hit its `conversation` and `identity`; `matches` maps each matched
182
- word to the parts it matched in: `fields`, `sections`, `preamble`, `path` or `text`. A
183
- hit carries no position: mark the words you show. A bad filter fails as a query does.
189
+ Room the search still waits for: show its hits, ask again, and never read pending as no
190
+ hits. `coverage` names the Rooms and conversations searched. Each list is ranked by
191
+ `score`, comparable only within it; ties come by `room`, then `path`, or by
192
+ `conversation`, then `identity`. A Document hit names its `room`, `path` and `type`, a
193
+ message hit its `conversation` and `identity`; `matches` maps each word of the search
194
+ to the parts it was found in: `fields`, `sections`, `preamble`, `path` or `text`. A hit
195
+ whose words were found carries `snippet: { part, text, at }`: the part's text around
196
+ the first word found, at most 80 characters on either side, and `at` that word's start
197
+ and end in `text`. Mark the words you show. A bad filter fails as a query does.
184
198
 
185
199
  ## Room Draft, Save, and outcome rules
186
200
 
187
201
  The MD Runtime owns one durable Room Draft per Room and Path, shared by every App and tab
188
202
  across reloads; a Room the Provider reports lost takes its Room Drafts and queue with it.
189
- Write one with `roomDraft.write(room, path, revision, parts)`, naming the revision you
190
- read or `null`, and every part it now changes: fields, sections and the preamble, or the
191
- whole Markdown, a creation, a move or a removal. A new part names its base, the value you
192
- showed when it was opened, a field's as `{ value }` or `null` for no such field, and keeps
193
- its first base; a binary Path entry's move or removal takes `null`. A write or discard
194
- from an older revision is refused as `stale` with the current Room Draft.
203
+ Write one with `roomDraft.write(room, path, revision, parts)`, naming the revision you read
204
+ or `null`, and every part it now changes: fields, sections and the preamble, or the whole
205
+ Markdown, a creation, a move, into another Room when it names `room`, or a removal. A new
206
+ part names its base, the value you showed when it was opened, a field's as `{ value }` or
207
+ `null` for no such field, and keeps its first base; a binary Path entry's move or removal
208
+ takes `null`. A write or discard from an older revision is refused as `stale` with the
209
+ current Room Draft.
195
210
 
196
211
  Save takes one Room and the Room Drafts of it to save, each with its revision, validates
197
- locally, and on success appends one Change Batch to that Room's queue and removes those
198
- Room Drafts. Refused as `stale`, `changed-underneath` naming each part whose base no
199
- longer matches the visible state, or a local validation rule, it creates nothing and
200
- leaves every Room Draft. A directory move or removal is that part on each Document and
201
- binary Path entry beneath it, saved together. `saveParts(room, [{ path, parts }])` saves
202
- parts, each Path once and each new part with its base, the same way without any Room
203
- Draft: one held at a saved Path stays as it is, and one held at a Path it moves moves with
204
- it to a destination that holds none. Save a change that is not a Room Draft with it, never
205
- by reading the Room Draft at that Path and writing it back.
212
+ locally, and on success appends one Change Batch to that Room's queue and removes those Room
213
+ Drafts. Refused as `stale`, `changed-underneath` naming each part whose base no longer
214
+ matches the visible state, or a local validation rule, it creates nothing and leaves every
215
+ Room Draft. A directory move or removal is that part on each Document and binary Path entry
216
+ beneath it, saved together; moves into another Room, saved alone, are one Change Batch in
217
+ both Rooms' queues. `saveParts(room, [{ path, parts }])` saves parts, each Path once and
218
+ each new part with its base, the same way but writes no Room Draft: one held at a saved Path
219
+ stays, one at a moved Path moves with it to a destination that holds none. Never save by
220
+ writing back a Room Draft read before.
206
221
 
207
222
  Outcomes follow the Provider's answer. An Accepted Change Batch stays in the queue, drawn
208
223
  over the confirmed layer, until that layer reaches the Room Version it was accepted at.
@@ -212,24 +227,23 @@ Provider's structured refusal code and fields as returned, not known to have app
212
227
  withdrawn locally. The rest of the queue keeps synchronizing, and Sync Status requires
213
228
  attention until each returned Room Draft is saved or discarded. `observe('queue', room)`
214
229
  shows each Pending Change Batch, which keeps no outcome once it leaves. Transport failure,
215
- Provider unavailability and a refusal the Provider marks retryable, until the reset it
216
- names, keep work Pending; the MD Runtime retries the same Change Batch identity and
217
- payload, never infers an outcome from transport uncertainty, and never combines,
218
- reorders, or rebases.
219
-
220
- On a Site, every Save stays in the visitor's browser: write grants and revisions do not
221
- refuse it, and its Pending Change shows in every query and across reloads until the
222
- browser's storage is cleared. It is never sent: `observe('queue', room)` shows it `local`,
223
- Sync Status never waits on it, and once the Room no longer lets it apply it leaves the
224
- queue and returns no Room Draft.
225
-
226
- `observe('service-mode')` answers the Provider's Service Mode, `open` or `write-halted`.
227
- While writes are halted, Save succeeds, its Change Batch waits unsent and the queue is
228
- submitted in order once writes reopen; an Action is never held, and one the halt refuses
229
- returns that refusal: show the Provider as read-only instead of retrying.
230
- `observe('readiness')` tells whether the App's code and bound Rooms are held locally
231
- (`ready`), each Room's state, each refused Room's file and rule, the persistence answer
232
- and a paused preparation's `capacity` cause; `retry()` resumes a paused preparation.
230
+ Provider unavailability and a refusal marked retryable, until the reset it names, keep
231
+ work Pending; the MD Runtime retries the same Change Batch identity and payload, never
232
+ infers an outcome from transport uncertainty, and never combines, reorders, or rebases.
233
+
234
+ On a Site, every Save stays in the visitor's browser: write grants and revisions do not refuse it,
235
+ and its Pending Change shows in every query and across reloads until the browser's storage is
236
+ cleared. It is never sent: `observe('queue', room)` shows it `local`, Sync Status never waits on
237
+ it, and once the Room no longer lets it apply it leaves the queue and returns no Room Draft.
238
+
239
+ `observe('service-mode')` answers the Provider's Service Mode, `open` or `write-halted`. While writes
240
+ are halted, Save succeeds, its Change Batch waits unsent and the queue is submitted in order once writes
241
+ reopen; an Action is never held, and one the halt refuses returns that refusal: show the Provider as
242
+ read-only instead of retrying. `observe('readiness')` tells whether code and bound Rooms are held
243
+ locally (`ready`), each Room's state, each refused Room's file and rule, the persistence answer, `space`
244
+ (`full` once the device's storage refused a write, Save and messages refusing as `durable-write` until
245
+ `retry()` or a later test write finds space, or once the origin refused a newer release), and the
246
+ `installation`'s Rooms, parts, bytes, `received`, `step` and `paused`.
233
247
 
234
248
  ## Content safety and launch promises
235
249
 
@@ -270,13 +284,10 @@ peer dependency. `useObserve(client, topic, ...input)` takes the arguments of `o
270
284
  and returns `{ state: 'loading' }` until the topic's first value arrives, then `{ state:
271
285
  'ready', value }`, re-rendering on each change; a `null` client stays loading.
272
286
  `useSave(client)` returns `busy`, the last `outcome` or `failure`, and `save(room,
273
- parts)`, which saves each Path's parts, each new part naming its base, through
274
- `saveParts(room, [{ path, parts }])`: it writes no Room Draft, so one another tab holds
275
- at that Path stays as it is and one at a Path it moves moves with it, a refused Save
276
- changes nothing, and a failure is recorded and rejects. `saveWritten(room, roomDrafts)`
277
- saves Room Drafts the App wrote itself, each named with the revision its last write returned: one another tab wrote since
278
- is refused as `stale`, and nothing is saved. A react-admin or Refine App uses the data
279
- providers of `@agentshouse/mdruntime-families`.
287
+ parts)`, which saves through `saveParts` and rejects with a recorded failure.
288
+ `saveWritten(room, roomDrafts)` saves Room Drafts the App wrote, each named with the
289
+ revision its last write returned: one another tab wrote since is refused as `stale`, and
290
+ nothing is saved. React-admin and Refine Apps use `@agentshouse/mdruntime-families`.
280
291
 
281
292
  ## The Chat
282
293
 
@@ -298,8 +309,9 @@ Mix `ChatMessageList` (`components` takes your `UserMessage` and `AssistantMessa
298
309
  `ChatInput` and `ChatQuestionCard` with your own design inside a `ChatProvider`, or
299
310
  compose assistant-ui's primitives there; `useChat()` gives `send`, the conversations, the
300
311
  Agents, questions to `answer`, `options` to `choose`, `commands`, the queue to `edit` or
301
- `unqueue`, `stop`, `kill` and outcomes; never replace its messages, sending or store. It
302
- shows a conversation's latest 50 messages, and assistant-ui's `loadEarlier()` the 50
303
- before, which `ChatMessageList` calls as the reader scrolls back. A secret question is
304
- never answered here; typed answers live in the Presentation State members named `typed:…`:
305
- leave them. `Markdown` draws Markdown safely.
312
+ `unqueue`, `stop`, `kill`, `renew`, which starts a new chat with the same Agent in place
313
+ of a conversation whose session could not resume, and outcomes; never replace its
314
+ messages, sending or store. It shows a conversation's latest 50 messages, and
315
+ assistant-ui's `loadEarlier()` the 50 before, which `ChatMessageList` calls as the reader
316
+ scrolls back. A secret question is never answered here; typed answers live in the
317
+ Presentation State members named `typed:…`: leave them. `Markdown` draws Markdown safely.
package/README.md CHANGED
@@ -12,14 +12,15 @@ 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 over the client: `useObserve`, `useSave` |
22
- | `@agentshouse/mdruntime/chat` | The Chat: `Chat`, `mountChat`, its parts and `ChatProvider` |
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/tables` | The host's database: the Authored store's and opened files' tables, `answerRuntime` |
22
+ | `@agentshouse/mdruntime/react` | React over the client: `useObserve`, `useSave` |
23
+ | `@agentshouse/mdruntime/chat` | The Chat: `Chat`, `mountChat`, its parts and `ChatProvider` |
23
24
 
24
25
  ## Usage
25
26
 
package/dist/adapter.d.ts CHANGED
@@ -10,14 +10,13 @@ export type TypedSelection = {
10
10
  roots: readonly string[];
11
11
  };
12
12
  export type OperationScopes = {
13
- read: readonly string[];
14
- sync: readonly string[];
15
13
  write: readonly string[];
16
14
  delete: readonly string[];
17
15
  };
18
16
  export type ReplicaAdmission = {
19
17
  selection: string;
20
18
  admission: Open<'admitted' | 'unavailable'>;
19
+ offline: Open<'locked' | 'open'>;
21
20
  };
22
21
  export type DiscoveredRoom = {
23
22
  name: string;
@@ -49,8 +48,9 @@ export type ListedConversation = {
49
48
  created: string;
50
49
  finished: string | null;
51
50
  outcome: string | null;
51
+ waiting: boolean;
52
52
  };
53
- export type ConversationAction = 'conversation.create' | 'conversation.send' | 'conversation.answer' | 'conversation.interrupt' | 'conversation.kill' | 'conversation.cancel' | 'conversation.delete' | 'conversation.history';
53
+ export type ConversationAction = 'conversation.create' | 'conversation.send' | 'conversation.attach' | 'conversation.answer' | 'conversation.interrupt' | 'conversation.kill' | 'conversation.cancel' | 'conversation.delete' | 'conversation.history';
54
54
  export type ConversationMessage = {
55
55
  identity: string;
56
56
  turn: string;
@@ -162,6 +162,18 @@ export type ConversationEvent = {
162
162
  kind: 'options';
163
163
  conversation: string;
164
164
  options: readonly SessionOption[];
165
+ } | {
166
+ kind: 'starting';
167
+ conversation: string;
168
+ step: string | null;
169
+ } | {
170
+ kind: 'link';
171
+ conversation: string;
172
+ connected: boolean;
173
+ } | {
174
+ kind: 'deliveries';
175
+ conversation: string;
176
+ unknown: readonly string[];
165
177
  } | {
166
178
  kind: 'accepted-message';
167
179
  conversation: string;
@@ -187,6 +199,7 @@ export type ActionDeclaration = {
187
199
  name: string;
188
200
  inputShape: unknown;
189
201
  resultKind: unknown;
202
+ room?: string;
190
203
  };
191
204
  export type ProviderLimit = {
192
205
  name: string;
@@ -233,7 +246,7 @@ export type ProviderRefusal = {
233
246
  export type ScopedRefusal = ProviderRefusal & {
234
247
  kind: 'scoped-refusal';
235
248
  locator: string;
236
- scope: Open<'content' | 'sync' | 'model' | 'operation' | 'undisclosed'>;
249
+ scope: Open<'content' | 'model' | 'operation' | 'undisclosed'>;
237
250
  };
238
251
  export type AdapterFailure = TransportUncertainty | RoomNotReadable | RevokedAuthorization | ScopedRefusal;
239
252
  export type ContractUnavailable = ProviderRefusal & {
@@ -242,7 +255,7 @@ export type ContractUnavailable = ProviderRefusal & {
242
255
  export type DiscoverResult = Discovery | TransportUncertainty | RevokedAuthorization | ContractUnavailable;
243
256
  export type PageToken = string;
244
257
  export type ChangeAuthor = {
245
- kind: Open<'user' | 'site'>;
258
+ kind: Open<'user' | 'site' | 'inbox'>;
246
259
  id: string;
247
260
  name: string;
248
261
  };
@@ -256,20 +269,32 @@ export type HeadChange = {
256
269
  time: string;
257
270
  };
258
271
  export type BinaryFile = {
259
- fileRef: string;
260
272
  byteLength: number;
261
273
  mediaType: string;
262
274
  sha256: string;
263
275
  };
276
+ export type HeldFile = {
277
+ readonly path: string;
278
+ readonly revision: string;
279
+ };
264
280
  export type HeldContent = {
265
- documents: Readonly<Record<string, string>>;
266
- revisions: Readonly<Record<string, string>>;
281
+ files(after: string | null, limit: number): Promise<readonly HeldFile[]>;
282
+ contents(paths: readonly string[]): Promise<ReadonlyMap<string, {
283
+ readonly content: string;
284
+ readonly revision: string;
285
+ }>>;
267
286
  };
268
287
  export type BootstrapRequest = {
269
288
  locator: string;
270
289
  selection: string;
271
290
  pageToken?: PageToken;
272
291
  held?: HeldContent;
292
+ received?: Uint8Array;
293
+ arriving?: (bytes: number) => void;
294
+ };
295
+ export type BootstrapInventory = {
296
+ readonly parts: number;
297
+ readonly bytes: number;
273
298
  };
274
299
  export type RoomModels = {
275
300
  collection?: ModelResult;
@@ -284,7 +309,10 @@ export type BootstrapPage = {
284
309
  fileIds?: Readonly<Record<string, string>>;
285
310
  changes: Readonly<Record<string, HeadChange>>;
286
311
  binaryFiles: Readonly<Record<string, BinaryFile>>;
312
+ folders?: readonly string[];
287
313
  pageToken?: PageToken;
314
+ inventory?: BootstrapInventory;
315
+ received?: Uint8Array;
288
316
  };
289
317
  export type BootstrapResult = BootstrapPage | {
290
318
  kind: 'beyond-horizon';
@@ -305,6 +333,8 @@ export type RefreshPage = {
305
333
  changes: Readonly<Record<string, HeadChange>>;
306
334
  binaryFiles: Readonly<Record<string, BinaryFile>>;
307
335
  removals: readonly string[];
336
+ folders?: readonly string[];
337
+ folderRemovals?: readonly string[];
308
338
  pageToken?: PageToken;
309
339
  };
310
340
  export type RefreshResult = {
@@ -315,6 +345,7 @@ export type RefreshResult = {
315
345
  export type MutationRequest = {
316
346
  locator: string;
317
347
  changeBatch: ChangeBatch;
348
+ file(localId: string): Promise<Blob>;
318
349
  upload?: unknown;
319
350
  };
320
351
  export type RetryableRefusal = ProviderRefusal & {
@@ -325,8 +356,7 @@ export type ServiceMode = Open<'open' | 'write-halted'>;
325
356
  export type ServiceModeSignal = {
326
357
  observe(notify: (mode: ServiceMode) => void): () => void;
327
358
  };
328
- export type MutationResult = {
329
- kind: 'accepted';
359
+ export type AcceptedRoom = {
330
360
  roomVersion: string;
331
361
  documents: Readonly<Record<string, string>>;
332
362
  revisions: Readonly<Record<string, string>>;
@@ -334,9 +364,13 @@ export type MutationResult = {
334
364
  changes: Readonly<Record<string, HeadChange>>;
335
365
  removals: readonly string[];
336
366
  binaryFiles?: Readonly<Record<string, BinaryFile>>;
367
+ };
368
+ export type MutationResult = (AcceptedRoom & {
369
+ kind: 'accepted';
337
370
  author?: string;
338
371
  time?: string;
339
- } | (ProviderRefusal & {
372
+ destination?: AcceptedRoom;
373
+ }) | (ProviderRefusal & {
340
374
  kind: 'conflicted';
341
375
  roomVersion?: string;
342
376
  affected: Readonly<Record<string, string>>;
@@ -353,7 +387,7 @@ export type HistoryAuthor = {
353
387
  kind: 'user';
354
388
  id: string;
355
389
  } | {
356
- kind: 'site';
390
+ kind: 'site' | 'inbox';
357
391
  id: string;
358
392
  name: string;
359
393
  };
@@ -385,22 +419,12 @@ export type BinaryRequest = {
385
419
  locator: string;
386
420
  path: string;
387
421
  revision: string;
388
- fileRef?: string;
389
- } | {
390
- kind: 'reference';
391
- fileRef: string;
392
- referrer: unknown;
393
- };
394
- export type ReferrerScope = {
395
- kind: 'room';
396
- locator: string;
397
- path?: string;
398
- } | {
399
- kind: 'conversations';
400
422
  };
401
423
  export type BinaryResult = {
402
424
  kind: 'binary';
403
- blob: Blob;
425
+ body: ReadableStream<Uint8Array>;
426
+ mediaType: string;
427
+ sha256?: string;
404
428
  } | (ProviderRefusal & {
405
429
  kind: 'rejected';
406
430
  }) | AdapterFailure;
@@ -429,9 +453,8 @@ export type ActionResult = {
429
453
  export type HeldRoom = {
430
454
  locator: string;
431
455
  roomVersion: string;
432
- documents: Readonly<Record<string, string>>;
433
- revisions: Readonly<Record<string, string>>;
434
456
  };
457
+ export type HeldRevisions = (locator: string, paths: readonly string[]) => Promise<ReadonlyMap<string, string>>;
435
458
  export type RoomStreamEvent = {
436
459
  kind: 'opened';
437
460
  } | {
@@ -462,19 +485,16 @@ export type StreamReceipts = {
462
485
  }): Promise<void>;
463
486
  drop(keys: readonly string[]): Promise<void>;
464
487
  };
465
- export type AcquiredDemand = {
466
- rooms: readonly string[];
467
- conversations: boolean;
468
- };
469
488
  export type RoomStream = {
470
- hold(rooms: readonly HeldRoom[], demand: AcquiredDemand | null): void;
489
+ hold(rooms: readonly HeldRoom[]): void;
471
490
  reopen(): void;
472
491
  published(locator: string, roomVersion: string): void;
473
- observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts): () => void;
492
+ observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts, revisions: HeldRevisions): () => void;
474
493
  };
475
494
  export type Adapter = {
476
495
  readonly localSaves?: true;
477
496
  readonly exhaustiveDiscovery?: true;
497
+ readonly roomTypes?: string;
478
498
  authorize(): Promise<Authorization>;
479
499
  discover(authorization: Authorization, scope?: DiscoveryScope): Promise<DiscoverResult>;
480
500
  bootstrap(authorization: Authorization, request: BootstrapRequest): Promise<BootstrapResult>;
@@ -482,10 +502,7 @@ export type Adapter = {
482
502
  mutate(authorization: Authorization, request: MutationRequest, keep: (upload: unknown) => Promise<void>): Promise<MutationResult>;
483
503
  history(authorization: Authorization, request: HistoryRequest): Promise<HistoryResult>;
484
504
  binary(authorization: Authorization, request: BinaryRequest): Promise<BinaryResult>;
485
- link(authorization: Authorization, request: Extract<BinaryRequest, {
486
- kind: 'path';
487
- }>): Promise<BinaryLinkResult>;
488
- referrerScope(referrer: unknown): ReferrerScope | null;
505
+ link(authorization: Authorization, request: BinaryRequest): Promise<BinaryLinkResult>;
489
506
  action(authorization: Authorization, request: ActionRequest): Promise<ActionResult>;
490
507
  reached(locator: string, roomVersion: string, target: string): boolean;
491
508
  follows(locator: string, roomVersion: string, next: string): boolean;