@agentshouse/mdruntime-adapter 0.1.0-cafd7caa7ae65 → 0.1.0-cb0bbc4ccacd0

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 (78) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +4 -65
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +8 -347
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +257 -277
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +24 -14
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +93 -54
  17. package/dist/history.d.ts +12 -0
  18. package/dist/history.d.ts.map +1 -0
  19. package/dist/history.js +92 -0
  20. package/dist/house-model.d.ts +641 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +361 -0
  23. package/dist/index.d.ts +11 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +10 -1
  26. package/dist/model.d.ts +8 -4
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +36 -36
  29. package/dist/part.d.ts +14 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +90 -0
  32. package/dist/read.d.ts +58 -43
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +245 -204
  35. package/dist/refusal.d.ts +0 -3
  36. package/dist/refusal.d.ts.map +1 -1
  37. package/dist/refusal.js +2 -6
  38. package/dist/room-stream.d.ts +20 -0
  39. package/dist/room-stream.d.ts.map +1 -0
  40. package/dist/room-stream.js +57 -0
  41. package/dist/room-types.d.ts +7 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +123 -0
  44. package/dist/search.d.ts +5 -0
  45. package/dist/search.d.ts.map +1 -0
  46. package/dist/search.js +47 -0
  47. package/dist/site.d.ts +1 -1
  48. package/dist/site.d.ts.map +1 -1
  49. package/dist/site.js +120 -131
  50. package/dist/space-schema.d.ts +7 -0
  51. package/dist/space-schema.d.ts.map +1 -0
  52. package/dist/space-schema.js +18 -0
  53. package/dist/stream.d.ts +13 -12
  54. package/dist/stream.d.ts.map +1 -1
  55. package/dist/stream.js +209 -158
  56. package/dist/transport.d.ts +85 -25
  57. package/dist/transport.d.ts.map +1 -1
  58. package/dist/transport.js +54 -11
  59. package/dist/upload.d.ts +12 -0
  60. package/dist/upload.d.ts.map +1 -0
  61. package/dist/upload.js +63 -0
  62. package/dist/version.d.ts +1 -0
  63. package/dist/version.d.ts.map +1 -1
  64. package/dist/version.js +1 -1
  65. package/dist/write.d.ts +18 -2
  66. package/dist/write.d.ts.map +1 -1
  67. package/dist/write.js +105 -71
  68. package/package.json +8 -4
  69. package/AGENTS.md +0 -302
  70. package/dist/gather.d.ts +0 -4
  71. package/dist/gather.d.ts.map +0 -1
  72. package/dist/gather.js +0 -45
  73. package/dist/handed.d.ts +0 -15
  74. package/dist/handed.d.ts.map +0 -1
  75. package/dist/handed.js +0 -38
  76. package/dist/referrer.d.ts +0 -7
  77. package/dist/referrer.d.ts.map +0 -1
  78. package/dist/referrer.js +0 -35
package/dist/write.js CHANGED
@@ -1,5 +1,5 @@
1
- import { departure, } from '@agentshouse/mdruntime';
2
- import { binaryFileOf, headChange } from './read.js';
1
+ import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
3
3
  import { sha256Hex, textBytes } from './digest.js';
4
4
  import { nativePath, roomLocalPath } from './map.js';
5
5
  import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
@@ -120,16 +120,36 @@ export function houseChanges(batch, handle) {
120
120
  }
121
121
  return { kind: 'changes', changes };
122
122
  }
123
- export function operationHead(batch) {
123
+ export function houseParts(saved, handle) {
124
+ return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
125
+ }
126
+ export function houseMove(batch, source, destination) {
127
+ const changes = [];
128
+ for (const { path, to } of batch.between?.moves ?? []) {
129
+ const existence = priorExistence(batch, path);
130
+ if (existence === undefined)
131
+ return { kind: 'unmapped', path, rule: 'precondition-missing' };
132
+ if (!('base' in existence)) {
133
+ return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
134
+ }
135
+ changes.push({
136
+ op: 'rename',
137
+ path: nativePath(path, source),
138
+ to: nativePath(to, destination),
139
+ base: existence.base,
140
+ });
141
+ }
142
+ return { kind: 'changes', changes };
143
+ }
144
+ export function operationHead(batch, room) {
124
145
  const writer = batch.writtenBy;
125
- return writer === undefined
126
- ? { operation_id: batch.id }
127
- : { operation_id: batch.id, app_ref: writer.app, release: writer.release };
146
+ const head = { operation_id: batch.id, room_ref: room };
147
+ return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
128
148
  }
129
149
  export function batchPaths(changes) {
130
150
  return [
131
151
  ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
132
- ].sort();
152
+ ];
133
153
  }
134
154
  export function deltaBody(changes) {
135
155
  return JSON.stringify({ changes });
@@ -144,16 +164,19 @@ export function uploadable(inline, bytes, bounds) {
144
164
  export function deltaDigest(delta) {
145
165
  return sha256Hex(delta);
146
166
  }
147
- function material(value, handle) {
167
+ function* material(value, handle, within = () => true) {
148
168
  if (!Array.isArray(value))
149
169
  return null;
150
170
  const held = [];
151
171
  for (const entry of value) {
172
+ yield ROW_WEIGHT;
152
173
  if (typeof entry !== 'object' || entry === null)
153
174
  return null;
154
175
  const file = entry;
155
176
  if (typeof file.path !== 'string')
156
177
  return null;
178
+ if (!within(file.path))
179
+ continue;
157
180
  if (file.content !== null && typeof file.content !== 'string')
158
181
  return null;
159
182
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
@@ -181,27 +204,69 @@ function material(value, handle) {
181
204
  }
182
205
  return held;
183
206
  }
184
- function affectedOf(held) {
207
+ function* affectedOf(held) {
185
208
  const affected = {};
186
209
  for (const entry of held) {
187
210
  if (entry.content !== null)
188
211
  affected[entry.path] = entry.content;
212
+ yield ROW_WEIGHT;
189
213
  }
190
214
  return affected;
191
215
  }
192
- export function mutationOutcome(status, body, locator, handle) {
216
+ function* acceptedOf(at, contents) {
217
+ const answer = answering();
218
+ for (const entry of contents) {
219
+ yield ROW_WEIGHT + (entry.content?.length ?? 0);
220
+ if (entry.revision === null) {
221
+ answer.removals.add(entry.path);
222
+ continue;
223
+ }
224
+ if (entry.content !== null)
225
+ answer.documents.set(entry.path, entry.content);
226
+ if (entry.binary !== undefined)
227
+ answer.binaryFiles.set(entry.path, entry.binary);
228
+ revised(answer, entry.path, entry.revision);
229
+ if (entry.head !== undefined)
230
+ answer.changes.set(entry.path, entry.head);
231
+ }
232
+ const unbinaried = answer.binaryFiles.size === 0;
233
+ const { binaryFiles, facts: _facts, ...room } = yield* answered(answer);
234
+ return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
235
+ }
236
+ function* movedOutcome(held, move) {
237
+ const authorities = Array.isArray(held.authorities) ? held.authorities : [];
238
+ const at = (authority) => {
239
+ const entry = authorities.find((one) => typeof one === 'object' &&
240
+ one !== null &&
241
+ one.authority === authority);
242
+ return entry === undefined ? null : readPosition(entry);
243
+ };
244
+ const left = at(move.source.authority);
245
+ const arrived = at(move.destination.authority);
246
+ if (left === null || arrived === null)
247
+ return { kind: 'transport-uncertainty' };
248
+ const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
249
+ const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
250
+ const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
251
+ if (leaving === null || arriving === null)
252
+ return { kind: 'transport-uncertainty' };
253
+ return {
254
+ kind: 'accepted',
255
+ ...(yield* acceptedOf(left, leaving)),
256
+ destination: yield* acceptedOf(arrived, arriving),
257
+ };
258
+ }
259
+ export function* mutationOutcome(status, body, locator, handle, move) {
193
260
  const refusal = doorRefusal(body);
194
261
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
195
262
  return { kind: 'write-halted' };
196
263
  }
197
- if (refusal !== null && refusal.code === 'expired')
198
- return { kind: 'expired' };
199
264
  if (refusal !== null && refusal.code === 'edit_conflict') {
200
265
  const { current, ...fields } = refusal.fields;
201
- const held = material(current, handle) ?? [];
266
+ const held = (yield* material(current, handle)) ?? [];
202
267
  return {
203
268
  kind: 'conflicted',
204
- affected: affectedOf(held),
269
+ affected: yield* affectedOf(held),
205
270
  code: refusal.code,
206
271
  fields,
207
272
  retryable: refusal.retryable,
@@ -225,8 +290,9 @@ export function mutationOutcome(status, body, locator, handle) {
225
290
  }
226
291
  if (classified !== null && classified.kind !== 'scoped-refusal')
227
292
  return classified;
228
- if (classified !== null && status === 403)
293
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
229
294
  return classified;
295
+ }
230
296
  if (refusal !== null && status >= 400) {
231
297
  return {
232
298
  kind: 'rejected',
@@ -240,39 +306,15 @@ export function mutationOutcome(status, body, locator, handle) {
240
306
  return { kind: 'transport-uncertainty' };
241
307
  }
242
308
  const held = body;
309
+ if (move !== undefined)
310
+ return yield* movedOutcome(held, move);
243
311
  const at = readPosition(held);
244
312
  if (at === null)
245
313
  return { kind: 'transport-uncertainty' };
246
- const contents = material(held.contents, handle);
314
+ const contents = yield* material(held.contents, handle);
247
315
  if (contents === null)
248
316
  return { kind: 'transport-uncertainty' };
249
- const documents = {};
250
- const revisions = {};
251
- const changes = {};
252
- const binaryFiles = {};
253
- const removals = [];
254
- for (const entry of contents) {
255
- if (entry.revision === null) {
256
- removals.push(entry.path);
257
- continue;
258
- }
259
- if (entry.content !== null)
260
- documents[entry.path] = entry.content;
261
- if (entry.binary !== undefined)
262
- binaryFiles[entry.path] = entry.binary;
263
- revisions[entry.path] = entry.revision;
264
- if (entry.head !== undefined)
265
- changes[entry.path] = entry.head;
266
- }
267
- return {
268
- kind: 'accepted',
269
- roomVersion: roomVersion(at),
270
- documents,
271
- revisions,
272
- changes,
273
- removals: removals.sort(),
274
- ...(Object.keys(binaryFiles).length === 0 ? {} : { binaryFiles }),
275
- };
317
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
276
318
  }
277
319
  export function rejectedMapping(mapping) {
278
320
  return {
@@ -292,27 +334,29 @@ export function revisionBody(input) {
292
334
  }
293
335
  function revisionAuthor(entry) {
294
336
  const user = entry.author_user;
337
+ const userName = entry.author_user_name;
295
338
  const site = entry.author_site;
296
- const name = entry.author_site_name;
297
- if (typeof user === 'string' && site === undefined && name === undefined) {
298
- return { kind: 'user', id: user };
339
+ const siteName = entry.author_site_name;
340
+ const inbox = entry.author_inbox;
341
+ const inboxName = entry.author_inbox_name;
342
+ const app = entry.author_app;
343
+ const appName = entry.author_app_name;
344
+ const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
345
+ if (typeof user === 'string' && typeof userName === 'string' && named.length === 0)
346
+ return { kind: 'user', id: user, name: userName };
347
+ if (user !== null || userName !== undefined || named.length !== 2)
348
+ return null;
349
+ if (typeof site === 'string' && typeof siteName === 'string') {
350
+ return { kind: 'site', id: site, name: siteName };
299
351
  }
300
- if (user === null && typeof site === 'string' && typeof name === 'string') {
301
- return { kind: 'site', id: site, name };
352
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
353
+ return { kind: 'inbox', id: inbox, name: inboxName };
354
+ }
355
+ if (typeof app === 'string' && typeof appName === 'string') {
356
+ return { kind: 'app', id: app, name: appName };
302
357
  }
303
358
  return null;
304
359
  }
305
- function historyBinary(entry) {
306
- if (entry.file === undefined)
307
- return undefined;
308
- const { file, bytes, media_type: mediaType, sha256 } = entry;
309
- if (typeof file !== 'string' ||
310
- typeof bytes !== 'number' ||
311
- typeof mediaType !== 'string' ||
312
- typeof sha256 !== 'string')
313
- return null;
314
- return { fileRef: file, byteLength: bytes, mediaType, sha256 };
315
- }
316
360
  export function historyOutcome(status, body, locator, request) {
317
361
  const classified = classifyDoor(status, body, locator);
318
362
  if (classified !== null)
@@ -333,17 +377,7 @@ export function historyOutcome(status, body, locator, request) {
333
377
  const named = entries[0];
334
378
  if (named === undefined)
335
379
  return { kind: 'no-history' };
336
- if (named.unavailable === true) {
337
- return {
338
- kind: 'scoped-refusal',
339
- locator,
340
- scope: 'content',
341
- code: 'retained_history_unavailable',
342
- fields: { path: request.path, revision: request.revision },
343
- retryable: false,
344
- };
345
- }
346
- if (typeof named.file === 'string')
380
+ if (typeof named.media_type === 'string')
347
381
  return { kind: 'no-history' };
348
382
  if (typeof named.content !== 'string')
349
383
  return { kind: 'transport-uncertainty' };
@@ -359,7 +393,7 @@ export function historyOutcome(status, body, locator, request) {
359
393
  typeof entry.created_at !== 'string') {
360
394
  return { kind: 'transport-uncertainty' };
361
395
  }
362
- const binaryFile = historyBinary(entry);
396
+ const binaryFile = binaryFileOf(entry);
363
397
  if (binaryFile === null)
364
398
  return { kind: 'transport-uncertainty' };
365
399
  revisions.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-cafd7caa7ae65",
3
+ "version": "0.1.0-cb0bbc4ccacd0",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  "access": "public"
10
10
  },
11
11
  "engines": {
12
- "node": ">=24.21.0"
12
+ "node": ">=24.22.1"
13
13
  },
14
14
  "exports": {
15
15
  ".": {
@@ -20,11 +20,15 @@
20
20
  },
21
21
  "files": [
22
22
  "dist",
23
- "AGENTS.md",
24
23
  "README.md",
25
24
  "LICENSE"
26
25
  ],
27
26
  "dependencies": {
28
- "@agentshouse/mdruntime": "0.1.0-c05b32a1b6587"
27
+ "@agentshouse/mdruntime": "0.1.0-ccc0e3407f107"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/agentshouse/core.git",
32
+ "directory": "mdruntime/packages/mdruntime-adapter"
29
33
  }
30
34
  }
package/AGENTS.md DELETED
@@ -1,302 +0,0 @@
1
- # Instructions for the App Creator's agent
2
-
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.
5
-
6
- ## The MD Runtime API
7
-
8
- App code reaches the MD Runtime through the remote client. The surfaces are
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
-
15
- The host attaches each port with its reach, and every member and observation
16
- answers within it: a Room outside it answers as one the replica does not hold,
17
- Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
- shows only those Documents and the Types of the models that govern them, and
19
- without conversations the conversation members, the chat draft and the
20
- conversation observation hold none. A change of the reach reaches every open
21
- observation as its new value, a query keeping unchanged Documents the same objects.
22
-
23
- Every `observe` resolves, once its first value has arrived, to a handle:
24
- `current()` is the latest complete value, `subscribe(listener)` hears each later
25
- value whole and returns its unsubscribe, and `close()` ends the observation.
26
- Closing the port ends every handle and rejects every pending call and
27
- observation; a client that reconnects observes again.
28
-
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.
63
-
64
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
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
68
- effect the Provider places in a Room carries `at`, that Room and Room Version;
69
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
70
- reached it, and the MD Runtime keeps refreshing that Room until it has;
71
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
72
- that document was written at a later Room Version. Each History revision
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.
96
-
97
- ## Local Query rules
98
-
99
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
100
- result and hears it again only when it changes, keeping every unchanged Document
101
- the same object, so a component can tell what changed by identity. A query is
102
- data:
103
-
104
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
105
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
106
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
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.
119
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
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
122
- matching Document of the same Room references. Each keeps a Document once.
123
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
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
131
- what a screen shows: a list that selects the Markdown hears every edit of it.
132
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
133
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
134
- or `null` for a write the Provider made itself, and `time` is the Provider's
135
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
136
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
137
- saved write takes the Provider's own once it is Accepted. A
138
- Room's last change is its Document with the latest `time`.
139
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
140
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
141
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
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.
144
- - **Results and errors.** A result carries no Room Version: read freshness from
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.
148
-
149
- ## Local Search rules
150
-
151
- `search({ text, documents, conversations, limit })` answers once, by words, from
152
- local state, with MiniSearch at its default configuration. There is no observed
153
- search.
154
-
155
- - **What is found.** A Document by its field values, its sections' headings and
156
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
157
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
158
- word forms, typo tolerance or prefix matching.
159
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
160
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
161
- apply before `limit`, which bounds each list; without it every hit returns.
162
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
163
- hits of one list of one search. A Document hit names its `room`, `path` and
164
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
165
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
166
- `path`, or `text`. A hit carries no position; mark the words in the text you
167
- show. An invalid filter fails with its Local Query error.
168
-
169
- ## Room Draft, Save, and outcome rules
170
-
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.
181
-
182
- Save takes one Room and the Room Drafts of it to save, each with its revision,
183
- validates locally, and on success appends one Change Batch to that Room's
184
- queue and removes those Room Drafts. It is refused with the `code` `stale`,
185
- `changed-underneath` naming each part whose base no longer matches the visible
186
- state, or a local validation rule, and then creates nothing and leaves every
187
- Room Draft in place. A directory move or removal is a move or removal part on
188
- each Document and binary Path entry beneath it, saved together.
189
-
190
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
191
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
192
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
193
- longer applies over the Room each leave the queue and return as Room Drafts on
194
- the Documents they changed, marked with why: the Provider's structured refusal
195
- code and fields as returned, not known to have applied, or withdrawn locally.
196
- The rest of the queue keeps synchronizing, and Sync Status requires attention
197
- until each returned Room Draft is saved again or discarded. A Change Batch
198
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
199
- Pending one, and a returned Room Draft says why it returned. Transport
200
- failure and Provider unavailability keep work Pending and do not infer a
201
- rejection. A refusal the Provider marks retryable stays Pending until the reset
202
- it names; the MD Runtime retries the same Change Batch identity and payload and
203
- never infers an outcome from transport uncertainty. The MD Runtime never
204
- combines, reorders, or rebases.
205
-
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.
217
-
218
- ## The neutrality rule
219
-
220
- No module outside an Adapter package imports, names, or special-cases a
221
- Provider. MD UI and every App reach data only through the client entry.
222
-
223
- ## Content-safety rules
224
-
225
- The Provider authorization belongs to the Runtime host and is never readable
226
- by the App's code. The App's code reaches the network only at the external
227
- origins its manifest declares, empty by default, and the Provider enforces
228
- that set. Every request to the Provider itself goes through the MD Runtime.
229
- Rendered Markdown never executes scripts, renders raw HTML only for the
230
- details and summary elements, and loads images and other resources only from
231
- origins the Provider's policy allows.
232
-
233
- ## Launch promises MD UI keeps
234
-
235
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
236
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
237
- a desktop. Its strings are English only, dates and numbers follow the
238
- browser locale, and content is never translated. Light and dark themes come
239
- from CSS custom properties with the browser's preference as the default and
240
- an App's override respected. What an App Creator's agent adds carries none
241
- of these promises by itself. Reading, querying and searching never wait for
242
- the network. Data lives only in the App Creator's browser and with the Provider.
243
-
244
- ## App code takes the client its host hands it and never constructs a Runtime
245
-
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.
252
- A Site's page may import `boundQuery` from `@agentshouse/mdruntime/entry` to fill
253
- the `{"$param": name}` arguments of its Entry Data Contract's query descriptors,
254
- so the page queries exactly what House served the entry HTML from.
255
-
256
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
257
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
258
- the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
259
- first value arrives, then `{ state: 'ready', value }`, re-rendering on each
260
- change; a `null` client observes nothing and stays loading. `useSave(client)`
261
- returns `busy`, the last `outcome` or `failure`, and `save(room, roomDrafts)`,
262
- which writes each Path's parts onto the Room Draft already there, keeping the
263
- bases its parts have, or onto a new one, and saves them together. A refused
264
- Save leaves the Room Drafts for the App to save again or discard; a failure is
265
- recorded and rejects. `saveRoomDrafts(client, room, roomDrafts)` is that save
266
- outside a component. A react-admin or Refine App reads and writes its Rooms
267
- through the data providers of `@agentshouse/mdruntime-families`.
268
-
269
- ## The Chat
270
-
271
- `@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App.
272
- Its required peers are React, React DOM and `@assistant-ui/react`: add React as
273
- a dependency, also in an App not written in React.
274
-
275
- Place the ready chat with `<Chat client={runtime} conversation={id}
276
- agent={agent} width="1/3" showChats />`: `conversation` opens one, `null` for a
277
- new chat, `agent` is the Agent a new chat goes to, `onOpen` hears each one it
278
- opens, and `width` is `full` (the place you give it), or `3/4`, `1/2` or `1/3`
279
- of the window docked at its right edge, whole on a narrow window. `showChats`
280
- adds its conversation list; or draw your own inside a `ChatProvider` around a
281
- `<Chat />` with no `client`. It carries its own styles; theme it with CSS custom
282
- properties on it or an ancestor: `--chat-background`, `--chat-surface`,
283
- `--chat-text`, `--chat-text-muted`, `--chat-accent`, `--chat-line`,
284
- `--chat-attention`, `--chat-danger`, `--chat-font`, `--chat-font-mono`,
285
- `--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for spacing);
286
- an unset one keeps House's light or dark look. `mountChat(element, { client })`
287
- places it outside React and returns `update(props)` and `unmount()`.
288
-
289
- Mix `ChatMessageList` (`components` takes your `UserMessage` and
290
- `AssistantMessage`), `ChatInput` and `ChatQuestionCard` with your own design
291
- inside a `ChatProvider`, or compose assistant-ui's primitives there; `useChat()`
292
- gives `send`, the conversations, the Agents, questions to `answer`, `options`
293
- to `choose`, `commands`, the queue to `edit` or `unqueue`, `stop`, `kill` and
294
- outcomes; never replace its messages, sending or store. A secret question is
295
- never answered here; typed answers live in Presentation State's `typed` key:
296
- keep it, and change Presentation State only inside `inTurn(client, work)` from
297
- `@agentshouse/mdruntime/client`. `Markdown` draws Markdown safely.
298
-
299
- ## What an agent must never do
300
-
301
- An agent must never read the authorization, load code from a Room, call the
302
- Provider directly, or rebase a refused Change Batch.
package/dist/gather.d.ts DELETED
@@ -1,4 +0,0 @@
1
- export declare function gatheredEach<A, R>(send: (asks: readonly A[], answer: (ask: number, result: R) => void) => Promise<void>): (ask: A) => Promise<R>;
2
- export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
3
- export declare function selections<T>(items: readonly T[], weight: (item: T) => number, limit: number): readonly (readonly T[])[];
4
- //# sourceMappingURL=gather.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"gather.d.ts","sourceRoot":"","sources":["../src/gather.ts"],"names":[],"mappings":"AAMA,wBAAgB,YAAY,CAAC,CAAC,EAAE,CAAC,EAC/B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,KAAK,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,GACpF,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAwBxB;AAED,wBAAgB,QAAQ,CAAC,CAAC,EAAE,CAAC,EAC3B,IAAI,EAAE,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,KAAK,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC,GAClD,CAAC,GAAG,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAMxB;AAED,wBAAgB,UAAU,CAAC,CAAC,EAC1B,KAAK,EAAE,SAAS,CAAC,EAAE,EACnB,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,EAC3B,KAAK,EAAE,MAAM,GACZ,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC,EAAE,CAgB3B"}
package/dist/gather.js DELETED
@@ -1,45 +0,0 @@
1
- export function gatheredEach(send) {
2
- let held = [];
3
- function flush() {
4
- const taken = held;
5
- held = [];
6
- send(taken.map((entry) => entry.ask), (ask, result) => {
7
- taken[ask]?.resolve(result);
8
- }).catch((reason) => {
9
- for (const entry of taken)
10
- entry.reject(reason);
11
- });
12
- }
13
- return (ask) => new Promise((resolve, reject) => {
14
- if (held.length === 0) {
15
- // Asks made in one task wait a single event-loop turn so they leave as one batch.
16
- setTimeout(flush, 0);
17
- }
18
- held.push({ ask, resolve, reject });
19
- });
20
- }
21
- export function gathered(send) {
22
- return gatheredEach(async (asks, answer) => {
23
- (await send(asks)).forEach((result, ask) => {
24
- answer(ask, result);
25
- });
26
- });
27
- }
28
- export function selections(items, weight, limit) {
29
- const parts = [];
30
- let part = [];
31
- let carried = 0;
32
- for (const item of items) {
33
- const weighed = weight(item);
34
- if (part.length > 0 && carried + weighed > limit) {
35
- parts.push(part);
36
- part = [];
37
- carried = 0;
38
- }
39
- part.push(item);
40
- carried += weighed;
41
- }
42
- if (part.length > 0)
43
- parts.push(part);
44
- return parts;
45
- }