@agentshouse/mdruntime-adapter 0.1.0-cc63dd043d0e2 → 0.1.0-cc65657e82614
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.
- package/README.md +5 -5
- package/dist/actions.d.ts +6 -6
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +25 -326
- package/dist/adapter.d.ts +1 -1
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +284 -250
- package/dist/app-reference.d.ts +1 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/authored-path.d.ts +10 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +35 -0
- package/dist/chunks.d.ts +37 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +247 -0
- package/dist/crockford.d.ts +3 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/digest.d.ts +0 -1
- package/dist/discovery.d.ts +28 -28
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +112 -79
- package/dist/history.d.ts +6 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +84 -0
- package/dist/house-model.d.ts +830 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +465 -0
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/map.d.ts +0 -1
- package/dist/model.d.ts +8 -19
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +53 -39
- package/dist/read.d.ts +63 -43
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +179 -265
- package/dist/refusal.d.ts +5 -12
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +31 -18
- package/dist/room-types.d.ts +4 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +135 -0
- package/dist/search.d.ts +4 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/session-content/bounds.d.ts +7 -0
- package/dist/session-content/check.d.ts +18 -0
- package/dist/session-content/index.d.ts +7 -0
- package/dist/session-content/parts.d.ts +102 -0
- package/dist/session-content/state.d.ts +61 -0
- package/dist/session-content/turn.d.ts +328 -0
- package/dist/site.d.ts +1 -2
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +128 -142
- package/dist/space-schema.d.ts +6 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +18 -12
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +345 -144
- package/dist/transport.d.ts +124 -27
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +55 -10
- package/dist/upload.d.ts +11 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/version.d.ts +2 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +10 -1
- package/dist/write.d.ts +20 -5
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +170 -60
- package/package.json +9 -6
- package/AGENTS.md +0 -215
- package/dist/gather.d.ts +0 -3
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -40
- package/dist/links.d.ts +0 -12
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -66
package/dist/read.js
CHANGED
|
@@ -1,10 +1,77 @@
|
|
|
1
|
-
import {
|
|
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 [authorityRoot(tracked.handle)];
|
|
7
|
-
}
|
|
8
75
|
export function schemaPath(handle, schema) {
|
|
9
76
|
return `${authorityRoot(handle)}/${schema}`;
|
|
10
77
|
}
|
|
@@ -17,319 +84,166 @@ export function parseGrant(body) {
|
|
|
17
84
|
const transfer = body.transfer;
|
|
18
85
|
if (typeof transfer.url !== 'string')
|
|
19
86
|
return null;
|
|
20
|
-
if (transfer.method === 'GET')
|
|
21
|
-
return { method: 'GET', url: transfer.url };
|
|
22
87
|
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
23
88
|
return null;
|
|
24
|
-
return {
|
|
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 };
|
|
25
102
|
}
|
|
26
103
|
function changeAuthor(value) {
|
|
27
104
|
if (typeof value !== 'object' || value === null)
|
|
28
105
|
return null;
|
|
29
|
-
const { user, site, name } = value;
|
|
106
|
+
const { user, site, inbox, app, name } = value;
|
|
30
107
|
if (typeof name !== 'string')
|
|
31
108
|
return null;
|
|
32
|
-
|
|
109
|
+
const named = [user, site, inbox, app].filter((id) => id !== undefined);
|
|
110
|
+
if (named.length !== 1)
|
|
111
|
+
return null;
|
|
112
|
+
if (typeof user === 'string')
|
|
33
113
|
return { kind: 'user', id: user, name };
|
|
34
|
-
if (typeof site === 'string'
|
|
114
|
+
if (typeof site === 'string')
|
|
35
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 };
|
|
36
120
|
return null;
|
|
37
121
|
}
|
|
38
122
|
export function headChange(held) {
|
|
39
123
|
const author = held.author === undefined ? null : changeAuthor(held.author);
|
|
40
124
|
if (held.author !== undefined && author === null)
|
|
41
125
|
return null;
|
|
42
|
-
if (held.
|
|
126
|
+
if (held.changed_at === undefined)
|
|
43
127
|
return undefined;
|
|
44
|
-
if (typeof held.
|
|
128
|
+
if (typeof held.changed_at !== 'string')
|
|
45
129
|
return null;
|
|
46
|
-
return { author, time: held.
|
|
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 };
|
|
47
139
|
}
|
|
48
140
|
function headed(head) {
|
|
49
141
|
return head === undefined ? {} : { head };
|
|
50
142
|
}
|
|
51
|
-
function
|
|
52
|
-
if (
|
|
53
|
-
return
|
|
54
|
-
const {
|
|
55
|
-
if (typeof
|
|
56
|
-
return null;
|
|
57
|
-
if (typeof bytes !== 'number' || !Number.isSafeInteger(bytes) || bytes < 0)
|
|
58
|
-
return null;
|
|
59
|
-
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')
|
|
60
148
|
return null;
|
|
61
|
-
return {
|
|
149
|
+
return { byteLength: bytes, mediaType, sha256 };
|
|
62
150
|
}
|
|
63
|
-
function
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const attachment = parseOriginal(entry);
|
|
69
|
-
if (attachment === null)
|
|
70
|
-
return null;
|
|
71
|
-
attachments.push(attachment);
|
|
72
|
-
}
|
|
73
|
-
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 };
|
|
74
156
|
}
|
|
75
|
-
function
|
|
76
|
-
return
|
|
157
|
+
function carriedSpace(held) {
|
|
158
|
+
return typeof held.space === 'string' ? { space: held.space } : {};
|
|
77
159
|
}
|
|
78
|
-
function parseFile(value, mode) {
|
|
160
|
+
export function parseFile(value, mode) {
|
|
79
161
|
if (typeof value !== 'object' || value === null)
|
|
80
162
|
return null;
|
|
81
163
|
const file = value;
|
|
82
164
|
if (typeof file.path !== 'string')
|
|
83
165
|
return null;
|
|
84
166
|
const head = headChange(file);
|
|
85
|
-
|
|
167
|
+
const created = createdOf(file);
|
|
168
|
+
const binary = binaryFileOf(file);
|
|
169
|
+
if (head === null || created === null || binary === null)
|
|
86
170
|
return null;
|
|
87
171
|
if (mode === 'site') {
|
|
88
172
|
if (typeof file.sha256 !== 'string')
|
|
89
173
|
return null;
|
|
90
|
-
return { path: file.path, revision: undefined, version: file.sha256, ...headed(head) };
|
|
91
|
-
}
|
|
92
|
-
if (typeof file.revision !== 'string')
|
|
93
|
-
return null;
|
|
94
|
-
return { path: file.path, revision: file.revision, version: file.revision, ...headed(head) };
|
|
95
|
-
}
|
|
96
|
-
function parseScope(value, mode) {
|
|
97
|
-
if (typeof value !== 'object' || value === null)
|
|
98
|
-
return null;
|
|
99
|
-
const held = value;
|
|
100
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
101
|
-
return null;
|
|
102
|
-
if (!Array.isArray(held.contents))
|
|
103
|
-
return null;
|
|
104
|
-
const manifest = held.manifest;
|
|
105
|
-
if (manifest.scope !== 'room')
|
|
106
|
-
return null;
|
|
107
|
-
const at = readPosition(manifest);
|
|
108
|
-
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
109
|
-
return null;
|
|
110
|
-
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
111
|
-
return null;
|
|
112
|
-
if (!Array.isArray(manifest.files))
|
|
113
|
-
return null;
|
|
114
|
-
const files = [];
|
|
115
|
-
for (const entry of manifest.files) {
|
|
116
|
-
const file = parseFile(entry, mode);
|
|
117
|
-
if (file === null)
|
|
118
|
-
return null;
|
|
119
|
-
files.push(file);
|
|
120
|
-
}
|
|
121
|
-
const contents = [];
|
|
122
|
-
for (const entry of held.contents) {
|
|
123
|
-
if (typeof entry !== 'object' || entry === null)
|
|
124
|
-
return null;
|
|
125
|
-
const content = entry;
|
|
126
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
127
|
-
return null;
|
|
128
|
-
contents.push({ path: content.path, content: content.content });
|
|
129
|
-
}
|
|
130
|
-
if (mode === 'site')
|
|
131
|
-
return { anchor: manifest.anchor, ...at, files, contents };
|
|
132
|
-
const attachments = parseOriginals(held.originals);
|
|
133
|
-
if (attachments === null)
|
|
134
|
-
return null;
|
|
135
|
-
return { anchor: manifest.anchor, ...at, files, contents, attachments };
|
|
136
|
-
}
|
|
137
|
-
export function parseEnvelope(body) {
|
|
138
|
-
if (typeof body !== 'object' || body === null)
|
|
139
|
-
return null;
|
|
140
|
-
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
141
|
-
return null;
|
|
142
|
-
const scopes = [];
|
|
143
|
-
for (const entry of body.scopes) {
|
|
144
|
-
const scope = parseScope(entry, 'credential');
|
|
145
|
-
if (scope === null)
|
|
146
|
-
return null;
|
|
147
|
-
scopes.push(scope);
|
|
148
|
-
}
|
|
149
|
-
return { scopes };
|
|
150
|
-
}
|
|
151
|
-
export function parseSiteBootstrap(body) {
|
|
152
|
-
return parseScope(body, 'site');
|
|
153
|
-
}
|
|
154
|
-
function parseChange(value, mode) {
|
|
155
|
-
if (typeof value !== 'object' || value === null)
|
|
156
|
-
return null;
|
|
157
|
-
const held = value;
|
|
158
|
-
if (typeof held.path !== 'string')
|
|
159
|
-
return null;
|
|
160
|
-
if (held.removed === true)
|
|
161
|
-
return { path: held.path, removed: true };
|
|
162
|
-
const head = headChange(held);
|
|
163
|
-
if (head === null)
|
|
164
|
-
return null;
|
|
165
|
-
if (mode === 'site') {
|
|
166
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
167
|
-
return null;
|
|
168
174
|
return {
|
|
169
|
-
path:
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
version: held.sha256,
|
|
175
|
+
path: file.path,
|
|
176
|
+
revision: binary?.sha256,
|
|
177
|
+
version: file.sha256,
|
|
173
178
|
...headed(head),
|
|
179
|
+
...binaried(binary),
|
|
180
|
+
...carriedFacts(file),
|
|
174
181
|
};
|
|
175
182
|
}
|
|
176
|
-
if (typeof
|
|
177
|
-
return {
|
|
178
|
-
path: held.path,
|
|
179
|
-
content: held.content,
|
|
180
|
-
revision: held.revision,
|
|
181
|
-
version: held.revision,
|
|
182
|
-
...headed(head),
|
|
183
|
-
};
|
|
184
|
-
}
|
|
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
|
-
return null;
|
|
192
|
-
}
|
|
193
|
-
export function parseEnumeration(body, mode) {
|
|
194
|
-
if (typeof body !== 'object' || body === null)
|
|
195
|
-
return null;
|
|
196
|
-
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
183
|
+
if (typeof file.revision !== 'string')
|
|
197
184
|
return null;
|
|
198
|
-
const authorities = [];
|
|
199
|
-
for (const entry of body.authorities) {
|
|
200
|
-
if (typeof entry !== 'object' || entry === null)
|
|
201
|
-
return null;
|
|
202
|
-
const held = entry;
|
|
203
|
-
const at = readPosition(held);
|
|
204
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
205
|
-
return null;
|
|
206
|
-
if (!Array.isArray(held.changes))
|
|
207
|
-
return null;
|
|
208
|
-
const changes = [];
|
|
209
|
-
for (const change of held.changes) {
|
|
210
|
-
const mapped = parseChange(change, mode);
|
|
211
|
-
if (mapped === null)
|
|
212
|
-
return null;
|
|
213
|
-
changes.push(mapped);
|
|
214
|
-
}
|
|
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)
|
|
221
|
-
return null;
|
|
222
|
-
authorities.push({ authority: held.authority, ...at, changes, attachments });
|
|
223
|
-
}
|
|
224
|
-
return { authorities };
|
|
225
|
-
}
|
|
226
|
-
export function advancedScope(scope, view) {
|
|
227
|
-
const files = new Map(scope.files.map((file) => [file.path, file]));
|
|
228
|
-
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
229
|
-
for (const change of view.changes) {
|
|
230
|
-
files.delete(change.path);
|
|
231
|
-
contents.delete(change.path);
|
|
232
|
-
if ('removed' in change)
|
|
233
|
-
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
|
-
});
|
|
241
|
-
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
|
-
}
|
|
247
185
|
return {
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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),
|
|
253
195
|
};
|
|
254
196
|
}
|
|
255
|
-
export function
|
|
256
|
-
return
|
|
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
|
+
};
|
|
257
205
|
}
|
|
258
|
-
export function
|
|
259
|
-
const contents = new Map(
|
|
260
|
-
const
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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();
|
|
264
213
|
for (const file of scope.files) {
|
|
265
|
-
|
|
266
|
-
|
|
214
|
+
yield ROW_WEIGHT;
|
|
215
|
+
if (file.space !== undefined)
|
|
216
|
+
continue;
|
|
267
217
|
if (file.head !== undefined)
|
|
268
|
-
changes
|
|
218
|
+
answer.changes.set(file.path, file.head);
|
|
219
|
+
if (file.created !== undefined)
|
|
220
|
+
answer.created.set(file.path, file.created);
|
|
269
221
|
const content = contents.get(file.path);
|
|
270
|
-
if (
|
|
271
|
-
|
|
272
|
-
else
|
|
273
|
-
documents
|
|
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);
|
|
274
230
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
revisions,
|
|
280
|
-
changes,
|
|
281
|
-
binaryTargets: binaryTargets.sort(),
|
|
282
|
-
...declared(scope.attachments),
|
|
283
|
-
};
|
|
284
|
-
}
|
|
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);
|
|
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 };
|
|
290
235
|
}
|
|
291
236
|
export function schemaOf(scope, schema) {
|
|
292
237
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
293
238
|
if (file === undefined)
|
|
294
|
-
return { schema: null, version: null };
|
|
239
|
+
return { schema: null, version: null, revision: null };
|
|
295
240
|
const content = scope.contents.find((entry) => entry.path === schema);
|
|
296
|
-
return content === undefined
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
const documents = {};
|
|
305
|
-
const revisions = {};
|
|
306
|
-
const changes = {};
|
|
307
|
-
const binaryTargets = [];
|
|
308
|
-
const removals = [];
|
|
309
|
-
for (const change of view.changes) {
|
|
310
|
-
if ('removed' in change) {
|
|
311
|
-
removals.push(change.path);
|
|
312
|
-
continue;
|
|
313
|
-
}
|
|
314
|
-
if ('content' in change) {
|
|
315
|
-
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;
|
|
324
|
-
}
|
|
325
|
-
return {
|
|
326
|
-
kind: 'net-advancement',
|
|
327
|
-
roomVersion: roomVersion(view),
|
|
328
|
-
documents,
|
|
329
|
-
revisions,
|
|
330
|
-
changes,
|
|
331
|
-
binaryTargets: binaryTargets.sort(),
|
|
332
|
-
removals: removals.sort(),
|
|
333
|
-
...declared(view.attachments),
|
|
334
|
-
};
|
|
241
|
+
return content === undefined
|
|
242
|
+
? null
|
|
243
|
+
: {
|
|
244
|
+
schema: content.content,
|
|
245
|
+
version: file.version,
|
|
246
|
+
revision: file.revision ?? null,
|
|
247
|
+
...(file.space === undefined ? {} : { space: file.space }),
|
|
248
|
+
};
|
|
335
249
|
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } from '@agentshouse/mdruntime';
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
export declare function
|
|
6
|
-
export declare function
|
|
7
|
-
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | {
|
|
8
|
-
kind: 'beyond-horizon';
|
|
9
|
-
} | null;
|
|
10
|
-
export declare function discoveryFailure(classified: AdapterFailure | {
|
|
11
|
-
kind: 'beyond-horizon';
|
|
12
|
-
}): DiscoverResult;
|
|
13
|
-
//# sourceMappingURL=refusal.d.ts.map
|
|
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;
|
|
5
|
+
export declare function classifyDoor(status: number, body: unknown, locator: string): AdapterFailure | null;
|
|
6
|
+
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
package/dist/refusal.d.ts.map
CHANGED
|
@@ -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,
|
|
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,38 +6,51 @@ 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:
|
|
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,
|
|
17
|
+
return { kind: 'scoped-refusal', locator, scope, ...refusal };
|
|
14
18
|
}
|
|
15
|
-
|
|
19
|
+
function doorFailure(status, body) {
|
|
16
20
|
if (status === 0)
|
|
17
21
|
return { kind: 'transport-uncertainty' };
|
|
18
|
-
const refusal = doorRefusal(body);
|
|
19
22
|
if (status === 401)
|
|
20
23
|
return { kind: 'revoked-authorization' };
|
|
21
|
-
|
|
24
|
+
const refusal = doorRefusal(body);
|
|
25
|
+
if (refusal?.retryable === true || refusal?.code === 'update_required') {
|
|
22
26
|
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
27
|
}
|
|
28
|
+
if (status === 404 || refusal?.code === 'room_not_found')
|
|
29
|
+
return { kind: 'room-not-readable' };
|
|
28
30
|
if (status < 400)
|
|
29
31
|
return null;
|
|
30
32
|
if (refusal === null)
|
|
31
33
|
return { kind: 'transport-uncertainty' };
|
|
32
|
-
|
|
33
|
-
return scopedRefusal(locator, 'operation', refusal);
|
|
34
|
-
return scopedRefusal(locator, 'undisclosed', refusal);
|
|
34
|
+
return { kind: 'refused', scope: status === 403 ? 'operation' : 'undisclosed', refusal };
|
|
35
35
|
}
|
|
36
|
-
export function
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export function classifyDoor(status, body, locator) {
|
|
37
|
+
const failure = doorFailure(status, body);
|
|
38
|
+
if (failure === null)
|
|
39
|
+
return null;
|
|
40
|
+
if (failure.kind === 'room-not-readable')
|
|
41
|
+
return { kind: 'room-not-readable', locator };
|
|
42
|
+
if (failure.kind === 'refused')
|
|
43
|
+
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
44
|
+
return failure;
|
|
45
|
+
}
|
|
46
|
+
export function discoveryFailure(status, body) {
|
|
47
|
+
const failure = doorFailure(status, body);
|
|
48
|
+
if (failure === null)
|
|
49
|
+
return null;
|
|
50
|
+
if (failure.kind === 'revoked-authorization')
|
|
51
|
+
return failure;
|
|
52
|
+
if (failure.kind === 'refused') {
|
|
53
|
+
return { kind: 'contract-unavailable', ...failure.refusal };
|
|
41
54
|
}
|
|
42
55
|
return { kind: 'transport-uncertainty' };
|
|
43
56
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
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;
|
|
@@ -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;AA8BxE,eAAO,MAAM,gBAAgB,QAmGjB,CAAC"}
|