@agentshouse/mdruntime-adapter 0.1.0-c19cd0fd6cd22 → 0.1.0-c1a4aa648b216

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.
Files changed (83) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +2 -1
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +20 -7
  5. package/dist/adapter.d.ts +0 -1
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +118 -121
  8. package/dist/authored-path.d.ts +9 -0
  9. package/dist/authored-path.d.ts.map +1 -0
  10. package/dist/authored-path.js +34 -0
  11. package/dist/chunks.d.ts +36 -0
  12. package/dist/chunks.d.ts.map +1 -0
  13. package/dist/chunks.js +281 -0
  14. package/dist/digest.d.ts +0 -1
  15. package/dist/discovery.d.ts +23 -7
  16. package/dist/discovery.d.ts.map +1 -1
  17. package/dist/discovery.js +163 -16
  18. package/dist/history.d.ts +1 -7
  19. package/dist/history.d.ts.map +1 -1
  20. package/dist/history.js +22 -29
  21. package/dist/index.d.ts +5 -6
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +4 -4
  24. package/dist/map.d.ts +0 -1
  25. package/dist/model.d.ts +6 -9
  26. package/dist/model.d.ts.map +1 -1
  27. package/dist/model.js +28 -26
  28. package/dist/read.d.ts +15 -24
  29. package/dist/read.d.ts.map +1 -1
  30. package/dist/read.js +66 -190
  31. package/dist/refusal.d.ts +3 -2
  32. package/dist/refusal.d.ts.map +1 -1
  33. package/dist/refusal.js +17 -7
  34. package/dist/search.d.ts +0 -1
  35. package/dist/search.d.ts.map +1 -1
  36. package/dist/search.js +5 -5
  37. package/dist/session-content/bounds.d.ts +7 -0
  38. package/dist/session-content/check.d.ts +18 -0
  39. package/dist/session-content/index.d.ts +7 -0
  40. package/dist/session-content/parts.d.ts +103 -0
  41. package/dist/session-content/state.d.ts +61 -0
  42. package/dist/session-content/turn.d.ts +328 -0
  43. package/dist/site.d.ts +0 -1
  44. package/dist/site.d.ts.map +1 -1
  45. package/dist/site.js +44 -58
  46. package/dist/space-schema.d.ts +6 -0
  47. package/dist/space-schema.d.ts.map +1 -0
  48. package/dist/space-schema.js +11 -0
  49. package/dist/stream.d.ts +4 -4
  50. package/dist/stream.d.ts.map +1 -1
  51. package/dist/stream.js +145 -72
  52. package/dist/transport.d.ts +46 -27
  53. package/dist/transport.d.ts.map +1 -1
  54. package/dist/transport.js +15 -14
  55. package/dist/uncertain.d.ts +5 -0
  56. package/dist/uncertain.d.ts.map +1 -0
  57. package/dist/uncertain.js +11 -0
  58. package/dist/upload.d.ts +3 -2
  59. package/dist/upload.d.ts.map +1 -1
  60. package/dist/upload.js +8 -6
  61. package/dist/version.d.ts +0 -1
  62. package/dist/write.d.ts +0 -2
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +22 -29
  65. package/package.json +3 -2
  66. package/dist/app-reference.d.ts +0 -2
  67. package/dist/app-reference.d.ts.map +0 -1
  68. package/dist/app-reference.js +0 -2
  69. package/dist/crockford.d.ts +0 -4
  70. package/dist/crockford.d.ts.map +0 -1
  71. package/dist/crockford.js +0 -3
  72. package/dist/house-model.d.ts +0 -892
  73. package/dist/house-model.d.ts.map +0 -1
  74. package/dist/house-model.js +0 -482
  75. package/dist/part.d.ts +0 -14
  76. package/dist/part.d.ts.map +0 -1
  77. package/dist/part.js +0 -90
  78. package/dist/room-stream.d.ts +0 -20
  79. package/dist/room-stream.d.ts.map +0 -1
  80. package/dist/room-stream.js +0 -78
  81. package/dist/room-types.d.ts +0 -7
  82. package/dist/room-types.d.ts.map +0 -1
  83. package/dist/room-types.js +0 -125
package/dist/read.js CHANGED
@@ -1,16 +1,16 @@
1
- import { paced, patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
- import { gunzipped } from './part.js';
3
- import { readPosition, roomVersion } from './version.js';
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 REVISION_FILE.exec(revision)?.[1];
5
+ return REVISION_REFERENCE_PATTERN.exec(revision)?.[1];
7
6
  }
8
7
  export function answering() {
9
8
  return {
10
9
  documents: new Map(),
11
- outlines: new Map(),
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.outlines.delete(path);
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
- ...(answer.outlines.size === 0 ? {} : { outlines: yield* patching({}, answer.outlines) }),
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.created_at === undefined)
126
+ if (held.changed_at === undefined)
125
127
  return undefined;
126
- if (typeof held.created_at !== 'string')
128
+ if (typeof held.changed_at !== 'string')
127
129
  return null;
128
- return { author, time: held.created_at };
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,45 +151,37 @@ export function binaryFileOf(held) {
141
151
  function binaried(binary) {
142
152
  return binary === undefined ? {} : { binary };
143
153
  }
144
- export function outlineOf(value) {
145
- if (value === undefined)
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 parseFile(value, mode) {
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
- const outline = outlineOf(file.outline);
171
- if (head === null || binary === null || outline === null)
171
+ if (head === null || created === null || binary === null)
172
172
  return null;
173
+ const content = file.content === undefined ? {} : { content: file.content };
173
174
  if (mode === 'site') {
174
175
  if (typeof file.sha256 !== 'string')
175
176
  return null;
176
177
  return {
177
178
  path: file.path,
178
- revision: binary?.sha256 ?? file.sha256,
179
+ revision: binary?.sha256,
179
180
  version: file.sha256,
180
181
  ...headed(head),
181
182
  ...binaried(binary),
182
- ...(outline === undefined ? {} : { outline }),
183
+ ...carriedFacts(file),
184
+ ...content,
183
185
  };
184
186
  }
185
187
  if (typeof file.revision !== 'string')
@@ -188,185 +190,59 @@ function parseFile(value, mode) {
188
190
  path: file.path,
189
191
  revision: file.revision,
190
192
  version: file.revision,
191
- ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
192
193
  ...headed(head),
194
+ ...createdHeld(created),
193
195
  ...binaried(binary),
194
- ...(outline === undefined ? {} : { outline }),
196
+ ...carriedFacts(file),
197
+ ...carriedSpace(file),
198
+ ...content,
195
199
  };
196
200
  }
197
- function parseModels(value, mode) {
198
- if (!Array.isArray(value))
199
- return null;
200
- const files = [];
201
- const contents = [];
202
- for (const entry of value) {
203
- const file = parseFile(entry, mode);
204
- const { content } = entry;
205
- if (file === null || typeof content !== 'string')
206
- return null;
207
- files.push(file);
208
- contents.push({ path: file.path, content });
209
- }
210
- return { files, contents };
211
- }
212
- function parseRoomHead(value, mode) {
213
- if (typeof value !== 'object' || value === null)
214
- return null;
215
- const held = value;
216
- if (typeof held.manifest !== 'object' || held.manifest === null)
217
- return null;
218
- const models = parseModels(held.models, mode);
219
- if (models === null)
220
- return null;
221
- const manifest = held.manifest;
222
- if (manifest.scope !== 'room')
223
- return null;
224
- const at = readPosition(manifest);
225
- if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
226
- return null;
227
- if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
228
- return null;
229
- return { anchor: manifest.anchor, ...at, models };
230
- }
231
- export async function roomHead(payload, mode) {
232
- let text = '';
233
- try {
234
- for await (const chunk of gunzipped(payload))
235
- text += chunk;
236
- return text.endsWith('\n') && text.indexOf('\n') === text.length - 1
237
- ? parseRoomHead(JSON.parse(text), mode)
238
- : null;
239
- }
240
- catch {
241
- return null;
242
- }
243
- }
244
- export function manifested(room, pageToken, models) {
245
- return {
246
- kind: 'bootstrap',
247
- roomVersion: roomVersion(room),
248
- documents: {},
249
- revisions: {},
250
- changes: {},
251
- binaryFiles: {},
252
- pageToken,
253
- ...(models === undefined ? {} : { models }),
254
- };
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);
255
214
  }
256
215
  export function modelScope(room) {
257
- return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
258
- }
259
- export function emptyScope(room) {
260
216
  return {
261
217
  anchor: room.anchor,
262
218
  position: room.position,
263
219
  logEpoch: room.logEpoch,
264
- files: [],
265
- contents: [],
220
+ files: room.models,
266
221
  };
267
222
  }
268
- function partLine(line, mode, read) {
269
- if (read.ended)
270
- return false;
271
- let entry;
272
- try {
273
- entry = JSON.parse(line);
274
- }
275
- catch {
276
- return false;
277
- }
278
- if (endLine(entry)) {
279
- read.ended = true;
280
- return true;
281
- }
282
- if (folderLine(entry)) {
283
- read.folders.push(entry.folder);
284
- return true;
285
- }
286
- const file = parseFile(entry, mode);
287
- if (file === null)
288
- return false;
289
- read.files.push(file);
290
- const { content } = entry;
291
- if (typeof content === 'string')
292
- read.contents.push({ path: file.path, content });
293
- else if (content !== undefined)
294
- return false;
295
- return true;
296
- }
297
- async function partRead(chunks, mode) {
298
- const read = { files: [], contents: [], folders: [], ended: false };
299
- const pace = paced();
300
- const unfinished = [];
301
- for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
302
- const text = chunk.value;
303
- let start = 0;
304
- for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
305
- const piece = text.slice(start, end);
306
- const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
307
- if (!partLine(line, mode, read)) {
308
- await chunks.cancel();
309
- return null;
310
- }
311
- start = end + 1;
312
- const due = pace(line.length + ROW_WEIGHT);
313
- if (due instanceof Promise)
314
- await due;
315
- }
316
- if (start < text.length)
317
- unfinished.push(text.slice(start));
318
- }
319
- return unfinished.length === 0 ? read : null;
320
- }
321
- function endLine(entry) {
322
- if (typeof entry !== 'object' || entry === null || !('end' in entry))
323
- return false;
324
- return entry.end === true && Object.keys(entry).length === 1;
325
- }
326
- function folderLine(entry) {
327
- if (typeof entry !== 'object' || entry === null || !('folder' in entry))
328
- return false;
329
- return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
330
- }
331
- export async function housePart(room, payload, mode) {
332
- const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
333
- if (read === null)
334
- return { kind: 'transport-uncertainty' };
335
- const { ended, ...scope } = read;
336
- return { scope: { ...emptyScope(room), ...scope }, ended };
337
- }
338
223
  export function* bootstrapping(scope) {
339
- const contents = new Map();
340
- for (const entry of scope.contents) {
341
- contents.set(entry.path, entry.content);
342
- yield ROW_WEIGHT;
343
- }
344
224
  const answer = answering();
345
225
  for (const file of scope.files) {
346
226
  yield ROW_WEIGHT;
347
- if (file.head !== undefined)
348
- answer.changes.set(file.path, file.head);
349
- const content = contents.get(file.path);
350
- if (file.binary !== undefined)
351
- answer.binaryFiles.set(file.path, file.binary);
352
- else if (content !== undefined)
353
- answer.documents.set(file.path, content);
354
- else if (file.outline !== undefined)
355
- answer.outlines.set(file.path, file.outline);
356
- if (file.revision !== undefined)
357
- revised(answer, file.path, file.revision);
227
+ if (file.space === undefined)
228
+ kept(answer, file);
358
229
  }
359
230
  for (const folder of scope.folders ?? [])
360
231
  folded(answer, folder, false);
361
232
  const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
362
233
  return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
363
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
+ }
364
245
  export function schemaOf(scope, schema) {
365
246
  const file = scope.files.find((entry) => entry.path === schema);
366
- if (file === undefined)
367
- return { schema: null, version: null, revision: null };
368
- const content = scope.contents.find((entry) => entry.path === schema);
369
- return content === undefined
370
- ? null
371
- : { schema: content.content, version: file.version, revision: file.revision ?? null };
247
+ return file === undefined ? { schema: null, version: null, revision: null } : schemaFile(file);
372
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
@@ -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,EACd,MAAM,wBAAwB,CAAC;AAEhC,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAOjE;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,eAAe,GACvB,aAAa,CAEf;AAqBD,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"}
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 { kind: 'transport-uncertainty' };
18
- const refusal = doorRefusal(body);
28
+ return UNANSWERED;
19
29
  if (status === 401)
20
30
  return { kind: 'revoked-authorization' };
21
- if (refusal?.retryable === true || refusal?.code === 'update_required') {
22
- return { kind: 'transport-uncertainty' };
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 { kind: 'transport-uncertainty' };
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 { kind: 'transport-uncertainty' };
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
@@ -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;AAsBrE,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,CAoBvB"}
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 UNCERTAIN;
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 {};