@agentshouse/mdruntime-adapter 0.1.0-c82b9ec2b727a → 0.1.0-c82ec25e72f2f
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/dist/actions.d.ts +4 -59
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +7 -289
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +170 -355
- package/dist/chunks.d.ts +28 -0
- package/dist/chunks.d.ts.map +1 -0
- package/dist/chunks.js +206 -0
- package/dist/discovery.d.ts +20 -8
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +65 -33
- 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 +640 -1
- package/dist/house-model.d.ts.map +1 -1
- package/dist/house-model.js +361 -415
- package/dist/index.d.ts +8 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -3
- package/dist/model.d.ts +5 -4
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +28 -23
- package/dist/part.d.ts +11 -12
- package/dist/part.d.ts.map +1 -1
- package/dist/part.js +63 -55
- package/dist/read.d.ts +21 -58
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +61 -222
- package/dist/refusal.d.ts +0 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +0 -5
- package/dist/room-stream.d.ts +20 -0
- package/dist/room-stream.d.ts.map +1 -0
- package/dist/room-stream.js +57 -0
- package/dist/room-types.d.ts +3 -3
- package/dist/room-types.d.ts.map +1 -1
- package/dist/room-types.js +8 -9
- 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 +78 -165
- 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 +229 -422
- package/dist/transport.d.ts +50 -36
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +55 -11
- package/dist/upload.d.ts.map +1 -1
- package/dist/upload.js +2 -2
- package/dist/write.d.ts +6 -1
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +18 -25
- package/package.json +2 -2
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -35
package/dist/chunks.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { type AdapterFailure, type BootstrapPart } from '@agentshouse/mdruntime';
|
|
2
|
+
import type { TrackedAuthority } from './discovery.js';
|
|
3
|
+
import { type HouseModels, type HouseScope } from './read.js';
|
|
4
|
+
import { type HouseDoor } from './transport.js';
|
|
5
|
+
import { type LogPosition } from './version.js';
|
|
6
|
+
export type ChunkAddress = {
|
|
7
|
+
readonly url: string;
|
|
8
|
+
readonly bytes: number;
|
|
9
|
+
};
|
|
10
|
+
export type ChunkedRoom = LogPosition & {
|
|
11
|
+
readonly anchor: string;
|
|
12
|
+
readonly chunks: ReadonlyMap<string, ChunkAddress>;
|
|
13
|
+
readonly parts: readonly BootstrapPart[];
|
|
14
|
+
readonly names: ReadonlyMap<string, string>;
|
|
15
|
+
readonly models: HouseModels;
|
|
16
|
+
};
|
|
17
|
+
export type Listed = ChunkedRoom | {
|
|
18
|
+
readonly kind: 'not-ready';
|
|
19
|
+
} | AdapterFailure;
|
|
20
|
+
export declare function partId(logEpoch: string, hash: string): string;
|
|
21
|
+
export declare function chunkLister(transport: HouseDoor, most: () => number): {
|
|
22
|
+
askAll: (entries: readonly TrackedAuthority[]) => void;
|
|
23
|
+
list: (entry: TrackedAuthority) => Promise<Listed>;
|
|
24
|
+
renew(entry: TrackedAuthority, installing: readonly TrackedAuthority[]): Promise<Listed>;
|
|
25
|
+
forget(): void;
|
|
26
|
+
};
|
|
27
|
+
export declare function chunkScope(body: ReadableStream<Uint8Array>, room: ChunkedRoom, arriving: ((bytes: number) => void) | undefined): Promise<HouseScope | null>;
|
|
28
|
+
//# sourceMappingURL=chunks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"chunks.d.ts","sourceRoot":"","sources":["../src/chunks.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,KAAK,cAAc,EAAE,KAAK,aAAa,EAAE,MAAM,wBAAwB,CAAC;AACpG,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACvD,OAAO,EAKL,KAAK,WAAW,EAChB,KAAK,UAAU,EAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAgB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE9D,MAAM,MAAM,YAAY,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AAE5E,MAAM,MAAM,WAAW,GAAG,WAAW,GAAG;IACtC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;IACnD,QAAQ,CAAC,KAAK,EAAE,SAAS,aAAa,EAAE,CAAC;IACzC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC5C,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GAAG,cAAc,CAAC;AAsCnF,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE7D;AAuCD,wBAAgB,WAAW,CAAC,SAAS,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,MAAM;sBAwCzC,SAAS,gBAAgB,EAAE;kBAU/B,gBAAgB,KAAG,OAAO,CAAC,MAAM,CAAC;iBASxC,gBAAgB,cAAc,SAAS,gBAAgB,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;;EAc3F;AAuCD,wBAAsB,UAAU,CAC9B,IAAI,EAAE,cAAc,CAAC,UAAU,CAAC,EAChC,IAAI,EAAE,WAAW,EACjB,QAAQ,EAAE,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC,GAAG,SAAS,GAC9C,OAAO,CAAC,UAAU,GAAG,IAAI,CAAC,CAgC5B"}
|
package/dist/chunks.js
ADDED
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import { paced, ROW_WEIGHT } from '@agentshouse/mdruntime';
|
|
2
|
+
import { authorityRoot, parseFile, } from './read.js';
|
|
3
|
+
import { classifyDoor } from './refusal.js';
|
|
4
|
+
import { houseDoorRoute } from './transport.js';
|
|
5
|
+
import { readPosition } from './version.js';
|
|
6
|
+
function authorKey(author) {
|
|
7
|
+
for (const kind of ['user', 'site', 'inbox']) {
|
|
8
|
+
if (typeof author[kind] === 'string')
|
|
9
|
+
return `${kind}:${author[kind]}`;
|
|
10
|
+
}
|
|
11
|
+
const { app, release, function: named } = author;
|
|
12
|
+
return typeof app === 'string' && typeof release === 'string' && typeof named === 'string'
|
|
13
|
+
? `app:${app}:${release}:${named}`
|
|
14
|
+
: null;
|
|
15
|
+
}
|
|
16
|
+
function namesOf(authors) {
|
|
17
|
+
if (!Array.isArray(authors))
|
|
18
|
+
return null;
|
|
19
|
+
const names = new Map();
|
|
20
|
+
for (const author of authors) {
|
|
21
|
+
const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
|
|
22
|
+
if (key === null || typeof author.name !== 'string')
|
|
23
|
+
return null;
|
|
24
|
+
names.set(key, author.name);
|
|
25
|
+
}
|
|
26
|
+
return names;
|
|
27
|
+
}
|
|
28
|
+
function modelsOf(models) {
|
|
29
|
+
if (!Array.isArray(models))
|
|
30
|
+
return null;
|
|
31
|
+
const files = [];
|
|
32
|
+
const contents = [];
|
|
33
|
+
for (const entry of models) {
|
|
34
|
+
const file = parseFile(entry, 'credential');
|
|
35
|
+
if (file === null || typeof entry.content !== 'string')
|
|
36
|
+
return null;
|
|
37
|
+
files.push(file);
|
|
38
|
+
contents.push({ path: file.path, content: entry.content });
|
|
39
|
+
}
|
|
40
|
+
return { files, contents };
|
|
41
|
+
}
|
|
42
|
+
export function partId(logEpoch, hash) {
|
|
43
|
+
return `${logEpoch}:${hash}`;
|
|
44
|
+
}
|
|
45
|
+
function chunkedRoom(room) {
|
|
46
|
+
const at = readPosition(room);
|
|
47
|
+
const names = namesOf(room.authors);
|
|
48
|
+
const models = modelsOf(room.models);
|
|
49
|
+
if (at === null || names === null || models === null || !Array.isArray(room.chunks))
|
|
50
|
+
return null;
|
|
51
|
+
const chunks = new Map();
|
|
52
|
+
const parts = [];
|
|
53
|
+
for (const chunk of room.chunks) {
|
|
54
|
+
const { hash, bytes, download } = chunk;
|
|
55
|
+
if (typeof hash !== 'string' || typeof bytes !== 'number' || typeof download !== 'string')
|
|
56
|
+
return null;
|
|
57
|
+
const id = partId(at.logEpoch, hash);
|
|
58
|
+
chunks.set(id, { url: download, bytes });
|
|
59
|
+
parts.push({ id, bytes });
|
|
60
|
+
}
|
|
61
|
+
return { anchor: room.room_ref, ...at, chunks, parts, names, models };
|
|
62
|
+
}
|
|
63
|
+
function listedRooms(answer) {
|
|
64
|
+
const rooms = answer.body?.rooms;
|
|
65
|
+
if (!Array.isArray(rooms))
|
|
66
|
+
return null;
|
|
67
|
+
const listed = new Map();
|
|
68
|
+
for (const room of rooms) {
|
|
69
|
+
if (typeof room !== 'object' || room === null || typeof room.room_ref !== 'string')
|
|
70
|
+
return null;
|
|
71
|
+
if (room.ready === false) {
|
|
72
|
+
listed.set(room.room_ref, { kind: 'not-ready' });
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const chunked = room.ready === true ? chunkedRoom(room) : null;
|
|
76
|
+
if (chunked === null)
|
|
77
|
+
return null;
|
|
78
|
+
listed.set(room.room_ref, chunked);
|
|
79
|
+
}
|
|
80
|
+
return listed;
|
|
81
|
+
}
|
|
82
|
+
export function chunkLister(transport, most) {
|
|
83
|
+
const asked = new Map();
|
|
84
|
+
function answered(entries, whole) {
|
|
85
|
+
const prefixes = whole ? ['/'] : entries.map((entry) => authorityRoot(entry.handle));
|
|
86
|
+
return transport.door(houseDoorRoute('room-chunks/list'), { prefixes }).then((answer) => {
|
|
87
|
+
const failure = classifyDoor(answer.status, answer.body, '');
|
|
88
|
+
if (failure !== null)
|
|
89
|
+
return failed(entries, failure);
|
|
90
|
+
const listed = listedRooms(answer);
|
|
91
|
+
return listed ?? failed(entries, { kind: 'transport-uncertainty' });
|
|
92
|
+
}, () => failed(entries, { kind: 'transport-uncertainty' }));
|
|
93
|
+
}
|
|
94
|
+
function failed(entries, failure) {
|
|
95
|
+
return new Map(entries.map((entry) => [
|
|
96
|
+
entry.authority,
|
|
97
|
+
failure.kind === 'room-not-readable' || failure.kind === 'scoped-refusal'
|
|
98
|
+
? { ...failure, locator: entry.locator }
|
|
99
|
+
: failure,
|
|
100
|
+
]));
|
|
101
|
+
}
|
|
102
|
+
function settled(entry, lists) {
|
|
103
|
+
return lists.then((listed) => listed.get(entry.authority) ?? { kind: 'room-not-readable', locator: entry.locator });
|
|
104
|
+
}
|
|
105
|
+
function askAll(entries) {
|
|
106
|
+
if (entries.length === 0)
|
|
107
|
+
return;
|
|
108
|
+
const lists = answered(entries, entries.length > most());
|
|
109
|
+
for (const entry of entries) {
|
|
110
|
+
const listed = settled(entry, lists);
|
|
111
|
+
listed.catch(() => { });
|
|
112
|
+
asked.set(entry.authority, { entry, listed });
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function list(entry) {
|
|
116
|
+
const held = asked.get(entry.authority);
|
|
117
|
+
asked.delete(entry.authority);
|
|
118
|
+
return held?.listed ?? settled(entry, answered([entry], false));
|
|
119
|
+
}
|
|
120
|
+
return {
|
|
121
|
+
askAll,
|
|
122
|
+
list,
|
|
123
|
+
renew(entry, installing) {
|
|
124
|
+
if (!asked.has(entry.authority)) {
|
|
125
|
+
const waiting = [...asked.values()].map((held) => held.entry);
|
|
126
|
+
const due = new Map([entry, ...installing, ...waiting].map((held) => [held.authority, held]));
|
|
127
|
+
askAll([...due.values()]);
|
|
128
|
+
}
|
|
129
|
+
return list(entry);
|
|
130
|
+
},
|
|
131
|
+
forget() {
|
|
132
|
+
asked.clear();
|
|
133
|
+
},
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function folderLine(entry) {
|
|
137
|
+
return typeof entry.folder === 'string' && Object.keys(entry).length === 1 ? entry.folder : null;
|
|
138
|
+
}
|
|
139
|
+
function chunkEntry(line, room, read) {
|
|
140
|
+
let entry;
|
|
141
|
+
try {
|
|
142
|
+
entry = JSON.parse(line);
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
return false;
|
|
146
|
+
}
|
|
147
|
+
if (typeof entry !== 'object' || entry === null)
|
|
148
|
+
return false;
|
|
149
|
+
const folder = folderLine(entry);
|
|
150
|
+
if (folder !== null) {
|
|
151
|
+
read.folders.push(folder);
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
const author = entry.author;
|
|
155
|
+
let named = entry;
|
|
156
|
+
if (author !== undefined) {
|
|
157
|
+
const key = typeof author === 'object' && author !== null ? authorKey(author) : null;
|
|
158
|
+
const name = key === null ? undefined : room.names.get(key);
|
|
159
|
+
if (name === undefined)
|
|
160
|
+
return false;
|
|
161
|
+
named = { ...entry, author: { ...author, name } };
|
|
162
|
+
}
|
|
163
|
+
const file = parseFile(named, 'credential');
|
|
164
|
+
if (file === null)
|
|
165
|
+
return false;
|
|
166
|
+
read.files.push(file);
|
|
167
|
+
if (typeof entry.content === 'string')
|
|
168
|
+
read.contents.push({ path: file.path, content: entry.content });
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
export async function chunkScope(body, room, arriving) {
|
|
172
|
+
const read = {
|
|
173
|
+
files: [],
|
|
174
|
+
contents: [],
|
|
175
|
+
folders: [],
|
|
176
|
+
};
|
|
177
|
+
const reader = body.getReader();
|
|
178
|
+
const decoder = new TextDecoder();
|
|
179
|
+
const pace = paced();
|
|
180
|
+
const unfinished = [];
|
|
181
|
+
let bytes = 0;
|
|
182
|
+
for (let chunk = await reader.read(); chunk.done !== true; chunk = await reader.read()) {
|
|
183
|
+
bytes += chunk.value.length;
|
|
184
|
+
arriving?.(bytes);
|
|
185
|
+
const text = decoder.decode(chunk.value, { stream: true });
|
|
186
|
+
let start = 0;
|
|
187
|
+
for (let end = text.indexOf('\n'); end !== -1; end = text.indexOf('\n', start)) {
|
|
188
|
+
const piece = text.slice(start, end);
|
|
189
|
+
const line = unfinished.length === 0 ? piece : unfinished.splice(0).join('') + piece;
|
|
190
|
+
start = end + 1;
|
|
191
|
+
if (line.length > 0 && !chunkEntry(line, room, read)) {
|
|
192
|
+
await reader.cancel();
|
|
193
|
+
return null;
|
|
194
|
+
}
|
|
195
|
+
const due = pace(line.length + ROW_WEIGHT);
|
|
196
|
+
if (due instanceof Promise)
|
|
197
|
+
await due;
|
|
198
|
+
}
|
|
199
|
+
if (start < text.length)
|
|
200
|
+
unfinished.push(text.slice(start));
|
|
201
|
+
}
|
|
202
|
+
const rest = unfinished.join('') + decoder.decode();
|
|
203
|
+
if (rest.length > 0 && !chunkEntry(rest, room, read))
|
|
204
|
+
return null;
|
|
205
|
+
return { anchor: room.anchor, position: room.position, logEpoch: room.logEpoch, ...read };
|
|
206
|
+
}
|
package/dist/discovery.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import type { Capability, DiscoveredRoom, Discovery, Member, ProviderLimit, Retention } from '@agentshouse/mdruntime';
|
|
2
2
|
import { type LogPosition } from './version.js';
|
|
3
3
|
export declare const PROVIDER_ACTIONS = "provider-actions";
|
|
4
|
-
export declare const DISCOVER_PREFIXES: readonly string[];
|
|
5
4
|
export type HouseBounds = {
|
|
6
5
|
max_authored_file_bytes: number;
|
|
7
6
|
max_batch_operations: number;
|
|
@@ -13,16 +12,14 @@ export type HouseBounds = {
|
|
|
13
12
|
max_inline_body_bytes: number;
|
|
14
13
|
max_upload_bytes: number;
|
|
15
14
|
max_prefixes: number;
|
|
16
|
-
max_held_files: number;
|
|
17
15
|
change_retention_seconds: number;
|
|
18
|
-
operation_retention_seconds: number;
|
|
19
16
|
max_move_documents?: number;
|
|
20
17
|
};
|
|
21
18
|
export type HouseOperations = {
|
|
22
19
|
write: readonly string[];
|
|
23
|
-
|
|
20
|
+
erase: readonly string[];
|
|
24
21
|
};
|
|
25
|
-
export type
|
|
22
|
+
export type HouseAccessLevel = 'search' | 'open' | 'keep';
|
|
26
23
|
export type HouseAuthority = LogPosition & {
|
|
27
24
|
roomRef: string;
|
|
28
25
|
roomHandle: string;
|
|
@@ -31,7 +28,7 @@ export type HouseAuthority = LogPosition & {
|
|
|
31
28
|
typedSelection: readonly string[] | null;
|
|
32
29
|
managedReplication: 'admitted' | 'unavailable';
|
|
33
30
|
protectedPaths: readonly string[];
|
|
34
|
-
|
|
31
|
+
level: HouseAccessLevel;
|
|
35
32
|
operations: HouseOperations;
|
|
36
33
|
};
|
|
37
34
|
export type HouseDiscoveryDocument = {
|
|
@@ -40,6 +37,11 @@ export type HouseDiscoveryDocument = {
|
|
|
40
37
|
authorities: readonly HouseAuthority[];
|
|
41
38
|
actions: readonly string[];
|
|
42
39
|
};
|
|
40
|
+
export type HouseAuthorityChange = {
|
|
41
|
+
member: Member;
|
|
42
|
+
authorities: readonly HouseAuthority[];
|
|
43
|
+
left: readonly string[];
|
|
44
|
+
};
|
|
43
45
|
export type TrackedAuthority = LogPosition & {
|
|
44
46
|
locator: string;
|
|
45
47
|
authority: string;
|
|
@@ -56,14 +58,24 @@ export type HouseSiteDiscovery = {
|
|
|
56
58
|
bounds: HouseBounds;
|
|
57
59
|
authorities: readonly HouseSiteAuthority[];
|
|
58
60
|
};
|
|
61
|
+
type RoomOwn = 'room_ref' | 'room_handle' | 'name' | 'position';
|
|
62
|
+
type Folded<A extends Record<RoomOwn, unknown>> = {
|
|
63
|
+
readonly shapes: readonly Omit<A, RoomOwn>[];
|
|
64
|
+
readonly rooms: readonly (Pick<A, RoomOwn> & {
|
|
65
|
+
readonly shape: number;
|
|
66
|
+
})[];
|
|
67
|
+
};
|
|
68
|
+
export declare function foldedAuthorities<A extends Record<RoomOwn, unknown>>(authorities: readonly A[]): Folded<A>;
|
|
59
69
|
export declare function parseDiscovery(body: unknown): HouseDiscoveryDocument | null;
|
|
70
|
+
export declare function parseAuthorityChange(body: unknown): HouseAuthorityChange | null;
|
|
60
71
|
export declare function parseSiteDiscovery(body: unknown): HouseSiteDiscovery | null;
|
|
61
72
|
export declare function siteTracked(document: HouseSiteDiscovery): TrackedAuthority[];
|
|
62
|
-
export declare function trackedFrom(document: HouseDiscoveryDocument): TrackedAuthority[];
|
|
73
|
+
export declare function trackedFrom(document: Pick<HouseDiscoveryDocument, 'authorities'>): TrackedAuthority[];
|
|
63
74
|
export declare function providerLimits(bounds: HouseBounds): readonly ProviderLimit[];
|
|
64
75
|
export declare function declaredRetention(bounds: HouseBounds): Retention;
|
|
65
|
-
export declare function capabilities(actions: HouseDiscoveryDocument['actions']
|
|
76
|
+
export declare function capabilities(actions: HouseDiscoveryDocument['actions']): readonly Capability[];
|
|
66
77
|
export declare function siteCapabilities(): readonly Capability[];
|
|
67
78
|
export declare function discoveredRoom(authority: HouseAuthority): DiscoveredRoom;
|
|
68
79
|
export declare function mapDiscovery(document: Pick<HouseDiscoveryDocument, 'bounds'>, rooms: readonly DiscoveredRoom[], declared: readonly Capability[]): Discovery;
|
|
80
|
+
export {};
|
|
69
81
|
//# sourceMappingURL=discovery.d.ts.map
|
package/dist/discovery.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"discovery.d.ts","sourceRoot":"","sources":["../src/discovery.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,UAAU,EACV,cAAc,EACd,SAAS,EACT,MAAM,EACN,aAAa,EACb,SAAS,EACV,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAA6B,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAE3E,eAAO,MAAM,gBAAgB,qBAAqB,CAAC;AAEnD,MAAM,MAAM,WAAW,GAAG;IACxB,uBAAuB,EAAE,MAAM,CAAC;IAChC,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,eAAe,EAAE,MAAM,CAAC;IACxB,qBAAqB,EAAE,MAAM,CAAC;IAC9B,gBAAgB,EAAE,MAAM,CAAC;IACzB,YAAY,EAAE,MAAM,CAAC;IACrB,wBAAwB,EAAE,MAAM,CAAC;IACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;CAC7B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC;AAEF,MAAM,MAAM,gBAAgB,GAAG,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAC;AAE1D,MAAM,MAAM,cAAc,GAAG,WAAW,GAAG;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,CAAC;IACb,MA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sBAAsB,EAAE,QAAQ,CAAC,EAChD,KAAK,EAAE,SAAS,cAAc,EAAE,EAChC,QAAQ,EAAE,SAAS,UAAU,EAAE,GAC9B,SAAS,CAQX"}
|
package/dist/discovery.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { declaredActions
|
|
1
|
+
import { declaredActions } from './actions.js';
|
|
2
|
+
import { SITE_SUBMISSION } from './transport.js';
|
|
2
3
|
import { readPosition, roomVersion } from './version.js';
|
|
3
4
|
export const PROVIDER_ACTIONS = 'provider-actions';
|
|
4
|
-
export const DISCOVER_PREFIXES = ['/'];
|
|
5
5
|
const BOUND_KEYS = [
|
|
6
6
|
'max_authored_file_bytes',
|
|
7
7
|
'max_batch_operations',
|
|
@@ -13,12 +13,10 @@ const BOUND_KEYS = [
|
|
|
13
13
|
'max_inline_body_bytes',
|
|
14
14
|
'max_upload_bytes',
|
|
15
15
|
'max_prefixes',
|
|
16
|
-
'max_held_files',
|
|
17
16
|
'change_retention_seconds',
|
|
18
|
-
'operation_retention_seconds',
|
|
19
17
|
];
|
|
20
|
-
const OPERATION_KEYS = ['write', '
|
|
21
|
-
const
|
|
18
|
+
const OPERATION_KEYS = ['write', 'erase'];
|
|
19
|
+
const ACCESS_LEVELS = ['search', 'open', 'keep'];
|
|
22
20
|
function stringList(value) {
|
|
23
21
|
if (!Array.isArray(value))
|
|
24
22
|
return null;
|
|
@@ -86,11 +84,11 @@ function parseAuthority(value) {
|
|
|
86
84
|
const typedSelection = parseTypedSelection(held.typed_selection);
|
|
87
85
|
const protectedPaths = stringList(held.protected_paths);
|
|
88
86
|
const operations = parseOperations(held.operations);
|
|
89
|
-
const
|
|
87
|
+
const level = ACCESS_LEVELS.find((one) => one === held.level);
|
|
90
88
|
if (at === null ||
|
|
91
89
|
typedSelection === undefined ||
|
|
92
90
|
protectedPaths === null ||
|
|
93
|
-
|
|
91
|
+
level === undefined ||
|
|
94
92
|
operations === null)
|
|
95
93
|
return null;
|
|
96
94
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
|
|
@@ -105,11 +103,52 @@ function parseAuthority(value) {
|
|
|
105
103
|
typedSelection,
|
|
106
104
|
managedReplication: held.managed_replication,
|
|
107
105
|
protectedPaths,
|
|
108
|
-
|
|
106
|
+
level,
|
|
109
107
|
operations,
|
|
110
108
|
...at,
|
|
111
109
|
};
|
|
112
110
|
}
|
|
111
|
+
function parseAuthorities(value) {
|
|
112
|
+
if (!Array.isArray(value))
|
|
113
|
+
return null;
|
|
114
|
+
const authorities = [];
|
|
115
|
+
for (const entry of value) {
|
|
116
|
+
const authority = parseAuthority(entry);
|
|
117
|
+
if (authority === null)
|
|
118
|
+
return null;
|
|
119
|
+
authorities.push(authority);
|
|
120
|
+
}
|
|
121
|
+
return authorities;
|
|
122
|
+
}
|
|
123
|
+
export function foldedAuthorities(authorities) {
|
|
124
|
+
const shapes = [];
|
|
125
|
+
const known = new Map();
|
|
126
|
+
const rooms = authorities.map(({ room_ref, room_handle, name, position, ...shape }) => {
|
|
127
|
+
const key = JSON.stringify(shape);
|
|
128
|
+
let held = known.get(key);
|
|
129
|
+
if (held === undefined) {
|
|
130
|
+
held = shapes.push(shape) - 1;
|
|
131
|
+
known.set(key, held);
|
|
132
|
+
}
|
|
133
|
+
return { room_ref, room_handle, name, position, shape: held };
|
|
134
|
+
});
|
|
135
|
+
return { shapes, rooms };
|
|
136
|
+
}
|
|
137
|
+
function unfolded(shapes, rooms) {
|
|
138
|
+
if (!Array.isArray(shapes) || !Array.isArray(rooms))
|
|
139
|
+
return null;
|
|
140
|
+
const authorities = [];
|
|
141
|
+
for (const room of rooms) {
|
|
142
|
+
if (typeof room !== 'object' || room === null)
|
|
143
|
+
return null;
|
|
144
|
+
const { shape, ...own } = room;
|
|
145
|
+
const held = typeof shape === 'number' ? shapes[shape] : undefined;
|
|
146
|
+
if (typeof held !== 'object' || held === null)
|
|
147
|
+
return null;
|
|
148
|
+
authorities.push({ ...held, ...own });
|
|
149
|
+
}
|
|
150
|
+
return authorities;
|
|
151
|
+
}
|
|
113
152
|
export function parseDiscovery(body) {
|
|
114
153
|
if (typeof body !== 'object' || body === null)
|
|
115
154
|
return null;
|
|
@@ -125,16 +164,19 @@ export function parseDiscovery(body) {
|
|
|
125
164
|
new Set(actions).size !== actions.length ||
|
|
126
165
|
actions.some((name) => name.length === 0))
|
|
127
166
|
return null;
|
|
128
|
-
|
|
167
|
+
const authorities = parseAuthorities(unfolded(held.shapes, held.rooms));
|
|
168
|
+
return authorities === null ? null : { member, bounds, authorities, actions };
|
|
169
|
+
}
|
|
170
|
+
export function parseAuthorityChange(body) {
|
|
171
|
+
if (typeof body !== 'object' || body === null)
|
|
129
172
|
return null;
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
}
|
|
137
|
-
return { member, bounds, authorities, actions };
|
|
173
|
+
const held = body;
|
|
174
|
+
const member = parseMember(held.member);
|
|
175
|
+
const authorities = parseAuthorities(held.authorities);
|
|
176
|
+
const left = stringList(held.left);
|
|
177
|
+
if (member === null || authorities === null || left === null)
|
|
178
|
+
return null;
|
|
179
|
+
return { member, authorities, left };
|
|
138
180
|
}
|
|
139
181
|
function parseSiteAuthority(value) {
|
|
140
182
|
if (typeof value !== 'object' || value === null)
|
|
@@ -215,27 +257,17 @@ export function providerLimits(bounds) {
|
|
|
215
257
|
export function declaredRetention(bounds) {
|
|
216
258
|
return {
|
|
217
259
|
history: { kind: 'no-declared-time-bound' },
|
|
218
|
-
outcome: bounds.operation_retention_seconds,
|
|
219
260
|
refreshHorizon: bounds.change_retention_seconds,
|
|
220
261
|
};
|
|
221
262
|
}
|
|
222
|
-
export function capabilities(actions
|
|
223
|
-
|
|
224
|
-
return [
|
|
225
|
-
{
|
|
226
|
-
name: PROVIDER_ACTIONS,
|
|
227
|
-
actions: declaredActions(actions),
|
|
228
|
-
...(house === undefined
|
|
229
|
-
? {}
|
|
230
|
-
: { conversationAgents: houseConversationAgents(house.authority) }),
|
|
231
|
-
},
|
|
232
|
-
];
|
|
263
|
+
export function capabilities(actions) {
|
|
264
|
+
return [{ name: PROVIDER_ACTIONS, actions: declaredActions(actions) }];
|
|
233
265
|
}
|
|
234
266
|
export function siteCapabilities() {
|
|
235
267
|
return [
|
|
236
268
|
{
|
|
237
269
|
name: PROVIDER_ACTIONS,
|
|
238
|
-
actions: [{ name:
|
|
270
|
+
actions: [{ name: SITE_SUBMISSION, inputShape: {}, resultKind: 'house' }],
|
|
239
271
|
},
|
|
240
272
|
];
|
|
241
273
|
}
|
|
@@ -248,12 +280,12 @@ export function discoveredRoom(authority) {
|
|
|
248
280
|
roomVersion: roomVersion(authority),
|
|
249
281
|
operations: {
|
|
250
282
|
write: [...authority.operations.write],
|
|
251
|
-
|
|
283
|
+
erase: [...authority.operations.erase],
|
|
252
284
|
},
|
|
253
285
|
replica: {
|
|
254
286
|
selection: locator,
|
|
255
287
|
admission: authority.managedReplication,
|
|
256
|
-
offline: authority.
|
|
288
|
+
offline: authority.level === 'open' ? 'locked' : 'open',
|
|
257
289
|
},
|
|
258
290
|
...(authority.typedSelection === null
|
|
259
291
|
? {}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AcceptedMessage, ActionResult, ConversationHistoryRequest } from '@agentshouse/mdruntime';
|
|
2
|
+
import { type HouseDoor } from './transport.js';
|
|
3
|
+
export declare const HISTORY_PAGE = 100;
|
|
4
|
+
type HistoryCursor = {
|
|
5
|
+
accepted_at: string;
|
|
6
|
+
message_id: string;
|
|
7
|
+
};
|
|
8
|
+
export declare function cursorPosition(cursor: HistoryCursor): string;
|
|
9
|
+
export declare function acceptedMessage(entry: unknown): AcceptedMessage | null;
|
|
10
|
+
export declare function houseHistory(transport: HouseDoor, request: ConversationHistoryRequest): Promise<ActionResult>;
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EAGZ,0BAA0B,EAC3B,MAAM,wBAAwB,CAAC;AAEhC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEhE,eAAO,MAAM,YAAY,MAAM,CAAC;AAIhC,KAAK,aAAa,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAAC;AAkBjE,wBAAgB,cAAc,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM,CAE5D;AAUD,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAUtE;AA8BD,wBAAsB,YAAY,CAChC,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,0BAA0B,GAClC,OAAO,CAAC,YAAY,CAAC,CAqBvB"}
|
package/dist/history.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { actionOutcome } from './actions.js';
|
|
2
|
+
import { houseDoorRoute } from './transport.js';
|
|
3
|
+
export const HISTORY_PAGE = 100;
|
|
4
|
+
const HISTORY = 'conversations/history';
|
|
5
|
+
function record(value) {
|
|
6
|
+
return typeof value === 'object' && value !== null ? value : {};
|
|
7
|
+
}
|
|
8
|
+
function text(value, name) {
|
|
9
|
+
const held = record(value)[name];
|
|
10
|
+
return typeof held === 'string' ? held : undefined;
|
|
11
|
+
}
|
|
12
|
+
function historyCursor(value) {
|
|
13
|
+
const acceptedAt = text(value, 'accepted_at');
|
|
14
|
+
const messageId = text(value, 'message_id');
|
|
15
|
+
if (acceptedAt === undefined || messageId === undefined)
|
|
16
|
+
return null;
|
|
17
|
+
return { accepted_at: acceptedAt, message_id: messageId };
|
|
18
|
+
}
|
|
19
|
+
export function cursorPosition(cursor) {
|
|
20
|
+
return JSON.stringify({ accepted_at: cursor.accepted_at, message_id: cursor.message_id });
|
|
21
|
+
}
|
|
22
|
+
function positionCursor(value) {
|
|
23
|
+
try {
|
|
24
|
+
return historyCursor(JSON.parse(value));
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
export function acceptedMessage(entry) {
|
|
31
|
+
const cursor = historyCursor(entry);
|
|
32
|
+
if (cursor === null)
|
|
33
|
+
return null;
|
|
34
|
+
return {
|
|
35
|
+
identity: cursor.message_id,
|
|
36
|
+
turn: text(entry, 'turn_id') ?? cursor.message_id,
|
|
37
|
+
position: cursorPosition(cursor),
|
|
38
|
+
text: text(entry, 'text') ?? '',
|
|
39
|
+
message: structuredClone(record(entry)),
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function historyPage(entry) {
|
|
43
|
+
const held = record(entry);
|
|
44
|
+
const conversation = text(held, 'conversation_id');
|
|
45
|
+
if (conversation === undefined || !Array.isArray(held.messages))
|
|
46
|
+
return null;
|
|
47
|
+
const messages = [];
|
|
48
|
+
for (const one of held.messages) {
|
|
49
|
+
const message = acceptedMessage(one);
|
|
50
|
+
if (message === null)
|
|
51
|
+
return null;
|
|
52
|
+
messages.push(message);
|
|
53
|
+
}
|
|
54
|
+
const next = held.next === null || held.next === undefined ? undefined : historyCursor(held.next);
|
|
55
|
+
if (next === null)
|
|
56
|
+
return null;
|
|
57
|
+
return { conversation, messages, ...(next === undefined ? {} : { next: cursorPosition(next) }) };
|
|
58
|
+
}
|
|
59
|
+
function historyAsks(request) {
|
|
60
|
+
const asks = [];
|
|
61
|
+
for (const { conversation, after } of request.conversations) {
|
|
62
|
+
const cursor = after === undefined ? undefined : positionCursor(after);
|
|
63
|
+
if (cursor === null)
|
|
64
|
+
return null;
|
|
65
|
+
asks.push({
|
|
66
|
+
conversation_id: conversation,
|
|
67
|
+
...(cursor === undefined ? {} : { after: cursor }),
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return asks;
|
|
71
|
+
}
|
|
72
|
+
export async function houseHistory(transport, request) {
|
|
73
|
+
const asks = historyAsks(request);
|
|
74
|
+
if (asks === null)
|
|
75
|
+
return { kind: 'rejected', code: 'invalid_request', fields: {}, retryable: false };
|
|
76
|
+
const asked = { conversations: asks, limit: HISTORY_PAGE };
|
|
77
|
+
const outcome = actionOutcome(await transport.door(houseDoorRoute(HISTORY), asked), HISTORY, asked);
|
|
78
|
+
if (outcome.kind !== 'action')
|
|
79
|
+
return outcome;
|
|
80
|
+
const answered = record(outcome.result).histories;
|
|
81
|
+
if (!Array.isArray(answered))
|
|
82
|
+
return { kind: 'transport-uncertainty' };
|
|
83
|
+
const histories = [];
|
|
84
|
+
for (const entry of answered) {
|
|
85
|
+
const page = historyPage(entry);
|
|
86
|
+
if (page === null)
|
|
87
|
+
return { kind: 'transport-uncertainty' };
|
|
88
|
+
histories.push(page);
|
|
89
|
+
}
|
|
90
|
+
const result = { histories };
|
|
91
|
+
return { kind: 'action', result };
|
|
92
|
+
}
|