@agentshouse/mdruntime-adapter 0.1.0-cfd03209dcd82 → 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.
Files changed (78) hide show
  1. package/README.md +2 -2
  2. package/dist/actions.d.ts +6 -46
  3. package/dist/actions.d.ts.map +1 -1
  4. package/dist/actions.js +23 -342
  5. package/dist/adapter.d.ts +1 -0
  6. package/dist/adapter.d.ts.map +1 -1
  7. package/dist/adapter.js +250 -278
  8. package/dist/app-reference.d.ts +2 -0
  9. package/dist/app-reference.d.ts.map +1 -0
  10. package/dist/app-reference.js +2 -0
  11. package/dist/authored-path.d.ts +11 -0
  12. package/dist/authored-path.d.ts.map +1 -0
  13. package/dist/authored-path.js +35 -0
  14. package/dist/chunks.d.ts +38 -0
  15. package/dist/chunks.d.ts.map +1 -0
  16. package/dist/chunks.js +247 -0
  17. package/dist/crockford.d.ts +4 -0
  18. package/dist/crockford.d.ts.map +1 -0
  19. package/dist/crockford.js +3 -0
  20. package/dist/discovery.d.ts +23 -14
  21. package/dist/discovery.d.ts.map +1 -1
  22. package/dist/discovery.js +92 -54
  23. package/dist/history.d.ts +12 -0
  24. package/dist/history.d.ts.map +1 -0
  25. package/dist/history.js +92 -0
  26. package/dist/house-model.d.ts +682 -0
  27. package/dist/house-model.d.ts.map +1 -0
  28. package/dist/house-model.js +397 -0
  29. package/dist/index.d.ts +12 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +11 -1
  32. package/dist/model.d.ts +5 -5
  33. package/dist/model.d.ts.map +1 -1
  34. package/dist/model.js +33 -43
  35. package/dist/read.d.ts +59 -44
  36. package/dist/read.d.ts.map +1 -1
  37. package/dist/read.js +158 -236
  38. package/dist/refusal.d.ts +1 -3
  39. package/dist/refusal.d.ts.map +1 -1
  40. package/dist/refusal.js +6 -6
  41. package/dist/room-types.d.ts +5 -0
  42. package/dist/room-types.d.ts.map +1 -0
  43. package/dist/room-types.js +120 -0
  44. package/dist/search.d.ts +5 -0
  45. package/dist/search.d.ts.map +1 -0
  46. package/dist/search.js +47 -0
  47. package/dist/site.d.ts +1 -1
  48. package/dist/site.d.ts.map +1 -1
  49. package/dist/site.js +110 -131
  50. package/dist/space-schema.d.ts +7 -0
  51. package/dist/space-schema.d.ts.map +1 -0
  52. package/dist/space-schema.js +18 -0
  53. package/dist/stream.d.ts +15 -13
  54. package/dist/stream.d.ts.map +1 -1
  55. package/dist/stream.js +279 -159
  56. package/dist/transport.d.ts +81 -25
  57. package/dist/transport.d.ts.map +1 -1
  58. package/dist/transport.js +54 -11
  59. package/dist/upload.d.ts +12 -0
  60. package/dist/upload.d.ts.map +1 -0
  61. package/dist/upload.js +63 -0
  62. package/dist/version.d.ts +1 -0
  63. package/dist/version.d.ts.map +1 -1
  64. package/dist/version.js +1 -1
  65. package/dist/write.d.ts +18 -2
  66. package/dist/write.d.ts.map +1 -1
  67. package/dist/write.js +108 -76
  68. package/package.json +8 -4
  69. package/AGENTS.md +0 -299
  70. package/dist/gather.d.ts +0 -4
  71. package/dist/gather.d.ts.map +0 -1
  72. package/dist/gather.js +0 -45
  73. package/dist/handed.d.ts +0 -15
  74. package/dist/handed.d.ts.map +0 -1
  75. package/dist/handed.js +0 -38
  76. package/dist/referrer.d.ts +0 -7
  77. package/dist/referrer.d.ts.map +0 -1
  78. package/dist/referrer.js +0 -35
package/dist/discovery.js CHANGED
@@ -1,7 +1,7 @@
1
- import { declaredActions, houseConversationAgents, SITE_SUBMIT } from './actions.js';
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 = ['read', 'sync', 'write', 'delete'];
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 parseHouseModel(value) {
44
+ function parseTypedSelection(value) {
39
45
  if (value === undefined)
40
46
  return null;
41
- if (typeof value !== 'object' || value === null)
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,15 @@ function parseAuthority(value) {
81
81
  return null;
82
82
  }
83
83
  const at = readPosition(held);
84
- const houseModel = parseHouseModel(held.house_model);
84
+ const typedSelection = parseTypedSelection(held.typed_selection);
85
85
  const protectedPaths = stringList(held.protected_paths);
86
86
  const operations = parseOperations(held.operations);
87
- if (at === null || houseModel === undefined || protectedPaths === null || operations === null)
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)
88
93
  return null;
89
94
  if (typeof held.room_ref !== 'string' || held.room_ref.length === 0)
90
95
  return null;
@@ -95,13 +100,55 @@ function parseAuthority(value) {
95
100
  roomHandle: held.room_handle,
96
101
  name: held.name,
97
102
  schema: held.model_root,
98
- houseModel,
103
+ typedSelection,
99
104
  managedReplication: held.managed_replication,
100
105
  protectedPaths,
106
+ level,
101
107
  operations,
102
108
  ...at,
103
109
  };
104
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
+ }
105
152
  export function parseDiscovery(body) {
106
153
  if (typeof body !== 'object' || body === null)
107
154
  return null;
@@ -117,16 +164,19 @@ export function parseDiscovery(body) {
117
164
  new Set(actions).size !== actions.length ||
118
165
  actions.some((name) => name.length === 0))
119
166
  return null;
120
- if (!Array.isArray(held.authorities))
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)
121
172
  return null;
122
- const authorities = [];
123
- for (const entry of held.authorities) {
124
- const authority = parseAuthority(entry);
125
- if (authority === null)
126
- return null;
127
- authorities.push(authority);
128
- }
129
- 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 };
130
180
  }
131
181
  function parseSiteAuthority(value) {
132
182
  if (typeof value !== 'object' || value === null)
@@ -174,25 +224,18 @@ export function siteTracked(document) {
174
224
  authority: authority.roomRef,
175
225
  handle: authority.roomHandle,
176
226
  schema: authority.schema,
177
- houseModel: null,
178
- schemas: [authority.schema],
227
+ typedSelection: null,
179
228
  position: authority.position,
180
229
  logEpoch: authority.logEpoch,
181
230
  }));
182
231
  }
183
- function schemasOf(authority) {
184
- return authority.houseModel === null
185
- ? [authority.schema]
186
- : [authority.schema, authority.houseModel.root];
187
- }
188
232
  export function trackedFrom(document) {
189
233
  return document.authorities.map((authority) => ({
190
234
  locator: authority.roomRef,
191
235
  authority: authority.roomRef,
192
236
  handle: authority.roomHandle,
193
237
  schema: authority.schema,
194
- houseModel: authority.houseModel,
195
- schemas: schemasOf(authority),
238
+ typedSelection: authority.typedSelection,
196
239
  position: authority.position,
197
240
  logEpoch: authority.logEpoch,
198
241
  }));
@@ -204,34 +247,27 @@ export function providerLimits(bounds) {
204
247
  { name: 'change-documents', value: bounds.max_batch_documents },
205
248
  { name: 'path-length', value: bounds.max_path_length },
206
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 }]),
207
253
  { name: 'write-rate' },
208
- { name: 'content-ceiling' },
254
+ { name: 'storage-limit' },
209
255
  ];
210
256
  }
211
257
  export function declaredRetention(bounds) {
212
258
  return {
213
259
  history: { kind: 'no-declared-time-bound' },
214
- outcome: bounds.operation_retention_seconds,
215
260
  refreshHorizon: bounds.change_retention_seconds,
216
261
  };
217
262
  }
218
- export function capabilities(document) {
219
- const house = document.authorities.find((authority) => authority.houseModel !== null);
220
- return [
221
- {
222
- name: PROVIDER_ACTIONS,
223
- actions: declaredActions(document.actions),
224
- ...(house === undefined
225
- ? {}
226
- : { conversationAgents: houseConversationAgents(house.roomRef) }),
227
- },
228
- ];
263
+ export function capabilities(actions) {
264
+ return [{ name: PROVIDER_ACTIONS, actions: declaredActions(actions) }];
229
265
  }
230
266
  export function siteCapabilities() {
231
267
  return [
232
268
  {
233
269
  name: PROVIDER_ACTIONS,
234
- actions: [{ name: SITE_SUBMIT, inputShape: {}, resultKind: 'house' }],
270
+ actions: [{ name: SITES_SUBMISSIONS_CREATE, inputShape: {}, resultKind: 'house' }],
235
271
  },
236
272
  ];
237
273
  }
@@ -243,16 +279,18 @@ export function discoveredRoom(authority) {
243
279
  handle: authority.roomHandle,
244
280
  roomVersion: roomVersion(authority),
245
281
  operations: {
246
- read: [...authority.operations.read],
247
- sync: [...authority.operations.sync],
248
282
  write: [...authority.operations.write],
249
- delete: [...authority.operations.delete],
283
+ erase: [...authority.operations.erase],
284
+ },
285
+ replica: {
286
+ selection: locator,
287
+ admission: authority.managedReplication,
288
+ offline: authority.level === 'open' ? 'locked' : 'open',
250
289
  },
251
- replica: { selection: locator, admission: authority.managedReplication },
252
- ...(authority.houseModel === null
290
+ ...(authority.typedSelection === null
253
291
  ? {}
254
- : { typedSelection: { roots: [...authority.houseModel.paths] } }),
255
- providerOwnedPaths: [...authority.protectedPaths, ...schemasOf(authority)],
292
+ : { typedSelection: { roots: [...authority.typedSelection] } }),
293
+ providerOwnedPaths: [...authority.protectedPaths, authority.schema],
256
294
  };
257
295
  }
258
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"}
@@ -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
+ }