@agentshouse/mdruntime-adapter 0.1.0-c6eb3c1455065 → 0.1.0-c707f9bb54aaa
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 +3 -3
- package/dist/actions.d.ts +6 -73
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -325
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +213 -436
- package/dist/authored-path.d.ts +65 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +164 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +1 -2
- package/dist/digest.d.ts.map +1 -1
- package/dist/digest.js +1 -1
- package/dist/discovery.d.ts +44 -19
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +239 -72
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +85 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -2
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -6
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +31 -48
- package/dist/read.d.ts +30 -63
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +142 -330
- package/dist/refusal.d.ts +6 -5
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +27 -11
- package/dist/room-query.d.ts +4 -0
- package/dist/room-query.d.ts.map +1 -0
- package/dist/room-query.js +51 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/check.d.ts +17 -0
- package/dist/session-content/index.d.ts +6 -0
- package/dist/session-content/parts.d.ts +30 -0
- package/dist/session-content/state.d.ts +59 -0
- package/dist/session-content/turn.d.ts +137 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +115 -190
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +15 -15
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +240 -416
- package/dist/transport.d.ts +88 -49
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +91 -11
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +17 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +106 -0
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +6 -3
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +47 -67
- package/package.json +9 -4
- package/AGENTS.md +0 -304
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -35
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -45
- package/dist/part.d.ts +0 -13
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -80
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -33
- package/dist/room-types.d.ts +0 -6
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -30
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export declare const GENERATED_PROVENANCE = "_provenance";
|
|
2
|
+
export declare const GENERATED_REVISIONS = "_revisions";
|
|
3
|
+
export declare const RESERVED_DERIVED = "_derived";
|
|
4
|
+
export declare const WHOLE_ESCAPED_NAMES: readonly string[];
|
|
5
|
+
export declare const LOCAL_COPY_MANIFEST = ".house";
|
|
6
|
+
export declare const LOCAL_COPY_ROOT_NAMES: readonly string[];
|
|
7
|
+
export declare const AUTHORED_NAME_MAX_BYTES = 255;
|
|
8
|
+
export declare const AUTHORED_PATH_MAX_BYTES = 768;
|
|
9
|
+
export declare const AUTHORED_NAME_RULE: {
|
|
10
|
+
readonly refusedCharacters: '/\\:*?"<>|';
|
|
11
|
+
readonly controlCharacters: 'Cc';
|
|
12
|
+
readonly refusedEnds: ' .';
|
|
13
|
+
readonly refusedStart: '-';
|
|
14
|
+
readonly gitNames: readonly ['.git', 'git~1'];
|
|
15
|
+
readonly windowsNames: readonly ["CON", "PRN", "AUX", "NUL", ...string[]];
|
|
16
|
+
readonly generatedNames: readonly ["_provenance", "_revisions", "_derived"];
|
|
17
|
+
readonly nameMaxBytes: 255;
|
|
18
|
+
readonly pathMaxBytes: 768;
|
|
19
|
+
};
|
|
20
|
+
export type NameRefusal = {
|
|
21
|
+
readonly rule: 'unicode';
|
|
22
|
+
} | {
|
|
23
|
+
readonly rule: 'character';
|
|
24
|
+
readonly character: string;
|
|
25
|
+
} | {
|
|
26
|
+
readonly rule: 'empty';
|
|
27
|
+
} | {
|
|
28
|
+
readonly rule: 'dots';
|
|
29
|
+
} | {
|
|
30
|
+
readonly rule: 'end';
|
|
31
|
+
readonly character: string;
|
|
32
|
+
} | {
|
|
33
|
+
readonly rule: 'git';
|
|
34
|
+
} | {
|
|
35
|
+
readonly rule: 'windows';
|
|
36
|
+
readonly reserved: string;
|
|
37
|
+
} | {
|
|
38
|
+
readonly rule: 'name_bytes';
|
|
39
|
+
readonly bytes: number;
|
|
40
|
+
} | {
|
|
41
|
+
readonly rule: 'start';
|
|
42
|
+
} | {
|
|
43
|
+
readonly rule: 'generated';
|
|
44
|
+
} | {
|
|
45
|
+
readonly rule: 'nfc';
|
|
46
|
+
};
|
|
47
|
+
export type PathRefusal = (NameRefusal & {
|
|
48
|
+
readonly name: string;
|
|
49
|
+
}) | {
|
|
50
|
+
readonly rule: 'root';
|
|
51
|
+
readonly name: string;
|
|
52
|
+
} | {
|
|
53
|
+
readonly rule: 'path_bytes';
|
|
54
|
+
readonly bytes: number;
|
|
55
|
+
};
|
|
56
|
+
export declare function utf8Bytes(text: string): number;
|
|
57
|
+
export declare function nameRefusal(name: string): NameRefusal | null;
|
|
58
|
+
export declare function pathRefusal(path: string): PathRefusal | null;
|
|
59
|
+
export declare function admittedPath(path: string): boolean;
|
|
60
|
+
export declare function sameName(left: string, right: string): boolean;
|
|
61
|
+
export declare function nameParts(name: string): {
|
|
62
|
+
readonly stem: string;
|
|
63
|
+
readonly extension: string;
|
|
64
|
+
};
|
|
65
|
+
export declare function fittedName(name: string, count?: number, tail?: string): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authored-path.d.ts","sourceRoot":"","sources":["../src/authored-path.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAElD,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,eAAO,MAAM,gBAAgB,aAAa,CAAC;AAE3C,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAMhD,CAAC;AAEF,eAAO,MAAM,mBAAmB,WAAW,CAAC;AAE5C,eAAO,MAAM,qBAAqB,EAAE,SAAS,MAAM,EAIlD,CAAC;AAEF,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAE3C,eAAO,MAAM,uBAAuB,MAAM,CAAC;AAI3C,eAAO,MAAM,kBAAkB;aAC7B,iBAAiB,EAAE,YAAY;aAC/B,iBAAiB,EAAE,IAAI;aACvB,WAAW,EAAE,IAAI;aACjB,YAAY,EAAE,GAAG;aACjB,QAAQ,YAAG,MAAM,EAAE,OAAO;aAC1B,YAAY;aAUZ,cAAc;aACd,YAAY;aACZ,YAAY;CACJ,CAAC;AAEX,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1D;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,E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,wBAAgB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAK7F;AAWD,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,SAAI,EAAE,IAAI,SAAK,GAAG,MAAM,CAUrE"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import { APP_PREFERENCES_HOME, APP_REFERENCE_PATTERN, foldedName } from '@agentshouse/mdmodel';
|
|
2
|
+
export const GENERATED_PROVENANCE = '_provenance';
|
|
3
|
+
export const GENERATED_REVISIONS = '_revisions';
|
|
4
|
+
export const RESERVED_DERIVED = '_derived';
|
|
5
|
+
export const WHOLE_ESCAPED_NAMES = [
|
|
6
|
+
'.',
|
|
7
|
+
'..',
|
|
8
|
+
GENERATED_PROVENANCE,
|
|
9
|
+
GENERATED_REVISIONS,
|
|
10
|
+
RESERVED_DERIVED,
|
|
11
|
+
];
|
|
12
|
+
export const LOCAL_COPY_MANIFEST = '.house';
|
|
13
|
+
export const LOCAL_COPY_ROOT_NAMES = [
|
|
14
|
+
'.gitignore',
|
|
15
|
+
'.ignore',
|
|
16
|
+
LOCAL_COPY_MANIFEST,
|
|
17
|
+
];
|
|
18
|
+
export const AUTHORED_NAME_MAX_BYTES = 255;
|
|
19
|
+
export const AUTHORED_PATH_MAX_BYTES = 768;
|
|
20
|
+
const FITTED_STEM = 'file';
|
|
21
|
+
export const AUTHORED_NAME_RULE = {
|
|
22
|
+
refusedCharacters: '/\\:*?"<>|',
|
|
23
|
+
controlCharacters: 'Cc',
|
|
24
|
+
refusedEnds: ' .',
|
|
25
|
+
refusedStart: '-',
|
|
26
|
+
gitNames: ['.git', 'git~1'],
|
|
27
|
+
windowsNames: [
|
|
28
|
+
'CON',
|
|
29
|
+
'PRN',
|
|
30
|
+
'AUX',
|
|
31
|
+
'NUL',
|
|
32
|
+
...['1', '2', '3', '4', '5', '6', '7', '8', '9', '¹', '²', '³'].flatMap((digit) => [
|
|
33
|
+
`COM${digit}`,
|
|
34
|
+
`LPT${digit}`,
|
|
35
|
+
]),
|
|
36
|
+
],
|
|
37
|
+
generatedNames: [GENERATED_PROVENANCE, GENERATED_REVISIONS, RESERVED_DERIVED],
|
|
38
|
+
nameMaxBytes: AUTHORED_NAME_MAX_BYTES,
|
|
39
|
+
pathMaxBytes: AUTHORED_PATH_MAX_BYTES,
|
|
40
|
+
};
|
|
41
|
+
const LONE_SURROGATE = /\p{Cs}/u;
|
|
42
|
+
const LONE_SURROGATES = /\p{Cs}/gu;
|
|
43
|
+
const CONTROL = /\p{Cc}/u;
|
|
44
|
+
const MAC_IGNORED = /[\u200C-\u200F\u202A-\u202E\u206A-\u206F\uFEFF]/gu;
|
|
45
|
+
const FOLDED_GIT_NAMES = new Set(AUTHORED_NAME_RULE.gitNames.map(foldedName));
|
|
46
|
+
const FOLDED_WINDOWS_NAMES = new Set(AUTHORED_NAME_RULE.windowsNames.map(foldedName));
|
|
47
|
+
const FOLDED_GENERATED_NAMES = new Set(AUTHORED_NAME_RULE.generatedNames.map(foldedName));
|
|
48
|
+
const FOLDED_ROOT_NAMES = new Set(LOCAL_COPY_ROOT_NAMES.map(foldedName));
|
|
49
|
+
export function utf8Bytes(text) {
|
|
50
|
+
let bytes = 0;
|
|
51
|
+
for (const point of text) {
|
|
52
|
+
const code = point.codePointAt(0);
|
|
53
|
+
bytes += code < 0x80 ? 1 : code < 0x800 ? 2 : code < 0x10000 ? 3 : 4;
|
|
54
|
+
}
|
|
55
|
+
return bytes;
|
|
56
|
+
}
|
|
57
|
+
function refusedCharacter(point) {
|
|
58
|
+
return AUTHORED_NAME_RULE.refusedCharacters.includes(point) || CONTROL.test(point);
|
|
59
|
+
}
|
|
60
|
+
function windowsName(name) {
|
|
61
|
+
const dot = name.indexOf('.');
|
|
62
|
+
const base = dot < 0 ? name : name.slice(0, dot);
|
|
63
|
+
return FOLDED_WINDOWS_NAMES.has(foldedName(base)) ? base : null;
|
|
64
|
+
}
|
|
65
|
+
export function nameRefusal(name) {
|
|
66
|
+
if (LONE_SURROGATE.test(name))
|
|
67
|
+
return { rule: 'unicode' };
|
|
68
|
+
for (const point of name)
|
|
69
|
+
if (refusedCharacter(point))
|
|
70
|
+
return { rule: 'character', character: point };
|
|
71
|
+
if (name === '')
|
|
72
|
+
return { rule: 'empty' };
|
|
73
|
+
if (name === '.' || name === '..')
|
|
74
|
+
return { rule: 'dots' };
|
|
75
|
+
const last = name.at(-1);
|
|
76
|
+
if (AUTHORED_NAME_RULE.refusedEnds.includes(last))
|
|
77
|
+
return { rule: 'end', character: last };
|
|
78
|
+
if (FOLDED_GIT_NAMES.has(foldedName(name.replace(MAC_IGNORED, ''))))
|
|
79
|
+
return { rule: 'git' };
|
|
80
|
+
const reserved = windowsName(name);
|
|
81
|
+
if (reserved !== null)
|
|
82
|
+
return { rule: 'windows', reserved };
|
|
83
|
+
const bytes = utf8Bytes(name);
|
|
84
|
+
if (bytes > AUTHORED_NAME_MAX_BYTES)
|
|
85
|
+
return { rule: 'name_bytes', bytes };
|
|
86
|
+
if (name.startsWith(AUTHORED_NAME_RULE.refusedStart))
|
|
87
|
+
return { rule: 'start' };
|
|
88
|
+
if (FOLDED_GENERATED_NAMES.has(foldedName(name)))
|
|
89
|
+
return { rule: 'generated' };
|
|
90
|
+
if (name.normalize('NFC') !== name)
|
|
91
|
+
return { rule: 'nfc' };
|
|
92
|
+
return null;
|
|
93
|
+
}
|
|
94
|
+
function appPreferences(path) {
|
|
95
|
+
return (path.endsWith('.md') &&
|
|
96
|
+
APP_REFERENCE_PATTERN.test(path.slice(APP_PREFERENCES_HOME.length + 1, -3)));
|
|
97
|
+
}
|
|
98
|
+
export function pathRefusal(path) {
|
|
99
|
+
const names = path.split('/');
|
|
100
|
+
const [root] = names;
|
|
101
|
+
if (FOLDED_ROOT_NAMES.has(foldedName(root)))
|
|
102
|
+
return { rule: 'root', name: root };
|
|
103
|
+
for (const name of names) {
|
|
104
|
+
const refused = nameRefusal(name);
|
|
105
|
+
if (refused !== null)
|
|
106
|
+
return { ...refused, name };
|
|
107
|
+
}
|
|
108
|
+
const bytes = utf8Bytes(path);
|
|
109
|
+
return bytes > AUTHORED_PATH_MAX_BYTES ? { rule: 'path_bytes', bytes } : null;
|
|
110
|
+
}
|
|
111
|
+
export function admittedPath(path) {
|
|
112
|
+
return (pathRefusal(path) === null &&
|
|
113
|
+
(!path.startsWith(`${APP_PREFERENCES_HOME}/`) || appPreferences(path)));
|
|
114
|
+
}
|
|
115
|
+
export function sameName(left, right) {
|
|
116
|
+
return foldedName(left) === foldedName(right);
|
|
117
|
+
}
|
|
118
|
+
function cutToBytes(text, bytes) {
|
|
119
|
+
let kept = '';
|
|
120
|
+
let used = 0;
|
|
121
|
+
for (const point of text) {
|
|
122
|
+
used += utf8Bytes(point);
|
|
123
|
+
if (used > bytes)
|
|
124
|
+
break;
|
|
125
|
+
kept += point;
|
|
126
|
+
}
|
|
127
|
+
return kept;
|
|
128
|
+
}
|
|
129
|
+
function trimmedEnd(text) {
|
|
130
|
+
let end = text.length;
|
|
131
|
+
while (end > 0 && AUTHORED_NAME_RULE.refusedEnds.includes(text[end - 1]))
|
|
132
|
+
end -= 1;
|
|
133
|
+
return text.slice(0, end);
|
|
134
|
+
}
|
|
135
|
+
function trimmedStart(text) {
|
|
136
|
+
let start = 0;
|
|
137
|
+
while (start < text.length && text[start] === AUTHORED_NAME_RULE.refusedStart)
|
|
138
|
+
start += 1;
|
|
139
|
+
return text.slice(start);
|
|
140
|
+
}
|
|
141
|
+
export function nameParts(name) {
|
|
142
|
+
const dot = name.lastIndexOf('.');
|
|
143
|
+
return dot <= 0
|
|
144
|
+
? { stem: name, extension: '' }
|
|
145
|
+
: { stem: name.slice(0, dot), extension: name.slice(dot) };
|
|
146
|
+
}
|
|
147
|
+
function fitted(stem, extension, tail, count) {
|
|
148
|
+
const suffix = count > 1 ? `-${count}` : '';
|
|
149
|
+
const room = AUTHORED_NAME_MAX_BYTES - utf8Bytes(suffix);
|
|
150
|
+
const whole = utf8Bytes(`${extension}${tail}`) < room;
|
|
151
|
+
const kept = whole ? `${extension}${tail}` : tail;
|
|
152
|
+
const cut = cutToBytes(whole ? stem : `${stem}${extension}`, room - utf8Bytes(kept));
|
|
153
|
+
return `${suffix === '' && kept === '' ? trimmedEnd(cut) : cut}${suffix}${kept}`;
|
|
154
|
+
}
|
|
155
|
+
export function fittedName(name, count = 1, tail = '') {
|
|
156
|
+
let replaced = '';
|
|
157
|
+
for (const point of name.replace(LONE_SURROGATES, '\uFFFD').normalize('NFC'))
|
|
158
|
+
replaced += refusedCharacter(point) ? '-' : point;
|
|
159
|
+
const { stem: typed, extension } = nameParts(trimmedEnd(replaced));
|
|
160
|
+
const stem = trimmedStart(typed);
|
|
161
|
+
const named = stem !== '' && nameRefusal(fitted(stem, extension, tail, 1)) === null ? stem : FITTED_STEM;
|
|
162
|
+
const counted = fitted(named, extension, tail, count);
|
|
163
|
+
return nameRefusal(counted) === null ? counted : fitted(FITTED_STEM, extension, tail, count);
|
|
164
|
+
}
|
package/dist/chunks.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type AdapterFailure, type BootstrapPart, type BootstrapResult } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseModels, type HouseScope } from './read.js';
|
|
4
|
+
import { type HouseDoor, type HouseMode } from './transport.js';
|
|
5
|
+
import { type LogPosition } from './version.js';
|
|
6
|
+
export type ChunkAddress = {
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly bytes: number;
|
|
9
|
+
};
|
|
10
|
+
export type ChunkedRoom = LogPosition & {
|
|
11
|
+
readonly anchor: string;
|
|
12
|
+
readonly mode: HouseMode;
|
|
13
|
+
readonly chunks: ReadonlyMap<string, ChunkAddress>;
|
|
14
|
+
readonly parts: readonly BootstrapPart[];
|
|
15
|
+
readonly names: ReadonlyMap<string, string>;
|
|
16
|
+
readonly models: HouseModels;
|
|
17
|
+
};
|
|
18
|
+
export type Listed = ChunkedRoom | {
|
|
19
|
+
readonly kind: 'not-ready';
|
|
20
|
+
} | AdapterFailure;
|
|
21
|
+
type Answered = {
|
|
22
|
+
readonly status: number;
|
|
23
|
+
readonly body: unknown;
|
|
24
|
+
};
|
|
25
|
+
export declare function partId(logEpoch: string, hash: string): string;
|
|
26
|
+
export declare function siteChunkList(answer: Answered, locator: string): Listed;
|
|
27
|
+
export declare function chunkedHead(listed: ChunkedRoom, entry: TrackedAuthority): Promise<BootstrapResult>;
|
|
28
|
+
export declare function chunkPart(body: ReadableStream<Uint8Array> | null, room: ChunkedRoom, id: string, arriving: ((bytes: number) => void) | undefined): Promise<BootstrapResult>;
|
|
29
|
+
export declare function chunkLister(transport: HouseDoor, most: () => number, tracked: (locator: string) => TrackedAuthority | undefined): {
|
|
30
|
+
askAll: (entries: readonly TrackedAuthority[]) => void;
|
|
31
|
+
list: (entry: TrackedAuthority) => Promise<Listed>;
|
|
32
|
+
renew(entry: TrackedAuthority, installing: readonly TrackedAuthority[]): Promise<Listed>;
|
|
33
|
+
forget(): void;
|
|
34
|
+
};
|
|
35
|
+
export declare function chunkScope(body: ReadableStream<Uint8Array>, room: ChunkedRoom, arriving: ((bytes: number) => void) | undefined): Promise<HouseScope | null>;
|
|
36
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAInB,OAAO,EAAkB,KAAK,SAAS,EAAE,KAA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W,EACjB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC9C,OAAO,CAAC,eAAe,CAAC,CAW1B;AAiBD,wBAAgB,WAAW,CACzB,SAAS,EAAE,SAAS,EACpB,IAAI,EAAE,MAAM,MAAM,EAClB,OAAO,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,gBAAgB,GAAG,SAAS;sBA0CjC,SAAS,gBAAgB,EAAE;kBA0B/B,gBAAgB,KAAG,OAAO,CAAC,MAAM,CAAC;iBAcxC,gBAAgB,cAAc,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;;EAY3F;AAqCD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CA4B5B"}
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
import { paced, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { manifestedModels } from './model.js';
|
|
3
|
+
import { authorityRoot, bootstrapping, documentEntry, } from './read.js';
|
|
4
|
+
import { classifyDoor } from './refusal.js';
|
|
5
|
+
import { failedOn, unusable } from './uncertain.js';
|
|
6
|
+
import { spaceSchemas } from './space-schema.js';
|
|
7
|
+
import { houseDoorRoute } from './transport.js';
|
|
8
|
+
import { readPosition, roomVersion } from './version.js';
|
|
9
|
+
function authorKey(author) {
|
|
10
|
+
for (const kind of ['user', 'site', 'inbox']) {
|
|
11
|
+
if (typeof author[kind] === 'string')
|
|
12
|
+
return `${kind}:${author[kind]}`;
|
|
13
|
+
}
|
|
14
|
+
const { app, release, function: named } = author;
|
|
15
|
+
return typeof app === 'string' && typeof release === 'string' && typeof named === 'string'
|
|
16
|
+
? `app:${app}:${release}:${named}`
|
|
17
|
+
: null;
|
|
18
|
+
}
|
|
19
|
+
function namesOf(authors) {
|
|
20
|
+
if (!Array.isArray(authors))
|
|
21
|
+
return null;
|
|
22
|
+
const names = new Map();
|
|
23
|
+
for (const author of authors) {
|
|
24
|
+
const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
|
|
25
|
+
if (key === null || typeof author.name !== 'string')
|
|
26
|
+
return null;
|
|
27
|
+
names.set(key, author.name);
|
|
28
|
+
}
|
|
29
|
+
return names;
|
|
30
|
+
}
|
|
31
|
+
function schemaText(file, texts) {
|
|
32
|
+
const { space, revision, content } = file;
|
|
33
|
+
if (content !== undefined) {
|
|
34
|
+
if (space !== undefined && revision !== undefined)
|
|
35
|
+
texts.keep(space, revision, content);
|
|
36
|
+
return content;
|
|
37
|
+
}
|
|
38
|
+
return space === undefined || revision === undefined ? undefined : texts.held(space, revision);
|
|
39
|
+
}
|
|
40
|
+
function modelsOf(models, mode, texts) {
|
|
41
|
+
if (!Array.isArray(models))
|
|
42
|
+
return null;
|
|
43
|
+
const files = [];
|
|
44
|
+
for (const entry of models) {
|
|
45
|
+
const file = documentEntry(entry, mode);
|
|
46
|
+
const content = file === null ? undefined : schemaText(file, texts);
|
|
47
|
+
if (file === null || content === undefined)
|
|
48
|
+
return null;
|
|
49
|
+
files.push({ ...file, content });
|
|
50
|
+
}
|
|
51
|
+
return files;
|
|
52
|
+
}
|
|
53
|
+
export function partId(logEpoch, hash) {
|
|
54
|
+
return `${logEpoch}:${hash}`;
|
|
55
|
+
}
|
|
56
|
+
function chunkedRoom(room, mode, texts) {
|
|
57
|
+
const at = readPosition(room);
|
|
58
|
+
const names = mode === 'site' ? new Map() : namesOf(room.authors);
|
|
59
|
+
const models = modelsOf(room.models, mode, texts);
|
|
60
|
+
if (at === null || names === null || models === null || !Array.isArray(room.chunks))
|
|
61
|
+
return null;
|
|
62
|
+
const chunks = new Map();
|
|
63
|
+
const parts = [];
|
|
64
|
+
for (const chunk of room.chunks) {
|
|
65
|
+
const { hash, bytes, download } = chunk;
|
|
66
|
+
if (typeof hash !== 'string' || typeof bytes !== 'number' || typeof download !== 'string')
|
|
67
|
+
return null;
|
|
68
|
+
const id = partId(at.logEpoch, hash);
|
|
69
|
+
chunks.set(id, { url: download, bytes });
|
|
70
|
+
parts.push({ id, bytes });
|
|
71
|
+
}
|
|
72
|
+
return { anchor: room.room_ref, ...at, mode, chunks, parts, names, models };
|
|
73
|
+
}
|
|
74
|
+
function listedRoom(room, mode, texts) {
|
|
75
|
+
if (typeof room !== 'object' || room === null)
|
|
76
|
+
return null;
|
|
77
|
+
const held = room;
|
|
78
|
+
if (typeof held.room_ref !== 'string')
|
|
79
|
+
return null;
|
|
80
|
+
if (held.ready === false)
|
|
81
|
+
return { kind: 'not-ready' };
|
|
82
|
+
return held.ready === true ? chunkedRoom(held, mode, texts) : null;
|
|
83
|
+
}
|
|
84
|
+
export function siteChunkList(answer, locator) {
|
|
85
|
+
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
86
|
+
if (failure !== null)
|
|
87
|
+
return failure;
|
|
88
|
+
return listedRoom(answer.body, 'site', spaceSchemas()) ?? unusable();
|
|
89
|
+
}
|
|
90
|
+
export async function chunkedHead(listed, entry) {
|
|
91
|
+
if (listed.anchor !== entry.authority)
|
|
92
|
+
return unusable();
|
|
93
|
+
const models = await manifestedModels({
|
|
94
|
+
anchor: listed.anchor,
|
|
95
|
+
position: listed.position,
|
|
96
|
+
logEpoch: listed.logEpoch,
|
|
97
|
+
models: listed.models,
|
|
98
|
+
}, entry);
|
|
99
|
+
return {
|
|
100
|
+
kind: 'bootstrap',
|
|
101
|
+
roomVersion: roomVersion(listed),
|
|
102
|
+
documents: {},
|
|
103
|
+
facts: {},
|
|
104
|
+
revisions: {},
|
|
105
|
+
changes: {},
|
|
106
|
+
attachments: {},
|
|
107
|
+
parts: listed.parts,
|
|
108
|
+
...(models === undefined ? {} : { models }),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
export async function chunkPart(body, room, id, arriving) {
|
|
112
|
+
const address = room.chunks.get(id);
|
|
113
|
+
if (body === null || address === undefined)
|
|
114
|
+
return unusable();
|
|
115
|
+
let scope;
|
|
116
|
+
try {
|
|
117
|
+
scope = await chunkScope(body, room, arriving);
|
|
118
|
+
}
|
|
119
|
+
catch (error) {
|
|
120
|
+
return failedOn(error);
|
|
121
|
+
}
|
|
122
|
+
if (scope === null)
|
|
123
|
+
return unusable();
|
|
124
|
+
return { ...(await stepped(bootstrapping(scope))), bytes: address.bytes };
|
|
125
|
+
}
|
|
126
|
+
function listedRooms(answer) {
|
|
127
|
+
const rooms = answer.body?.rooms;
|
|
128
|
+
if (!Array.isArray(rooms))
|
|
129
|
+
return null;
|
|
130
|
+
const listed = new Map();
|
|
131
|
+
const texts = spaceSchemas();
|
|
132
|
+
for (const room of rooms) {
|
|
133
|
+
const held = listedRoom(room, 'credential', texts);
|
|
134
|
+
if (held === null)
|
|
135
|
+
return null;
|
|
136
|
+
listed.set(room.room_ref, held);
|
|
137
|
+
}
|
|
138
|
+
return listed;
|
|
139
|
+
}
|
|
140
|
+
export function chunkLister(transport, most, tracked) {
|
|
141
|
+
const asked = new Map();
|
|
142
|
+
const unlisted = new Set();
|
|
143
|
+
function answered(entries, whole) {
|
|
144
|
+
const prefixes = whole ? ['/'] : entries.map((entry) => authorityRoot(entry.handle));
|
|
145
|
+
return transport.door(houseDoorRoute('room-chunks/list'), { prefixes }).then((answer) => {
|
|
146
|
+
const failure = classifyDoor(answer.status, answer.body, '');
|
|
147
|
+
if (failure !== null)
|
|
148
|
+
return failed(entries, failure);
|
|
149
|
+
const listed = listedRooms(answer);
|
|
150
|
+
return listed ?? failed(entries, unusable());
|
|
151
|
+
}, (error) => failed(entries, failedOn(error)));
|
|
152
|
+
}
|
|
153
|
+
function failed(entries, failure) {
|
|
154
|
+
return new Map(entries.map((entry) => [
|
|
155
|
+
entry.authority,
|
|
156
|
+
failure.kind === 'room-not-readable' || failure.kind === 'scoped-refusal'
|
|
157
|
+
? { ...failure, locator: entry.locator }
|
|
158
|
+
: failure,
|
|
159
|
+
]));
|
|
160
|
+
}
|
|
161
|
+
function settled(entry, lists) {
|
|
162
|
+
return lists.then((listed) => listed.get(entry.authority) ?? { kind: 'room-not-readable', locator: entry.locator });
|
|
163
|
+
}
|
|
164
|
+
function askAll(entries) {
|
|
165
|
+
if (entries.length === 0)
|
|
166
|
+
return;
|
|
167
|
+
const lists = answered(entries, entries.length > most());
|
|
168
|
+
for (const entry of entries) {
|
|
169
|
+
const listed = settled(entry, lists);
|
|
170
|
+
listed.catch(() => { });
|
|
171
|
+
asked.set(entry.authority, { entry, listed });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
function current(entry) {
|
|
175
|
+
return asked.get(entry.authority)?.entry.handle === entry.handle;
|
|
176
|
+
}
|
|
177
|
+
function askTogether(entries) {
|
|
178
|
+
askAll([...new Map(entries.map((one) => [one.authority, one])).values()]);
|
|
179
|
+
}
|
|
180
|
+
function waiting() {
|
|
181
|
+
return [...unlisted].flatMap((locator) => {
|
|
182
|
+
const entry = tracked(locator);
|
|
183
|
+
if (entry === undefined)
|
|
184
|
+
unlisted.delete(locator);
|
|
185
|
+
return entry ?? [];
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
function list(entry) {
|
|
189
|
+
if (!current(entry))
|
|
190
|
+
askTogether([...waiting().filter((one) => !current(one)), entry]);
|
|
191
|
+
const { listed } = asked.get(entry.authority);
|
|
192
|
+
asked.delete(entry.authority);
|
|
193
|
+
return listed.then((answer) => {
|
|
194
|
+
if ('kind' in answer)
|
|
195
|
+
unlisted.add(entry.locator);
|
|
196
|
+
else
|
|
197
|
+
unlisted.delete(entry.locator);
|
|
198
|
+
return answer;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
askAll,
|
|
203
|
+
list,
|
|
204
|
+
renew(entry, installing) {
|
|
205
|
+
if (!current(entry)) {
|
|
206
|
+
const listed = [...asked.values()].flatMap((held) => tracked(held.entry.locator) ?? []);
|
|
207
|
+
askTogether([...listed, ...waiting(), ...installing, entry]);
|
|
208
|
+
}
|
|
209
|
+
return list(entry);
|
|
210
|
+
},
|
|
211
|
+
forget() {
|
|
212
|
+
asked.clear();
|
|
213
|
+
unlisted.clear();
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
}
|
|
217
|
+
function folderLine(entry) {
|
|
218
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1 ? entry.folder : null;
|
|
219
|
+
}
|
|
220
|
+
function chunkEntry(line, room, read) {
|
|
221
|
+
let entry;
|
|
222
|
+
try {
|
|
223
|
+
entry = JSON.parse(line);
|
|
224
|
+
}
|
|
225
|
+
catch {
|
|
226
|
+
return false;
|
|
227
|
+
}
|
|
228
|
+
if (typeof entry !== 'object' || entry === null)
|
|
229
|
+
return false;
|
|
230
|
+
const folder = folderLine(entry);
|
|
231
|
+
if (folder !== null) {
|
|
232
|
+
read.folders.push(folder);
|
|
233
|
+
return true;
|
|
234
|
+
}
|
|
235
|
+
const author = entry.author;
|
|
236
|
+
let named = entry;
|
|
237
|
+
if (author !== undefined) {
|
|
238
|
+
const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
|
|
239
|
+
const name = key === null ? undefined : room.names.get(key);
|
|
240
|
+
if (name === undefined)
|
|
241
|
+
return false;
|
|
242
|
+
named = { ...entry, author: { ...author, name } };
|
|
243
|
+
}
|
|
244
|
+
const file = documentEntry(named, room.mode);
|
|
245
|
+
if (file === null)
|
|
246
|
+
return false;
|
|
247
|
+
read.files.push(file);
|
|
248
|
+
return true;
|
|
249
|
+
}
|
|
250
|
+
export async function chunkScope(body, room, arriving) {
|
|
251
|
+
const read = { files: [], folders: [] };
|
|
252
|
+
const reader = body.getReader();
|
|
253
|
+
const decoder = new TextDecoder();
|
|
254
|
+
const pace = paced();
|
|
255
|
+
const unfinished = [];
|
|
256
|
+
let bytes = 0;
|
|
257
|
+
for (let chunk = await reader.read(); chunk.done !== true; chunk = await reader.read()) {
|
|
258
|
+
bytes += chunk.value.length;
|
|
259
|
+
arriving?.(bytes);
|
|
260
|
+
const text = decoder.decode(chunk.value, { stream: true });
|
|
261
|
+
let start = 0;
|
|
262
|
+
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
263
|
+
const piece = text.slice(start, end);
|
|
264
|
+
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
265
|
+
start = end + 1;
|
|
266
|
+
if (line.length > 0 && !chunkEntry(line, room, read)) {
|
|
267
|
+
await reader.cancel();
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
const due = pace(line.length + ROW_WEIGHT);
|
|
271
|
+
if (due instanceof Promise)
|
|
272
|
+
await due;
|
|
273
|
+
}
|
|
274
|
+
if (start < text.length)
|
|
275
|
+
unfinished.push(text.slice(start));
|
|
276
|
+
}
|
|
277
|
+
const rest = unfinished.join('') + decoder.decode();
|
|
278
|
+
if (rest.length > 0 && !chunkEntry(rest, room, read))
|
|
279
|
+
return null;
|
|
280
|
+
return { anchor: room.anchor, position: room.position, logEpoch: room.logEpoch, ...read };
|
|
281
|
+
}
|
package/dist/digest.d.ts
CHANGED
package/dist/digest.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,
|
|
1
|
+
{"version":3,"file":"digest.d.ts","sourceRoot":"","sources":["../src/digest.ts"],"names":[],"mappings":"AAAA,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED,wBAAsB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAG9D"}
|
package/dist/digest.js
CHANGED
|
@@ -2,6 +2,6 @@ export function textBytes(value) {
|
|
|
2
2
|
return new TextEncoder().encode(value).length;
|
|
3
3
|
}
|
|
4
4
|
export async function sha256Hex(value) {
|
|
5
|
-
const digest = await crypto.subtle.digest('SHA-256',
|
|
5
|
+
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(value));
|
|
6
6
|
return [...new Uint8Array(digest)].map((byte) => byte.toString(16).padStart(2, '0')).join('');
|
|
7
7
|
}
|