@agentshouse/mdruntime-adapter 0.1.0-c29c7d612b2d0 → 0.1.0-c2ae88cedfb65
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/AGENTS.md +275 -275
- package/dist/actions.d.ts +1 -0
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +19 -26
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +170 -48
- package/dist/discovery.d.ts +2 -1
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +5 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/read.d.ts +21 -1
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +78 -4
- package/dist/site.d.ts +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +82 -44
- package/dist/stream.d.ts +3 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +240 -45
- package/dist/transport.d.ts +38 -1
- package/dist/transport.d.ts.map +1 -1
- 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.map +1 -1
- package/dist/write.js +8 -4
- package/package.json +2 -2
package/dist/read.d.ts
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
|
-
import type { BinaryFile, BootstrapPage, RefreshResult } from '@agentshouse/mdruntime';
|
|
1
|
+
import type { AdapterFailure, BinaryFile, BootstrapPage, RefreshResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseMode } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
5
5
|
export type HeadChange = BootstrapPage['changes'][string];
|
|
6
|
+
export declare function identities(revisions: Readonly<Record<string, string>>): {
|
|
7
|
+
fileIds?: Record<string, string>;
|
|
8
|
+
};
|
|
6
9
|
export type HouseManifestFile = {
|
|
7
10
|
path: string;
|
|
8
11
|
revision: string | undefined;
|
|
9
12
|
version: string;
|
|
13
|
+
sha256?: string;
|
|
10
14
|
head?: HeadChange;
|
|
11
15
|
binary?: BinaryFile;
|
|
12
16
|
};
|
|
@@ -19,9 +23,14 @@ export type HouseScope = LogPosition & {
|
|
|
19
23
|
files: readonly HouseManifestFile[];
|
|
20
24
|
contents: readonly HouseContent[];
|
|
21
25
|
};
|
|
26
|
+
export type HouseCut = {
|
|
27
|
+
position: string;
|
|
28
|
+
log_epoch: string;
|
|
29
|
+
};
|
|
22
30
|
export type HouseCursor = {
|
|
23
31
|
room: string;
|
|
24
32
|
path: string | null;
|
|
33
|
+
cut?: HouseCut;
|
|
25
34
|
};
|
|
26
35
|
export type HouseEnvelope = {
|
|
27
36
|
scopes: readonly HouseScope[];
|
|
@@ -51,9 +60,18 @@ export type HouseChange = {
|
|
|
51
60
|
version: string;
|
|
52
61
|
head?: HeadChange;
|
|
53
62
|
};
|
|
63
|
+
export type HousePage = {
|
|
64
|
+
after: string;
|
|
65
|
+
through: string;
|
|
66
|
+
read: number;
|
|
67
|
+
};
|
|
54
68
|
export type HouseView = LogPosition & {
|
|
55
69
|
authority: string;
|
|
56
70
|
changes: readonly HouseChange[];
|
|
71
|
+
next?: HousePage;
|
|
72
|
+
};
|
|
73
|
+
type PageFailure = AdapterFailure | {
|
|
74
|
+
kind: 'beyond-horizon';
|
|
57
75
|
};
|
|
58
76
|
export type HouseEnumeration = {
|
|
59
77
|
authorities: readonly HouseView[];
|
|
@@ -72,6 +90,7 @@ export declare function parseSiteBootstrap(body: unknown): HouseScope | null;
|
|
|
72
90
|
export declare function siteBootstrapNext(body: unknown): string | null;
|
|
73
91
|
export declare function siteBootstrapOffset(body: unknown): number | null;
|
|
74
92
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
|
93
|
+
export declare function wholeView(first: HouseView, more: (page: HousePage) => Promise<HouseView | PageFailure>): Promise<HouseView | PageFailure>;
|
|
75
94
|
export declare function advancedScope(scope: HouseScope, view: HouseView): HouseScope;
|
|
76
95
|
export declare function matchesScope(scope: HouseScope, tracked: TrackedAuthority): boolean;
|
|
77
96
|
export declare function bootstrapOf(scope: HouseScope): BootstrapPage;
|
|
@@ -83,4 +102,5 @@ export type HouseSchema = {
|
|
|
83
102
|
export declare function schemaOf(scope: HouseScope, schema: string): HouseSchema | null;
|
|
84
103
|
export declare function viewOf(enumeration: HouseEnumeration, tracked: TrackedAuthority): HouseView | undefined;
|
|
85
104
|
export declare function refreshFrom(view: HouseView, fromRoomVersion: string): RefreshResult;
|
|
105
|
+
export {};
|
|
86
106
|
//# sourceMappingURL=read.d.ts.map
|
package/dist/read.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,aAAa,EAEb,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,UAAU,EACV,aAAa,EAEb,aAAa,EACd,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAsC,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAEpF,MAAM,MAAM,UAAU,GAAG,aAAa,CAAC,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAI1D,wBAAgB,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,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E,MAAM,GAAG,IAAI,CAAC;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB,CAAC;AAEF,wBAAgB,QAAQ,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAO9E;AAED,wBAAgB,MAAM,CACpB,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE,gBAAgB,GACxB,SAAS,GAAG,SAAS,CAEvB;AAED,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,GAAG,aAAa,CA2BnF"}
|
package/dist/read.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import { readPosition, roomVersion } from './version.js';
|
|
1
|
+
import { DECIMAL, readPosition, roomVersion } from './version.js';
|
|
2
|
+
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
3
|
+
export function identities(revisions) {
|
|
4
|
+
const fileIds = Object.fromEntries(Object.entries(revisions).flatMap(([path, revision]) => {
|
|
5
|
+
const file = REVISION_FILE.exec(revision)?.[1];
|
|
6
|
+
return file === undefined ? [] : [[path, file]];
|
|
7
|
+
}));
|
|
8
|
+
return Object.keys(fileIds).length === 0 ? {} : { fileIds };
|
|
9
|
+
}
|
|
2
10
|
export function authorityRoot(handle) {
|
|
3
11
|
return `/rooms/${handle}`;
|
|
4
12
|
}
|
|
@@ -92,6 +100,7 @@ function parseFile(value, mode) {
|
|
|
92
100
|
path: file.path,
|
|
93
101
|
revision: file.revision,
|
|
94
102
|
version: file.revision,
|
|
103
|
+
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
95
104
|
...headed(head),
|
|
96
105
|
...binaried(binary),
|
|
97
106
|
};
|
|
@@ -132,13 +141,26 @@ function parseScope(value, mode) {
|
|
|
132
141
|
}
|
|
133
142
|
return { anchor: manifest.anchor, ...at, files, contents };
|
|
134
143
|
}
|
|
144
|
+
function parseCut(value) {
|
|
145
|
+
if (value === undefined)
|
|
146
|
+
return undefined;
|
|
147
|
+
if (typeof value !== 'object' || value === null)
|
|
148
|
+
return null;
|
|
149
|
+
const { position, log_epoch: logEpoch } = value;
|
|
150
|
+
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
151
|
+
return null;
|
|
152
|
+
return { position, log_epoch: logEpoch };
|
|
153
|
+
}
|
|
135
154
|
function parseCursor(value) {
|
|
136
155
|
if (typeof value !== 'object' || value === null)
|
|
137
156
|
return null;
|
|
138
|
-
const { room, path } = value;
|
|
157
|
+
const { room, path, cut } = value;
|
|
139
158
|
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
140
159
|
return null;
|
|
141
|
-
|
|
160
|
+
const parsed = parseCut(cut);
|
|
161
|
+
if (parsed === null)
|
|
162
|
+
return null;
|
|
163
|
+
return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
|
|
142
164
|
}
|
|
143
165
|
export function parseEnvelope(body) {
|
|
144
166
|
if (typeof body !== 'object' || body === null)
|
|
@@ -234,10 +256,60 @@ export function parseEnumeration(body, mode) {
|
|
|
234
256
|
return null;
|
|
235
257
|
changes.push(mapped);
|
|
236
258
|
}
|
|
237
|
-
|
|
259
|
+
const next = held.next === undefined ? undefined : readPage(held.next);
|
|
260
|
+
if (next === null)
|
|
261
|
+
return null;
|
|
262
|
+
authorities.push({
|
|
263
|
+
authority: held.authority,
|
|
264
|
+
...at,
|
|
265
|
+
changes,
|
|
266
|
+
...(next === undefined ? {} : { next }),
|
|
267
|
+
});
|
|
238
268
|
}
|
|
239
269
|
return { authorities };
|
|
240
270
|
}
|
|
271
|
+
function readPage(held) {
|
|
272
|
+
if (typeof held !== 'object' || held === null)
|
|
273
|
+
return null;
|
|
274
|
+
const { after, through, read } = held;
|
|
275
|
+
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
276
|
+
return null;
|
|
277
|
+
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
278
|
+
return null;
|
|
279
|
+
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
280
|
+
return null;
|
|
281
|
+
return { after, through, read };
|
|
282
|
+
}
|
|
283
|
+
function advances(asked, next) {
|
|
284
|
+
const moved = BigInt(next.through) - BigInt(asked.through);
|
|
285
|
+
return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
|
|
286
|
+
}
|
|
287
|
+
export async function wholeView(first, more) {
|
|
288
|
+
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
289
|
+
let view = first;
|
|
290
|
+
while (view.next !== undefined) {
|
|
291
|
+
const asked = view.next;
|
|
292
|
+
const page = await more(asked);
|
|
293
|
+
if ('kind' in page)
|
|
294
|
+
return page;
|
|
295
|
+
if (page.position !== asked.through ||
|
|
296
|
+
page.logEpoch !== first.logEpoch ||
|
|
297
|
+
(page.next !== undefined && !advances(asked, page.next))) {
|
|
298
|
+
return { kind: 'transport-uncertainty' };
|
|
299
|
+
}
|
|
300
|
+
for (const change of page.changes) {
|
|
301
|
+
changes.delete(change.path);
|
|
302
|
+
changes.set(change.path, change);
|
|
303
|
+
}
|
|
304
|
+
view = page;
|
|
305
|
+
}
|
|
306
|
+
return {
|
|
307
|
+
authority: first.authority,
|
|
308
|
+
position: view.position,
|
|
309
|
+
logEpoch: first.logEpoch,
|
|
310
|
+
changes: [...changes.values()],
|
|
311
|
+
};
|
|
312
|
+
}
|
|
241
313
|
export function advancedScope(scope, view) {
|
|
242
314
|
const files = new Map(scope.files.map((file) => [file.path, file]));
|
|
243
315
|
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
@@ -289,6 +361,7 @@ export function bootstrapOf(scope) {
|
|
|
289
361
|
roomVersion: roomVersion(scope),
|
|
290
362
|
documents,
|
|
291
363
|
revisions,
|
|
364
|
+
...identities(revisions),
|
|
292
365
|
changes,
|
|
293
366
|
binaryFiles,
|
|
294
367
|
};
|
|
@@ -332,6 +405,7 @@ export function refreshFrom(view, fromRoomVersion) {
|
|
|
332
405
|
roomVersion: roomVersion(view),
|
|
333
406
|
documents,
|
|
334
407
|
revisions,
|
|
408
|
+
...identities(revisions),
|
|
335
409
|
changes,
|
|
336
410
|
binaryFiles,
|
|
337
411
|
removals: removals.sort(),
|
package/dist/site.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { Adapter } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type HouseSiteTransport } from './transport.js';
|
|
3
|
-
export declare function createSiteAdapter(transport: HouseSiteTransport): Adapter;
|
|
3
|
+
export declare function createSiteAdapter(transport: HouseSiteTransport, snapshot?: boolean): Adapter;
|
|
4
4
|
//# sourceMappingURL=site.d.ts.map
|
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,EAUR,MAAM,wBAAwB,CAAC;AA2BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAyCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAwR1F"}
|
package/dist/site.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { actionOutcome, SITE_SUBMIT } from './actions.js';
|
|
2
2
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
3
3
|
import { partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
-
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, siteBootstrapNext, siteBootstrapOffset, viewOf, } from './read.js';
|
|
4
|
+
import { advancedScope, bootstrapOf, parseEnumeration, parseSiteBootstrap, refreshFrom, siteBootstrapNext, siteBootstrapOffset, viewOf, wholeView, } from './read.js';
|
|
5
5
|
import { sha256Hex } from './digest.js';
|
|
6
6
|
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
7
7
|
import { houseNotifications } from './stream.js';
|
|
@@ -9,6 +9,9 @@ import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR
|
|
|
9
9
|
import { houseReferrer } from './referrer.js';
|
|
10
10
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
11
11
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
12
|
+
function unfound() {
|
|
13
|
+
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
14
|
+
}
|
|
12
15
|
function siteRoom(tracked) {
|
|
13
16
|
return {
|
|
14
17
|
name: tracked.handle,
|
|
@@ -23,21 +26,47 @@ function siteRoom(tracked) {
|
|
|
23
26
|
function settled(refused) {
|
|
24
27
|
return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
|
|
25
28
|
}
|
|
26
|
-
export function createSiteAdapter(transport) {
|
|
29
|
+
export function createSiteAdapter(transport, snapshot = false) {
|
|
27
30
|
const notifications = houseNotifications(transport, 'site');
|
|
28
31
|
const tracked = new Map();
|
|
29
32
|
function published(referrer) {
|
|
30
33
|
const named = houseReferrer(referrer, tracked);
|
|
31
34
|
return named === null || !tracked.has(named.locator) ? null : named;
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
function fileRoute(request) {
|
|
37
|
+
const named = published(request.kind === 'path' ? { room: request.locator, path: request.path } : request.referrer);
|
|
38
|
+
if (named === null) {
|
|
39
|
+
return { kind: 'rejected', code: 'referrer_unknown', fields: {}, retryable: false };
|
|
40
|
+
}
|
|
41
|
+
if (request.fileRef === undefined)
|
|
42
|
+
return unfound();
|
|
43
|
+
const { room_ref, path, record } = named.referrer;
|
|
44
|
+
return `${SITE_FILES}${room_ref}/${encodeURIComponent(request.fileRef)}/${path === undefined
|
|
45
|
+
? `${SITE_FILE_RECORD}/${encodeURIComponent(record)}`
|
|
46
|
+
: encodeURIComponent(path)}`;
|
|
47
|
+
}
|
|
48
|
+
async function enumerated(entry, from, page) {
|
|
34
49
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
35
|
-
positions: [
|
|
50
|
+
positions: [
|
|
51
|
+
page === undefined
|
|
52
|
+
? presented(entry.authority, from)
|
|
53
|
+
: {
|
|
54
|
+
...presented(entry.authority, { position: page.after, logEpoch: from.logEpoch }),
|
|
55
|
+
page: { through: page.through, read: page.read },
|
|
56
|
+
},
|
|
57
|
+
],
|
|
36
58
|
});
|
|
37
59
|
const classified = classifyRead(answer.status, answer.body, entry.locator);
|
|
38
60
|
if (classified !== null)
|
|
39
61
|
return classified;
|
|
40
|
-
|
|
62
|
+
const found = parseEnumeration(answer.body, 'site');
|
|
63
|
+
if (found === null)
|
|
64
|
+
return UNCERTAIN;
|
|
65
|
+
return viewOf(found, entry) ?? { kind: 'room-not-readable', locator: entry.locator };
|
|
66
|
+
}
|
|
67
|
+
async function enumeration(entry, from) {
|
|
68
|
+
const first = await enumerated(entry, from);
|
|
69
|
+
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
41
70
|
}
|
|
42
71
|
async function bootstrapPart(entry, after, offset) {
|
|
43
72
|
const query = [
|
|
@@ -96,12 +125,9 @@ export function createSiteAdapter(transport) {
|
|
|
96
125
|
if (after !== null || next !== null || roomVersion(scope) === roomVersion(entry)) {
|
|
97
126
|
return { scope, next };
|
|
98
127
|
}
|
|
99
|
-
const
|
|
100
|
-
if ('kind' in
|
|
101
|
-
return { failure: settled(
|
|
102
|
-
const view = viewOf(found, entry);
|
|
103
|
-
if (view === undefined)
|
|
104
|
-
return { failure: { kind: 'room-not-readable', locator: entry.locator } };
|
|
128
|
+
const view = await enumeration(entry, scope);
|
|
129
|
+
if ('kind' in view)
|
|
130
|
+
return { failure: settled(view) };
|
|
105
131
|
return { scope: advancedScope(scope, view), next: null };
|
|
106
132
|
}
|
|
107
133
|
async function refreshed(entry, fromRoomVersion) {
|
|
@@ -113,12 +139,9 @@ export function createSiteAdapter(transport) {
|
|
|
113
139
|
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
114
140
|
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
115
141
|
}
|
|
116
|
-
const
|
|
117
|
-
if ('kind' in
|
|
118
|
-
return
|
|
119
|
-
const view = viewOf(found, entry);
|
|
120
|
-
if (view === undefined)
|
|
121
|
-
return { kind: 'room-not-readable', locator: entry.locator };
|
|
142
|
+
const view = await enumeration(entry, from);
|
|
143
|
+
if ('kind' in view)
|
|
144
|
+
return view;
|
|
122
145
|
notifications.reach(entry.authority, view);
|
|
123
146
|
const answer = refreshFrom(view, fromRoomVersion);
|
|
124
147
|
if (answer.kind !== 'net-advancement')
|
|
@@ -128,6 +151,7 @@ export function createSiteAdapter(transport) {
|
|
|
128
151
|
}
|
|
129
152
|
return {
|
|
130
153
|
localSaves: true,
|
|
154
|
+
exhaustiveDiscovery: true,
|
|
131
155
|
async authorize() {
|
|
132
156
|
return {};
|
|
133
157
|
},
|
|
@@ -175,6 +199,11 @@ export function createSiteAdapter(transport) {
|
|
|
175
199
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
176
200
|
if (request.pageToken !== undefined)
|
|
177
201
|
return UNCERTAIN;
|
|
202
|
+
if (snapshot) {
|
|
203
|
+
return request.fromRoomVersion === roomVersion(entry)
|
|
204
|
+
? { kind: 'still-current' }
|
|
205
|
+
: { kind: 'beyond-horizon' };
|
|
206
|
+
}
|
|
178
207
|
return refreshed(entry, request.fromRoomVersion);
|
|
179
208
|
},
|
|
180
209
|
async mutate() {
|
|
@@ -184,24 +213,26 @@ export function createSiteAdapter(transport) {
|
|
|
184
213
|
return { kind: 'no-history' };
|
|
185
214
|
},
|
|
186
215
|
async binary(_authorization, request) {
|
|
187
|
-
const
|
|
188
|
-
if (
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
if (
|
|
192
|
-
return
|
|
193
|
-
}
|
|
194
|
-
const { room_ref, path, record } = named.referrer;
|
|
195
|
-
const read = await transport.download(`${SITE_FILES}${room_ref}/${encodeURIComponent(request.fileRef)}/${path === undefined
|
|
196
|
-
? `${SITE_FILE_RECORD}/${encodeURIComponent(record)}`
|
|
197
|
-
: encodeURIComponent(path)}`);
|
|
198
|
-
if (read.status === 404) {
|
|
199
|
-
return { kind: 'rejected', code: 'file_not_found', fields: {}, retryable: false };
|
|
200
|
-
}
|
|
216
|
+
const route = fileRoute(request);
|
|
217
|
+
if (typeof route !== 'string')
|
|
218
|
+
return route;
|
|
219
|
+
const read = await transport.download(route);
|
|
220
|
+
if (read.status === 404)
|
|
221
|
+
return unfound();
|
|
201
222
|
return read.status === 200 && read.blob !== null
|
|
202
223
|
? { kind: 'binary', blob: read.blob }
|
|
203
224
|
: UNCERTAIN;
|
|
204
225
|
},
|
|
226
|
+
async link(_authorization, request) {
|
|
227
|
+
const route = fileRoute(request);
|
|
228
|
+
if (typeof route !== 'string')
|
|
229
|
+
return route;
|
|
230
|
+
return {
|
|
231
|
+
kind: 'link',
|
|
232
|
+
url: route,
|
|
233
|
+
name: request.path.slice(request.path.lastIndexOf('/') + 1),
|
|
234
|
+
};
|
|
235
|
+
},
|
|
205
236
|
referrerScope(referrer) {
|
|
206
237
|
const named = published(referrer);
|
|
207
238
|
if (named === null)
|
|
@@ -228,20 +259,27 @@ export function createSiteAdapter(transport) {
|
|
|
228
259
|
return UNCERTAIN;
|
|
229
260
|
return actionOutcome(await transport.door(SITE_DOOR_SUBMIT, request.input), SITE_SUBMIT);
|
|
230
261
|
},
|
|
231
|
-
roomStream:
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
262
|
+
roomStream: snapshot
|
|
263
|
+
? undefined
|
|
264
|
+
: {
|
|
265
|
+
hold(rooms) {
|
|
266
|
+
notifications.send(rooms.flatMap((room) => {
|
|
267
|
+
const entry = tracked.get(room.locator);
|
|
268
|
+
const at = logPosition(room.roomVersion);
|
|
269
|
+
if (entry === undefined || at === null)
|
|
270
|
+
return [];
|
|
271
|
+
notifications.reach(entry.authority, at);
|
|
272
|
+
return [presented(entry.authority, at)];
|
|
273
|
+
}));
|
|
274
|
+
},
|
|
275
|
+
reopen: notifications.reopen,
|
|
276
|
+
observe: notifications.observe,
|
|
277
|
+
published(locator, roomVersion) {
|
|
278
|
+
const at = logPosition(roomVersion);
|
|
279
|
+
if (at !== null)
|
|
280
|
+
notifications.published(locator, at);
|
|
281
|
+
},
|
|
241
282
|
},
|
|
242
|
-
reopen: notifications.reopen,
|
|
243
|
-
observe: notifications.observe,
|
|
244
|
-
},
|
|
245
283
|
serviceMode: notifications.serviceMode,
|
|
246
284
|
};
|
|
247
285
|
}
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ConversationStream, RefreshPage, RoomStreamEvent, ServiceModeSignal } from '@agentshouse/mdruntime';
|
|
1
|
+
import type { ConversationStream, RefreshPage, RoomStreamEvent, ServiceModeSignal, StreamReceipts } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import type { HouseDoor, HouseHeldRoom, HouseMode, HouseStreamEntry } from './transport.js';
|
|
4
4
|
import { type LogPosition } from './version.js';
|
|
@@ -10,8 +10,9 @@ export type StreamedAdvancement = {
|
|
|
10
10
|
};
|
|
11
11
|
export type HouseNotifications = {
|
|
12
12
|
runtime: string;
|
|
13
|
-
observe(notify: (event: RoomStreamEvent) => void): () => void;
|
|
13
|
+
observe(notify: (event: RoomStreamEvent) => void, receipts: StreamReceipts): () => void;
|
|
14
14
|
send(rooms: readonly HouseHeldRoom[]): void;
|
|
15
|
+
published(locator: string, at: LogPosition): void;
|
|
15
16
|
reopen(): void;
|
|
16
17
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
17
18
|
reach(authority: string, at: LogPosition): void;
|
package/dist/stream.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,kBAAkB,EAElB,WAAW,EACX,eAAe,EAEf,iBAAiB,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGV,kBAAkB,EAElB,WAAW,EACX,eAAe,EAEf,iBAAiB,EACjB,cAAc,EAEf,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,KAAK,EACV,SAAS,EACT,aAAa,EAEb,SAAS,EAET,gBAAgB,EAEjB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AA0C7D,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;AAEvE,MAAM,MAAM,mBAAmB,GAAG;IAChC,IAAI,EAAE,WAAW,CAAC;IAClB,OAAO,EAAE,SAAS,gBAAgB,EAAE,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,EAAE,QAAQ,EAAE,cAAc,GAAG,MAAM,IAAI,CAAC;IACxF,IAAI,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,GAAG,IAAI,CAAC;IAC5C,SAAS,CAAC,OAAO,EAAE,MAAM,EAA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