@agentshouse/mdruntime-adapter 0.1.0-cc63dd043d0e2 → 0.1.0-cc710a8825617

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 (51) hide show
  1. package/AGENTS.md +270 -183
  2. package/README.md +3 -3
  3. package/dist/actions.d.ts +63 -2
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +154 -138
  6. package/dist/adapter.d.ts +1 -0
  7. package/dist/adapter.d.ts.map +1 -1
  8. package/dist/adapter.js +325 -166
  9. package/dist/discovery.d.ts +6 -12
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +32 -36
  12. package/dist/gather.d.ts +1 -0
  13. package/dist/gather.d.ts.map +1 -1
  14. package/dist/gather.js +11 -6
  15. package/dist/handed.d.ts +15 -0
  16. package/dist/handed.d.ts.map +1 -0
  17. package/dist/handed.js +38 -0
  18. package/dist/index.d.ts +2 -2
  19. package/dist/index.d.ts.map +1 -1
  20. package/dist/index.js +1 -1
  21. package/dist/model.d.ts +7 -18
  22. package/dist/model.d.ts.map +1 -1
  23. package/dist/model.js +60 -39
  24. package/dist/read.d.ts +35 -7
  25. package/dist/read.d.ts.map +1 -1
  26. package/dist/read.js +164 -86
  27. package/dist/referrer.d.ts +7 -0
  28. package/dist/referrer.d.ts.map +1 -0
  29. package/dist/referrer.js +35 -0
  30. package/dist/refusal.d.ts +5 -9
  31. package/dist/refusal.d.ts.map +1 -1
  32. package/dist/refusal.js +31 -17
  33. package/dist/site.d.ts +1 -1
  34. package/dist/site.d.ts.map +1 -1
  35. package/dist/site.js +191 -107
  36. package/dist/stream.d.ts +10 -4
  37. package/dist/stream.d.ts.map +1 -1
  38. package/dist/stream.js +391 -47
  39. package/dist/transport.d.ts +79 -11
  40. package/dist/transport.d.ts.map +1 -1
  41. package/dist/transport.js +3 -1
  42. package/dist/version.d.ts +2 -0
  43. package/dist/version.d.ts.map +1 -1
  44. package/dist/version.js +10 -1
  45. package/dist/write.d.ts +2 -1
  46. package/dist/write.d.ts.map +1 -1
  47. package/dist/write.js +96 -14
  48. package/package.json +3 -4
  49. package/dist/links.d.ts +0 -12
  50. package/dist/links.d.ts.map +0 -1
  51. package/dist/links.js +0 -66
package/dist/read.js CHANGED
@@ -1,9 +1,20 @@
1
- import { readPosition, roomVersion } from './version.js';
1
+ import { DECIMAL, readPosition, roomVersion } from './version.js';
2
+ const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
3
+ export function identities(revisions) {
4
+ const fileIds = Object.fromEntries(Object.entries(revisions).flatMap(([path, revision]) => {
5
+ const file = REVISION_FILE.exec(revision)?.[1];
6
+ return file === undefined ? [] : [[path, file]];
7
+ }));
8
+ return Object.keys(fileIds).length === 0 ? {} : { fileIds };
9
+ }
2
10
  export function authorityRoot(handle) {
3
11
  return `/rooms/${handle}`;
4
12
  }
5
13
  export function contentPrefixes(tracked) {
6
- return [authorityRoot(tracked.handle)];
14
+ return [
15
+ authorityRoot(tracked.handle),
16
+ ...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
17
+ ];
7
18
  }
8
19
  export function schemaPath(handle, schema) {
9
20
  return `${authorityRoot(handle)}/${schema}`;
@@ -48,32 +59,19 @@ export function headChange(held) {
48
59
  function headed(head) {
49
60
  return head === undefined ? {} : { head };
50
61
  }
51
- function parseOriginal(value) {
52
- if (typeof value !== 'object' || value === null)
53
- return null;
54
- const { attachment, name, bytes, media_type: mediaType } = value;
55
- if (typeof attachment !== 'string' || typeof name !== 'string')
56
- return null;
57
- if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0)
58
- return null;
59
- if (mediaType !== null && typeof mediaType !== 'string')
60
- return null;
61
- return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
62
- }
63
- function parseOriginals(value) {
64
- if (!Array.isArray(value))
62
+ export function binaryFileOf(held) {
63
+ if (held.file === undefined)
64
+ return undefined;
65
+ const { file, bytes, media_type: mediaType, sha256 } = held;
66
+ if (typeof file !== 'string' ||
67
+ typeof bytes !== 'number' ||
68
+ typeof mediaType !== 'string' ||
69
+ typeof sha256 !== 'string')
65
70
  return null;
66
- const attachments = [];
67
- for (const entry of value) {
68
- const attachment = parseOriginal(entry);
69
- if (attachment === null)
70
- return null;
71
- attachments.push(attachment);
72
- }
73
- return attachments;
71
+ return { fileRef: file, byteLength: bytes, mediaType, sha256 };
74
72
  }
75
- function declared(attachments) {
76
- return attachments === undefined ? {} : { attachments };
73
+ function binaried(binary) {
74
+ return binary === undefined ? {} : { binary };
77
75
  }
78
76
  function parseFile(value, mode) {
79
77
  if (typeof value !== 'object' || value === null)
@@ -82,16 +80,30 @@ function parseFile(value, mode) {
82
80
  if (typeof file.path !== 'string')
83
81
  return null;
84
82
  const head = headChange(file);
85
- if (head === null)
83
+ const binary = binaryFileOf(file);
84
+ if (head === null || binary === null)
86
85
  return null;
87
86
  if (mode === 'site') {
88
87
  if (typeof file.sha256 !== 'string')
89
88
  return null;
90
- return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
89
+ return {
90
+ path: file.path,
91
+ revision: binary?.sha256,
92
+ version: file.sha256,
93
+ ...headed(head),
94
+ ...binaried(binary),
95
+ };
91
96
  }
92
97
  if (typeof file.revision !== 'string')
93
98
  return null;
94
- return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
99
+ return {
100
+ path: file.path,
101
+ revision: file.revision,
102
+ version: file.revision,
103
+ ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
104
+ ...headed(head),
105
+ ...binaried(binary),
106
+ };
95
107
  }
96
108
  function parseScope(value, mode) {
97
109
  if (typeof value !== 'object' || value === null)
@@ -127,12 +139,28 @@ function parseScope(value, mode) {
127
139
  return null;
128
140
  contents.push({ path: content.path, content: content.content });
129
141
  }
130
- if (mode === 'site')
131
- return { anchor: manifest.anchor, ...at, files, contents };
132
- const attachments = parseOriginals(held.originals);
133
- if (attachments === null)
142
+ return { anchor: manifest.anchor, ...at, files, contents };
143
+ }
144
+ function parseCut(value) {
145
+ if (value === undefined)
146
+ return undefined;
147
+ if (typeof value !== 'object' || value === null)
148
+ return null;
149
+ const { position, log_epoch: logEpoch } = value;
150
+ if (typeof position !== 'string' || typeof logEpoch !== 'string')
151
+ return null;
152
+ return { position, log_epoch: logEpoch };
153
+ }
154
+ function parseCursor(value) {
155
+ if (typeof value !== 'object' || value === null)
156
+ return null;
157
+ const { room, path, cut } = value;
158
+ if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
134
159
  return null;
135
- return { anchor: manifest.anchor, ...at, files, contents, attachments };
160
+ const parsed = parseCut(cut);
161
+ if (parsed === null)
162
+ return null;
163
+ return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
136
164
  }
137
165
  export function parseEnvelope(body) {
138
166
  if (typeof body !== 'object' || body === null)
@@ -146,11 +174,26 @@ export function parseEnvelope(body) {
146
174
  return null;
147
175
  scopes.push(scope);
148
176
  }
149
- return { scopes };
177
+ if (!('next' in body) || body.next === undefined)
178
+ return { scopes };
179
+ const next = parseCursor(body.next);
180
+ return next === null ? null : { scopes, next };
150
181
  }
151
182
  export function parseSiteBootstrap(body) {
152
183
  return parseScope(body, 'site');
153
184
  }
185
+ export function siteBootstrapNext(body) {
186
+ if (typeof body !== 'object' || body === null || !('next' in body))
187
+ return null;
188
+ return typeof body.next === 'string' && body.next.length > 0 ? body.next : null;
189
+ }
190
+ export function siteBootstrapOffset(body) {
191
+ if (typeof body !== 'object' || body === null || !('offset' in body))
192
+ return null;
193
+ return Number.isSafeInteger(body.offset) && body.offset > 0
194
+ ? body.offset
195
+ : null;
196
+ }
154
197
  function parseChange(value, mode) {
155
198
  if (typeof value !== 'object' || value === null)
156
199
  return null;
@@ -160,8 +203,15 @@ function parseChange(value, mode) {
160
203
  if (held.removed === true)
161
204
  return { path: held.path, removed: true };
162
205
  const head = headChange(held);
163
- if (head === null)
206
+ const binary = binaryFileOf(held);
207
+ if (head === null || binary === null)
164
208
  return null;
209
+ if (binary !== undefined) {
210
+ if (mode === 'credential' && typeof held.revision !== 'string')
211
+ return null;
212
+ const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
213
+ return { path: held.path, binary, revision, version: revision, ...headed(head) };
214
+ }
165
215
  if (mode === 'site') {
166
216
  if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
167
217
  return null;
@@ -182,12 +232,6 @@ function parseChange(value, mode) {
182
232
  ...headed(head),
183
233
  };
184
234
  }
185
- if (typeof held.reference === 'object' && held.reference !== null) {
186
- const reference = held.reference;
187
- if (typeof reference.revision !== 'string')
188
- return null;
189
- return { path: held.path, reference: { revision: reference.revision } };
190
- }
191
235
  return null;
192
236
  }
193
237
  export function parseEnumeration(body, mode) {
@@ -212,17 +256,60 @@ export function parseEnumeration(body, mode) {
212
256
  return null;
213
257
  changes.push(mapped);
214
258
  }
215
- if (mode === 'site') {
216
- authorities.push({ authority: held.authority, ...at, changes });
217
- continue;
218
- }
219
- const attachments = parseOriginals(held.originals);
220
- if (attachments === null)
259
+ const next = held.next === undefined ? undefined : readPage(held.next);
260
+ if (next === null)
221
261
  return null;
222
- authorities.push({ authority: held.authority, ...at, changes, attachments });
262
+ authorities.push({
263
+ authority: held.authority,
264
+ ...at,
265
+ changes,
266
+ ...(next === undefined ? {} : { next }),
267
+ });
223
268
  }
224
269
  return { authorities };
225
270
  }
271
+ function readPage(held) {
272
+ if (typeof held !== 'object' || held === null)
273
+ return null;
274
+ const { after, through, read } = held;
275
+ if (typeof after !== 'string' || !DECIMAL.test(after))
276
+ return null;
277
+ if (typeof through !== 'string' || !DECIMAL.test(through))
278
+ return null;
279
+ if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
280
+ return null;
281
+ return { after, through, read };
282
+ }
283
+ function advances(asked, next) {
284
+ const moved = BigInt(next.through) - BigInt(asked.through);
285
+ return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
286
+ }
287
+ export async function wholeView(first, more) {
288
+ const changes = new Map(first.changes.map((change) => [change.path, change]));
289
+ let view = first;
290
+ while (view.next !== undefined) {
291
+ const asked = view.next;
292
+ const page = await more(asked);
293
+ if ('kind' in page)
294
+ return page;
295
+ if (page.position !== asked.through ||
296
+ page.logEpoch !== first.logEpoch ||
297
+ (page.next !== undefined && !advances(asked, page.next))) {
298
+ return { kind: 'transport-uncertainty' };
299
+ }
300
+ for (const change of page.changes) {
301
+ changes.delete(change.path);
302
+ changes.set(change.path, change);
303
+ }
304
+ view = page;
305
+ }
306
+ return {
307
+ authority: first.authority,
308
+ position: view.position,
309
+ logEpoch: first.logEpoch,
310
+ changes: [...changes.values()],
311
+ };
312
+ }
226
313
  export function advancedScope(scope, view) {
227
314
  const files = new Map(scope.files.map((file) => [file.path, file]));
228
315
  const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
@@ -231,18 +318,15 @@ export function advancedScope(scope, view) {
231
318
  contents.delete(change.path);
232
319
  if ('removed' in change)
233
320
  continue;
234
- if ('content' in change) {
235
- files.set(change.path, {
236
- path: change.path,
237
- revision: change.revision,
238
- version: change.version,
239
- ...headed(change.head),
240
- });
321
+ files.set(change.path, {
322
+ path: change.path,
323
+ revision: change.revision,
324
+ version: change.version,
325
+ ...headed(change.head),
326
+ ...('binary' in change ? { binary: change.binary } : {}),
327
+ });
328
+ if ('content' in change)
241
329
  contents.set(change.path, change.content);
242
- continue;
243
- }
244
- const { revision } = change.reference;
245
- files.set(change.path, { path: change.path, revision, version: revision });
246
330
  }
247
331
  return {
248
332
  ...scope,
@@ -260,16 +344,16 @@ export function bootstrapOf(scope) {
260
344
  const documents = {};
261
345
  const revisions = {};
262
346
  const changes = {};
263
- const binaryTargets = [];
347
+ const binaryFiles = {};
264
348
  for (const file of scope.files) {
265
349
  if (file.revision !== undefined)
266
350
  revisions[file.path] = file.revision;
267
351
  if (file.head !== undefined)
268
352
  changes[file.path] = file.head;
269
353
  const content = contents.get(file.path);
270
- if (content === undefined)
271
- binaryTargets.push(file.path);
272
- else
354
+ if (file.binary !== undefined)
355
+ binaryFiles[file.path] = file.binary;
356
+ else if (content !== undefined)
273
357
  documents[file.path] = content;
274
358
  }
275
359
  return {
@@ -277,23 +361,19 @@ export function bootstrapOf(scope) {
277
361
  roomVersion: roomVersion(scope),
278
362
  documents,
279
363
  revisions,
364
+ ...identities(revisions),
280
365
  changes,
281
- binaryTargets: binaryTargets.sort(),
282
- ...declared(scope.attachments),
366
+ binaryFiles,
283
367
  };
284
368
  }
285
- export function schemaFrom(envelope, tracked, schema) {
286
- const scope = envelope.scopes.find((entry) => matchesScope(entry, tracked));
287
- if (scope === undefined)
288
- return null;
289
- return schemaOf(scope, schema);
290
- }
291
369
  export function schemaOf(scope, schema) {
292
370
  const file = scope.files.find((entry) => entry.path === schema);
293
371
  if (file === undefined)
294
- return { schema: null, version: null };
372
+ return { schema: null, version: null, revision: null };
295
373
  const content = scope.contents.find((entry) => entry.path === schema);
296
- return content === undefined ? null : { schema: content.content, version: file.version };
374
+ return content === undefined
375
+ ? null
376
+ : { schema: content.content, version: file.version, revision: file.revision ?? null };
297
377
  }
298
378
  export function viewOf(enumeration, tracked) {
299
379
  return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
@@ -304,32 +384,30 @@ export function refreshFrom(view, fromRoomVersion) {
304
384
  const documents = {};
305
385
  const revisions = {};
306
386
  const changes = {};
307
- const binaryTargets = [];
387
+ const binaryFiles = {};
308
388
  const removals = [];
309
389
  for (const change of view.changes) {
310
390
  if ('removed' in change) {
311
391
  removals.push(change.path);
312
392
  continue;
313
393
  }
314
- if ('content' in change) {
394
+ if ('content' in change)
315
395
  documents[change.path] = change.content;
316
- if (change.revision !== undefined)
317
- revisions[change.path] = change.revision;
318
- if (change.head !== undefined)
319
- changes[change.path] = change.head;
320
- continue;
321
- }
322
- binaryTargets.push(change.path);
323
- revisions[change.path] = change.reference.revision;
396
+ else
397
+ binaryFiles[change.path] = change.binary;
398
+ if (change.revision !== undefined)
399
+ revisions[change.path] = change.revision;
400
+ if (change.head !== undefined)
401
+ changes[change.path] = change.head;
324
402
  }
325
403
  return {
326
404
  kind: 'net-advancement',
327
405
  roomVersion: roomVersion(view),
328
406
  documents,
329
407
  revisions,
408
+ ...identities(revisions),
330
409
  changes,
331
- binaryTargets: binaryTargets.sort(),
410
+ binaryFiles,
332
411
  removals: removals.sort(),
333
- ...declared(view.attachments),
334
412
  };
335
413
  }
@@ -0,0 +1,7 @@
1
+ import type { TrackedAuthority } from './discovery.js';
2
+ export type HouseReferrer = {
3
+ locator: string;
4
+ referrer: Readonly<Record<string, string>>;
5
+ };
6
+ export declare function houseReferrer(referrer: unknown, tracked: ReadonlyMap<string, TrackedAuthority>): HouseReferrer | null;
7
+ //# sourceMappingURL=referrer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"referrer.d.ts","sourceRoot":"","sources":["../src/referrer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,MAAM,MAAM,aAAa,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC;IAAC,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAgB5F,wBAAgB,aAAa,CAC3B,QAAQ,EAAE,OAAO,EACjB,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,gBAAgB,CAAC,GAC7C,aAAa,GAAG,IAAI,CAqBtB"}
@@ -0,0 +1,35 @@
1
+ function fields(value) {
2
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
3
+ ? value
4
+ : null;
5
+ }
6
+ function named(held, ...keys) {
7
+ const present = Object.keys(held);
8
+ return (present.length === keys.length &&
9
+ keys.every((key) => typeof held[key] === 'string' && held[key] !== ''));
10
+ }
11
+ export function houseReferrer(referrer, tracked) {
12
+ const held = fields(referrer);
13
+ if (held === null)
14
+ return null;
15
+ if (named(held, 'room', 'path')) {
16
+ const entry = tracked.get(held.room);
17
+ if (entry === undefined)
18
+ return null;
19
+ return {
20
+ locator: entry.locator,
21
+ referrer: { room_ref: entry.authority, path: held.path },
22
+ };
23
+ }
24
+ if (named(held, 'room_ref', 'record')) {
25
+ const roomRef = held.room_ref;
26
+ const entry = [...tracked.values()].find((candidate) => candidate.authority === roomRef);
27
+ return {
28
+ locator: entry?.locator ?? roomRef,
29
+ referrer: { room_ref: roomRef, record: held.record },
30
+ };
31
+ }
32
+ if (named(held, 'message'))
33
+ return { locator: '', referrer: { message: held.message } };
34
+ return null;
35
+ }
package/dist/refusal.d.ts CHANGED
@@ -1,13 +1,9 @@
1
1
  import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
2
- export type DoorRefusal = ProviderRefusal & {
3
- retryable: boolean;
4
- };
5
- export declare function doorRefusal(body: unknown): DoorRefusal | null;
6
- export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: DoorRefusal): ScopedRefusal;
7
- export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | {
2
+ export declare function doorRefusal(body: unknown): ProviderRefusal | null;
3
+ export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
4
+ export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
5
+ export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
8
6
  kind: 'beyond-horizon';
9
7
  } | null;
10
- export declare function discoveryFailure(classified: AdapterFailure | {
11
- kind: 'beyond-horizon';
12
- }): DiscoverResult;
8
+ export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
13
9
  //# 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,MAAM,MAAM,WAAW,GAAG,eAAe,GAAG;IAAE,SAAS,EAAE,OAAO,CAAA;CAAE,CAAC;AAEnE,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAO7D;AAED,wBAAgB,aAAa,CAC3B,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,EAC7B,OAAO,EAAE,WAAW,GACnB,aAAa,CAEf;AAED,wBAAgB,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAapD;AAED,wBAAgB,gBAAgB,CAC9B,UAAU,EAAE,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACtD,cAAc,CAMhB"}
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,YAAY,CAC1B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,MAAM,GACd,cAAc,GAAG;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAAG,IAAI,CAGpD;AAED,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,cAAc,GAAG,IAAI,CAQrF"}
package/dist/refusal.js CHANGED
@@ -6,38 +6,52 @@ export function doorRefusal(body) {
6
6
  const error = body.error;
7
7
  if (typeof error.code !== 'string')
8
8
  return null;
9
- const { code, ...fields } = error;
10
- return { code, fields, retryable: error.retryable === true };
9
+ const { code, retryable, ...fields } = error;
10
+ return { code, fields, retryable: retryable === true };
11
11
  }
12
12
  export function scopedRefusal(locator, scope, refusal) {
13
- return { kind: 'scoped-refusal', locator, scope, code: refusal.code, fields: refusal.fields };
13
+ return { kind: 'scoped-refusal', locator, scope, ...refusal };
14
14
  }
15
- export function classifyDoor(status, body, locator) {
15
+ function doorFailure(status, body) {
16
16
  if (status === 0)
17
17
  return { kind: 'transport-uncertainty' };
18
18
  const refusal = doorRefusal(body);
19
19
  if (status === 401)
20
20
  return { kind: 'revoked-authorization' };
21
- if (refusal?.retryable === true)
21
+ if (refusal?.retryable === true || refusal?.code === 'update_required') {
22
22
  return { kind: 'transport-uncertainty' };
23
- if (refusal !== null && refusal.code === 'position_expired')
24
- return { kind: 'beyond-horizon' };
25
- if (status === 404 || refusal?.code === 'room_not_found') {
26
- return { kind: 'room-not-readable', locator };
27
23
  }
24
+ if (status === 404 || refusal?.code === 'room_not_found')
25
+ return { kind: 'room-not-readable' };
28
26
  if (status < 400)
29
27
  return null;
30
28
  if (refusal === null)
31
29
  return { kind: 'transport-uncertainty' };
32
- if (status === 403)
33
- return scopedRefusal(locator, 'operation', refusal);
34
- return scopedRefusal(locator, 'undisclosed', refusal);
30
+ return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
31
+ }
32
+ export function classifyDoor(status, body, locator) {
33
+ const failure = doorFailure(status, body);
34
+ if (failure === null)
35
+ return null;
36
+ if (failure.kind === 'room-not-readable')
37
+ return { kind: 'room-not-readable', locator };
38
+ if (failure.kind === 'refused')
39
+ return scopedRefusal(locator, failure.scope, failure.refusal);
40
+ return failure;
35
41
  }
36
- export function discoveryFailure(classified) {
37
- if (classified.kind === 'revoked-authorization')
38
- return classified;
39
- if (classified.kind === 'scoped-refusal') {
40
- return { kind: 'contract-unavailable', code: classified.code, fields: classified.fields };
42
+ export function classifyRead(status, body, locator) {
43
+ if (doorRefusal(body)?.code === 'expired')
44
+ return { kind: 'beyond-horizon' };
45
+ return classifyDoor(status, body, locator);
46
+ }
47
+ export function discoveryFailure(status, body) {
48
+ const failure = doorFailure(status, body);
49
+ if (failure === null)
50
+ return null;
51
+ if (failure.kind === 'revoked-authorization')
52
+ return failure;
53
+ if (failure.kind === 'refused') {
54
+ return { kind: 'contract-unavailable', ...failure.refusal };
41
55
  }
42
56
  return { kind: 'transport-uncertainty' };
43
57
  }
package/dist/site.d.ts CHANGED
@@ -1,4 +1,4 @@
1
1
  import type { Adapter } from '@agentshouse/mdruntime';
2
2
  import { type HouseSiteTransport } from './transport.js';
3
- export declare function createSiteAdapter(transport: HouseSiteTransport): Adapter;
3
+ export declare function createSiteAdapter(transport: HouseSiteTransport, snapshot?: boolean): Adapter;
4
4
  //# sourceMappingURL=site.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAQR,MAAM,wBAAwB,CAAC;AA+BhC,OAAO,EAML,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAsCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,GAAG,OAAO,CAuKxE"}
1
+ {"version":3,"file":"site.d.ts","sourceRoot":"","sources":["../src/site.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,OAAO,EAOR,MAAM,wBAAwB,CAAC;AA2BhC,OAAO,EAOL,KAAK,kBAAkB,EACxB,MAAM,gBAAgB,CAAC;AAmCxB,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,kBAAkB,EAAE,QAAQ,UAAQ,GAAG,OAAO,CA+Q1F"}