@agentshouse/mdruntime-adapter 0.1.0-alpha.9 → 0.1.0-c09c6f263662c

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 (64) hide show
  1. package/AGENTS.md +272 -33
  2. package/README.md +32 -0
  3. package/dist/actions.d.ts +43 -13
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +270 -351
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +361 -221
  8. package/dist/digest.js +1 -5
  9. package/dist/discovery.d.ts +23 -34
  10. package/dist/discovery.d.ts.map +1 -1
  11. package/dist/discovery.js +154 -231
  12. package/dist/gather.d.ts +4 -0
  13. package/dist/gather.d.ts.map +1 -0
  14. package/dist/gather.js +45 -0
  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 -3
  21. package/dist/map.d.ts +2 -2
  22. package/dist/map.d.ts.map +1 -1
  23. package/dist/map.js +6 -7
  24. package/dist/model.d.ts +8 -18
  25. package/dist/model.d.ts.map +1 -1
  26. package/dist/model.js +63 -57
  27. package/dist/read.d.ts +40 -29
  28. package/dist/read.d.ts.map +1 -1
  29. package/dist/read.js +209 -208
  30. package/dist/referrer.d.ts +7 -0
  31. package/dist/referrer.d.ts.map +1 -0
  32. package/dist/referrer.js +35 -0
  33. package/dist/refusal.d.ts +5 -7
  34. package/dist/refusal.d.ts.map +1 -1
  35. package/dist/refusal.js +47 -69
  36. package/dist/site.d.ts.map +1 -1
  37. package/dist/site.js +144 -153
  38. package/dist/stream.d.ts +17 -6
  39. package/dist/stream.d.ts.map +1 -1
  40. package/dist/stream.js +251 -215
  41. package/dist/transport.d.ts +81 -33
  42. package/dist/transport.d.ts.map +1 -1
  43. package/dist/transport.js +4 -3
  44. package/dist/version.d.ts +2 -0
  45. package/dist/version.d.ts.map +1 -1
  46. package/dist/version.js +32 -18
  47. package/dist/write.d.ts +7 -8
  48. package/dist/write.d.ts.map +1 -1
  49. package/dist/write.js +196 -206
  50. package/package.json +5 -13
  51. package/dist/actions.js.map +0 -1
  52. package/dist/adapter.js.map +0 -1
  53. package/dist/digest.js.map +0 -1
  54. package/dist/discovery.js.map +0 -1
  55. package/dist/index.js.map +0 -1
  56. package/dist/map.js.map +0 -1
  57. package/dist/model.js.map +0 -1
  58. package/dist/read.js.map +0 -1
  59. package/dist/refusal.js.map +0 -1
  60. package/dist/site.js.map +0 -1
  61. package/dist/stream.js.map +0 -1
  62. package/dist/transport.js.map +0 -1
  63. package/dist/version.js.map +0 -1
  64. package/dist/write.js.map +0 -1
package/dist/read.js CHANGED
@@ -1,128 +1,192 @@
1
- import { PROVIDER_SELECTION_ROOTS } from './discovery.js';
2
1
  import { readPosition, roomVersion } from './version.js';
3
2
  export function authorityRoot(handle) {
4
- return handle === undefined ? '/private' : `/rooms/${handle}`;
3
+ return `/rooms/${handle}`;
5
4
  }
6
- export const ROOM_README = 'ROOM.md';
7
- export function selectionRoots(tracked) {
8
- if (tracked.handle === undefined) {
9
- return [
10
- tracked.collectionRoot,
11
- ...PROVIDER_SELECTION_ROOTS
12
- ];
13
- }
5
+ export function contentPrefixes(tracked) {
14
6
  return [
15
- ROOM_README,
16
- tracked.collectionRoot
7
+ authorityRoot(tracked.handle),
8
+ ...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
17
9
  ];
18
10
  }
19
- export function contentPrefixes(tracked) {
20
- const root = authorityRoot(tracked.handle);
21
- return selectionRoots(tracked).filter((entry)=>entry !== ROOM_README).map((entry)=>`${root}/${entry}`);
22
- }
23
- export function modelPrefix(tracked, modelRoot) {
24
- return `${authorityRoot(tracked.handle)}/${modelRoot}`;
11
+ export function schemaPath(handle, schema) {
12
+ return `${authorityRoot(handle)}/${schema}`;
25
13
  }
26
14
  export function parseGrant(body) {
27
- if (typeof body !== 'object' || body === null) return null;
15
+ if (typeof body !== 'object' || body === null)
16
+ return null;
28
17
  if (!('transfer' in body) || typeof body.transfer !== 'object' || body.transfer === null) {
29
18
  return null;
30
19
  }
31
20
  const transfer = body.transfer;
32
- if (transfer.method !== 'GET' && transfer.method !== 'POST') return null;
33
- if (typeof transfer.operation !== 'string' || typeof transfer.url !== 'string') return null;
34
- return {
35
- method: transfer.method,
36
- operation: transfer.operation,
37
- url: transfer.url
38
- };
21
+ if (typeof transfer.url !== 'string')
22
+ return null;
23
+ if (transfer.method === 'GET')
24
+ return { method: 'GET', url: transfer.url };
25
+ if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
26
+ return null;
27
+ return { method: 'POST', operation: transfer.operation, url: transfer.url };
28
+ }
29
+ function changeAuthor(value) {
30
+ if (typeof value !== 'object' || value === null)
31
+ return null;
32
+ const { user, site, name } = value;
33
+ if (typeof name !== 'string')
34
+ return null;
35
+ if (typeof user === 'string' && site === undefined)
36
+ return { kind: 'user', id: user, name };
37
+ if (typeof site === 'string' && user === undefined)
38
+ return { kind: 'site', id: site, name };
39
+ return null;
40
+ }
41
+ export function headChange(held) {
42
+ const author = held.author === undefined ? null : changeAuthor(held.author);
43
+ if (held.author !== undefined && author === null)
44
+ return null;
45
+ if (held.created_at === undefined)
46
+ return undefined;
47
+ if (typeof held.created_at !== 'string')
48
+ return null;
49
+ return { author, time: held.created_at };
50
+ }
51
+ function headed(head) {
52
+ return head === undefined ? {} : { head };
53
+ }
54
+ export function binaryFileOf(held) {
55
+ if (held.file === undefined)
56
+ return undefined;
57
+ const { file, bytes, media_type: mediaType, sha256 } = held;
58
+ if (typeof file !== 'string' ||
59
+ typeof bytes !== 'number' ||
60
+ typeof mediaType !== 'string' ||
61
+ typeof sha256 !== 'string')
62
+ return null;
63
+ return { fileRef: file, byteLength: bytes, mediaType, sha256 };
64
+ }
65
+ function binaried(binary) {
66
+ return binary === undefined ? {} : { binary };
39
67
  }
40
68
  function parseFile(value, mode) {
41
- if (typeof value !== 'object' || value === null) return null;
69
+ if (typeof value !== 'object' || value === null)
70
+ return null;
42
71
  const file = value;
43
- if (typeof file.path !== 'string') return null;
72
+ if (typeof file.path !== 'string')
73
+ return null;
74
+ const head = headChange(file);
75
+ const binary = binaryFileOf(file);
76
+ if (head === null || binary === null)
77
+ return null;
44
78
  if (mode === 'site') {
45
- if (typeof file.sha256 !== 'string') return null;
79
+ if (typeof file.sha256 !== 'string')
80
+ return null;
46
81
  return {
47
82
  path: file.path,
48
- revision: undefined,
49
- version: file.sha256
83
+ revision: binary?.sha256,
84
+ version: file.sha256,
85
+ ...headed(head),
86
+ ...binaried(binary),
50
87
  };
51
88
  }
52
- if (typeof file.revision !== 'string') return null;
89
+ if (typeof file.revision !== 'string')
90
+ return null;
53
91
  return {
54
92
  path: file.path,
55
93
  revision: file.revision,
56
- version: file.revision
94
+ version: file.revision,
95
+ ...headed(head),
96
+ ...binaried(binary),
57
97
  };
58
98
  }
59
99
  function parseScope(value, mode) {
60
- if (typeof value !== 'object' || value === null) return null;
100
+ if (typeof value !== 'object' || value === null)
101
+ return null;
61
102
  const held = value;
62
- if (typeof held.manifest !== 'object' || held.manifest === null) return null;
63
- if (!Array.isArray(held.contents)) return null;
103
+ if (typeof held.manifest !== 'object' || held.manifest === null)
104
+ return null;
105
+ if (!Array.isArray(held.contents))
106
+ return null;
64
107
  const manifest = held.manifest;
65
- if (manifest.scope !== 'room' && manifest.scope !== 'private') return null;
108
+ if (manifest.scope !== 'room')
109
+ return null;
66
110
  const at = readPosition(manifest);
67
- if (typeof manifest.anchor !== 'string' || at === null) return null;
68
- if (!Array.isArray(manifest.files)) return null;
111
+ if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
112
+ return null;
113
+ if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
114
+ return null;
115
+ if (!Array.isArray(manifest.files))
116
+ return null;
69
117
  const files = [];
70
- for (const entry of manifest.files){
118
+ for (const entry of manifest.files) {
71
119
  const file = parseFile(entry, mode);
72
- if (file === null) return null;
120
+ if (file === null)
121
+ return null;
73
122
  files.push(file);
74
123
  }
75
124
  const contents = [];
76
- for (const entry of held.contents){
77
- if (typeof entry !== 'object' || entry === null) return null;
125
+ for (const entry of held.contents) {
126
+ if (typeof entry !== 'object' || entry === null)
127
+ return null;
78
128
  const content = entry;
79
- if (typeof content.path !== 'string' || typeof content.content !== 'string') return null;
80
- contents.push({
81
- path: content.path,
82
- content: content.content
83
- });
129
+ if (typeof content.path !== 'string' || typeof content.content !== 'string')
130
+ return null;
131
+ contents.push({ path: content.path, content: content.content });
84
132
  }
85
- return {
86
- scope: manifest.scope,
87
- anchor: manifest.anchor,
88
- roomHandle: typeof manifest.room_handle === 'string' ? manifest.room_handle : undefined,
89
- ...at,
90
- files,
91
- contents
92
- };
133
+ return { anchor: manifest.anchor, ...at, files, contents };
134
+ }
135
+ function parseCursor(value) {
136
+ if (typeof value !== 'object' || value === null)
137
+ return null;
138
+ const { room, path } = value;
139
+ if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
140
+ return null;
141
+ return { room, path };
93
142
  }
94
143
  export function parseEnvelope(body) {
95
- if (typeof body !== 'object' || body === null) return null;
96
- if (!('scopes' in body) || !Array.isArray(body.scopes)) return null;
144
+ if (typeof body !== 'object' || body === null)
145
+ return null;
146
+ if (!('scopes' in body) || !Array.isArray(body.scopes))
147
+ return null;
97
148
  const scopes = [];
98
- for (const entry of body.scopes){
149
+ for (const entry of body.scopes) {
99
150
  const scope = parseScope(entry, 'credential');
100
- if (scope === null) return null;
151
+ if (scope === null)
152
+ return null;
101
153
  scopes.push(scope);
102
154
  }
103
- return {
104
- scopes
105
- };
155
+ if (!('next' in body) || body.next === undefined)
156
+ return { scopes };
157
+ const next = parseCursor(body.next);
158
+ return next === null ? null : { scopes, next };
106
159
  }
107
160
  export function parseSiteBootstrap(body) {
108
- const scope = parseScope(body, 'site');
109
- return scope !== null && scope.scope === 'room' ? scope : null;
161
+ return parseScope(body, 'site');
110
162
  }
111
163
  function parseChange(value, mode) {
112
- if (typeof value !== 'object' || value === null) return null;
164
+ if (typeof value !== 'object' || value === null)
165
+ return null;
113
166
  const held = value;
114
- if (typeof held.path !== 'string') return null;
115
- if (held.removed === true) return {
116
- path: held.path,
117
- removed: true
118
- };
167
+ if (typeof held.path !== 'string')
168
+ return null;
169
+ if (held.removed === true)
170
+ return { path: held.path, removed: true };
171
+ const head = headChange(held);
172
+ const binary = binaryFileOf(held);
173
+ if (head === null || binary === null)
174
+ return null;
175
+ if (binary !== undefined) {
176
+ if (mode === 'credential' && typeof held.revision !== 'string')
177
+ return null;
178
+ const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
179
+ return { path: held.path, binary, revision, version: revision, ...headed(head) };
180
+ }
119
181
  if (mode === 'site') {
120
- if (typeof held.content !== 'string' || typeof held.sha256 !== 'string') return null;
182
+ if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
183
+ return null;
121
184
  return {
122
185
  path: held.path,
123
186
  content: held.content,
124
187
  revision: undefined,
125
- version: held.sha256
188
+ version: held.sha256,
189
+ ...headed(head),
126
190
  };
127
191
  }
128
192
  if (typeof held.content === 'string' && typeof held.revision === 'string') {
@@ -130,197 +194,134 @@ function parseChange(value, mode) {
130
194
  path: held.path,
131
195
  content: held.content,
132
196
  revision: held.revision,
133
- version: held.revision
134
- };
135
- }
136
- if (typeof held.reference === 'object' && held.reference !== null) {
137
- const reference = held.reference;
138
- if (typeof reference.revision !== 'string') return null;
139
- return {
140
- path: held.path,
141
- reference: {
142
- revision: reference.revision
143
- }
197
+ version: held.revision,
198
+ ...headed(head),
144
199
  };
145
200
  }
146
201
  return null;
147
202
  }
148
203
  export function parseEnumeration(body, mode) {
149
- if (typeof body !== 'object' || body === null) return null;
150
- if (!('authorities' in body) || !Array.isArray(body.authorities)) return null;
204
+ if (typeof body !== 'object' || body === null)
205
+ return null;
206
+ if (!('authorities' in body) || !Array.isArray(body.authorities))
207
+ return null;
151
208
  const authorities = [];
152
- for (const entry of body.authorities){
153
- if (typeof entry !== 'object' || entry === null) return null;
209
+ for (const entry of body.authorities) {
210
+ if (typeof entry !== 'object' || entry === null)
211
+ return null;
154
212
  const held = entry;
155
213
  const at = readPosition(held);
156
- if (typeof held.authority !== 'string' || at === null) return null;
157
- if (!Array.isArray(held.changes)) return null;
214
+ if (typeof held.authority !== 'string' || at === null)
215
+ return null;
216
+ if (!Array.isArray(held.changes))
217
+ return null;
158
218
  const changes = [];
159
- for (const change of held.changes){
219
+ for (const change of held.changes) {
160
220
  const mapped = parseChange(change, mode);
161
- if (mapped === null) return null;
221
+ if (mapped === null)
222
+ return null;
162
223
  changes.push(mapped);
163
224
  }
164
- authorities.push({
165
- authority: held.authority,
166
- ...at,
167
- changes
168
- });
225
+ authorities.push({ authority: held.authority, ...at, changes });
169
226
  }
170
- return {
171
- authorities
172
- };
227
+ return { authorities };
173
228
  }
174
229
  export function advancedScope(scope, view) {
175
- const files = new Map(scope.files.map((file)=>[
176
- file.path,
177
- file
178
- ]));
179
- const contents = new Map(scope.contents.map((entry)=>[
180
- entry.path,
181
- entry.content
182
- ]));
183
- for (const change of view.changes){
230
+ const files = new Map(scope.files.map((file) => [file.path, file]));
231
+ const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
232
+ for (const change of view.changes) {
184
233
  files.delete(change.path);
185
234
  contents.delete(change.path);
186
- if ('removed' in change) continue;
187
- if ('content' in change) {
188
- files.set(change.path, {
189
- path: change.path,
190
- revision: change.revision,
191
- version: change.version
192
- });
193
- contents.set(change.path, change.content);
235
+ if ('removed' in change)
194
236
  continue;
195
- }
196
- const { revision } = change.reference;
197
237
  files.set(change.path, {
198
238
  path: change.path,
199
- revision,
200
- version: revision
239
+ revision: change.revision,
240
+ version: change.version,
241
+ ...headed(change.head),
242
+ ...('binary' in change ? { binary: change.binary } : {}),
201
243
  });
244
+ if ('content' in change)
245
+ contents.set(change.path, change.content);
202
246
  }
203
247
  return {
204
248
  ...scope,
205
249
  position: view.position,
206
250
  logEpoch: view.logEpoch,
207
- files: [
208
- ...files.values()
209
- ],
210
- contents: [
211
- ...contents
212
- ].map(([path, content])=>({
213
- path,
214
- content
215
- }))
251
+ files: [...files.values()],
252
+ contents: [...contents].map(([path, content]) => ({ path, content })),
216
253
  };
217
254
  }
218
255
  export function matchesScope(scope, tracked) {
219
- if (tracked.handle === undefined) return scope.scope === 'private';
220
- return scope.roomHandle === tracked.handle || scope.anchor === tracked.authority;
221
- }
222
- export function withinRoot(path, root) {
223
- return path === root || path.startsWith(`${root}/`);
224
- }
225
- export function selects(tracked, path) {
226
- if (tracked.modelRoots.some((root)=>withinRoot(path, root))) return false;
227
- return selectionRoots(tracked).some((root)=>withinRoot(path, root));
228
- }
229
- export function bootstrapFrom(envelope, tracked) {
230
- const scope = envelope.scopes.find((entry)=>matchesScope(entry, tracked));
231
- if (scope === undefined) return {
232
- kind: 'room-not-readable',
233
- locator: tracked.locator
234
- };
235
- return bootstrapOf(scope, tracked);
256
+ return scope.anchor === tracked.authority;
236
257
  }
237
- export function bootstrapOf(scope, tracked) {
238
- const contents = new Map(scope.contents.map((entry)=>[
239
- entry.path,
240
- entry.content
241
- ]));
258
+ export function bootstrapOf(scope) {
259
+ const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
242
260
  const documents = {};
243
261
  const revisions = {};
244
- const binaryTargets = [];
245
- for (const file of scope.files){
246
- if (!selects(tracked, file.path)) continue;
247
- if (file.revision !== undefined) revisions[file.path] = file.revision;
262
+ const changes = {};
263
+ const binaryFiles = {};
264
+ for (const file of scope.files) {
265
+ if (file.revision !== undefined)
266
+ revisions[file.path] = file.revision;
267
+ if (file.head !== undefined)
268
+ changes[file.path] = file.head;
248
269
  const content = contents.get(file.path);
249
- if (content === undefined) binaryTargets.push(file.path);
250
- else documents[file.path] = content;
270
+ if (file.binary !== undefined)
271
+ binaryFiles[file.path] = file.binary;
272
+ else if (content !== undefined)
273
+ documents[file.path] = content;
251
274
  }
252
275
  return {
253
276
  kind: 'bootstrap',
254
277
  roomVersion: roomVersion(scope),
255
278
  documents,
256
279
  revisions,
257
- binaryTargets: binaryTargets.sort()
280
+ changes,
281
+ binaryFiles,
258
282
  };
259
283
  }
260
- export const MODEL_DEFINITION_ADDRESS = 'types';
261
- export function definitionAddress(path) {
262
- return `${MODEL_DEFINITION_ADDRESS}/${path.slice(path.lastIndexOf('/') + 1)}`;
284
+ export function schemaOf(scope, schema) {
285
+ const file = scope.files.find((entry) => entry.path === schema);
286
+ if (file === undefined)
287
+ return { schema: null, version: null, revision: null };
288
+ const content = scope.contents.find((entry) => entry.path === schema);
289
+ return content === undefined
290
+ ? null
291
+ : { schema: content.content, version: file.version, revision: file.revision ?? null };
263
292
  }
264
- export function definitionsFrom(envelope, tracked, modelRoot) {
265
- const scope = envelope.scopes.find((entry)=>matchesScope(entry, tracked));
266
- if (scope === undefined) return null;
267
- return definitionsOf(scope, modelRoot);
293
+ export function viewOf(enumeration, tracked) {
294
+ return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
268
295
  }
269
- export function definitionsOf(scope, modelRoot) {
270
- const contents = new Map(scope.contents.map((entry)=>[
271
- entry.path,
272
- entry.content
273
- ]));
274
- const definitions = {};
275
- const versions = [];
276
- for (const file of scope.files){
277
- if (!withinRoot(file.path, modelRoot)) continue;
278
- const content = contents.get(file.path);
279
- const address = definitionAddress(file.path);
280
- if (content === undefined || Object.hasOwn(definitions, address)) return null;
281
- definitions[address] = content;
282
- versions.push(`${file.path} ${file.version}`);
283
- }
284
- return {
285
- definitions,
286
- versions: versions.sort()
287
- };
288
- }
289
- export function refreshFrom(enumeration, tracked, fromRoomVersion) {
290
- const view = enumeration.authorities.find((entry)=>entry.authority === tracked.authority);
291
- if (view === undefined) return {
292
- kind: 'room-not-readable',
293
- locator: tracked.locator
294
- };
295
- if (roomVersion(view) === fromRoomVersion) return {
296
- kind: 'still-current'
297
- };
296
+ export function refreshFrom(view, fromRoomVersion) {
297
+ if (roomVersion(view) === fromRoomVersion)
298
+ return { kind: 'still-current' };
298
299
  const documents = {};
299
300
  const revisions = {};
300
- const binaryTargets = [];
301
+ const changes = {};
302
+ const binaryFiles = {};
301
303
  const removals = [];
302
- for (const change of view.changes){
303
- if (!selects(tracked, change.path)) continue;
304
+ for (const change of view.changes) {
304
305
  if ('removed' in change) {
305
306
  removals.push(change.path);
306
307
  continue;
307
308
  }
308
- if ('content' in change) {
309
+ if ('content' in change)
309
310
  documents[change.path] = change.content;
310
- if (change.revision !== undefined) revisions[change.path] = change.revision;
311
- continue;
312
- }
313
- binaryTargets.push(change.path);
314
- revisions[change.path] = change.reference.revision;
311
+ else
312
+ binaryFiles[change.path] = change.binary;
313
+ if (change.revision !== undefined)
314
+ revisions[change.path] = change.revision;
315
+ if (change.head !== undefined)
316
+ changes[change.path] = change.head;
315
317
  }
316
318
  return {
317
319
  kind: 'net-advancement',
318
320
  roomVersion: roomVersion(view),
319
321
  documents,
320
322
  revisions,
321
- binaryTargets: binaryTargets.sort(),
322
- removals: removals.sort()
323
+ changes,
324
+ binaryFiles,
325
+ removals: removals.sort(),
323
326
  };
324
327
  }
325
-
326
- //# sourceMappingURL=read.js.map
@@ -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,11 +1,9 @@
1
1
  import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
2
- export type DoorRefusal = ProviderRefusal;
3
- export declare function doorRefusal(body: unknown): DoorRefusal | null;
4
- export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: DoorRefusal): ScopedRefusal;
5
- 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 | {
6
6
  kind: 'beyond-horizon';
7
7
  } | null;
8
- export declare function discoveryFailure(classified: AdapterFailure | {
9
- kind: 'beyond-horizon';
10
- }): DiscoverResult;
8
+ export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
11
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;AAgBhC,MAAM,MAAM,WAAW,GAAG,eAAe,CAAC;AAE1C,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,CAepD;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;AAmBD,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"}