@agentshouse/mdruntime-adapter 0.1.0-c84b58736cfc7 → 0.1.0-c85fd6db0c262
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 +3 -56
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +1 -288
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +128 -326
- 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 +12 -12
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +44 -51
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +91 -0
- package/dist/house-model.d.ts +955 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +521 -0
- package/dist/index.d.ts +9 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/model.d.ts +5 -2
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +10 -29
- package/dist/part.d.ts +12 -13
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +66 -61
- package/dist/read.d.ts +15 -57
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +99 -249
- package/dist/refusal.d.ts +0 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +0 -5
- 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 +2 -1
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +62 -3
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +75 -157
- package/dist/stream.d.ts +13 -14
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +160 -423
- package/dist/transport.d.ts +46 -36
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +53 -11
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +26 -15
- package/dist/write.d.ts +4 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +10 -2
- package/package.json +8 -4
- package/AGENTS.md +0 -317
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -35
package/dist/read.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { patching, ROW_WEIGHT,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { paced, patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { gunzipped } from './part.js';
|
|
3
|
+
import { readPosition, roomVersion } from './version.js';
|
|
4
4
|
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
5
5
|
function fileOf(revision) {
|
|
6
6
|
return REVISION_FILE.exec(revision)?.[1];
|
|
@@ -98,10 +98,10 @@ export function parseFileAddress(body) {
|
|
|
98
98
|
function changeAuthor(value) {
|
|
99
99
|
if (typeof value !== 'object' || value === null)
|
|
100
100
|
return null;
|
|
101
|
-
const { user, site, inbox, name } = value;
|
|
101
|
+
const { user, site, inbox, app, name } = value;
|
|
102
102
|
if (typeof name !== 'string')
|
|
103
103
|
return null;
|
|
104
|
-
const named = [user, site, inbox].filter((id) => id !== undefined);
|
|
104
|
+
const named = [user, site, inbox, app].filter((id) => id !== undefined);
|
|
105
105
|
if (named.length !== 1)
|
|
106
106
|
return null;
|
|
107
107
|
if (typeof user === 'string')
|
|
@@ -110,6 +110,8 @@ function changeAuthor(value) {
|
|
|
110
110
|
return { kind: 'site', id: site, name };
|
|
111
111
|
if (typeof inbox === 'string')
|
|
112
112
|
return { kind: 'inbox', id: inbox, name };
|
|
113
|
+
if (typeof app === 'string')
|
|
114
|
+
return { kind: 'app', id: app, name };
|
|
113
115
|
return null;
|
|
114
116
|
}
|
|
115
117
|
export function headChange(held) {
|
|
@@ -168,13 +170,29 @@ function parseFile(value, mode) {
|
|
|
168
170
|
...binaried(binary),
|
|
169
171
|
};
|
|
170
172
|
}
|
|
171
|
-
function
|
|
173
|
+
function parseModels(value, mode) {
|
|
174
|
+
if (!Array.isArray(value))
|
|
175
|
+
return null;
|
|
176
|
+
const files = [];
|
|
177
|
+
const contents = [];
|
|
178
|
+
for (const entry of value) {
|
|
179
|
+
const file = parseFile(entry, mode);
|
|
180
|
+
const { content } = entry;
|
|
181
|
+
if (file === null || typeof content !== 'string')
|
|
182
|
+
return null;
|
|
183
|
+
files.push(file);
|
|
184
|
+
contents.push({ path: file.path, content });
|
|
185
|
+
}
|
|
186
|
+
return { files, contents };
|
|
187
|
+
}
|
|
188
|
+
function parseRoomHead(value, mode) {
|
|
172
189
|
if (typeof value !== 'object' || value === null)
|
|
173
190
|
return null;
|
|
174
191
|
const held = value;
|
|
175
192
|
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
176
193
|
return null;
|
|
177
|
-
|
|
194
|
+
const models = parseModels(held.models, mode);
|
|
195
|
+
if (models === null)
|
|
178
196
|
return null;
|
|
179
197
|
const manifest = held.manifest;
|
|
180
198
|
if (manifest.scope !== 'room')
|
|
@@ -184,44 +202,22 @@ function parseRoomParts(value) {
|
|
|
184
202
|
return null;
|
|
185
203
|
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
186
204
|
return null;
|
|
187
|
-
|
|
188
|
-
for (const entry of held.parts) {
|
|
189
|
-
const part = parsePart(entry);
|
|
190
|
-
if (part === null)
|
|
191
|
-
return null;
|
|
192
|
-
parts.push(part);
|
|
193
|
-
}
|
|
194
|
-
return { anchor: manifest.anchor, ...at, parts };
|
|
205
|
+
return { anchor: manifest.anchor, ...at, models };
|
|
195
206
|
}
|
|
196
|
-
export function
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (room === null)
|
|
205
|
-
return null;
|
|
206
|
-
rooms.push(room);
|
|
207
|
+
export async function roomHead(payload, mode) {
|
|
208
|
+
let text = '';
|
|
209
|
+
try {
|
|
210
|
+
for await (const chunk of gunzipped(payload))
|
|
211
|
+
text += chunk;
|
|
212
|
+
return text.endsWith('\n') && text.indexOf('\n') === text.length - 1
|
|
213
|
+
? parseRoomHead(JSON.parse(text), mode)
|
|
214
|
+
: null;
|
|
207
215
|
}
|
|
208
|
-
|
|
209
|
-
return { rooms };
|
|
210
|
-
const next = body.next;
|
|
211
|
-
if (typeof next !== 'object' || next === null || typeof next.room !== 'string')
|
|
216
|
+
catch {
|
|
212
217
|
return null;
|
|
213
|
-
|
|
214
|
-
}
|
|
215
|
-
export function parseSiteParted(body) {
|
|
216
|
-
return parseRoomParts(body);
|
|
217
|
-
}
|
|
218
|
-
export function partInventory(room) {
|
|
219
|
-
return {
|
|
220
|
-
parts: room.parts.length,
|
|
221
|
-
bytes: room.parts.reduce((sum, part) => sum + part.bytes, 0),
|
|
222
|
-
};
|
|
218
|
+
}
|
|
223
219
|
}
|
|
224
|
-
export function manifested(room,
|
|
220
|
+
export function manifested(room, pageToken, models) {
|
|
225
221
|
return {
|
|
226
222
|
kind: 'bootstrap',
|
|
227
223
|
roomVersion: roomVersion(room),
|
|
@@ -229,10 +225,13 @@ export function manifested(room, inventory, pageToken) {
|
|
|
229
225
|
revisions: {},
|
|
230
226
|
changes: {},
|
|
231
227
|
binaryFiles: {},
|
|
232
|
-
inventory,
|
|
233
228
|
pageToken,
|
|
229
|
+
...(models === undefined ? {} : { models }),
|
|
234
230
|
};
|
|
235
231
|
}
|
|
232
|
+
export function modelScope(room) {
|
|
233
|
+
return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
|
|
234
|
+
}
|
|
236
235
|
export function emptyScope(room) {
|
|
237
236
|
return {
|
|
238
237
|
anchor: room.anchor,
|
|
@@ -242,193 +241,75 @@ export function emptyScope(room) {
|
|
|
242
241
|
contents: [],
|
|
243
242
|
};
|
|
244
243
|
}
|
|
245
|
-
function
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
const end = text.indexOf('\n', start);
|
|
252
|
-
if (end === -1)
|
|
253
|
-
return null;
|
|
254
|
-
let entry;
|
|
255
|
-
try {
|
|
256
|
-
entry = JSON.parse(text.slice(start, end));
|
|
257
|
-
}
|
|
258
|
-
catch {
|
|
259
|
-
return null;
|
|
260
|
-
}
|
|
261
|
-
start = end + 1;
|
|
262
|
-
if (folderLine(entry)) {
|
|
263
|
-
folders.push(entry.folder);
|
|
264
|
-
yield ROW_WEIGHT;
|
|
265
|
-
continue;
|
|
266
|
-
}
|
|
267
|
-
const file = parseFile(entry, mode);
|
|
268
|
-
if (file === null)
|
|
269
|
-
return null;
|
|
270
|
-
files.push(file);
|
|
271
|
-
const { content } = entry;
|
|
272
|
-
if (typeof content === 'string')
|
|
273
|
-
contents.push({ path: file.path, content });
|
|
274
|
-
else if (content !== undefined)
|
|
275
|
-
return null;
|
|
276
|
-
yield ROW_WEIGHT;
|
|
244
|
+
function partLine(line, mode, read) {
|
|
245
|
+
if (read.ended)
|
|
246
|
+
return false;
|
|
247
|
+
let entry;
|
|
248
|
+
try {
|
|
249
|
+
entry = JSON.parse(line);
|
|
277
250
|
}
|
|
278
|
-
|
|
279
|
-
}
|
|
280
|
-
function folderLine(entry) {
|
|
281
|
-
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
251
|
+
catch {
|
|
282
252
|
return false;
|
|
283
|
-
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
284
|
-
}
|
|
285
|
-
export async function housePart(room, frame, listed, mode) {
|
|
286
|
-
const payload = await checkedPayload(frame, listed);
|
|
287
|
-
if (payload === null)
|
|
288
|
-
return null;
|
|
289
|
-
const text = await gunzipped(payload);
|
|
290
|
-
const read = text === null ? null : await stepped(partLines(text, mode));
|
|
291
|
-
return read === null ? { kind: 'transport-uncertainty' } : { ...emptyScope(room), ...read };
|
|
292
|
-
}
|
|
293
|
-
function folderChange(value) {
|
|
294
|
-
if (typeof value !== 'object' || value === null)
|
|
295
|
-
return null;
|
|
296
|
-
const { path, folder, removed, ...rest } = value;
|
|
297
|
-
return typeof path === 'string' &&
|
|
298
|
-
folder === true &&
|
|
299
|
-
(removed === undefined || removed === true) &&
|
|
300
|
-
Object.keys(rest).length === 0
|
|
301
|
-
? { path, removed: removed === true }
|
|
302
|
-
: null;
|
|
303
|
-
}
|
|
304
|
-
function parseChange(value, mode) {
|
|
305
|
-
if (typeof value !== 'object' || value === null)
|
|
306
|
-
return null;
|
|
307
|
-
const held = value;
|
|
308
|
-
if (typeof held.path !== 'string')
|
|
309
|
-
return null;
|
|
310
|
-
if (held.removed === true)
|
|
311
|
-
return { path: held.path, removed: true };
|
|
312
|
-
const head = headChange(held);
|
|
313
|
-
const binary = binaryFileOf(held);
|
|
314
|
-
if (head === null || binary === null)
|
|
315
|
-
return null;
|
|
316
|
-
if (binary !== undefined) {
|
|
317
|
-
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
318
|
-
return null;
|
|
319
|
-
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
320
|
-
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
321
253
|
}
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
return {
|
|
326
|
-
path: held.path,
|
|
327
|
-
content: held.content,
|
|
328
|
-
revision: undefined,
|
|
329
|
-
version: held.sha256,
|
|
330
|
-
...headed(head),
|
|
331
|
-
};
|
|
254
|
+
if (endLine(entry)) {
|
|
255
|
+
read.ended = true;
|
|
256
|
+
return true;
|
|
332
257
|
}
|
|
333
|
-
if (
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
content: held.content,
|
|
337
|
-
revision: held.revision,
|
|
338
|
-
version: held.revision,
|
|
339
|
-
...headed(head),
|
|
340
|
-
};
|
|
258
|
+
if (folderLine(entry)) {
|
|
259
|
+
read.folders.push(entry.folder);
|
|
260
|
+
return true;
|
|
341
261
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
if (
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const
|
|
363
|
-
if (
|
|
364
|
-
|
|
365
|
-
continue;
|
|
366
|
-
}
|
|
367
|
-
const mapped = parseChange(change, mode);
|
|
368
|
-
if (mapped === null)
|
|
262
|
+
const file = parseFile(entry, mode);
|
|
263
|
+
if (file === null)
|
|
264
|
+
return false;
|
|
265
|
+
read.files.push(file);
|
|
266
|
+
const { content } = entry;
|
|
267
|
+
if (typeof content === 'string')
|
|
268
|
+
read.contents.push({ path: file.path, content });
|
|
269
|
+
else if (content !== undefined)
|
|
270
|
+
return false;
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
async function partRead(chunks, mode) {
|
|
274
|
+
const read = { files: [], contents: [], folders: [], ended: false };
|
|
275
|
+
const pace = paced();
|
|
276
|
+
const unfinished = [];
|
|
277
|
+
for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
|
|
278
|
+
const text = chunk.value;
|
|
279
|
+
let start = 0;
|
|
280
|
+
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
281
|
+
const piece = text.slice(start, end);
|
|
282
|
+
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
283
|
+
if (!partLine(line, mode, read)) {
|
|
284
|
+
await chunks.cancel();
|
|
369
285
|
return null;
|
|
370
|
-
|
|
286
|
+
}
|
|
287
|
+
start = end + 1;
|
|
288
|
+
const due = pace(line.length + ROW_WEIGHT);
|
|
289
|
+
if (due instanceof Promise)
|
|
290
|
+
await due;
|
|
371
291
|
}
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
return null;
|
|
375
|
-
authorities.push({
|
|
376
|
-
authority: held.authority,
|
|
377
|
-
...at,
|
|
378
|
-
changes,
|
|
379
|
-
...(folders.length === 0 ? {} : { folders }),
|
|
380
|
-
...(next === undefined ? {} : { next }),
|
|
381
|
-
});
|
|
292
|
+
if (start < text.length)
|
|
293
|
+
unfinished.push(text.slice(start));
|
|
382
294
|
}
|
|
383
|
-
return
|
|
295
|
+
return unfinished.length === 0 ? read : null;
|
|
384
296
|
}
|
|
385
|
-
function
|
|
386
|
-
if (typeof
|
|
387
|
-
return
|
|
388
|
-
|
|
389
|
-
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
390
|
-
return null;
|
|
391
|
-
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
392
|
-
return null;
|
|
393
|
-
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
394
|
-
return null;
|
|
395
|
-
return { after, through, read };
|
|
297
|
+
function endLine(entry) {
|
|
298
|
+
if (typeof entry !== 'object' || entry === null || !('end' in entry))
|
|
299
|
+
return false;
|
|
300
|
+
return entry.end === true && Object.keys(entry).length === 1;
|
|
396
301
|
}
|
|
397
|
-
function
|
|
398
|
-
|
|
399
|
-
|
|
302
|
+
function folderLine(entry) {
|
|
303
|
+
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
304
|
+
return false;
|
|
305
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
400
306
|
}
|
|
401
|
-
export async function
|
|
402
|
-
const
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
const page = await more(asked);
|
|
408
|
-
if ('kind' in page)
|
|
409
|
-
return page;
|
|
410
|
-
if (page.position !== asked.through ||
|
|
411
|
-
page.logEpoch !== first.logEpoch ||
|
|
412
|
-
(page.next !== undefined && !advances(asked, page.next))) {
|
|
413
|
-
return { kind: 'transport-uncertainty' };
|
|
414
|
-
}
|
|
415
|
-
for (const change of page.changes) {
|
|
416
|
-
changes.delete(change.path);
|
|
417
|
-
changes.set(change.path, change);
|
|
418
|
-
}
|
|
419
|
-
for (const folder of page.folders ?? []) {
|
|
420
|
-
folders.delete(folder.path);
|
|
421
|
-
folders.set(folder.path, folder);
|
|
422
|
-
}
|
|
423
|
-
view = page;
|
|
424
|
-
}
|
|
425
|
-
return {
|
|
426
|
-
authority: first.authority,
|
|
427
|
-
position: view.position,
|
|
428
|
-
logEpoch: first.logEpoch,
|
|
429
|
-
changes: [...changes.values()],
|
|
430
|
-
...(folders.size === 0 ? {} : { folders: [...folders.values()] }),
|
|
431
|
-
};
|
|
307
|
+
export async function housePart(room, payload, mode) {
|
|
308
|
+
const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
|
|
309
|
+
if (read === null)
|
|
310
|
+
return { kind: 'transport-uncertainty' };
|
|
311
|
+
const { ended, ...scope } = read;
|
|
312
|
+
return { scope: { ...emptyScope(room), ...scope }, ended };
|
|
432
313
|
}
|
|
433
314
|
export function* bootstrapping(scope) {
|
|
434
315
|
const contents = new Map();
|
|
@@ -463,34 +344,3 @@ export function schemaOf(scope, schema) {
|
|
|
463
344
|
? null
|
|
464
345
|
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
465
346
|
}
|
|
466
|
-
export function viewOf(enumeration, tracked) {
|
|
467
|
-
return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
|
|
468
|
-
}
|
|
469
|
-
function* refreshing(view, fromRoomVersion) {
|
|
470
|
-
if (roomVersion(view) === fromRoomVersion)
|
|
471
|
-
return { kind: 'still-current' };
|
|
472
|
-
const answer = answering();
|
|
473
|
-
for (const change of view.changes) {
|
|
474
|
-
yield ROW_WEIGHT;
|
|
475
|
-
if ('removed' in change) {
|
|
476
|
-
answer.removals.add(change.path);
|
|
477
|
-
continue;
|
|
478
|
-
}
|
|
479
|
-
if ('content' in change)
|
|
480
|
-
answer.documents.set(change.path, change.content);
|
|
481
|
-
else
|
|
482
|
-
answer.binaryFiles.set(change.path, change.binary);
|
|
483
|
-
if (change.head !== undefined)
|
|
484
|
-
answer.changes.set(change.path, change.head);
|
|
485
|
-
if (change.revision !== undefined)
|
|
486
|
-
revised(answer, change.path, change.revision);
|
|
487
|
-
}
|
|
488
|
-
for (const folder of view.folders ?? []) {
|
|
489
|
-
yield ROW_WEIGHT;
|
|
490
|
-
folded(answer, folder.path, folder.removed);
|
|
491
|
-
}
|
|
492
|
-
return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
|
|
493
|
-
}
|
|
494
|
-
export async function refreshFrom(view, fromRoomVersion) {
|
|
495
|
-
return stepped(refreshing(view, fromRoomVersion));
|
|
496
|
-
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -2,8 +2,5 @@ import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } f
|
|
|
2
2
|
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
3
|
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
4
4
|
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
5
|
-
export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
6
|
-
kind: 'beyond-horizon';
|
|
7
|
-
} | null;
|
|
8
5
|
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
9
6
|
//# sourceMappingURL=refusal.d.ts.map
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAqBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACd,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAqBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAQrF"}
|
package/dist/refusal.js
CHANGED
|
@@ -39,11 +39,6 @@ export function classifyDoor(status, body, locator) {
|
|
|
39
39
|
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
40
40
|
return failure;
|
|
41
41
|
}
|
|
42
|
-
export function classifyRead(status, body, locator) {
|
|
43
|
-
if (doorRefusal(body)?.code === 'expired')
|
|
44
|
-
return { kind: 'beyond-horizon' };
|
|
45
|
-
return classifyDoor(status, body, locator);
|
|
46
|
-
}
|
|
47
42
|
export function discoveryFailure(status, body) {
|
|
48
43
|
const failure = doorFailure(status, body);
|
|
49
44
|
if (failure === null)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BootstrapResult, RoomModels } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseScope } from './read.js';
|
|
4
|
+
import type { HouseMode } from './transport.js';
|
|
5
|
+
export type StreamedPart = {
|
|
6
|
+
readonly scope: HouseScope;
|
|
7
|
+
readonly first: boolean;
|
|
8
|
+
readonly ended: boolean;
|
|
9
|
+
readonly models: RoomModels | undefined;
|
|
10
|
+
readonly pageToken: string | undefined;
|
|
11
|
+
readonly bytes: number;
|
|
12
|
+
};
|
|
13
|
+
export declare function roomStreams(mode: HouseMode): {
|
|
14
|
+
head: (entry: TrackedAuthority, room: ReadableStream<Uint8Array>, arriving: ((bytes: number) => void) | undefined, signal: AbortSignal | undefined) => Promise<BootstrapResult>;
|
|
15
|
+
part: (entry: TrackedAuthority, token: string) => Promise<StreamedPart | Exclude<BootstrapResult, {
|
|
16
|
+
kind: 'bootstrap';
|
|
17
|
+
}>>;
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=room-stream.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-stream.d.ts","sourceRoot":"","sources":["../src/room-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAuD,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAYhD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS;kBAKhC,gBAAgB,QACjB,cAAc,CAAC,UAAU,CAAC,YACtB,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,UACvC,WAAW,GAAG,SAAS,KAC9B,OAAO,CAAC,eAAe,CAAC;kBAelB,gBAAgB,SAChB,MAAM,KACZ,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;EAkC3E"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { manifestedModels, partModels } from './model.js';
|
|
2
|
+
import { roomFrames } from './part.js';
|
|
3
|
+
import { housePart, manifested, roomHead } from './read.js';
|
|
4
|
+
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
5
|
+
export function roomStreams(mode) {
|
|
6
|
+
const open = new Map();
|
|
7
|
+
let opened = 0;
|
|
8
|
+
async function head(entry, room, arriving, signal) {
|
|
9
|
+
const frames = roomFrames(room, arriving, signal);
|
|
10
|
+
const first = await frames();
|
|
11
|
+
if (first.kind !== 'frame')
|
|
12
|
+
return UNCERTAIN;
|
|
13
|
+
const held = await roomHead(first.payload, mode);
|
|
14
|
+
if (held === null || held.anchor !== entry.authority)
|
|
15
|
+
return UNCERTAIN;
|
|
16
|
+
const { models, seen } = await manifestedModels(held, entry);
|
|
17
|
+
opened += 1;
|
|
18
|
+
const id = String(opened);
|
|
19
|
+
open.set(id, { entry, head: held, frames, next: 1, seen });
|
|
20
|
+
signal?.addEventListener('abort', () => open.delete(id), { once: true });
|
|
21
|
+
return { ...manifested(held, `${id}:1`, models), bytes: first.bytes };
|
|
22
|
+
}
|
|
23
|
+
async function part(entry, token) {
|
|
24
|
+
const [id = '', at = ''] = token.split(':');
|
|
25
|
+
const room = open.get(id);
|
|
26
|
+
if (room === undefined || room.entry.locator !== entry.locator || String(room.next) !== at)
|
|
27
|
+
return UNCERTAIN;
|
|
28
|
+
const frame = await room.frames();
|
|
29
|
+
if (frame.kind !== 'frame') {
|
|
30
|
+
open.delete(id);
|
|
31
|
+
return UNCERTAIN;
|
|
32
|
+
}
|
|
33
|
+
const read = await housePart(room.head, frame.payload, mode);
|
|
34
|
+
if ('kind' in read) {
|
|
35
|
+
open.delete(id);
|
|
36
|
+
return read;
|
|
37
|
+
}
|
|
38
|
+
const { scope, ended } = read;
|
|
39
|
+
const first = room.next === 1;
|
|
40
|
+
room.next += 1;
|
|
41
|
+
room.seen = [
|
|
42
|
+
...room.seen,
|
|
43
|
+
...(scope.files.some((file) => file.path === entry.schema) ? [entry.schema] : []),
|
|
44
|
+
];
|
|
45
|
+
if (ended)
|
|
46
|
+
open.delete(id);
|
|
47
|
+
return {
|
|
48
|
+
scope,
|
|
49
|
+
first,
|
|
50
|
+
ended,
|
|
51
|
+
models: await partModels(scope, entry, new Set(room.seen), ended),
|
|
52
|
+
pageToken: ended ? undefined : `${id}:${room.next}`,
|
|
53
|
+
bytes: frame.bytes,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return { head, part };
|
|
57
|
+
}
|
package/dist/room-types.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'whatsapp', 'messenger', 'instagram'];
|
|
1
|
+
export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'telegram-business', 'whatsapp', 'messenger', 'instagram', 'viber', 'tiktok'];
|
|
2
2
|
export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
|
|
3
3
|
export declare const INBOX_CHAT_TYPE = "inbox-chat";
|
|
4
4
|
export declare const INBOX_MESSAGE_TYPE = "inbox-message";
|
|
5
|
+
export declare const HOUSE_NAMEABLE_ROOM_TYPES: string[];
|
|
5
6
|
export declare const HOUSE_ROOM_TYPES: string;
|
|
6
7
|
//# sourceMappingURL=room-types.d.ts.map
|
package/dist/room-types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,eAAe,eAAe,CAAC;AAE5C,eAAO,MAAM,kBAAkB,kBAAkB,CAAC;AAElD,eAAO,MAAM,yBAAyB,UAAwC,CAAC;AAyB/E,eAAO,MAAM,gBAAgB,QA6FjB,CAAC"}
|
package/dist/room-types.js
CHANGED
|
@@ -1,6 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { APP_REFERENCE_PATTERN } from './app-reference.js';
|
|
2
|
+
import { HOUSE_MODEL_TYPES } from './house-model.js';
|
|
3
|
+
export const INBOX_CHANNEL_KINDS = [
|
|
4
|
+
'telegram-bot',
|
|
5
|
+
'telegram-business',
|
|
6
|
+
'whatsapp',
|
|
7
|
+
'messenger',
|
|
8
|
+
'instagram',
|
|
9
|
+
'viber',
|
|
10
|
+
'tiktok',
|
|
11
|
+
];
|
|
2
12
|
export const INBOX_CHAT_TYPE = 'inbox-chat';
|
|
3
13
|
export const INBOX_MESSAGE_TYPE = 'inbox-message';
|
|
14
|
+
export const HOUSE_NAMEABLE_ROOM_TYPES = [INBOX_CHAT_TYPE, INBOX_MESSAGE_TYPE];
|
|
15
|
+
const WAYFINDING_MAP_TYPE = 'wayfinding-map';
|
|
16
|
+
const WAYFINDING_TICKET_TYPE = 'wayfinding-ticket';
|
|
17
|
+
const WAYFINDING_MAP_SECTIONS = [
|
|
18
|
+
'Destination',
|
|
19
|
+
'Notes',
|
|
20
|
+
'Decisions so far',
|
|
21
|
+
'Not yet specified',
|
|
22
|
+
'Out of scope',
|
|
23
|
+
];
|
|
4
24
|
const IDENTITY = "{ type: string, pattern: '^\\S+$' }";
|
|
5
25
|
const AGENT = [' agent: { type: string, format: uuid }', ' name: { type: string }'];
|
|
6
26
|
const ASSIGNEE = [
|
|
@@ -27,7 +47,6 @@ export const HOUSE_ROOM_TYPES = [
|
|
|
27
47
|
' type: object',
|
|
28
48
|
' properties:',
|
|
29
49
|
...AGENT,
|
|
30
|
-
' conversation: { type: string, format: uuid }',
|
|
31
50
|
' required: [inbox, channel, chat, customer]',
|
|
32
51
|
`${INBOX_MESSAGE_TYPE}:`,
|
|
33
52
|
' properties:',
|
|
@@ -41,6 +60,7 @@ export const HOUSE_ROOM_TYPES = [
|
|
|
41
60
|
` channel_message: ${IDENTITY}`,
|
|
42
61
|
' state: { enum: [sending, sent, failed] }',
|
|
43
62
|
' reason: { type: string }',
|
|
63
|
+
' labelled: { const: true }',
|
|
44
64
|
' reactions:',
|
|
45
65
|
' type: array',
|
|
46
66
|
' items:',
|
|
@@ -59,8 +79,47 @@ export const HOUSE_ROOM_TYPES = [
|
|
|
59
79
|
' assignee:',
|
|
60
80
|
...ASSIGNEE,
|
|
61
81
|
' sent_outside: { const: true }',
|
|
82
|
+
' template:',
|
|
83
|
+
' type: object',
|
|
84
|
+
' properties:',
|
|
85
|
+
' name: { type: string, minLength: 1 }',
|
|
86
|
+
' language: { type: string, minLength: 1 }',
|
|
87
|
+
' required: [name, language]',
|
|
88
|
+
' values:',
|
|
89
|
+
' type: object',
|
|
90
|
+
' additionalProperties: { type: string }',
|
|
91
|
+
' withheld: { const: true }',
|
|
62
92
|
' required: [direction]',
|
|
63
93
|
' if: { properties: { direction: { const: in } } }',
|
|
64
94
|
' then: { required: [sent_at] }',
|
|
65
|
-
|
|
95
|
+
`${WAYFINDING_MAP_TYPE}:`,
|
|
96
|
+
' properties:',
|
|
97
|
+
' title: { type: string }',
|
|
98
|
+
' required: [title]',
|
|
99
|
+
' sections:',
|
|
100
|
+
...WAYFINDING_MAP_SECTIONS.map((name) => ` ${name}: { kind: text, required: true }`),
|
|
101
|
+
`${WAYFINDING_TICKET_TYPE}:`,
|
|
102
|
+
' properties:',
|
|
103
|
+
' title: { type: string }',
|
|
104
|
+
' kind: { enum: [research, prototype, grilling, task] }',
|
|
105
|
+
' status: { enum: [open, in-progress, done, out-of-scope] }',
|
|
106
|
+
` map: { type: string, reference: ${WAYFINDING_MAP_TYPE} }`,
|
|
107
|
+
` blocked_by: { type: array, items: { type: string, reference: ${WAYFINDING_TICKET_TYPE} } }`,
|
|
108
|
+
' assignee:',
|
|
109
|
+
...ASSIGNEE,
|
|
110
|
+
' conversation: { type: string, format: uuid }',
|
|
111
|
+
` app: { type: string, pattern: '${APP_REFERENCE_PATTERN.source}' }`,
|
|
112
|
+
' required: [title, kind, status, map, blocked_by]',
|
|
113
|
+
' sections:',
|
|
114
|
+
' Question: { kind: text }',
|
|
115
|
+
' Answer: { kind: text }',
|
|
116
|
+
' allOf:',
|
|
117
|
+
' - if: { properties: { status: { enum: [in-progress, done, out-of-scope] } }, required: [status] }',
|
|
118
|
+
' then: { required: [assignee] }',
|
|
119
|
+
' else: { properties: { assignee: false } }',
|
|
120
|
+
' - if: { properties: { assignee: { required: [agent] } }, required: [assignee] }',
|
|
121
|
+
' else: { properties: { conversation: false } }',
|
|
122
|
+
' - if: { properties: { status: { enum: [done, out-of-scope] } }, required: [status] }',
|
|
123
|
+
' then: { sections: { Answer: { kind: text, required: true } } }',
|
|
124
|
+
HOUSE_MODEL_TYPES,
|
|
66
125
|
].join('\n');
|
package/dist/site.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AAehC,OAAO,EAKL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuBxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAkK1F"}
|