@agentshouse/mdruntime-adapter 0.1.0-ccdfb41af2abb → 0.1.0-ccfaf175ec3b4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/actions.d.ts +3 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +26 -9
- package/dist/adapter.d.ts +0 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +118 -138
- package/dist/authored-path.d.ts +9 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +34 -0
- package/dist/chunks.d.ts +36 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +281 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +23 -7
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +163 -16
- package/dist/history.d.ts +1 -7
- package/dist/history.d.ts.map +1 -1
- package/dist/history.js +24 -30
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -4
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +6 -9
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +28 -26
- package/dist/read.d.ts +15 -24
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +66 -189
- package/dist/refusal.d.ts +3 -2
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +17 -7
- package/dist/search.d.ts +0 -1
- package/dist/search.d.ts.map +1 -1
- package/dist/search.js +5 -5
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +103 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +0 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +44 -50
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +11 -0
- package/dist/stream.d.ts +4 -4
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +146 -72
- package/dist/transport.d.ts +47 -27
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +15 -14
- 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 -2
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +8 -6
- package/dist/version.d.ts +0 -1
- package/dist/write.d.ts +0 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +22 -29
- package/package.json +3 -2
- package/dist/app-reference.d.ts +0 -2
- package/dist/app-reference.d.ts.map +0 -1
- package/dist/app-reference.js +0 -2
- package/dist/crockford.d.ts +0 -4
- package/dist/crockford.d.ts.map +0 -1
- package/dist/crockford.js +0 -3
- package/dist/house-model.d.ts +0 -892
- package/dist/house-model.d.ts.map +0 -1
- package/dist/house-model.js +0 -482
- package/dist/part.d.ts +0 -14
- package/dist/part.d.ts.map +0 -1
- package/dist/part.js +0 -90
- package/dist/room-stream.d.ts +0 -19
- package/dist/room-stream.d.ts.map +0 -1
- package/dist/room-stream.js +0 -57
- package/dist/room-types.d.ts +0 -7
- package/dist/room-types.d.ts.map +0 -1
- package/dist/room-types.js +0 -125
package/dist/read.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
|
|
1
|
+
import { patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
|
|
2
|
+
import { REVISION_REFERENCE_PATTERN } from '@agentshouse/mdmodel';
|
|
3
|
+
import { roomVersion } from './version.js';
|
|
5
4
|
function fileOf(revision) {
|
|
6
|
-
return
|
|
5
|
+
return REVISION_REFERENCE_PATTERN.exec(revision)?.[1];
|
|
7
6
|
}
|
|
8
7
|
export function answering() {
|
|
9
8
|
return {
|
|
10
9
|
documents: new Map(),
|
|
11
|
-
|
|
10
|
+
facts: new Map(),
|
|
12
11
|
revisions: new Map(),
|
|
13
12
|
fileIds: new Map(),
|
|
13
|
+
created: new Map(),
|
|
14
14
|
changes: new Map(),
|
|
15
15
|
binaryFiles: new Map(),
|
|
16
16
|
removals: new Set(),
|
|
@@ -26,9 +26,10 @@ export function revised(answer, path, revision) {
|
|
|
26
26
|
}
|
|
27
27
|
export function forgotten(answer, path) {
|
|
28
28
|
answer.documents.delete(path);
|
|
29
|
-
answer.
|
|
29
|
+
answer.facts.delete(path);
|
|
30
30
|
answer.revisions.delete(path);
|
|
31
31
|
answer.fileIds.delete(path);
|
|
32
|
+
answer.created.delete(path);
|
|
32
33
|
answer.changes.delete(path);
|
|
33
34
|
answer.binaryFiles.delete(path);
|
|
34
35
|
answer.removals.delete(path);
|
|
@@ -55,9 +56,10 @@ export function* answered(answer) {
|
|
|
55
56
|
const removals = yield* pathsOf(answer.removals);
|
|
56
57
|
return {
|
|
57
58
|
documents: yield* patching({}, answer.documents),
|
|
58
|
-
|
|
59
|
+
facts: yield* patching({}, answer.facts),
|
|
59
60
|
revisions: yield* patching({}, answer.revisions),
|
|
60
61
|
...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
|
|
62
|
+
...(answer.created.size === 0 ? {} : { created: yield* patching({}, answer.created) }),
|
|
61
63
|
changes: yield* patching({}, answer.changes),
|
|
62
64
|
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
63
65
|
removals,
|
|
@@ -121,11 +123,19 @@ export function headChange(held) {
|
|
|
121
123
|
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
122
124
|
if (held.author !== undefined && author === null)
|
|
123
125
|
return null;
|
|
124
|
-
if (held.
|
|
126
|
+
if (held.changed_at === undefined)
|
|
125
127
|
return undefined;
|
|
126
|
-
if (typeof held.
|
|
128
|
+
if (typeof held.changed_at !== 'string')
|
|
127
129
|
return null;
|
|
128
|
-
return { author, time: held.
|
|
130
|
+
return { author, time: held.changed_at };
|
|
131
|
+
}
|
|
132
|
+
function createdOf(held) {
|
|
133
|
+
if (held.created_at === undefined)
|
|
134
|
+
return undefined;
|
|
135
|
+
return typeof held.created_at === 'string' ? held.created_at : null;
|
|
136
|
+
}
|
|
137
|
+
function createdHeld(created) {
|
|
138
|
+
return created === undefined ? {} : { created };
|
|
129
139
|
}
|
|
130
140
|
function headed(head) {
|
|
131
141
|
return head === undefined ? {} : { head };
|
|
@@ -141,34 +151,26 @@ export function binaryFileOf(held) {
|
|
|
141
151
|
function binaried(binary) {
|
|
142
152
|
return binary === undefined ? {} : { binary };
|
|
143
153
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
return undefined;
|
|
147
|
-
if (typeof value !== 'object' || value === null)
|
|
148
|
-
return null;
|
|
149
|
-
const { type, fields, links } = value;
|
|
150
|
-
if (type !== null && typeof type !== 'string')
|
|
151
|
-
return null;
|
|
152
|
-
if (fields !== null && (typeof fields !== 'object' || Array.isArray(fields)))
|
|
153
|
-
return null;
|
|
154
|
-
if (!Array.isArray(links) || links.some((link) => typeof link !== 'string'))
|
|
155
|
-
return null;
|
|
156
|
-
return {
|
|
157
|
-
type: type,
|
|
158
|
-
fields: fields,
|
|
159
|
-
links: links,
|
|
160
|
-
};
|
|
154
|
+
function carriedFacts(held) {
|
|
155
|
+
return held.facts === undefined ? {} : { facts: held.facts };
|
|
161
156
|
}
|
|
162
|
-
function
|
|
157
|
+
function carriedSpace(held) {
|
|
158
|
+
return typeof held.space === 'string' ? { space: held.space } : {};
|
|
159
|
+
}
|
|
160
|
+
export function documentEntry(value, mode) {
|
|
163
161
|
if (typeof value !== 'object' || value === null)
|
|
164
162
|
return null;
|
|
165
163
|
const file = value;
|
|
166
164
|
if (typeof file.path !== 'string')
|
|
167
165
|
return null;
|
|
166
|
+
if (file.content !== undefined && typeof file.content !== 'string')
|
|
167
|
+
return null;
|
|
168
168
|
const head = headChange(file);
|
|
169
|
+
const created = createdOf(file);
|
|
169
170
|
const binary = binaryFileOf(file);
|
|
170
|
-
if (head === null || binary === null)
|
|
171
|
+
if (head === null || created === null || binary === null)
|
|
171
172
|
return null;
|
|
173
|
+
const content = file.content === undefined ? {} : { content: file.content };
|
|
172
174
|
if (mode === 'site') {
|
|
173
175
|
if (typeof file.sha256 !== 'string')
|
|
174
176
|
return null;
|
|
@@ -178,194 +180,69 @@ function parseFile(value, mode) {
|
|
|
178
180
|
version: file.sha256,
|
|
179
181
|
...headed(head),
|
|
180
182
|
...binaried(binary),
|
|
183
|
+
...carriedFacts(file),
|
|
184
|
+
...content,
|
|
181
185
|
};
|
|
182
186
|
}
|
|
183
|
-
|
|
184
|
-
if (typeof file.revision !== 'string' || outline === null)
|
|
187
|
+
if (typeof file.revision !== 'string')
|
|
185
188
|
return null;
|
|
186
189
|
return {
|
|
187
190
|
path: file.path,
|
|
188
191
|
revision: file.revision,
|
|
189
192
|
version: file.revision,
|
|
190
|
-
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
191
193
|
...headed(head),
|
|
194
|
+
...createdHeld(created),
|
|
192
195
|
...binaried(binary),
|
|
193
|
-
...(
|
|
196
|
+
...carriedFacts(file),
|
|
197
|
+
...carriedSpace(file),
|
|
198
|
+
...content,
|
|
194
199
|
};
|
|
195
200
|
}
|
|
196
|
-
function
|
|
197
|
-
if (
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
return { files, contents };
|
|
210
|
-
}
|
|
211
|
-
function parseRoomHead(value, mode) {
|
|
212
|
-
if (typeof value !== 'object' || value === null)
|
|
213
|
-
return null;
|
|
214
|
-
const held = value;
|
|
215
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
216
|
-
return null;
|
|
217
|
-
const models = parseModels(held.models, mode);
|
|
218
|
-
if (models === null)
|
|
219
|
-
return null;
|
|
220
|
-
const manifest = held.manifest;
|
|
221
|
-
if (manifest.scope !== 'room')
|
|
222
|
-
return null;
|
|
223
|
-
const at = readPosition(manifest);
|
|
224
|
-
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
225
|
-
return null;
|
|
226
|
-
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
227
|
-
return null;
|
|
228
|
-
return { anchor: manifest.anchor, ...at, models };
|
|
229
|
-
}
|
|
230
|
-
export async function roomHead(payload, mode) {
|
|
231
|
-
let text = '';
|
|
232
|
-
try {
|
|
233
|
-
for await (const chunk of gunzipped(payload))
|
|
234
|
-
text += chunk;
|
|
235
|
-
return text.endsWith('\n') && text.indexOf('\n') === text.length - 1
|
|
236
|
-
? parseRoomHead(JSON.parse(text), mode)
|
|
237
|
-
: null;
|
|
238
|
-
}
|
|
239
|
-
catch {
|
|
240
|
-
return null;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
export function manifested(room, pageToken, models) {
|
|
244
|
-
return {
|
|
245
|
-
kind: 'bootstrap',
|
|
246
|
-
roomVersion: roomVersion(room),
|
|
247
|
-
documents: {},
|
|
248
|
-
revisions: {},
|
|
249
|
-
changes: {},
|
|
250
|
-
binaryFiles: {},
|
|
251
|
-
pageToken,
|
|
252
|
-
...(models === undefined ? {} : { models }),
|
|
253
|
-
};
|
|
201
|
+
export function kept(answer, file) {
|
|
202
|
+
if (file.head !== undefined)
|
|
203
|
+
answer.changes.set(file.path, file.head);
|
|
204
|
+
if (file.created !== undefined)
|
|
205
|
+
answer.created.set(file.path, file.created);
|
|
206
|
+
if (file.binary !== undefined)
|
|
207
|
+
answer.binaryFiles.set(file.path, file.binary);
|
|
208
|
+
else if (file.content !== undefined)
|
|
209
|
+
answer.documents.set(file.path, file.content);
|
|
210
|
+
if (file.binary === undefined && file.facts !== undefined)
|
|
211
|
+
answer.facts.set(file.path, file.facts);
|
|
212
|
+
if (file.revision !== undefined)
|
|
213
|
+
revised(answer, file.path, file.revision);
|
|
254
214
|
}
|
|
255
215
|
export function modelScope(room) {
|
|
256
|
-
return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
|
|
257
|
-
}
|
|
258
|
-
export function emptyScope(room) {
|
|
259
216
|
return {
|
|
260
217
|
anchor: room.anchor,
|
|
261
218
|
position: room.position,
|
|
262
219
|
logEpoch: room.logEpoch,
|
|
263
|
-
files:
|
|
264
|
-
contents: [],
|
|
220
|
+
files: room.models,
|
|
265
221
|
};
|
|
266
222
|
}
|
|
267
|
-
function partLine(line, mode, read) {
|
|
268
|
-
if (read.ended)
|
|
269
|
-
return false;
|
|
270
|
-
let entry;
|
|
271
|
-
try {
|
|
272
|
-
entry = JSON.parse(line);
|
|
273
|
-
}
|
|
274
|
-
catch {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
if (endLine(entry)) {
|
|
278
|
-
read.ended = true;
|
|
279
|
-
return true;
|
|
280
|
-
}
|
|
281
|
-
if (folderLine(entry)) {
|
|
282
|
-
read.folders.push(entry.folder);
|
|
283
|
-
return true;
|
|
284
|
-
}
|
|
285
|
-
const file = parseFile(entry, mode);
|
|
286
|
-
if (file === null)
|
|
287
|
-
return false;
|
|
288
|
-
read.files.push(file);
|
|
289
|
-
const { content } = entry;
|
|
290
|
-
if (typeof content === 'string')
|
|
291
|
-
read.contents.push({ path: file.path, content });
|
|
292
|
-
else if (content !== undefined)
|
|
293
|
-
return false;
|
|
294
|
-
return true;
|
|
295
|
-
}
|
|
296
|
-
async function partRead(chunks, mode) {
|
|
297
|
-
const read = { files: [], contents: [], folders: [], ended: false };
|
|
298
|
-
const pace = paced();
|
|
299
|
-
const unfinished = [];
|
|
300
|
-
for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
|
|
301
|
-
const text = chunk.value;
|
|
302
|
-
let start = 0;
|
|
303
|
-
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
304
|
-
const piece = text.slice(start, end);
|
|
305
|
-
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
306
|
-
if (!partLine(line, mode, read)) {
|
|
307
|
-
await chunks.cancel();
|
|
308
|
-
return null;
|
|
309
|
-
}
|
|
310
|
-
start = end + 1;
|
|
311
|
-
const due = pace(line.length + ROW_WEIGHT);
|
|
312
|
-
if (due instanceof Promise)
|
|
313
|
-
await due;
|
|
314
|
-
}
|
|
315
|
-
if (start < text.length)
|
|
316
|
-
unfinished.push(text.slice(start));
|
|
317
|
-
}
|
|
318
|
-
return unfinished.length === 0 ? read : null;
|
|
319
|
-
}
|
|
320
|
-
function endLine(entry) {
|
|
321
|
-
if (typeof entry !== 'object' || entry === null || !('end' in entry))
|
|
322
|
-
return false;
|
|
323
|
-
return entry.end === true && Object.keys(entry).length === 1;
|
|
324
|
-
}
|
|
325
|
-
function folderLine(entry) {
|
|
326
|
-
if (typeof entry !== 'object' || entry === null || !('folder' in entry))
|
|
327
|
-
return false;
|
|
328
|
-
return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
|
|
329
|
-
}
|
|
330
|
-
export async function housePart(room, payload, mode) {
|
|
331
|
-
const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
|
|
332
|
-
if (read === null)
|
|
333
|
-
return { kind: 'transport-uncertainty' };
|
|
334
|
-
const { ended, ...scope } = read;
|
|
335
|
-
return { scope: { ...emptyScope(room), ...scope }, ended };
|
|
336
|
-
}
|
|
337
223
|
export function* bootstrapping(scope) {
|
|
338
|
-
const contents = new Map();
|
|
339
|
-
for (const entry of scope.contents) {
|
|
340
|
-
contents.set(entry.path, entry.content);
|
|
341
|
-
yield ROW_WEIGHT;
|
|
342
|
-
}
|
|
343
224
|
const answer = answering();
|
|
344
225
|
for (const file of scope.files) {
|
|
345
226
|
yield ROW_WEIGHT;
|
|
346
|
-
if (file.
|
|
347
|
-
answer
|
|
348
|
-
const content = contents.get(file.path);
|
|
349
|
-
if (file.binary !== undefined)
|
|
350
|
-
answer.binaryFiles.set(file.path, file.binary);
|
|
351
|
-
else if (content !== undefined)
|
|
352
|
-
answer.documents.set(file.path, content);
|
|
353
|
-
else if (file.outline !== undefined)
|
|
354
|
-
answer.outlines.set(file.path, file.outline);
|
|
355
|
-
if (file.revision !== undefined)
|
|
356
|
-
revised(answer, file.path, file.revision);
|
|
227
|
+
if (file.space === undefined)
|
|
228
|
+
kept(answer, file);
|
|
357
229
|
}
|
|
358
230
|
for (const folder of scope.folders ?? [])
|
|
359
231
|
folded(answer, folder, false);
|
|
360
232
|
const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
|
|
361
233
|
return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
|
|
362
234
|
}
|
|
235
|
+
export function schemaFile(file) {
|
|
236
|
+
return file.content === undefined
|
|
237
|
+
? null
|
|
238
|
+
: {
|
|
239
|
+
schema: file.content,
|
|
240
|
+
version: file.version,
|
|
241
|
+
revision: file.revision ?? null,
|
|
242
|
+
...(file.space === undefined ? {} : { space: file.space }),
|
|
243
|
+
};
|
|
244
|
+
}
|
|
363
245
|
export function schemaOf(scope, schema) {
|
|
364
246
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
365
|
-
|
|
366
|
-
return { schema: null, version: null, revision: null };
|
|
367
|
-
const content = scope.contents.find((entry) => entry.path === schema);
|
|
368
|
-
return content === undefined
|
|
369
|
-
? null
|
|
370
|
-
: { schema: content.content, version: file.version, revision: file.revision ?? null };
|
|
247
|
+
return file === undefined ? { schema: null, version: null, revision: null } : schemaFile(file);
|
|
371
248
|
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
1
|
+
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal, TransportUncertainty } from '@agentshouse/mdruntime';
|
|
2
2
|
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
|
+
export declare function answeredFailure(status: number, body: unknown): TransportUncertainty;
|
|
4
|
+
export declare function resetOf(refusal: ProviderRefusal | null): string | undefined;
|
|
3
5
|
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
4
6
|
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
5
7
|
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
6
|
-
//# sourceMappingURL=refusal.d.ts.map
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,
|
|
1
|
+
{"version":3,"file":"refusal.d.ts","sourceRoot":"","sources":["../src/refusal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,eAAe,EACf,aAAa,EACb,oBAAoB,EACrB,MAAM,wBAAwB,CAAC;AAGhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,oBAAoB,CAInF;AAED,wBAAgB,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,IAAI,GAAG,MAAM,GAAG,SAAS,CAG3E;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAoBD,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG,IAAI,CAMvB;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAQrF"}
|
package/dist/refusal.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { refusedFor, UNANSWERED, unusable } from './uncertain.js';
|
|
1
2
|
export function doorRefusal(body) {
|
|
2
3
|
if (typeof body !== 'object' || body === null)
|
|
3
4
|
return null;
|
|
@@ -9,24 +10,33 @@ export function doorRefusal(body) {
|
|
|
9
10
|
const { code, retryable, ...fields } = error;
|
|
10
11
|
return { code, fields, retryable: retryable === true };
|
|
11
12
|
}
|
|
13
|
+
export function answeredFailure(status, body) {
|
|
14
|
+
const refusal = doorRefusal(body);
|
|
15
|
+
if (refusal !== null)
|
|
16
|
+
return refusedFor(refusal);
|
|
17
|
+
return status === 0 || (status >= 500 && body === null) ? UNANSWERED : unusable();
|
|
18
|
+
}
|
|
19
|
+
export function resetOf(refusal) {
|
|
20
|
+
const reset = refusal?.fields.retry_at;
|
|
21
|
+
return refusal?.retryable === true && typeof reset === 'string' ? reset : undefined;
|
|
22
|
+
}
|
|
12
23
|
export function scopedRefusal(locator, scope, refusal) {
|
|
13
24
|
return { kind: 'scoped-refusal', locator, scope, ...refusal };
|
|
14
25
|
}
|
|
15
26
|
function doorFailure(status, body) {
|
|
16
27
|
if (status === 0)
|
|
17
|
-
return
|
|
18
|
-
const refusal = doorRefusal(body);
|
|
28
|
+
return UNANSWERED;
|
|
19
29
|
if (status === 401)
|
|
20
30
|
return { kind: 'revoked-authorization' };
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
const refusal = doorRefusal(body);
|
|
32
|
+
if (refusal?.retryable === true || refusal?.code === 'update_required')
|
|
33
|
+
return refusedFor(refusal);
|
|
24
34
|
if (status === 404 || refusal?.code === 'room_not_found')
|
|
25
35
|
return { kind: 'room-not-readable' };
|
|
26
36
|
if (status < 400)
|
|
27
37
|
return null;
|
|
28
38
|
if (refusal === null)
|
|
29
|
-
return
|
|
39
|
+
return answeredFailure(status, body);
|
|
30
40
|
return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
|
|
31
41
|
}
|
|
32
42
|
export function classifyDoor(status, body, locator) {
|
|
@@ -48,5 +58,5 @@ export function discoveryFailure(status, body) {
|
|
|
48
58
|
if (failure.kind === 'refused') {
|
|
49
59
|
return { kind: 'contract-unavailable', ...failure.refusal };
|
|
50
60
|
}
|
|
51
|
-
return
|
|
61
|
+
return failure.kind === 'transport-uncertainty' ? failure : answeredFailure(status, body);
|
|
52
62
|
}
|
package/dist/search.d.ts
CHANGED
|
@@ -2,4 +2,3 @@ import type { SearchAnswer, SearchAsk } from '@agentshouse/mdruntime';
|
|
|
2
2
|
import type { TrackedAuthority } from './discovery.js';
|
|
3
3
|
import { type HouseTransport } from './transport.js';
|
|
4
4
|
export declare function houseSearch(transport: Pick<HouseTransport, 'door'>, tracked: readonly TrackedAuthority[], request: SearchAsk): Promise<SearchAnswer>;
|
|
5
|
-
//# sourceMappingURL=search.d.ts.map
|
package/dist/search.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAoBrE,wBAAsB,WAAW,CAC/B,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,YAAY,CAAC,CAsBvB"}
|
package/dist/search.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { doorRefusal } from './refusal.js';
|
|
1
|
+
import { answeredFailure, doorRefusal } from './refusal.js';
|
|
2
2
|
import { houseDoorRoute } from './transport.js';
|
|
3
3
|
const ROOMS = '/rooms/';
|
|
4
|
-
const UNCERTAIN = { kind: 'transport-uncertainty' };
|
|
5
4
|
function hitOf(file, locators) {
|
|
6
5
|
if (typeof file !== 'object' || file === null)
|
|
7
6
|
return null;
|
|
@@ -27,7 +26,7 @@ export async function houseSearch(transport, tracked, request) {
|
|
|
27
26
|
: tracked.filter((entry) => request.rooms.includes(entry.locator));
|
|
28
27
|
if (named !== null && named.length === 0)
|
|
29
28
|
return { kind: 'found', documents: [] };
|
|
30
|
-
const answer = await transport.door(houseDoorRoute('search'), {
|
|
29
|
+
const answer = await transport.door(houseDoorRoute('rooms/search'), {
|
|
31
30
|
query: request.text,
|
|
32
31
|
...(named === null ? {} : { paths: named.map((entry) => `${ROOMS}${entry.handle}`) }),
|
|
33
32
|
});
|
|
@@ -37,8 +36,9 @@ export async function houseSearch(transport, tracked, request) {
|
|
|
37
36
|
if (refusal !== null)
|
|
38
37
|
return { kind: 'rejected', ...refusal };
|
|
39
38
|
const files = answer.body?.files;
|
|
40
|
-
if (answer.status !== 200 || !Array.isArray(files))
|
|
41
|
-
return
|
|
39
|
+
if (answer.status !== 200 || !Array.isArray(files)) {
|
|
40
|
+
return answeredFailure(answer.status, answer.body);
|
|
41
|
+
}
|
|
42
42
|
const locators = new Map(tracked.map((entry) => [entry.handle, entry.locator]));
|
|
43
43
|
return {
|
|
44
44
|
kind: 'found',
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const OUTPUT_LINES = 20;
|
|
2
|
+
export declare const OUTPUT_CHARACTERS = 4000;
|
|
3
|
+
export declare const DIFF_CHARACTERS = 10000;
|
|
4
|
+
export declare const FIRST_PART_CHARACTERS = 2000;
|
|
5
|
+
export declare function lastLines(output: string): string;
|
|
6
|
+
export declare function firstPart(result: string): string;
|
|
7
|
+
export declare function keptDiff(diff: string): string | null;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type Check<T> = (value: unknown) => value is T;
|
|
2
|
+
export type Checked<C> = C extends Check<infer T> ? T : never;
|
|
3
|
+
type Shape = Readonly<Record<string, Check<unknown>>>;
|
|
4
|
+
export type Shaped<S extends Shape> = {
|
|
5
|
+
readonly [K in keyof S]: Checked<S[K]>;
|
|
6
|
+
};
|
|
7
|
+
export declare const text: Check<string>;
|
|
8
|
+
export declare const integer: Check<number>;
|
|
9
|
+
export declare const count: Check<number>;
|
|
10
|
+
export declare const figure: Check<number>;
|
|
11
|
+
export declare const instant: Check<string>;
|
|
12
|
+
export declare function oneOf<const V extends readonly string[]>(...values: V): Check<V[number]>;
|
|
13
|
+
export declare function where<T>(check: Check<T>, holds: (value: T) => boolean): Check<T>;
|
|
14
|
+
export declare function nullable<T>(check: Check<T>): Check<T | null>;
|
|
15
|
+
export declare function list<T>(check: Check<T>): Check<readonly T[]>;
|
|
16
|
+
export declare function exact<const S extends Shape>(shape: S): Check<Shaped<S>>;
|
|
17
|
+
export declare function anyOf<const C extends readonly Check<unknown>[]>(...checks: C): Check<Checked<C[number]>>;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { DIFF_CHARACTERS, FIRST_PART_CHARACTERS, firstPart, keptDiff, lastLines, OUTPUT_CHARACTERS, OUTPUT_LINES, } from './bounds.js';
|
|
2
|
+
export { isOwn, isPart } from './parts.js';
|
|
3
|
+
export type { Call, FileChange, Part, PartOf, Status } from './parts.js';
|
|
4
|
+
export { isState, standingState } from './state.js';
|
|
5
|
+
export type { SessionState, Tokens } from './state.js';
|
|
6
|
+
export { applied, isOperation, isTurn } from './turn.js';
|
|
7
|
+
export type { Operation, Turn } from './turn.js';
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { type Check, type Checked } from './check.js';
|
|
2
|
+
declare const STATUS: Check<"done" | "failed" | "running" | "stopped">;
|
|
3
|
+
export type Status = Checked<typeof STATUS>;
|
|
4
|
+
declare const FILE_CHANGE: Check<import("./check.js").Shaped<{
|
|
5
|
+
readonly path: Check<string>;
|
|
6
|
+
readonly added: Check<number>;
|
|
7
|
+
readonly removed: Check<number>;
|
|
8
|
+
readonly diff: Check<string | null>;
|
|
9
|
+
}>>;
|
|
10
|
+
export type FileChange = Checked<typeof FILE_CHANGE>;
|
|
11
|
+
export declare const BACKGROUND_KINDS: readonly ['shell', 'task', 'monitor', 'schedule'];
|
|
12
|
+
declare const PART: Check<import("./check.js").Shaped<{
|
|
13
|
+
readonly type: Check<"call">;
|
|
14
|
+
readonly parent: Check<number | null>;
|
|
15
|
+
readonly line: Check<string>;
|
|
16
|
+
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
17
|
+
readonly duration: Check<number | null>;
|
|
18
|
+
readonly kind: Check<"command">;
|
|
19
|
+
readonly exit: Check<number | null>;
|
|
20
|
+
readonly output: Check<string>;
|
|
21
|
+
}> | import("./check.js").Shaped<{
|
|
22
|
+
readonly type: Check<"call">;
|
|
23
|
+
readonly parent: Check<number | null>;
|
|
24
|
+
readonly line: Check<string>;
|
|
25
|
+
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
26
|
+
readonly duration: Check<number | null>;
|
|
27
|
+
readonly kind: Check<"edit">;
|
|
28
|
+
readonly files: Check<readonly import("./check.js").Shaped<{
|
|
29
|
+
readonly path: Check<string>;
|
|
30
|
+
readonly added: Check<number>;
|
|
31
|
+
readonly removed: Check<number>;
|
|
32
|
+
readonly diff: Check<string | null>;
|
|
33
|
+
}>[]>;
|
|
34
|
+
}> | import("./check.js").Shaped<{
|
|
35
|
+
readonly type: Check<"call">;
|
|
36
|
+
readonly parent: Check<number | null>;
|
|
37
|
+
readonly line: Check<string>;
|
|
38
|
+
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
39
|
+
readonly duration: Check<number | null>;
|
|
40
|
+
readonly kind: Check<"read" | "search">;
|
|
41
|
+
readonly returned: Check<number | null>;
|
|
42
|
+
}> | import("./check.js").Shaped<{
|
|
43
|
+
readonly type: Check<"call">;
|
|
44
|
+
readonly parent: Check<number | null>;
|
|
45
|
+
readonly line: Check<string>;
|
|
46
|
+
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
47
|
+
readonly duration: Check<number | null>;
|
|
48
|
+
readonly kind: Check<"fetch" | "other" | "tool">;
|
|
49
|
+
readonly output: Check<string>;
|
|
50
|
+
}> | import("./check.js").Shaped<{
|
|
51
|
+
readonly type: Check<"subagent">;
|
|
52
|
+
readonly parent: Check<number | null>;
|
|
53
|
+
readonly kind: Check<"agent" | "fork" | "workflow">;
|
|
54
|
+
readonly name: Check<string | null>;
|
|
55
|
+
readonly task: Check<string>;
|
|
56
|
+
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
57
|
+
readonly step: Check<string | null>;
|
|
58
|
+
readonly report: Check<string | null>;
|
|
59
|
+
readonly tokens: Check<number | null>;
|
|
60
|
+
readonly calls: Check<number | null>;
|
|
61
|
+
readonly duration: Check<number | null>;
|
|
62
|
+
}> | import("./check.js").Shaped<{
|
|
63
|
+
readonly type: Check<"reasoning" | "text">;
|
|
64
|
+
readonly parent: Check<number | null>;
|
|
65
|
+
readonly text: Check<string>;
|
|
66
|
+
}> | import("./check.js").Shaped<{
|
|
67
|
+
readonly type: Check<"message">;
|
|
68
|
+
readonly parent: Check<number | null>;
|
|
69
|
+
readonly command: Check<"agent-functions/cancel" | "agent-functions/mail/send" | "agent-functions/send">;
|
|
70
|
+
readonly target: Check<string | null>;
|
|
71
|
+
}> | import("./check.js").Shaped<{
|
|
72
|
+
readonly type: Check<"image">;
|
|
73
|
+
readonly parent: Check<number | null>;
|
|
74
|
+
readonly file: Check<string>;
|
|
75
|
+
readonly name: Check<string>;
|
|
76
|
+
readonly media_type: Check<string>;
|
|
77
|
+
}> | import("./check.js").Shaped<{
|
|
78
|
+
readonly type: Check<"plan">;
|
|
79
|
+
readonly parent: Check<number | null>;
|
|
80
|
+
readonly entries: Check<readonly import("./check.js").Shaped<{
|
|
81
|
+
readonly content: Check<string>;
|
|
82
|
+
readonly status: Check<"done" | "pending" | "running">;
|
|
83
|
+
}>[]>;
|
|
84
|
+
}> | import("./check.js").Shaped<{
|
|
85
|
+
readonly type: Check<"notice">;
|
|
86
|
+
readonly parent: Check<number | null>;
|
|
87
|
+
readonly kind: Check<"compaction" | "error" | "info" | "mode" | "model" | "retry" | "warning">;
|
|
88
|
+
readonly text: Check<string>;
|
|
89
|
+
}> | import("./check.js").Shaped<{
|
|
90
|
+
readonly type: Check<"background">;
|
|
91
|
+
readonly parent: Check<number | null>;
|
|
92
|
+
readonly kind: Check<"monitor" | "schedule" | "shell" | "task">;
|
|
93
|
+
readonly label: Check<string>;
|
|
94
|
+
readonly status: Check<"done" | "failed" | "running" | "stopped">;
|
|
95
|
+
}>>;
|
|
96
|
+
export type Part = Checked<typeof PART>;
|
|
97
|
+
export type PartOf<T extends Part['type']> = Extract<Part, {
|
|
98
|
+
readonly type: T;
|
|
99
|
+
}>;
|
|
100
|
+
export type Call = PartOf<'call'>;
|
|
101
|
+
export declare const isPart: Check<Part>;
|
|
102
|
+
export declare function isOwn(part: Part): boolean;
|
|
103
|
+
export {};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type Check, type Checked } from './check.js';
|
|
2
|
+
export declare const TOKENS: Check<import("./check.js").Shaped<{
|
|
3
|
+
readonly input: Check<number>;
|
|
4
|
+
readonly output: Check<number>;
|
|
5
|
+
readonly cache_read: Check<number>;
|
|
6
|
+
readonly cache_write: Check<number>;
|
|
7
|
+
}>>;
|
|
8
|
+
export type Tokens = Checked<typeof TOKENS>;
|
|
9
|
+
declare const STATE: Check<import("./check.js").Shaped<{
|
|
10
|
+
readonly title: Check<string | null>;
|
|
11
|
+
readonly context: Check<import("./check.js").Shaped<{
|
|
12
|
+
readonly used: Check<number>;
|
|
13
|
+
readonly window: Check<number>;
|
|
14
|
+
readonly breakdown: Check<readonly import("./check.js").Shaped<{
|
|
15
|
+
readonly name: Check<string>;
|
|
16
|
+
readonly tokens: Check<number>;
|
|
17
|
+
}>[]>;
|
|
18
|
+
}> | null>;
|
|
19
|
+
readonly limits: Check<readonly import("./check.js").Shaped<{
|
|
20
|
+
readonly name: Check<string | null>;
|
|
21
|
+
readonly minutes: Check<number>;
|
|
22
|
+
readonly percent: Check<number>;
|
|
23
|
+
readonly resets: Check<string | null>;
|
|
24
|
+
}>[]>;
|
|
25
|
+
readonly cost: Check<import("./check.js").Shaped<{
|
|
26
|
+
readonly amount: Check<number>;
|
|
27
|
+
readonly currency: Check<string>;
|
|
28
|
+
}> | null>;
|
|
29
|
+
readonly tokens: Check<import("./check.js").Shaped<{
|
|
30
|
+
readonly input: Check<number>;
|
|
31
|
+
readonly output: Check<number>;
|
|
32
|
+
readonly cache_read: Check<number>;
|
|
33
|
+
readonly cache_write: Check<number>;
|
|
34
|
+
}> | null>;
|
|
35
|
+
readonly duration: Check<number | null>;
|
|
36
|
+
readonly files: Check<readonly import("./check.js").Shaped<{
|
|
37
|
+
readonly path: Check<string>;
|
|
38
|
+
readonly added: Check<number>;
|
|
39
|
+
readonly removed: Check<number>;
|
|
40
|
+
}>[]>;
|
|
41
|
+
readonly branch: Check<string | null>;
|
|
42
|
+
readonly worktree: Check<string | null>;
|
|
43
|
+
readonly pull: Check<import("./check.js").Shaped<{
|
|
44
|
+
readonly number: Check<number>;
|
|
45
|
+
readonly url: Check<string>;
|
|
46
|
+
}> | null>;
|
|
47
|
+
readonly model: Check<string | null>;
|
|
48
|
+
readonly effort: Check<string | null>;
|
|
49
|
+
readonly mode: Check<string | null>;
|
|
50
|
+
readonly suggestion: Check<string | null>;
|
|
51
|
+
readonly running: Check<readonly import("./check.js").Shaped<{
|
|
52
|
+
readonly kind: Check<"monitor" | "schedule" | "shell" | "subagent" | "task">;
|
|
53
|
+
readonly label: Check<string>;
|
|
54
|
+
readonly progress: Check<string | null>;
|
|
55
|
+
readonly next: Check<string | null>;
|
|
56
|
+
}>[]>;
|
|
57
|
+
}>>;
|
|
58
|
+
export type SessionState = Checked<typeof STATE>;
|
|
59
|
+
export declare const isState: Check<SessionState>;
|
|
60
|
+
export declare function standingState(state: SessionState, saved: string, ended: string | null): SessionState;
|
|
61
|
+
export {};
|