@agentshouse/mdruntime-adapter 0.1.0-cd028205a5103 → 0.1.0-cd0511bd2d033

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 (72) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +4 -5
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +13 -322
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +285 -205
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/crockford.d.ts +4 -0
  12. package/dist/crockford.d.ts.map +1 -0
  13. package/dist/crockford.js +3 -0
  14. package/dist/discovery.d.ts +25 -14
  15. package/dist/discovery.d.ts.map +1 -1
  16. package/dist/discovery.js +104 -51
  17. package/dist/history.d.ts +12 -0
  18. package/dist/history.d.ts.map +1 -0
  19. package/dist/history.js +92 -0
  20. package/dist/house-model.d.ts +719 -0
  21. package/dist/house-model.d.ts.map +1 -0
  22. package/dist/house-model.js +393 -0
  23. package/dist/index.d.ts +11 -1
  24. package/dist/index.d.ts.map +1 -1
  25. package/dist/index.js +10 -0
  26. package/dist/model.d.ts +6 -3
  27. package/dist/model.d.ts.map +1 -1
  28. package/dist/model.js +15 -30
  29. package/dist/part.d.ts +14 -0
  30. package/dist/part.d.ts.map +1 -0
  31. package/dist/part.js +90 -0
  32. package/dist/read.d.ts +59 -41
  33. package/dist/read.d.ts.map +1 -1
  34. package/dist/read.js +254 -231
  35. package/dist/refusal.d.ts +2 -8
  36. package/dist/refusal.d.ts.map +1 -1
  37. package/dist/refusal.js +6 -14
  38. package/dist/room-stream.d.ts +19 -0
  39. package/dist/room-stream.d.ts.map +1 -0
  40. package/dist/room-stream.js +57 -0
  41. package/dist/room-types.d.ts +7 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +125 -0
  44. package/dist/search.d.ts +5 -0
  45. package/dist/search.d.ts.map +1 -0
  46. package/dist/search.js +47 -0
  47. package/dist/site.d.ts +1 -1
  48. package/dist/site.d.ts.map +1 -1
  49. package/dist/site.js +130 -106
  50. package/dist/stream.d.ts +12 -12
  51. package/dist/stream.d.ts.map +1 -1
  52. package/dist/stream.js +204 -151
  53. package/dist/transport.d.ts +92 -24
  54. package/dist/transport.d.ts.map +1 -1
  55. package/dist/transport.js +55 -9
  56. package/dist/upload.d.ts +12 -0
  57. package/dist/upload.d.ts.map +1 -0
  58. package/dist/upload.js +63 -0
  59. package/dist/version.d.ts +1 -0
  60. package/dist/version.d.ts.map +1 -1
  61. package/dist/version.js +1 -1
  62. package/dist/write.d.ts +20 -10
  63. package/dist/write.d.ts.map +1 -1
  64. package/dist/write.js +162 -54
  65. package/package.json +9 -6
  66. package/AGENTS.md +0 -244
  67. package/dist/gather.d.ts +0 -3
  68. package/dist/gather.d.ts.map +0 -1
  69. package/dist/gather.js +0 -40
  70. package/dist/links.d.ts +0 -20
  71. package/dist/links.d.ts.map +0 -1
  72. package/dist/links.js +0 -104
package/dist/read.js CHANGED
@@ -1,13 +1,75 @@
1
+ import { paced, patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { gunzipped } from './part.js';
1
3
  import { readPosition, roomVersion } from './version.js';
4
+ const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
5
+ function fileOf(revision) {
6
+ return REVISION_FILE.exec(revision)?.[1];
7
+ }
8
+ export function answering() {
9
+ return {
10
+ documents: new Map(),
11
+ facts: new Map(),
12
+ revisions: new Map(),
13
+ fileIds: new Map(),
14
+ changes: new Map(),
15
+ binaryFiles: new Map(),
16
+ removals: new Set(),
17
+ folders: new Set(),
18
+ folderRemovals: new Set(),
19
+ };
20
+ }
21
+ export function revised(answer, path, revision) {
22
+ answer.revisions.set(path, revision);
23
+ const file = fileOf(revision);
24
+ if (file !== undefined)
25
+ answer.fileIds.set(path, file);
26
+ }
27
+ export function forgotten(answer, path) {
28
+ answer.documents.delete(path);
29
+ answer.facts.delete(path);
30
+ answer.revisions.delete(path);
31
+ answer.fileIds.delete(path);
32
+ answer.changes.delete(path);
33
+ answer.binaryFiles.delete(path);
34
+ answer.removals.delete(path);
35
+ }
36
+ export function folded(answer, path, removed) {
37
+ if (removed) {
38
+ answer.folders.delete(path);
39
+ answer.folderRemovals.add(path);
40
+ }
41
+ else {
42
+ answer.folderRemovals.delete(path);
43
+ answer.folders.add(path);
44
+ }
45
+ }
46
+ function* pathsOf(paths) {
47
+ const list = [];
48
+ for (const path of paths) {
49
+ list.push(path);
50
+ yield ROW_WEIGHT;
51
+ }
52
+ return list;
53
+ }
54
+ export function* answered(answer) {
55
+ const removals = yield* pathsOf(answer.removals);
56
+ return {
57
+ documents: yield* patching({}, answer.documents),
58
+ facts: yield* patching({}, answer.facts),
59
+ revisions: yield* patching({}, answer.revisions),
60
+ ...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
61
+ changes: yield* patching({}, answer.changes),
62
+ binaryFiles: yield* patching({}, answer.binaryFiles),
63
+ removals,
64
+ ...(answer.folders.size === 0 ? {} : { folders: yield* pathsOf(answer.folders) }),
65
+ ...(answer.folderRemovals.size === 0
66
+ ? {}
67
+ : { folderRemovals: yield* pathsOf(answer.folderRemovals) }),
68
+ };
69
+ }
2
70
  export function authorityRoot(handle) {
3
71
  return `/rooms/${handle}`;
4
72
  }
5
- export function contentPrefixes(tracked) {
6
- return [
7
- authorityRoot(tracked.handle),
8
- ...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
9
- ];
10
- }
11
73
  export function schemaPath(handle, schema) {
12
74
  return `${authorityRoot(handle)}/${schema}`;
13
75
  }
@@ -20,22 +82,39 @@ export function parseGrant(body) {
20
82
  const transfer = body.transfer;
21
83
  if (typeof transfer.url !== 'string')
22
84
  return null;
23
- if (transfer.method === 'GET')
24
- return { method: 'GET', url: transfer.url };
25
85
  if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
26
86
  return null;
27
- return { method: 'POST', operation: transfer.operation, url: transfer.url };
87
+ return { operation: transfer.operation, url: transfer.url };
88
+ }
89
+ export function parseFileAddress(body) {
90
+ if (typeof body !== 'object' || body === null)
91
+ return null;
92
+ const { download, name, sha256, media_type: mediaType } = body;
93
+ if (typeof download !== 'string' ||
94
+ typeof name !== 'string' ||
95
+ typeof sha256 !== 'string' ||
96
+ typeof mediaType !== 'string') {
97
+ return null;
98
+ }
99
+ return { url: download, name, sha256, mediaType };
28
100
  }
29
101
  function changeAuthor(value) {
30
102
  if (typeof value !== 'object' || value === null)
31
103
  return null;
32
- const { user, site, name } = value;
104
+ const { user, site, inbox, app, name } = value;
33
105
  if (typeof name !== 'string')
34
106
  return null;
35
- if (typeof user === 'string' && site === undefined)
107
+ const named = [user, site, inbox, app].filter((id) => id !== undefined);
108
+ if (named.length !== 1)
109
+ return null;
110
+ if (typeof user === 'string')
36
111
  return { kind: 'user', id: user, name };
37
- if (typeof site === 'string' && user === undefined)
112
+ if (typeof site === 'string')
38
113
  return { kind: 'site', id: site, name };
114
+ if (typeof inbox === 'string')
115
+ return { kind: 'inbox', id: inbox, name };
116
+ if (typeof app === 'string')
117
+ return { kind: 'app', id: app, name };
39
118
  return null;
40
119
  }
41
120
  export function headChange(held) {
@@ -51,32 +130,19 @@ export function headChange(held) {
51
130
  function headed(head) {
52
131
  return head === undefined ? {} : { head };
53
132
  }
54
- function parseOriginal(value) {
55
- if (typeof value !== 'object' || value === null)
56
- return null;
57
- const { attachment, name, bytes, media_type: mediaType } = value;
58
- if (typeof attachment !== 'string' || typeof name !== 'string')
59
- return null;
60
- if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0)
61
- return null;
62
- if (mediaType !== null && typeof mediaType !== 'string')
133
+ export function binaryFileOf(held) {
134
+ if (held.media_type === undefined)
135
+ return undefined;
136
+ const { bytes, media_type: mediaType, sha256 } = held;
137
+ if (typeof bytes !== 'number' || typeof mediaType !== 'string' || typeof sha256 !== 'string')
63
138
  return null;
64
- return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
139
+ return { byteLength: bytes, mediaType, sha256 };
65
140
  }
66
- export function parseOriginals(value) {
67
- if (!Array.isArray(value))
68
- return null;
69
- const attachments = [];
70
- for (const entry of value) {
71
- const attachment = parseOriginal(entry);
72
- if (attachment === null)
73
- return null;
74
- attachments.push(attachment);
75
- }
76
- return attachments;
141
+ function binaried(binary) {
142
+ return binary === undefined ? {} : { binary };
77
143
  }
78
- function declared(attachments) {
79
- return attachments === undefined ? {} : { attachments };
144
+ export function carriedFacts(held) {
145
+ return held.facts === undefined ? {} : { facts: held.facts };
80
146
  }
81
147
  function parseFile(value, mode) {
82
148
  if (typeof value !== 'object' || value === null)
@@ -85,24 +151,56 @@ function parseFile(value, mode) {
85
151
  if (typeof file.path !== 'string')
86
152
  return null;
87
153
  const head = headChange(file);
88
- if (head === null)
154
+ const binary = binaryFileOf(file);
155
+ if (head === null || binary === null)
89
156
  return null;
90
157
  if (mode === 'site') {
91
158
  if (typeof file.sha256 !== 'string')
92
159
  return null;
93
- return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
160
+ return {
161
+ path: file.path,
162
+ revision: binary?.sha256,
163
+ version: file.sha256,
164
+ ...headed(head),
165
+ ...binaried(binary),
166
+ ...carriedFacts(file),
167
+ };
94
168
  }
95
169
  if (typeof file.revision !== 'string')
96
170
  return null;
97
- return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
171
+ return {
172
+ path: file.path,
173
+ revision: file.revision,
174
+ version: file.revision,
175
+ ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
176
+ ...headed(head),
177
+ ...binaried(binary),
178
+ ...carriedFacts(file),
179
+ };
98
180
  }
99
- function parseScope(value, mode) {
181
+ function parseModels(value, mode) {
182
+ if (!Array.isArray(value))
183
+ return null;
184
+ const files = [];
185
+ const contents = [];
186
+ for (const entry of value) {
187
+ const file = parseFile(entry, mode);
188
+ const { content } = entry;
189
+ if (file === null || typeof content !== 'string')
190
+ return null;
191
+ files.push(file);
192
+ contents.push({ path: file.path, content });
193
+ }
194
+ return { files, contents };
195
+ }
196
+ function parseRoomHead(value, mode) {
100
197
  if (typeof value !== 'object' || value === null)
101
198
  return null;
102
199
  const held = value;
103
200
  if (typeof held.manifest !== 'object' || held.manifest === null)
104
201
  return null;
105
- if (!Array.isArray(held.contents))
202
+ const models = parseModels(held.models, mode);
203
+ if (models === null)
106
204
  return null;
107
205
  const manifest = held.manifest;
108
206
  if (manifest.scope !== 'room')
@@ -112,178 +210,141 @@ function parseScope(value, mode) {
112
210
  return null;
113
211
  if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
114
212
  return null;
115
- if (!Array.isArray(manifest.files))
116
- return null;
117
- const files = [];
118
- for (const entry of manifest.files) {
119
- const file = parseFile(entry, mode);
120
- if (file === null)
121
- return null;
122
- files.push(file);
123
- }
124
- const contents = [];
125
- for (const entry of held.contents) {
126
- if (typeof entry !== 'object' || entry === null)
127
- return null;
128
- const content = entry;
129
- if (typeof content.path !== 'string' || typeof content.content !== 'string')
130
- return null;
131
- contents.push({ path: content.path, content: content.content });
132
- }
133
- if (mode === 'site')
134
- return { anchor: manifest.anchor, ...at, files, contents };
135
- const attachments = parseOriginals(held.originals);
136
- if (attachments === null)
137
- return null;
138
- return { anchor: manifest.anchor, ...at, files, contents, attachments };
213
+ return { anchor: manifest.anchor, ...at, models };
139
214
  }
140
- export function parseEnvelope(body) {
141
- if (typeof body !== 'object' || body === null)
142
- return null;
143
- if (!('scopes' in body) || !Array.isArray(body.scopes))
215
+ export async function roomHead(payload, mode) {
216
+ let text = '';
217
+ try {
218
+ for await (const chunk of gunzipped(payload))
219
+ text += chunk;
220
+ return text.endsWith('\n') && text.indexOf('\n') === text.length - 1
221
+ ? parseRoomHead(JSON.parse(text), mode)
222
+ : null;
223
+ }
224
+ catch {
144
225
  return null;
145
- const scopes = [];
146
- for (const entry of body.scopes) {
147
- const scope = parseScope(entry, 'credential');
148
- if (scope === null)
149
- return null;
150
- scopes.push(scope);
151
226
  }
152
- return { scopes };
153
227
  }
154
- export function parseSiteBootstrap(body) {
155
- return parseScope(body, 'site');
228
+ export function manifested(room, pageToken, models) {
229
+ return {
230
+ kind: 'bootstrap',
231
+ roomVersion: roomVersion(room),
232
+ documents: {},
233
+ facts: {},
234
+ revisions: {},
235
+ changes: {},
236
+ binaryFiles: {},
237
+ pageToken,
238
+ ...(models === undefined ? {} : { models }),
239
+ };
156
240
  }
157
- function parseChange(value, mode) {
158
- if (typeof value !== 'object' || value === null)
159
- return null;
160
- const held = value;
161
- if (typeof held.path !== 'string')
162
- return null;
163
- if (held.removed === true)
164
- return { path: held.path, removed: true };
165
- const head = headChange(held);
166
- if (head === null)
167
- return null;
168
- if (mode === 'site') {
169
- if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
170
- return null;
171
- return {
172
- path: held.path,
173
- content: held.content,
174
- revision: undefined,
175
- version: held.sha256,
176
- ...headed(head),
177
- };
241
+ export function modelScope(room) {
242
+ return { ...emptyScope(room), files: room.models.files, contents: room.models.contents };
243
+ }
244
+ export function emptyScope(room) {
245
+ return {
246
+ anchor: room.anchor,
247
+ position: room.position,
248
+ logEpoch: room.logEpoch,
249
+ files: [],
250
+ contents: [],
251
+ };
252
+ }
253
+ function partLine(line, mode, read) {
254
+ if (read.ended)
255
+ return false;
256
+ let entry;
257
+ try {
258
+ entry = JSON.parse(line);
178
259
  }
179
- if (typeof held.content === 'string' && typeof held.revision === 'string') {
180
- return {
181
- path: held.path,
182
- content: held.content,
183
- revision: held.revision,
184
- version: held.revision,
185
- ...headed(head),
186
- };
260
+ catch {
261
+ return false;
187
262
  }
188
- if (typeof held.reference === 'object' && held.reference !== null) {
189
- const reference = held.reference;
190
- if (typeof reference.revision !== 'string')
191
- return null;
192
- return { path: held.path, reference: { revision: reference.revision } };
263
+ if (endLine(entry)) {
264
+ read.ended = true;
265
+ return true;
193
266
  }
194
- return null;
267
+ if (folderLine(entry)) {
268
+ read.folders.push(entry.folder);
269
+ return true;
270
+ }
271
+ const file = parseFile(entry, mode);
272
+ if (file === null)
273
+ return false;
274
+ read.files.push(file);
275
+ const { content } = entry;
276
+ if (typeof content === 'string')
277
+ read.contents.push({ path: file.path, content });
278
+ else if (content !== undefined)
279
+ return false;
280
+ return true;
195
281
  }
196
- export function parseEnumeration(body, mode) {
197
- if (typeof body !== 'object' || body === null)
198
- return null;
199
- if (!('authorities' in body) || !Array.isArray(body.authorities))
200
- return null;
201
- const authorities = [];
202
- for (const entry of body.authorities) {
203
- if (typeof entry !== 'object' || entry === null)
204
- return null;
205
- const held = entry;
206
- const at = readPosition(held);
207
- if (typeof held.authority !== 'string' || at === null)
208
- return null;
209
- if (!Array.isArray(held.changes))
210
- return null;
211
- const changes = [];
212
- for (const change of held.changes) {
213
- const mapped = parseChange(change, mode);
214
- if (mapped === null)
282
+ async function partRead(chunks, mode) {
283
+ const read = { files: [], contents: [], folders: [], ended: false };
284
+ const pace = paced();
285
+ const unfinished = [];
286
+ for (let chunk = await chunks.read(); chunk.done !== true; chunk = await chunks.read()) {
287
+ const text = chunk.value;
288
+ let start = 0;
289
+ for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
290
+ const piece = text.slice(start, end);
291
+ const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
292
+ if (!partLine(line, mode, read)) {
293
+ await chunks.cancel();
215
294
  return null;
216
- changes.push(mapped);
295
+ }
296
+ start = end + 1;
297
+ const due = pace(line.length + ROW_WEIGHT);
298
+ if (due instanceof Promise)
299
+ await due;
217
300
  }
218
- if (mode === 'site') {
219
- authorities.push({ authority: held.authority, ...at, changes });
220
- continue;
221
- }
222
- const attachments = parseOriginals(held.originals);
223
- if (attachments === null)
224
- return null;
225
- authorities.push({ authority: held.authority, ...at, changes, attachments });
301
+ if (start < text.length)
302
+ unfinished.push(text.slice(start));
226
303
  }
227
- return { authorities };
304
+ return unfinished.length === 0 ? read : null;
228
305
  }
229
- export function advancedScope(scope, view) {
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) {
233
- files.delete(change.path);
234
- contents.delete(change.path);
235
- if ('removed' in change)
236
- continue;
237
- if ('content' in change) {
238
- files.set(change.path, {
239
- path: change.path,
240
- revision: change.revision,
241
- version: change.version,
242
- ...headed(change.head),
243
- });
244
- contents.set(change.path, change.content);
245
- continue;
246
- }
247
- const { revision } = change.reference;
248
- files.set(change.path, { path: change.path, revision, version: revision });
249
- }
250
- return {
251
- ...scope,
252
- position: view.position,
253
- logEpoch: view.logEpoch,
254
- files: [...files.values()],
255
- contents: [...contents].map(([path, content]) => ({ path, content })),
256
- };
306
+ function endLine(entry) {
307
+ if (typeof entry !== 'object' || entry === null || !('end' in entry))
308
+ return false;
309
+ return entry.end === true && Object.keys(entry).length === 1;
310
+ }
311
+ function folderLine(entry) {
312
+ if (typeof entry !== 'object' || entry === null || !('folder' in entry))
313
+ return false;
314
+ return typeof entry.folder === 'string' && Object.keys(entry).length === 1;
257
315
  }
258
- export function matchesScope(scope, tracked) {
259
- return scope.anchor === tracked.authority;
316
+ export async function housePart(room, payload, mode) {
317
+ const read = await partRead(gunzipped(payload).getReader(), mode).catch(() => null);
318
+ if (read === null)
319
+ return { kind: 'transport-uncertainty' };
320
+ const { ended, ...scope } = read;
321
+ return { scope: { ...emptyScope(room), ...scope }, ended };
260
322
  }
261
- export function bootstrapOf(scope) {
262
- const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
263
- const documents = {};
264
- const revisions = {};
265
- const changes = {};
266
- const binaryTargets = [];
323
+ export function* bootstrapping(scope) {
324
+ const contents = new Map();
325
+ for (const entry of scope.contents) {
326
+ contents.set(entry.path, entry.content);
327
+ yield ROW_WEIGHT;
328
+ }
329
+ const answer = answering();
267
330
  for (const file of scope.files) {
268
- if (file.revision !== undefined)
269
- revisions[file.path] = file.revision;
331
+ yield ROW_WEIGHT;
270
332
  if (file.head !== undefined)
271
- changes[file.path] = file.head;
333
+ answer.changes.set(file.path, file.head);
272
334
  const content = contents.get(file.path);
273
- if (content === undefined)
274
- binaryTargets.push(file.path);
275
- else
276
- documents[file.path] = content;
335
+ if (file.binary !== undefined)
336
+ answer.binaryFiles.set(file.path, file.binary);
337
+ else if (content !== undefined)
338
+ answer.documents.set(file.path, content);
339
+ if (file.binary === undefined && file.facts !== undefined)
340
+ answer.facts.set(file.path, file.facts);
341
+ if (file.revision !== undefined)
342
+ revised(answer, file.path, file.revision);
277
343
  }
278
- return {
279
- kind: 'bootstrap',
280
- roomVersion: roomVersion(scope),
281
- documents,
282
- revisions,
283
- changes,
284
- binaryTargets: binaryTargets.sort(),
285
- ...declared(scope.attachments),
286
- };
344
+ for (const folder of scope.folders ?? [])
345
+ folded(answer, folder, false);
346
+ const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
347
+ return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
287
348
  }
288
349
  export function schemaOf(scope, schema) {
289
350
  const file = scope.files.find((entry) => entry.path === schema);
@@ -294,41 +355,3 @@ export function schemaOf(scope, schema) {
294
355
  ? null
295
356
  : { schema: content.content, version: file.version, revision: file.revision ?? null };
296
357
  }
297
- export function viewOf(enumeration, tracked) {
298
- return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
299
- }
300
- export function refreshFrom(view, fromRoomVersion) {
301
- if (roomVersion(view) === fromRoomVersion)
302
- return { kind: 'still-current' };
303
- const documents = {};
304
- const revisions = {};
305
- const changes = {};
306
- const binaryTargets = [];
307
- const removals = [];
308
- for (const change of view.changes) {
309
- if ('removed' in change) {
310
- removals.push(change.path);
311
- continue;
312
- }
313
- if ('content' in change) {
314
- documents[change.path] = change.content;
315
- if (change.revision !== undefined)
316
- revisions[change.path] = change.revision;
317
- if (change.head !== undefined)
318
- changes[change.path] = change.head;
319
- continue;
320
- }
321
- binaryTargets.push(change.path);
322
- revisions[change.path] = change.reference.revision;
323
- }
324
- return {
325
- kind: 'net-advancement',
326
- roomVersion: roomVersion(view),
327
- documents,
328
- revisions,
329
- changes,
330
- binaryTargets: binaryTargets.sort(),
331
- removals: removals.sort(),
332
- ...declared(view.attachments),
333
- };
334
- }
package/dist/refusal.d.ts CHANGED
@@ -1,12 +1,6 @@
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;
2
+ export declare function doorRefusal(body: unknown): ProviderRefusal | null;
3
+ export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
7
4
  export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
8
- export declare function classifyRead(status: number, body: unknown, locator: string): AdapterFailure | {
9
- kind: 'beyond-horizon';
10
- } | null;
11
5
  export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
12
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,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;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,CAYrF"}
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"}
package/dist/refusal.js CHANGED
@@ -6,11 +6,11 @@ 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
15
  function doorFailure(status, body) {
16
16
  if (status === 0)
@@ -18,8 +18,9 @@ function doorFailure(status, body) {
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
+ }
23
24
  if (status === 404 || refusal?.code === 'room_not_found')
24
25
  return { kind: 'room-not-readable' };
25
26
  if (status < 400)
@@ -38,11 +39,6 @@ export function classifyDoor(status, body, locator) {
38
39
  return scopedRefusal(locator, failure.scope, failure.refusal);
39
40
  return failure;
40
41
  }
41
- export function classifyRead(status, body, locator) {
42
- if (doorRefusal(body)?.code === 'expired')
43
- return { kind: 'beyond-horizon' };
44
- return classifyDoor(status, body, locator);
45
- }
46
42
  export function discoveryFailure(status, body) {
47
43
  const failure = doorFailure(status, body);
48
44
  if (failure === null)
@@ -50,11 +46,7 @@ export function discoveryFailure(status, body) {
50
46
  if (failure.kind === 'revoked-authorization')
51
47
  return failure;
52
48
  if (failure.kind === 'refused') {
53
- return {
54
- kind: 'contract-unavailable',
55
- code: failure.refusal.code,
56
- fields: failure.refusal.fields,
57
- };
49
+ return { kind: 'contract-unavailable', ...failure.refusal };
58
50
  }
59
51
  return { kind: 'transport-uncertainty' };
60
52
  }
@@ -0,0 +1,19 @@
1
+ import type { BootstrapResult, RoomModels } from '@agentshouse/mdruntime';
2
+ import type { TrackedAuthority } from './discovery.js';
3
+ import { type HouseScope } from './read.js';
4
+ import type { HouseMode } from './transport.js';
5
+ export type StreamedPart = {
6
+ readonly scope: HouseScope;
7
+ readonly first: boolean;
8
+ readonly ended: boolean;
9
+ readonly models: RoomModels | undefined;
10
+ readonly pageToken: string | undefined;
11
+ readonly bytes: number;
12
+ };
13
+ export declare function roomStreams(mode: HouseMode): {
14
+ head: (entry: TrackedAuthority, room: ReadableStream<Uint8Array>, arriving: ((bytes: number) => void) | undefined, signal: AbortSignal | undefined) => Promise<BootstrapResult>;
15
+ part: (entry: TrackedAuthority, token: string) => Promise<StreamedPart | Exclude<BootstrapResult, {
16
+ kind: 'bootstrap';
17
+ }>>;
18
+ };
19
+ //# sourceMappingURL=room-stream.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-stream.d.ts","sourceRoot":"","sources":["../src/room-stream.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAC1E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,OAAO,EAAuD,KAAK,UAAU,EAAE,MAAM,WAAW,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAYhD,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC;IAC3B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,SAAS,CAAC;IACxC,QAAQ,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC;IACvC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS;kBAKhC,gBAAgB,QACjB,cAAc,CAAC,UAAU,CAAC,YACtB,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,UACvC,WAAW,GAAG,SAAS,KAC9B,OAAO,CAAC,eAAe,CAAC;kBAelB,gBAAgB,SAChB,MAAM,KACZ,OAAO,CAAC,YAAY,GAAG,OAAO,CAAC,eAAe,EAAE;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC,CAAC;EAkC3E"}