@agentshouse/mdruntime 0.1.0-alpha.7 → 0.1.0-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/adapter.d.ts +107 -16
- package/dist/adapter.d.ts.map +1 -1
- package/dist/adapter.js.map +1 -1
- package/dist/bootstrap.d.ts +6 -1
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/bootstrap.js +14 -6
- package/dist/bootstrap.js.map +1 -1
- package/dist/change.d.ts +1 -0
- package/dist/change.d.ts.map +1 -1
- package/dist/change.js.map +1 -1
- package/dist/client.d.ts +63 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +227 -0
- package/dist/client.js.map +1 -0
- package/dist/collection.d.ts +19 -4
- package/dist/collection.d.ts.map +1 -1
- package/dist/collection.js +88 -25
- package/dist/collection.js.map +1 -1
- package/dist/connection.d.ts +37 -9
- package/dist/connection.d.ts.map +1 -1
- package/dist/connection.js +818 -274
- package/dist/connection.js.map +1 -1
- package/dist/conversation.d.ts +57 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +401 -0
- package/dist/conversation.js.map +1 -0
- package/dist/durability.d.ts +8 -3
- package/dist/durability.d.ts.map +1 -1
- package/dist/durability.js +5 -59
- package/dist/durability.js.map +1 -1
- package/dist/file.d.ts +20 -0
- package/dist/file.d.ts.map +1 -0
- package/dist/file.js +149 -0
- package/dist/file.js.map +1 -0
- package/dist/host.d.ts +9 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +200 -0
- package/dist/host.js.map +1 -0
- package/dist/identity.d.ts +2 -0
- package/dist/identity.d.ts.map +1 -0
- package/dist/identity.js +16 -0
- package/dist/identity.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/memory.d.ts +16 -2
- package/dist/memory.d.ts.map +1 -1
- package/dist/memory.js +196 -15
- package/dist/memory.js.map +1 -1
- package/dist/model.d.ts +70 -0
- package/dist/model.d.ts.map +1 -0
- package/dist/model.js +28 -0
- package/dist/model.js.map +1 -0
- package/dist/outcome.d.ts +16 -9
- package/dist/outcome.d.ts.map +1 -1
- package/dist/outcome.js +10 -0
- package/dist/outcome.js.map +1 -1
- package/dist/query.d.ts +13 -0
- package/dist/query.d.ts.map +1 -0
- package/dist/query.js +18 -0
- package/dist/query.js.map +1 -0
- package/dist/refresh.d.ts +2 -1
- package/dist/refresh.d.ts.map +1 -1
- package/dist/refresh.js +6 -4
- package/dist/refresh.js.map +1 -1
- package/dist/replica.d.ts +5 -2
- package/dist/replica.d.ts.map +1 -1
- package/dist/replica.js +23 -6
- package/dist/replica.js.map +1 -1
- package/dist/save.d.ts +6 -1
- package/dist/save.d.ts.map +1 -1
- package/dist/save.js +52 -11
- package/dist/save.js.map +1 -1
- package/dist/status.d.ts +11 -2
- package/dist/status.d.ts.map +1 -1
- package/dist/status.js +5 -4
- package/dist/status.js.map +1 -1
- package/dist/store.d.ts +38 -4
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +64 -7
- package/dist/store.js.map +1 -1
- package/dist/wire.d.ts +63 -0
- package/dist/wire.d.ts.map +1 -0
- package/dist/wire.js +139 -0
- package/dist/wire.js.map +1 -0
- package/package.json +10 -2
package/dist/memory.js
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { ROOM_CONTRACT_VERSION } from './adapter.js';
|
|
2
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
|
+
}
|
|
3
19
|
function named(source, paths) {
|
|
4
20
|
const taken = {};
|
|
5
21
|
for (const path of paths){
|
|
@@ -22,18 +38,25 @@ export function createMemoryAdapter(options = {}) {
|
|
|
22
38
|
];
|
|
23
39
|
const capabilities = options.capabilities ?? [];
|
|
24
40
|
const providerLimits = options.providerLimits ?? [];
|
|
25
|
-
const retention = options.retention
|
|
26
|
-
history: 1,
|
|
27
|
-
outcome: 1,
|
|
28
|
-
refreshHorizon: 1
|
|
29
|
-
};
|
|
30
|
-
const origins = options.origins ?? [
|
|
31
|
-
'https://origin.example'
|
|
32
|
-
];
|
|
41
|
+
const retention = declaredRetention(options.retention);
|
|
33
42
|
const pageSize = options.pageSize;
|
|
34
43
|
const scripts = {};
|
|
35
44
|
const served = new Map();
|
|
36
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 ?? []);
|
|
37
60
|
function retain(entries) {
|
|
38
61
|
for (const room of entries){
|
|
39
62
|
const versions = served.get(room.locator) ?? new Map();
|
|
@@ -46,8 +69,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
46
69
|
return {
|
|
47
70
|
name: room.name,
|
|
48
71
|
locator: room.locator,
|
|
72
|
+
collectionRoot: room.collectionRoot,
|
|
49
73
|
roomVersion: room.roomVersion,
|
|
50
|
-
|
|
74
|
+
operations: room.operations,
|
|
75
|
+
replica: room.replica,
|
|
76
|
+
attachedModel: room.attachedModel,
|
|
77
|
+
...room.typedSelection === undefined ? {} : {
|
|
78
|
+
typedSelection: room.typedSelection
|
|
79
|
+
},
|
|
51
80
|
providerOwnedPaths: room.providerOwnedPaths
|
|
52
81
|
};
|
|
53
82
|
}
|
|
@@ -102,6 +131,99 @@ export function createMemoryAdapter(options = {}) {
|
|
|
102
131
|
}
|
|
103
132
|
};
|
|
104
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
|
+
}
|
|
105
227
|
function discovery() {
|
|
106
228
|
return {
|
|
107
229
|
kind: 'discovery',
|
|
@@ -110,8 +232,7 @@ export function createMemoryAdapter(options = {}) {
|
|
|
110
232
|
rooms: rooms.map(declared),
|
|
111
233
|
capabilities,
|
|
112
234
|
providerLimits,
|
|
113
|
-
retention
|
|
114
|
-
origins
|
|
235
|
+
retention
|
|
115
236
|
};
|
|
116
237
|
}
|
|
117
238
|
return {
|
|
@@ -121,10 +242,65 @@ export function createMemoryAdapter(options = {}) {
|
|
|
121
242
|
];
|
|
122
243
|
retain(rooms);
|
|
123
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
|
+
}
|
|
289
|
+
},
|
|
124
290
|
script (operation, answer) {
|
|
125
291
|
if (answer === undefined) delete scripts[operation];
|
|
126
292
|
else scripts[operation] = answer;
|
|
127
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
|
+
},
|
|
128
304
|
async authorize () {
|
|
129
305
|
return resolveScript(scripts.authorize, ()=>({}), undefined);
|
|
130
306
|
},
|
|
@@ -182,7 +358,8 @@ export function createMemoryAdapter(options = {}) {
|
|
|
182
358
|
}
|
|
183
359
|
return {
|
|
184
360
|
kind: 'rejected',
|
|
185
|
-
|
|
361
|
+
code: 'unscripted-mutation',
|
|
362
|
+
fields: {},
|
|
186
363
|
affected: {}
|
|
187
364
|
};
|
|
188
365
|
}, request);
|
|
@@ -203,10 +380,14 @@ export function createMemoryAdapter(options = {}) {
|
|
|
203
380
|
}, request);
|
|
204
381
|
},
|
|
205
382
|
async action (_authorization, request) {
|
|
206
|
-
return resolveScript(scripts.action, ()=>
|
|
383
|
+
return resolveScript(scripts.action, ()=>{
|
|
384
|
+
if (request.name.startsWith('conversation.')) return conversationAction(request);
|
|
385
|
+
return {
|
|
207
386
|
kind: 'rejected',
|
|
208
|
-
|
|
209
|
-
|
|
387
|
+
code: 'unscripted-action',
|
|
388
|
+
fields: {}
|
|
389
|
+
};
|
|
390
|
+
}, request);
|
|
210
391
|
}
|
|
211
392
|
};
|
|
212
393
|
}
|
package/dist/memory.js.map
CHANGED
|
@@ -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';\nimport { MD_MODEL } from './collection.js';\n\nexport type MemoryRoom = DiscoveredRoom & {\n documents?: Readonly<Record<string, string>>;\n revisions?: Readonly<Record<string, string>>;\n binaryTargets?: readonly string[];\n};\n\nexport type MemoryAdapterOptions = {\n rooms?: readonly MemoryRoom[];\n pageSize?: number;\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 MemoryRoom[]): void;\n script(operation: keyof Adapter, answer: unknown): void;\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 = options.retention ?? { history: 1, outcome: 1, refreshHorizon: 1 };\n const origins = options.origins ?? ['https://origin.example'];\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\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 roomVersion: room.roomVersion,\n writeGrants: room.writeGrants,\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 discovery(): DiscoverResult {\n return {\n kind: 'discovery',\n supportedVersions,\n mdModel,\n rooms: rooms.map(declared),\n capabilities,\n providerLimits,\n retention,\n origins,\n };\n }\n\n return {\n setRooms(next) {\n rooms = [...next];\n retain(rooms);\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, 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', text: '', 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 kind: 'rejected',\n text: '',\n }),\n request,\n );\n },\n };\n}\n"],"names":["ROOM_CONTRACT_VERSION","MD_MODEL","named","source","paths","taken","path","value","undefined","resolveScript","answer","fallback","request","createMemoryAdapter","options","rooms","mdModel","supportedVersions","capabilities","providerLimits","retention","history","outcome","refreshHorizon","origins","pageSize","scripts","served","Map","refreshPages","retain","entries","room","versions","get","locator","set","roomVersion","declared","name","writeGrants","providerOwnedPaths","page","from","Object","keys","documents","sort","size","length","slice","next","kind","revisions","binaryTargets","pageToken","String","advancement","at","current","previous","currentTargets","Set","previousTargets","changed","filter","opening","target","has","removals","discovery","map","setRooms","script","operation","authorize","discover","_authorization","bootstrap","find","entry","Number","refresh","continuation","fromRoomVersion","Error","mutate","text","affected","action"],"mappings":"AAAA,SACEA,qBAAqB,QAmBhB,eAAe;AACtB,SAASC,QAAQ,QAAQ,kBAAkB;AAgC3C,SAASC,MACPC,MAAwC,EACxCC,KAAwB;IAExB,MAAMC,QAAgC,CAAC;IACvC,KAAK,MAAMC,QAAQF,MAAO;QACxB,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BAAEe,MAAM;oBAAgB;gBACjC;gBACA,MAAMT,OAAOhB,OAAOO,GAAG,CAACF,KAAKG,OAAO,GAAGD,IAAItB,QAAQwE,eAAe;gBAClE,IAAIzC,SAASnC,WAAW,OAAO;oBAAE4C,MAAM;gBAAiB;gBACxD,OAAOK,YAAYzB,MAAMW,MAAM;YACjC,GACA/B;QAEJ;QACA,MAAM0E,QAAOT,cAA6B,EAAEjE,OAAwB;YAClE,OAAOH,cACLiB,QAAQ4D,MAAM,EACd;gBACE,MAAMtD,OAAOjB,MAAMgE,IAAI,CAAC,CAACC,QAAUA,MAAM7C,OAAO,KAAKvB,QAAQuB,OAAO;gBACpE,IAAIH,SAASxB,WAAW;oBACtB,OAAO;wBAAE4C,MAAM;wBAAqBjB,SAASvB,QAAQuB,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBAAEiB,MAAM;oBAAYmC,MAAM;oBAAIC,UAAU,CAAC;gBAAE;YACpD,GACA5E;QAEJ;QACA,MAAMS,SAAQwD,cAA6B,EAAEjE,OAAuB;YAClE,OAAOH,cACLiB,QAAQL,OAAO,EACf;gBACE,MAAMW,OAAOjB,MAAMgE,IAAI,CAAC,CAACC,QAAUA,MAAM7C,OAAO,KAAKvB,QAAQuB,OAAO;gBACpE,IAAIH,SAASxB,WAAW;oBACtB,OAAO;wBAAE4C,MAAM;wBAAqBjB,SAASvB,QAAQuB,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBACLiB,MAAM;oBACNC,WAAW,EAAE;gBACf;YACF,GACAzC;QAEJ;QACA,MAAM6E,QAAOZ,cAA6B,EAAEjE,OAAsB;YAChE,OAAOH,cACLiB,QAAQ+D,MAAM,EACd,IAAO,CAAA;oBACLrC,MAAM;oBACNmC,MAAM;gBACR,CAAA,GACA3E;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,OAAOC,QAAQ,CAACF,UAAUP,OAAO,CAACE,OAAO,KAAKK,UAAUP,OAAO,CAACE,OAAO,GAAG,GAAG;QAC/E,OAAOK;IACT;IACA,MAAM,IAAIG,MAAM;AAClB;AA8CA,SAASC,MACPC,MAAwC,EACxCC,KAAwB;IAExB,MAAMC,QAAgC,CAAC;IACvC,KAAK,MAAMC,QAAQF,MAAO;QACxB,MAAMP,QAAQM,MAAM,CAACG,KAAK;QAC1B,IAAIT,UAAUU,WAAWF,KAAK,CAACC,KAAK,GAAGT;IACzC;IACA,OAAOQ;AACT;AAEA,eAAeG,cACbC,MAAgC,EAChCC,QAA8B,EAC9BC,OAAU;IAEV,IAAIF,WAAWF,WAAW,OAAOG;IACjC,OAAO,OAAOD,WAAW,aAAa,AAACA,OAAwCE,WAAWF;AAC5F;AAEA,OAAO,SAASG,oBAAoBC,UAAgC,CAAC,CAAC;IACpE,IAAIC,QAAQD,QAAQC,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QAAUA,MAAMQ,OAAO,KAAKlC,QAAQkC,OAAO;gBACpE,IAAIH,SAASnC,WAAW;oBACtB,OAAO;wBAAEf,MAAM;wBAAqBqD,SAASlC,QAAQkC,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBAAErD,MAAM;oBAAY8F,MAAM;oBAAuBC,QAAQ,CAAC;oBAAG6C,UAAU,CAAC;gBAAE;YACnF,GACAzH;QAEJ;QACA,MAAMpB,SAAQiI,cAA6B,EAAE7G,OAAuB;YAClE,OAAOH,cACLY,QAAQ7B,OAAO,EACf;gBACE,MAAMmD,OAAO5B,MAAM2G,IAAI,CAAC,CAACpF,QAAUA,MAAMQ,OAAO,KAAKlC,QAAQkC,OAAO;gBACpE,IAAIH,SAASnC,WAAW;oBACtB,OAAO;wBAAEf,MAAM;wBAAqBqD,SAASlC,QAAQkC,OAAO;oBAAC;gBAC/D;gBACA,OAAO;oBACLrD,MAAM;oBACNyE,WAAW,EAAE;gBACf;YACF,GACAtD;QAEJ;QACA,MAAM0H,QAAOb,cAA6B,EAAE7G,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"}
|
package/dist/model.d.ts
ADDED
|
@@ -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,CAAA;CAAE,GACzD;IACE,MAAM,EAAE,S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AAM,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"}
|
package/dist/outcome.d.ts
CHANGED
|
@@ -1,30 +1,37 @@
|
|
|
1
|
+
import type { ActionResult, ProviderRefusal, RetryableRefusal } from './adapter.js';
|
|
1
2
|
import type { ChangeBatch } from './change.js';
|
|
2
3
|
export type AffectedState = Readonly<Record<string, string>>;
|
|
4
|
+
export type CallResult = ActionResult | {
|
|
5
|
+
kind: 'undeclared';
|
|
6
|
+
};
|
|
3
7
|
export type QueueOutcome = {
|
|
4
8
|
kind: 'pending';
|
|
5
|
-
} | {
|
|
9
|
+
} | (ProviderRefusal & {
|
|
6
10
|
kind: 'conflicted';
|
|
7
|
-
roomVersion
|
|
11
|
+
roomVersion?: string;
|
|
8
12
|
affected: AffectedState;
|
|
9
|
-
|
|
10
|
-
} | {
|
|
13
|
+
}) | (ProviderRefusal & {
|
|
11
14
|
kind: 'rejected';
|
|
12
15
|
affected: AffectedState;
|
|
13
|
-
|
|
14
|
-
} | {
|
|
16
|
+
}) | RetryableRefusal | {
|
|
15
17
|
kind: 'expired';
|
|
16
18
|
};
|
|
17
19
|
export type AcceptedOutcome = {
|
|
18
20
|
kind: 'accepted';
|
|
19
21
|
roomVersion: string;
|
|
20
|
-
author
|
|
21
|
-
time
|
|
22
|
+
author?: string;
|
|
23
|
+
time?: string;
|
|
22
24
|
};
|
|
23
25
|
export type SubmissionOutcome = QueueOutcome | AcceptedOutcome;
|
|
24
26
|
export type QueueEntry = {
|
|
25
27
|
readonly batch: ChangeBatch;
|
|
26
28
|
readonly outcome: QueueOutcome;
|
|
27
29
|
};
|
|
28
|
-
export
|
|
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;
|
|
29
36
|
export declare function queuedOutcome(outcome: SubmissionOutcome | undefined): QueueOutcome;
|
|
30
37
|
//# sourceMappingURL=outcome.d.ts.map
|
package/dist/outcome.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7D,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;
|
|
1
|
+
{"version":3,"file":"outcome.d.ts","sourceRoot":"","sources":["../src/outcome.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACpF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CA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AAa,CAAC,OAAO,EAAE,iBAAiB,GAAG,SAAS,GAAG,YAAY,CAKlF"}
|
package/dist/outcome.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
export function refused(outcome) {
|
|
2
2
|
return outcome?.kind === 'conflicted' || outcome?.kind === 'rejected' || outcome?.kind === 'expired';
|
|
3
3
|
}
|
|
4
|
+
export function withheldUntilReset(outcome, at) {
|
|
5
|
+
return outcome?.kind === 'retryable-refusal' && outcome.reset !== undefined && at < Date.parse(outcome.reset);
|
|
6
|
+
}
|
|
7
|
+
export function refusalOf(outcome) {
|
|
8
|
+
if (outcome.kind === 'expired') return null;
|
|
9
|
+
return {
|
|
10
|
+
code: outcome.code,
|
|
11
|
+
fields: outcome.fields
|
|
12
|
+
};
|
|
13
|
+
}
|
|
4
14
|
export function queuedOutcome(outcome) {
|
|
5
15
|
if (outcome === undefined || outcome.kind === 'accepted' || outcome.kind === 'pending') {
|
|
6
16
|
return {
|
package/dist/outcome.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["/workspace/packages/mdruntime/src/outcome.ts"],"sourcesContent":["import type { ChangeBatch } from './change.js';\n\nexport type AffectedState = Readonly<Record<string, string>>;\n\nexport type QueueOutcome =\n | { kind: 'pending' }\n | {\n kind: 'conflicted';\n roomVersion
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/outcome.ts"],"sourcesContent":["import type { ActionResult, ProviderRefusal, RetryableRefusal } from './adapter.js';\nimport type { ChangeBatch } from './change.js';\n\nexport type AffectedState = Readonly<Record<string, string>>;\n\nexport type CallResult = ActionResult | { kind: 'undeclared' };\n\nexport type QueueOutcome =\n | { kind: 'pending' }\n | (ProviderRefusal & {\n kind: 'conflicted';\n roomVersion?: string;\n affected: AffectedState;\n })\n | (ProviderRefusal & {\n kind: 'rejected';\n affected: AffectedState;\n })\n | RetryableRefusal\n | { kind: 'expired' };\n\nexport type AcceptedOutcome = {\n kind: 'accepted';\n roomVersion: string;\n author?: string;\n time?: string;\n};\n\nexport type SubmissionOutcome = QueueOutcome | AcceptedOutcome;\n\nexport type QueueEntry = {\n readonly batch: ChangeBatch;\n readonly outcome: QueueOutcome;\n};\n\nexport type RefusedOutcome = Extract<QueueOutcome, { kind: 'conflicted' | 'rejected' | 'expired' }>;\n\nexport function refused(outcome: SubmissionOutcome | undefined): outcome is RefusedOutcome {\n return (\n outcome?.kind === 'conflicted' || outcome?.kind === 'rejected' || outcome?.kind === 'expired'\n );\n}\n\nexport function withheldUntilReset(outcome: SubmissionOutcome | undefined, at: number): boolean {\n return (\n outcome?.kind === 'retryable-refusal' &&\n outcome.reset !== undefined &&\n at < Date.parse(outcome.reset)\n );\n}\n\nexport function refusalOf(outcome: RefusedOutcome): ProviderRefusal | null {\n if (outcome.kind === 'expired') return null;\n return { code: outcome.code, fields: outcome.fields };\n}\n\nexport function queuedOutcome(outcome: SubmissionOutcome | undefined): QueueOutcome {\n if (outcome === undefined || outcome.kind === 'accepted' || outcome.kind === 'pending') {\n return { kind: 'pending' };\n }\n return outcome;\n}\n"],"names":["refused","outcome","kind","withheldUntilReset","at","reset","undefined","Date","parse","refusalOf","code","fields","queuedOutcome"],"mappings":"AAqCA,OAAO,SAASA,QAAQC,OAAsC;IAC5D,OACEA,SAASC,SAAS,gBAAgBD,SAASC,SAAS,cAAcD,SAASC,SAAS;AAExF;AAEA,OAAO,SAASC,mBAAmBF,OAAsC,EAAEG,EAAU;IACnF,OACEH,SAASC,SAAS,uBAClBD,QAAQI,KAAK,KAAKC,aAClBF,KAAKG,KAAKC,KAAK,CAACP,QAAQI,KAAK;AAEjC;AAEA,OAAO,SAASI,UAAUR,OAAuB;IAC/C,IAAIA,QAAQC,IAAI,KAAK,WAAW,OAAO;IACvC,OAAO;QAAEQ,MAAMT,QAAQS,IAAI;QAAEC,QAAQV,QAAQU,MAAM;IAAC;AACtD;AAEA,OAAO,SAASC,cAAcX,OAAsC;IAClE,IAAIA,YAAYK,aAAaL,QAAQC,IAAI,KAAK,cAAcD,QAAQC,IAAI,KAAK,WAAW;QACtF,OAAO;YAAEA,MAAM;QAAU;IAC3B;IACA,OAAOD;AACT"}
|
package/dist/query.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { QueryOptions, QueryResult } from '@agentshouse/query';
|
|
2
|
+
import type { Document } from '@agentshouse/mdmodel';
|
|
3
|
+
import type { TypesResult } from './model.js';
|
|
4
|
+
export type QueryInput = {
|
|
5
|
+
room: string;
|
|
6
|
+
roomVersion: string;
|
|
7
|
+
documents: Readonly<Record<string, Document>>;
|
|
8
|
+
model: TypesResult;
|
|
9
|
+
typedSelection: TypesResult | null;
|
|
10
|
+
};
|
|
11
|
+
export type QueryBinding = (rooms: readonly QueryInput[], options: QueryOptions) => QueryResult;
|
|
12
|
+
export declare function rawQuery(rooms: readonly QueryInput[]): QueryResult;
|
|
13
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../src/query.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAE9C,MAAM,MAAM,UAAU,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC,CAAC;IAC9C,KAAK,EAAE,WAAW,CAAC;IACnB,cAAc,EAAE,WAAW,GAAG,IAAI,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,EAAE,OAAO,EAAE,YAAY,KAAK,WAAW,CAAC;AAChG,wBAAgB,QAAQ,CAAC,KAAK,EAAE,SAAS,UAAU,EAAE,GAAG,WAAW,CAgBlE"}
|
package/dist/query.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export function rawQuery(rooms) {
|
|
2
|
+
return {
|
|
3
|
+
roomVersions: Object.fromEntries(rooms.map((room)=>[
|
|
4
|
+
room.room,
|
|
5
|
+
room.roomVersion
|
|
6
|
+
])),
|
|
7
|
+
groups: null,
|
|
8
|
+
documents: rooms.flatMap((room)=>Object.entries(room.documents).filter(([path])=>path.endsWith('.md')).map(([path, document])=>({
|
|
9
|
+
...structuredClone(document),
|
|
10
|
+
type: document.type ?? 'any',
|
|
11
|
+
room: room.room,
|
|
12
|
+
path,
|
|
13
|
+
backlinks: []
|
|
14
|
+
})))
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/workspace/packages/mdruntime/src/query.ts"],"sourcesContent":["import type { QueryOptions, QueryResult } from '@agentshouse/query';\nimport type { Document } from '@agentshouse/mdmodel';\nimport type { TypesResult } from './model.js';\n\nexport type QueryInput = {\n room: string;\n roomVersion: string;\n documents: Readonly<Record<string, Document>>;\n model: TypesResult;\n typedSelection: TypesResult | null;\n};\nexport type QueryBinding = (rooms: readonly QueryInput[], options: QueryOptions) => QueryResult;\nexport function rawQuery(rooms: readonly QueryInput[]): QueryResult {\n return {\n roomVersions: Object.fromEntries(rooms.map((room) => [room.room, room.roomVersion])),\n groups: null,\n documents: rooms.flatMap((room) =>\n Object.entries(room.documents)\n .filter(([path]) => path.endsWith('.md'))\n .map(([path, document]) => ({\n ...structuredClone(document),\n type: document.type ?? 'any',\n room: room.room,\n path,\n backlinks: [],\n })),\n ),\n };\n}\n"],"names":["rawQuery","rooms","roomVersions","Object","fromEntries","map","room","roomVersion","groups","documents","flatMap","entries","filter","path","endsWith","document","structuredClone","type","backlinks"],"mappings":"AAYA,OAAO,SAASA,SAASC,KAA4B;IACnD,OAAO;QACLC,cAAcC,OAAOC,WAAW,CAACH,MAAMI,GAAG,CAAC,CAACC,OAAS;gBAACA,KAAKA,IAAI;gBAAEA,KAAKC,WAAW;aAAC;QAClFC,QAAQ;QACRC,WAAWR,MAAMS,OAAO,CAAC,CAACJ,OACxBH,OAAOQ,OAAO,CAACL,KAAKG,SAAS,EAC1BG,MAAM,CAAC,CAAC,CAACC,KAAK,GAAKA,KAAKC,QAAQ,CAAC,QACjCT,GAAG,CAAC,CAAC,CAACQ,MAAME,SAAS,GAAM,CAAA;oBAC1B,GAAGC,gBAAgBD,SAAS;oBAC5BE,MAAMF,SAASE,IAAI,IAAI;oBACvBX,MAAMA,KAAKA,IAAI;oBACfO;oBACAK,WAAW,EAAE;gBACf,CAAA;IAEN;AACF"}
|
package/dist/refresh.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AttachedModelBinding } from './model.js';
|
|
1
2
|
import type { Adapter, AdapterFailure, Authorization } from './adapter.js';
|
|
2
3
|
import { type ConfirmedLayer } from './replica.js';
|
|
3
4
|
import { type Unconfirmed } from './transfer.js';
|
|
@@ -9,5 +10,5 @@ export type RefreshOutcome = {
|
|
|
9
10
|
} | {
|
|
10
11
|
kind: 'beyond-horizon';
|
|
11
12
|
} | Unconfirmed | AdapterFailure;
|
|
12
|
-
export declare function refreshRoom(adapter: Adapter, authorization: Authorization, confirmed: ConfirmedLayer): Promise<RefreshOutcome>;
|
|
13
|
+
export declare function refreshRoom(adapter: Adapter, authorization: Authorization, confirmed: ConfirmedLayer, binding: AttachedModelBinding | null): Promise<RefreshOutcome>;
|
|
13
14
|
//# sourceMappingURL=refresh.d.ts.map
|
package/dist/refresh.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AACxF,OAAO,
|
|
1
|
+
{"version":3,"file":"refresh.d.ts","sourceRoot":"","sources":["../src/refresh.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAC;AACvD,OAAO,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,aAAa,EAAe,MAAM,cAAc,CAAC;AACxF,OAAO,EAAc,KAAK,cAAc,EAAE,MAAM,cAAc,CAAC;AAC/D,OAAO,EAAe,KAAK,WAAW,EAAE,MAAM,eAAe,CAAC;AAE9D,MAAM,MAAM,cAAc,GACtB;IAAE,IAAI,EAAE,eAAe,CAAA;CAAE,GACzB;IAAE,IAAI,EAAE,UAAU,CAAC;IAAC,SAAS,EAAE,cAAc,CAAA;CAAE,GAC/C;IAAE,IAAI,EAAE,gBAAgB,CAAA;CAAE,GAC1B,WAAW,GACX,cAAc,CAAC;AAEnB,wBAAsB,WAAW,CAC/B,OAAO,EAAE,OAAO,EAChB,aAAa,EAAE,aAAa,EAC5B,SAAS,EAAE,cAAc,EACzB,OAAO,EAAE,oBAAoB,GAAG,IAAI,GACnC,OAAO,CAAC,cAAc,CAAC,CAsDzB"}
|