@agentshouse/mdruntime 0.1.0-alpha.1 → 0.1.0-alpha.10

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 (104) hide show
  1. package/dist/adapter.d.ts +142 -29
  2. package/dist/adapter.d.ts.map +1 -1
  3. package/dist/adapter.js.map +1 -1
  4. package/dist/bootstrap.d.ts +14 -0
  5. package/dist/bootstrap.d.ts.map +1 -0
  6. package/dist/bootstrap.js +55 -0
  7. package/dist/bootstrap.js.map +1 -0
  8. package/dist/change.d.ts +65 -0
  9. package/dist/change.d.ts.map +1 -0
  10. package/dist/change.js +12 -0
  11. package/dist/change.js.map +1 -0
  12. package/dist/client.d.ts +63 -0
  13. package/dist/client.d.ts.map +1 -0
  14. package/dist/client.js +227 -0
  15. package/dist/client.js.map +1 -0
  16. package/dist/collection.d.ts +33 -0
  17. package/dist/collection.d.ts.map +1 -0
  18. package/dist/collection.js +115 -0
  19. package/dist/collection.js.map +1 -0
  20. package/dist/connection.d.ts +85 -7
  21. package/dist/connection.d.ts.map +1 -1
  22. package/dist/connection.js +1573 -46
  23. package/dist/connection.js.map +1 -1
  24. package/dist/conversation.d.ts +57 -0
  25. package/dist/conversation.d.ts.map +1 -0
  26. package/dist/conversation.js +404 -0
  27. package/dist/conversation.js.map +1 -0
  28. package/dist/durability.d.ts +9 -0
  29. package/dist/durability.d.ts.map +1 -0
  30. package/dist/durability.js +11 -0
  31. package/dist/durability.js.map +1 -0
  32. package/dist/file.d.ts +20 -0
  33. package/dist/file.d.ts.map +1 -0
  34. package/dist/file.js +149 -0
  35. package/dist/file.js.map +1 -0
  36. package/dist/host.d.ts +9 -0
  37. package/dist/host.d.ts.map +1 -0
  38. package/dist/host.js +200 -0
  39. package/dist/host.js.map +1 -0
  40. package/dist/identity.d.ts +2 -0
  41. package/dist/identity.d.ts.map +1 -0
  42. package/dist/identity.js +16 -0
  43. package/dist/identity.js.map +1 -0
  44. package/dist/index.d.ts +15 -2
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +1 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/log.d.ts +5 -0
  49. package/dist/log.d.ts.map +1 -0
  50. package/dist/log.js +15 -0
  51. package/dist/log.js.map +1 -0
  52. package/dist/memory.d.ts +24 -4
  53. package/dist/memory.d.ts.map +1 -1
  54. package/dist/memory.js +300 -37
  55. package/dist/memory.js.map +1 -1
  56. package/dist/model.d.ts +70 -0
  57. package/dist/model.d.ts.map +1 -0
  58. package/dist/model.js +28 -0
  59. package/dist/model.js.map +1 -0
  60. package/dist/outcome.d.ts +37 -0
  61. package/dist/outcome.d.ts.map +1 -0
  62. package/dist/outcome.js +23 -0
  63. package/dist/outcome.js.map +1 -0
  64. package/dist/overlay.d.ts +8 -0
  65. package/dist/overlay.d.ts.map +1 -0
  66. package/dist/overlay.js +139 -0
  67. package/dist/overlay.js.map +1 -0
  68. package/dist/paths.d.ts +6 -0
  69. package/dist/paths.d.ts.map +1 -0
  70. package/dist/paths.js +47 -0
  71. package/dist/paths.js.map +1 -0
  72. package/dist/query.d.ts +13 -0
  73. package/dist/query.d.ts.map +1 -0
  74. package/dist/query.js +18 -0
  75. package/dist/query.js.map +1 -0
  76. package/dist/refresh.d.ts +14 -0
  77. package/dist/refresh.d.ts.map +1 -0
  78. package/dist/refresh.js +65 -0
  79. package/dist/refresh.js.map +1 -0
  80. package/dist/replica.d.ts +23 -0
  81. package/dist/replica.d.ts.map +1 -0
  82. package/dist/replica.js +78 -0
  83. package/dist/replica.js.map +1 -0
  84. package/dist/save.d.ts +31 -0
  85. package/dist/save.d.ts.map +1 -0
  86. package/dist/save.js +537 -0
  87. package/dist/save.js.map +1 -0
  88. package/dist/status.d.ts +25 -0
  89. package/dist/status.d.ts.map +1 -0
  90. package/dist/status.js +32 -0
  91. package/dist/status.js.map +1 -0
  92. package/dist/store.d.ts +76 -0
  93. package/dist/store.d.ts.map +1 -0
  94. package/dist/store.js +191 -0
  95. package/dist/store.js.map +1 -0
  96. package/dist/transfer.d.ts +5 -0
  97. package/dist/transfer.d.ts.map +1 -0
  98. package/dist/transfer.js +5 -0
  99. package/dist/transfer.js.map +1 -0
  100. package/dist/wire.d.ts +63 -0
  101. package/dist/wire.d.ts.map +1 -0
  102. package/dist/wire.js +139 -0
  103. package/dist/wire.js.map +1 -0
  104. package/package.json +14 -2
package/dist/memory.js CHANGED
@@ -1,42 +1,238 @@
1
1
  import { ROOM_CONTRACT_VERSION } from './adapter.js';
2
- async function resolveScript(answer, fallback) {
2
+ import { MD_MODEL } from './collection.js';
3
+ const FIXTURE_RETENTION = {
4
+ history: {
5
+ kind: 'duration',
6
+ seconds: 1
7
+ },
8
+ outcome: 1,
9
+ refreshHorizon: 1
10
+ };
11
+ function declaredRetention(value) {
12
+ const retention = value ?? FIXTURE_RETENTION;
13
+ if (retention.history.kind === 'no-declared-time-bound') return retention;
14
+ if (Number.isFinite(retention.history.seconds) && retention.history.seconds > 0) {
15
+ return retention;
16
+ }
17
+ throw new Error('history retention duration must be a finite positive number of seconds');
18
+ }
19
+ function named(source, paths) {
20
+ const taken = {};
21
+ for (const path of paths){
22
+ const value = source[path];
23
+ if (value !== undefined) taken[path] = value;
24
+ }
25
+ return taken;
26
+ }
27
+ async function resolveScript(answer, fallback, request) {
3
28
  if (answer === undefined) return fallback();
4
- return typeof answer === 'function' ? answer() : answer;
29
+ return typeof answer === 'function' ? answer(request) : answer;
5
30
  }
6
31
  export function createMemoryAdapter(options = {}) {
7
32
  let rooms = options.rooms === undefined ? [] : [
8
33
  ...options.rooms
9
34
  ];
10
- const mdModel = options.mdModel ?? {
11
- identity: 'mdmodel',
12
- version: '1.0.0'
13
- };
35
+ const mdModel = options.mdModel ?? MD_MODEL;
14
36
  const supportedVersions = options.supportedVersions ?? [
15
37
  ROOM_CONTRACT_VERSION
16
38
  ];
17
39
  const capabilities = options.capabilities ?? [];
18
40
  const providerLimits = options.providerLimits ?? [];
19
- const retention = options.retention ?? {
20
- history: 1,
21
- outcome: 1,
22
- refreshHorizon: 1
23
- };
24
- const origins = options.origins ?? [
25
- 'https://origin.example'
26
- ];
41
+ const retention = declaredRetention(options.retention);
42
+ const pageSize = options.pageSize;
27
43
  const scripts = {};
44
+ const served = new Map();
45
+ const refreshPages = new Map();
46
+ const observers = new Set();
47
+ const listeners = new Set();
48
+ const scripted = new Map();
49
+ const unsealed = new Map();
50
+ const sealed = new Set();
51
+ const historyPageSize = options.historyPageSize;
52
+ let selected = [];
53
+ let viewed = [];
54
+ let issued = 0;
55
+ function scriptConversations(entries) {
56
+ scripted.clear();
57
+ for (const entry of entries)scripted.set(entry.conversation, entry);
58
+ }
59
+ scriptConversations(options.conversations ?? []);
60
+ function retain(entries) {
61
+ for (const room of entries){
62
+ const versions = served.get(room.locator) ?? new Map();
63
+ versions.set(room.roomVersion, room);
64
+ served.set(room.locator, versions);
65
+ }
66
+ }
67
+ retain(rooms);
68
+ function declared(room) {
69
+ return {
70
+ name: room.name,
71
+ locator: room.locator,
72
+ collectionRoot: room.collectionRoot,
73
+ roomVersion: room.roomVersion,
74
+ operations: room.operations,
75
+ replica: room.replica,
76
+ attachedModel: room.attachedModel,
77
+ ...room.typedSelection === undefined ? {} : {
78
+ typedSelection: room.typedSelection
79
+ },
80
+ providerOwnedPaths: room.providerOwnedPaths
81
+ };
82
+ }
83
+ function page(room, from) {
84
+ const paths = Object.keys(room.documents ?? {}).sort();
85
+ const size = pageSize ?? paths.length;
86
+ const taken = paths.slice(from, from + size);
87
+ const next = from + taken.length;
88
+ return {
89
+ kind: 'bootstrap',
90
+ roomVersion: room.roomVersion,
91
+ documents: named(room.documents ?? {}, taken),
92
+ revisions: named(room.revisions ?? {}, taken),
93
+ binaryTargets: from === 0 ? room.binaryTargets ?? [] : [],
94
+ ...next < paths.length ? {
95
+ pageToken: String(next)
96
+ } : {}
97
+ };
98
+ }
99
+ function advancement(room, from, at) {
100
+ const current = room.documents ?? {};
101
+ const previous = from.documents ?? {};
102
+ const currentTargets = new Set(room.binaryTargets ?? []);
103
+ const previousTargets = new Set(from.binaryTargets ?? []);
104
+ const changed = Object.keys(current).filter((path)=>current[path] !== previous[path]).sort();
105
+ const size = pageSize ?? changed.length;
106
+ const taken = changed.slice(at, at + size);
107
+ const next = at + taken.length;
108
+ const opening = at === 0;
109
+ const pageToken = next < changed.length ? `refresh-${refreshPages.size}` : undefined;
110
+ if (pageToken !== undefined) refreshPages.set(pageToken, {
111
+ room,
112
+ from,
113
+ at: next
114
+ });
115
+ return {
116
+ kind: 'net-advancement',
117
+ roomVersion: room.roomVersion,
118
+ documents: named(current, taken),
119
+ revisions: named(room.revisions ?? {}, taken),
120
+ binaryTargets: opening ? [
121
+ ...currentTargets
122
+ ].filter((target)=>!previousTargets.has(target)) : [],
123
+ removals: opening ? [
124
+ ...Object.keys(previous).filter((path)=>!(path in current) && !currentTargets.has(path)),
125
+ ...[
126
+ ...previousTargets
127
+ ].filter((target)=>!currentTargets.has(target) && !(target in current))
128
+ ].sort() : [],
129
+ ...pageToken === undefined ? {} : {
130
+ pageToken
131
+ }
132
+ };
133
+ }
134
+ function historyOf(conversation, cursor) {
135
+ const messages = conversation.messages ?? [];
136
+ const until = typeof cursor === 'string' ? Number(cursor) : messages.length;
137
+ if (!Number.isInteger(until) || until < 0 || until > messages.length) {
138
+ return {
139
+ kind: 'rejected',
140
+ code: 'unknown-cursor',
141
+ fields: {
142
+ cursor
143
+ }
144
+ };
145
+ }
146
+ const size = historyPageSize ?? messages.length;
147
+ const from = Math.max(0, until - size);
148
+ return {
149
+ kind: 'action',
150
+ result: {
151
+ messages: messages.slice(from, until),
152
+ ...from === 0 ? {} : {
153
+ cursor: String(from)
154
+ }
155
+ }
156
+ };
157
+ }
158
+ function conversationAction(request) {
159
+ const name = request.name;
160
+ const input = request.input ?? {};
161
+ if (name === 'conversation.create') {
162
+ issued += 1;
163
+ const conversation = `conversation-${issued}`;
164
+ scripted.set(conversation, {
165
+ conversation
166
+ });
167
+ return {
168
+ kind: 'action',
169
+ result: {
170
+ conversation
171
+ }
172
+ };
173
+ }
174
+ const named = typeof input.conversation === 'string' ? input.conversation : '';
175
+ const conversation = scripted.get(named);
176
+ if (conversation === undefined) {
177
+ return {
178
+ kind: 'rejected',
179
+ code: 'unknown-conversation',
180
+ fields: {
181
+ conversation: named
182
+ }
183
+ };
184
+ }
185
+ const outcome = conversation.outcomes?.[name];
186
+ if (outcome !== undefined) return outcome;
187
+ if (name === 'conversation.history') return historyOf(conversation, input.cursor);
188
+ if (name === 'conversation.send') {
189
+ issued += 1;
190
+ const turn = `turn-${issued}`;
191
+ unsealed.set(turn, named);
192
+ return {
193
+ kind: 'action',
194
+ result: {
195
+ turn
196
+ }
197
+ };
198
+ }
199
+ if (name === 'conversation.cancel') {
200
+ const turn = typeof input.turn === 'string' ? input.turn : '';
201
+ if (sealed.has(turn) || !unsealed.has(turn)) {
202
+ return {
203
+ kind: 'rejected',
204
+ code: 'turn-sealed',
205
+ fields: {
206
+ turn
207
+ }
208
+ };
209
+ }
210
+ unsealed.delete(turn);
211
+ return {
212
+ kind: 'action',
213
+ result: {
214
+ turn,
215
+ cancelled: true
216
+ }
217
+ };
218
+ }
219
+ if (name === 'conversation.delete') scripted.delete(named);
220
+ return {
221
+ kind: 'action',
222
+ result: {
223
+ conversation: named
224
+ }
225
+ };
226
+ }
28
227
  function discovery() {
29
228
  return {
30
229
  kind: 'discovery',
31
230
  supportedVersions,
32
231
  mdModel,
33
- rooms: [
34
- ...rooms
35
- ],
232
+ rooms: rooms.map(declared),
36
233
  capabilities,
37
234
  providerLimits,
38
- retention,
39
- origins
235
+ retention
40
236
  };
41
237
  }
42
238
  return {
@@ -44,16 +240,72 @@ export function createMemoryAdapter(options = {}) {
44
240
  rooms = [
45
241
  ...next
46
242
  ];
243
+ retain(rooms);
244
+ },
245
+ setConversations (next) {
246
+ scriptConversations(next);
247
+ },
248
+ notifyRoomVersion (notification) {
249
+ for (const observer of observers)observer(notification);
250
+ },
251
+ notifyConversation (event) {
252
+ if (event.kind === 'accepted-message') {
253
+ sealed.add(event.message.turn);
254
+ unsealed.delete(event.message.turn);
255
+ }
256
+ for (const listener of listeners)listener(event);
257
+ },
258
+ selectedRooms () {
259
+ return selected;
260
+ },
261
+ viewedConversations () {
262
+ return viewed;
263
+ },
264
+ conversations: {
265
+ view (next) {
266
+ viewed = [
267
+ ...next
268
+ ];
269
+ },
270
+ observe (notify) {
271
+ listeners.add(notify);
272
+ return ()=>{
273
+ listeners.delete(notify);
274
+ };
275
+ }
276
+ },
277
+ roomVersions: {
278
+ select (locators) {
279
+ selected = [
280
+ ...locators
281
+ ];
282
+ },
283
+ observe (notify) {
284
+ observers.add(notify);
285
+ return ()=>{
286
+ observers.delete(notify);
287
+ };
288
+ }
47
289
  },
48
290
  script (operation, answer) {
49
291
  if (answer === undefined) delete scripts[operation];
50
292
  else scripts[operation] = answer;
51
293
  },
294
+ async model (_authorization, request) {
295
+ return resolveScript(scripts.model, ()=>{
296
+ const room = rooms.find((entry)=>entry.locator === request.locator);
297
+ const answer = request.attached === 'collection' ? room?.model : room?.selectionModel;
298
+ return answer ?? {
299
+ kind: 'model-unavailable',
300
+ reason: 'not-readable'
301
+ };
302
+ }, request);
303
+ },
52
304
  async authorize () {
53
- return resolveScript(scripts.authorize, ()=>({}));
305
+ return resolveScript(scripts.authorize, ()=>({}), undefined);
54
306
  },
55
307
  async discover (_authorization) {
56
- return resolveScript(scripts.discover, discovery);
308
+ return resolveScript(scripts.discover, discovery, undefined);
57
309
  },
58
310
  async bootstrap (_authorization, request) {
59
311
  return resolveScript(scripts.bootstrap, ()=>{
@@ -64,11 +316,8 @@ export function createMemoryAdapter(options = {}) {
64
316
  locator: request.locator
65
317
  };
66
318
  }
67
- return {
68
- kind: 'bootstrap',
69
- roomVersion: room.roomVersion
70
- };
71
- });
319
+ return page(room, request.pageToken === undefined ? 0 : Number(request.pageToken));
320
+ }, request);
72
321
  },
73
322
  async refresh (_authorization, request) {
74
323
  return resolveScript(scripts.refresh, ()=>{
@@ -79,16 +328,24 @@ export function createMemoryAdapter(options = {}) {
79
328
  locator: request.locator
80
329
  };
81
330
  }
331
+ if (request.pageToken !== undefined) {
332
+ const continuation = refreshPages.get(request.pageToken);
333
+ if (continuation === undefined || continuation.room.locator !== request.locator || continuation.from.roomVersion !== request.fromRoomVersion) {
334
+ throw new Error('Invalid Refresh Page Token');
335
+ }
336
+ return advancement(continuation.room, continuation.from, continuation.at);
337
+ }
82
338
  if (request.fromRoomVersion === room.roomVersion) {
83
339
  return {
84
340
  kind: 'still-current'
85
341
  };
86
342
  }
87
- return {
88
- kind: 'net-advancement',
89
- roomVersion: room.roomVersion
343
+ const from = served.get(room.locator)?.get(request.fromRoomVersion);
344
+ if (from === undefined) return {
345
+ kind: 'beyond-horizon'
90
346
  };
91
- });
347
+ return advancement(room, from, 0);
348
+ }, request);
92
349
  },
93
350
  async mutate (_authorization, request) {
94
351
  return resolveScript(scripts.mutate, ()=>{
@@ -101,9 +358,11 @@ export function createMemoryAdapter(options = {}) {
101
358
  }
102
359
  return {
103
360
  kind: 'rejected',
104
- text: ''
361
+ code: 'unscripted-mutation',
362
+ fields: {},
363
+ affected: {}
105
364
  };
106
- });
365
+ }, request);
107
366
  },
108
367
  async history (_authorization, request) {
109
368
  return resolveScript(scripts.history, ()=>{
@@ -118,13 +377,17 @@ export function createMemoryAdapter(options = {}) {
118
377
  kind: 'history',
119
378
  revisions: []
120
379
  };
121
- });
380
+ }, request);
122
381
  },
123
- async action (_authorization, _request) {
124
- return resolveScript(scripts.action, ()=>({
382
+ async action (_authorization, request) {
383
+ return resolveScript(scripts.action, ()=>{
384
+ if (request.name.startsWith('conversation.')) return conversationAction(request);
385
+ return {
125
386
  kind: 'rejected',
126
- text: ''
127
- }));
387
+ code: 'unscripted-action',
388
+ fields: {}
389
+ };
390
+ }, request);
128
391
  }
129
392
  };
130
393
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/memory.ts"],"sourcesContent":["import {\n ROOM_CONTRACT_VERSION,\n type ActionRequest,\n type ActionResult,\n type Adapter,\n type Authorization,\n type BootstrapRequest,\n type BootstrapResult,\n type Capability,\n type DiscoverResult,\n type DiscoveredRoom,\n type HistoryRequest,\n type HistoryResult,\n type MdModelIdentity,\n type MutationRequest,\n type MutationResult,\n type ProviderLimit,\n type RefreshRequest,\n type RefreshResult,\n type Retention,\n} from './adapter.js';\n\nexport type MemoryAdapterOptions = {\n rooms?: readonly DiscoveredRoom[];\n mdModel?: MdModelIdentity;\n supportedVersions?: readonly number[];\n capabilities?: readonly Capability[];\n providerLimits?: readonly ProviderLimit[];\n retention?: Retention;\n origins?: readonly string[];\n};\n\nexport type MemoryAdapter = Adapter & {\n setRooms(rooms: readonly DiscoveredRoom[]): void;\n script(operation: keyof Adapter, answer: unknown): void;\n};\n\ntype Script<T> = T | (() => T | Promise<T>);\n\nasync function resolveScript<T>(answer: Script<T> | undefined, fallback: () => T | Promise<T>) {\n if (answer === undefined) return fallback();\n return typeof answer === 'function' ? (answer as () => T | Promise<T>)() : answer;\n}\n\nexport function createMemoryAdapter(options: MemoryAdapterOptions = {}): MemoryAdapter {\n let rooms = options.rooms === undefined ? [] : [...options.rooms];\n const mdModel = options.mdModel ?? { identity: 'mdmodel', version: '1.0.0' };\n const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];\n const capabilities = options.capabilities ?? [];\n const providerLimits = options.providerLimits ?? [];\n const retention = options.retention ?? { history: 1, outcome: 1, refreshHorizon: 1 };\n const origins = options.origins ?? ['https://origin.example'];\n const scripts: Partial<Record<keyof Adapter, unknown>> = {};\n\n function discovery(): DiscoverResult {\n return {\n kind: 'discovery',\n supportedVersions,\n mdModel,\n rooms: [...rooms],\n capabilities,\n providerLimits,\n retention,\n origins,\n };\n }\n\n return {\n setRooms(next) {\n rooms = [...next];\n },\n script(operation, answer) {\n if (answer === undefined) delete scripts[operation];\n else scripts[operation] = answer;\n },\n async authorize() {\n return resolveScript<Authorization>(\n scripts.authorize as Script<Authorization> | undefined,\n () => ({}),\n );\n },\n async discover(_authorization: Authorization) {\n return resolveScript<DiscoverResult>(\n scripts.discover as Script<DiscoverResult> | undefined,\n discovery,\n );\n },\n async bootstrap(_authorization: Authorization, request: BootstrapRequest) {\n return resolveScript<BootstrapResult>(\n scripts.bootstrap as Script<BootstrapResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return { kind: 'bootstrap', roomVersion: room.roomVersion };\n },\n );\n },\n async refresh(_authorization: Authorization, request: RefreshRequest) {\n return resolveScript<RefreshResult>(\n scripts.refresh as Script<RefreshResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n if (request.fromRoomVersion === room.roomVersion) {\n return { kind: 'still-current' };\n }\n return { kind: 'net-advancement', roomVersion: room.roomVersion };\n },\n );\n },\n async mutate(_authorization: Authorization, request: MutationRequest) {\n return resolveScript<MutationResult>(\n scripts.mutate as Script<MutationResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return { kind: 'rejected', text: '' };\n },\n );\n },\n async history(_authorization: Authorization, request: HistoryRequest) {\n return resolveScript<HistoryResult>(\n scripts.history as Script<HistoryResult> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return {\n kind: 'history',\n revisions: [],\n };\n },\n );\n },\n async action(_authorization: Authorization, _request: ActionRequest) {\n return resolveScript<ActionResult>(\n scripts.action as Script<ActionResult> | undefined,\n () => ({\n kind: 'rejected',\n text: '',\n }),\n );\n },\n };\n}\n"],"names":["ROOM_CONTRACT_VERSION","resolveScript","answer","fallback","undefined","createMemoryAdapter","options","rooms","mdModel","identity","version","supportedVersions","capabilities","providerLimits","retention","history","outcome","refreshHorizon","origins","scripts","discovery","kind","setRooms","next","script","operation","authorize","discover","_authorization","bootstrap","request","room","find","entry","locator","roomVersion","refresh","fromRoomVersion","mutate","text","revisions","action","_request"],"mappings":"AAAA,SACEA,qBAAqB,QAmBhB,eAAe;AAmBtB,eAAeC,cAAiBC,MAA6B,EAAEC,QAA8B;IAC3F,IAAID,WAAWE,WAAW,OAAOD;IACjC,OAAO,OAAOD,WAAW,aAAa,AAACA,WAAoCA;AAC7E;AAEA,OAAO,SAASG,oBAAoBC,UAAgC,CAAC,CAAC;IACpE,IAAIC,QAAQD,QAAQC,KAAK,KAAKH,YAAY,EAAE,GAAG;WAAIE,QAAQC,KAAK;KAAC;IACjE,MAAMC,UAAUF,QAAQE,OAAO,IAAI;QAAEC,UAAU;QAAWC,SAAS;IAAQ;IAC3E,MAAMC,oBAAoBL,QAAQK,iBAAiB,IAAI;QAACX;KAAsB;IAC9E,MAAMY,eAAeN,QAAQM,YAAY,IAAI,EAAE;IAC/C,MAAMC,iBAAiBP,QAAQO,cAAc,IAAI,EAAE;IACnD,MAAMC,YAAYR,QAAQQ,SAAS,IAAI;QAAEC,SAAS;QAAGC,SAAS;QAAGC,gBAAgB;IAAE;IACnF,MAAMC,UAAUZ,QAAQY,OAAO,IAAI;QAAC;KAAyB;IAC7D,MAAMC,UAAmD,CAAC;IAE1D,SAASC;QACP,OAAO;YACLC,MAAM;YACNV;YACAH;YACAD,OAAO;mBAAIA;aAAM;YACjBK;YACAC;YACAC;YACAI;QACF;IACF;IAEA,OAAO;QACLI,UAASC,IAAI;YACXhB,QAAQ;mBAAIgB;aAAK;QACnB;QACAC,QAAOC,SAAS,EAAEvB,MAAM;YACtB,IAAIA,WAAWE,WAAW,OAAOe,OAAO,CAACM,UAAU;iBAC9CN,OAAO,CAACM,UAAU,GAAGvB;QAC5B;QACA,MAAMwB;YACJ,OAAOzB,cACLkB,QAAQO,SAAS,EACjB,IAAO,CAAA,CAAC,CAAA;QAEZ;QACA,MAAM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6B,EAAEE,OAAuB;YAClE,OAAO7B,cACLkB,QAAQJ,OAAO,EACf;gBACE,MAAMgB,OAAOxB,MAAMyB,IAAI,CAAC,CAACC,QAAUA,MAAMC,OAAO,KAAKJ,QAAQI,OAAO;gBACpE,IAAIH,SAAS3B,WAAW;oBACtB,OAAO;wBAAEiB,MAAM;wBAAqBa,SAASJ,QAAQI,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBACLb,MAAM;oBACNmB,WAAW,EAAE;gBACf;YACF;QAEJ;QACA,MAAMC,QAAOb,cAA6B,EAAEc,QAAuB;YACjE,OAAOzC,cACLkB,QAAQsB,MAAM,EACd,IAAO,CAAA;oBACLpB,MAAM;oBACNkB,MAAM;gBACR,CAAA;QAEJ;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/memory.ts"],"sourcesContent":["import type { ModelResult } from './model.js';\nimport {\n ROOM_CONTRACT_VERSION,\n type ActionRequest,\n type ActionResult,\n type Adapter,\n type Authorization,\n type BootstrapRequest,\n type BootstrapResult,\n type Capability,\n type ConversationAction,\n type ConversationEvent,\n type ConversationMessage,\n type DiscoverResult,\n type DiscoveredRoom,\n type HistoryRequest,\n type HistoryResult,\n type MdModelIdentity,\n type MutationRequest,\n type MutationResult,\n type ProviderLimit,\n type RefreshRequest,\n type RefreshResult,\n type Retention,\n type RoomVersionNotification,\n} from './adapter.js';\nimport { MD_MODEL } from './collection.js';\n\nconst FIXTURE_RETENTION: Retention = {\n history: { kind: 'duration', seconds: 1 },\n outcome: 1,\n refreshHorizon: 1,\n};\n\nfunction declaredRetention(value: Retention | undefined): Retention {\n const retention = value ?? FIXTURE_RETENTION;\n if (retention.history.kind === 'no-declared-time-bound') return retention;\n if (Number.isFinite(retention.history.seconds) && retention.history.seconds > 0) {\n return retention;\n }\n throw new Error('history retention duration must be a finite positive number of seconds');\n}\n\nexport type MemoryRoom = DiscoveredRoom & {\n model?: ModelResult;\n selectionModel?: ModelResult;\n documents?: Readonly<Record<string, string>>;\n revisions?: Readonly<Record<string, string>>;\n binaryTargets?: readonly string[];\n};\n\nexport type MemoryConversation = {\n conversation: string;\n messages?: readonly ConversationMessage[];\n outcomes?: Partial<Record<ConversationAction, ActionResult>>;\n};\n\nexport type MemoryAdapterOptions = {\n rooms?: readonly MemoryRoom[];\n conversations?: readonly MemoryConversation[];\n historyPageSize?: number;\n pageSize?: number;\n mdModel?: MdModelIdentity;\n supportedVersions?: readonly number[];\n capabilities?: readonly Capability[];\n providerLimits?: readonly ProviderLimit[];\n retention?: Retention;\n};\n\nexport type MemoryAdapter = Adapter & {\n setRooms(rooms: readonly MemoryRoom[]): void;\n setConversations(conversations: readonly MemoryConversation[]): void;\n script(operation: keyof Adapter, answer: unknown): void;\n notifyRoomVersion(notification: RoomVersionNotification): void;\n notifyConversation(event: ConversationEvent): void;\n selectedRooms(): readonly string[];\n viewedConversations(): readonly string[];\n};\n\ntype Script<T, R> = T | ((request: R) => T | Promise<T>);\n\ntype RefreshContinuation = {\n room: MemoryRoom;\n from: MemoryRoom;\n at: number;\n};\n\nfunction named(\n source: Readonly<Record<string, string>>,\n paths: readonly string[],\n): Readonly<Record<string, string>> {\n const taken: Record<string, string> = {};\n for (const path of paths) {\n const value = source[path];\n if (value !== undefined) taken[path] = value;\n }\n return taken;\n}\n\nasync function resolveScript<T, R>(\n answer: Script<T, R> | undefined,\n fallback: () => T | Promise<T>,\n request: R,\n) {\n if (answer === undefined) return fallback();\n return typeof answer === 'function' ? (answer as (value: R) => T | Promise<T>)(request) : answer;\n}\n\nexport function createMemoryAdapter(options: MemoryAdapterOptions = {}): MemoryAdapter {\n let rooms = options.rooms === undefined ? [] : [...options.rooms];\n const mdModel = options.mdModel ?? MD_MODEL;\n const supportedVersions = options.supportedVersions ?? [ROOM_CONTRACT_VERSION];\n const capabilities = options.capabilities ?? [];\n const providerLimits = options.providerLimits ?? [];\n const retention = declaredRetention(options.retention);\n const pageSize = options.pageSize;\n const scripts: Partial<Record<keyof Adapter, unknown>> = {};\n const served = new Map<string, Map<string, MemoryRoom>>();\n const refreshPages = new Map<string, RefreshContinuation>();\n const observers = new Set<(notification: RoomVersionNotification) => void>();\n const listeners = new Set<(event: ConversationEvent) => void>();\n const scripted = new Map<string, MemoryConversation>();\n const unsealed = new Map<string, string>();\n const sealed = new Set<string>();\n const historyPageSize = options.historyPageSize;\n let selected: readonly string[] = [];\n let viewed: readonly string[] = [];\n let issued = 0;\n\n function scriptConversations(entries: readonly MemoryConversation[]) {\n scripted.clear();\n for (const entry of entries) scripted.set(entry.conversation, entry);\n }\n\n scriptConversations(options.conversations ?? []);\n\n function retain(entries: readonly MemoryRoom[]) {\n for (const room of entries) {\n const versions = served.get(room.locator) ?? new Map<string, MemoryRoom>();\n versions.set(room.roomVersion, room);\n served.set(room.locator, versions);\n }\n }\n\n retain(rooms);\n\n function declared(room: MemoryRoom): DiscoveredRoom {\n return {\n name: room.name,\n locator: room.locator,\n collectionRoot: room.collectionRoot,\n roomVersion: room.roomVersion,\n operations: room.operations,\n replica: room.replica,\n attachedModel: room.attachedModel,\n ...(room.typedSelection === undefined ? {} : { typedSelection: room.typedSelection }),\n providerOwnedPaths: room.providerOwnedPaths,\n };\n }\n\n function page(room: MemoryRoom, from: number): BootstrapResult {\n const paths = Object.keys(room.documents ?? {}).sort();\n const size = pageSize ?? paths.length;\n const taken = paths.slice(from, from + size);\n const next = from + taken.length;\n return {\n kind: 'bootstrap',\n roomVersion: room.roomVersion,\n documents: named(room.documents ?? {}, taken),\n revisions: named(room.revisions ?? {}, taken),\n binaryTargets: from === 0 ? (room.binaryTargets ?? []) : [],\n ...(next < paths.length ? { pageToken: String(next) } : {}),\n };\n }\n\n function advancement(room: MemoryRoom, from: MemoryRoom, at: number): RefreshResult {\n const current = room.documents ?? {};\n const previous = from.documents ?? {};\n const currentTargets = new Set(room.binaryTargets ?? []);\n const previousTargets = new Set(from.binaryTargets ?? []);\n const changed = Object.keys(current)\n .filter((path) => current[path] !== previous[path])\n .sort();\n const size = pageSize ?? changed.length;\n const taken = changed.slice(at, at + size);\n const next = at + taken.length;\n const opening = at === 0;\n const pageToken = next < changed.length ? `refresh-${refreshPages.size}` : undefined;\n if (pageToken !== undefined) refreshPages.set(pageToken, { room, from, at: next });\n return {\n kind: 'net-advancement',\n roomVersion: room.roomVersion,\n documents: named(current, taken),\n revisions: named(room.revisions ?? {}, taken),\n binaryTargets: opening\n ? [...currentTargets].filter((target) => !previousTargets.has(target))\n : [],\n removals: opening\n ? [\n ...Object.keys(previous).filter(\n (path) => !(path in current) && !currentTargets.has(path),\n ),\n ...[...previousTargets].filter(\n (target) => !currentTargets.has(target) && !(target in current),\n ),\n ].sort()\n : [],\n ...(pageToken === undefined ? {} : { pageToken }),\n };\n }\n\n function historyOf(conversation: MemoryConversation, cursor: unknown): ActionResult {\n const messages = conversation.messages ?? [];\n const until = typeof cursor === 'string' ? Number(cursor) : messages.length;\n if (!Number.isInteger(until) || until < 0 || until > messages.length) {\n return { kind: 'rejected', code: 'unknown-cursor', fields: { cursor } };\n }\n const size = historyPageSize ?? messages.length;\n const from = Math.max(0, until - size);\n return {\n kind: 'action',\n result: {\n messages: messages.slice(from, until),\n ...(from === 0 ? {} : { cursor: String(from) }),\n },\n };\n }\n\n function conversationAction(request: ActionRequest): ActionResult {\n const name = request.name as ConversationAction;\n const input = (request.input ?? {}) as {\n conversation?: unknown;\n turn?: unknown;\n cursor?: unknown;\n };\n if (name === 'conversation.create') {\n issued += 1;\n const conversation = `conversation-${issued}`;\n scripted.set(conversation, { conversation });\n return { kind: 'action', result: { conversation } };\n }\n const named = typeof input.conversation === 'string' ? input.conversation : '';\n const conversation = scripted.get(named);\n if (conversation === undefined) {\n return { kind: 'rejected', code: 'unknown-conversation', fields: { conversation: named } };\n }\n const outcome = conversation.outcomes?.[name];\n if (outcome !== undefined) return outcome;\n if (name === 'conversation.history') return historyOf(conversation, input.cursor);\n if (name === 'conversation.send') {\n issued += 1;\n const turn = `turn-${issued}`;\n unsealed.set(turn, named);\n return { kind: 'action', result: { turn } };\n }\n if (name === 'conversation.cancel') {\n const turn = typeof input.turn === 'string' ? input.turn : '';\n if (sealed.has(turn) || !unsealed.has(turn)) {\n return { kind: 'rejected', code: 'turn-sealed', fields: { turn } };\n }\n unsealed.delete(turn);\n return { kind: 'action', result: { turn, cancelled: true } };\n }\n if (name === 'conversation.delete') scripted.delete(named);\n return { kind: 'action', result: { conversation: named } };\n }\n\n function discovery(): DiscoverResult {\n return {\n kind: 'discovery',\n supportedVersions,\n mdModel,\n rooms: rooms.map(declared),\n capabilities,\n providerLimits,\n retention,\n };\n }\n\n return {\n setRooms(next) {\n rooms = [...next];\n retain(rooms);\n },\n setConversations(next) {\n scriptConversations(next);\n },\n notifyRoomVersion(notification) {\n for (const observer of observers) observer(notification);\n },\n notifyConversation(event) {\n if (event.kind === 'accepted-message') {\n sealed.add(event.message.turn);\n unsealed.delete(event.message.turn);\n }\n for (const listener of listeners) listener(event);\n },\n selectedRooms() {\n return selected;\n },\n viewedConversations() {\n return viewed;\n },\n conversations: {\n view(next) {\n viewed = [...next];\n },\n observe(notify) {\n listeners.add(notify);\n return () => {\n listeners.delete(notify);\n };\n },\n },\n roomVersions: {\n select(locators) {\n selected = [...locators];\n },\n observe(notify) {\n observers.add(notify);\n return () => {\n observers.delete(notify);\n };\n },\n },\n script(operation, answer) {\n if (answer === undefined) delete scripts[operation];\n else scripts[operation] = answer;\n },\n async model(_authorization, request) {\n return resolveScript(\n scripts.model as Script<ModelResult, typeof request> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n const answer = request.attached === 'collection' ? room?.model : room?.selectionModel;\n return answer ?? { kind: 'model-unavailable', reason: 'not-readable' };\n },\n request,\n );\n },\n async authorize() {\n return resolveScript<Authorization, void>(\n scripts.authorize as Script<Authorization, void> | undefined,\n () => ({}),\n undefined,\n );\n },\n async discover(_authorization: Authorization) {\n return resolveScript<DiscoverResult, void>(\n scripts.discover as Script<DiscoverResult, void> | undefined,\n discovery,\n undefined,\n );\n },\n async bootstrap(_authorization: Authorization, request: BootstrapRequest) {\n return resolveScript<BootstrapResult, BootstrapRequest>(\n scripts.bootstrap as Script<BootstrapResult, BootstrapRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return page(room, request.pageToken === undefined ? 0 : Number(request.pageToken));\n },\n request,\n );\n },\n async refresh(_authorization: Authorization, request: RefreshRequest) {\n return resolveScript<RefreshResult, RefreshRequest>(\n scripts.refresh as Script<RefreshResult, RefreshRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n if (request.pageToken !== undefined) {\n const continuation = refreshPages.get(request.pageToken);\n if (\n continuation === undefined ||\n continuation.room.locator !== request.locator ||\n continuation.from.roomVersion !== request.fromRoomVersion\n ) {\n throw new Error('Invalid Refresh Page Token');\n }\n return advancement(continuation.room, continuation.from, continuation.at);\n }\n if (request.fromRoomVersion === room.roomVersion) {\n return { kind: 'still-current' };\n }\n const from = served.get(room.locator)?.get(request.fromRoomVersion);\n if (from === undefined) return { kind: 'beyond-horizon' };\n return advancement(room, from, 0);\n },\n request,\n );\n },\n async mutate(_authorization: Authorization, request: MutationRequest) {\n return resolveScript<MutationResult, MutationRequest>(\n scripts.mutate as Script<MutationResult, MutationRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return { kind: 'rejected', code: 'unscripted-mutation', fields: {}, affected: {} };\n },\n request,\n );\n },\n async history(_authorization: Authorization, request: HistoryRequest) {\n return resolveScript<HistoryResult, HistoryRequest>(\n scripts.history as Script<HistoryResult, HistoryRequest> | undefined,\n () => {\n const room = rooms.find((entry) => entry.locator === request.locator);\n if (room === undefined) {\n return { kind: 'room-not-readable', locator: request.locator };\n }\n return {\n kind: 'history',\n revisions: [],\n };\n },\n request,\n );\n },\n async action(_authorization: Authorization, request: ActionRequest) {\n return resolveScript<ActionResult, ActionRequest>(\n scripts.action as Script<ActionResult, ActionRequest> | undefined,\n () => {\n if (request.name.startsWith('conversation.')) return conversationAction(request);\n return { kind: 'rejected', code: 'unscripted-action', fields: {} };\n },\n request,\n );\n },\n };\n}\n"],"names":["ROOM_CONTRACT_VERSION","MD_MODEL","FIXTURE_RETENTION","history","kind","seconds","outcome","refreshHorizon","declaredRetention","value","retention","Number","isFinite","Error","named","source","paths","taken","path","undefined","resolveScript","answer","fallback","request","createMemoryAdapter","options","rooms","mdModel","supportedVersions","capabilities","providerLimits","pageSize","scripts","served","Map","refreshPages","observers","Set","listeners","scripted","unsealed","sealed","historyPageSize","selected","viewed","issued","scriptConversations","entries","clear","entry","set","conversation","conversations","retain","room","versions","get","locator","roomVersion","declared","name","collectionRoot","operations","replica","attachedModel","typedSelection","providerOwnedPaths","page","from","Object","keys","documents","sort","size","length","slice","next","revisions","binaryTargets","pageToken","String","advancement","at","current","previous","currentTargets","previousTargets","changed","filter","opening","target","has","removals","historyOf","cursor","messages","until","isInteger","code","fields","Math","max","result","conversationAction","input","outcomes","turn","delete","cancelled","discovery","map","setRooms","setConversations","notifyRoomVersion","notification","observer","notifyConversation","event","add","message","listener","selectedRooms","viewedConversations","view","observe","notify","roomVersions","select","locators","script","operation","model","_authorization","find","attached","selectionModel","reason","authorize","discover","bootstrap","refresh","continuation","fromRoomVersion","mutate","affected","action","startsWith"],"mappings":"AACA,SACEA,qBAAqB,QAuBhB,eAAe;AACtB,SAASC,QAAQ,QAAQ,kBAAkB;AAE3C,MAAMC,oBAA+B;IACnCC,SAAS;QAAEC,MAAM;QAAYC,SAAS;IAAE;IACxCC,SAAS;IACTC,gBAAgB;AAClB;AAEA,SAASC,kBAAkBC,KAA4B;IACrD,MAAMC,YAAYD,SAASP;IAC3B,IAAIQ,UAAUP,OAAO,CAACC,IAAI,KAAK,0BAA0B,OAAOM;IAChE,IAAIC,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,OAAsB;YAChE,OAAOH,cACLY,QAAQiH,MAAM,EACd;gBACE,IAAI1H,QAAQqC,IAAI,CAACsF,UAAU,CAAC,kBAAkB,OAAO3C,mBAAmBhF;gBACxE,OAAO;oBAAEnB,MAAM;oBAAY8F,MAAM;oBAAqBC,QAAQ,CAAC;gBAAE;YACnE,GACA5E;QAEJ;IACF;AACF"}
@@ -0,0 +1,70 @@
1
+ import type { Validation } from '@agentshouse/mdmodel';
2
+ import type { MdType } from './collection.js';
3
+ export type ModelIdentity = {
4
+ identity: string;
5
+ version: string;
6
+ };
7
+ export type ModelSnapshot = ModelIdentity & {
8
+ definitions: Readonly<Record<string, string>>;
9
+ };
10
+ export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | 'version-changed' | 'invalid' | 'binding-unavailable';
11
+ export type ModelResult = {
12
+ kind: 'model';
13
+ snapshot: ModelSnapshot;
14
+ } | {
15
+ kind: 'model-unavailable';
16
+ reason: ModelUnavailableReason;
17
+ } | {
18
+ kind: 'transport-uncertainty';
19
+ } | {
20
+ kind: 'revoked-authorization';
21
+ };
22
+ export type ModelState = {
23
+ status: 'unavailable';
24
+ reason: ModelUnavailableReason;
25
+ } | {
26
+ status: 'current' | 'cached';
27
+ snapshot: ModelSnapshot;
28
+ verifiedWith: ModelIdentity;
29
+ types: readonly MdType[];
30
+ };
31
+ export type TypesResult = {
32
+ status: 'unavailable';
33
+ reason: ModelUnavailableReason;
34
+ } | {
35
+ status: 'current' | 'cached';
36
+ identity: string;
37
+ version: string;
38
+ verifiedWith: ModelIdentity;
39
+ types: readonly MdType[];
40
+ };
41
+ export type ModelValidation = {
42
+ verdict: 'accept';
43
+ } | (Extract<Validation, {
44
+ verdict: 'refuse';
45
+ }> & {
46
+ source: 'content' | 'model';
47
+ });
48
+ export type AttachedModelBinding = {
49
+ verify(snapshot: ModelSnapshot): {
50
+ kind: 'verified';
51
+ types: readonly MdType[];
52
+ } | {
53
+ kind: 'invalid';
54
+ };
55
+ validate(input: {
56
+ model: ModelSnapshot;
57
+ documents: Readonly<Record<string, string>>;
58
+ binaryTargets: readonly string[];
59
+ }): ModelValidation;
60
+ };
61
+ export type ValidationReceipt = {
62
+ identity: string;
63
+ version: string;
64
+ source: 'current' | 'cached';
65
+ };
66
+ export declare const NO_MODEL: ModelState;
67
+ export declare function modelTypes(state: ModelState): TypesResult;
68
+ export declare function cached(state: ModelState): ModelState;
69
+ export declare function sameModel(left: ModelIdentity, right: ModelIdentity): boolean;
70
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAE9C,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAClE,MAAM,MAAM,aAAa,GAAG,aAAa,GAAG;IAAE,WAAW,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAA;CAAE,CAAC;AAC9F,MAAM,MAAM,sBAAsB,GAC9B,cAAc,GACd,SAAS,GACT,cAAc,GACd,iBAAiB,GACjB,SAAS,GACT,qBAAqB,CAAC;AAC1B,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,uBAAuB,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,uBAAuB,CAAA;CAAE,CAAC;AACtC,MAAM,MAAM,UAAU,GAClB;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAA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,CAAA;CAAE,CAAC;AACpG,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAUzD;AACD,wBAAgB,MAAM,CAAC,KAAK,EAAE,UAAU,GAAG,UAAU,CAEpD;AACD,wBAAgB,SAAS,CAAC,IAAI,EAAE,aAAa,EAAE,KAAK,EAAE,aAAa,GAAG,OAAO,CAE5E"}
package/dist/model.js ADDED
@@ -0,0 +1,28 @@
1
+ export const NO_MODEL = {
2
+ status: 'unavailable',
3
+ reason: 'not-acquired'
4
+ };
5
+ export function modelTypes(state) {
6
+ return state.status === 'unavailable' ? {
7
+ ...state
8
+ } : {
9
+ status: state.status,
10
+ identity: state.snapshot.identity,
11
+ version: state.snapshot.version,
12
+ verifiedWith: {
13
+ ...state.verifiedWith
14
+ },
15
+ types: structuredClone(state.types)
16
+ };
17
+ }
18
+ export function cached(state) {
19
+ return state.status === 'unavailable' ? state : {
20
+ ...state,
21
+ status: 'cached'
22
+ };
23
+ }
24
+ export function sameModel(left, right) {
25
+ return left.identity === right.identity && left.version === right.version;
26
+ }
27
+
28
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/model.ts"],"sourcesContent":["import type { Validation } from '@agentshouse/mdmodel';\nimport type { MdType } from './collection.js';\n\nexport type ModelIdentity = { identity: string; version: string };\nexport type ModelSnapshot = ModelIdentity & { definitions: Readonly<Record<string, string>> };\nexport type ModelUnavailableReason =\n | 'not-readable'\n | 'revoked'\n | 'not-acquired'\n | 'version-changed'\n | 'invalid'\n | 'binding-unavailable';\nexport type ModelResult =\n | { kind: 'model'; snapshot: ModelSnapshot }\n | { kind: 'model-unavailable'; reason: ModelUnavailableReason }\n | { kind: 'transport-uncertainty' }\n | { kind: 'revoked-authorization' };\nexport type ModelState =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n snapshot: ModelSnapshot;\n verifiedWith: ModelIdentity;\n types: readonly MdType[];\n };\nexport type TypesResult =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n identity: string;\n version: string;\n verifiedWith: ModelIdentity;\n types: readonly MdType[];\n };\nexport type ModelValidation =\n | { verdict: 'accept' }\n | (Extract<Validation, { verdict: 'refuse' }> & { source: 'content' | 'model' });\nexport type AttachedModelBinding = {\n verify(\n snapshot: ModelSnapshot,\n ): { kind: 'verified'; types: readonly MdType[] } | { kind: 'invalid' };\n validate(input: {\n model: ModelSnapshot;\n documents: Readonly<Record<string, string>>;\n binaryTargets: readonly string[];\n }): ModelValidation;\n};\nexport type ValidationReceipt = { identity: string; version: string; source: 'current' | 'cached' };\nexport const NO_MODEL: ModelState = { status: 'unavailable', reason: 'not-acquired' };\nexport function modelTypes(state: ModelState): TypesResult {\n return state.status === 'unavailable'\n ? { ...state }\n : {\n status: state.status,\n identity: state.snapshot.identity,\n version: state.snapshot.version,\n verifiedWith: { ...state.verifiedWith },\n types: structuredClone(state.types),\n };\n}\nexport function cached(state: ModelState): ModelState {\n return state.status === 'unavailable' ? state : { ...state, status: 'cached' };\n}\nexport function sameModel(left: ModelIdentity, right: ModelIdentity): boolean {\n return left.identity === right.identity && left.version === right.version;\n}\n"],"names":["NO_MODEL","status","reason","modelTypes","state","identity","snapshot","version","verifiedWith","types","structuredClone","cached","sameModel","left","right"],"mappings":"AAgDA,OAAO,MAAMA,WAAuB;IAAEC,QAAQ;IAAeC,QAAQ;AAAe,EAAE;AACtF,OAAO,SAASC,WAAWC,KAAiB;IAC1C,OAAOA,MAAMH,MAAM,KAAK,gBACpB;QAAE,GAAGG,KAAK;IAAC,IACX;QACEH,QAAQG,MAAMH,MAAM;QACpBI,UAAUD,MAAME,QAAQ,CAACD,QAAQ;QACjCE,SAASH,MAAME,QAAQ,CAACC,OAAO;QAC/BC,cAAc;YAAE,GAAGJ,MAAMI,YAAY;QAAC;QACtCC,OAAOC,gBAAgBN,MAAMK,KAAK;IACpC;AACN;AACA,OAAO,SAASE,OAAOP,KAAiB;IACtC,OAAOA,MAAMH,MAAM,KAAK,gBAAgBG,QAAQ;QAAE,GAAGA,KAAK;QAAEH,QAAQ;IAAS;AAC/E;AACA,OAAO,SAASW,UAAUC,IAAmB,EAAEC,KAAoB;IACjE,OAAOD,KAAKR,QAAQ,KAAKS,MAAMT,QAAQ,IAAIQ,KAAKN,OAAO,KAAKO,MAAMP,OAAO;AAC3E"}
@@ -0,0 +1,37 @@
1
+ import type { ActionResult, ProviderRefusal, RetryableRefusal } from './adapter.js';
2
+ import type { ChangeBatch } from './change.js';
3
+ export type AffectedState = Readonly<Record<string, string>>;
4
+ export type CallResult = ActionResult | {
5
+ kind: 'undeclared';
6
+ };
7
+ export type QueueOutcome = {
8
+ kind: 'pending';
9
+ } | (ProviderRefusal & {
10
+ kind: 'conflicted';
11
+ roomVersion?: string;
12
+ affected: AffectedState;
13
+ }) | (ProviderRefusal & {
14
+ kind: 'rejected';
15
+ affected: AffectedState;
16
+ }) | RetryableRefusal | {
17
+ kind: 'expired';
18
+ };
19
+ export type AcceptedOutcome = {
20
+ kind: 'accepted';
21
+ roomVersion: string;
22
+ author?: string;
23
+ time?: string;
24
+ };
25
+ export type SubmissionOutcome = QueueOutcome | AcceptedOutcome;
26
+ export type QueueEntry = {
27
+ readonly batch: ChangeBatch;
28
+ readonly outcome: QueueOutcome;
29
+ };
30
+ export type RefusedOutcome = Extract<QueueOutcome, {
31
+ kind: 'conflicted' | 'rejected' | 'expired';
32
+ }>;
33
+ export declare function refused(outcome: SubmissionOutcome | undefined): outcome is RefusedOutcome;
34
+ export declare function withheldUntilReset(outcome: SubmissionOutcome | undefined, at: number): boolean;
35
+ export declare function refusalOf(outcome: RefusedOutcome): ProviderRefusal | null;
36
+ export declare function queuedOutcome(outcome: SubmissionOutcome | undefined): QueueOutcome;
37
+ //# sourceMappingURL=outcome.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3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