@agentshouse/mdruntime-adapter 0.1.0-c7d05e09c73b7 → 0.1.0-c7edf402e20a3

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 (75) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +6 -5
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +25 -322
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +278 -233
  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/authored-path.d.ts +11 -0
  12. package/dist/authored-path.d.ts.map +1 -0
  13. package/dist/authored-path.js +35 -0
  14. package/dist/chunks.d.ts +38 -0
  15. package/dist/chunks.d.ts.map +1 -0
  16. package/dist/chunks.js +247 -0
  17. package/dist/crockford.d.ts +4 -0
  18. package/dist/crockford.d.ts.map +1 -0
  19. package/dist/crockford.js +3 -0
  20. package/dist/discovery.d.ts +24 -14
  21. package/dist/discovery.d.ts.map +1 -1
  22. package/dist/discovery.js +98 -53
  23. package/dist/history.d.ts +12 -0
  24. package/dist/history.d.ts.map +1 -0
  25. package/dist/history.js +92 -0
  26. package/dist/house-model.d.ts +682 -0
  27. package/dist/house-model.d.ts.map +1 -0
  28. package/dist/house-model.js +397 -0
  29. package/dist/index.d.ts +12 -1
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +11 -0
  32. package/dist/model.d.ts +5 -5
  33. package/dist/model.d.ts.map +1 -1
  34. package/dist/model.js +33 -43
  35. package/dist/read.d.ts +61 -46
  36. package/dist/read.d.ts.map +1 -1
  37. package/dist/read.js +176 -272
  38. package/dist/refusal.d.ts +3 -8
  39. package/dist/refusal.d.ts.map +1 -1
  40. package/dist/refusal.js +10 -14
  41. package/dist/room-types.d.ts +5 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +120 -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 +122 -106
  50. package/dist/space-schema.d.ts +7 -0
  51. package/dist/space-schema.d.ts.map +1 -0
  52. package/dist/space-schema.js +18 -0
  53. package/dist/stream.d.ts +15 -13
  54. package/dist/stream.d.ts.map +1 -1
  55. package/dist/stream.js +279 -152
  56. package/dist/transport.d.ts +89 -24
  57. package/dist/transport.d.ts.map +1 -1
  58. package/dist/transport.js +55 -9
  59. package/dist/upload.d.ts +12 -0
  60. package/dist/upload.d.ts.map +1 -0
  61. package/dist/upload.js +63 -0
  62. package/dist/version.d.ts +1 -0
  63. package/dist/version.d.ts.map +1 -1
  64. package/dist/version.js +1 -1
  65. package/dist/write.d.ts +20 -10
  66. package/dist/write.d.ts.map +1 -1
  67. package/dist/write.js +161 -63
  68. package/package.json +9 -6
  69. package/AGENTS.md +0 -253
  70. package/dist/gather.d.ts +0 -4
  71. package/dist/gather.d.ts.map +0 -1
  72. package/dist/gather.js +0 -45
  73. package/dist/links.d.ts +0 -20
  74. package/dist/links.d.ts.map +0 -1
  75. package/dist/links.js +0 -104
package/dist/read.js CHANGED
@@ -1,13 +1,77 @@
1
- import { readPosition, roomVersion } from './version.js';
1
+ import { patching, ROW_WEIGHT, } from '@agentshouse/mdruntime';
2
+ import { roomVersion } from './version.js';
3
+ const REVISION_FILE = /^fr_([0-9a-z]+)\.[0-9a-z]+\.[0-9a-z]$/u;
4
+ function fileOf(revision) {
5
+ return REVISION_FILE.exec(revision)?.[1];
6
+ }
7
+ export function answering() {
8
+ return {
9
+ documents: new Map(),
10
+ facts: new Map(),
11
+ revisions: new Map(),
12
+ fileIds: new Map(),
13
+ created: 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.created.delete(path);
33
+ answer.changes.delete(path);
34
+ answer.binaryFiles.delete(path);
35
+ answer.removals.delete(path);
36
+ }
37
+ export function folded(answer, path, removed) {
38
+ if (removed) {
39
+ answer.folders.delete(path);
40
+ answer.folderRemovals.add(path);
41
+ }
42
+ else {
43
+ answer.folderRemovals.delete(path);
44
+ answer.folders.add(path);
45
+ }
46
+ }
47
+ function* pathsOf(paths) {
48
+ const list = [];
49
+ for (const path of paths) {
50
+ list.push(path);
51
+ yield ROW_WEIGHT;
52
+ }
53
+ return list;
54
+ }
55
+ export function* answered(answer) {
56
+ const removals = yield* pathsOf(answer.removals);
57
+ return {
58
+ documents: yield* patching({}, answer.documents),
59
+ facts: yield* patching({}, answer.facts),
60
+ revisions: yield* patching({}, answer.revisions),
61
+ ...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
62
+ ...(answer.created.size === 0 ? {} : { created: yield* patching({}, answer.created) }),
63
+ changes: yield* patching({}, answer.changes),
64
+ binaryFiles: yield* patching({}, answer.binaryFiles),
65
+ removals,
66
+ ...(answer.folders.size === 0 ? {} : { folders: yield* pathsOf(answer.folders) }),
67
+ ...(answer.folderRemovals.size === 0
68
+ ? {}
69
+ : { folderRemovals: yield* pathsOf(answer.folderRemovals) }),
70
+ };
71
+ }
2
72
  export function authorityRoot(handle) {
3
73
  return `/rooms/${handle}`;
4
74
  }
5
- export function contentPrefixes(tracked) {
6
- return [
7
- authorityRoot(tracked.handle),
8
- ...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
9
- ];
10
- }
11
75
  export function schemaPath(handle, schema) {
12
76
  return `${authorityRoot(handle)}/${schema}`;
13
77
  }
@@ -20,281 +84,154 @@ export function parseGrant(body) {
20
84
  const transfer = body.transfer;
21
85
  if (typeof transfer.url !== 'string')
22
86
  return null;
23
- if (transfer.method === 'GET')
24
- return { method: 'GET', url: transfer.url };
25
87
  if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
26
88
  return null;
27
- return { method: 'POST', operation: transfer.operation, url: transfer.url };
89
+ return { operation: transfer.operation, url: transfer.url };
90
+ }
91
+ export function parseFileAddress(body) {
92
+ if (typeof body !== 'object' || body === null)
93
+ return null;
94
+ const { download, name, sha256, media_type: mediaType } = body;
95
+ if (typeof download !== 'string' ||
96
+ typeof name !== 'string' ||
97
+ typeof sha256 !== 'string' ||
98
+ typeof mediaType !== 'string') {
99
+ return null;
100
+ }
101
+ return { url: download, name, sha256, mediaType };
28
102
  }
29
103
  function changeAuthor(value) {
30
104
  if (typeof value !== 'object' || value === null)
31
105
  return null;
32
- const { user, site, name } = value;
106
+ const { user, site, inbox, app, name } = value;
33
107
  if (typeof name !== 'string')
34
108
  return null;
35
- if (typeof user === 'string' && site === undefined)
109
+ const named = [user, site, inbox, app].filter((id) => id !== undefined);
110
+ if (named.length !== 1)
111
+ return null;
112
+ if (typeof user === 'string')
36
113
  return { kind: 'user', id: user, name };
37
- if (typeof site === 'string' && user === undefined)
114
+ if (typeof site === 'string')
38
115
  return { kind: 'site', id: site, name };
116
+ if (typeof inbox === 'string')
117
+ return { kind: 'inbox', id: inbox, name };
118
+ if (typeof app === 'string')
119
+ return { kind: 'app', id: app, name };
39
120
  return null;
40
121
  }
41
122
  export function headChange(held) {
42
123
  const author = held.author === undefined ? null : changeAuthor(held.author);
43
124
  if (held.author !== undefined && author === null)
44
125
  return null;
45
- if (held.created_at === undefined)
126
+ if (held.changed_at === undefined)
46
127
  return undefined;
47
- if (typeof held.created_at !== 'string')
128
+ if (typeof held.changed_at !== 'string')
48
129
  return null;
49
- return { author, time: held.created_at };
130
+ return { author, time: held.changed_at };
131
+ }
132
+ export 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 };
50
139
  }
51
140
  function headed(head) {
52
141
  return head === undefined ? {} : { head };
53
142
  }
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')
143
+ export function binaryFileOf(held) {
144
+ if (held.media_type === undefined)
145
+ return undefined;
146
+ const { bytes, media_type: mediaType, sha256 } = held;
147
+ if (typeof bytes !== 'number' || typeof mediaType !== 'string' || typeof sha256 !== 'string')
63
148
  return null;
64
- return { reference: attachment, name, byteLength: bytes, mediaType, entry: value };
149
+ return { byteLength: bytes, mediaType, sha256 };
65
150
  }
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;
151
+ function binaried(binary) {
152
+ return binary === undefined ? {} : { binary };
153
+ }
154
+ export function carriedFacts(held) {
155
+ return held.facts === undefined ? {} : { facts: held.facts };
77
156
  }
78
- function declared(attachments) {
79
- return attachments === undefined ? {} : { attachments };
157
+ function carriedSpace(held) {
158
+ return typeof held.space === 'string' ? { space: held.space } : {};
80
159
  }
81
- function parseFile(value, mode) {
160
+ export function parseFile(value, mode) {
82
161
  if (typeof value !== 'object' || value === null)
83
162
  return null;
84
163
  const file = value;
85
164
  if (typeof file.path !== 'string')
86
165
  return null;
87
166
  const head = headChange(file);
88
- if (head === null)
167
+ const created = createdOf(file);
168
+ const binary = binaryFileOf(file);
169
+ if (head === null || created === null || binary === null)
89
170
  return null;
90
171
  if (mode === 'site') {
91
172
  if (typeof file.sha256 !== 'string')
92
173
  return null;
93
- return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
94
- }
95
- if (typeof file.revision !== 'string')
96
- return null;
97
- return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
98
- }
99
- function parseScope(value, mode) {
100
- if (typeof value !== 'object' || value === null)
101
- return null;
102
- const held = value;
103
- if (typeof held.manifest !== 'object' || held.manifest === null)
104
- return null;
105
- if (!Array.isArray(held.contents))
106
- return null;
107
- const manifest = held.manifest;
108
- if (manifest.scope !== 'room')
109
- return null;
110
- const at = readPosition(manifest);
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;
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 };
139
- }
140
- function parseCursor(value) {
141
- if (typeof value !== 'object' || value === null)
142
- return null;
143
- const { room, path } = value;
144
- if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
145
- return null;
146
- return { room, path };
147
- }
148
- export function parseEnvelope(body) {
149
- if (typeof body !== 'object' || body === null)
150
- return null;
151
- if (!('scopes' in body) || !Array.isArray(body.scopes))
152
- return null;
153
- const scopes = [];
154
- for (const entry of body.scopes) {
155
- const scope = parseScope(entry, 'credential');
156
- if (scope === null)
157
- return null;
158
- scopes.push(scope);
159
- }
160
- if (!('next' in body) || body.next === undefined)
161
- return { scopes };
162
- const next = parseCursor(body.next);
163
- return next === null ? null : { scopes, next };
164
- }
165
- export function parseSiteBootstrap(body) {
166
- return parseScope(body, 'site');
167
- }
168
- function parseChange(value, mode) {
169
- if (typeof value !== 'object' || value === null)
170
- return null;
171
- const held = value;
172
- if (typeof held.path !== 'string')
173
- return null;
174
- if (held.removed === true)
175
- return { path: held.path, removed: true };
176
- const head = headChange(held);
177
- if (head === null)
178
- return null;
179
- if (mode === 'site') {
180
- if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
181
- return null;
182
174
  return {
183
- path: held.path,
184
- content: held.content,
185
- revision: undefined,
186
- version: held.sha256,
175
+ path: file.path,
176
+ revision: binary?.sha256,
177
+ version: file.sha256,
187
178
  ...headed(head),
179
+ ...binaried(binary),
180
+ ...carriedFacts(file),
188
181
  };
189
182
  }
190
- if (typeof held.content === 'string' && typeof held.revision === 'string') {
191
- return {
192
- path: held.path,
193
- content: held.content,
194
- revision: held.revision,
195
- version: held.revision,
196
- ...headed(head),
197
- };
198
- }
199
- if (typeof held.reference === 'object' && held.reference !== null) {
200
- const reference = held.reference;
201
- if (typeof reference.revision !== 'string')
202
- return null;
203
- return { path: held.path, reference: { revision: reference.revision } };
204
- }
205
- return null;
206
- }
207
- export function parseEnumeration(body, mode) {
208
- if (typeof body !== 'object' || body === null)
209
- return null;
210
- if (!('authorities' in body) || !Array.isArray(body.authorities))
183
+ if (typeof file.revision !== 'string')
211
184
  return null;
212
- const authorities = [];
213
- for (const entry of body.authorities) {
214
- if (typeof entry !== 'object' || entry === null)
215
- return null;
216
- const held = entry;
217
- const at = readPosition(held);
218
- if (typeof held.authority !== 'string' || at === null)
219
- return null;
220
- if (!Array.isArray(held.changes))
221
- return null;
222
- const changes = [];
223
- for (const change of held.changes) {
224
- const mapped = parseChange(change, mode);
225
- if (mapped === null)
226
- return null;
227
- changes.push(mapped);
228
- }
229
- if (mode === 'site') {
230
- authorities.push({ authority: held.authority, ...at, changes });
231
- continue;
232
- }
233
- const attachments = parseOriginals(held.originals);
234
- if (attachments === null)
235
- return null;
236
- authorities.push({ authority: held.authority, ...at, changes, attachments });
237
- }
238
- return { authorities };
239
- }
240
- export function advancedScope(scope, view) {
241
- const files = new Map(scope.files.map((file) => [file.path, file]));
242
- const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
243
- for (const change of view.changes) {
244
- files.delete(change.path);
245
- contents.delete(change.path);
246
- if ('removed' in change)
247
- continue;
248
- if ('content' in change) {
249
- files.set(change.path, {
250
- path: change.path,
251
- revision: change.revision,
252
- version: change.version,
253
- ...headed(change.head),
254
- });
255
- contents.set(change.path, change.content);
256
- continue;
257
- }
258
- const { revision } = change.reference;
259
- files.set(change.path, { path: change.path, revision, version: revision });
260
- }
261
185
  return {
262
- ...scope,
263
- position: view.position,
264
- logEpoch: view.logEpoch,
265
- files: [...files.values()],
266
- contents: [...contents].map(([path, content]) => ({ path, content })),
186
+ path: file.path,
187
+ revision: file.revision,
188
+ version: file.revision,
189
+ ...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
190
+ ...headed(head),
191
+ ...createdHeld(created),
192
+ ...binaried(binary),
193
+ ...carriedFacts(file),
194
+ ...carriedSpace(file),
267
195
  };
268
196
  }
269
- export function matchesScope(scope, tracked) {
270
- return scope.anchor === tracked.authority;
197
+ export function modelScope(room) {
198
+ return {
199
+ anchor: room.anchor,
200
+ position: room.position,
201
+ logEpoch: room.logEpoch,
202
+ files: room.models.files,
203
+ contents: room.models.contents,
204
+ };
271
205
  }
272
- export function bootstrapOf(scope) {
273
- const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
274
- const documents = {};
275
- const revisions = {};
276
- const changes = {};
277
- const binaryTargets = [];
206
+ export function* bootstrapping(scope) {
207
+ const contents = new Map();
208
+ for (const entry of scope.contents) {
209
+ contents.set(entry.path, entry.content);
210
+ yield ROW_WEIGHT;
211
+ }
212
+ const answer = answering();
278
213
  for (const file of scope.files) {
279
- if (file.revision !== undefined)
280
- revisions[file.path] = file.revision;
214
+ yield ROW_WEIGHT;
215
+ if (file.space !== undefined)
216
+ continue;
281
217
  if (file.head !== undefined)
282
- changes[file.path] = file.head;
218
+ answer.changes.set(file.path, file.head);
219
+ if (file.created !== undefined)
220
+ answer.created.set(file.path, file.created);
283
221
  const content = contents.get(file.path);
284
- if (content === undefined)
285
- binaryTargets.push(file.path);
286
- else
287
- documents[file.path] = content;
222
+ if (file.binary !== undefined)
223
+ answer.binaryFiles.set(file.path, file.binary);
224
+ else if (content !== undefined)
225
+ answer.documents.set(file.path, content);
226
+ if (file.binary === undefined && file.facts !== undefined)
227
+ answer.facts.set(file.path, file.facts);
228
+ if (file.revision !== undefined)
229
+ revised(answer, file.path, file.revision);
288
230
  }
289
- return {
290
- kind: 'bootstrap',
291
- roomVersion: roomVersion(scope),
292
- documents,
293
- revisions,
294
- changes,
295
- binaryTargets: binaryTargets.sort(),
296
- ...declared(scope.attachments),
297
- };
231
+ for (const folder of scope.folders ?? [])
232
+ folded(answer, folder, false);
233
+ const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
234
+ return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
298
235
  }
299
236
  export function schemaOf(scope, schema) {
300
237
  const file = scope.files.find((entry) => entry.path === schema);
@@ -303,43 +240,10 @@ export function schemaOf(scope, schema) {
303
240
  const content = scope.contents.find((entry) => entry.path === schema);
304
241
  return content === undefined
305
242
  ? null
306
- : { schema: content.content, version: file.version, revision: file.revision ?? null };
307
- }
308
- export function viewOf(enumeration, tracked) {
309
- return enumeration.authorities.find((entry) => entry.authority === tracked.authority);
310
- }
311
- export function refreshFrom(view, fromRoomVersion) {
312
- if (roomVersion(view) === fromRoomVersion)
313
- return { kind: 'still-current' };
314
- const documents = {};
315
- const revisions = {};
316
- const changes = {};
317
- const binaryTargets = [];
318
- const removals = [];
319
- for (const change of view.changes) {
320
- if ('removed' in change) {
321
- removals.push(change.path);
322
- continue;
323
- }
324
- if ('content' in change) {
325
- documents[change.path] = change.content;
326
- if (change.revision !== undefined)
327
- revisions[change.path] = change.revision;
328
- if (change.head !== undefined)
329
- changes[change.path] = change.head;
330
- continue;
331
- }
332
- binaryTargets.push(change.path);
333
- revisions[change.path] = change.reference.revision;
334
- }
335
- return {
336
- kind: 'net-advancement',
337
- roomVersion: roomVersion(view),
338
- documents,
339
- revisions,
340
- changes,
341
- binaryTargets: binaryTargets.sort(),
342
- removals: removals.sort(),
343
- ...declared(view.attachments),
344
- };
243
+ : {
244
+ schema: content.content,
245
+ version: file.version,
246
+ revision: file.revision ?? null,
247
+ ...(file.space === undefined ? {} : { space: file.space }),
248
+ };
345
249
  }
package/dist/refusal.d.ts CHANGED
@@ -1,12 +1,7 @@
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 resetOf(refusal: ProviderRefusal | null): string | undefined;
4
+ export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
7
5
  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
6
  export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
12
7
  //# 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,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;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,15 @@ 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
+ }
12
+ export function resetOf(refusal) {
13
+ const reset = refusal?.fields.retry_at;
14
+ return refusal?.retryable === true && typeof reset === 'string' ? reset : undefined;
11
15
  }
12
16
  export function scopedRefusal(locator, scope, refusal) {
13
- return { kind: 'scoped-refusal', locator, scope, code: refusal.code, fields: refusal.fields };
17
+ return { kind: 'scoped-refusal', locator, scope, ...refusal };
14
18
  }
15
19
  function doorFailure(status, body) {
16
20
  if (status === 0)
@@ -18,8 +22,9 @@ function doorFailure(status, body) {
18
22
  const refusal = doorRefusal(body);
19
23
  if (status === 401)
20
24
  return { kind: 'revoked-authorization' };
21
- if (refusal?.retryable === true)
25
+ if (refusal?.retryable === true || refusal?.code === 'update_required') {
22
26
  return { kind: 'transport-uncertainty' };
27
+ }
23
28
  if (status === 404 || refusal?.code === 'room_not_found')
24
29
  return { kind: 'room-not-readable' };
25
30
  if (status < 400)
@@ -38,11 +43,6 @@ export function classifyDoor(status, body, locator) {
38
43
  return scopedRefusal(locator, failure.scope, failure.refusal);
39
44
  return failure;
40
45
  }
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
46
  export function discoveryFailure(status, body) {
47
47
  const failure = doorFailure(status, body);
48
48
  if (failure === null)
@@ -50,11 +50,7 @@ export function discoveryFailure(status, body) {
50
50
  if (failure.kind === 'revoked-authorization')
51
51
  return failure;
52
52
  if (failure.kind === 'refused') {
53
- return {
54
- kind: 'contract-unavailable',
55
- code: failure.refusal.code,
56
- fields: failure.refusal.fields,
57
- };
53
+ return { kind: 'contract-unavailable', ...failure.refusal };
58
54
  }
59
55
  return { kind: 'transport-uncertainty' };
60
56
  }
@@ -0,0 +1,5 @@
1
+ export declare const INBOX_CHANNEL_KINDS: readonly ['telegram-bot', 'telegram-business', 'whatsapp', 'messenger', 'instagram', 'viber', 'tiktok'];
2
+ export type InboxChannelKind = (typeof INBOX_CHANNEL_KINDS)[number];
3
+ export declare const HOUSE_NAMEABLE_ROOM_TYPES: string[];
4
+ export declare const HOUSE_ROOM_TYPES: string;
5
+ //# sourceMappingURL=room-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"room-types.d.ts","sourceRoot":"","sources":["../src/room-types.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,mBAAmB,YAC9B,cAAc,EACd,mBAAmB,EACnB,UAAU,EACV,WAAW,EACX,WAAW,EACX,OAAO,EACP,QAAQ,CACA,CAAC;AAEX,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,yBAAyB,UAAiC,CAAC;AAyBxE,eAAO,MAAM,gBAAgB,QAyFjB,CAAC"}