@agentshouse/mdruntime-adapter 0.1.0-cf22c8563f9f4 → 0.1.0-cf41d9210cb6b
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/actions.d.ts +51 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +123 -214
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +336 -109
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/discovery.d.ts +9 -11
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +55 -36
- package/dist/gather.d.ts +1 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +15 -20
- package/dist/house-model.d.ts +2 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +489 -0
- package/dist/index.d.ts +8 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/model.d.ts +6 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +32 -20
- package/dist/part.d.ts +14 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +90 -0
- package/dist/read.d.ts +74 -20
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +353 -168
- package/dist/refusal.d.ts +2 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +6 -9
- package/dist/room-stream.d.ts +19 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +57 -0
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +125 -0
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +131 -62
- package/dist/stream.d.ts +6 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +366 -44
- package/dist/transport.d.ts +76 -11
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +4 -0
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +18 -9
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +164 -41
- package/package.json +9 -6
- package/AGENTS.md +0 -244
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/write.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
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
5
|
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
@@ -73,6 +74,25 @@ function operationOf(batch, change, handle) {
|
|
|
73
74
|
const operation = created(change, path);
|
|
74
75
|
return operation === null ? { rule: 'type-missing' } : { operation };
|
|
75
76
|
}
|
|
77
|
+
if (change.kind === 'binary') {
|
|
78
|
+
const written = {
|
|
79
|
+
op: 'upload',
|
|
80
|
+
path,
|
|
81
|
+
local_id: change.localId,
|
|
82
|
+
bytes: change.byteLength,
|
|
83
|
+
sha256: change.sha256,
|
|
84
|
+
media_type: change.mediaType,
|
|
85
|
+
};
|
|
86
|
+
const from = departure(batch.changes, batch.changes.indexOf(change));
|
|
87
|
+
if (from === change.path && priorAbsence(batch, change.path) !== undefined)
|
|
88
|
+
return { operation: written };
|
|
89
|
+
const replaced = priorExistence(batch, from);
|
|
90
|
+
if (replaced === undefined)
|
|
91
|
+
return { rule: 'precondition-missing' };
|
|
92
|
+
if (!('base' in replaced))
|
|
93
|
+
return { rule: 'presence-base-unrepresentable' };
|
|
94
|
+
return { operation: { ...written, base: replaced.base } };
|
|
95
|
+
}
|
|
76
96
|
const existence = priorExistence(batch, change.path);
|
|
77
97
|
if (existence === undefined)
|
|
78
98
|
return { rule: 'precondition-missing' };
|
|
@@ -100,6 +120,27 @@ export function houseChanges(batch, handle) {
|
|
|
100
120
|
}
|
|
101
121
|
return { kind: 'changes', changes };
|
|
102
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
|
+
}
|
|
103
144
|
export function operationHead(batch) {
|
|
104
145
|
const writer = batch.writtenBy;
|
|
105
146
|
return writer === undefined
|
|
@@ -109,7 +150,7 @@ export function operationHead(batch) {
|
|
|
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
|
-
]
|
|
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,29 +199,84 @@ 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
|
-
|
|
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) {
|
|
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 === 'expired')
|
|
170
|
-
return
|
|
265
|
+
if (refusal !== null && refusal.code === 'expired') {
|
|
266
|
+
return refusal.fields.restored === true
|
|
267
|
+
? { kind: 'expired', restored: true }
|
|
268
|
+
: { kind: 'expired' };
|
|
269
|
+
}
|
|
171
270
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
172
271
|
const { current, ...fields } = refusal.fields;
|
|
173
|
-
const held = material(current, handle) ?? [];
|
|
174
|
-
return {
|
|
272
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
273
|
+
return {
|
|
274
|
+
kind: 'conflicted',
|
|
275
|
+
affected: yield* affectedOf(held),
|
|
276
|
+
code: refusal.code,
|
|
277
|
+
fields,
|
|
278
|
+
retryable: refusal.retryable,
|
|
279
|
+
};
|
|
175
280
|
}
|
|
176
281
|
if (refusal !== null && status === 404) {
|
|
177
282
|
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
@@ -181,47 +286,41 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
181
286
|
if (refusal?.retryable === true &&
|
|
182
287
|
typeof reset === 'string' &&
|
|
183
288
|
classified?.kind === 'transport-uncertainty') {
|
|
184
|
-
return {
|
|
289
|
+
return {
|
|
290
|
+
kind: 'retryable-refusal',
|
|
291
|
+
code: refusal.code,
|
|
292
|
+
fields: refusal.fields,
|
|
293
|
+
retryable: true,
|
|
294
|
+
reset,
|
|
295
|
+
};
|
|
185
296
|
}
|
|
186
297
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
187
298
|
return classified;
|
|
188
|
-
if (classified !== null && status === 403)
|
|
299
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
189
300
|
return classified;
|
|
301
|
+
}
|
|
190
302
|
if (refusal !== null && status >= 400) {
|
|
191
|
-
return {
|
|
303
|
+
return {
|
|
304
|
+
kind: 'rejected',
|
|
305
|
+
affected: {},
|
|
306
|
+
code: refusal.code,
|
|
307
|
+
fields: refusal.fields,
|
|
308
|
+
retryable: refusal.retryable,
|
|
309
|
+
};
|
|
192
310
|
}
|
|
193
311
|
if (status !== 200 || typeof body !== 'object' || body === null) {
|
|
194
312
|
return { kind: 'transport-uncertainty' };
|
|
195
313
|
}
|
|
196
314
|
const held = body;
|
|
315
|
+
if (move !== undefined)
|
|
316
|
+
return yield* movedOutcome(held, move);
|
|
197
317
|
const at = readPosition(held);
|
|
198
318
|
if (at === null)
|
|
199
319
|
return { kind: 'transport-uncertainty' };
|
|
200
|
-
const contents = material(held.contents, handle);
|
|
320
|
+
const contents = yield* material(held.contents, handle);
|
|
201
321
|
if (contents === null)
|
|
202
322
|
return { kind: 'transport-uncertainty' };
|
|
203
|
-
|
|
204
|
-
if (originals === null)
|
|
205
|
-
return { kind: 'transport-uncertainty' };
|
|
206
|
-
const documents = {};
|
|
207
|
-
const revisions = {};
|
|
208
|
-
const removals = [];
|
|
209
|
-
for (const entry of contents) {
|
|
210
|
-
if (entry.content === null || entry.revision === null) {
|
|
211
|
-
removals.push(entry.path);
|
|
212
|
-
continue;
|
|
213
|
-
}
|
|
214
|
-
documents[entry.path] = entry.content;
|
|
215
|
-
revisions[entry.path] = entry.revision;
|
|
216
|
-
}
|
|
217
|
-
return {
|
|
218
|
-
kind: 'accepted',
|
|
219
|
-
roomVersion: roomVersion(at),
|
|
220
|
-
documents,
|
|
221
|
-
revisions,
|
|
222
|
-
removals: removals.sort(),
|
|
223
|
-
originals,
|
|
224
|
-
};
|
|
323
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
225
324
|
}
|
|
226
325
|
export function rejectedMapping(mapping) {
|
|
227
326
|
return {
|
|
@@ -229,6 +328,7 @@ export function rejectedMapping(mapping) {
|
|
|
229
328
|
affected: {},
|
|
230
329
|
code: mapping.rule,
|
|
231
330
|
fields: { path: mapping.path },
|
|
331
|
+
retryable: false,
|
|
232
332
|
};
|
|
233
333
|
}
|
|
234
334
|
export function revisionBody(input) {
|
|
@@ -241,12 +341,24 @@ export function revisionBody(input) {
|
|
|
241
341
|
function revisionAuthor(entry) {
|
|
242
342
|
const user = entry.author_user;
|
|
243
343
|
const site = entry.author_site;
|
|
244
|
-
const
|
|
245
|
-
|
|
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)
|
|
246
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 };
|
|
247
359
|
}
|
|
248
|
-
if (
|
|
249
|
-
return { kind: '
|
|
360
|
+
if (typeof app === 'string' && typeof appName === 'string') {
|
|
361
|
+
return { kind: 'app', id: app, name: appName };
|
|
250
362
|
}
|
|
251
363
|
return null;
|
|
252
364
|
}
|
|
@@ -274,11 +386,14 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
274
386
|
return {
|
|
275
387
|
kind: 'scoped-refusal',
|
|
276
388
|
locator,
|
|
277
|
-
scope: '
|
|
389
|
+
scope: 'operation',
|
|
278
390
|
code: 'retained_history_unavailable',
|
|
279
391
|
fields: { path: request.path, revision: request.revision },
|
|
392
|
+
retryable: false,
|
|
280
393
|
};
|
|
281
394
|
}
|
|
395
|
+
if (typeof named.media_type === 'string')
|
|
396
|
+
return { kind: 'no-history' };
|
|
282
397
|
if (typeof named.content !== 'string')
|
|
283
398
|
return { kind: 'transport-uncertainty' };
|
|
284
399
|
return { kind: 'revision', content: named.content };
|
|
@@ -293,7 +408,15 @@ export function historyOutcome(status, body, locator, request) {
|
|
|
293
408
|
typeof entry.created_at !== 'string') {
|
|
294
409
|
return { kind: 'transport-uncertainty' };
|
|
295
410
|
}
|
|
296
|
-
|
|
411
|
+
const binaryFile = binaryFileOf(entry);
|
|
412
|
+
if (binaryFile === null)
|
|
413
|
+
return { kind: 'transport-uncertainty' };
|
|
414
|
+
revisions.push({
|
|
415
|
+
revision: entry.revision,
|
|
416
|
+
author,
|
|
417
|
+
time: entry.created_at,
|
|
418
|
+
...(binaryFile === undefined ? {} : { binaryFile }),
|
|
419
|
+
});
|
|
297
420
|
}
|
|
298
421
|
const next = held.next_before;
|
|
299
422
|
return {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agentshouse/mdruntime-adapter",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-cf41d9210cb6b",
|
|
4
4
|
"description": "Agents House Adapter for the MD Runtime",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -9,23 +9,26 @@
|
|
|
9
9
|
"access": "public"
|
|
10
10
|
},
|
|
11
11
|
"engines": {
|
|
12
|
-
"node": ">=24.
|
|
12
|
+
"node": ">=24.22.1"
|
|
13
13
|
},
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
|
-
"
|
|
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/
|
|
29
|
-
|
|
27
|
+
"@agentshouse/mdruntime": "0.1.0-cfac557170cf3"
|
|
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,244 +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,
|
|
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
|
-
Each conversation the Provider's conversation list names is held complete in the
|
|
31
|
-
browser. `conversation.list()` and `observe('conversations')` answer each with its
|
|
32
|
-
Agent's identity and name, its name, created and finished times, last outcome and live
|
|
33
|
-
`state`: `asking` while a question waits, `working` while a turn runs, else `idle`,
|
|
34
|
-
and `started`, when the running turn began, or `null`.
|
|
35
|
-
Observe one with `observe('conversation', id, { limit })`: the view
|
|
36
|
-
holds its latest `limit` messages, or all of them, oldest first, its chat
|
|
37
|
-
draft, and what the Provider streams for it whether or not anything views it:
|
|
38
|
-
the running `turn` with its message parts and its context in use and window, the
|
|
39
|
-
open questions, the process state, and the CLI's commands and options. These live
|
|
40
|
-
only in memory: the message accepted under the turn's id replaces the running turn,
|
|
41
|
-
and none of them is stored or searchable.
|
|
42
|
-
`chatDraft.write` and `chatDraft.discard` keep what the App Creator composes;
|
|
43
|
-
sending it is a Provider Action that needs the Provider reachable and is never
|
|
44
|
-
queued.
|
|
45
|
-
|
|
46
|
-
Each Room in Rooms lists its `attachments`, the files the Provider holds for it
|
|
47
|
-
that its Documents link by the Provider's reference, ordered by `reference`,
|
|
48
|
-
each with `name`, `byteLength`, `mediaType` and the Provider's own entry as
|
|
49
|
-
`entry`. They are as the Provider last declared them and hold no bytes;
|
|
50
|
-
open one through the Provider Action that serves it.
|
|
51
|
-
|
|
52
|
-
Rooms, Query, Search, Observe, Types, Room Draft, Save, and Reached never
|
|
53
|
-
touch the network.
|
|
54
|
-
History and Call go to the Provider through the Adapter. A Call result whose
|
|
55
|
-
effect the Provider places in a Room carries `at`, that Room and Room Version;
|
|
56
|
-
`reached(room, roomVersion)` answers whether the Room's confirmed state has
|
|
57
|
-
reached it, and the MD Runtime keeps refreshing that Room until it has;
|
|
58
|
-
`reached(room, roomVersion, path)` answers whether the held confirmed copy of
|
|
59
|
-
that document was written at a later Room Version. Each History revision
|
|
60
|
-
names its author, `{ kind: 'user', id }` or `{ kind: 'site', id, name }`.
|
|
61
|
-
History of a Path no current document holds answers the removed document's
|
|
62
|
-
revisions with `deleted: true`, newest first; that revision is what a link to
|
|
63
|
-
the Path opens. Every
|
|
64
|
-
member of the
|
|
65
|
-
client is asynchronous. Results are detached snapshots. Nothing in this
|
|
66
|
-
surface returns the authorization, performs a request the App's code
|
|
67
|
-
composes, or exposes the browser store.
|
|
68
|
-
|
|
69
|
-
Read the deployment facts with `observe('deployment-facts')`. Interpret the
|
|
70
|
-
opaque value using the host's contract.
|
|
71
|
-
|
|
72
|
-
The in-memory Adapter at `@agentshouse/mdruntime/memory` is for tests and
|
|
73
|
-
ships in no bundle.
|
|
74
|
-
|
|
75
|
-
## Local Query rules
|
|
76
|
-
|
|
77
|
-
`query(q)` answers once from local state; `observe('query', q)` holds the whole
|
|
78
|
-
result and hears it again only when it changes, keeping every unchanged Document
|
|
79
|
-
the same object, so a component can tell what changed by identity. A query is
|
|
80
|
-
data:
|
|
81
|
-
|
|
82
|
-
- **Filter.** `rooms` names Room locators and defaults to every Room. `types`
|
|
83
|
-
names MD Types, and `any` names untyped Markdown Documents. `pathPrefix` is a
|
|
84
|
-
directory: `notes` keeps `notes/a.md` and not `notes2/a.md`.
|
|
85
|
-
- **Fields.** Every frontmatter value is named by JSON Pointer: `/status`,
|
|
86
|
-
`/shipping/city`, `~1` for a `/` and `~0` for a `~` in a key. A segment that
|
|
87
|
-
meets a list applies to every item and a number names one item. `where` names
|
|
88
|
-
pointers, ANDs them, and nests `$and` and `$or`; a pointer through a list holds
|
|
89
|
-
when any item satisfies it. A bare value is equality; the operators are `$eq`,
|
|
90
|
-
`$ne`, `$in`, `$nin`, `$gt`, `$gte`, `$lt`, `$lte`, `$all`, `$size` and
|
|
91
|
-
`$exists`. Equality on a list asks whether it contains the value. Missing, null and empty differ:
|
|
92
|
-
`$exists: false` keeps a missing field, `null` an explicit null, `''` empty
|
|
93
|
-
text and `$size: 0` an empty list. A date compares in calendar order and never
|
|
94
|
-
with a date-time. A reference compares by the Room Path it resolves to.
|
|
95
|
-
Untyped frontmatter, and a value under `oneOf` or a conditional, is plain
|
|
96
|
-
values. There is no text containment or regular
|
|
97
|
-
expression.
|
|
98
|
-
- **Relations.** `hop: { field, types, where, pathPrefix }` keeps Documents whose
|
|
99
|
-
reference at pointer `field`, at any depth, points to a matching Document of the
|
|
100
|
-
same Room. `backlinks: { field, types, where, pathPrefix }` keeps Documents that a
|
|
101
|
-
matching Document of the same Room references. Each keeps a Document once.
|
|
102
|
-
- **Parts.** A Document query must `select`: `'all'`, or `fields`, `sections`,
|
|
103
|
-
`preamble`, `markdown`, `backlinks` and `change`, where `fields` is `'all'` or a
|
|
104
|
-
list of pointers and `sections` `'all'` or a list of names. Selected pointers
|
|
105
|
-
return the frontmatter holding only them, nested as written. A backlink names
|
|
106
|
-
the referring Path, MD Type and the pointer it came from as `field`. Room and Path always return; a Markdown
|
|
107
|
-
Document also returns its MD Type. A non-Markdown Document or binary link
|
|
108
|
-
target returns only Room and Path. An unselected part is absent. Select only
|
|
109
|
-
what a screen shows: a list that selects the Markdown hears every edit of it.
|
|
110
|
-
- **Change.** `change` is `{ author, time }` of the Document's head revision as
|
|
111
|
-
the Provider last delivered it: `author` is `{ kind: 'user' | 'site', id, name }`
|
|
112
|
-
or `null` for a write the Provider made itself, and `time` is the Provider's
|
|
113
|
-
ISO 8601 change time. It is `null` where the Provider delivered no time, as at
|
|
114
|
-
a Site. An unsent edit or move keeps it, an unsent creation has none, and a
|
|
115
|
-
saved write takes the Provider's own once it is Accepted and refreshed. A
|
|
116
|
-
Room's last change is its Document with the latest `time`.
|
|
117
|
-
- **Order and groups.** `orderBy` sorts by `room`, `path`, `type` or `{ field }`
|
|
118
|
-
with TanStack DB's own options, and ties end with Room, then Path. `groupBy` by
|
|
119
|
-
`room`, `type` or `{ field }` answers `{ groups: [{ key, count }] }`, counted
|
|
120
|
-
over every match and ordered by `count` or a key. A sort or group takes only a
|
|
121
|
-
pointer that holds one value. `limit` bounds the Documents or the groups.
|
|
122
|
-
- **Results and errors.** A result carries no Room Version: read freshness from
|
|
123
|
-
Rooms and Sync Status. An invalid query fails with `invalid-query`,
|
|
124
|
-
`unknown-type`, `unknown-field` or `wrong-kind`, naming where, and never
|
|
125
|
-
answers an empty result in its place.
|
|
126
|
-
|
|
127
|
-
## Local Search rules
|
|
128
|
-
|
|
129
|
-
`search({ text, documents, conversations, limit })` answers once, by words, from
|
|
130
|
-
local state, with MiniSearch at its default configuration. There is no observed
|
|
131
|
-
search.
|
|
132
|
-
|
|
133
|
-
- **What is found.** A Document by its field values, its sections' headings and
|
|
134
|
-
text, its preamble and its Path; a message by its text. Frontmatter keys, Room
|
|
135
|
-
Drafts, chat drafts and a running turn's parts are never found. There are no phrases,
|
|
136
|
-
word forms, typo tolerance or prefix matching.
|
|
137
|
-
- **Narrowing.** `documents` is a Local Query filter: `rooms`, `types`, `where`,
|
|
138
|
-
`pathPrefix`, `hop` and `backlinks`. `conversations` names conversations. Both
|
|
139
|
-
apply before `limit`, which bounds each list; without it every hit returns.
|
|
140
|
-
- **Results.** `{ documents, messages }`, each ranked by `score`, which compares
|
|
141
|
-
hits of one list of one search. A Document hit names its `room`, `path` and
|
|
142
|
-
`type`, a message hit its `conversation` and `identity`, and `matches` maps each
|
|
143
|
-
matched word to the parts it matched in: `fields`, `sections`, `preamble` or
|
|
144
|
-
`path`, or `text`. A hit carries no position; mark the words in the text you
|
|
145
|
-
show. An invalid filter fails with its Local Query error.
|
|
146
|
-
|
|
147
|
-
## Room Draft, Save, and outcome rules
|
|
148
|
-
|
|
149
|
-
The MD Runtime owns one Room Draft per Room and Path, shared by every App and
|
|
150
|
-
tab. It is durable: it survives reload and navigation. A Room that Discovery
|
|
151
|
-
stops listing takes its Room Drafts and its queue with it.
|
|
152
|
-
Write a Room Draft with `roomDraft.write(room, path, revision, parts)`, naming
|
|
153
|
-
the revision you read, or `null` when there was none, and every part it should
|
|
154
|
-
now change: fields, sections and the preamble, or the whole Markdown, a
|
|
155
|
-
creation, a move, or a removal. A part new to the Room Draft names its base,
|
|
156
|
-
the value you showed when it was opened; the MD Runtime keeps a part's first
|
|
157
|
-
base. A binary link target has a Room Draft too, for a move or a removal, with
|
|
158
|
-
`null` as its base. A write or a discard from an older revision is refused as `stale` with
|
|
159
|
-
the current Room Draft; read it and write again.
|
|
160
|
-
|
|
161
|
-
Save takes one Room and the Room Drafts of it to save, each with its revision,
|
|
162
|
-
validates locally, and on success appends one Change Batch to that Room's
|
|
163
|
-
queue and removes those Room Drafts. It is refused as `stale`, as
|
|
164
|
-
`changed-underneath` naming each part whose base no longer matches the visible
|
|
165
|
-
state, or by a local validation rule, and then creates nothing and leaves every
|
|
166
|
-
Room Draft in place. A directory move or removal is a move or removal part on
|
|
167
|
-
each Document and binary link target beneath it, saved together.
|
|
168
|
-
|
|
169
|
-
Outcomes follow the Provider's answer. An Accepted Change Batch stays in the
|
|
170
|
-
queue, drawn over the confirmed layer, until the confirmed layer reaches the
|
|
171
|
-
Room Version it was accepted at, and then leaves it. Conflicted and Rejected, an expired operation, and a change that no
|
|
172
|
-
longer applies over the Room each leave the queue and return as Room Drafts on
|
|
173
|
-
the Documents they changed, marked with why: the Provider's structured refusal
|
|
174
|
-
code and fields as returned, not known to have applied, or withdrawn locally.
|
|
175
|
-
The rest of the queue keeps synchronizing, and Sync Status requires attention
|
|
176
|
-
until each returned Room Draft is saved again or discarded. A Change Batch
|
|
177
|
-
keeps no outcome once it leaves the queue; `observe('queue', room)` shows each
|
|
178
|
-
Pending one, and a returned Room Draft says why it returned. Transport
|
|
179
|
-
failure and Provider unavailability keep work Pending and do not infer a
|
|
180
|
-
rejection. A refusal the Provider marks retryable stays Pending until the reset
|
|
181
|
-
it names; the MD Runtime retries the same Change Batch identity and payload and
|
|
182
|
-
never infers an outcome from transport uncertainty. The MD Runtime never
|
|
183
|
-
combines, reorders, or rebases.
|
|
184
|
-
|
|
185
|
-
`observe('service-mode')` answers the Provider's Service
|
|
186
|
-
Mode, `open` or `write-halted`. While writes are halted, Save still succeeds,
|
|
187
|
-
its Change Batch waits unsent, and the queue is submitted in order once the
|
|
188
|
-
Provider reopens writes. An Action is never held: a write the Provider refuses
|
|
189
|
-
for the halt returns that refusal to its caller. Show the Provider as read-only
|
|
190
|
-
instead of retrying.
|
|
191
|
-
|
|
192
|
-
## The neutrality rule
|
|
193
|
-
|
|
194
|
-
No module outside an Adapter package imports, names, or special-cases a
|
|
195
|
-
Provider. MD UI and every App reach data only through the client entry.
|
|
196
|
-
|
|
197
|
-
## Content-safety rules
|
|
198
|
-
|
|
199
|
-
The Provider authorization belongs to the Runtime host and is never readable
|
|
200
|
-
by the App's code. The App's code reaches the network only at the external
|
|
201
|
-
origins its manifest declares, empty by default, and the Provider enforces
|
|
202
|
-
that set. Every request to the Provider itself goes through the MD Runtime.
|
|
203
|
-
Rendered Markdown never executes scripts, renders raw HTML only for the
|
|
204
|
-
details and summary elements, and loads images and other resources only from
|
|
205
|
-
origins the Provider's policy allows.
|
|
206
|
-
|
|
207
|
-
## Launch promises MD UI keeps
|
|
208
|
-
|
|
209
|
-
MD UI uses semantic HTML, is fully operable from a keyboard with visible
|
|
210
|
-
focus and labelled controls, and lays out from a 360 pixel wide viewport to
|
|
211
|
-
a desktop. Its strings are English only, dates and numbers follow the
|
|
212
|
-
browser locale, and content is never translated. Light and dark themes come
|
|
213
|
-
from CSS custom properties with the browser's preference as the default and
|
|
214
|
-
an App's override respected. What an App Creator's agent adds carries none
|
|
215
|
-
of these promises by itself. Reading, querying and searching never wait for
|
|
216
|
-
the network. Data lives only in the App Creator's browser and with the Provider.
|
|
217
|
-
|
|
218
|
-
## App code takes the client its host hands it and never constructs a Runtime
|
|
219
|
-
|
|
220
|
-
App code takes the client its host hands it: in House,
|
|
221
|
-
`connectHouseBridge().runtime` from `@agentshouse/app-bridge` resolves to the
|
|
222
|
-
client House built into the page. It never constructs a Runtime or a client.
|
|
223
|
-
It imports only types from `@agentshouse/mdruntime/client`, does not call
|
|
224
|
-
`connectMdRuntime` or `serveMdRuntime`, and does not import the package main,
|
|
225
|
-
the host entry, or the Adapter package. Hosts and tests use those entries; the
|
|
226
|
-
served App does not.
|
|
227
|
-
|
|
228
|
-
A React App may observe and save through `@agentshouse/mdruntime/react`, which
|
|
229
|
-
names React as a peer dependency. `useObserve(client, topic, ...input)` takes
|
|
230
|
-
the arguments of `observe` and returns the topic's current value, `undefined`
|
|
231
|
-
until it arrives, re-rendering on each change; a `null` client observes
|
|
232
|
-
nothing. `useSave(client)` returns `busy`, the last `outcome` or `failure`, and
|
|
233
|
-
`save(room, roomDrafts)`, which writes each Path's parts onto the Room Draft
|
|
234
|
-
already there, keeping the bases its parts have, or onto a new one, and saves
|
|
235
|
-
them together. A refused Save leaves the Room Drafts for the App to save again
|
|
236
|
-
or discard; a failure is recorded and rejects. `saveRoomDrafts(client, room,
|
|
237
|
-
roomDrafts)` is that save outside a component. A react-admin or Refine App
|
|
238
|
-
reads and writes its Rooms through the data providers of
|
|
239
|
-
`@agentshouse/mdruntime-families`.
|
|
240
|
-
|
|
241
|
-
## What an agent must never do
|
|
242
|
-
|
|
243
|
-
An agent must never read the authorization, load code from a Room, call the
|
|
244
|
-
Provider directly, or rebase a refused Change Batch.
|
package/dist/links.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { HeldRoom, MutationResult, RoomAttachment } from '@agentshouse/mdruntime';
|
|
2
|
-
import type { HouseScope, HouseView } from './read.js';
|
|
3
|
-
import type { StreamedAdvancement } from './stream.js';
|
|
4
|
-
export type RoomLinks = {
|
|
5
|
-
roomVersion: string;
|
|
6
|
-
handed: ReadonlyMap<string, RoomAttachment>;
|
|
7
|
-
paths: ReadonlyMap<string, ReadonlySet<string>>;
|
|
8
|
-
revisions: ReadonlyMap<string, string>;
|
|
9
|
-
};
|
|
10
|
-
export declare function scopeLinks(scope: HouseScope): RoomLinks;
|
|
11
|
-
export declare function heldLinks(held: HeldRoom): RoomLinks;
|
|
12
|
-
export declare function acceptedLinks(held: RoomLinks, accepted: Extract<MutationResult, {
|
|
13
|
-
kind: 'accepted';
|
|
14
|
-
}>, roomVersion: string, originals: readonly RoomAttachment[]): {
|
|
15
|
-
links: RoomLinks;
|
|
16
|
-
attachments?: readonly RoomAttachment[];
|
|
17
|
-
};
|
|
18
|
-
export declare function enumeratedLinks(view: HouseView, earlier: RoomLinks | undefined): RoomLinks;
|
|
19
|
-
export declare function streamedLinks(held: RoomLinks, advanced: StreamedAdvancement): RoomLinks | null;
|
|
20
|
-
//# sourceMappingURL=links.d.ts.map
|
package/dist/links.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"links.d.ts","sourceRoot":"","sources":["../src/links.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACvF,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACvD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAOvD,MAAM,MAAM,SAAS,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC5C,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC,CAAC;IAChD,SAAS,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACxC,CAAC;AAcF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAWvD;AAOD,wBAAgB,SAAS,CAAC,IAAI,EAAE,QAAQ,GAAG,SAAS,CAOnD;AAED,wBAAgB,aAAa,CAC3B,IAAI,EAAE,SAAS,EACf,QAAQ,EAAE,OAAO,CAAC,cAAc,EAAE;IAAE,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC,EACvD,WAAW,EAAE,MAAM,EACnB,SAAS,EAAE,SAAS,cAAc,EAAE,GACnC;IAAE,KAAK,EAAE,SAAS,CAAC;IAAC,WAAW,CAAC,EAAE,SAAS,cAAc,EAAE,CAAA;CAAE,CA2B/D;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,SAAS,GAAG,SAAS,GAAG,SAAS,CAgB1F;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,mBAAmB,GAAG,SAAS,GAAG,IAAI,CAoB9F"}
|