@agentshouse/mdruntime-adapter 0.1.0-cd23c45caa798 → 0.1.0-cd519a0f878dc
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 -16
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +23 -53
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +124 -132
- 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 +3 -8
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +11 -24
- package/dist/house-model.d.ts +2 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +441 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/model.d.ts +5 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +11 -13
- package/dist/part.d.ts +4 -2
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +15 -13
- package/dist/read.d.ts +28 -7
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +172 -95
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +124 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +45 -55
- package/dist/stream.d.ts +1 -0
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +17 -2
- package/dist/transport.d.ts +10 -10
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +1 -1
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +13 -17
- package/package.json +8 -4
- package/AGENTS.md +0 -304
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -45
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -33
package/dist/part.js
CHANGED
|
@@ -35,14 +35,19 @@ function hex(bytes) {
|
|
|
35
35
|
text += byte.toString(16).padStart(2, '0');
|
|
36
36
|
return text;
|
|
37
37
|
}
|
|
38
|
-
export
|
|
38
|
+
export function partArrival(listed, arriving) {
|
|
39
|
+
if (arriving === undefined)
|
|
40
|
+
return undefined;
|
|
41
|
+
return (answered) => arriving(Math.min(listed.bytes, Math.floor((answered * 3) / 4)));
|
|
42
|
+
}
|
|
43
|
+
export function partFrame(body) {
|
|
39
44
|
if (typeof body !== 'object' || body === null)
|
|
40
45
|
return null;
|
|
41
46
|
const { part } = body;
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
if (frame
|
|
47
|
+
return typeof part === 'string' ? decoded(part) : null;
|
|
48
|
+
}
|
|
49
|
+
export async function checkedPayload(frame, listed) {
|
|
50
|
+
if (frame.length !== listed.bytes)
|
|
46
51
|
return null;
|
|
47
52
|
if (frame.length < PART_HEAD_BYTES + PART_DIGEST_BYTES)
|
|
48
53
|
return null;
|
|
@@ -59,14 +64,11 @@ export async function checkedPayload(body, listed) {
|
|
|
59
64
|
}
|
|
60
65
|
return payload;
|
|
61
66
|
}
|
|
62
|
-
export
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
catch {
|
|
68
|
-
return null;
|
|
69
|
-
}
|
|
67
|
+
export function gunzipped(payload) {
|
|
68
|
+
return new Blob([payload])
|
|
69
|
+
.stream()
|
|
70
|
+
.pipeThrough(new DecompressionStream('gzip'))
|
|
71
|
+
.pipeThrough(new TextDecoderStream());
|
|
70
72
|
}
|
|
71
73
|
export function unverifiedPart(locator) {
|
|
72
74
|
return {
|
package/dist/read.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AdapterFailure, type BinaryFile, type BootstrapPage, type RefreshResult, type TransportUncertainty } from '@agentshouse/mdruntime';
|
|
1
|
+
import { type AdapterFailure, type BinaryFile, type BootstrapInventory, type BootstrapPage, type RefreshResult, type RoomModels, type TransportUncertainty } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import { type HousePart } from './part.js';
|
|
4
4
|
import type { HouseMode } from './transport.js';
|
|
@@ -11,10 +11,13 @@ export type Answered = {
|
|
|
11
11
|
readonly changes: Map<string, HeadChange>;
|
|
12
12
|
readonly binaryFiles: Map<string, BinaryFile>;
|
|
13
13
|
readonly removals: Set<string>;
|
|
14
|
+
readonly folders: Set<string>;
|
|
15
|
+
readonly folderRemovals: Set<string>;
|
|
14
16
|
};
|
|
15
17
|
export declare function answering(): Answered;
|
|
16
18
|
export declare function revised(answer: Answered, path: string, revision: string): void;
|
|
17
19
|
export declare function forgotten(answer: Answered, path: string): void;
|
|
20
|
+
export declare function folded(answer: Answered, path: string, removed: boolean): void;
|
|
18
21
|
export declare function answered(answer: Answered): Generator<number, {
|
|
19
22
|
documents: Readonly<Record<string, string>>;
|
|
20
23
|
revisions: Readonly<Record<string, string>>;
|
|
@@ -22,6 +25,8 @@ export declare function answered(answer: Answered): Generator<number, {
|
|
|
22
25
|
changes: Readonly<Record<string, HeadChange>>;
|
|
23
26
|
binaryFiles: Readonly<Record<string, BinaryFile>>;
|
|
24
27
|
removals: readonly string[];
|
|
28
|
+
folders?: readonly string[];
|
|
29
|
+
folderRemovals?: readonly string[];
|
|
25
30
|
}, void>;
|
|
26
31
|
export type HouseManifestFile = {
|
|
27
32
|
path: string;
|
|
@@ -39,9 +44,15 @@ export type HouseScope = LogPosition & {
|
|
|
39
44
|
anchor: string;
|
|
40
45
|
files: readonly HouseManifestFile[];
|
|
41
46
|
contents: readonly HouseContent[];
|
|
47
|
+
folders?: readonly string[];
|
|
48
|
+
};
|
|
49
|
+
export type HouseModels = {
|
|
50
|
+
files: readonly HouseManifestFile[];
|
|
51
|
+
contents: readonly HouseContent[];
|
|
42
52
|
};
|
|
43
53
|
export type HouseRoomParts = LogPosition & {
|
|
44
54
|
anchor: string;
|
|
55
|
+
models: HouseModels;
|
|
45
56
|
parts: readonly HousePart[];
|
|
46
57
|
};
|
|
47
58
|
export type HouseParted = {
|
|
@@ -49,13 +60,15 @@ export type HouseParted = {
|
|
|
49
60
|
next?: string;
|
|
50
61
|
};
|
|
51
62
|
export type HouseGrant = {
|
|
52
|
-
method: 'GET';
|
|
53
|
-
url: string;
|
|
54
|
-
} | {
|
|
55
|
-
method: 'POST';
|
|
56
63
|
operation: string;
|
|
57
64
|
url: string;
|
|
58
65
|
};
|
|
66
|
+
export type HouseFileAddress = {
|
|
67
|
+
url: string;
|
|
68
|
+
name: string;
|
|
69
|
+
sha256: string;
|
|
70
|
+
mediaType: string;
|
|
71
|
+
};
|
|
59
72
|
export type HouseChange = {
|
|
60
73
|
path: string;
|
|
61
74
|
removed: true;
|
|
@@ -77,9 +90,14 @@ export type HousePage = {
|
|
|
77
90
|
through: string;
|
|
78
91
|
read: number;
|
|
79
92
|
};
|
|
93
|
+
export type HouseFolder = {
|
|
94
|
+
path: string;
|
|
95
|
+
removed: boolean;
|
|
96
|
+
};
|
|
80
97
|
export type HouseView = LogPosition & {
|
|
81
98
|
authority: string;
|
|
82
99
|
changes: readonly HouseChange[];
|
|
100
|
+
folders?: readonly HouseFolder[];
|
|
83
101
|
next?: HousePage;
|
|
84
102
|
};
|
|
85
103
|
type PageFailure = AdapterFailure | {
|
|
@@ -91,6 +109,7 @@ export type HouseEnumeration = {
|
|
|
91
109
|
export declare function authorityRoot(handle: string): string;
|
|
92
110
|
export declare function schemaPath(handle: string, schema: string): string;
|
|
93
111
|
export declare function parseGrant(body: unknown): HouseGrant | null;
|
|
112
|
+
export declare function parseFileAddress(body: unknown): HouseFileAddress | null;
|
|
94
113
|
export declare function headChange(held: {
|
|
95
114
|
readonly author?: unknown;
|
|
96
115
|
readonly created_at?: unknown;
|
|
@@ -98,11 +117,13 @@ export declare function headChange(held: {
|
|
|
98
117
|
export declare function binaryFileOf(held: Readonly<Record<string, unknown>>): BinaryFile | undefined | null;
|
|
99
118
|
export declare function parseParted(body: unknown): HouseParted | null;
|
|
100
119
|
export declare function parseSiteParted(body: unknown): HouseRoomParts | null;
|
|
120
|
+
export declare function partInventory(room: HouseRoomParts): BootstrapInventory;
|
|
121
|
+
export declare function manifested(room: HouseRoomParts, inventory: BootstrapInventory, pageToken: string, models: RoomModels | undefined): BootstrapPage;
|
|
122
|
+
export declare function modelScope(room: HouseRoomParts): HouseScope;
|
|
101
123
|
export declare function emptyScope(room: HouseRoomParts): HouseScope;
|
|
102
|
-
export declare function housePart(room: HouseRoomParts,
|
|
124
|
+
export declare function housePart(room: HouseRoomParts, frame: Uint8Array<ArrayBuffer>, listed: HousePart, mode: HouseMode): Promise<HouseScope | TransportUncertainty | null>;
|
|
103
125
|
export declare function parseEnumeration(body: unknown, mode: HouseMode): HouseEnumeration | null;
|
|
104
126
|
export declare function wholeView(first: HouseView, more: (page: HousePage) => Promise<HouseView | PageFailure>): Promise<HouseView | PageFailure>;
|
|
105
|
-
export declare function advancedScope(scope: HouseScope, view: HouseView): Generator<number, HouseScope, void>;
|
|
106
127
|
export declare function bootstrapping(scope: HouseScope): Generator<number, BootstrapPage, void>;
|
|
107
128
|
export type HouseSchema = {
|
|
108
129
|
schema: string | null;
|
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,
|
|
1
|
+
{"version":3,"file":"read.d.ts","sourceRoot":"","sources":["../src/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,aAAa,EAElB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,oBAA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B,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;AA0BD,wBAAsB,WAAW,CAC/B,IAAI,EAAE,SAAS,EACf,eAAe,EAAE,MAAM,GACtB,OAAO,CAAC,aAAa,CAAC,CAExB"}
|
package/dist/read.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { patching, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
1
|
+
import { paced, patching, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
2
2
|
import { checkedPayload, gunzipped, parsePart } from './part.js';
|
|
3
3
|
import { DECIMAL, readPosition, roomVersion } from './version.js';
|
|
4
4
|
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
@@ -13,6 +13,8 @@ export function answering() {
|
|
|
13
13
|
changes: new Map(),
|
|
14
14
|
binaryFiles: new Map(),
|
|
15
15
|
removals: new Set(),
|
|
16
|
+
folders: new Set(),
|
|
17
|
+
folderRemovals: new Set(),
|
|
16
18
|
};
|
|
17
19
|
}
|
|
18
20
|
export function revised(answer, path, revision) {
|
|
@@ -29,12 +31,26 @@ export function forgotten(answer, path) {
|
|
|
29
31
|
answer.binaryFiles.delete(path);
|
|
30
32
|
answer.removals.delete(path);
|
|
31
33
|
}
|
|
32
|
-
export function
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
export function folded(answer, path, removed) {
|
|
35
|
+
if (removed) {
|
|
36
|
+
answer.folders.delete(path);
|
|
37
|
+
answer.folderRemovals.add(path);
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
answer.folderRemovals.delete(path);
|
|
41
|
+
answer.folders.add(path);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function* pathsOf(paths) {
|
|
45
|
+
const list = [];
|
|
46
|
+
for (const path of paths) {
|
|
47
|
+
list.push(path);
|
|
36
48
|
yield ROW_WEIGHT;
|
|
37
49
|
}
|
|
50
|
+
return list;
|
|
51
|
+
}
|
|
52
|
+
export function* answered(answer) {
|
|
53
|
+
const removals = yield* pathsOf(answer.removals);
|
|
38
54
|
return {
|
|
39
55
|
documents: yield* patching({}, answer.documents),
|
|
40
56
|
revisions: yield* patching({}, answer.revisions),
|
|
@@ -42,6 +58,10 @@ export function* answered(answer) {
|
|
|
42
58
|
changes: yield* patching({}, answer.changes),
|
|
43
59
|
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
44
60
|
removals,
|
|
61
|
+
...(answer.folders.size === 0 ? {} : { folders: yield* pathsOf(answer.folders) }),
|
|
62
|
+
...(answer.folderRemovals.size === 0
|
|
63
|
+
? {}
|
|
64
|
+
: { folderRemovals: yield* pathsOf(answer.folderRemovals) }),
|
|
45
65
|
};
|
|
46
66
|
}
|
|
47
67
|
export function authorityRoot(handle) {
|
|
@@ -59,22 +79,37 @@ export function parseGrant(body) {
|
|
|
59
79
|
const transfer = body.transfer;
|
|
60
80
|
if (typeof transfer.url !== 'string')
|
|
61
81
|
return null;
|
|
62
|
-
if (transfer.method === 'GET')
|
|
63
|
-
return { method: 'GET', url: transfer.url };
|
|
64
82
|
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
65
83
|
return null;
|
|
66
|
-
return {
|
|
84
|
+
return { operation: transfer.operation, url: transfer.url };
|
|
85
|
+
}
|
|
86
|
+
export function parseFileAddress(body) {
|
|
87
|
+
if (typeof body !== 'object' || body === null)
|
|
88
|
+
return null;
|
|
89
|
+
const { download, name, sha256, media_type: mediaType } = body;
|
|
90
|
+
if (typeof download !== 'string' ||
|
|
91
|
+
typeof name !== 'string' ||
|
|
92
|
+
typeof sha256 !== 'string' ||
|
|
93
|
+
typeof mediaType !== 'string') {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
return { url: download, name, sha256, mediaType };
|
|
67
97
|
}
|
|
68
98
|
function changeAuthor(value) {
|
|
69
99
|
if (typeof value !== 'object' || value === null)
|
|
70
100
|
return null;
|
|
71
|
-
const { user, site, name } = value;
|
|
101
|
+
const { user, site, inbox, name } = value;
|
|
72
102
|
if (typeof name !== 'string')
|
|
73
103
|
return null;
|
|
74
|
-
|
|
104
|
+
const named = [user, site, inbox].filter((id) => id !== undefined);
|
|
105
|
+
if (named.length !== 1)
|
|
106
|
+
return null;
|
|
107
|
+
if (typeof user === 'string')
|
|
75
108
|
return { kind: 'user', id: user, name };
|
|
76
|
-
if (typeof site === 'string'
|
|
109
|
+
if (typeof site === 'string')
|
|
77
110
|
return { kind: 'site', id: site, name };
|
|
111
|
+
if (typeof inbox === 'string')
|
|
112
|
+
return { kind: 'inbox', id: inbox, name };
|
|
78
113
|
return null;
|
|
79
114
|
}
|
|
80
115
|
export function headChange(held) {
|
|
@@ -91,15 +126,12 @@ function headed(head) {
|
|
|
91
126
|
return head === undefined ? {} : { head };
|
|
92
127
|
}
|
|
93
128
|
export function binaryFileOf(held) {
|
|
94
|
-
if (held.
|
|
129
|
+
if (held.media_type === undefined)
|
|
95
130
|
return undefined;
|
|
96
|
-
const {
|
|
97
|
-
if (typeof
|
|
98
|
-
typeof bytes !== 'number' ||
|
|
99
|
-
typeof mediaType !== 'string' ||
|
|
100
|
-
typeof sha256 !== 'string')
|
|
131
|
+
const { bytes, media_type: mediaType, sha256 } = held;
|
|
132
|
+
if (typeof bytes !== 'number' || typeof mediaType !== 'string' || typeof sha256 !== 'string')
|
|
101
133
|
return null;
|
|
102
|
-
return {
|
|
134
|
+
return { byteLength: bytes, mediaType, sha256 };
|
|
103
135
|
}
|
|
104
136
|
function binaried(binary) {
|
|
105
137
|
return binary === undefined ? {} : { binary };
|
|
@@ -136,7 +168,22 @@ function parseFile(value, mode) {
|
|
|
136
168
|
...binaried(binary),
|
|
137
169
|
};
|
|
138
170
|
}
|
|
139
|
-
function
|
|
171
|
+
function parseModels(value, mode) {
|
|
172
|
+
if (!Array.isArray(value))
|
|
173
|
+
return null;
|
|
174
|
+
const files = [];
|
|
175
|
+
const contents = [];
|
|
176
|
+
for (const entry of value) {
|
|
177
|
+
const file = parseFile(entry, mode);
|
|
178
|
+
const { content } = entry;
|
|
179
|
+
if (file === null || typeof content !== 'string')
|
|
180
|
+
return null;
|
|
181
|
+
files.push(file);
|
|
182
|
+
contents.push({ path: file.path, content });
|
|
183
|
+
}
|
|
184
|
+
return { files, contents };
|
|
185
|
+
}
|
|
186
|
+
function parseRoomParts(value, mode) {
|
|
140
187
|
if (typeof value !== 'object' || value === null)
|
|
141
188
|
return null;
|
|
142
189
|
const held = value;
|
|
@@ -144,6 +191,9 @@ function parseRoomParts(value) {
|
|
|
144
191
|
return null;
|
|
145
192
|
if (!Array.isArray(held.parts))
|
|
146
193
|
return null;
|
|
194
|
+
const models = parseModels(held.models, mode);
|
|
195
|
+
if (models === null)
|
|
196
|
+
return null;
|
|
147
197
|
const manifest = held.manifest;
|
|
148
198
|
if (manifest.scope !== 'room')
|
|
149
199
|
return null;
|
|
@@ -159,7 +209,7 @@ function parseRoomParts(value) {
|
|
|
159
209
|
return null;
|
|
160
210
|
parts.push(part);
|
|
161
211
|
}
|
|
162
|
-
return { anchor: manifest.anchor, ...at, parts };
|
|
212
|
+
return { anchor: manifest.anchor, ...at, models, parts };
|
|
163
213
|
}
|
|
164
214
|
export function parseParted(body) {
|
|
165
215
|
if (typeof body !== 'object' || body === null)
|
|
@@ -168,7 +218,7 @@ export function parseParted(body) {
|
|
|
168
218
|
return null;
|
|
169
219
|
const rooms = [];
|
|
170
220
|
for (const entry of body.scopes) {
|
|
171
|
-
const room = parseRoomParts(entry);
|
|
221
|
+
const room = parseRoomParts(entry, 'credential');
|
|
172
222
|
if (room === null)
|
|
173
223
|
return null;
|
|
174
224
|
rooms.push(room);
|
|
@@ -181,7 +231,29 @@ export function parseParted(body) {
|
|
|
181
231
|
return { rooms, next: next.room };
|
|
182
232
|
}
|
|
183
233
|
export function parseSiteParted(body) {
|
|
184
|
-
return parseRoomParts(body);
|
|
234
|
+
return parseRoomParts(body, 'site');
|
|
235
|
+
}
|
|
236
|
+
export function partInventory(room) {
|
|
237
|
+
return {
|
|
238
|
+
parts: room.parts.length,
|
|
239
|
+
bytes: room.parts.reduce((sum, part) => sum + part.bytes, 0),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
export function manifested(room, inventory, pageToken, models) {
|
|
243
|
+
return {
|
|
244
|
+
kind: 'bootstrap',
|
|
245
|
+
roomVersion: roomVersion(room),
|
|
246
|
+
documents: {},
|
|
247
|
+
revisions: {},
|
|
248
|
+
changes: {},
|
|
249
|
+
binaryFiles: {},
|
|
250
|
+
inventory,
|
|
251
|
+
pageToken,
|
|
252
|
+
...(models === undefined ? {} : { models }),
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
export function modelScope(room) {
|
|
256
|
+
return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
|
|
185
257
|
}
|
|
186
258
|
export function emptyScope(room) {
|
|
187
259
|
return {
|
|
@@ -192,50 +264,76 @@ export function emptyScope(room) {
|
|
|
192
264
|
contents: [],
|
|
193
265
|
};
|
|
194
266
|
}
|
|
195
|
-
function
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
267
|
+
function partLine(line, mode, read) {
|
|
268
|
+
let entry;
|
|
269
|
+
try {
|
|
270
|
+
entry = JSON.parse(line);
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
return false;
|
|
274
|
+
}
|
|
275
|
+
if (folderLine(entry)) {
|
|
276
|
+
read.folders.push(entry.folder);
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
const file = parseFile(entry, mode);
|
|
280
|
+
if (file === null)
|
|
281
|
+
return false;
|
|
282
|
+
read.files.push(file);
|
|
283
|
+
const { content } = entry;
|
|
284
|
+
if (typeof content === 'string')
|
|
285
|
+
read.contents.push({ path: file.path, content });
|
|
286
|
+
else if (content !== undefined)
|
|
287
|
+
return false;
|
|
288
|
+
return true;
|
|
289
|
+
}
|
|
290
|
+
async function partRead(chunks, mode) {
|
|
291
|
+
const read = { files: [], contents: [], folders: [] };
|
|
292
|
+
const pace = paced();
|
|
293
|
+
const unfinished = [];
|
|
294
|
+
for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
|
|
295
|
+
const text = chunk.value;
|
|
296
|
+
let start = 0;
|
|
297
|
+
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
298
|
+
const piece = text.slice(start, end);
|
|
299
|
+
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
300
|
+
if (!partLine(line, mode, read)) {
|
|
301
|
+
await chunks.cancel();
|
|
302
|
+
return null;
|
|
303
|
+
}
|
|
304
|
+
start = end + 1;
|
|
305
|
+
const due = pace(line.length + ROW_WEIGHT);
|
|
306
|
+
if (due instanceof Promise)
|
|
307
|
+
await due;
|
|
209
308
|
}
|
|
210
|
-
start
|
|
211
|
-
|
|
212
|
-
continue;
|
|
213
|
-
const file = parseFile(entry, mode);
|
|
214
|
-
if (file === null)
|
|
215
|
-
return null;
|
|
216
|
-
files.push(file);
|
|
217
|
-
const { content } = entry;
|
|
218
|
-
if (typeof content === 'string')
|
|
219
|
-
contents.push({ path: file.path, content });
|
|
220
|
-
else if (content !== undefined)
|
|
221
|
-
return null;
|
|
222
|
-
yield ROW_WEIGHT;
|
|
309
|
+
if (start < text.length)
|
|
310
|
+
unfinished.push(text.slice(start));
|
|
223
311
|
}
|
|
224
|
-
return
|
|
312
|
+
return unfinished.length === 0 ? read : null;
|
|
225
313
|
}
|
|
226
314
|
function folderLine(entry) {
|
|
227
315
|
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
228
316
|
return false;
|
|
229
317
|
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
230
318
|
}
|
|
231
|
-
export async function housePart(room,
|
|
232
|
-
const payload = await checkedPayload(
|
|
319
|
+
export async function housePart(room, frame, listed, mode) {
|
|
320
|
+
const payload = await checkedPayload(frame, listed);
|
|
233
321
|
if (payload === null)
|
|
234
322
|
return null;
|
|
235
|
-
const
|
|
236
|
-
const read = text === null ? null : await stepped(partLines(text, mode));
|
|
323
|
+
const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
|
|
237
324
|
return read === null ? { kind: 'transport-uncertainty' } : { ...emptyScope(room), ...read };
|
|
238
325
|
}
|
|
326
|
+
function folderChange(value) {
|
|
327
|
+
if (typeof value !== 'object' || value === null)
|
|
328
|
+
return null;
|
|
329
|
+
const { path, folder, removed, ...rest } = value;
|
|
330
|
+
return typeof path === 'string' &&
|
|
331
|
+
folder === true &&
|
|
332
|
+
(removed === undefined || removed === true) &&
|
|
333
|
+
Object.keys(rest).length === 0
|
|
334
|
+
? { path, removed: removed === true }
|
|
335
|
+
: null;
|
|
336
|
+
}
|
|
239
337
|
function parseChange(value, mode) {
|
|
240
338
|
if (typeof value !== 'object' || value === null)
|
|
241
339
|
return null;
|
|
@@ -292,7 +390,13 @@ export function parseEnumeration(body, mode) {
|
|
|
292
390
|
if (!Array.isArray(held.changes))
|
|
293
391
|
return null;
|
|
294
392
|
const changes = [];
|
|
393
|
+
const folders = [];
|
|
295
394
|
for (const change of held.changes) {
|
|
395
|
+
const folder = folderChange(change);
|
|
396
|
+
if (folder !== null) {
|
|
397
|
+
folders.push(folder);
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
296
400
|
const mapped = parseChange(change, mode);
|
|
297
401
|
if (mapped === null)
|
|
298
402
|
return null;
|
|
@@ -305,6 +409,7 @@ export function parseEnumeration(body, mode) {
|
|
|
305
409
|
authority: held.authority,
|
|
306
410
|
...at,
|
|
307
411
|
changes,
|
|
412
|
+
...(folders.length === 0 ? {} : { folders }),
|
|
308
413
|
...(next === undefined ? {} : { next }),
|
|
309
414
|
});
|
|
310
415
|
}
|
|
@@ -328,6 +433,7 @@ function advances(asked, next) {
|
|
|
328
433
|
}
|
|
329
434
|
export async function wholeView(first, more) {
|
|
330
435
|
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
436
|
+
const folders = new Map((first.folders ?? []).map((folder) => [folder.path, folder]));
|
|
331
437
|
let view = first;
|
|
332
438
|
while (view.next !== undefined) {
|
|
333
439
|
const asked = view.next;
|
|
@@ -343,6 +449,10 @@ export async function wholeView(first, more) {
|
|
|
343
449
|
changes.delete(change.path);
|
|
344
450
|
changes.set(change.path, change);
|
|
345
451
|
}
|
|
452
|
+
for (const folder of page.folders ?? []) {
|
|
453
|
+
folders.delete(folder.path);
|
|
454
|
+
folders.set(folder.path, folder);
|
|
455
|
+
}
|
|
346
456
|
view = page;
|
|
347
457
|
}
|
|
348
458
|
return {
|
|
@@ -350,46 +460,7 @@ export async function wholeView(first, more) {
|
|
|
350
460
|
position: view.position,
|
|
351
461
|
logEpoch: first.logEpoch,
|
|
352
462
|
changes: [...changes.values()],
|
|
353
|
-
|
|
354
|
-
}
|
|
355
|
-
export function* advancedScope(scope, view) {
|
|
356
|
-
const files = new Map();
|
|
357
|
-
for (const file of scope.files) {
|
|
358
|
-
files.set(file.path, file);
|
|
359
|
-
yield ROW_WEIGHT;
|
|
360
|
-
}
|
|
361
|
-
const contents = new Map();
|
|
362
|
-
for (const entry of scope.contents) {
|
|
363
|
-
contents.set(entry.path, entry.content);
|
|
364
|
-
yield ROW_WEIGHT;
|
|
365
|
-
}
|
|
366
|
-
for (const change of view.changes) {
|
|
367
|
-
files.delete(change.path);
|
|
368
|
-
contents.delete(change.path);
|
|
369
|
-
yield ROW_WEIGHT;
|
|
370
|
-
if ('removed' in change)
|
|
371
|
-
continue;
|
|
372
|
-
files.set(change.path, {
|
|
373
|
-
path: change.path,
|
|
374
|
-
revision: change.revision,
|
|
375
|
-
version: change.version,
|
|
376
|
-
...headed(change.head),
|
|
377
|
-
...('binary' in change ? { binary: change.binary } : {}),
|
|
378
|
-
});
|
|
379
|
-
if ('content' in change)
|
|
380
|
-
contents.set(change.path, change.content);
|
|
381
|
-
}
|
|
382
|
-
const listed = [];
|
|
383
|
-
for (const [path, content] of contents) {
|
|
384
|
-
listed.push({ path, content });
|
|
385
|
-
yield ROW_WEIGHT;
|
|
386
|
-
}
|
|
387
|
-
return {
|
|
388
|
-
...scope,
|
|
389
|
-
position: view.position,
|
|
390
|
-
logEpoch: view.logEpoch,
|
|
391
|
-
files: [...files.values()],
|
|
392
|
-
contents: listed,
|
|
463
|
+
...(folders.size === 0 ? {} : { folders: [...folders.values()] }),
|
|
393
464
|
};
|
|
394
465
|
}
|
|
395
466
|
export function* bootstrapping(scope) {
|
|
@@ -411,7 +482,9 @@ export function* bootstrapping(scope) {
|
|
|
411
482
|
if (file.revision !== undefined)
|
|
412
483
|
revised(answer, file.path, file.revision);
|
|
413
484
|
}
|
|
414
|
-
const
|
|
485
|
+
for (const folder of scope.folders ?? [])
|
|
486
|
+
folded(answer, folder, false);
|
|
487
|
+
const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
|
|
415
488
|
return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
|
|
416
489
|
}
|
|
417
490
|
export function schemaOf(scope, schema) {
|
|
@@ -445,6 +518,10 @@ function* refreshing(view, fromRoomVersion) {
|
|
|
445
518
|
if (change.revision !== undefined)
|
|
446
519
|
revised(answer, change.path, change.revision);
|
|
447
520
|
}
|
|
521
|
+
for (const folder of view.folders ?? []) {
|
|
522
|
+
yield ROW_WEIGHT;
|
|
523
|
+
folded(answer, folder.path, folder.removed);
|
|
524
|
+
}
|
|
448
525
|
return { kind: 'net-advancement', roomVersion: roomVersion(view), ...(yield* answered(answer)) };
|
|
449
526
|
}
|
|
450
527
|
export async function refreshFrom(view, fromRoomVersion) {
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'whatsapp', 'messenger', 'instagram', 'viber', 'tiktok'];
|
|
2
|
+
export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
|
|
3
|
+
export declare const INBOX_CHAT_TYPE = "inbox-chat";
|
|
4
|
+
export declare const INBOX_MESSAGE_TYPE = "inbox-message";
|
|
5
|
+
export declare const HOUSE_NAMEABLE_ROOM_TYPES: string[];
|
|
6
|
+
export declare const HOUSE_ROOM_TYPES: string;
|
|
7
|
+
//# sourceMappingURL=room-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,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"}
|