@agentshouse/mdruntime-adapter 0.1.0-cf9ab9b7cbbca → 0.1.0-cfd2dc1938a2c
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 -66
- package/dist/actions.d.ts.map +1 -1
- package/dist/actions.js +23 -340
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js +245 -366
- 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 +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 +682 -0
- package/dist/house-model.d.ts.map +1 -0
- package/dist/house-model.js +397 -0
- package/dist/index.d.ts +12 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -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 +57 -64
- package/dist/read.d.ts.map +1 -1
- package/dist/read.js +154 -318
- package/dist/refusal.d.ts +1 -3
- package/dist/refusal.d.ts.map +1 -1
- package/dist/refusal.js +4 -5
- 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.map +1 -1
- package/dist/site.js +102 -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 +261 -421
- package/dist/transport.d.ts +66 -43
- 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 +108 -80
- package/package.json +8 -4
- package/AGENTS.md +0 -299
- 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/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',
|
|
@@ -13,11 +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 = ['
|
|
18
|
+
const OPERATION_KEYS = ['write', 'erase'];
|
|
19
|
+
const ACCESS_LEVELS = ['search', 'open', 'keep'];
|
|
21
20
|
function stringList(value) {
|
|
22
21
|
if (!Array.isArray(value))
|
|
23
22
|
return null;
|
|
@@ -34,18 +33,18 @@ function parseBounds(value) {
|
|
|
34
33
|
return null;
|
|
35
34
|
bounds[key] = amount;
|
|
36
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
|
+
}
|
|
37
42
|
return bounds;
|
|
38
43
|
}
|
|
39
|
-
function
|
|
44
|
+
function parseTypedSelection(value) {
|
|
40
45
|
if (value === undefined)
|
|
41
46
|
return null;
|
|
42
|
-
|
|
43
|
-
return undefined;
|
|
44
|
-
const held = value;
|
|
45
|
-
const paths = stringList(held.paths);
|
|
46
|
-
if (typeof held.root !== 'string' || held.root.length === 0 || paths === null)
|
|
47
|
-
return undefined;
|
|
48
|
-
return { root: held.root, paths };
|
|
47
|
+
return stringList(value) ?? undefined;
|
|
49
48
|
}
|
|
50
49
|
function parseMember(value) {
|
|
51
50
|
if (typeof value !== 'object' || value === null)
|
|
@@ -82,10 +81,15 @@ function parseAuthority(value) {
|
|
|
82
81
|
return null;
|
|
83
82
|
}
|
|
84
83
|
const at = readPosition(held);
|
|
85
|
-
const
|
|
84
|
+
const typedSelection = parseTypedSelection(held.typed_selection);
|
|
86
85
|
const protectedPaths = stringList(held.protected_paths);
|
|
87
86
|
const operations = parseOperations(held.operations);
|
|
88
|
-
|
|
87
|
+
const level = ACCESS_LEVELS.find((one) => one === held.level);
|
|
88
|
+
if (at === null ||
|
|
89
|
+
typedSelection === undefined ||
|
|
90
|
+
protectedPaths === null ||
|
|
91
|
+
level === undefined ||
|
|
92
|
+
operations === null)
|
|
89
93
|
return null;
|
|
90
94
|
if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
|
|
91
95
|
return null;
|
|
@@ -96,13 +100,55 @@ function parseAuthority(value) {
|
|
|
96
100
|
roomHandle: held.room_handle,
|
|
97
101
|
name: held.name,
|
|
98
102
|
schema: held.model_root,
|
|
99
|
-
|
|
103
|
+
typedSelection,
|
|
100
104
|
managedReplication: held.managed_replication,
|
|
101
105
|
protectedPaths,
|
|
106
|
+
level,
|
|
102
107
|
operations,
|
|
103
108
|
...at,
|
|
104
109
|
};
|
|
105
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
|
+
}
|
|
106
152
|
export function parseDiscovery(body) {
|
|
107
153
|
if (typeof body !== 'object' || body === null)
|
|
108
154
|
return null;
|
|
@@ -118,16 +164,19 @@ export function parseDiscovery(body) {
|
|
|
118
164
|
new Set(actions).size !== actions.length ||
|
|
119
165
|
actions.some((name) => name.length === 0))
|
|
120
166
|
return null;
|
|
121
|
-
|
|
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)
|
|
122
172
|
return null;
|
|
123
|
-
const
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
}
|
|
130
|
-
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 };
|
|
131
180
|
}
|
|
132
181
|
function parseSiteAuthority(value) {
|
|
133
182
|
if (typeof value !== 'object' || value === null)
|
|
@@ -175,25 +224,18 @@ export function siteTracked(document) {
|
|
|
175
224
|
authority: authority.roomRef,
|
|
176
225
|
handle: authority.roomHandle,
|
|
177
226
|
schema: authority.schema,
|
|
178
|
-
|
|
179
|
-
schemas: [authority.schema],
|
|
227
|
+
typedSelection: null,
|
|
180
228
|
position: authority.position,
|
|
181
229
|
logEpoch: authority.logEpoch,
|
|
182
230
|
}));
|
|
183
231
|
}
|
|
184
|
-
function schemasOf(authority) {
|
|
185
|
-
return authority.houseModel === null
|
|
186
|
-
? [authority.schema]
|
|
187
|
-
: [authority.schema, authority.houseModel.root];
|
|
188
|
-
}
|
|
189
232
|
export function trackedFrom(document) {
|
|
190
233
|
return document.authorities.map((authority) => ({
|
|
191
234
|
locator: authority.roomRef,
|
|
192
235
|
authority: authority.roomRef,
|
|
193
236
|
handle: authority.roomHandle,
|
|
194
237
|
schema: authority.schema,
|
|
195
|
-
|
|
196
|
-
schemas: schemasOf(authority),
|
|
238
|
+
typedSelection: authority.typedSelection,
|
|
197
239
|
position: authority.position,
|
|
198
240
|
logEpoch: authority.logEpoch,
|
|
199
241
|
}));
|
|
@@ -205,34 +247,27 @@ export function providerLimits(bounds) {
|
|
|
205
247
|
{ name: 'change-documents', value: bounds.max_batch_documents },
|
|
206
248
|
{ name: 'path-length', value: bounds.max_path_length },
|
|
207
249
|
{ name: 'path-depth', value: bounds.max_path_depth },
|
|
250
|
+
...(bounds.max_move_documents === undefined
|
|
251
|
+
? []
|
|
252
|
+
: [{ name: 'move-documents', value: bounds.max_move_documents }]),
|
|
208
253
|
{ name: 'write-rate' },
|
|
209
|
-
{ name: '
|
|
254
|
+
{ name: 'storage-limit' },
|
|
210
255
|
];
|
|
211
256
|
}
|
|
212
257
|
export function declaredRetention(bounds) {
|
|
213
258
|
return {
|
|
214
259
|
history: { kind: 'no-declared-time-bound' },
|
|
215
|
-
outcome: bounds.operation_retention_seconds,
|
|
216
260
|
refreshHorizon: bounds.change_retention_seconds,
|
|
217
261
|
};
|
|
218
262
|
}
|
|
219
|
-
export function capabilities(
|
|
220
|
-
|
|
221
|
-
return [
|
|
222
|
-
{
|
|
223
|
-
name: PROVIDER_ACTIONS,
|
|
224
|
-
actions: declaredActions(document.actions),
|
|
225
|
-
...(house === undefined
|
|
226
|
-
? {}
|
|
227
|
-
: { conversationAgents: houseConversationAgents(house.roomRef) }),
|
|
228
|
-
},
|
|
229
|
-
];
|
|
263
|
+
export function capabilities(actions) {
|
|
264
|
+
return [{ name: PROVIDER_ACTIONS, actions: declaredActions(actions) }];
|
|
230
265
|
}
|
|
231
266
|
export function siteCapabilities() {
|
|
232
267
|
return [
|
|
233
268
|
{
|
|
234
269
|
name: PROVIDER_ACTIONS,
|
|
235
|
-
actions: [{ name:
|
|
270
|
+
actions: [{ name: SITES_SUBMISSIONS_CREATE, inputShape: {}, resultKind: 'house' }],
|
|
236
271
|
},
|
|
237
272
|
];
|
|
238
273
|
}
|
|
@@ -244,16 +279,18 @@ export function discoveredRoom(authority) {
|
|
|
244
279
|
handle: authority.roomHandle,
|
|
245
280
|
roomVersion: roomVersion(authority),
|
|
246
281
|
operations: {
|
|
247
|
-
read: [...authority.operations.read],
|
|
248
|
-
sync: [...authority.operations.sync],
|
|
249
282
|
write: [...authority.operations.write],
|
|
250
|
-
|
|
283
|
+
erase: [...authority.operations.erase],
|
|
284
|
+
},
|
|
285
|
+
replica: {
|
|
286
|
+
selection: locator,
|
|
287
|
+
admission: authority.managedReplication,
|
|
288
|
+
offline: authority.level === 'open' ? 'locked' : 'open',
|
|
251
289
|
},
|
|
252
|
-
|
|
253
|
-
...(authority.houseModel === null
|
|
290
|
+
...(authority.typedSelection === null
|
|
254
291
|
? {}
|
|
255
|
-
: { typedSelection: { roots: [...authority.
|
|
256
|
-
providerOwnedPaths: [...authority.protectedPaths,
|
|
292
|
+
: { typedSelection: { roots: [...authority.typedSelection] } }),
|
|
293
|
+
providerOwnedPaths: [...authority.protectedPaths, authority.schema],
|
|
257
294
|
};
|
|
258
295
|
}
|
|
259
296
|
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
|
+
}
|