@agentshouse/mdruntime-adapter 0.1.0-c7d05e09c73b7 → 0.1.0-c7edf402e20a3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/actions.d.ts +6 -5
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +25 -322
- package/dist/adapter.d.ts +1 -0
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +278 -233
- 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/authored-path.d.ts +11 -0
- package/dist/authored-path.d.ts.map +1 -0
- package/dist/authored-path.js +35 -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 +24 -14
- package/dist/discovery.d.ts.map +1 -1
- package/dist/discovery.js +98 -53
- 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 +682 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +397 -0
- package/dist/index.d.ts +12 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -0
- package/dist/model.d.ts +5 -5
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +33 -43
- package/dist/read.d.ts +61 -46
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +176 -272
- package/dist/refusal.d.ts +3 -8
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +10 -14
- package/dist/room-types.d.ts +5 -0
- package/dist/room-types.d.ts.map +1 -0
- package/dist/room-types.js +120 -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 +1 -1
- package/dist/site.d.ts.map +1 -1
- package/dist/site.js +122 -106
- 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 +15 -13
- package/dist/stream.d.ts.map +1 -1
- package/dist/stream.js +279 -152
- package/dist/transport.d.ts +89 -24
- package/dist/transport.d.ts.map +1 -1
- package/dist/transport.js +55 -9
- package/dist/upload.d.ts +12 -0
- package/dist/upload.d.ts.map +1 -0
- package/dist/upload.js +63 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/write.d.ts +20 -10
- package/dist/write.d.ts.map +1 -1
- package/dist/write.js +161 -63
- package/package.json +9 -6
- package/AGENTS.md +0 -253
- package/dist/gather.d.ts +0 -4
- package/dist/gather.d.ts.map +0 -1
- package/dist/gather.js +0 -45
- package/dist/links.d.ts +0 -20
- package/dist/links.d.ts.map +0 -1
- package/dist/links.js +0 -104
package/dist/discovery.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { declaredActions
|
|
1
|
+
import { declaredActions } from './actions.js';
|
|
2
|
+
import { SITES_SUBMISSIONS_CREATE } 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',
|
|
@@ -14,9 +14,9 @@ const BOUND_KEYS = [
|
|
|
14
14
|
'max_upload_bytes',
|
|
15
15
|
'max_prefixes',
|
|
16
16
|
'change_retention_seconds',
|
|
17
|
-
'operation_retention_seconds',
|
|
18
17
|
];
|
|
19
|
-
const OPERATION_KEYS = ['
|
|
18
|
+
const OPERATION_KEYS = ['write', 'erase'];
|
|
19
|
+
const ACCESS_LEVELS = ['search', 'open', 'keep'];
|
|
20
20
|
function stringList(value) {
|
|
21
21
|
if (!Array.isArray(value))
|
|
22
22
|
return null;
|
|
@@ -33,18 +33,18 @@ function parseBounds(value) {
|
|
|
33
33
|
return null;
|
|
34
34
|
bounds[key] = amount;
|
|
35
35
|
}
|
|
36
|
+
const moves = held.max_move_documents;
|
|
37
|
+
if (moves !== undefined) {
|
|
38
|
+
if (typeof moves !== 'number' || !Number.isFinite(moves))
|
|
39
|
+
return null;
|
|
40
|
+
bounds.max_move_documents = moves;
|
|
41
|
+
}
|
|
36
42
|
return bounds;
|
|
37
43
|
}
|
|
38
|
-
function
|
|
44
|
+
function parseTypedSelection(value) {
|
|
39
45
|
if (value === undefined)
|
|
40
46
|
return null;
|
|
41
|
-
|
|
42
|
-
return undefined;
|
|
43
|
-
const held = value;
|
|
44
|
-
const paths = stringList(held.paths);
|
|
45
|
-
if (typeof held.root !== 'string' || held.root.length === 0 || paths === null)
|
|
46
|
-
return undefined;
|
|
47
|
-
return { root: held.root, paths };
|
|
47
|
+
return stringList(value) ?? undefined;
|
|
48
48
|
}
|
|
49
49
|
function parseMember(value) {
|
|
50
50
|
if (typeof value !== 'object' || value === null)
|
|
@@ -81,10 +81,17 @@ function parseAuthority(value) {
|
|
|
81
81
|
return null;
|
|
82
82
|
}
|
|
83
83
|
const at = readPosition(held);
|
|
84
|
-
const
|
|
84
|
+
const typedSelection = parseTypedSelection(held.typed_selection);
|
|
85
85
|
const protectedPaths = stringList(held.protected_paths);
|
|
86
|
+
const writtenHomes = stringList(held.written_homes);
|
|
86
87
|
const operations = parseOperations(held.operations);
|
|
87
|
-
|
|
88
|
+
const level = ACCESS_LEVELS.find((one) => one === held.level);
|
|
89
|
+
if (at === null ||
|
|
90
|
+
typedSelection === undefined ||
|
|
91
|
+
protectedPaths === null ||
|
|
92
|
+
writtenHomes === null ||
|
|
93
|
+
level === undefined ||
|
|
94
|
+
operations === null)
|
|
88
95
|
return null;
|
|
89
96
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
|
|
90
97
|
return null;
|
|
@@ -95,13 +102,56 @@ function parseAuthority(value) {
|
|
|
95
102
|
roomHandle: held.room_handle,
|
|
96
103
|
name: held.name,
|
|
97
104
|
schema: held.model_root,
|
|
98
|
-
|
|
105
|
+
typedSelection,
|
|
99
106
|
managedReplication: held.managed_replication,
|
|
100
107
|
protectedPaths,
|
|
108
|
+
writtenHomes,
|
|
109
|
+
level,
|
|
101
110
|
operations,
|
|
102
111
|
...at,
|
|
103
112
|
};
|
|
104
113
|
}
|
|
114
|
+
function parseAuthorities(value) {
|
|
115
|
+
if (!Array.isArray(value))
|
|
116
|
+
return null;
|
|
117
|
+
const authorities = [];
|
|
118
|
+
for (const entry of value) {
|
|
119
|
+
const authority = parseAuthority(entry);
|
|
120
|
+
if (authority === null)
|
|
121
|
+
return null;
|
|
122
|
+
authorities.push(authority);
|
|
123
|
+
}
|
|
124
|
+
return authorities;
|
|
125
|
+
}
|
|
126
|
+
export function foldedAuthorities(authorities) {
|
|
127
|
+
const shapes = [];
|
|
128
|
+
const known = new Map();
|
|
129
|
+
const rooms = authorities.map(({ room_ref, room_handle, name, position, ...shape }) => {
|
|
130
|
+
const key = JSON.stringify(shape);
|
|
131
|
+
let held = known.get(key);
|
|
132
|
+
if (held === undefined) {
|
|
133
|
+
held = shapes.push(shape) - 1;
|
|
134
|
+
known.set(key, held);
|
|
135
|
+
}
|
|
136
|
+
return { room_ref, room_handle, name, position, shape: held };
|
|
137
|
+
});
|
|
138
|
+
return { shapes, rooms };
|
|
139
|
+
}
|
|
140
|
+
function unfolded(shapes, rooms) {
|
|
141
|
+
if (!Array.isArray(shapes) || !Array.isArray(rooms))
|
|
142
|
+
return null;
|
|
143
|
+
const authorities = [];
|
|
144
|
+
for (const room of rooms) {
|
|
145
|
+
if (typeof room !== 'object' || room === null)
|
|
146
|
+
return null;
|
|
147
|
+
const { shape, ...own } = room;
|
|
148
|
+
const held = typeof shape === 'number' ? shapes[shape] : undefined;
|
|
149
|
+
if (typeof held !== 'object' || held === null)
|
|
150
|
+
return null;
|
|
151
|
+
authorities.push({ ...held, ...own });
|
|
152
|
+
}
|
|
153
|
+
return authorities;
|
|
154
|
+
}
|
|
105
155
|
export function parseDiscovery(body) {
|
|
106
156
|
if (typeof body !== 'object' || body === null)
|
|
107
157
|
return null;
|
|
@@ -117,16 +167,19 @@ export function parseDiscovery(body) {
|
|
|
117
167
|
new Set(actions).size !== actions.length ||
|
|
118
168
|
actions.some((name) => name.length === 0))
|
|
119
169
|
return null;
|
|
120
|
-
|
|
170
|
+
const authorities = parseAuthorities(unfolded(held.shapes, held.rooms));
|
|
171
|
+
return authorities === null ? null : { member, bounds, authorities, actions };
|
|
172
|
+
}
|
|
173
|
+
export function parseAuthorityChange(body) {
|
|
174
|
+
if (typeof body !== 'object' || body === null)
|
|
121
175
|
return null;
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
}
|
|
129
|
-
return { member, bounds, authorities, actions };
|
|
176
|
+
const held = body;
|
|
177
|
+
const member = parseMember(held.member);
|
|
178
|
+
const authorities = parseAuthorities(held.authorities);
|
|
179
|
+
const left = stringList(held.left);
|
|
180
|
+
if (member === null || authorities === null || left === null)
|
|
181
|
+
return null;
|
|
182
|
+
return { member, authorities, left };
|
|
130
183
|
}
|
|
131
184
|
function parseSiteAuthority(value) {
|
|
132
185
|
if (typeof value !== 'object' || value === null)
|
|
@@ -174,25 +227,18 @@ export function siteTracked(document) {
|
|
|
174
227
|
authority: authority.roomRef,
|
|
175
228
|
handle: authority.roomHandle,
|
|
176
229
|
schema: authority.schema,
|
|
177
|
-
|
|
178
|
-
schemas: [authority.schema],
|
|
230
|
+
typedSelection: null,
|
|
179
231
|
position: authority.position,
|
|
180
232
|
logEpoch: authority.logEpoch,
|
|
181
233
|
}));
|
|
182
234
|
}
|
|
183
|
-
function schemasOf(authority) {
|
|
184
|
-
return authority.houseModel === null
|
|
185
|
-
? [authority.schema]
|
|
186
|
-
: [authority.schema, authority.houseModel.root];
|
|
187
|
-
}
|
|
188
235
|
export function trackedFrom(document) {
|
|
189
236
|
return document.authorities.map((authority) => ({
|
|
190
237
|
locator: authority.roomRef,
|
|
191
238
|
authority: authority.roomRef,
|
|
192
239
|
handle: authority.roomHandle,
|
|
193
240
|
schema: authority.schema,
|
|
194
|
-
|
|
195
|
-
schemas: schemasOf(authority),
|
|
241
|
+
typedSelection: authority.typedSelection,
|
|
196
242
|
position: authority.position,
|
|
197
243
|
logEpoch: authority.logEpoch,
|
|
198
244
|
}));
|
|
@@ -204,34 +250,30 @@ export function providerLimits(bounds) {
|
|
|
204
250
|
{ name: 'change-documents', value: bounds.max_batch_documents },
|
|
205
251
|
{ name: 'path-length', value: bounds.max_path_length },
|
|
206
252
|
{ name: 'path-depth', value: bounds.max_path_depth },
|
|
253
|
+
...(bounds.max_move_documents === undefined
|
|
254
|
+
? []
|
|
255
|
+
: [{ name: 'move-documents', value: bounds.max_move_documents }]),
|
|
207
256
|
{ name: 'write-rate' },
|
|
208
|
-
{ name: '
|
|
257
|
+
{ name: 'storage-limit' },
|
|
209
258
|
];
|
|
210
259
|
}
|
|
211
260
|
export function declaredRetention(bounds) {
|
|
212
261
|
return {
|
|
213
262
|
history: { kind: 'no-declared-time-bound' },
|
|
214
|
-
outcome: bounds.operation_retention_seconds,
|
|
215
263
|
refreshHorizon: bounds.change_retention_seconds,
|
|
216
264
|
};
|
|
217
265
|
}
|
|
218
|
-
export function capabilities(
|
|
219
|
-
|
|
266
|
+
export function capabilities(actions) {
|
|
267
|
+
return [{ name: PROVIDER_ACTIONS, actions: declaredActions(actions) }];
|
|
268
|
+
}
|
|
269
|
+
export function siteCapabilities() {
|
|
220
270
|
return [
|
|
221
271
|
{
|
|
222
272
|
name: PROVIDER_ACTIONS,
|
|
223
|
-
actions:
|
|
224
|
-
...(house === undefined
|
|
225
|
-
? {}
|
|
226
|
-
: { conversationAgents: houseConversationAgents(house.roomRef) }),
|
|
273
|
+
actions: [{ name: SITES_SUBMISSIONS_CREATE, inputShape: {}, resultKind: 'house' }],
|
|
227
274
|
},
|
|
228
275
|
];
|
|
229
276
|
}
|
|
230
|
-
export function siteCapabilities() {
|
|
231
|
-
return [
|
|
232
|
-
{ name: PROVIDER_ACTIONS, actions: [{ name: 'submit', inputShape: {}, resultKind: 'house' }] },
|
|
233
|
-
];
|
|
234
|
-
}
|
|
235
277
|
export function discoveredRoom(authority) {
|
|
236
278
|
const locator = authority.roomRef;
|
|
237
279
|
return {
|
|
@@ -240,16 +282,19 @@ export function discoveredRoom(authority) {
|
|
|
240
282
|
handle: authority.roomHandle,
|
|
241
283
|
roomVersion: roomVersion(authority),
|
|
242
284
|
operations: {
|
|
243
|
-
read: [...authority.operations.read],
|
|
244
|
-
sync: [...authority.operations.sync],
|
|
245
285
|
write: [...authority.operations.write],
|
|
246
|
-
|
|
286
|
+
erase: [...authority.operations.erase],
|
|
287
|
+
},
|
|
288
|
+
replica: {
|
|
289
|
+
selection: locator,
|
|
290
|
+
admission: authority.managedReplication,
|
|
291
|
+
offline: authority.level === 'open' ? 'locked' : 'open',
|
|
247
292
|
},
|
|
248
|
-
|
|
249
|
-
...(authority.houseModel === null
|
|
293
|
+
...(authority.typedSelection === null
|
|
250
294
|
? {}
|
|
251
|
-
: { typedSelection: { roots: [...authority.
|
|
252
|
-
providerOwnedPaths: [...authority.protectedPaths,
|
|
295
|
+
: { typedSelection: { roots: [...authority.typedSelection] } }),
|
|
296
|
+
providerOwnedPaths: [...authority.protectedPaths, authority.schema],
|
|
297
|
+
authoredPaths: [...authority.writtenHomes],
|
|
253
298
|
};
|
|
254
299
|
}
|
|
255
300
|
export function mapDiscovery(document, rooms, declared) {
|
|
@@ -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/list';
|
|
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
|
+
}
|