@agentshouse/mdruntime-adapter 0.1.0-c6296cfbceb56 → 0.1.0-c658cd7165027

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 (68) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +130 -7
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +41 -148
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +283 -171
  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 +7 -10
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +44 -36
  17. package/dist/gather.d.ts +1 -2
  18. package/dist/gather.d.ts.map +1 -1
  19. package/dist/gather.js +5 -15
  20. package/dist/house-model.d.ts +2938 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +1614 -0
  23. package/dist/index.d.ts +8 -2
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +7 -1
  26. package/dist/model.d.ts +5 -2
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +10 -15
  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 +66 -18
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +318 -128
  35. package/dist/refusal.d.ts.map +1 -1
  36. package/dist/refusal.js +2 -1
  37. package/dist/room-stream.d.ts +19 -0
  38. package/dist/room-stream.d.ts.map +1 -0
  39. package/dist/room-stream.js +57 -0
  40. package/dist/room-types.d.ts +7 -0
  41. package/dist/room-types.d.ts.map +1 -0
  42. package/dist/room-types.js +126 -0
  43. package/dist/site.d.ts +1 -1
  44. package/dist/site.d.ts.map +1 -1
  45. package/dist/site.js +113 -87
  46. package/dist/stream.d.ts +2 -4
  47. package/dist/stream.d.ts.map +1 -1
  48. package/dist/stream.js +103 -47
  49. package/dist/transport.d.ts +49 -11
  50. package/dist/transport.d.ts.map +1 -1
  51. package/dist/transport.js +2 -1
  52. package/dist/upload.d.ts +12 -0
  53. package/dist/upload.d.ts.map +1 -0
  54. package/dist/upload.js +63 -0
  55. package/dist/version.d.ts +1 -0
  56. package/dist/version.d.ts.map +1 -1
  57. package/dist/version.js +1 -1
  58. package/dist/write.d.ts +16 -1
  59. package/dist/write.d.ts.map +1 -1
  60. package/dist/write.js +109 -59
  61. package/package.json +8 -5
  62. package/AGENTS.md +0 -318
  63. package/dist/handed.d.ts +0 -15
  64. package/dist/handed.d.ts.map +0 -1
  65. package/dist/handed.js +0 -38
  66. package/dist/referrer.d.ts +0 -7
  67. package/dist/referrer.d.ts.map +0 -1
  68. package/dist/referrer.js +0 -35
package/dist/write.js CHANGED
@@ -1,5 +1,5 @@
1
- import { departure, } from '@agentshouse/mdruntime';
2
- import { 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,6 +120,27 @@ export function houseChanges(batch, handle) {
120
120
  }
121
121
  return { kind: 'changes', changes };
122
122
  }
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
+ }
123
144
  export function operationHead(batch) {
124
145
  const writer = batch.writtenBy;
125
146
  return writer === undefined
@@ -129,7 +150,7 @@ export function operationHead(batch) {
129
150
  export function batchPaths(changes) {
130
151
  return [
131
152
  ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
132
- ].sort();
153
+ ];
133
154
  }
134
155
  export function deltaBody(changes) {
135
156
  return JSON.stringify({ changes });
@@ -144,21 +165,25 @@ export function uploadable(inline, bytes, bounds) {
144
165
  export function deltaDigest(delta) {
145
166
  return sha256Hex(delta);
146
167
  }
147
- function material(value, handle) {
168
+ function* material(value, handle, within = () => true) {
148
169
  if (!Array.isArray(value))
149
170
  return null;
150
171
  const held = [];
151
172
  for (const entry of value) {
173
+ yield ROW_WEIGHT;
152
174
  if (typeof entry !== 'object' || entry === null)
153
175
  return null;
154
176
  const file = entry;
155
177
  if (typeof file.path !== 'string')
156
178
  return null;
179
+ if (!within(file.path))
180
+ continue;
157
181
  if (file.content !== null && typeof file.content !== 'string')
158
182
  return null;
159
183
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
160
184
  return null;
161
- if (file.file !== undefined && typeof file.file !== 'string')
185
+ const binary = binaryFileOf(file);
186
+ if (binary === null)
162
187
  return null;
163
188
  const head = headChange(file);
164
189
  if (head === null)
@@ -174,33 +199,80 @@ function material(value, handle) {
174
199
  path,
175
200
  content: file.content,
176
201
  revision: typeof file.revision === 'string' ? file.revision : null,
177
- file: typeof file.file === 'string' ? file.file : null,
202
+ ...(binary === undefined ? {} : { binary }),
178
203
  ...(head === undefined ? {} : { head }),
179
204
  });
180
205
  }
181
206
  return held;
182
207
  }
183
- function affectedOf(held) {
208
+ function* affectedOf(held) {
184
209
  const affected = {};
185
210
  for (const entry of held) {
186
211
  if (entry.content !== null)
187
212
  affected[entry.path] = entry.content;
213
+ yield ROW_WEIGHT;
188
214
  }
189
215
  return affected;
190
216
  }
191
- export function mutationOutcome(status, body, locator, handle) {
217
+ function* acceptedOf(at, contents) {
218
+ const answer = answering();
219
+ for (const entry of contents) {
220
+ yield ROW_WEIGHT + (entry.content?.length ?? 0);
221
+ if (entry.revision === null) {
222
+ answer.removals.add(entry.path);
223
+ continue;
224
+ }
225
+ if (entry.content !== null)
226
+ answer.documents.set(entry.path, entry.content);
227
+ if (entry.binary !== undefined)
228
+ answer.binaryFiles.set(entry.path, entry.binary);
229
+ revised(answer, entry.path, entry.revision);
230
+ if (entry.head !== undefined)
231
+ answer.changes.set(entry.path, entry.head);
232
+ }
233
+ const unbinaried = answer.binaryFiles.size === 0;
234
+ const { binaryFiles, ...room } = yield* answered(answer);
235
+ return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
236
+ }
237
+ function* movedOutcome(held, move) {
238
+ const authorities = Array.isArray(held.authorities) ? held.authorities : [];
239
+ const at = (authority) => {
240
+ const entry = authorities.find((one) => typeof one === 'object' &&
241
+ one !== null &&
242
+ one.authority === authority);
243
+ return entry === undefined ? null : readPosition(entry);
244
+ };
245
+ const left = at(move.source.authority);
246
+ const arrived = at(move.destination.authority);
247
+ if (left === null || arrived === null)
248
+ return { kind: 'transport-uncertainty' };
249
+ const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
250
+ const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
251
+ const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
252
+ if (leaving === null || arriving === null)
253
+ return { kind: 'transport-uncertainty' };
254
+ return {
255
+ kind: 'accepted',
256
+ ...(yield* acceptedOf(left, leaving)),
257
+ destination: yield* acceptedOf(arrived, arriving),
258
+ };
259
+ }
260
+ export function* mutationOutcome(status, body, locator, handle, move) {
192
261
  const refusal = doorRefusal(body);
193
262
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
194
263
  return { kind: 'write-halted' };
195
264
  }
196
- if (refusal !== null && refusal.code === 'expired')
197
- return { kind: 'expired' };
265
+ if (refusal !== null && refusal.code === 'expired') {
266
+ return refusal.fields.restored === true
267
+ ? { kind: 'expired', restored: true }
268
+ : { kind: 'expired' };
269
+ }
198
270
  if (refusal !== null && refusal.code === 'edit_conflict') {
199
271
  const { current, ...fields } = refusal.fields;
200
- const held = material(current, handle) ?? [];
272
+ const held = (yield* material(current, handle)) ?? [];
201
273
  return {
202
274
  kind: 'conflicted',
203
- affected: affectedOf(held),
275
+ affected: yield* affectedOf(held),
204
276
  code: refusal.code,
205
277
  fields,
206
278
  retryable: refusal.retryable,
@@ -224,8 +296,9 @@ export function mutationOutcome(status, body, locator, handle) {
224
296
  }
225
297
  if (classified !== null && classified.kind !== 'scoped-refusal')
226
298
  return classified;
227
- if (classified !== null && status === 403)
299
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
228
300
  return classified;
301
+ }
229
302
  if (refusal !== null && status >= 400) {
230
303
  return {
231
304
  kind: 'rejected',
@@ -239,39 +312,15 @@ export function mutationOutcome(status, body, locator, handle) {
239
312
  return { kind: 'transport-uncertainty' };
240
313
  }
241
314
  const held = body;
315
+ if (move !== undefined)
316
+ return yield* movedOutcome(held, move);
242
317
  const at = readPosition(held);
243
318
  if (at === null)
244
319
  return { kind: 'transport-uncertainty' };
245
- const contents = material(held.contents, handle);
320
+ const contents = yield* material(held.contents, handle);
246
321
  if (contents === null)
247
322
  return { kind: 'transport-uncertainty' };
248
- const documents = {};
249
- const revisions = {};
250
- const changes = {};
251
- const fileRefs = {};
252
- const removals = [];
253
- for (const entry of contents) {
254
- if (entry.revision === null) {
255
- removals.push(entry.path);
256
- continue;
257
- }
258
- if (entry.content !== null)
259
- documents[entry.path] = entry.content;
260
- if (entry.file !== null)
261
- fileRefs[entry.path] = entry.file;
262
- revisions[entry.path] = entry.revision;
263
- if (entry.head !== undefined)
264
- changes[entry.path] = entry.head;
265
- }
266
- return {
267
- kind: 'accepted',
268
- roomVersion: roomVersion(at),
269
- documents,
270
- revisions,
271
- changes,
272
- removals: removals.sort(),
273
- ...(Object.keys(fileRefs).length === 0 ? {} : { fileRefs }),
274
- };
323
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
275
324
  }
276
325
  export function rejectedMapping(mapping) {
277
326
  return {
@@ -292,26 +341,27 @@ export function revisionBody(input) {
292
341
  function revisionAuthor(entry) {
293
342
  const user = entry.author_user;
294
343
  const site = entry.author_site;
295
- const name = entry.author_site_name;
296
- if (typeof user === 'string' && site === undefined && name === undefined) {
344
+ const siteName = entry.author_site_name;
345
+ const inbox = entry.author_inbox;
346
+ const inboxName = entry.author_inbox_name;
347
+ const app = entry.author_app;
348
+ const appName = entry.author_app_name;
349
+ const named = [site, siteName, inbox, inboxName, app, appName].filter((held) => held !== undefined);
350
+ if (typeof user === 'string' && named.length === 0)
297
351
  return { kind: 'user', id: user };
352
+ if (user !== null || named.length !== 2)
353
+ return null;
354
+ if (typeof site === 'string' && typeof siteName === 'string') {
355
+ return { kind: 'site', id: site, name: siteName };
356
+ }
357
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
358
+ return { kind: 'inbox', id: inbox, name: inboxName };
298
359
  }
299
- if (user === null && typeof site === 'string' && typeof name === 'string') {
300
- return { kind: 'site', id: site, name };
360
+ if (typeof app === 'string' && typeof appName === 'string') {
361
+ return { kind: 'app', id: app, name: appName };
301
362
  }
302
363
  return null;
303
364
  }
304
- function historyBinary(entry) {
305
- if (entry.file === undefined)
306
- return undefined;
307
- const { file, bytes, media_type: mediaType, sha256 } = entry;
308
- if (typeof file !== 'string' ||
309
- typeof bytes !== 'number' ||
310
- typeof mediaType !== 'string' ||
311
- typeof sha256 !== 'string')
312
- return null;
313
- return { fileRef: file, byteLength: bytes, mediaType, sha256 };
314
- }
315
365
  export function historyOutcome(status, body, locator, request) {
316
366
  const classified = classifyDoor(status, body, locator);
317
367
  if (classified !== null)
@@ -336,13 +386,13 @@ export function historyOutcome(status, body, locator, request) {
336
386
  return {
337
387
  kind: 'scoped-refusal',
338
388
  locator,
339
- scope: 'content',
389
+ scope: 'operation',
340
390
  code: 'retained_history_unavailable',
341
391
  fields: { path: request.path, revision: request.revision },
342
392
  retryable: false,
343
393
  };
344
394
  }
345
- if (typeof named.file === 'string')
395
+ if (typeof named.media_type === 'string')
346
396
  return { kind: 'no-history' };
347
397
  if (typeof named.content !== 'string')
348
398
  return { kind: 'transport-uncertainty' };
@@ -358,7 +408,7 @@ export function historyOutcome(status, body, locator, request) {
358
408
  typeof entry.created_at !== 'string') {
359
409
  return { kind: 'transport-uncertainty' };
360
410
  }
361
- const binaryFile = historyBinary(entry);
411
+ const binaryFile = binaryFileOf(entry);
362
412
  if (binaryFile === null)
363
413
  return { kind: 'transport-uncertainty' };
364
414
  revisions.push({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-c6296cfbceb56",
3
+ "version": "0.1.0-c658cd7165027",
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,12 +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/mdmodel": "0.1.0-cc9fa0498a7f7",
29
- "@agentshouse/mdruntime": "0.1.0-cde2b99d2fcbc"
27
+ "@agentshouse/mdruntime": "0.1.0-c73e437bf1616"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "git+https://github.com/agentshouse/core.git",
32
+ "directory": "mdruntime/packages/mdruntime-adapter"
30
33
  }
31
34
  }
package/AGENTS.md DELETED
@@ -1,318 +0,0 @@
1
- # Instructions for the App Creator's agent
2
-
3
- These instructions address an agent in an environment with Git. Obtain the
4
- App Repository, change it, build, and push. They are documentation, not 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,
11
- the reported persistence answer, reauthorization, conversation, the chat draft,
12
- and Presentation State. Sync Status, the Service Mode, the storage-loss
13
- statement, the deployment facts and the signed-in member are observations only.
14
-
15
- The host attaches each port with its reach, and every member and observation
16
- answers within it: a Room outside it answers as one the replica does not hold,
17
- Rooms lists only the Rooms reached whole, a Room reached for single Documents
18
- shows only those Documents and the Types of the models that govern them, and
19
- without conversations the conversation members, the chat draft and the
20
- conversation observation hold none.
21
- A change of the reach reaches every open observation as its new value, a query
22
- keeping every unchanged Document the same object.
23
-
24
- Every `observe` resolves, once its first value has arrived, to a handle:
25
- `current()` is the latest complete value, `subscribe(listener)` hears each later
26
- value whole and returns its unsubscribe, and `close()` ends the observation.
27
- Closing the port ends every handle and rejects every pending call and
28
- observation; a client that reconnects observes again.
29
-
30
- `observe('agents')` answers every Agent a new conversation can go to, each
31
- `{ identity, name }`, whether or not it has a conversation yet.
32
- Each conversation the Provider's conversation list names is held complete in the
33
- browser. `conversation.list()` and `observe('conversations')` answer each with its
34
- Agent's identity and name, its name, created and finished times, last outcome and live
35
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
36
- and `started`, when the running turn began, or `null`.
37
- Observe one with `observe('conversation', id, { limit })`: the view
38
- holds its latest `limit` messages, or all of them, oldest first, its chat
39
- draft, and what the Provider streams for it whether or not anything views it:
40
- the running `turn` with its message parts and its context in use and window, the
41
- open questions, the process state, and the CLI's commands and options. These live
42
- only in memory: the message accepted under the turn's id replaces the running turn,
43
- and none of them is stored or searchable.
44
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
45
- sending it is a Provider Action that needs the Provider reachable and is never
46
- queued.
47
-
48
- A binary file at a Path of a Room is a binary Path entry. Query lists it by
49
- `path` with its `binaryFile` record and never its bytes: `{ state: 'accepted',
50
- revision, path, fileRef, byteLength, mediaType, sha256 }`, or, from a Save until
51
- the Provider accepts it, `{ state: 'pending', localId, path, byteLength,
52
- mediaType, sha256 }` with no revision. Write one with a Room Draft whose only part
53
- is `file: { blob }`, a `Blob` whose `type` is its media type; Save keeps the bytes
54
- in its Pending Change, works offline, and the record turns accepted with the
55
- Provider's revision once the Pending Change is accepted. Move or remove an
56
- accepted one as a Document. Move or remove a pending one the same way, before or
57
- after Save: the Room Draft or its queued Pending Change carries the bytes to the
58
- new Path or drops them, and once that Pending Change has gone to the Provider
59
- Save refuses it as `unknown-revision` until it is accepted. Read the bytes with
60
- `binaryFile.read(room, path)`: a pending record answers its saved bytes, and
61
- every read of an accepted one asks the Provider again and keeps nothing. Pass a
62
- History revision as `binaryFile.read(room, path, revision)` to open that
63
- revision, a removed file's last one included. Text, a Record attachment or a conversation
64
- message may name a file directly by its `fileRef`; read that file with
65
- `binaryFile.readReference({ fileRef, referrer })`, where the referrer is the
66
- `referrer` the Provider gave beside the reference, or `{ room, path }` of the
67
- document whose text names it. Both answer `{ kind: 'binary', blob }` or a
68
- refusal or failure. History of a binary Path lists each revision's
69
- `binaryFile` metadata without bytes.
70
-
71
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
72
- touch the network.
73
- History, the binary file reads and Call go to the Provider through the Adapter. Call takes the Action names
74
- the Adapter declares; any other name answers `undeclared` without reaching the
75
- Provider. A Call result whose
76
- effect the Provider places in a Room carries `at`, that Room and Room Version;
77
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
78
- reached it, and the MD Runtime keeps refreshing that Room until it has;
79
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
80
- that document was written at a later Room Version. Each History revision
81
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
82
- History of a Path no current document holds answers the removed document's
83
- revisions with `deleted: true`, newest first; that revision is what a link to
84
- the Path opens. Every
85
- member of the
86
- client is asynchronous. Results are detached snapshots. Nothing in this
87
- surface returns the authorization, performs a request the App's code
88
- composes, or exposes the browser store.
89
-
90
- Every refusal and failure carries `code` and `retryable`: each Call and History answer
91
- other than its result, a refused Save or Room Draft write, a returned Room Draft's
92
- reason, a Room's refusal and the Connection Refusal, and every error a member rejects
93
- with, beside its message. A Provider refusal carries the Provider's own `retryable`.
94
- Every code and every value the API answers is open: handle one you do not know by its
95
- `code` and `retryable`.
96
-
97
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
98
- opaque value using the host's contract.
99
-
100
- `observe('member')` answers who uses the App: the User the Provider signed in,
101
- `{ kind: 'user', id, name }` in the shape of a change's `author`, so a Document
102
- whose `change.author.id` equals its `id` is that User's own. It is `null` until
103
- the Provider first names one, and where it names none, such as a Site. The
104
- MD Runtime keeps it with the Local Replicas, so it answers offline once known,
105
- and every port hears the next member the Provider names; signing out answers
106
- `null`, then ends the observation with the authorization. It is the only way App code learns who
107
- uses it.
108
-
109
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
110
- ships in no bundle.
111
-
112
- ## Local Query rules
113
-
114
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
115
- result and hears it again only when it changes, keeping every unchanged Document
116
- the same object, so a component can tell what changed by identity. A query is
117
- data:
118
-
119
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
120
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
121
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
122
- - **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
123
- `/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
124
- meets a list applies to every item and a number names one item. `where` names
125
- pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
126
- when any item satisfies it. A bare value is equality; the operators are `$eq`,
127
- `$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
128
- `$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
129
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
130
- text and `$size: 0` an empty list. A date compares in calendar order and never
131
- with a date-time. A reference compares by the Room Path it resolves to.
132
- Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
133
- values. There is no text containment or regular
134
- expression.
135
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
136
- reference at pointer `field`, at any depth, points to a matching Document of the
137
- same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
138
- matching Document of the same Room references. Each keeps a Document once.
139
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
140
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
141
- list of pointers and `sections` `'all'` or a list of names. Selected pointers
142
- return the frontmatter holding only them, nested as written. A backlink names
143
- the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
144
- Document also returns its MD Type. A non-Markdown Document returns only Room
145
- and Path, and a binary Path entry Room, Path and its `binaryFile` record,
146
- whatever is selected. An unselected part is absent. Select only
147
- what a screen shows: a list that selects the Markdown hears every edit of it.
148
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
149
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
150
- or `null` for a write the Provider made itself, and `time` is the Provider's
151
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
152
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
153
- saved write takes the Provider's own once it is Accepted. A
154
- Room's last change is its Document with the latest `time`.
155
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
156
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
157
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
158
- over every match and ordered by `count` or a key. A sort or group takes only a
159
- pointer that holds one value. `limit` bounds the Documents or the groups.
160
- - **Results and errors.** A result carries no Room Version: read freshness from
161
- Rooms and Sync Status. An invalid query fails with the `code`
162
- `invalid-query`, `unknown-type`, `unknown-field` or `wrong-kind`, naming where,
163
- and never answers an empty result in its place.
164
-
165
- ## Local Search rules
166
-
167
- `search({ text, documents, conversations, limit })` answers once, by words, from
168
- local state, with MiniSearch at its default configuration. There is no observed
169
- search.
170
-
171
- - **What is found.** A Document by its field values, its sections' headings and
172
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
173
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
174
- word forms, typo tolerance or prefix matching.
175
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
176
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
177
- apply before `limit`, which bounds each list; without it every hit returns.
178
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
179
- hits of one list of one search. A Document hit names its `room`, `path` and
180
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
181
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
182
- `path`, or `text`. A hit carries no position; mark the words in the text you
183
- show. An invalid filter fails with its Local Query error.
184
-
185
- ## Room Draft, Save, and outcome rules
186
-
187
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
188
- tab. It is durable: it survives reload and navigation. A Room that Discovery
189
- stops listing takes its Room Drafts and its queue with it.
190
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
191
- the revision you read, or `null` when there was none, and every part it should
192
- now change: fields, sections and the preamble, or the whole Markdown, a
193
- creation, a move, or a removal. A part new to the Room Draft names its base,
194
- the value you showed when it was opened; the MD Runtime keeps a part's first
195
- base. A binary link target has a Room Draft too, for a move or a removal, with
196
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
197
- the current Room Draft; read it and write again.
198
-
199
- Save takes one Room and the Room Drafts of it to save, each with its revision,
200
- validates locally, and on success appends one Change Batch to that Room's
201
- queue and removes those Room Drafts. It is refused with the `code` `stale`,
202
- `changed-underneath` naming each part whose base no longer matches the visible
203
- state, or a local validation rule, and then creates nothing and leaves every
204
- Room Draft in place. A directory move or removal is a move or removal part on
205
- each Document and binary link target beneath it, saved together.
206
-
207
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
208
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
209
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
210
- longer applies over the Room each leave the queue and return as Room Drafts on
211
- the Documents they changed, marked with why: the Provider's structured refusal
212
- code and fields as returned, not known to have applied, or withdrawn locally.
213
- The rest of the queue keeps synchronizing, and Sync Status requires attention
214
- until each returned Room Draft is saved again or discarded. A Change Batch
215
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
216
- Pending one, and a returned Room Draft says why it returned. Transport
217
- failure and Provider unavailability keep work Pending and do not infer a
218
- rejection. A refusal the Provider marks retryable stays Pending until the reset
219
- it names; the MD Runtime retries the same Change Batch identity and payload and
220
- never infers an outcome from transport uncertainty. The MD Runtime never
221
- combines, reorders, or rebases.
222
-
223
- On a Site, every Save stays in the visitor's browser. Write grants and
224
- revisions do not refuse it, and its Pending Change shows in every query and
225
- across reloads until the browser's storage is cleared. It is never sent:
226
- `observe('queue', room)` shows it `local`, and Sync Status never waits on it.
227
- Once the Room changes so that it no longer applies, it leaves the queue and
228
- returns no Room Draft.
229
-
230
- `observe('service-mode')` answers the Provider's Service
231
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
232
- its Change Batch waits unsent, and the queue is submitted in order once the
233
- Provider reopens writes. An Action is never held: a write the Provider refuses
234
- for the halt returns that refusal to its caller. Show the Provider as read-only
235
- instead of retrying.
236
-
237
- ## The neutrality rule
238
-
239
- No module outside an Adapter package imports, names, or special-cases a
240
- Provider. MD UI and every App reach data only through the client entry.
241
-
242
- ## Content-safety rules
243
-
244
- The Provider authorization belongs to the Runtime host and is never readable
245
- by the App's code. The App's code reaches the network only at the external
246
- origins its manifest declares, empty by default, and the Provider enforces
247
- that set. Every request to the Provider itself goes through the MD Runtime.
248
- Rendered Markdown never executes scripts, renders raw HTML only for the
249
- details and summary elements, and loads images and other resources only from
250
- origins the Provider's policy allows.
251
-
252
- ## Launch promises MD UI keeps
253
-
254
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
255
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
256
- a desktop. Its strings are English only, dates and numbers follow the
257
- browser locale, and content is never translated. Light and dark themes come
258
- from CSS custom properties with the browser's preference as the default and
259
- an App's override respected. What an App Creator's agent adds carries none
260
- of these promises by itself. Reading, querying and searching never wait for
261
- the network. Data lives only in the App Creator's browser and with the Provider.
262
-
263
- ## App code takes the client its host hands it and never constructs a Runtime
264
-
265
- App code takes the client its host hands it: in House, `houseBridge().runtime`
266
- from `@agentshouse/app-bridge` resolves to the client House built into the page.
267
- It never constructs a Runtime or a client. It imports only types from
268
- `@agentshouse/mdruntime/client`, does not call `connectMdRuntime` or
269
- `serveMdRuntime`, and does not import the package main, the host entry, or the
270
- Adapter package. Hosts and tests use those entries; the served App does not.
271
-
272
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
273
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
274
- the arguments of `observe` and returns `{ state: 'loading' }` until the topic's
275
- first value arrives, then `{ state: 'ready', value }`, re-rendering on each
276
- change; a `null` client observes nothing and stays loading. `useSave(client)`
277
- returns `busy`, the last `outcome` or `failure`, and `save(room, roomDrafts)`,
278
- which writes each Path's parts onto the Room Draft already there, keeping the
279
- bases its parts have, or onto a new one, and saves them together. A refused
280
- Save leaves the Room Drafts for the App to save again or discard; a failure is
281
- recorded and rejects. `saveRoomDrafts(client, room, roomDrafts)` is that save
282
- outside a component. A react-admin or Refine App reads and writes its Rooms
283
- through the data providers of `@agentshouse/mdruntime-families`.
284
-
285
- ## The Chat
286
-
287
- `@agentshouse/mdruntime/chat` holds the Chat, one data layer for every App.
288
- Its required peers are React, React DOM and `@assistant-ui/react`: add React as
289
- a dependency, also in an App not written in React.
290
-
291
- Place the ready chat with `<Chat client={runtime} conversation={id}
292
- agent={agent} width="1/3" showChats />`: `conversation` opens one, `null` for a
293
- new chat, `agent` is the Agent a new chat goes to, `onOpen` hears each one it
294
- opens, and `width` is `full` (the place you give it), or `3/4`, `1/2` or `1/3`
295
- of the window docked at its right edge, whole on a narrow window. `showChats`
296
- adds its conversation list; or draw your own inside a `ChatProvider` around a
297
- `<Chat />` with no `client`. It carries its own styles; theme it with CSS custom
298
- properties on it or an ancestor: `--chat-background`, `--chat-surface`,
299
- `--chat-text`, `--chat-text-muted`, `--chat-accent`, `--chat-line`,
300
- `--chat-attention`, `--chat-danger`, `--chat-font`, `--chat-font-mono`,
301
- `--chat-font-size`, `--chat-radius` and `--chat-density` (a factor for spacing);
302
- an unset one keeps House's light or dark look. `mountChat(element, { client })`
303
- places it outside React and returns `update(props)` and `unmount()`.
304
-
305
- Mix `ChatMessageList` (`components` takes your `UserMessage` and
306
- `AssistantMessage`), `ChatInput` and `ChatQuestionCard` with your own design
307
- inside a `ChatProvider`, or compose assistant-ui's primitives there; `useChat()`
308
- gives `send`, the conversations, the Agents, questions to `answer`, `options`
309
- to `choose`, `commands`, the queue to `edit` or `unqueue`, `stop`, `kill` and
310
- outcomes; never replace its messages, sending or store. A secret question is
311
- never answered here; typed answers live in Presentation State's `typed` key:
312
- keep it, and change Presentation State only inside `inTurn(client, work)` from
313
- `@agentshouse/mdruntime/client`. `Markdown` draws Markdown safely.
314
-
315
- ## What an agent must never do
316
-
317
- An agent must never read the authorization, load code from a Room, call the
318
- Provider directly, or rebase a refused Change Batch.
package/dist/handed.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { HeldRoom, MutationResult } from '@agentshouse/mdruntime';
2
- import type { HouseScope, HouseView } from './read.js';
3
- import type { StreamedAdvancement } from './stream.js';
4
- export type HandedRoom = {
5
- roomVersion: string;
6
- revisions: ReadonlyMap<string, string>;
7
- };
8
- export declare function scopeHanded(scope: HouseScope): HandedRoom;
9
- export declare function heldHanded(held: HeldRoom): HandedRoom;
10
- export declare function acceptedHanded(held: HandedRoom, accepted: Extract<MutationResult, {
11
- kind: 'accepted';
12
- }>, roomVersion: string): HandedRoom;
13
- export declare function enumeratedHanded(view: HouseView, earlier: HandedRoom | undefined): HandedRoom;
14
- export declare function streamedHanded(held: HandedRoom, advanced: StreamedAdvancement): HandedRoom;
15
- //# sourceMappingURL=handed.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handed.d.ts","sourceRoot":"","sources":["../src/handed.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGvD,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CASzD;AAOD,wBAAgB,UAAU,CAAC,IAAI,EAAE,QAAQ,GAAG,UAAU,CAErD;AAED,wBAAgB,cAAc,CAC5B,IAAI,EAAE,UAAU,EAChB,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACvD,WAAW,EAAE,MAAM,GAClB,UAAU,CAKZ;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,GAAG,SAAS,GAAG,UAAU,CAM7F;AAED,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,GAAG,UAAU,CAM1F"}