@agentshouse/mdruntime-adapter 0.1.0-cca5d676bc88e → 0.1.0-ccc7c7aecd1ac

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 (76) hide show
  1. package/README.md +3 -3
  2. package/dist/actions.d.ts +6 -6
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +28 -328
  5. package/dist/adapter.d.ts +1 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +314 -222
  8. package/dist/authored-path.d.ts +9 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +34 -0
  11. package/dist/chunks.d.ts +36 -0
  12. package/dist/chunks.d.ts.map +1 -0
  13. package/dist/chunks.js +281 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/discovery.d.ts +46 -20
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +266 -67
  18. package/dist/history.d.ts +6 -0
  19. package/dist/history.d.ts.map +1 -0
  20. package/dist/history.js +85 -0
  21. package/dist/index.d.ts +10 -3
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +9 -1
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -6
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +35 -38
  28. package/dist/read.d.ts +54 -48
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +182 -266
  31. package/dist/refusal.d.ts +10 -13
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +54 -24
  34. package/dist/room-query.d.ts +4 -0
  35. package/dist/room-query.d.ts.map +1 -0
  36. package/dist/room-query.js +36 -0
  37. package/dist/search.d.ts +4 -0
  38. package/dist/search.d.ts.map +1 -0
  39. package/dist/search.js +47 -0
  40. package/dist/session-content/check.d.ts +17 -0
  41. package/dist/session-content/index.d.ts +6 -0
  42. package/dist/session-content/parts.d.ts +30 -0
  43. package/dist/session-content/state.d.ts +59 -0
  44. package/dist/session-content/turn.d.ts +137 -0
  45. package/dist/site.d.ts +1 -2
  46. package/dist/site.d.ts.map +1 -1
  47. package/dist/site.js +139 -107
  48. package/dist/space-schema.d.ts +6 -0
  49. package/dist/space-schema.d.ts.map +1 -0
  50. package/dist/space-schema.js +11 -0
  51. package/dist/stream.d.ts +14 -13
  52. package/dist/stream.d.ts.map +1 -1
  53. package/dist/stream.js +282 -148
  54. package/dist/transport.d.ts +125 -30
  55. package/dist/transport.d.ts.map +1 -1
  56. package/dist/transport.js +90 -10
  57. package/dist/uncertain.d.ts +5 -0
  58. package/dist/uncertain.d.ts.map +1 -0
  59. package/dist/uncertain.js +11 -0
  60. package/dist/upload.d.ts +13 -0
  61. package/dist/upload.d.ts.map +1 -0
  62. package/dist/upload.js +65 -0
  63. package/dist/version.d.ts +1 -1
  64. package/dist/version.d.ts.map +1 -1
  65. package/dist/version.js +1 -1
  66. package/dist/write.d.ts +20 -12
  67. package/dist/write.d.ts.map +1 -1
  68. package/dist/write.js +183 -78
  69. package/package.json +10 -6
  70. package/AGENTS.md +0 -231
  71. package/dist/gather.d.ts +0 -3
  72. package/dist/gather.d.ts.map +0 -1
  73. package/dist/gather.js +0 -40
  74. package/dist/links.d.ts +0 -20
  75. package/dist/links.d.ts.map +0 -1
  76. package/dist/links.js +0 -104
package/dist/write.js CHANGED
@@ -1,8 +1,10 @@
1
- import { parseOriginals } from './read.js';
1
+ import { departure, partsChanges, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
2
3
  import { sha256Hex, textBytes } from './digest.js';
3
4
  import { nativePath, roomLocalPath } from './map.js';
4
- import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
5
+ import { answeredFailure, classifyDoor, doorRefusal, resetOf, scopedRefusal } from './refusal.js';
5
6
  import { readPosition, roomVersion } from './version.js';
7
+ import { unusable } from './uncertain.js';
6
8
  function priorField(batch, path, name) {
7
9
  return batch.preconditions.find((precondition) => precondition.kind === 'field' && precondition.path === path && precondition.name === name);
8
10
  }
@@ -27,7 +29,7 @@ function created(change, path) {
27
29
  const { type, ...fields } = change.fields;
28
30
  if (typeof type !== 'string' || type.length === 0)
29
31
  return null;
30
- return { op: 'create_typed', path, type, fields, sections: change.sections };
32
+ return { op: 'create_typed', path, type, fields };
31
33
  }
32
34
  function operationOf(batch, change, handle) {
33
35
  const path = nativePath(change.path, handle);
@@ -73,6 +75,25 @@ function operationOf(batch, change, handle) {
73
75
  const operation = created(change, path);
74
76
  return operation === null ? { rule: 'type-missing' } : { operation };
75
77
  }
78
+ if (change.kind === 'binary') {
79
+ const written = {
80
+ op: 'upload',
81
+ path,
82
+ local_id: change.localId,
83
+ bytes: change.byteLength,
84
+ sha256: change.sha256,
85
+ media_type: change.mediaType,
86
+ };
87
+ const from = departure(batch.changes, batch.changes.indexOf(change));
88
+ if (from === change.path && priorAbsence(batch, change.path) !== undefined)
89
+ return { operation: written };
90
+ const replaced = priorExistence(batch, from);
91
+ if (replaced === undefined)
92
+ return { rule: 'precondition-missing' };
93
+ if (!('base' in replaced))
94
+ return { rule: 'presence-base-unrepresentable' };
95
+ return { operation: { ...written, base: replaced.base } };
96
+ }
76
97
  const existence = priorExistence(batch, change.path);
77
98
  if (existence === undefined)
78
99
  return { rule: 'precondition-missing' };
@@ -100,16 +121,36 @@ export function houseChanges(batch, handle) {
100
121
  }
101
122
  return { kind: 'changes', changes };
102
123
  }
103
- export function operationHead(batch) {
124
+ export function houseParts(saved, handle) {
125
+ return houseChanges({ id: '', baseRoomVersion: '', ...partsChanges(saved) }, handle);
126
+ }
127
+ export function houseMove(batch, source, destination) {
128
+ const changes = [];
129
+ for (const { path, to } of batch.between?.moves ?? []) {
130
+ const existence = priorExistence(batch, path);
131
+ if (existence === undefined)
132
+ return { kind: 'unmapped', path, rule: 'precondition-missing' };
133
+ if (!('base' in existence)) {
134
+ return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
135
+ }
136
+ changes.push({
137
+ op: 'rename',
138
+ path: nativePath(path, source),
139
+ to: nativePath(to, destination),
140
+ base: existence.base,
141
+ });
142
+ }
143
+ return { kind: 'changes', changes };
144
+ }
145
+ export function operationHead(batch, room) {
104
146
  const writer = batch.writtenBy;
105
- return writer === undefined
106
- ? { operation_id: batch.id }
107
- : { operation_id: batch.id, app_ref: writer.app, release: writer.release };
147
+ const head = { operation_id: batch.id, room_ref: room };
148
+ return writer === undefined ? head : { ...head, app_ref: writer.app, release: writer.release };
108
149
  }
109
150
  export function batchPaths(changes) {
110
151
  return [
111
152
  ...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
112
- ].sort();
153
+ ];
113
154
  }
114
155
  export function deltaBody(changes) {
115
156
  return JSON.stringify({ changes });
@@ -124,20 +165,29 @@ export function uploadable(inline, bytes, bounds) {
124
165
  export function deltaDigest(delta) {
125
166
  return sha256Hex(delta);
126
167
  }
127
- function material(value, handle) {
168
+ function* material(value, handle, within = () => true) {
128
169
  if (!Array.isArray(value))
129
170
  return null;
130
171
  const held = [];
131
172
  for (const entry of value) {
173
+ yield ROW_WEIGHT;
132
174
  if (typeof entry !== 'object' || entry === null)
133
175
  return null;
134
176
  const file = entry;
135
177
  if (typeof file.path !== 'string')
136
178
  return null;
179
+ if (!within(file.path))
180
+ continue;
137
181
  if (file.content !== null && typeof file.content !== 'string')
138
182
  return null;
139
183
  if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
140
184
  return null;
185
+ const binary = binaryFileOf(file);
186
+ if (binary === null)
187
+ return null;
188
+ const head = headChange(file);
189
+ if (head === null)
190
+ return null;
141
191
  let path;
142
192
  try {
143
193
  path = roomLocalPath(file.path, handle);
@@ -149,80 +199,122 @@ function material(value, handle) {
149
199
  path,
150
200
  content: file.content,
151
201
  revision: typeof file.revision === 'string' ? file.revision : null,
202
+ ...(binary === undefined ? {} : { binary }),
203
+ ...(head === undefined ? {} : { head }),
152
204
  });
153
205
  }
154
206
  return held;
155
207
  }
156
- function affectedOf(held) {
208
+ function* affectedOf(held) {
157
209
  const affected = {};
158
210
  for (const entry of held) {
159
211
  if (entry.content !== null)
160
212
  affected[entry.path] = entry.content;
213
+ yield ROW_WEIGHT;
161
214
  }
162
215
  return affected;
163
216
  }
164
- 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, facts: _facts, ...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 unusable();
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 unusable();
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) {
165
261
  const refusal = doorRefusal(body);
166
262
  if (refusal !== null && refusal.code === 'service_mode_write_halted') {
167
263
  return { kind: 'write-halted' };
168
264
  }
169
- if (refusal !== null && refusal.code === 'operation_expired')
170
- return { kind: 'expired' };
171
265
  if (refusal !== null && refusal.code === 'edit_conflict') {
172
266
  const { current, ...fields } = refusal.fields;
173
- const held = material(current, handle) ?? [];
174
- return { kind: 'conflicted', affected: affectedOf(held), code: refusal.code, fields };
267
+ const held = (yield* material(current, handle)) ?? [];
268
+ return {
269
+ kind: 'conflicted',
270
+ affected: yield* affectedOf(held),
271
+ code: refusal.code,
272
+ fields,
273
+ retryable: refusal.retryable,
274
+ };
175
275
  }
176
276
  if (refusal !== null && status === 404) {
177
277
  return scopedRefusal(locator, 'undisclosed', refusal);
178
278
  }
179
279
  const classified = classifyDoor(status, body, locator);
180
- const reset = refusal?.fields.retry_at;
181
- if (refusal?.retryable === true &&
182
- typeof reset === 'string' &&
183
- classified?.kind === 'transport-uncertainty') {
184
- return { kind: 'retryable-refusal', code: refusal.code, fields: refusal.fields, reset };
185
- }
186
- if (classified !== null && classified.kind !== 'scoped-refusal') {
187
- return classified.kind === 'beyond-horizon' ? { kind: 'expired' } : classified;
280
+ const reset = resetOf(refusal);
281
+ if (refusal !== null && reset !== undefined && classified?.kind === 'transport-uncertainty') {
282
+ return {
283
+ kind: 'retryable-refusal',
284
+ code: refusal.code,
285
+ fields: refusal.fields,
286
+ retryable: true,
287
+ reset,
288
+ };
188
289
  }
189
- if (classified !== null && status === 403)
290
+ if (classified !== null && classified.kind !== 'scoped-refusal')
291
+ return classified;
292
+ if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
190
293
  return classified;
191
- if (refusal !== null && status >= 400) {
192
- return { kind: 'rejected', affected: {}, code: refusal.code, fields: refusal.fields };
193
294
  }
194
- if (status !== 200 || typeof body !== 'object' || body === null) {
195
- return { kind: 'transport-uncertainty' };
295
+ if (refusal !== null && status >= 400) {
296
+ return {
297
+ kind: 'rejected',
298
+ affected: {},
299
+ code: refusal.code,
300
+ fields: refusal.fields,
301
+ retryable: refusal.retryable,
302
+ };
196
303
  }
304
+ if (status !== 200)
305
+ return answeredFailure(status, body);
306
+ if (typeof body !== 'object' || body === null)
307
+ return unusable();
197
308
  const held = body;
309
+ if (move !== undefined)
310
+ return yield* movedOutcome(held, move);
198
311
  const at = readPosition(held);
199
312
  if (at === null)
200
- return { kind: 'transport-uncertainty' };
201
- const contents = material(held.contents, handle);
313
+ return unusable();
314
+ const contents = yield* material(held.contents, handle);
202
315
  if (contents === null)
203
- return { kind: 'transport-uncertainty' };
204
- const originals = parseOriginals(held.originals);
205
- if (originals === null)
206
- return { kind: 'transport-uncertainty' };
207
- const documents = {};
208
- const revisions = {};
209
- const removals = [];
210
- for (const entry of contents) {
211
- if (entry.content === null || entry.revision === null) {
212
- removals.push(entry.path);
213
- continue;
214
- }
215
- documents[entry.path] = entry.content;
216
- revisions[entry.path] = entry.revision;
217
- }
218
- return {
219
- kind: 'accepted',
220
- roomVersion: roomVersion(at),
221
- documents,
222
- revisions,
223
- removals: removals.sort(),
224
- originals,
225
- };
316
+ return unusable();
317
+ return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
226
318
  }
227
319
  export function rejectedMapping(mapping) {
228
320
  return {
@@ -230,6 +322,7 @@ export function rejectedMapping(mapping) {
230
322
  affected: {},
231
323
  code: mapping.rule,
232
324
  fields: { path: mapping.path },
325
+ retryable: false,
233
326
  };
234
327
  }
235
328
  export function revisionBody(input) {
@@ -241,48 +334,51 @@ export function revisionBody(input) {
241
334
  }
242
335
  function revisionAuthor(entry) {
243
336
  const user = entry.author_user;
337
+ const userName = entry.author_user_name;
244
338
  const site = entry.author_site;
245
- const name = entry.author_site_name;
246
- if (typeof user === 'string' && site === undefined && name === undefined) {
247
- 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 };
351
+ }
352
+ if (typeof inbox === 'string' && typeof inboxName === 'string') {
353
+ return { kind: 'inbox', id: inbox, name: inboxName };
248
354
  }
249
- if (user === null && typeof site === 'string' && typeof name === 'string') {
250
- return { kind: 'site', id: site, name };
355
+ if (typeof app === 'string' && typeof appName === 'string') {
356
+ return { kind: 'app', id: app, name: appName };
251
357
  }
252
358
  return null;
253
359
  }
254
360
  export function historyOutcome(status, body, locator, request) {
255
361
  const classified = classifyDoor(status, body, locator);
256
- if (classified !== null) {
257
- return classified.kind === 'beyond-horizon' ? { kind: 'transport-uncertainty' } : classified;
258
- }
362
+ if (classified !== null)
363
+ return classified;
259
364
  if (status !== 200 || typeof body !== 'object' || body === null) {
260
- return { kind: 'transport-uncertainty' };
365
+ return unusable();
261
366
  }
262
367
  const held = body;
263
368
  if (!Array.isArray(held.revisions))
264
- return { kind: 'transport-uncertainty' };
369
+ return unusable();
265
370
  const entries = [];
266
371
  for (const entry of held.revisions) {
267
372
  if (typeof entry !== 'object' || entry === null)
268
- return { kind: 'transport-uncertainty' };
373
+ return unusable();
269
374
  entries.push(entry);
270
375
  }
271
- if (request.revision !== undefined) {
272
- const named = entries[0];
376
+ const named = entries[0];
377
+ if (request.revision !== undefined && typeof named?.media_type !== 'string') {
273
378
  if (named === undefined)
274
379
  return { kind: 'no-history' };
275
- if (named.unavailable === true) {
276
- return {
277
- kind: 'scoped-refusal',
278
- locator,
279
- scope: 'content',
280
- code: 'retained_history_unavailable',
281
- fields: { path: request.path, revision: request.revision },
282
- };
283
- }
284
380
  if (typeof named.content !== 'string')
285
- return { kind: 'transport-uncertainty' };
381
+ return unusable();
286
382
  return { kind: 'revision', content: named.content };
287
383
  }
288
384
  if (entries.length === 0)
@@ -293,14 +389,23 @@ export function historyOutcome(status, body, locator, request) {
293
389
  if (typeof entry.revision !== 'string' ||
294
390
  author === null ||
295
391
  typeof entry.created_at !== 'string') {
296
- return { kind: 'transport-uncertainty' };
392
+ return unusable();
297
393
  }
298
- revisions.push({ revision: entry.revision, author, time: entry.created_at });
394
+ const binaryFile = binaryFileOf(entry);
395
+ if (binaryFile === null)
396
+ return unusable();
397
+ revisions.push({
398
+ revision: entry.revision,
399
+ author,
400
+ time: entry.created_at,
401
+ ...(binaryFile === undefined ? {} : { binaryFile }),
402
+ });
299
403
  }
300
404
  const next = held.next_before;
301
405
  return {
302
406
  kind: 'history',
303
407
  revisions,
304
408
  ...(typeof next === 'number' ? { pageToken: String(next) } : {}),
409
+ ...(held.deleted === true ? { deleted: true } : {}),
305
410
  };
306
411
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime-adapter",
3
- "version": "0.1.0-cca5d676bc88e",
3
+ "version": "0.1.0-ccc7c7aecd1ac",
4
4
  "description": "Agents House Adapter for the MD Runtime",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -9,23 +9,27 @@
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
  ".": {
16
16
  "types": "./dist/index.d.ts",
17
- "import": "./dist/index.js"
17
+ "default": "./dist/index.js"
18
18
  },
19
19
  "./package.json": "./package.json"
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-c68e2039f1ca8",
29
- "@agentshouse/mdruntime": "0.1.0-cf6041a06849c"
27
+ "@agentshouse/mdmodel": "0.1.0-ca3c1be3cd1a3",
28
+ "@agentshouse/mdruntime": "0.1.0-c23bcab68bec7"
29
+ },
30
+ "repository": {
31
+ "type": "git",
32
+ "url": "git+https://github.com/agentshouse/core.git",
33
+ "directory": "mdruntime/packages/mdruntime-adapter"
30
34
  }
31
35
  }
package/AGENTS.md DELETED
@@ -1,231 +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
5
- enforcement.
6
-
7
- ## The MD Runtime API
8
-
9
- App code reaches the MD Runtime through the remote client. The surfaces are
10
- Rooms, Query, Search, Observe, Types, Room Draft, Save, History, 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 and the deployment facts 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, a
17
- Room reached for single Documents shows only those Documents, the Types of the
18
- models that govern them and no attachments, and without conversations the
19
- conversation members, the chat draft and the conversation observation hold none.
20
- A change of the reach reaches every open observation as its new value, a query
21
- keeping every unchanged Document the same object.
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
- Each conversation the Provider's conversation list names is held complete in the
30
- browser. `conversation.list()` and `observe('conversations')` answer each with its
31
- Agent's identity and name, its name, created and finished times, last outcome and live
32
- `state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
33
- and `started`, when the running turn began, or `null`.
34
- Observe one with `observe('conversation', id, { limit })`: the view
35
- holds its latest `limit` messages, or all of them, oldest first, its chat
36
- draft, and what the Provider streams for it whether or not anything views it:
37
- the running `turn` with its message parts and its context in use and window, the
38
- open questions, the process state, and the CLI's commands and options. These live
39
- only in memory: the message accepted under the turn's id replaces the running turn,
40
- and none of them is stored or searchable.
41
- `chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
42
- sending it is a Provider Action that needs the Provider reachable and is never
43
- queued.
44
-
45
- Each Room in Rooms lists its `attachments`, the files the Provider holds for it
46
- that its Documents link by the Provider's reference, ordered by `reference`,
47
- each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
48
- `entry`. They are as the Provider last declared them and hold no bytes;
49
- open one through the Provider Action that serves it.
50
-
51
- Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
52
- touch the network.
53
- History and Call go to the Provider through the Adapter. A Call result whose
54
- effect the Provider places in a Room carries `at`, that Room and Room Version;
55
- `reached(room, roomVersion)` answers whether the Room's confirmed state has
56
- reached it, and the MD Runtime keeps refreshing that Room until it has;
57
- `reached(room, roomVersion, path)` answers whether the held confirmed copy of
58
- that document was written at a later Room Version. Each History revision
59
- names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`. Every
60
- member of the
61
- client is asynchronous. Results are detached snapshots. Nothing in this
62
- surface returns the authorization, performs a request the App's code
63
- composes, or exposes the browser store.
64
-
65
- Read the deployment facts with `observe('deployment-facts')`. Interpret the
66
- opaque value using the host's contract.
67
-
68
- The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
69
- ships in no bundle.
70
-
71
- ## Local Query rules
72
-
73
- `query(q)` answers once from local state; `observe('query', q)` holds the whole
74
- result and hears it again only when it changes, keeping every unchanged Document
75
- the same object, so a component can tell what changed by identity. A query is
76
- data:
77
-
78
- - **Filter.** `rooms` names Room locators and defaults to every Room. `types`
79
- names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
80
- directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
81
- - **Fields.** `where` names frontmatter fields, ANDs them, and nests `$and` and
82
- `$or`. A bare value is equality; the operators are `$eq`, `$ne`, `$in`, `$nin`,
83
- `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and `$exists`. Equality on a list
84
- asks whether it contains the value. Missing, null and empty differ:
85
- `$exists: false` keeps a missing field, `null` an explicit null, `''` empty
86
- text and `$size: 0` an empty list. A date compares in calendar order and never
87
- with a date-time. A reference compares by the Room Path it resolves to.
88
- Untyped frontmatter is plain values. There is no text containment or regular
89
- expression.
90
- - **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
91
- reference `field` points to a matching Document of the same Room.
92
- `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
93
- matching Document of the same Room references. Each keeps a Document once.
94
- - **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
95
- `preamble`, `markdown`, `backlinks` and `change`, where `fields` and `sections`
96
- are `'all'` or a list of names. Room and Path always return; a Markdown
97
- Document also returns its MD Type. A non-Markdown Document or binary link
98
- target returns only Room and Path. An unselected part is absent. Select only
99
- what a screen shows: a list that selects the Markdown hears every edit of it.
100
- - **Change.** `change` is `{ author, time }` of the Document's head revision as
101
- the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
102
- or `null` for a write the Provider made itself, and `time` is the Provider's
103
- ISO 8601 change time. It is `null` where the Provider delivered no time, as at
104
- a Site. An unsent edit or move keeps it, an unsent creation has none, and a
105
- saved write takes the Provider's own once it is Accepted and refreshed. A
106
- Room's last change is its Document with the latest `time`.
107
- - **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
108
- with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
109
- `room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
110
- over every match and ordered by `count` or a key. `limit` bounds the Documents
111
- or the groups.
112
- - **Results and errors.** A result carries no Room Version: read freshness from
113
- Rooms and Sync Status. An invalid query fails with `invalid-query`,
114
- `unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
115
- answers an empty result in its place.
116
-
117
- ## Local Search rules
118
-
119
- `search({ text, documents, conversations, limit })` answers once, by words, from
120
- local state, with MiniSearch at its default configuration. There is no observed
121
- search.
122
-
123
- - **What is found.** A Document by its field values, its sections' headings and
124
- text, its preamble and its Path; a message by its text. Frontmatter keys, Room
125
- Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
126
- word forms, typo tolerance or prefix matching.
127
- - **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
128
- `pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
129
- apply before `limit`, which bounds each list; without it every hit returns.
130
- - **Results.** `{ documents, messages }`, each ranked by `score`, which compares
131
- hits of one list of one search. A Document hit names its `room`, `path` and
132
- `type`, a message hit its `conversation` and `identity`, and `matches` maps each
133
- matched word to the parts it matched in: `fields`, `sections`, `preamble` or
134
- `path`, or `text`. A hit carries no position; mark the words in the text you
135
- show. An invalid filter fails with its Local Query error.
136
-
137
- ## Room Draft, Save, and outcome rules
138
-
139
- The MD Runtime owns one Room Draft per Room and Path, shared by every App and
140
- tab. It is durable: it survives reload and navigation. A Room that Discovery
141
- stops listing takes its Room Drafts and its queue with it.
142
- Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
143
- the revision you read, or `null` when there was none, and every part it should
144
- now change: fields, sections and the preamble, or the whole Markdown, a
145
- creation, a move, or a removal. A part new to the Room Draft names its base,
146
- the value you showed when it was opened; the MD Runtime keeps a part's first
147
- base. A binary link target has a Room Draft too, for a move or a removal, with
148
- `null` as its base. A write or a discard from an older revision is refused as `stale` with
149
- the current Room Draft; read it and write again.
150
-
151
- Save takes one Room and the Room Drafts of it to save, each with its revision,
152
- validates locally, and on success appends one Change Batch to that Room's
153
- queue and removes those Room Drafts. It is refused as `stale`, as
154
- `changed-underneath` naming each part whose base no longer matches the visible
155
- state, or by a local validation rule, and then creates nothing and leaves every
156
- Room Draft in place. A directory move or removal is a move or removal part on
157
- each Document and binary link target beneath it, saved together.
158
-
159
- Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
160
- queue, drawn over the confirmed layer, until the confirmed layer reaches the
161
- Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
162
- longer applies over the Room each leave the queue and return as Room Drafts on
163
- the Documents they changed, marked with why: the Provider's structured refusal
164
- code and fields as returned, not known to have applied, or withdrawn locally.
165
- The rest of the queue keeps synchronizing, and Sync Status requires attention
166
- until each returned Room Draft is saved again or discarded. A Change Batch
167
- keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
168
- Pending one, and a returned Room Draft says why it returned. Transport
169
- failure and Provider unavailability keep work Pending and do not infer a
170
- rejection. A refusal the Provider marks retryable stays Pending until the reset
171
- it names; the MD Runtime retries the same Change Batch identity and payload and
172
- never infers an outcome from transport uncertainty. The MD Runtime never
173
- combines, reorders, or rebases.
174
-
175
- `observe('service-mode')` answers the Provider's Service
176
- Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
177
- its Change Batch waits unsent, and the queue is submitted in order once the
178
- Provider reopens writes. An Action is never held: a write the Provider refuses
179
- for the halt returns that refusal to its caller. Show the Provider as read-only
180
- instead of retrying.
181
-
182
- ## The neutrality rule
183
-
184
- No module outside an Adapter package imports, names, or special-cases a
185
- Provider. MD UI and every App reach data only through the client entry.
186
-
187
- ## Content-safety rules
188
-
189
- The Provider authorization belongs to the Runtime host and is never readable
190
- by the App's code. The App's code reaches the network only at the external
191
- origins its manifest declares, empty by default, and the Provider enforces
192
- that set. Every request to the Provider itself goes through the MD Runtime.
193
- Rendered Markdown never executes scripts, renders raw HTML only for the
194
- details and summary elements, and loads images and other resources only from
195
- origins the Provider's policy allows.
196
-
197
- ## Launch promises MD UI keeps
198
-
199
- MD UI uses semantic HTML, is fully operable from a keyboard with visible
200
- focus and labelled controls, and lays out from a 360 pixel wide viewport to
201
- a desktop. Its strings are English only, dates and numbers follow the
202
- browser locale, and content is never translated. Light and dark themes come
203
- from CSS custom properties with the browser's preference as the default and
204
- an App's override respected. What an App Creator's agent adds carries none
205
- of these promises by itself. Reading, querying and searching never wait for
206
- the network. Data lives only in the App Creator's browser and with the Provider.
207
-
208
- ## App code takes the client its host hands it and never constructs a Runtime
209
-
210
- App code takes the client its host hands it: in House,
211
- `connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
212
- client House built into the page. It never constructs a Runtime or a client.
213
- It imports only types from `@agentshouse/mdruntime/client`, does not call
214
- `connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
215
- the host entry, or the Adapter package. Hosts and tests use those entries; the
216
- served App does not.
217
-
218
- A React App may observe and save through `@agentshouse/mdruntime/react`, which
219
- names React as a peer dependency. `useObserve(client, topic, ...input)` takes
220
- the arguments of `observe` and returns the topic's current value, `undefined`
221
- until it arrives, re-rendering on each change; a `null` client observes
222
- nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
223
- `save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
224
- already there, keeping the bases its parts have, or onto a new one, and saves
225
- them together. A refused Save leaves the Room Drafts for the App to save again
226
- or discard; a failure is recorded and rejects.
227
-
228
- ## What an agent must never do
229
-
230
- An agent must never read the authorization, load code from a Room, call the
231
- Provider directly, or rebase a refused Change Batch.
package/dist/gather.d.ts DELETED
@@ -1,3 +0,0 @@
1
- export declare function gathered<A, R>(send: (asks: readonly A[]) => Promise<readonly R[]>): (ask: A) => Promise<R>;
2
- export declare function selections<T>(items: readonly T[], weight: (item: T) => number, limit: number): readonly (readonly T[])[];
3
- //# sourceMappingURL=gather.d.ts.map