@agentshouse/mdruntime-adapter 0.1.0-ccd2ccb1f7214 → 0.1.0-cd23c45caa798
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 +28 -23
- package/dist/actions.d.ts +11 -5
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +77 -97
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +144 -87
- 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/handed.d.ts +6 -6
- package/dist/handed.d.ts.map +1 -1
- package/dist/handed.js +36 -29
- package/dist/part.d.ts +13 -0
- package/dist/part.d.ts.map +1 -0
- package/dist/part.js +80 -0
- package/dist/read.d.ts +33 -23
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +159 -120
- package/dist/referrer.d.ts.map +1 -1
- package/dist/referrer.js +0 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +58 -74
- package/dist/stream.d.ts +2 -3
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +23 -34
- package/dist/transport.d.ts +2 -1
- package/dist/transport.d.ts.map +1 -1
- package/dist/write.d.ts +12 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +79 -38
- package/package.json +2 -2
package/dist/referrer.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"referrer.d.ts","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAgB5F,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC7C,aAAa,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"referrer.d.ts","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAgB5F,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC7C,aAAa,GAAG,IAAI,CAoBtB"}
|
package/dist/referrer.js
CHANGED
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,EAUR,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAUR,MAAM,wBAAwB,CAAC;AA6BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAuCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CAkQ1F"}
|
package/dist/site.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
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
4
|
import { partModels, streamedModels, viewModels } from './model.js';
|
|
4
|
-
import { advancedScope,
|
|
5
|
-
import {
|
|
5
|
+
import { advancedScope, bootstrapping, emptyScope, housePart, parseEnumeration, parseSiteParted, refreshFrom, viewOf, wholeView, } from './read.js';
|
|
6
|
+
import { PART_ATTEMPTS, unverifiedPart } from './part.js';
|
|
6
7
|
import { classifyDoor, classifyRead, discoveryFailure } from './refusal.js';
|
|
7
8
|
import { houseNotifications } from './stream.js';
|
|
8
9
|
import { SITE_DOOR_BOOTSTRAP, SITE_DOOR_DISCOVER, SITE_DOOR_ENUMERATE, SITE_DOOR_SUBMIT, SITE_FILE_RECORD, SITE_FILES, } from './transport.js';
|
|
@@ -18,8 +19,8 @@ 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
|
}
|
|
@@ -29,6 +30,7 @@ function settled(refused) {
|
|
|
29
30
|
export function createSiteAdapter(transport, snapshot = false) {
|
|
30
31
|
const notifications = houseNotifications(transport, 'site');
|
|
31
32
|
const tracked = new Map();
|
|
33
|
+
const expired = new Map();
|
|
32
34
|
function published(referrer) {
|
|
33
35
|
const named = houseReferrer(referrer, tracked);
|
|
34
36
|
return named === null || !tracked.has(named.locator) ? null : named;
|
|
@@ -68,73 +70,48 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
68
70
|
const first = await enumerated(entry, from);
|
|
69
71
|
return 'kind' in first ? first : wholeView(first, (page) => enumerated(entry, from, page));
|
|
70
72
|
}
|
|
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('&')}`}`);
|
|
73
|
+
async function partedRoom(entry) {
|
|
74
|
+
const cut = expired.get(entry.locator);
|
|
75
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}${cut === undefined ? '' : `?expired=${cut}`}`);
|
|
77
76
|
const classified = classifyDoor(answer.status, answer.body, entry.locator);
|
|
78
77
|
if (classified !== null)
|
|
79
|
-
return
|
|
80
|
-
const
|
|
81
|
-
return
|
|
78
|
+
return classified;
|
|
79
|
+
const room = parseSiteParted(answer.body);
|
|
80
|
+
return room === null || room.anchor !== entry.authority ? UNCERTAIN : room;
|
|
82
81
|
}
|
|
83
|
-
async function
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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;
|
|
82
|
+
async function fetchedPart(entry, room, listed) {
|
|
83
|
+
for (let attempt = 0; attempt < PART_ATTEMPTS; attempt += 1) {
|
|
84
|
+
const answer = await transport.read(`${SITE_DOOR_BOOTSTRAP}${entry.authority}?part=${encodeURIComponent(listed.part)}`);
|
|
85
|
+
const failure = classifyRead(answer.status, answer.body, entry.locator);
|
|
86
|
+
if (failure?.kind === 'beyond-horizon')
|
|
87
|
+
expired.set(entry.locator, room.position);
|
|
88
|
+
if (failure !== null)
|
|
89
|
+
return failure;
|
|
90
|
+
const scope = await housePart(room, answer.body, listed, 'site');
|
|
91
|
+
if (scope !== null)
|
|
92
|
+
return scope;
|
|
106
93
|
}
|
|
107
|
-
|
|
108
|
-
if (file === undefined || (await sha256Hex(text)) !== file.version)
|
|
109
|
-
return UNCERTAIN;
|
|
110
|
-
return { ...scope, contents: [...scope.contents.slice(0, -1), { path, content: text }] };
|
|
94
|
+
return unverifiedPart(entry.locator);
|
|
111
95
|
}
|
|
112
|
-
async function caughtUp(entry,
|
|
113
|
-
const
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
const scope = await assembled(entry, part.scope, next, offset);
|
|
122
|
-
return 'kind' in scope ? { failure: scope } : { scope, next };
|
|
123
|
-
}
|
|
124
|
-
const { scope } = part;
|
|
125
|
-
if (after !== null || next !== null || roomVersion(scope) === roomVersion(entry)) {
|
|
126
|
-
return { scope, next };
|
|
127
|
-
}
|
|
96
|
+
async function caughtUp(entry, continued) {
|
|
97
|
+
const listed = continued.room.parts[continued.next];
|
|
98
|
+
const scope = listed === undefined
|
|
99
|
+
? emptyScope(continued.room)
|
|
100
|
+
: await fetchedPart(entry, continued.room, listed);
|
|
101
|
+
if ('kind' in scope)
|
|
102
|
+
return scope;
|
|
103
|
+
if (continued.room.parts.length > 1 || roomVersion(scope) === roomVersion(entry))
|
|
104
|
+
return scope;
|
|
128
105
|
const view = await enumeration(entry, scope);
|
|
129
106
|
if ('kind' in view)
|
|
130
|
-
return
|
|
131
|
-
return
|
|
107
|
+
return settled(view);
|
|
108
|
+
return stepped(advancedScope(scope, view));
|
|
132
109
|
}
|
|
133
110
|
async function refreshed(entry, fromRoomVersion) {
|
|
134
111
|
const from = logPosition(fromRoomVersion);
|
|
135
112
|
if (from === null)
|
|
136
113
|
return { kind: 'beyond-horizon' };
|
|
137
|
-
const streamed = notifications.advance(entry, from);
|
|
114
|
+
const streamed = await stepped(notifications.advance(entry, from));
|
|
138
115
|
if (streamed !== null) {
|
|
139
116
|
const models = await streamedModels(streamed.schemas, entry, 'site');
|
|
140
117
|
return models === undefined ? streamed.page : { ...streamed.page, models };
|
|
@@ -143,7 +120,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
143
120
|
if ('kind' in view)
|
|
144
121
|
return view;
|
|
145
122
|
notifications.reach(entry.authority, view);
|
|
146
|
-
const answer = refreshFrom(view, fromRoomVersion);
|
|
123
|
+
const answer = await refreshFrom(view, fromRoomVersion);
|
|
147
124
|
if (answer.kind !== 'net-advancement')
|
|
148
125
|
return answer;
|
|
149
126
|
const models = await viewModels(view, entry);
|
|
@@ -174,23 +151,30 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
174
151
|
const entry = tracked.get(request.locator);
|
|
175
152
|
if (entry === undefined)
|
|
176
153
|
return { kind: 'room-not-readable', locator: request.locator };
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
154
|
+
let continued;
|
|
155
|
+
if (request.pageToken === undefined) {
|
|
156
|
+
const room = await partedRoom(entry);
|
|
157
|
+
if ('kind' in room)
|
|
158
|
+
return room;
|
|
159
|
+
continued = { room, next: 0, seen: [] };
|
|
160
|
+
}
|
|
161
|
+
else
|
|
162
|
+
continued = JSON.parse(request.pageToken);
|
|
163
|
+
const scope = await caughtUp(entry, continued);
|
|
164
|
+
if ('kind' in scope)
|
|
165
|
+
return scope;
|
|
166
|
+
notifications.reach(entry.authority, scope);
|
|
167
|
+
const next = continued.next + 1;
|
|
168
|
+
const more = next < continued.room.parts.length;
|
|
184
169
|
const seen = [
|
|
185
|
-
...
|
|
186
|
-
...entry.schemas.filter((schema) =>
|
|
170
|
+
...continued.seen,
|
|
171
|
+
...entry.schemas.filter((schema) => scope.files.some((file) => file.path === schema)),
|
|
187
172
|
];
|
|
188
|
-
const models = await partModels(
|
|
189
|
-
const continuation = held.next === null ? null : { after: held.next, seen };
|
|
173
|
+
const models = await partModels(scope, entry, new Set(seen), !more);
|
|
190
174
|
return {
|
|
191
|
-
...
|
|
175
|
+
...(await stepped(bootstrapping(scope))),
|
|
192
176
|
...(models === undefined ? {} : { models }),
|
|
193
|
-
...(
|
|
177
|
+
...(more ? { pageToken: JSON.stringify({ ...continued, next, seen }) } : {}),
|
|
194
178
|
};
|
|
195
179
|
},
|
|
196
180
|
async refresh(_authorization, request) {
|
|
@@ -238,7 +222,7 @@ export function createSiteAdapter(transport, snapshot = false) {
|
|
|
238
222
|
if (named === null)
|
|
239
223
|
return null;
|
|
240
224
|
const { path } = named.referrer;
|
|
241
|
-
return {
|
|
225
|
+
return { locator: named.locator, ...(path === undefined ? {} : { path }) };
|
|
242
226
|
},
|
|
243
227
|
reached(locator, version, target) {
|
|
244
228
|
return reachedVersion(version, target, tracked.get(locator)?.logEpoch);
|
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,7 @@ export type HouseNotifications = {
|
|
|
16
15
|
reopen(): void;
|
|
17
16
|
track(authorities: readonly TrackedAuthority[]): void;
|
|
18
17
|
reach(authority: string, at: LogPosition): void;
|
|
19
|
-
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): StreamedAdvancement | null
|
|
18
|
+
advance(tracked: TrackedAuthority, from: LogPosition, holds?: HeldRevision): Generator<number, StreamedAdvancement | null, void>;
|
|
20
19
|
conversations: ConversationStream;
|
|
21
20
|
serviceMode: ServiceModeSignal;
|
|
22
21
|
};
|
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;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,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,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,CA0iB5F"}
|
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, 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,7 @@ export function houseNotifications(transport, mode) {
|
|
|
554
556
|
held,
|
|
555
557
|
});
|
|
556
558
|
},
|
|
557
|
-
advance(tracked, from, holds) {
|
|
559
|
+
*advance(tracked, from, holds) {
|
|
558
560
|
const line = lines.get(tracked.authority);
|
|
559
561
|
const start = position(from.position);
|
|
560
562
|
if (line === undefined || start === null || line.logEpoch !== from.logEpoch)
|
|
@@ -563,36 +565,22 @@ export function houseNotifications(transport, mode) {
|
|
|
563
565
|
const first = pending[0];
|
|
564
566
|
if (first === undefined || first.after > start)
|
|
565
567
|
return null;
|
|
566
|
-
const
|
|
567
|
-
const revisions = {};
|
|
568
|
-
const changes = {};
|
|
569
|
-
const binaryFiles = {};
|
|
570
|
-
const removals = [];
|
|
571
|
-
const applied = [];
|
|
568
|
+
const answer = answering();
|
|
572
569
|
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
570
|
for (const frame of pending) {
|
|
583
571
|
for (const entry of frame.entries) {
|
|
572
|
+
yield ROW_WEIGHT + (entry.text?.length ?? 0);
|
|
584
573
|
if (entry.kind === 'edited' &&
|
|
585
574
|
entry.revision !== undefined &&
|
|
586
575
|
holds?.(entry.path, entry.revision) === true) {
|
|
587
|
-
|
|
576
|
+
forgotten(answer, entry.path);
|
|
588
577
|
continue;
|
|
589
578
|
}
|
|
590
|
-
applied.push(entry);
|
|
591
579
|
if (tracked.schemas.includes(entry.path))
|
|
592
580
|
schemas.set(entry.path, entry);
|
|
593
581
|
if (entry.kind === 'removed') {
|
|
594
|
-
|
|
595
|
-
removals.
|
|
582
|
+
forgotten(answer, entry.path);
|
|
583
|
+
answer.removals.add(entry.path);
|
|
596
584
|
continue;
|
|
597
585
|
}
|
|
598
586
|
const binary = binaryFileOf(entry);
|
|
@@ -603,32 +591,33 @@ export function houseNotifications(transport, mode) {
|
|
|
603
591
|
const head = headChange(entry);
|
|
604
592
|
if (head === null)
|
|
605
593
|
return null;
|
|
606
|
-
|
|
594
|
+
forgotten(answer, entry.path);
|
|
607
595
|
if (binary === undefined)
|
|
608
|
-
documents
|
|
596
|
+
answer.documents.set(entry.path, entry.text);
|
|
609
597
|
else
|
|
610
|
-
binaryFiles
|
|
598
|
+
answer.binaryFiles.set(entry.path, binary);
|
|
611
599
|
const revision = entry.revision ?? binary?.sha256;
|
|
612
600
|
if (revision !== undefined)
|
|
613
|
-
|
|
601
|
+
revised(answer, entry.path, revision);
|
|
614
602
|
if (head !== undefined)
|
|
615
|
-
changes
|
|
603
|
+
answer.changes.set(entry.path, head);
|
|
616
604
|
}
|
|
617
605
|
}
|
|
618
606
|
const last = pending.at(-1);
|
|
619
|
-
lines.
|
|
607
|
+
const current = lines.get(tracked.authority);
|
|
608
|
+
if (current?.logEpoch === line.logEpoch) {
|
|
609
|
+
lines.set(tracked.authority, {
|
|
610
|
+
...current,
|
|
611
|
+
frames: current.frames.filter((frame) => frame.position > start),
|
|
612
|
+
held: current.held !== null && current.held > last.position ? current.held : last.position,
|
|
613
|
+
});
|
|
614
|
+
}
|
|
620
615
|
return {
|
|
621
616
|
page: {
|
|
622
617
|
kind: 'net-advancement',
|
|
623
618
|
roomVersion: roomVersion({ position: last.position.toString(), logEpoch: line.logEpoch }),
|
|
624
|
-
|
|
625
|
-
revisions,
|
|
626
|
-
...identities(revisions),
|
|
627
|
-
changes,
|
|
628
|
-
binaryFiles,
|
|
629
|
-
removals: removals.sort(),
|
|
619
|
+
...(yield* answered(answer)),
|
|
630
620
|
},
|
|
631
|
-
entries: applied,
|
|
632
621
|
schemas,
|
|
633
622
|
};
|
|
634
623
|
},
|
package/dist/transport.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type HouseDoorAnswer = {
|
|
|
17
17
|
export declare const DOOR_FILES_GET = "/door/files/get";
|
|
18
18
|
export declare const SITE_FILES = "/_house/files/";
|
|
19
19
|
export declare const SITE_FILE_RECORD = "record";
|
|
20
|
-
export type HouseByteAct = 'authored_batch_upload' | '
|
|
20
|
+
export type HouseByteAct = 'authored_batch_upload' | 'file_upload' | 'binary_stage';
|
|
21
21
|
export type HouseByteBody = string | ArrayBuffer | Uint8Array | Blob;
|
|
22
22
|
export type HouseBytesAnswer = {
|
|
23
23
|
status: number;
|
|
@@ -58,6 +58,7 @@ export type HouseListedConversation = {
|
|
|
58
58
|
created_at: string;
|
|
59
59
|
finished_at: string | null;
|
|
60
60
|
outcome: string | null;
|
|
61
|
+
waiting: boolean;
|
|
61
62
|
};
|
|
62
63
|
export type HouseStreamFrame = {
|
|
63
64
|
type: 'part';
|
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,CAAC;AAEhD,eAAO,MAAM,kBAAkB,0BAA0B,CAAC;AAE1D,eAAO,MAAM,mBAAmB,4BAA4B,CAAC;AAE7D,eAAO,MAAM,mBAAmB,2BAA2B,CAAC;AAE5D,eAAO,MAAM,gBAAgB,wBAAwB,CAAC;AAEtD,MAAM,MAAM,SAAS,GAAG,YAAY,GAAG,MAAM,CAAC;AAE9C,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,cAAc,oBAAoB,CAAC;AAEhD,e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Q,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;CACpD,CAAC"}
|
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","sourceRoot":"","sources":["../src/write.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,W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M,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAAE,GAC3C,aAAa,CAyDf"}
|
package/dist/write.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { departure, } from '@agentshouse/mdruntime';
|
|
2
|
-
import { binaryFileOf, headChange,
|
|
1
|
+
import { departure, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { answered, answering, binaryFileOf, headChange, revised } from './read.js';
|
|
3
3
|
import { sha256Hex, textBytes } from './digest.js';
|
|
4
4
|
import { nativePath, roomLocalPath } from './map.js';
|
|
5
5
|
import { classifyDoor, doorRefusal, scopedRefusal } from './refusal.js';
|
|
@@ -120,6 +120,24 @@ export function houseChanges(batch, handle) {
|
|
|
120
120
|
}
|
|
121
121
|
return { kind: 'changes', changes };
|
|
122
122
|
}
|
|
123
|
+
export function houseMove(batch, source, destination) {
|
|
124
|
+
const changes = [];
|
|
125
|
+
for (const { path, to } of batch.between?.moves ?? []) {
|
|
126
|
+
const existence = priorExistence(batch, path);
|
|
127
|
+
if (existence === undefined)
|
|
128
|
+
return { kind: 'unmapped', path, rule: 'precondition-missing' };
|
|
129
|
+
if (!('base' in existence)) {
|
|
130
|
+
return { kind: 'unmapped', path, rule: 'presence-base-unrepresentable' };
|
|
131
|
+
}
|
|
132
|
+
changes.push({
|
|
133
|
+
op: 'rename',
|
|
134
|
+
path: nativePath(path, source),
|
|
135
|
+
to: nativePath(to, destination),
|
|
136
|
+
base: existence.base,
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
return { kind: 'changes', changes };
|
|
140
|
+
}
|
|
123
141
|
export function operationHead(batch) {
|
|
124
142
|
const writer = batch.writtenBy;
|
|
125
143
|
return writer === undefined
|
|
@@ -129,7 +147,7 @@ export function operationHead(batch) {
|
|
|
129
147
|
export function batchPaths(changes) {
|
|
130
148
|
return [
|
|
131
149
|
...new Set(changes.flatMap((change) => change.op === 'rename' ? [String(change.path), String(change.to)] : [String(change.path)])),
|
|
132
|
-
]
|
|
150
|
+
];
|
|
133
151
|
}
|
|
134
152
|
export function deltaBody(changes) {
|
|
135
153
|
return JSON.stringify({ changes });
|
|
@@ -144,16 +162,19 @@ export function uploadable(inline, bytes, bounds) {
|
|
|
144
162
|
export function deltaDigest(delta) {
|
|
145
163
|
return sha256Hex(delta);
|
|
146
164
|
}
|
|
147
|
-
function material(value, handle) {
|
|
165
|
+
function* material(value, handle, within = () => true) {
|
|
148
166
|
if (!Array.isArray(value))
|
|
149
167
|
return null;
|
|
150
168
|
const held = [];
|
|
151
169
|
for (const entry of value) {
|
|
170
|
+
yield ROW_WEIGHT;
|
|
152
171
|
if (typeof entry !== 'object' || entry === null)
|
|
153
172
|
return null;
|
|
154
173
|
const file = entry;
|
|
155
174
|
if (typeof file.path !== 'string')
|
|
156
175
|
return null;
|
|
176
|
+
if (!within(file.path))
|
|
177
|
+
continue;
|
|
157
178
|
if (file.content !== null && typeof file.content !== 'string')
|
|
158
179
|
return null;
|
|
159
180
|
if (file.revision !== null && file.revision !== undefined && typeof file.revision !== 'string')
|
|
@@ -181,15 +202,59 @@ function material(value, handle) {
|
|
|
181
202
|
}
|
|
182
203
|
return held;
|
|
183
204
|
}
|
|
184
|
-
function affectedOf(held) {
|
|
205
|
+
function* affectedOf(held) {
|
|
185
206
|
const affected = {};
|
|
186
207
|
for (const entry of held) {
|
|
187
208
|
if (entry.content !== null)
|
|
188
209
|
affected[entry.path] = entry.content;
|
|
210
|
+
yield ROW_WEIGHT;
|
|
189
211
|
}
|
|
190
212
|
return affected;
|
|
191
213
|
}
|
|
192
|
-
|
|
214
|
+
function* acceptedOf(at, contents) {
|
|
215
|
+
const answer = answering();
|
|
216
|
+
for (const entry of contents) {
|
|
217
|
+
yield ROW_WEIGHT + (entry.content?.length ?? 0);
|
|
218
|
+
if (entry.revision === null) {
|
|
219
|
+
answer.removals.add(entry.path);
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
if (entry.content !== null)
|
|
223
|
+
answer.documents.set(entry.path, entry.content);
|
|
224
|
+
if (entry.binary !== undefined)
|
|
225
|
+
answer.binaryFiles.set(entry.path, entry.binary);
|
|
226
|
+
revised(answer, entry.path, entry.revision);
|
|
227
|
+
if (entry.head !== undefined)
|
|
228
|
+
answer.changes.set(entry.path, entry.head);
|
|
229
|
+
}
|
|
230
|
+
const unbinaried = answer.binaryFiles.size === 0;
|
|
231
|
+
const { binaryFiles, ...room } = yield* answered(answer);
|
|
232
|
+
return { roomVersion: roomVersion(at), ...room, ...(unbinaried ? {} : { binaryFiles }) };
|
|
233
|
+
}
|
|
234
|
+
function* movedOutcome(held, move) {
|
|
235
|
+
const authorities = Array.isArray(held.authorities) ? held.authorities : [];
|
|
236
|
+
const at = (authority) => {
|
|
237
|
+
const entry = authorities.find((one) => typeof one === 'object' &&
|
|
238
|
+
one !== null &&
|
|
239
|
+
one.authority === authority);
|
|
240
|
+
return entry === undefined ? null : readPosition(entry);
|
|
241
|
+
};
|
|
242
|
+
const left = at(move.source.authority);
|
|
243
|
+
const arrived = at(move.destination.authority);
|
|
244
|
+
if (left === null || arrived === null)
|
|
245
|
+
return { kind: 'transport-uncertainty' };
|
|
246
|
+
const under = (handle) => (path) => path.startsWith(`/rooms/${handle}/`);
|
|
247
|
+
const leaving = yield* material(held.contents, move.source.handle, under(move.source.handle));
|
|
248
|
+
const arriving = yield* material(held.contents, move.destination.handle, under(move.destination.handle));
|
|
249
|
+
if (leaving === null || arriving === null)
|
|
250
|
+
return { kind: 'transport-uncertainty' };
|
|
251
|
+
return {
|
|
252
|
+
kind: 'accepted',
|
|
253
|
+
...(yield* acceptedOf(left, leaving)),
|
|
254
|
+
destination: yield* acceptedOf(arrived, arriving),
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
export function* mutationOutcome(status, body, locator, handle, move) {
|
|
193
258
|
const refusal = doorRefusal(body);
|
|
194
259
|
if (refusal !== null && refusal.code === 'service_mode_write_halted') {
|
|
195
260
|
return { kind: 'write-halted' };
|
|
@@ -201,10 +266,10 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
201
266
|
}
|
|
202
267
|
if (refusal !== null && refusal.code === 'edit_conflict') {
|
|
203
268
|
const { current, ...fields } = refusal.fields;
|
|
204
|
-
const held = material(current, handle) ?? [];
|
|
269
|
+
const held = (yield* material(current, handle)) ?? [];
|
|
205
270
|
return {
|
|
206
271
|
kind: 'conflicted',
|
|
207
|
-
affected: affectedOf(held),
|
|
272
|
+
affected: yield* affectedOf(held),
|
|
208
273
|
code: refusal.code,
|
|
209
274
|
fields,
|
|
210
275
|
retryable: refusal.retryable,
|
|
@@ -228,8 +293,9 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
228
293
|
}
|
|
229
294
|
if (classified !== null && classified.kind !== 'scoped-refusal')
|
|
230
295
|
return classified;
|
|
231
|
-
if (classified !== null && status === 403)
|
|
296
|
+
if (classified !== null && status === 403 && refusal?.code === 'operation_denied') {
|
|
232
297
|
return classified;
|
|
298
|
+
}
|
|
233
299
|
if (refusal !== null && status >= 400) {
|
|
234
300
|
return {
|
|
235
301
|
kind: 'rejected',
|
|
@@ -243,40 +309,15 @@ export function mutationOutcome(status, body, locator, handle) {
|
|
|
243
309
|
return { kind: 'transport-uncertainty' };
|
|
244
310
|
}
|
|
245
311
|
const held = body;
|
|
312
|
+
if (move !== undefined)
|
|
313
|
+
return yield* movedOutcome(held, move);
|
|
246
314
|
const at = readPosition(held);
|
|
247
315
|
if (at === null)
|
|
248
316
|
return { kind: 'transport-uncertainty' };
|
|
249
|
-
const contents = material(held.contents, handle);
|
|
317
|
+
const contents = yield* material(held.contents, handle);
|
|
250
318
|
if (contents === null)
|
|
251
319
|
return { kind: 'transport-uncertainty' };
|
|
252
|
-
|
|
253
|
-
const revisions = {};
|
|
254
|
-
const changes = {};
|
|
255
|
-
const binaryFiles = {};
|
|
256
|
-
const removals = [];
|
|
257
|
-
for (const entry of contents) {
|
|
258
|
-
if (entry.revision === null) {
|
|
259
|
-
removals.push(entry.path);
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
if (entry.content !== null)
|
|
263
|
-
documents[entry.path] = entry.content;
|
|
264
|
-
if (entry.binary !== undefined)
|
|
265
|
-
binaryFiles[entry.path] = entry.binary;
|
|
266
|
-
revisions[entry.path] = entry.revision;
|
|
267
|
-
if (entry.head !== undefined)
|
|
268
|
-
changes[entry.path] = entry.head;
|
|
269
|
-
}
|
|
270
|
-
return {
|
|
271
|
-
kind: 'accepted',
|
|
272
|
-
roomVersion: roomVersion(at),
|
|
273
|
-
documents,
|
|
274
|
-
revisions,
|
|
275
|
-
...identities(revisions),
|
|
276
|
-
changes,
|
|
277
|
-
removals: removals.sort(),
|
|
278
|
-
...(Object.keys(binaryFiles).length === 0 ? {} : { binaryFiles }),
|
|
279
|
-
};
|
|
320
|
+
return { kind: 'accepted', ...(yield* acceptedOf(at, contents)) };
|
|
280
321
|
}
|
|
281
322
|
export function rejectedMapping(mapping) {
|
|
282
323
|
return {
|