@agentshouse/mdruntime-adapter 0.1.0-cda5b3be3317e → 0.1.0-cdc1a38081f09
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 +96 -78
- package/dist/actions.d.ts +14 -21
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +83 -133
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +210 -162
- package/dist/discovery.d.ts +3 -2
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +24 -6
- package/dist/gather.d.ts +1 -1
- package/dist/gather.d.ts.map +1 -1
- package/dist/gather.js +4 -14
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/model.d.ts +5 -1
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +8 -1
- package/dist/part.d.ts +15 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +82 -0
- package/dist/read.d.ts +57 -26
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +268 -152
- package/dist/room-types.d.ts +6 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +83 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +77 -104
- package/dist/stream.d.ts +3 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +38 -34
- package/dist/transport.d.ts +11 -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 +12 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +92 -55
- package/package.json +3 -3
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/dist/site.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
+
import { stepped } from '@agentshouse/mdruntime';
|
|
1
2
|
import { actionOutcome, SITE_SUBMIT } from './actions.js';
|
|
2
3
|
import { mapDiscovery, parseSiteDiscovery, siteCapabilities, siteTracked, } from './discovery.js';
|
|
3
|
-
import { partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { manifestedModels, partModels, streamedModels, viewModels } from './model.js';
|
|
5
|
+
import { bootstrapping, emptyScope, housePart, manifested, parseEnumeration, parseSiteParted, partInventory, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
6
|
+
import { PART_ATTEMPTS, partArrival, partFrame, unverifiedPart } from './part.js';
|
|
6
7
|
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
8
|
+
import { HOUSE_ROOM_TYPES } from './room-types.js';
|
|
7
9
|
import { houseNotifications } from './stream.js';
|
|
8
|
-
import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT,
|
|
9
|
-
import { houseReferrer } from './referrer.js';
|
|
10
|
+
import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILES, } from './transport.js';
|
|
10
11
|
import { followsVersion, logPosition, presented, reachedVersion, roomVersion, } from './version.js';
|
|
11
12
|
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
12
13
|
function unfound() {
|
|
@@ -18,32 +19,20 @@ function siteRoom(tracked) {
|
|
|
18
19
|
locator: tracked.locator,
|
|
19
20
|
handle: tracked.handle,
|
|
20
21
|
roomVersion: roomVersion(tracked),
|
|
21
|
-
operations: {
|
|
22
|
-
replica: { selection: tracked.locator, admission: 'admitted' },
|
|
22
|
+
operations: { write: [], delete: [] },
|
|
23
|
+
replica: { selection: tracked.locator, admission: 'admitted', offline: 'open' },
|
|
23
24
|
providerOwnedPaths: [],
|
|
24
25
|
};
|
|
25
26
|
}
|
|
26
|
-
function settled(refused) {
|
|
27
|
-
return refused.kind === 'beyond-horizon' ? UNCERTAIN : refused;
|
|
28
|
-
}
|
|
29
27
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
30
28
|
const notifications = houseNotifications(transport, 'site');
|
|
31
29
|
const tracked = new Map();
|
|
32
|
-
|
|
33
|
-
const named = houseReferrer(referrer, tracked);
|
|
34
|
-
return named === null || !tracked.has(named.locator) ? null : named;
|
|
35
|
-
}
|
|
30
|
+
const expired = new Map();
|
|
36
31
|
function fileRoute(request) {
|
|
37
|
-
const
|
|
38
|
-
if (
|
|
39
|
-
return { kind: '
|
|
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)}`;
|
|
32
|
+
const entry = tracked.get(request.locator);
|
|
33
|
+
if (entry === undefined)
|
|
34
|
+
return { kind: 'room-not-readable', locator: request.locator };
|
|
35
|
+
return `${SITE_FILES}${entry.authority}/${encodeURIComponent(request.revision)}/${encodeURIComponent(request.path)}`;
|
|
47
36
|
}
|
|
48
37
|
async function enumerated(entry, from, page) {
|
|
49
38
|
const answer = await transport.door(SITE_DOOR_ENUMERATE, {
|
|
@@ -68,73 +57,43 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
68
57
|
const first = await enumerated(entry, from);
|
|
69
58
|
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
70
59
|
}
|
|
71
|
-
async function
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
...(offset === null ? [] : [`offset=${offset}`]),
|
|
75
|
-
];
|
|
76
|
-
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${query.length === 0 ? '' : `?${query.join('&')}`}`);
|
|
60
|
+
async function partedRoom(entry) {
|
|
61
|
+
const cut = expired.get(entry.locator);
|
|
62
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`);
|
|
77
63
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
78
64
|
if (classified !== null)
|
|
79
|
-
return
|
|
80
|
-
const
|
|
81
|
-
return
|
|
82
|
-
}
|
|
83
|
-
async function assembled(entry, scope, path, offset) {
|
|
84
|
-
const opened = scope.contents.at(-1);
|
|
85
|
-
if (opened === undefined || opened.path !== path || opened.content.length !== offset) {
|
|
86
|
-
return UNCERTAIN;
|
|
87
|
-
}
|
|
88
|
-
let text = opened.content;
|
|
89
|
-
for (;;) {
|
|
90
|
-
const part = await bootstrapPart(entry, path, text.length);
|
|
91
|
-
if ('failure' in part)
|
|
92
|
-
return part.failure;
|
|
93
|
-
const [piece] = part.scope.contents;
|
|
94
|
-
if (piece === undefined ||
|
|
95
|
-
part.scope.contents.length !== 1 ||
|
|
96
|
-
piece.path !== path ||
|
|
97
|
-
piece.content.length === 0) {
|
|
98
|
-
return UNCERTAIN;
|
|
99
|
-
}
|
|
100
|
-
text += piece.content;
|
|
101
|
-
const more = siteBootstrapOffset(part.body);
|
|
102
|
-
if (more === null)
|
|
103
|
-
break;
|
|
104
|
-
if (more !== text.length)
|
|
105
|
-
return UNCERTAIN;
|
|
106
|
-
}
|
|
107
|
-
const file = scope.files.find((held) => held.path === path);
|
|
108
|
-
if (file === undefined || (await sha256Hex(text)) !== file.version)
|
|
109
|
-
return UNCERTAIN;
|
|
110
|
-
return { ...scope, contents: [...scope.contents.slice(0, -1), { path, content: text }] };
|
|
65
|
+
return classified;
|
|
66
|
+
const room = parseSiteParted(answer.body);
|
|
67
|
+
return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
|
|
111
68
|
}
|
|
112
|
-
async function
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
if (offset !== null) {
|
|
119
|
-
if (next === null)
|
|
120
|
-
return { failure: UNCERTAIN };
|
|
121
|
-
const scope = await assembled(entry, part.scope, next, offset);
|
|
122
|
-
return 'kind' in scope ? { failure: scope } : { scope, next };
|
|
69
|
+
async function fetchedPart(entry, room, listed, received, arriving) {
|
|
70
|
+
if (received !== undefined) {
|
|
71
|
+
const kept = new Uint8Array(received);
|
|
72
|
+
const held = await housePart(room, kept, listed, 'site');
|
|
73
|
+
if (held !== null)
|
|
74
|
+
return 'kind' in held ? held : { scope: held, frame: kept };
|
|
123
75
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
76
|
+
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
77
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`, partArrival(listed, arriving));
|
|
78
|
+
const failure = classifyRead(answer.status, answer.body, entry.locator);
|
|
79
|
+
if (failure?.kind === 'beyond-horizon')
|
|
80
|
+
expired.set(entry.locator, room.position);
|
|
81
|
+
if (failure !== null)
|
|
82
|
+
return failure;
|
|
83
|
+
const frame = partFrame(answer.body);
|
|
84
|
+
if (frame === null)
|
|
85
|
+
continue;
|
|
86
|
+
const scope = await housePart(room, frame, listed, 'site');
|
|
87
|
+
if (scope !== null)
|
|
88
|
+
return 'kind' in scope ? scope : { scope, frame };
|
|
127
89
|
}
|
|
128
|
-
|
|
129
|
-
if ('kind' in view)
|
|
130
|
-
return { failure: settled(view) };
|
|
131
|
-
return { scope: advancedScope(scope, view), next: null };
|
|
90
|
+
return unverifiedPart(entry.locator);
|
|
132
91
|
}
|
|
133
92
|
async function refreshed(entry, fromRoomVersion) {
|
|
134
93
|
const from = logPosition(fromRoomVersion);
|
|
135
94
|
if (from === null)
|
|
136
95
|
return { kind: 'beyond-horizon' };
|
|
137
|
-
const streamed = notifications.advance(entry, from);
|
|
96
|
+
const streamed = await stepped(notifications.advance(entry, from));
|
|
138
97
|
if (streamed !== null) {
|
|
139
98
|
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
140
99
|
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
@@ -143,7 +102,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
143
102
|
if ('kind' in view)
|
|
144
103
|
return view;
|
|
145
104
|
notifications.reach(entry.authority, view);
|
|
146
|
-
const answer = refreshFrom(view, fromRoomVersion);
|
|
105
|
+
const answer = await refreshFrom(view, fromRoomVersion);
|
|
147
106
|
if (answer.kind !== 'net-advancement')
|
|
148
107
|
return answer;
|
|
149
108
|
const models = await viewModels(view, entry);
|
|
@@ -152,6 +111,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
152
111
|
return {
|
|
153
112
|
localSaves: true,
|
|
154
113
|
exhaustiveDiscovery: true,
|
|
114
|
+
roomTypes: HOUSE_ROOM_TYPES,
|
|
155
115
|
async authorize() {
|
|
156
116
|
return {};
|
|
157
117
|
},
|
|
@@ -174,23 +134,43 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
174
134
|
const entry = tracked.get(request.locator);
|
|
175
135
|
if (entry === undefined)
|
|
176
136
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
137
|
+
let continued;
|
|
138
|
+
let inventory;
|
|
139
|
+
if (request.pageToken === undefined) {
|
|
140
|
+
const room = await partedRoom(entry);
|
|
141
|
+
if ('kind' in room)
|
|
142
|
+
return room;
|
|
143
|
+
const { models, seen } = await manifestedModels(room, entry);
|
|
144
|
+
continued = { room, next: 0, seen };
|
|
145
|
+
inventory = partInventory(room);
|
|
146
|
+
if (inventory.parts > 0) {
|
|
147
|
+
return manifested(room, inventory, JSON.stringify(continued), models);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
continued = JSON.parse(request.pageToken);
|
|
152
|
+
const listed = continued.room.parts[continued.next];
|
|
153
|
+
const sent = listed === undefined
|
|
154
|
+
? { scope: emptyScope(continued.room), frame: null }
|
|
155
|
+
: await fetchedPart(entry, continued.room, listed, request.received, request.arriving);
|
|
156
|
+
if ('kind' in sent)
|
|
157
|
+
return sent;
|
|
158
|
+
const { scope } = sent;
|
|
159
|
+
notifications.reach(entry.authority, scope);
|
|
160
|
+
const next = continued.next + 1;
|
|
161
|
+
const more = next < continued.room.parts.length;
|
|
184
162
|
const seen = [
|
|
185
|
-
...
|
|
186
|
-
...entry.schemas.filter((schema) =>
|
|
163
|
+
...continued.seen,
|
|
164
|
+
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
187
165
|
];
|
|
188
|
-
const models = await partModels(
|
|
189
|
-
const
|
|
166
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
167
|
+
const { folders: _folders, ...page } = await stepped(bootstrapping(scope));
|
|
190
168
|
return {
|
|
191
|
-
...
|
|
169
|
+
...page,
|
|
192
170
|
...(models === undefined ? {} : { models }),
|
|
193
|
-
...(
|
|
171
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
172
|
+
...(inventory === undefined ? {} : { inventory }),
|
|
173
|
+
...(sent.frame === null ? {} : { received: sent.frame }),
|
|
194
174
|
};
|
|
195
175
|
},
|
|
196
176
|
async refresh(_authorization, request) {
|
|
@@ -219,8 +199,8 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
219
199
|
const read = await transport.download(route);
|
|
220
200
|
if (read.status === 404)
|
|
221
201
|
return unfound();
|
|
222
|
-
return read.status === 200 && read.
|
|
223
|
-
? { kind: 'binary',
|
|
202
|
+
return read.status === 200 && read.body !== null
|
|
203
|
+
? { kind: 'binary', body: read.body, mediaType: read.mediaType }
|
|
224
204
|
: UNCERTAIN;
|
|
225
205
|
},
|
|
226
206
|
async link(_authorization, request) {
|
|
@@ -233,13 +213,6 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
233
213
|
name: request.path.slice(request.path.lastIndexOf('/') + 1),
|
|
234
214
|
};
|
|
235
215
|
},
|
|
236
|
-
referrerScope(referrer) {
|
|
237
|
-
const named = published(referrer);
|
|
238
|
-
if (named === null)
|
|
239
|
-
return null;
|
|
240
|
-
const { path } = named.referrer;
|
|
241
|
-
return { kind: 'room', locator: named.locator, ...(path === undefined ? {} : { path }) };
|
|
242
|
-
},
|
|
243
216
|
reached(locator, version, target) {
|
|
244
217
|
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
|
245
218
|
},
|
package/dist/stream.d.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ConversationStream, type RefreshPage, type RoomStreamEvent, type ServiceModeSignal, type 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';
|
|
5
5
|
export type HeldRevision = (path: string, revision: string) => boolean;
|
|
6
6
|
export type StreamedAdvancement = {
|
|
7
7
|
page: RefreshPage;
|
|
8
|
-
entries: readonly HouseStreamEntry[];
|
|
9
8
|
schemas: ReadonlyMap<string, HouseStreamEntry>;
|
|
10
9
|
};
|
|
11
10
|
export type HouseNotifications = {
|
|
@@ -16,7 +15,8 @@ export type HouseNotifications = {
|
|
|
16
15
|
reopen(): void;
|
|
17
16
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
18
17
|
reach(authority: string, at: LogPosition): void;
|
|
19
|
-
|
|
18
|
+
edited(tracked: TrackedAuthority, from: LogPosition): readonly string[];
|
|
19
|
+
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
|
|
20
20
|
conversations: ConversationStream;
|
|
21
21
|
serviceMode: ServiceModeSignal;
|
|
22
22
|
};
|
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,
|
|
1
|
+
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../src/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,kBAAkB,EAEvB,KAAK,WAAW,EAChB,KAAK,eAAe,EAEpB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EAEpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAUvD,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,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,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAClD,MAAM,IAAI,IAAI,CAAC;IACf,KAAK,CAAC,WAAW,EAAE,SAAS,gBAAgB,EAAE,GAAG,IAAI,CAAC;IACtD,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,WAAW,GAAG,IAAI,CAAC;IAChD,MAAM,CAAC,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,WAAW,GAAG,SAAS,MAAM,EAAE,CAAC;IACxE,OAAO,CACL,OAAO,EAAE,gBAAgB,EACzB,IAAI,EAAE,WAAW,EACjB,KAAK,CAAC,EAAE,YAAY,GACnB,SAAS,CAAC,MAAM,EAAE,mBAAmB,GAAG,IAAI,EAAE,IAAI,CAAC,CAAC;IACvD,aAAa,EAAE,kBAAkB,CAAC;IAClC,WAAW,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAmFF,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,GAAG,kBAAkB,CA8jB5F"}
|
package/dist/stream.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
1
2
|
import { acceptedMessage } from './actions.js';
|
|
2
3
|
import { sha256Hex } from './digest.js';
|
|
3
|
-
import { binaryFileOf, headChange,
|
|
4
|
+
import { answered, answering, binaryFileOf, folded, forgotten, headChange, revised, } from './read.js';
|
|
4
5
|
import { roomVersion } from './version.js';
|
|
5
6
|
const HELD_FRAMES_MAX = 256;
|
|
6
7
|
function turnOperation(frame) {
|
|
@@ -15,6 +16,7 @@ function listedConversation(listed) {
|
|
|
15
16
|
created: listed.created_at,
|
|
16
17
|
finished: listed.finished_at,
|
|
17
18
|
outcome: listed.outcome,
|
|
19
|
+
waiting: listed.waiting,
|
|
18
20
|
};
|
|
19
21
|
}
|
|
20
22
|
function position(value) {
|
|
@@ -554,7 +556,18 @@ export function houseNotifications(transport, mode) {
|
|
|
554
556
|
held,
|
|
555
557
|
});
|
|
556
558
|
},
|
|
557
|
-
|
|
559
|
+
edited(tracked, from) {
|
|
560
|
+
const line = lines.get(tracked.authority);
|
|
561
|
+
const start = position(from.position);
|
|
562
|
+
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
563
|
+
return [];
|
|
564
|
+
return [
|
|
565
|
+
...new Set(line.frames
|
|
566
|
+
.filter((frame) => frame.position > start)
|
|
567
|
+
.flatMap((frame) => frame.entries.flatMap((entry) => entry.kind === 'edited' && entry.revision !== undefined ? [entry.path] : []))),
|
|
568
|
+
];
|
|
569
|
+
},
|
|
570
|
+
*advance(tracked, from, holds) {
|
|
558
571
|
const line = lines.get(tracked.authority);
|
|
559
572
|
const start = position(from.position);
|
|
560
573
|
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
@@ -563,36 +576,26 @@ export function houseNotifications(transport, mode) {
|
|
|
563
576
|
const first = pending[0];
|
|
564
577
|
if (first === undefined || first.after > start)
|
|
565
578
|
return null;
|
|
566
|
-
const
|
|
567
|
-
const revisions = {};
|
|
568
|
-
const changes = {};
|
|
569
|
-
const binaryFiles = {};
|
|
570
|
-
const removals = [];
|
|
571
|
-
const applied = [];
|
|
579
|
+
const answer = answering();
|
|
572
580
|
const schemas = new Map();
|
|
573
|
-
const forget = (path) => {
|
|
574
|
-
delete documents[path];
|
|
575
|
-
delete revisions[path];
|
|
576
|
-
delete changes[path];
|
|
577
|
-
delete binaryFiles[path];
|
|
578
|
-
const removed = removals.indexOf(path);
|
|
579
|
-
if (removed !== -1)
|
|
580
|
-
removals.splice(removed, 1);
|
|
581
|
-
};
|
|
582
581
|
for (const frame of pending) {
|
|
583
582
|
for (const entry of frame.entries) {
|
|
583
|
+
yield ROW_WEIGHT + (entry.text?.length ?? 0);
|
|
584
|
+
if (entry.kind === 'folder') {
|
|
585
|
+
folded(answer, entry.path, entry.removed === true);
|
|
586
|
+
continue;
|
|
587
|
+
}
|
|
584
588
|
if (entry.kind === 'edited' &&
|
|
585
589
|
entry.revision !== undefined &&
|
|
586
590
|
holds?.(entry.path, entry.revision) === true) {
|
|
587
|
-
|
|
591
|
+
forgotten(answer, entry.path);
|
|
588
592
|
continue;
|
|
589
593
|
}
|
|
590
|
-
applied.push(entry);
|
|
591
594
|
if (tracked.schemas.includes(entry.path))
|
|
592
595
|
schemas.set(entry.path, entry);
|
|
593
596
|
if (entry.kind === 'removed') {
|
|
594
|
-
|
|
595
|
-
removals.
|
|
597
|
+
forgotten(answer, entry.path);
|
|
598
|
+
answer.removals.add(entry.path);
|
|
596
599
|
continue;
|
|
597
600
|
}
|
|
598
601
|
const binary = binaryFileOf(entry);
|
|
@@ -603,32 +606,33 @@ export function houseNotifications(transport, mode) {
|
|
|
603
606
|
const head = headChange(entry);
|
|
604
607
|
if (head === null)
|
|
605
608
|
return null;
|
|
606
|
-
|
|
609
|
+
forgotten(answer, entry.path);
|
|
607
610
|
if (binary === undefined)
|
|
608
|
-
documents
|
|
611
|
+
answer.documents.set(entry.path, entry.text);
|
|
609
612
|
else
|
|
610
|
-
binaryFiles
|
|
613
|
+
answer.binaryFiles.set(entry.path, binary);
|
|
611
614
|
const revision = entry.revision ?? binary?.sha256;
|
|
612
615
|
if (revision !== undefined)
|
|
613
|
-
|
|
616
|
+
revised(answer, entry.path, revision);
|
|
614
617
|
if (head !== undefined)
|
|
615
|
-
changes
|
|
618
|
+
answer.changes.set(entry.path, head);
|
|
616
619
|
}
|
|
617
620
|
}
|
|
618
621
|
const last = pending.at(-1);
|
|
619
|
-
lines.
|
|
622
|
+
const current = lines.get(tracked.authority);
|
|
623
|
+
if (current?.logEpoch === line.logEpoch) {
|
|
624
|
+
lines.set(tracked.authority, {
|
|
625
|
+
...current,
|
|
626
|
+
frames: current.frames.filter((frame) => frame.position > start),
|
|
627
|
+
held: current.held !== null && current.held > last.position ? current.held : last.position,
|
|
628
|
+
});
|
|
629
|
+
}
|
|
620
630
|
return {
|
|
621
631
|
page: {
|
|
622
632
|
kind: 'net-advancement',
|
|
623
633
|
roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
|
|
624
|
-
|
|
625
|
-
revisions,
|
|
626
|
-
...identities(revisions),
|
|
627
|
-
changes,
|
|
628
|
-
binaryFiles,
|
|
629
|
-
removals: removals.sort(),
|
|
634
|
+
...(yield* answered(answer)),
|
|
630
635
|
},
|
|
631
|
-
entries: applied,
|
|
632
636
|
schemas,
|
|
633
637
|
};
|
|
634
638
|
},
|
package/dist/transport.d.ts
CHANGED
|
@@ -15,27 +15,26 @@ export type HouseDoorAnswer = {
|
|
|
15
15
|
body: unknown;
|
|
16
16
|
};
|
|
17
17
|
export declare const DOOR_FILES_GET = "/door/files/get";
|
|
18
|
+
export declare const DOOR_FILES_FINISH = "/door/files/finish";
|
|
18
19
|
export declare const SITE_FILES = "/_house/files/";
|
|
19
|
-
export
|
|
20
|
-
export type HouseByteAct = 'authored_batch_upload' | 'conversation_file_upload' | 'binary_stage';
|
|
21
|
-
export type HouseByteBody = string | ArrayBuffer | Uint8Array | Blob;
|
|
20
|
+
export type HouseByteAct = 'authored_batch_upload';
|
|
22
21
|
export type HouseBytesAnswer = {
|
|
23
22
|
status: number;
|
|
24
|
-
|
|
23
|
+
body: ReadableStream<Uint8Array> | null;
|
|
24
|
+
mediaType: string;
|
|
25
25
|
};
|
|
26
26
|
export type HouseByteTransfer = {
|
|
27
27
|
act: HouseByteAct;
|
|
28
28
|
url: string;
|
|
29
|
-
body:
|
|
30
|
-
operation?: string;
|
|
29
|
+
body: string;
|
|
31
30
|
};
|
|
32
31
|
export type HouseStreamEntry = {
|
|
33
32
|
path: string;
|
|
34
|
-
kind: 'edited' | 'removed' | 'piece';
|
|
33
|
+
kind: 'edited' | 'removed' | 'piece' | 'folder';
|
|
34
|
+
removed?: true;
|
|
35
35
|
revision?: string;
|
|
36
36
|
sha256?: string;
|
|
37
37
|
text?: string;
|
|
38
|
-
file?: string;
|
|
39
38
|
bytes?: number;
|
|
40
39
|
media_type?: string;
|
|
41
40
|
author?: {
|
|
@@ -58,6 +57,7 @@ export type HouseListedConversation = {
|
|
|
58
57
|
created_at: string;
|
|
59
58
|
finished_at: string | null;
|
|
60
59
|
outcome: string | null;
|
|
60
|
+
waiting: boolean;
|
|
61
61
|
};
|
|
62
62
|
export type HouseStreamFrame = {
|
|
63
63
|
type: 'part';
|
|
@@ -164,16 +164,17 @@ export type HouseStream = {
|
|
|
164
164
|
closed(notify: (closing: HouseClosing) => void): () => void;
|
|
165
165
|
};
|
|
166
166
|
export type HouseDoor = {
|
|
167
|
-
door(route: string, body: unknown): Promise<HouseDoorAnswer>;
|
|
167
|
+
door(route: string, body: unknown, arriving?: (bytes: number) => void): Promise<HouseDoorAnswer>;
|
|
168
168
|
stream: HouseStream;
|
|
169
169
|
};
|
|
170
170
|
export type HouseTransport = HouseDoor & {
|
|
171
171
|
transfer(request: HouseByteTransfer): Promise<HouseDoorAnswer>;
|
|
172
|
+
put(url: string, body: Blob, headers: Readonly<Record<string, string>>): Promise<number>;
|
|
172
173
|
download(url: string): Promise<HouseBytesAnswer>;
|
|
173
174
|
};
|
|
174
175
|
export type HouseSiteTransport = HouseDoor & {
|
|
175
176
|
online(): boolean;
|
|
176
|
-
read(route: string): Promise<HouseDoorAnswer>;
|
|
177
|
+
read(route: string, arriving?: (bytes: number) => void): Promise<HouseDoorAnswer>;
|
|
177
178
|
download(route: string): Promise<HouseBytesAnswer>;
|
|
178
179
|
};
|
|
179
180
|
export {};
|
package/dist/transport.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAE/E,eAAO,MAAM,aAAa,mBAAmB,CAAC;AAE9C,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,eAAO,MAAM,UAAU,gBAAgB,CAAC;AAExC,eAAO,MAAM,iBAAiB,uBAAuB,CAAC;AAEtD,eAAO,MAAM,cAAc,oBAAoB,C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C,CAAC;IAC/D,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACzF,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CAClD,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG,SAAS,GAAG;IAC3C,MAAM,IAAI,OAAO,CAAC;IAClB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,eAAe,CAAC,CAAC;IAClF,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACpD,CAAC"}
|
package/dist/transport.js
CHANGED
|
@@ -9,5 +9,5 @@ export const SITE_DOOR_BOOTSTRAP = '/_house/door/bootstrap/';
|
|
|
9
9
|
export const SITE_DOOR_ENUMERATE = '/_house/door/enumerate';
|
|
10
10
|
export const SITE_DOOR_SUBMIT = '/_house/door/submit';
|
|
11
11
|
export const DOOR_FILES_GET = '/door/files/get';
|
|
12
|
+
export const DOOR_FILES_FINISH = '/door/files/finish';
|
|
12
13
|
export const SITE_FILES = '/_house/files/';
|
|
13
|
-
export const SITE_FILE_RECORD = 'record';
|
package/dist/upload.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type HouseDoorAnswer, type HouseTransport } from './transport.js';
|
|
2
|
+
export type HouseUpload = {
|
|
3
|
+
readonly id: string;
|
|
4
|
+
readonly partBytes: number;
|
|
5
|
+
readonly parts: readonly {
|
|
6
|
+
readonly part: number;
|
|
7
|
+
readonly url: string;
|
|
8
|
+
}[];
|
|
9
|
+
};
|
|
10
|
+
export declare function houseUpload(value: unknown): HouseUpload | null;
|
|
11
|
+
export declare function finishedUpload(transport: HouseTransport, first: HouseUpload, blob: Blob): Promise<HouseDoorAnswer | null>;
|
|
12
|
+
//# sourceMappingURL=upload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AACA,OAAO,EAAqB,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAE9F,MAAM,MAAM,WAAW,GAAG;IACxB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,SAAS;QAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC5E,CAAC;AAeF,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAQ9D;AA8BD,wBAAsB,cAAc,CAClC,SAAS,EAAE,cAAc,EACzB,KAAK,EAAE,WAAW,EAClB,IAAI,EAAE,IAAI,GACT,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC,CAejC"}
|
package/dist/upload.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { sha256 } from '@agentshouse/mdruntime/digest';
|
|
2
|
+
import { DOOR_FILES_FINISH } from './transport.js';
|
|
3
|
+
const FINISHING_ROUNDS = 24;
|
|
4
|
+
function record(value) {
|
|
5
|
+
return value !== null && typeof value === 'object' ? value : {};
|
|
6
|
+
}
|
|
7
|
+
function part(value) {
|
|
8
|
+
const { part: number, url } = record(value);
|
|
9
|
+
return Number.isSafeInteger(number) && number > 0 && typeof url === 'string'
|
|
10
|
+
? { part: number, url }
|
|
11
|
+
: null;
|
|
12
|
+
}
|
|
13
|
+
export function houseUpload(value) {
|
|
14
|
+
const { id, part_bytes: partBytes, parts = [] } = record(value);
|
|
15
|
+
if (typeof id !== 'string' || !Number.isSafeInteger(partBytes) || partBytes <= 0)
|
|
16
|
+
return null;
|
|
17
|
+
if (!Array.isArray(parts))
|
|
18
|
+
return null;
|
|
19
|
+
const named = parts.map(part);
|
|
20
|
+
if (named.some((one) => one === null))
|
|
21
|
+
return null;
|
|
22
|
+
return { id, partBytes: partBytes, parts: named };
|
|
23
|
+
}
|
|
24
|
+
function checksum(hex) {
|
|
25
|
+
let bytes = '';
|
|
26
|
+
for (let at = 0; at < hex.length; at += 2)
|
|
27
|
+
bytes += String.fromCharCode(Number.parseInt(hex.slice(at, at + 2), 16));
|
|
28
|
+
return { 'x-amz-checksum-sha256': btoa(bytes) };
|
|
29
|
+
}
|
|
30
|
+
async function partSha256(blob, partBytes) {
|
|
31
|
+
const parts = [];
|
|
32
|
+
for (let start = 0; start === 0 || start < blob.size; start += partBytes)
|
|
33
|
+
parts.push(await sha256(blob.slice(start, start + partBytes)));
|
|
34
|
+
return parts;
|
|
35
|
+
}
|
|
36
|
+
async function sent(transport, upload, blob, digests) {
|
|
37
|
+
for (const { part: number, url } of upload.parts) {
|
|
38
|
+
const start = (number - 1) * upload.partBytes;
|
|
39
|
+
const slice = blob.slice(start, start + upload.partBytes);
|
|
40
|
+
if ((await transport.put(url, slice, checksum(digests[number - 1]))) !== 200)
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
export async function finishedUpload(transport, first, blob) {
|
|
46
|
+
const digests = await partSha256(blob, first.partBytes);
|
|
47
|
+
let upload = first;
|
|
48
|
+
for (let round = 0; round < FINISHING_ROUNDS; round += 1) {
|
|
49
|
+
if (!(await sent(transport, upload, blob, digests)))
|
|
50
|
+
return null;
|
|
51
|
+
const answer = await transport.door(DOOR_FILES_FINISH, {
|
|
52
|
+
upload: upload.id,
|
|
53
|
+
part_sha256: digests,
|
|
54
|
+
});
|
|
55
|
+
if (answer.status !== 200)
|
|
56
|
+
return answer;
|
|
57
|
+
const missing = houseUpload(record(answer.body).upload);
|
|
58
|
+
if (missing === null)
|
|
59
|
+
return answer;
|
|
60
|
+
upload = missing;
|
|
61
|
+
}
|
|
62
|
+
return null;
|
|
63
|
+
}
|
package/dist/write.d.ts
CHANGED
|
@@ -10,6 +10,7 @@ export type ChangeMapping = {
|
|
|
10
10
|
rule: string;
|
|
11
11
|
};
|
|
12
12
|
export declare function houseChanges(batch: ChangeBatch, handle: string): ChangeMapping;
|
|
13
|
+
export declare function houseMove(batch: ChangeBatch, source: string, destination: string): ChangeMapping;
|
|
13
14
|
export type OperationHead = {
|
|
14
15
|
readonly operation_id: string;
|
|
15
16
|
readonly app_ref?: string;
|
|
@@ -21,7 +22,17 @@ export declare function deltaBody(changes: readonly HouseOperation[]): string;
|
|
|
21
22
|
export declare function deltaBytes(delta: string): number;
|
|
22
23
|
export declare function uploadable(inline: Readonly<Record<string, unknown>>, bytes: number, bounds: Pick<HouseBounds, 'max_inline_body_bytes' | 'max_upload_bytes'>): boolean;
|
|
23
24
|
export declare function deltaDigest(delta: string): Promise<string>;
|
|
24
|
-
export
|
|
25
|
+
export type MoveAuthorities = {
|
|
26
|
+
readonly source: {
|
|
27
|
+
readonly authority: string;
|
|
28
|
+
readonly handle: string;
|
|
29
|
+
};
|
|
30
|
+
readonly destination: {
|
|
31
|
+
readonly authority: string;
|
|
32
|
+
readonly handle: string;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export declare function mutationOutcome(status: number, body: unknown, locator: string, handle: string, move?: MoveAuthorities): Generator<number, MutationResult, void>;
|
|
25
36
|
export declare function rejectedMapping(mapping: Extract<ChangeMapping, {
|
|
26
37
|
kind: 'unmapped';
|
|
27
38
|
}>): {
|
package/dist/write.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"write.d.ts","sourceRo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