@agentshouse/mdruntime-adapter 0.1.0-c8d322eea4abd → 0.1.0-c8f2ffa9f2e89
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/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +7 -6
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +51 -36
- package/dist/authored-path.js +1 -1
- package/dist/chunks.d.ts +1 -1
- package/dist/chunks.d.ts.map +1 -1
- package/dist/chunks.js +37 -15
- package/dist/history.d.ts +1 -6
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +21 -28
- package/dist/house-model.d.ts +133 -4
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +157 -98
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/refusal.d.ts +2 -1
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +12 -6
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +62 -46
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +4 -4
- package/dist/session-content/index.d.ts +1 -1
- package/dist/session-content/parts.d.ts +4 -3
- package/dist/session-content/turn.d.ts +3 -3
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +12 -10
- package/dist/space-schema.d.ts +1 -1
- package/dist/space-schema.d.ts.map +1 -1
- package/dist/space-schema.js +2 -2
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +34 -11
- package/dist/transport.d.ts +3 -5
- package/dist/transport.d.ts.map +1 -1
- package/dist/uncertain.d.ts +5 -0
- package/dist/uncertain.d.ts.map +1 -0
- package/dist/uncertain.js +11 -0
- package/dist/upload.d.ts +3 -1
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +8 -6
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +17 -15
- package/package.json +2 -2
package/dist/actions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"actions.d.ts","sourceRoot":"","sources":["../src/actions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG7F,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAEtE,MAAM,MAAM,YAAY,GAAG,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AAExD,eAAO,MAAM,kBAAkB,EAAE,SAAS,MAAM,EAG/C,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,SAAS,MAAM,EAKhD,CAAC;AAEF,wBAAgB,eAAe,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,GAAG,SAAS,iBAAiB,EAAE,CAEvF;AAED,wBAAgB,WAAW,CACzB,SAAS,EAAE,YAAY,EACvB,OAAO,EAAE,aAAa,GACrB,OAAO,CAAC,YAAY,CAAC,CAIvB;AAwBD,wBAAgB,aAAa,CAAC,MAAM,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,YAAY,CAajG"}
|
package/dist/actions.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { doorRefusal, resetOf } from './refusal.js';
|
|
1
|
+
import { answeredFailure, doorRefusal, resetOf } from './refusal.js';
|
|
2
|
+
import { refusedFor } from './uncertain.js';
|
|
2
3
|
export const HOUSE_UNKEPT_READS = [
|
|
3
4
|
'account/security/read',
|
|
4
5
|
'clients/last-use/list',
|
|
@@ -42,17 +43,17 @@ export function actionOutcome(answer, name, input) {
|
|
|
42
43
|
if (answer.status === 401)
|
|
43
44
|
return { kind: 'revoked-authorization' };
|
|
44
45
|
const refusal = doorRefusal(answer.body);
|
|
45
|
-
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
46
|
-
return
|
|
47
|
-
}
|
|
46
|
+
if (refusal?.code === 'operation_contended' && numbered(input))
|
|
47
|
+
return refusedFor(refusal);
|
|
48
48
|
if (refusal !== null) {
|
|
49
49
|
const reset = resetOf(refusal);
|
|
50
50
|
return { kind: 'rejected', ...refusal, ...(reset === undefined ? {} : { reset }) };
|
|
51
51
|
}
|
|
52
52
|
if (answer.status === 404)
|
|
53
53
|
return unimplemented(name);
|
|
54
|
-
if (answer.status === 0 || answer.status >= 400)
|
|
55
|
-
return
|
|
54
|
+
if (answer.status === 0 || answer.status >= 400) {
|
|
55
|
+
return answeredFailure(answer.status, answer.body);
|
|
56
|
+
}
|
|
56
57
|
return { kind: 'action', result: answer.body };
|
|
57
58
|
}
|
|
58
59
|
async function carry(transport, route, name, input) {
|
package/dist/adapter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAIV,OAAO,EAIP,aAAa,EAiBd,MAAM,wBAAwB,CAAC;AA0BhC,OAAO,EAIL,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACpB,MAAM,gBAAgB,CAAC;AAqBxB,MAAM,MAAM,yBAAyB,GACjC;IACE,SAAS,EAAE,cAAc,CAAC;IAC1B,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC,CAAC;CACrC,GACD;IAAE,IAAI,EAAE,kBAAkB,CAAC;IAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;CAAE,CAAC;AAqBrD,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,yBAAyB,GAAG,OAAO,CA2bpF"}
|
package/dist/adapter.js
CHANGED
|
@@ -7,7 +7,8 @@ import { spaceSchemas } from './space-schema.js';
|
|
|
7
7
|
import { finishedUpload, houseUpload } from './upload.js';
|
|
8
8
|
import { houseAction, HOUSE_LEADING_READS, HOUSE_UNKEPT_READS } from './actions.js';
|
|
9
9
|
import { houseSearch } from './search.js';
|
|
10
|
-
import { classifyDoor, doorRefusal } from './refusal.js';
|
|
10
|
+
import { answeredFailure, classifyDoor, doorRefusal } from './refusal.js';
|
|
11
|
+
import { UNANSWERED, unusable } from './uncertain.js';
|
|
11
12
|
import { houseNotifications, } from './stream.js';
|
|
12
13
|
import { houseDoorRoute, } from './transport.js';
|
|
13
14
|
import { batchPaths, deltaBody, deltaBytes, deltaDigest, historyOutcome, houseChanges, houseMove, mutationOutcome, operationHead, rejectedMapping, revisionBody, uploadable, } from './write.js';
|
|
@@ -15,13 +16,15 @@ import { admittedPath } from './authored-path.js';
|
|
|
15
16
|
import { HOUSE_TYPED_PATHS } from './house-model.js';
|
|
16
17
|
import { HOUSE_NAMEABLE_ROOM_TYPES, HOUSE_ROOM_TYPES } from './room-types.js';
|
|
17
18
|
import { followsVersion, reachedVersion, roomVersion } from './version.js';
|
|
18
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
19
|
-
const UNCERTAIN_READ = { kind: 'transport-uncertainty' };
|
|
20
19
|
const OCTET_STREAM = 'application/octet-stream';
|
|
21
20
|
const EXPIRED_ADDRESS = 403;
|
|
22
21
|
function lapsedGrant(outcome) {
|
|
23
22
|
return outcome.kind === 'rejected' && outcome.code === 'upload_unavailable';
|
|
24
23
|
}
|
|
24
|
+
function unstagedRefusal(answer) {
|
|
25
|
+
const refusal = doorRefusal(answer.body);
|
|
26
|
+
return refusal?.code === 'files_unstaged' ? refusal : null;
|
|
27
|
+
}
|
|
25
28
|
export function createAgentsHouseAdapter(options) {
|
|
26
29
|
if ('site' in options)
|
|
27
30
|
return createSiteAdapter(options.site, options.snapshot === true);
|
|
@@ -86,15 +89,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
86
89
|
const room = chunked.get(entry.locator);
|
|
87
90
|
const address = room?.chunks.get(id);
|
|
88
91
|
if (room === undefined || address === undefined)
|
|
89
|
-
return
|
|
92
|
+
return UNANSWERED;
|
|
90
93
|
const read = await transport.download(address.url);
|
|
91
94
|
if (read.status !== EXPIRED_ADDRESS)
|
|
92
95
|
return { room, read };
|
|
93
96
|
const renewed = await renewal(entry, room);
|
|
94
|
-
if ('kind' in renewed
|
|
95
|
-
return
|
|
97
|
+
if ('kind' in renewed)
|
|
98
|
+
return renewed;
|
|
99
|
+
const renewedAddress = renewed.chunks.get(id);
|
|
100
|
+
if (renewedAddress === undefined)
|
|
101
|
+
return unusable();
|
|
96
102
|
chunked.set(entry.locator, renewed);
|
|
97
|
-
return { room: renewed, read: await transport.download(
|
|
103
|
+
return { room: renewed, read: await transport.download(renewedAddress.url) };
|
|
98
104
|
}
|
|
99
105
|
function renewal(entry, stale) {
|
|
100
106
|
const held = renewals.get(stale);
|
|
@@ -116,8 +122,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
116
122
|
}
|
|
117
123
|
async function chunkPage(entry, id, arriving) {
|
|
118
124
|
const fetched = await chunkRead(entry, id);
|
|
119
|
-
if (
|
|
120
|
-
return
|
|
125
|
+
if ('kind' in fetched)
|
|
126
|
+
return fetched;
|
|
127
|
+
if (fetched.read.status !== 200)
|
|
128
|
+
return answeredFailure(fetched.read.status, null);
|
|
121
129
|
return chunkPart(fetched.read.body, fetched.room, id, arriving);
|
|
122
130
|
}
|
|
123
131
|
function authorityFor(locator) {
|
|
@@ -156,37 +164,38 @@ export function createAgentsHouseAdapter(options) {
|
|
|
156
164
|
}
|
|
157
165
|
const grant = parseGrant(minted.body);
|
|
158
166
|
if (grant === null)
|
|
159
|
-
return { outcome:
|
|
167
|
+
return { outcome: unusable() };
|
|
160
168
|
const delivered = await transport.transfer({
|
|
161
169
|
url: grant.url,
|
|
162
170
|
body: `${grant.operation}\n${delta}`,
|
|
163
171
|
});
|
|
164
|
-
if (delivered.status !== 200)
|
|
165
|
-
return { outcome:
|
|
172
|
+
if (delivered.status !== 200) {
|
|
173
|
+
return { outcome: answeredFailure(delivered.status, delivered.body) };
|
|
174
|
+
}
|
|
166
175
|
const holding = parseGrant(delivered.body);
|
|
167
176
|
if (holding === null)
|
|
168
|
-
return { outcome:
|
|
177
|
+
return { outcome: unusable() };
|
|
169
178
|
const upload = { url: holding.url, operation: holding.operation, bytes, sha256 };
|
|
170
179
|
await keep(upload);
|
|
171
180
|
return { body: { ...head, paths, upload, runtime: notifications.runtime } };
|
|
172
181
|
}
|
|
173
|
-
async function staged(
|
|
174
|
-
const refusal = doorRefusal(answer.body);
|
|
175
|
-
if (refusal?.code !== 'files_unstaged')
|
|
176
|
-
return null;
|
|
177
|
-
const uploads = refusal.fields.upload;
|
|
182
|
+
async function staged(uploads, { changeBatch: batch, file }) {
|
|
178
183
|
if (!Array.isArray(uploads))
|
|
179
|
-
return
|
|
184
|
+
return unusable();
|
|
180
185
|
for (const named of uploads) {
|
|
181
186
|
const upload = houseUpload(named);
|
|
182
187
|
const change = batch.changes.find((held) => held.kind === 'binary' && held.sha256 === named.sha256);
|
|
183
188
|
if (upload === null || change === undefined)
|
|
184
|
-
return
|
|
189
|
+
return unusable();
|
|
185
190
|
const finished = await finishedUpload(transport, upload, await file(change.localId));
|
|
186
|
-
if (
|
|
187
|
-
return
|
|
191
|
+
if ('unfinished' in finished)
|
|
192
|
+
return answeredFailure(finished.unfinished, null);
|
|
193
|
+
if (finished.status !== 200)
|
|
194
|
+
return answeredFailure(finished.status, finished.body);
|
|
195
|
+
if (finished.body?.staged !== true)
|
|
196
|
+
return unusable();
|
|
188
197
|
}
|
|
189
|
-
return
|
|
198
|
+
return null;
|
|
190
199
|
}
|
|
191
200
|
async function submit(request, head, changes, delta, bytes, entry, handed, keep, into) {
|
|
192
201
|
const inline = { ...head, changes, runtime: notifications.runtime };
|
|
@@ -196,14 +205,18 @@ export function createAgentsHouseAdapter(options) {
|
|
|
196
205
|
if ('outcome' in prepared)
|
|
197
206
|
return prepared.outcome;
|
|
198
207
|
const answer = await transport.door(houseDoorRoute('files/batch'), prepared.body);
|
|
199
|
-
const
|
|
200
|
-
if (
|
|
201
|
-
|
|
202
|
-
|
|
208
|
+
const unstaged = unstagedRefusal(answer);
|
|
209
|
+
if (unstaged !== null) {
|
|
210
|
+
const staging = await staged(unstaged.fields.upload, request);
|
|
211
|
+
if (staging !== null)
|
|
212
|
+
return staging;
|
|
213
|
+
}
|
|
214
|
+
const settled = unstaged === null
|
|
203
215
|
? answer
|
|
204
216
|
: await transport.door(houseDoorRoute('files/batch'), prepared.body);
|
|
205
|
-
if (
|
|
206
|
-
return
|
|
217
|
+
if (unstaged !== null && unstagedRefusal(settled) !== null) {
|
|
218
|
+
return answeredFailure(settled.status, settled.body);
|
|
219
|
+
}
|
|
207
220
|
return stepped(mutationOutcome(settled.status, settled.body, entry.locator, entry.handle, into === undefined
|
|
208
221
|
? undefined
|
|
209
222
|
: {
|
|
@@ -224,7 +237,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
224
237
|
: failure;
|
|
225
238
|
}
|
|
226
239
|
const address = parseFileAddress(answer.body);
|
|
227
|
-
return address === null ?
|
|
240
|
+
return address === null ? unusable() : { kind: 'address', ...address };
|
|
228
241
|
}
|
|
229
242
|
function linked(answer, locator) {
|
|
230
243
|
const address = addressed(answer, locator);
|
|
@@ -256,8 +269,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
256
269
|
return address;
|
|
257
270
|
read = await transport.download(address.url);
|
|
258
271
|
}
|
|
259
|
-
if (read.status !== 200
|
|
260
|
-
return
|
|
272
|
+
if (read.status !== 200)
|
|
273
|
+
return answeredFailure(read.status, null);
|
|
274
|
+
if (read.body === null)
|
|
275
|
+
return unusable();
|
|
261
276
|
return {
|
|
262
277
|
kind: 'binary',
|
|
263
278
|
body: read.body,
|
|
@@ -358,10 +373,10 @@ export function createAgentsHouseAdapter(options) {
|
|
|
358
373
|
return refused;
|
|
359
374
|
const upload = houseUpload(declared.body?.upload);
|
|
360
375
|
if (upload === null)
|
|
361
|
-
return
|
|
376
|
+
return unusable();
|
|
362
377
|
const finished = await finishedUpload(transport, upload, request.blob);
|
|
363
|
-
if (
|
|
364
|
-
return
|
|
378
|
+
if ('unfinished' in finished)
|
|
379
|
+
return answeredFailure(finished.unfinished, null);
|
|
365
380
|
const unfinished = refusedAttach(finished, request.locator);
|
|
366
381
|
if (unfinished !== null)
|
|
367
382
|
return unfinished;
|
|
@@ -369,7 +384,7 @@ export function createAgentsHouseAdapter(options) {
|
|
|
369
384
|
const root = `/rooms/${entry.handle}/`;
|
|
370
385
|
return typeof path === 'string' && path.startsWith(root) && typeof revision === 'string'
|
|
371
386
|
? { kind: 'attached', path: path.slice(root.length), revision }
|
|
372
|
-
:
|
|
387
|
+
: unusable();
|
|
373
388
|
},
|
|
374
389
|
reached(locator, version, target) {
|
|
375
390
|
return reachedVersion(version, target, authorityFor(locator)?.logEpoch);
|
package/dist/authored-path.js
CHANGED
|
@@ -11,7 +11,7 @@ export const WHOLE_ESCAPED_NAMES = [
|
|
|
11
11
|
];
|
|
12
12
|
export const AUTHORED_SEGMENT_MAX_CHARS = 255;
|
|
13
13
|
const REFUSED_SEGMENTS = [
|
|
14
|
-
...WHOLE_ESCAPED_NAMES.map((name) => name.
|
|
14
|
+
...WHOLE_ESCAPED_NAMES.map((name) => name.split('.').join('[.]')),
|
|
15
15
|
'[.][Gg][Ii][Tt][.]*',
|
|
16
16
|
].join('|');
|
|
17
17
|
export const AUTHORED_SEGMENT = new RegExp(`^(?!(?:${REFUSED_SEGMENTS})(?:/|$))[A-Za-z0-9._][A-Za-z0-9._-]{0,${AUTHORED_SEGMENT_MAX_CHARS - 1}}$`);
|
package/dist/chunks.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type AdapterFailure, type BootstrapPart, type BootstrapResult } from '@agentshouse/mdruntime';
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import { type HouseModels, type HouseScope } from './read.js';
|
|
4
|
-
import type
|
|
4
|
+
import { type SpaceSchemas } from './space-schema.js';
|
|
5
5
|
import { type HouseDoor, type HouseMode } from './transport.js';
|
|
6
6
|
import { type LogPosition } from './version.js';
|
|
7
7
|
export type ChunkAddress = {
|
package/dist/chunks.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,eAAe,EACrB,MAAM,wBAAwB,CAAC;AAChC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAML,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAGnB,OAAO,EAAgB,KAAK,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAkB,KAAK,SAAS,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,cAAc,CAAC;AAEnF,KAAK,QAAQ,GAAG;IAAE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,CAAC;AAsDpE,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAgCD,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAIvE;AAED,wBAAsB,WAAW,CAC/B,MAAM,EAAE,WAAW,EACnB,KAAK,EAAE,gBAAgB,EACvB,MAAM,EAAE,YAAY,GACnB,OAAO,CAAC,eAAe,CAAC,CAuB1B;AAED,wBAAsB,SAAS,CAC7B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,GAAG,IAAI,EACvC,IAAI,EAAE,WAAW,EACjB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC9C,OAAO,CAAC,eAAe,CAAC,CAW1B;AAiBD,wBAAgB,WAAW,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,MAAM;sBAwCzC,SAAS,gBAAgB,EAAE;kBAU/B,gBAAgB,KAAG,OAAO,CAAC,MAAM,CAAC;iBASxC,gBAAgB,cAAc,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;;EAc3F;AAuCD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAgC5B"}
|
package/dist/chunks.js
CHANGED
|
@@ -2,6 +2,8 @@ import { paced, ROW_WEIGHT, stepped, } from '@agentshouse/mdruntime';
|
|
|
2
2
|
import { manifestedModels } from './model.js';
|
|
3
3
|
import { authorityRoot, bootstrapping, parseFile, } from './read.js';
|
|
4
4
|
import { classifyDoor } from './refusal.js';
|
|
5
|
+
import { failedOn, unusable } from './uncertain.js';
|
|
6
|
+
import { spaceSchemas } from './space-schema.js';
|
|
5
7
|
import { houseDoorRoute } from './transport.js';
|
|
6
8
|
import { readPosition, roomVersion } from './version.js';
|
|
7
9
|
function authorKey(author) {
|
|
@@ -26,27 +28,40 @@ function namesOf(authors) {
|
|
|
26
28
|
}
|
|
27
29
|
return names;
|
|
28
30
|
}
|
|
29
|
-
function
|
|
31
|
+
function schemaText(entry, file, texts) {
|
|
32
|
+
const { space, revision } = file;
|
|
33
|
+
if (typeof entry.content === 'string') {
|
|
34
|
+
if (space !== undefined && revision !== undefined)
|
|
35
|
+
texts.keep(space, revision, entry.content);
|
|
36
|
+
return entry.content;
|
|
37
|
+
}
|
|
38
|
+
return space === undefined || revision === undefined ? undefined : texts.held(space, revision);
|
|
39
|
+
}
|
|
40
|
+
function answerTexts() {
|
|
41
|
+
return spaceSchemas(Number.POSITIVE_INFINITY);
|
|
42
|
+
}
|
|
43
|
+
function modelsOf(models, mode, texts) {
|
|
30
44
|
if (!Array.isArray(models))
|
|
31
45
|
return null;
|
|
32
46
|
const files = [];
|
|
33
47
|
const contents = [];
|
|
34
48
|
for (const entry of models) {
|
|
35
49
|
const file = parseFile(entry, mode);
|
|
36
|
-
|
|
50
|
+
const content = file === null ? undefined : schemaText(entry, file, texts);
|
|
51
|
+
if (file === null || content === undefined)
|
|
37
52
|
return null;
|
|
38
53
|
files.push(file);
|
|
39
|
-
contents.push({ path: file.path, content
|
|
54
|
+
contents.push({ path: file.path, content });
|
|
40
55
|
}
|
|
41
56
|
return { files, contents };
|
|
42
57
|
}
|
|
43
58
|
export function partId(logEpoch, hash) {
|
|
44
59
|
return `${logEpoch}:${hash}`;
|
|
45
60
|
}
|
|
46
|
-
function chunkedRoom(room, mode) {
|
|
61
|
+
function chunkedRoom(room, mode, texts) {
|
|
47
62
|
const at = readPosition(room);
|
|
48
63
|
const names = mode === 'site' ? new Map() : namesOf(room.authors);
|
|
49
|
-
const models = modelsOf(room.models, mode);
|
|
64
|
+
const models = modelsOf(room.models, mode, texts);
|
|
50
65
|
if (at === null || names === null || models === null || !Array.isArray(room.chunks))
|
|
51
66
|
return null;
|
|
52
67
|
const chunks = new Map();
|
|
@@ -61,7 +76,7 @@ function chunkedRoom(room, mode) {
|
|
|
61
76
|
}
|
|
62
77
|
return { anchor: room.room_ref, ...at, mode, chunks, parts, names, models };
|
|
63
78
|
}
|
|
64
|
-
function listedRoom(room, mode) {
|
|
79
|
+
function listedRoom(room, mode, texts) {
|
|
65
80
|
if (typeof room !== 'object' || room === null)
|
|
66
81
|
return null;
|
|
67
82
|
const held = room;
|
|
@@ -69,17 +84,17 @@ function listedRoom(room, mode) {
|
|
|
69
84
|
return null;
|
|
70
85
|
if (held.ready === false)
|
|
71
86
|
return { kind: 'not-ready' };
|
|
72
|
-
return held.ready === true ? chunkedRoom(held, mode) : null;
|
|
87
|
+
return held.ready === true ? chunkedRoom(held, mode, texts) : null;
|
|
73
88
|
}
|
|
74
89
|
export function siteChunkList(answer, locator) {
|
|
75
90
|
const failure = classifyDoor(answer.status, answer.body, locator);
|
|
76
91
|
if (failure !== null)
|
|
77
92
|
return failure;
|
|
78
|
-
return listedRoom(answer.body, 'site') ??
|
|
93
|
+
return listedRoom(answer.body, 'site', answerTexts()) ?? unusable();
|
|
79
94
|
}
|
|
80
95
|
export async function chunkedHead(listed, entry, spaces) {
|
|
81
96
|
if (listed.anchor !== entry.authority)
|
|
82
|
-
return
|
|
97
|
+
return unusable();
|
|
83
98
|
const models = await manifestedModels({
|
|
84
99
|
anchor: listed.anchor,
|
|
85
100
|
position: listed.position,
|
|
@@ -101,10 +116,16 @@ export async function chunkedHead(listed, entry, spaces) {
|
|
|
101
116
|
export async function chunkPart(body, room, id, arriving) {
|
|
102
117
|
const address = room.chunks.get(id);
|
|
103
118
|
if (body === null || address === undefined)
|
|
104
|
-
return
|
|
105
|
-
|
|
119
|
+
return unusable();
|
|
120
|
+
let scope;
|
|
121
|
+
try {
|
|
122
|
+
scope = await chunkScope(body, room, arriving);
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
return failedOn(error);
|
|
126
|
+
}
|
|
106
127
|
if (scope === null)
|
|
107
|
-
return
|
|
128
|
+
return unusable();
|
|
108
129
|
return { ...(await stepped(bootstrapping(scope))), bytes: address.bytes };
|
|
109
130
|
}
|
|
110
131
|
function listedRooms(answer) {
|
|
@@ -112,8 +133,9 @@ function listedRooms(answer) {
|
|
|
112
133
|
if (!Array.isArray(rooms))
|
|
113
134
|
return null;
|
|
114
135
|
const listed = new Map();
|
|
136
|
+
const texts = answerTexts();
|
|
115
137
|
for (const room of rooms) {
|
|
116
|
-
const held = listedRoom(room, 'credential');
|
|
138
|
+
const held = listedRoom(room, 'credential', texts);
|
|
117
139
|
if (held === null)
|
|
118
140
|
return null;
|
|
119
141
|
listed.set(room.room_ref, held);
|
|
@@ -129,8 +151,8 @@ export function chunkLister(transport, most) {
|
|
|
129
151
|
if (failure !== null)
|
|
130
152
|
return failed(entries, failure);
|
|
131
153
|
const listed = listedRooms(answer);
|
|
132
|
-
return listed ?? failed(entries,
|
|
133
|
-
}, () => failed(entries,
|
|
154
|
+
return listed ?? failed(entries, unusable());
|
|
155
|
+
}, (error) => failed(entries, failedOn(error)));
|
|
134
156
|
}
|
|
135
157
|
function failed(entries, failure) {
|
|
136
158
|
return new Map(entries.map((entry) => [
|
package/dist/history.d.ts
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { AcceptedMessage, ActionResult, ConversationHistoryRequest } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type HouseDoor } from './transport.js';
|
|
3
3
|
export declare const HISTORY_PAGE = 100;
|
|
4
|
-
|
|
5
|
-
accepted_at: string;
|
|
6
|
-
message_id: string;
|
|
7
|
-
};
|
|
8
|
-
export declare function cursorPosition(cursor: HistoryCursor): string;
|
|
4
|
+
export declare function changeCursor(change: number): string;
|
|
9
5
|
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
10
6
|
export declare function houseHistory(transport: HouseDoor, request: ConversationHistoryRequest): Promise<ActionResult>;
|
|
11
|
-
export {};
|
package/dist/history.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAGZ,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAGZ,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhE,eAAO,MAAM,YAAY,MAAM,CAAC;AAqBhC,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAatE;AA6BD,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,YAAY,CAAC,CAqBvB"}
|
package/dist/history.js
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { actionOutcome } from './actions.js';
|
|
2
2
|
import { houseDoorRoute } from './transport.js';
|
|
3
|
+
import { unusable } from './uncertain.js';
|
|
3
4
|
export const HISTORY_PAGE = 100;
|
|
4
5
|
const HISTORY = 'conversations/history/list';
|
|
6
|
+
const CHANGE_DIGITS = 16;
|
|
7
|
+
const CHANGE = new RegExp(`^[0-9]{${CHANGE_DIGITS}}$`);
|
|
5
8
|
function record(value) {
|
|
6
9
|
return typeof value === 'object' && value !== null ? value : {};
|
|
7
10
|
}
|
|
@@ -9,32 +12,23 @@ function text(value, name) {
|
|
|
9
12
|
const held = record(value)[name];
|
|
10
13
|
return typeof held === 'string' ? held : undefined;
|
|
11
14
|
}
|
|
12
|
-
function
|
|
13
|
-
|
|
14
|
-
const messageId = text(value, 'message_id');
|
|
15
|
-
if (acceptedAt === undefined || messageId === undefined)
|
|
16
|
-
return null;
|
|
17
|
-
return { accepted_at: acceptedAt, message_id: messageId };
|
|
18
|
-
}
|
|
19
|
-
export function cursorPosition(cursor) {
|
|
20
|
-
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
15
|
+
function changeOf(value) {
|
|
16
|
+
return Number.isSafeInteger(value) && value > 0 ? value : null;
|
|
21
17
|
}
|
|
22
|
-
function
|
|
23
|
-
|
|
24
|
-
return historyCursor(JSON.parse(value));
|
|
25
|
-
}
|
|
26
|
-
catch {
|
|
27
|
-
return null;
|
|
28
|
-
}
|
|
18
|
+
export function changeCursor(change) {
|
|
19
|
+
return String(change).padStart(CHANGE_DIGITS, '0');
|
|
29
20
|
}
|
|
30
21
|
export function acceptedMessage(entry) {
|
|
31
|
-
const
|
|
32
|
-
|
|
22
|
+
const identity = text(entry, 'message_id');
|
|
23
|
+
const acceptedAt = text(entry, 'accepted_at');
|
|
24
|
+
const change = changeOf(record(entry).change);
|
|
25
|
+
if (identity === undefined || acceptedAt === undefined || change === null)
|
|
33
26
|
return null;
|
|
34
27
|
return {
|
|
35
|
-
identity
|
|
36
|
-
turn: text(entry, 'turn_id') ??
|
|
37
|
-
position:
|
|
28
|
+
identity,
|
|
29
|
+
turn: text(entry, 'turn_id') ?? identity,
|
|
30
|
+
position: JSON.stringify({ accepted_at: acceptedAt, message_id: identity }),
|
|
31
|
+
change: changeCursor(change),
|
|
38
32
|
text: text(entry, 'text') ?? '',
|
|
39
33
|
message: structuredClone(record(entry)),
|
|
40
34
|
};
|
|
@@ -51,20 +45,19 @@ function historyPage(entry) {
|
|
|
51
45
|
return null;
|
|
52
46
|
messages.push(message);
|
|
53
47
|
}
|
|
54
|
-
const next = held.next === null || held.next === undefined ? undefined :
|
|
48
|
+
const next = held.next === null || held.next === undefined ? undefined : changeOf(held.next);
|
|
55
49
|
if (next === null)
|
|
56
50
|
return null;
|
|
57
|
-
return { conversation, messages, ...(next === undefined ? {} : { next:
|
|
51
|
+
return { conversation, messages, ...(next === undefined ? {} : { next: changeCursor(next) }) };
|
|
58
52
|
}
|
|
59
53
|
function historyAsks(request) {
|
|
60
54
|
const asks = [];
|
|
61
55
|
for (const { conversation, after } of request.conversations) {
|
|
62
|
-
|
|
63
|
-
if (cursor === null)
|
|
56
|
+
if (after !== undefined && !CHANGE.test(after))
|
|
64
57
|
return null;
|
|
65
58
|
asks.push({
|
|
66
59
|
conversation_id: conversation,
|
|
67
|
-
...(
|
|
60
|
+
...(after === undefined ? {} : { after: Number(after) }),
|
|
68
61
|
});
|
|
69
62
|
}
|
|
70
63
|
return asks;
|
|
@@ -79,12 +72,12 @@ export async function houseHistory(transport, request) {
|
|
|
79
72
|
return outcome;
|
|
80
73
|
const answered = record(outcome.result).histories;
|
|
81
74
|
if (!Array.isArray(answered))
|
|
82
|
-
return
|
|
75
|
+
return unusable();
|
|
83
76
|
const histories = [];
|
|
84
77
|
for (const entry of answered) {
|
|
85
78
|
const page = historyPage(entry);
|
|
86
79
|
if (page === null)
|
|
87
|
-
return
|
|
80
|
+
return unusable();
|
|
88
81
|
histories.push(page);
|
|
89
82
|
}
|
|
90
83
|
const result = { histories };
|