@agentshouse/mdruntime-adapter 0.1.0-c8f1d7ae21976 → 0.1.0-c9107451c8ea3
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 +2 -2
- package/dist/actions.d.ts +4 -66
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +8 -337
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +238 -365
- package/dist/app-reference.d.ts +2 -0
- package/dist/app-reference.d.ts.map +1 -0
- package/dist/app-reference.js +2 -0
- package/dist/chunks.d.ts +38 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +247 -0
- package/dist/crockford.d.ts +4 -0
- package/dist/crockford.d.ts.map +1 -0
- package/dist/crockford.js +3 -0
- package/dist/discovery.d.ts +23 -15
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +92 -55
- package/dist/history.d.ts +12 -0
- package/dist/history.d.ts.map +1 -0
- package/dist/history.js +92 -0
- package/dist/house-model.d.ts +672 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +377 -0
- package/dist/index.d.ts +11 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/model.d.ts +5 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +34 -41
- package/dist/read.d.ts +51 -61
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +137 -306
- package/dist/refusal.d.ts +0 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +0 -5
- package/dist/room-types.d.ts +7 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +123 -0
- package/dist/search.d.ts +5 -0
- package/dist/search.d.ts.map +1 -0
- package/dist/search.js +47 -0
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +100 -202
- package/dist/space-schema.d.ts +7 -0
- package/dist/space-schema.d.ts.map +1 -0
- package/dist/space-schema.js +18 -0
- package/dist/stream.d.ts +16 -15
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +254 -420
- package/dist/transport.d.ts +70 -44
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +54 -11
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/write.d.ts +18 -2
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +105 -74
- package/package.json +8 -4
- package/AGENTS.md +0 -300
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/handed.d.ts +0 -15
- package/dist/handed.d.ts.map +0 -1
- package/dist/handed.js +0 -38
- package/dist/referrer.d.ts +0 -7
- package/dist/referrer.d.ts.map +0 -1
- package/dist/referrer.js +0 -35
package/dist/read.js
CHANGED
|
@@ -1,13 +1,74 @@
|
|
|
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
|
+
changes: new Map(),
|
|
14
|
+
binaryFiles: new Map(),
|
|
15
|
+
removals: new Set(),
|
|
16
|
+
folders: new Set(),
|
|
17
|
+
folderRemovals: new Set(),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export function revised(answer, path, revision) {
|
|
21
|
+
answer.revisions.set(path, revision);
|
|
22
|
+
const file = fileOf(revision);
|
|
23
|
+
if (file !== undefined)
|
|
24
|
+
answer.fileIds.set(path, file);
|
|
25
|
+
}
|
|
26
|
+
export function forgotten(answer, path) {
|
|
27
|
+
answer.documents.delete(path);
|
|
28
|
+
answer.facts.delete(path);
|
|
29
|
+
answer.revisions.delete(path);
|
|
30
|
+
answer.fileIds.delete(path);
|
|
31
|
+
answer.changes.delete(path);
|
|
32
|
+
answer.binaryFiles.delete(path);
|
|
33
|
+
answer.removals.delete(path);
|
|
34
|
+
}
|
|
35
|
+
export function folded(answer, path, removed) {
|
|
36
|
+
if (removed) {
|
|
37
|
+
answer.folders.delete(path);
|
|
38
|
+
answer.folderRemovals.add(path);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
answer.folderRemovals.delete(path);
|
|
42
|
+
answer.folders.add(path);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function* pathsOf(paths) {
|
|
46
|
+
const list = [];
|
|
47
|
+
for (const path of paths) {
|
|
48
|
+
list.push(path);
|
|
49
|
+
yield ROW_WEIGHT;
|
|
50
|
+
}
|
|
51
|
+
return list;
|
|
52
|
+
}
|
|
53
|
+
export function* answered(answer) {
|
|
54
|
+
const removals = yield* pathsOf(answer.removals);
|
|
55
|
+
return {
|
|
56
|
+
documents: yield* patching({}, answer.documents),
|
|
57
|
+
facts: yield* patching({}, answer.facts),
|
|
58
|
+
revisions: yield* patching({}, answer.revisions),
|
|
59
|
+
...(answer.fileIds.size === 0 ? {} : { fileIds: yield* patching({}, answer.fileIds) }),
|
|
60
|
+
changes: yield* patching({}, answer.changes),
|
|
61
|
+
binaryFiles: yield* patching({}, answer.binaryFiles),
|
|
62
|
+
removals,
|
|
63
|
+
...(answer.folders.size === 0 ? {} : { folders: yield* pathsOf(answer.folders) }),
|
|
64
|
+
...(answer.folderRemovals.size === 0
|
|
65
|
+
? {}
|
|
66
|
+
: { folderRemovals: yield* pathsOf(answer.folderRemovals) }),
|
|
67
|
+
};
|
|
68
|
+
}
|
|
2
69
|
export function authorityRoot(handle) {
|
|
3
70
|
return `/rooms/${handle}`;
|
|
4
71
|
}
|
|
5
|
-
export function contentPrefixes(tracked) {
|
|
6
|
-
return [
|
|
7
|
-
authorityRoot(tracked.handle),
|
|
8
|
-
...tracked.schemas.map((schema) => schemaPath(tracked.handle, schema)),
|
|
9
|
-
];
|
|
10
|
-
}
|
|
11
72
|
export function schemaPath(handle, schema) {
|
|
12
73
|
return `${authorityRoot(handle)}/${schema}`;
|
|
13
74
|
}
|
|
@@ -20,22 +81,39 @@ export function parseGrant(body) {
|
|
|
20
81
|
const transfer = body.transfer;
|
|
21
82
|
if (typeof transfer.url !== 'string')
|
|
22
83
|
return null;
|
|
23
|
-
if (transfer.method === 'GET')
|
|
24
|
-
return { method: 'GET', url: transfer.url };
|
|
25
84
|
if (transfer.method !== 'POST' || typeof transfer.operation !== 'string')
|
|
26
85
|
return null;
|
|
27
|
-
return {
|
|
86
|
+
return { operation: transfer.operation, url: transfer.url };
|
|
87
|
+
}
|
|
88
|
+
export function parseFileAddress(body) {
|
|
89
|
+
if (typeof body !== 'object' || body === null)
|
|
90
|
+
return null;
|
|
91
|
+
const { download, name, sha256, media_type: mediaType } = body;
|
|
92
|
+
if (typeof download !== 'string' ||
|
|
93
|
+
typeof name !== 'string' ||
|
|
94
|
+
typeof sha256 !== 'string' ||
|
|
95
|
+
typeof mediaType !== 'string') {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return { url: download, name, sha256, mediaType };
|
|
28
99
|
}
|
|
29
100
|
function changeAuthor(value) {
|
|
30
101
|
if (typeof value !== 'object' || value === null)
|
|
31
102
|
return null;
|
|
32
|
-
const { user, site, name } = value;
|
|
103
|
+
const { user, site, inbox, app, name } = value;
|
|
33
104
|
if (typeof name !== 'string')
|
|
34
105
|
return null;
|
|
35
|
-
|
|
106
|
+
const named = [user, site, inbox, app].filter((id) => id !== undefined);
|
|
107
|
+
if (named.length !== 1)
|
|
108
|
+
return null;
|
|
109
|
+
if (typeof user === 'string')
|
|
36
110
|
return { kind: 'user', id: user, name };
|
|
37
|
-
if (typeof site === 'string'
|
|
111
|
+
if (typeof site === 'string')
|
|
38
112
|
return { kind: 'site', id: site, name };
|
|
113
|
+
if (typeof inbox === 'string')
|
|
114
|
+
return { kind: 'inbox', id: inbox, name };
|
|
115
|
+
if (typeof app === 'string')
|
|
116
|
+
return { kind: 'app', id: app, name };
|
|
39
117
|
return null;
|
|
40
118
|
}
|
|
41
119
|
export function headChange(held) {
|
|
@@ -52,20 +130,23 @@ function headed(head) {
|
|
|
52
130
|
return head === undefined ? {} : { head };
|
|
53
131
|
}
|
|
54
132
|
export function binaryFileOf(held) {
|
|
55
|
-
if (held.
|
|
133
|
+
if (held.media_type === undefined)
|
|
56
134
|
return undefined;
|
|
57
|
-
const {
|
|
58
|
-
if (typeof
|
|
59
|
-
typeof bytes !== 'number' ||
|
|
60
|
-
typeof mediaType !== 'string' ||
|
|
61
|
-
typeof sha256 !== 'string')
|
|
135
|
+
const { bytes, media_type: mediaType, sha256 } = held;
|
|
136
|
+
if (typeof bytes !== 'number' || typeof mediaType !== 'string' || typeof sha256 !== 'string')
|
|
62
137
|
return null;
|
|
63
|
-
return {
|
|
138
|
+
return { byteLength: bytes, mediaType, sha256 };
|
|
64
139
|
}
|
|
65
140
|
function binaried(binary) {
|
|
66
141
|
return binary === undefined ? {} : { binary };
|
|
67
142
|
}
|
|
68
|
-
function
|
|
143
|
+
export function carriedFacts(held) {
|
|
144
|
+
return held.facts === undefined ? {} : { facts: held.facts };
|
|
145
|
+
}
|
|
146
|
+
function carriedSpace(held) {
|
|
147
|
+
return typeof held.space === 'string' ? { space: held.space } : {};
|
|
148
|
+
}
|
|
149
|
+
export function parseFile(value, mode) {
|
|
69
150
|
if (typeof value !== 'object' || value === null)
|
|
70
151
|
return null;
|
|
71
152
|
const file = value;
|
|
@@ -84,6 +165,7 @@ function parseFile(value, mode) {
|
|
|
84
165
|
version: file.sha256,
|
|
85
166
|
...headed(head),
|
|
86
167
|
...binaried(binary),
|
|
168
|
+
...carriedFacts(file),
|
|
87
169
|
};
|
|
88
170
|
}
|
|
89
171
|
if (typeof file.revision !== 'string')
|
|
@@ -95,267 +177,46 @@ function parseFile(value, mode) {
|
|
|
95
177
|
...(typeof file.sha256 === 'string' ? { sha256: file.sha256 } : {}),
|
|
96
178
|
...headed(head),
|
|
97
179
|
...binaried(binary),
|
|
180
|
+
...carriedFacts(file),
|
|
181
|
+
...carriedSpace(file),
|
|
98
182
|
};
|
|
99
183
|
}
|
|
100
|
-
function
|
|
101
|
-
if (typeof value !== 'object' || value === null)
|
|
102
|
-
return null;
|
|
103
|
-
const held = value;
|
|
104
|
-
if (typeof held.manifest !== 'object' || held.manifest === null)
|
|
105
|
-
return null;
|
|
106
|
-
if (!Array.isArray(held.contents))
|
|
107
|
-
return null;
|
|
108
|
-
const manifest = held.manifest;
|
|
109
|
-
if (manifest.scope !== 'room')
|
|
110
|
-
return null;
|
|
111
|
-
const at = readPosition(manifest);
|
|
112
|
-
if (typeof manifest.anchor !== 'string' || manifest.anchor.length === 0 || at === null)
|
|
113
|
-
return null;
|
|
114
|
-
if (typeof manifest.room_handle !== 'string' || manifest.room_handle.length === 0)
|
|
115
|
-
return null;
|
|
116
|
-
if (!Array.isArray(manifest.files))
|
|
117
|
-
return null;
|
|
118
|
-
const files = [];
|
|
119
|
-
for (const entry of manifest.files) {
|
|
120
|
-
const file = parseFile(entry, mode);
|
|
121
|
-
if (file === null)
|
|
122
|
-
return null;
|
|
123
|
-
files.push(file);
|
|
124
|
-
}
|
|
125
|
-
const contents = [];
|
|
126
|
-
for (const entry of held.contents) {
|
|
127
|
-
if (typeof entry !== 'object' || entry === null)
|
|
128
|
-
return null;
|
|
129
|
-
const content = entry;
|
|
130
|
-
if (typeof content.path !== 'string' || typeof content.content !== 'string')
|
|
131
|
-
return null;
|
|
132
|
-
contents.push({ path: content.path, content: content.content });
|
|
133
|
-
}
|
|
134
|
-
return { anchor: manifest.anchor, ...at, files, contents };
|
|
135
|
-
}
|
|
136
|
-
function parseCut(value) {
|
|
137
|
-
if (value === undefined)
|
|
138
|
-
return undefined;
|
|
139
|
-
if (typeof value !== 'object' || value === null)
|
|
140
|
-
return null;
|
|
141
|
-
const { position, log_epoch: logEpoch } = value;
|
|
142
|
-
if (typeof position !== 'string' || typeof logEpoch !== 'string')
|
|
143
|
-
return null;
|
|
144
|
-
return { position, log_epoch: logEpoch };
|
|
145
|
-
}
|
|
146
|
-
function parseCursor(value) {
|
|
147
|
-
if (typeof value !== 'object' || value === null)
|
|
148
|
-
return null;
|
|
149
|
-
const { room, path, cut } = value;
|
|
150
|
-
if (typeof room !== 'string' || (path !== null && typeof path !== 'string'))
|
|
151
|
-
return null;
|
|
152
|
-
const parsed = parseCut(cut);
|
|
153
|
-
if (parsed === null)
|
|
154
|
-
return null;
|
|
155
|
-
return { room, path, ...(parsed === undefined ? {} : { cut: parsed }) };
|
|
156
|
-
}
|
|
157
|
-
export function parseEnvelope(body) {
|
|
158
|
-
if (typeof body !== 'object' || body === null)
|
|
159
|
-
return null;
|
|
160
|
-
if (!('scopes' in body) || !Array.isArray(body.scopes))
|
|
161
|
-
return null;
|
|
162
|
-
const scopes = [];
|
|
163
|
-
for (const entry of body.scopes) {
|
|
164
|
-
const scope = parseScope(entry, 'credential');
|
|
165
|
-
if (scope === null)
|
|
166
|
-
return null;
|
|
167
|
-
scopes.push(scope);
|
|
168
|
-
}
|
|
169
|
-
if (!('next' in body) || body.next === undefined)
|
|
170
|
-
return { scopes };
|
|
171
|
-
const next = parseCursor(body.next);
|
|
172
|
-
return next === null ? null : { scopes, next };
|
|
173
|
-
}
|
|
174
|
-
export function parseSiteBootstrap(body) {
|
|
175
|
-
return parseScope(body, 'site');
|
|
176
|
-
}
|
|
177
|
-
export function siteBootstrapNext(body) {
|
|
178
|
-
if (typeof body !== 'object' || body === null || !('next' in body))
|
|
179
|
-
return null;
|
|
180
|
-
return typeof body.next === 'string' && body.next.length > 0 ? body.next : null;
|
|
181
|
-
}
|
|
182
|
-
export function siteBootstrapOffset(body) {
|
|
183
|
-
if (typeof body !== 'object' || body === null || !('offset' in body))
|
|
184
|
-
return null;
|
|
185
|
-
return Number.isSafeInteger(body.offset) && body.offset > 0
|
|
186
|
-
? body.offset
|
|
187
|
-
: null;
|
|
188
|
-
}
|
|
189
|
-
function parseChange(value, mode) {
|
|
190
|
-
if (typeof value !== 'object' || value === null)
|
|
191
|
-
return null;
|
|
192
|
-
const held = value;
|
|
193
|
-
if (typeof held.path !== 'string')
|
|
194
|
-
return null;
|
|
195
|
-
if (held.removed === true)
|
|
196
|
-
return { path: held.path, removed: true };
|
|
197
|
-
const head = headChange(held);
|
|
198
|
-
const binary = binaryFileOf(held);
|
|
199
|
-
if (head === null || binary === null)
|
|
200
|
-
return null;
|
|
201
|
-
if (binary !== undefined) {
|
|
202
|
-
if (mode === 'credential' && typeof held.revision !== 'string')
|
|
203
|
-
return null;
|
|
204
|
-
const revision = typeof held.revision === 'string' ? held.revision : binary.sha256;
|
|
205
|
-
return { path: held.path, binary, revision, version: revision, ...headed(head) };
|
|
206
|
-
}
|
|
207
|
-
if (mode === 'site') {
|
|
208
|
-
if (typeof held.content !== 'string' || typeof held.sha256 !== 'string')
|
|
209
|
-
return null;
|
|
210
|
-
return {
|
|
211
|
-
path: held.path,
|
|
212
|
-
content: held.content,
|
|
213
|
-
revision: undefined,
|
|
214
|
-
version: held.sha256,
|
|
215
|
-
...headed(head),
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
if (typeof held.content === 'string' && typeof held.revision === 'string') {
|
|
219
|
-
return {
|
|
220
|
-
path: held.path,
|
|
221
|
-
content: held.content,
|
|
222
|
-
revision: held.revision,
|
|
223
|
-
version: held.revision,
|
|
224
|
-
...headed(head),
|
|
225
|
-
};
|
|
226
|
-
}
|
|
227
|
-
return null;
|
|
228
|
-
}
|
|
229
|
-
export function parseEnumeration(body, mode) {
|
|
230
|
-
if (typeof body !== 'object' || body === null)
|
|
231
|
-
return null;
|
|
232
|
-
if (!('authorities' in body) || !Array.isArray(body.authorities))
|
|
233
|
-
return null;
|
|
234
|
-
const authorities = [];
|
|
235
|
-
for (const entry of body.authorities) {
|
|
236
|
-
if (typeof entry !== 'object' || entry === null)
|
|
237
|
-
return null;
|
|
238
|
-
const held = entry;
|
|
239
|
-
const at = readPosition(held);
|
|
240
|
-
if (typeof held.authority !== 'string' || at === null)
|
|
241
|
-
return null;
|
|
242
|
-
if (!Array.isArray(held.changes))
|
|
243
|
-
return null;
|
|
244
|
-
const changes = [];
|
|
245
|
-
for (const change of held.changes) {
|
|
246
|
-
const mapped = parseChange(change, mode);
|
|
247
|
-
if (mapped === null)
|
|
248
|
-
return null;
|
|
249
|
-
changes.push(mapped);
|
|
250
|
-
}
|
|
251
|
-
const next = held.next === undefined ? undefined : readPage(held.next);
|
|
252
|
-
if (next === null)
|
|
253
|
-
return null;
|
|
254
|
-
authorities.push({
|
|
255
|
-
authority: held.authority,
|
|
256
|
-
...at,
|
|
257
|
-
changes,
|
|
258
|
-
...(next === undefined ? {} : { next }),
|
|
259
|
-
});
|
|
260
|
-
}
|
|
261
|
-
return { authorities };
|
|
262
|
-
}
|
|
263
|
-
function readPage(held) {
|
|
264
|
-
if (typeof held !== 'object' || held === null)
|
|
265
|
-
return null;
|
|
266
|
-
const { after, through, read } = held;
|
|
267
|
-
if (typeof after !== 'string' || !DECIMAL.test(after))
|
|
268
|
-
return null;
|
|
269
|
-
if (typeof through !== 'string' || !DECIMAL.test(through))
|
|
270
|
-
return null;
|
|
271
|
-
if (typeof read !== 'number' || !Number.isSafeInteger(read) || read < 0)
|
|
272
|
-
return null;
|
|
273
|
-
return { after, through, read };
|
|
274
|
-
}
|
|
275
|
-
function advances(asked, next) {
|
|
276
|
-
const moved = BigInt(next.through) - BigInt(asked.through);
|
|
277
|
-
return moved > 0n || (moved === 0n && next.after === asked.after && next.read > asked.read);
|
|
278
|
-
}
|
|
279
|
-
export async function wholeView(first, more) {
|
|
280
|
-
const changes = new Map(first.changes.map((change) => [change.path, change]));
|
|
281
|
-
let view = first;
|
|
282
|
-
while (view.next !== undefined) {
|
|
283
|
-
const asked = view.next;
|
|
284
|
-
const page = await more(asked);
|
|
285
|
-
if ('kind' in page)
|
|
286
|
-
return page;
|
|
287
|
-
if (page.position !== asked.through ||
|
|
288
|
-
page.logEpoch !== first.logEpoch ||
|
|
289
|
-
(page.next !== undefined && !advances(asked, page.next))) {
|
|
290
|
-
return { kind: 'transport-uncertainty' };
|
|
291
|
-
}
|
|
292
|
-
for (const change of page.changes) {
|
|
293
|
-
changes.delete(change.path);
|
|
294
|
-
changes.set(change.path, change);
|
|
295
|
-
}
|
|
296
|
-
view = page;
|
|
297
|
-
}
|
|
184
|
+
export function modelScope(room) {
|
|
298
185
|
return {
|
|
299
|
-
|
|
300
|
-
position:
|
|
301
|
-
logEpoch:
|
|
302
|
-
|
|
186
|
+
anchor: room.anchor,
|
|
187
|
+
position: room.position,
|
|
188
|
+
logEpoch: room.logEpoch,
|
|
189
|
+
files: room.models.files,
|
|
190
|
+
contents: room.models.contents,
|
|
303
191
|
};
|
|
304
192
|
}
|
|
305
|
-
export function
|
|
306
|
-
const
|
|
307
|
-
const
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
contents.delete(change.path);
|
|
311
|
-
if ('removed' in change)
|
|
312
|
-
continue;
|
|
313
|
-
files.set(change.path, {
|
|
314
|
-
path: change.path,
|
|
315
|
-
revision: change.revision,
|
|
316
|
-
version: change.version,
|
|
317
|
-
...headed(change.head),
|
|
318
|
-
...('binary' in change ? { binary: change.binary } : {}),
|
|
319
|
-
});
|
|
320
|
-
if ('content' in change)
|
|
321
|
-
contents.set(change.path, change.content);
|
|
193
|
+
export function* bootstrapping(scope) {
|
|
194
|
+
const contents = new Map();
|
|
195
|
+
for (const entry of scope.contents) {
|
|
196
|
+
contents.set(entry.path, entry.content);
|
|
197
|
+
yield ROW_WEIGHT;
|
|
322
198
|
}
|
|
323
|
-
|
|
324
|
-
...scope,
|
|
325
|
-
position: view.position,
|
|
326
|
-
logEpoch: view.logEpoch,
|
|
327
|
-
files: [...files.values()],
|
|
328
|
-
contents: [...contents].map(([path, content]) => ({ path, content })),
|
|
329
|
-
};
|
|
330
|
-
}
|
|
331
|
-
export function matchesScope(scope, tracked) {
|
|
332
|
-
return scope.anchor === tracked.authority;
|
|
333
|
-
}
|
|
334
|
-
export function bootstrapOf(scope) {
|
|
335
|
-
const contents = new Map(scope.contents.map((entry) => [entry.path, entry.content]));
|
|
336
|
-
const documents = {};
|
|
337
|
-
const revisions = {};
|
|
338
|
-
const changes = {};
|
|
339
|
-
const binaryFiles = {};
|
|
199
|
+
const answer = answering();
|
|
340
200
|
for (const file of scope.files) {
|
|
341
|
-
|
|
342
|
-
|
|
201
|
+
yield ROW_WEIGHT;
|
|
202
|
+
if (file.space !== undefined)
|
|
203
|
+
continue;
|
|
343
204
|
if (file.head !== undefined)
|
|
344
|
-
changes
|
|
205
|
+
answer.changes.set(file.path, file.head);
|
|
345
206
|
const content = contents.get(file.path);
|
|
346
207
|
if (file.binary !== undefined)
|
|
347
|
-
binaryFiles
|
|
208
|
+
answer.binaryFiles.set(file.path, file.binary);
|
|
348
209
|
else if (content !== undefined)
|
|
349
|
-
documents
|
|
210
|
+
answer.documents.set(file.path, content);
|
|
211
|
+
if (file.binary === undefined && file.facts !== undefined)
|
|
212
|
+
answer.facts.set(file.path, file.facts);
|
|
213
|
+
if (file.revision !== undefined)
|
|
214
|
+
revised(answer, file.path, file.revision);
|
|
350
215
|
}
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
revisions,
|
|
356
|
-
changes,
|
|
357
|
-
binaryFiles,
|
|
358
|
-
};
|
|
216
|
+
for (const folder of scope.folders ?? [])
|
|
217
|
+
folded(answer, folder, false);
|
|
218
|
+
const { removals: _removals, folderRemovals: _folderRemovals, ...page } = yield* answered(answer);
|
|
219
|
+
return { kind: 'bootstrap', roomVersion: roomVersion(scope), ...page };
|
|
359
220
|
}
|
|
360
221
|
export function schemaOf(scope, schema) {
|
|
361
222
|
const file = scope.files.find((entry) => entry.path === schema);
|
|
@@ -364,40 +225,10 @@ export function schemaOf(scope, schema) {
|
|
|
364
225
|
const content = scope.contents.find((entry) => entry.path === schema);
|
|
365
226
|
return content === undefined
|
|
366
227
|
? null
|
|
367
|
-
: {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
if (roomVersion(view) === fromRoomVersion)
|
|
374
|
-
return { kind: 'still-current' };
|
|
375
|
-
const documents = {};
|
|
376
|
-
const revisions = {};
|
|
377
|
-
const changes = {};
|
|
378
|
-
const binaryFiles = {};
|
|
379
|
-
const removals = [];
|
|
380
|
-
for (const change of view.changes) {
|
|
381
|
-
if ('removed' in change) {
|
|
382
|
-
removals.push(change.path);
|
|
383
|
-
continue;
|
|
384
|
-
}
|
|
385
|
-
if ('content' in change)
|
|
386
|
-
documents[change.path] = change.content;
|
|
387
|
-
else
|
|
388
|
-
binaryFiles[change.path] = change.binary;
|
|
389
|
-
if (change.revision !== undefined)
|
|
390
|
-
revisions[change.path] = change.revision;
|
|
391
|
-
if (change.head !== undefined)
|
|
392
|
-
changes[change.path] = change.head;
|
|
393
|
-
}
|
|
394
|
-
return {
|
|
395
|
-
kind: 'net-advancement',
|
|
396
|
-
roomVersion: roomVersion(view),
|
|
397
|
-
documents,
|
|
398
|
-
revisions,
|
|
399
|
-
changes,
|
|
400
|
-
binaryFiles,
|
|
401
|
-
removals: removals.sort(),
|
|
402
|
-
};
|
|
228
|
+
: {
|
|
229
|
+
schema: content.content,
|
|
230
|
+
version: file.version,
|
|
231
|
+
revision: file.revision ?? null,
|
|
232
|
+
...(file.space === undefined ? {} : { space: file.space }),
|
|
233
|
+
};
|
|
403
234
|
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -2,8 +2,5 @@ import type { AdapterFailure, DiscoverResult, ProviderRefusal, ScopedRefusal } f
|
|
|
2
2
|
export declare function doorRefusal(body: unknown): ProviderRefusal | null;
|
|
3
3
|
export declare function scopedRefusal(locator: string, scope: ScopedRefusal['scope'], refusal: ProviderRefusal): ScopedRefusal;
|
|
4
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
|
-
kind: 'beyond-horizon';
|
|
7
|
-
} | null;
|
|
8
5
|
export declare function discoveryFailure(status: number, body: unknown): DiscoverResult | null;
|
|
9
6
|
//# sourceMappingURL=refusal.d.ts.map
|
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,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,
|
|
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
|
@@ -39,11 +39,6 @@ export function classifyDoor(status, body, locator) {
|
|
|
39
39
|
return scopedRefusal(locator, failure.scope, failure.refusal);
|
|
40
40
|
return failure;
|
|
41
41
|
}
|
|
42
|
-
export function classifyRead(status, body, locator) {
|
|
43
|
-
if (doorRefusal(body)?.code === 'expired')
|
|
44
|
-
return { kind: 'beyond-horizon' };
|
|
45
|
-
return classifyDoor(status, body, locator);
|
|
46
|
-
}
|
|
47
42
|
export function discoveryFailure(status, body) {
|
|
48
43
|
const failure = doorFailure(status, body);
|
|
49
44
|
if (failure === null)
|
|
@@ -0,0 +1,7 @@
|
|
|
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 CHAT_TYPE = "chat";
|
|
4
|
+
export declare const CHAT_MESSAGE_TYPE = "chat-message";
|
|
5
|
+
export declare const HOUSE_NAMEABLE_ROOM_TYPES: string[];
|
|
6
|
+
export declare const HOUSE_ROOM_TYPES: string;
|
|
7
|
+
//# 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":"AAGA,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,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,iBAAiB,iBAAiB,CAAC;AAEhD,eAAO,MAAM,yBAAyB,UAAiC,CAAC;AAyBxE,eAAO,MAAM,gBAAgB,QA2FjB,CAAC"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import { APP_REFERENCE_PATTERN } from './app-reference.js';
|
|
2
|
+
import { HOUSE_MODEL_TYPES } from './house-model.js';
|
|
3
|
+
export const INBOX_CHANNEL_KINDS = [
|
|
4
|
+
'telegram-bot',
|
|
5
|
+
'telegram-business',
|
|
6
|
+
'whatsapp',
|
|
7
|
+
'messenger',
|
|
8
|
+
'instagram',
|
|
9
|
+
'viber',
|
|
10
|
+
'tiktok',
|
|
11
|
+
];
|
|
12
|
+
export const CHAT_TYPE = 'chat';
|
|
13
|
+
export const CHAT_MESSAGE_TYPE = 'chat-message';
|
|
14
|
+
export const HOUSE_NAMEABLE_ROOM_TYPES = [CHAT_TYPE, CHAT_MESSAGE_TYPE];
|
|
15
|
+
const WAYFINDING_MAP_TYPE = 'wayfinding-map';
|
|
16
|
+
const WAYFINDING_TICKET_TYPE = 'wayfinding-ticket';
|
|
17
|
+
const WAYFINDING_MAP_SECTIONS = [
|
|
18
|
+
'Destination',
|
|
19
|
+
'Notes',
|
|
20
|
+
'Decisions so far',
|
|
21
|
+
'Not yet specified',
|
|
22
|
+
'Out of scope',
|
|
23
|
+
];
|
|
24
|
+
const IDENTITY = "{ type: string, pattern: '^\\S+$' }";
|
|
25
|
+
const AGENT = [' agent: { type: string, format: uuid }', ' name: { type: string }'];
|
|
26
|
+
const ASSIGNEE = [
|
|
27
|
+
' type: object',
|
|
28
|
+
' properties:',
|
|
29
|
+
' user: { type: string, format: uuid }',
|
|
30
|
+
...AGENT,
|
|
31
|
+
];
|
|
32
|
+
export const HOUSE_ROOM_TYPES = [
|
|
33
|
+
`${CHAT_TYPE}:`,
|
|
34
|
+
' properties:',
|
|
35
|
+
' inbox: { type: string, format: uuid }',
|
|
36
|
+
` channel: { enum: [${INBOX_CHANNEL_KINDS.join(', ')}] }`,
|
|
37
|
+
` chat: ${IDENTITY}`,
|
|
38
|
+
' customer:',
|
|
39
|
+
' type: object',
|
|
40
|
+
' properties:',
|
|
41
|
+
' name: { type: string }',
|
|
42
|
+
` username: ${IDENTITY}`,
|
|
43
|
+
` phone: ${IDENTITY}`,
|
|
44
|
+
' assignee:',
|
|
45
|
+
...ASSIGNEE,
|
|
46
|
+
' return_to:',
|
|
47
|
+
' type: object',
|
|
48
|
+
' properties:',
|
|
49
|
+
...AGENT,
|
|
50
|
+
' required: [chat, customer]',
|
|
51
|
+
`${CHAT_MESSAGE_TYPE}:`,
|
|
52
|
+
' properties:',
|
|
53
|
+
' direction: { enum: [in, out] }',
|
|
54
|
+
' sender:',
|
|
55
|
+
' type: object',
|
|
56
|
+
' properties:',
|
|
57
|
+
' name: { type: string }',
|
|
58
|
+
` username: ${IDENTITY}`,
|
|
59
|
+
' sent_at: { type: string, format: date-time }',
|
|
60
|
+
` channel_message: ${IDENTITY}`,
|
|
61
|
+
' labelled: { const: true }',
|
|
62
|
+
' reactions:',
|
|
63
|
+
' type: array',
|
|
64
|
+
' items:',
|
|
65
|
+
' type: object',
|
|
66
|
+
' properties:',
|
|
67
|
+
' reaction: { type: string, minLength: 1 }',
|
|
68
|
+
' sender:',
|
|
69
|
+
' type: object',
|
|
70
|
+
' properties:',
|
|
71
|
+
` id: ${IDENTITY}`,
|
|
72
|
+
' name: { type: string }',
|
|
73
|
+
` username: ${IDENTITY}`,
|
|
74
|
+
' count: { type: integer, minimum: 1 }',
|
|
75
|
+
' required: [reaction]',
|
|
76
|
+
` post: ${IDENTITY}`,
|
|
77
|
+
' assignee:',
|
|
78
|
+
...ASSIGNEE,
|
|
79
|
+
' sent_outside: { const: true }',
|
|
80
|
+
' template:',
|
|
81
|
+
' type: object',
|
|
82
|
+
' properties:',
|
|
83
|
+
' name: { type: string, minLength: 1 }',
|
|
84
|
+
' language: { type: string, minLength: 1 }',
|
|
85
|
+
' required: [name, language]',
|
|
86
|
+
' values:',
|
|
87
|
+
' type: object',
|
|
88
|
+
' additionalProperties: { type: string }',
|
|
89
|
+
' withheld: { const: true }',
|
|
90
|
+
' required: [direction]',
|
|
91
|
+
' if: { properties: { direction: { const: in } } }',
|
|
92
|
+
' then: { required: [sent_at] }',
|
|
93
|
+
`${WAYFINDING_MAP_TYPE}:`,
|
|
94
|
+
' properties:',
|
|
95
|
+
' title: { type: string }',
|
|
96
|
+
' required: [title]',
|
|
97
|
+
' sections:',
|
|
98
|
+
...WAYFINDING_MAP_SECTIONS.map((name) => ` ${name}: { kind: text, required: true }`),
|
|
99
|
+
`${WAYFINDING_TICKET_TYPE}:`,
|
|
100
|
+
' properties:',
|
|
101
|
+
' title: { type: string }',
|
|
102
|
+
' kind: { enum: [research, prototype, grilling, task] }',
|
|
103
|
+
' status: { enum: [open, in-progress, done, out-of-scope] }',
|
|
104
|
+
` map: { type: string, reference: ${WAYFINDING_MAP_TYPE} }`,
|
|
105
|
+
` blocked_by: { type: array, items: { type: string, reference: ${WAYFINDING_TICKET_TYPE} } }`,
|
|
106
|
+
' assignee:',
|
|
107
|
+
...ASSIGNEE,
|
|
108
|
+
' conversation: { type: string, format: uuid }',
|
|
109
|
+
` app: { type: string, pattern: '${APP_REFERENCE_PATTERN.source}' }`,
|
|
110
|
+
' required: [title, kind, status, map, blocked_by]',
|
|
111
|
+
' sections:',
|
|
112
|
+
' Question: { kind: text }',
|
|
113
|
+
' Answer: { kind: text }',
|
|
114
|
+
' allOf:',
|
|
115
|
+
' - if: { properties: { status: { enum: [in-progress, done, out-of-scope] } }, required: [status] }',
|
|
116
|
+
' then: { required: [assignee] }',
|
|
117
|
+
' else: { properties: { assignee: false } }',
|
|
118
|
+
' - if: { properties: { assignee: { required: [agent] } }, required: [assignee] }',
|
|
119
|
+
' else: { properties: { conversation: false } }',
|
|
120
|
+
' - if: { properties: { status: { enum: [done, out-of-scope] } }, required: [status] }',
|
|
121
|
+
' then: { sections: { Answer: { kind: text, required: true } } }',
|
|
122
|
+
HOUSE_MODEL_TYPES,
|
|
123
|
+
].join('\n');
|
package/dist/search.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SearchAnswer, SearchAsk } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseTransport } from './transport.js';
|
|
4
|
+
export declare function houseSearch(transport: Pick<HouseTransport, 'door'>, tracked: readonly TrackedAuthority[], request: SearchAsk): Promise<SearchAnswer>;
|
|
5
|
+
//# sourceMappingURL=search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"search.d.ts","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAa,MAAM,wBAAwB,CAAC;AACjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,OAAO,EAAkB,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAsBrE,wBAAsB,WAAW,CAC/B,SAAS,EAAE,IAAI,CAAC,cAAc,EAAE,MAAM,CAAC,EACvC,OAAO,EAAE,SAAS,gBAAgB,EAAE,EACpC,OAAO,EAAE,SAAS,GACjB,OAAO,CAAC,YAAY,CAAC,CAoBvB"}
|