@agentshouse/mdruntime 0.1.0-alpha.37 → 0.1.0-alpha.39

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/memory.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ModelResult } from './model.js';
2
- import { type AcceptedMessage, type ActionResult, type Adapter, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type MdModelIdentity, type ProviderLimit, type Retention, type RoomVersionNotification } from './adapter.js';
2
+ import { type AcceptedMessage, type ActionResult, type Adapter, type Capability, type ConversationAction, type ConversationEvent, type DiscoveredRoom, type MdModelIdentity, type ProviderLimit, type Retention, type RoomVersionNotification, type ServiceMode } from './adapter.js';
3
3
  export type MemoryRoom = DiscoveredRoom & {
4
4
  model?: ModelResult;
5
5
  selectionModel?: ModelResult;
@@ -29,9 +29,9 @@ export type MemoryAdapter = Adapter & {
29
29
  script(operation: keyof Adapter, answer: unknown): void;
30
30
  notifyRoomVersion(notification: RoomVersionNotification): void;
31
31
  notifyConversation(event: ConversationEvent): void;
32
+ notifyServiceMode(mode: ServiceMode): void;
32
33
  selectedRooms(): readonly string[];
33
34
  replicatedConversations(): readonly string[];
34
- viewedConversations(): readonly string[];
35
35
  };
36
36
  export declare function createMemoryAdapter(options?: MemoryAdapterOptions): MemoryAdapter;
37
37
  //# sourceMappingURL=memory.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAEL,KAAK,eAAe,EAEpB,KAAK,YAAY,EACjB,KAAK,OAAO,EAIZ,KAAK,UAAU,EACf,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAGtB,KAAK,cAAc,EAGnB,KAAK,eAAe,EAGpB,KAAK,aAAa,EAGlB,KAAK,SAAS,EACd,KAAK,uBAAuB,EAC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{}) {
45
45
  const refreshPages = new Map();
46
46
  const observers = new Set();
47
47
  const listeners = new Set();
48
+ const modeObservers = new Set();
48
49
  const scripted = new Map();
49
50
  const unsealed = new Map();
50
51
  const sealed = new Set();
51
52
  const historyPageSize = options.historyPageSize;
52
53
  let selected = [];
53
54
  let replicated = [];
54
- let viewed = [];
55
55
  let issued = 0;
56
56
  function scriptConversations(entries) {
57
57
  scripted.clear();
@@ -247,30 +247,23 @@ export function createMemoryAdapter(options = {}) {
247
247
  sealed.add(event.message.turn);
248
248
  unsealed.delete(event.message.turn);
249
249
  }
250
- const delivered = event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;
251
- if (!delivered.includes(event.conversation)) return;
252
250
  for (const listener of listeners)listener(event);
253
251
  },
252
+ notifyServiceMode (mode) {
253
+ for (const observer of modeObservers)observer(mode);
254
+ },
254
255
  selectedRooms () {
255
256
  return selected;
256
257
  },
257
258
  replicatedConversations () {
258
259
  return replicated;
259
260
  },
260
- viewedConversations () {
261
- return viewed;
262
- },
263
261
  conversations: {
264
262
  replicate (next) {
265
263
  replicated = [
266
264
  ...next
267
265
  ];
268
266
  },
269
- view (next) {
270
- viewed = [
271
- ...next
272
- ];
273
- },
274
267
  observe (notify) {
275
268
  listeners.add(notify);
276
269
  return ()=>{
@@ -278,6 +271,14 @@ export function createMemoryAdapter(options = {}) {
278
271
  };
279
272
  }
280
273
  },
274
+ serviceMode: {
275
+ observe (notify) {
276
+ modeObservers.add(notify);
277
+ return ()=>{
278
+ modeObservers.delete(notify);
279
+ };
280
+ }
281
+ },
281
282
  roomVersions: {
282
283
  select (locators) {
283
284
  selected = [
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/memory.ts"],"sourcesContent":["import type { ModelResult } from './model.js';\nimport {\n ROOM_CONTRACT_VERSION,\n type AcceptedMessage,\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 ConversationHistoryPage,\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 AcceptedMessage[];\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 replicatedConversations(): 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 replicated: 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, after: unknown): ActionResult {\n const messages = conversation.messages ?? [];\n const first =\n typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;\n const from = first === -1 ? messages.length : first;\n const page = messages.slice(from, from + (historyPageSize ?? messages.length));\n const last = page.at(-1);\n const result: ConversationHistoryPage = {\n messages: page,\n ...(last !== undefined && from + page.length < messages.length\n ? { next: last.position }\n : {}),\n };\n return { kind: 'action', result };\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 after?: 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.after);\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 const delivered =\n event.kind === 'accepted-message' || event.kind === 'gap' ? replicated : viewed;\n if (!delivered.includes(event.conversation)) return;\n for (const listener of listeners) listener(event);\n },\n selectedRooms() {\n return selected;\n },\n replicatedConversations() {\n return replicated;\n },\n viewedConversations() {\n return viewed;\n },\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\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","replicated","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","after","messages","first","findIndex","message","position","last","result","conversationAction","input","code","fields","outcomes","turn","delete","cancelled","discovery","map","setRooms","setConversations","notifyRoomVersion","notification","observer","notifyConversation","event","add","delivered","includes","listener","selectedRooms","replicatedConversations","viewedConversations","replicate","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,QAwBhB,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;AA+CA,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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3,"sources":["/workspace/packages/mdruntime/src/memory.ts"],"sourcesContent":["import type { ModelResult } from './model.js';\nimport {\n ROOM_CONTRACT_VERSION,\n type AcceptedMessage,\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 ConversationHistoryPage,\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 type ServiceMode,\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 AcceptedMessage[];\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 notifyServiceMode(mode: ServiceMode): void;\n selectedRooms(): readonly string[];\n replicatedConversations(): 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 modeObservers = new Set<(mode: ServiceMode) => 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 replicated: 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, after: unknown): ActionResult {\n const messages = conversation.messages ?? [];\n const first =\n typeof after === 'string' ? messages.findIndex((message) => message.position > after) : 0;\n const from = first === -1 ? messages.length : first;\n const page = messages.slice(from, from + (historyPageSize ?? messages.length));\n const last = page.at(-1);\n const result: ConversationHistoryPage = {\n messages: page,\n ...(last !== undefined && from + page.length < messages.length\n ? { next: last.position }\n : {}),\n };\n return { kind: 'action', result };\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 after?: 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.after);\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 notifyServiceMode(mode) {\n for (const observer of modeObservers) observer(mode);\n },\n selectedRooms() {\n return selected;\n },\n replicatedConversations() {\n return replicated;\n },\n conversations: {\n replicate(next) {\n replicated = [...next];\n },\n observe(notify) {\n listeners.add(notify);\n return () => {\n listeners.delete(notify);\n };\n },\n },\n serviceMode: {\n observe(notify) {\n modeObservers.add(notify);\n return () => {\n modeObservers.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","modeObservers","scripted","unsealed","sealed","historyPageSize","selected","replicated","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","after","messages","first","findIndex","message","position","last","result","conversationAction","input","code","fields","outcomes","turn","delete","cancelled","discovery","map","setRooms","setConversations","notifyRoomVersion","notification","observer","notifyConversation","event","add","listener","notifyServiceMode","mode","selectedRooms","replicatedConversations","replicate","observe","notify","serviceMode","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,QAyBhB,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;AA+CA,SAASC,MACPC,MAAwC,EACxCC,KAAwB;IAExB,MAAMC,QAAgC,CAAC;IACvC,KAAK,MAAMC,QAAQF,MAAO;QACxB,MAAMP,QAAQM,MAAM,C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AM,EACd;gBACE,IAAI9H,QAAQsC,IAAI,CAACyF,UAAU,CAAC,kBAAkB,OAAO/C,mBAAmBhF;gBACxE,OAAO;oBAAEnB,MAAM;oBAAYqG,MAAM;oBAAqBC,QAAQ,CAAC;gBAAE;YACnE,GACAnF;QAEJ;IACF;AACF"}
package/dist/model.d.ts CHANGED
@@ -4,7 +4,7 @@ export type ModelIdentity = {
4
4
  version: string;
5
5
  };
6
6
  export type ModelSnapshot = ModelIdentity & {
7
- definitions: Readonly<Record<string, string>>;
7
+ schema: string | null;
8
8
  };
9
9
  export type ModelUnavailableReason = 'not-readable' | 'revoked' | 'not-acquired' | 'version-changed' | 'invalid';
10
10
  export type ModelResult = {
@@ -20,7 +20,6 @@ export type ModelResult = {
20
20
  };
21
21
  export type MdType = {
22
22
  name: string;
23
- path: string;
24
23
  fields: Readonly<Record<string, FieldSpec>>;
25
24
  sections: Readonly<Record<string, SectionSpec>>;
26
25
  };
@@ -1 +1 @@
1
- {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../src/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAE9F,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,CAAC;AACd,MAAM,MAAM,WAAW,GACnB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,QAAQ,EAAE,aAAa,CAAA;CAAE,GAC1C;IAAE,IAAI,EAAE,mBAAmB,CAAC;IAAC,M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AAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,GACzD;IACE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,aAAa,CAAC,OAAO,CAAC,CAAC;CAC/B,CAAC;AACN,MAAM,MAAM,WAAW,GACnB;IAAE,MAAM,EAAE,aAAa,CAAC;IAAC,MAAM,EAAE,sBAAsB,CAAA;CAAE,GACzD;IACE,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAC;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,YAAY,EAAE,aAAa,CAAC;IAC5B,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B,CAAC;AACN,MAAM,MAAM,iBAAiB,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,SAAS,GAAG,QAAQ,CAAA;CAAE,CAAC;AACpG,eAAO,MAAM,QAAQ,EAAE,UAA8D,CAAC;AACtF,wBAAgB,YAAY,CAAC,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,UAAU,GAAG,SAAS,CAGhG;AACD,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,GAAG,WAAW,CAczD;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 CHANGED
@@ -16,9 +16,8 @@ export function modelTypes(state) {
16
16
  verifiedWith: {
17
17
  ...state.verifiedWith
18
18
  },
19
- types: structuredClone(Object.values(state.types).sort((left, right)=>left.address < right.address ? -1 : left.address > right.address ? 1 : 0).map(({ name, address, fields, sections })=>({
19
+ types: structuredClone(Object.values(state.types).sort((left, right)=>left.name < right.name ? -1 : left.name > right.name ? 1 : 0).map(({ name, fields, sections })=>({
20
20
  name,
21
- path: address,
22
21
  fields,
23
22
  sections
24
23
  })))
package/dist/model.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/model.ts"],"sourcesContent":["import type { Definition, FieldSpec, SectionSpec, VerifiedModel } from '@agentshouse/mdmodel';\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';\nexport type ModelResult =\n | { kind: 'model'; snapshot: ModelSnapshot }\n | { kind: 'model-unavailable'; reason: ModelUnavailableReason }\n | { kind: 'transport-uncertainty' }\n | { kind: 'revoked-authorization' };\nexport type MdType = {\n name: string;\n path: string;\n fields: Readonly<Record<string, FieldSpec>>;\n sections: Readonly<Record<string, SectionSpec>>;\n};\nexport type ModelState =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n snapshot: ModelSnapshot;\n verifiedWith: ModelIdentity;\n types: VerifiedModel['types'];\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 ValidationReceipt = { identity: string; version: string; source: 'current' | 'cached' };\nexport const NO_MODEL: ModelState = { status: 'unavailable', reason: 'not-acquired' };\nexport function definitionOf(state: ModelState, type: string | undefined): Definition | undefined {\n if (state.status === 'unavailable' || type === undefined) return undefined;\n return Object.hasOwn(state.types, type) ? state.types[type] : undefined;\n}\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(\n Object.values(state.types)\n .sort((left, right) =>\n left.address < right.address ? -1 : left.address > right.address ? 1 : 0,\n )\n .map(({ name, address, fields, sections }) => ({\n name,\n path: address,\n fields,\n sections,\n })),\n ),\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","definitionOf","state","type","undefined","Object","hasOwn","types","modelTypes","identity","snapshot","version","verifiedWith","structuredClone","values","sort","left","right","address","map","name","fields","sections","path","cached","sameModel"],"mappings":"AAuCA,OAAO,MAAMA,WAAuB;IAAEC,QAAQ;IAAeC,QAAQ;AAAe,EAAE;AACtF,OAAO,SAASC,aAAaC,KAAiB,EAAEC,IAAwB;IACtE,IAAID,MAAMH,MAAM,KAAK,iBAAiBI,SAASC,WAAW,OAAOA;IACjE,OAAOC,OAAOC,MAAM,CAACJ,MAAMK,KAAK,EAAEJ,QAAQD,MAAMK,KAAK,CAACJ,KAAK,GAAGC;AAChE;AACA,OAAO,SAASI,WAAWN,KAAiB;IAC1C,OAAOA,MAAMH,MAAM,KAAK,gBACpB;QAAE,GAAGG,KAAK;IAAC,IACX;QACEH,QAAQG,MAAMH,MAAM;QACpBU,UAAUP,MAAMQ,QAAQ,CAACD,QAAQ;QACjCE,SAAST,MAAMQ,QAAQ,CAACC,OAAO;QAC/BC,cAAc;YAAE,GAAGV,MAAMU,YAAY;QAAC;QACtCL,OAAOM,gBACLR,OAAOS,MAAM,CAACZ,MAAMK,KAAK,EACtBQ,IAAI,CAAC,CAACC,MAAMC,QACXD,KAAKE,OAAO,GAAGD,MAAMC,OAAO,GAAG,CAAC,IAAIF,KAAKE,OAAO,GAAGD,MAAMC,OAAO,GAAG,IAAI,GAExEC,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAEF,OAAO,EAAEG,MAAM,EAAEC,QAAQ,EAAE,GAAM,CAAA;gBAC7CF;gBACAG,MAAML;gBACNG;gBACAC;YACF,CAAA;IAEN;AACN;AACA,OAAO,SAASE,OAAOtB,KAAiB;IACtC,OAAOA,MAAMH,MAAM,KAAK,gBAAgBG,QAAQ;QAAE,GAAGA,KAAK;QAAEH,QAAQ;IAAS;AAC/E;AACA,OAAO,SAAS0B,UAAUT,IAAmB,EAAEC,KAAoB;IACjE,OAAOD,KAAKP,QAAQ,KAAKQ,MAAMR,QAAQ,IAAIO,KAAKL,OAAO,KAAKM,MAAMN,OAAO;AAC3E"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/model.ts"],"sourcesContent":["import type { Definition, FieldSpec, SectionSpec, VerifiedModel } from '@agentshouse/mdmodel';\n\nexport type ModelIdentity = { identity: string; version: string };\nexport type ModelSnapshot = ModelIdentity & { schema: string | null };\nexport type ModelUnavailableReason =\n | 'not-readable'\n | 'revoked'\n | 'not-acquired'\n | 'version-changed'\n | 'invalid';\nexport type ModelResult =\n | { kind: 'model'; snapshot: ModelSnapshot }\n | { kind: 'model-unavailable'; reason: ModelUnavailableReason }\n | { kind: 'transport-uncertainty' }\n | { kind: 'revoked-authorization' };\nexport type MdType = {\n name: string;\n fields: Readonly<Record<string, FieldSpec>>;\n sections: Readonly<Record<string, SectionSpec>>;\n};\nexport type ModelState =\n | { status: 'unavailable'; reason: ModelUnavailableReason }\n | {\n status: 'current' | 'cached';\n snapshot: ModelSnapshot;\n verifiedWith: ModelIdentity;\n types: VerifiedModel['types'];\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 ValidationReceipt = { identity: string; version: string; source: 'current' | 'cached' };\nexport const NO_MODEL: ModelState = { status: 'unavailable', reason: 'not-acquired' };\nexport function definitionOf(state: ModelState, type: string | undefined): Definition | undefined {\n if (state.status === 'unavailable' || type === undefined) return undefined;\n return Object.hasOwn(state.types, type) ? state.types[type] : undefined;\n}\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(\n Object.values(state.types)\n .sort((left, right) => (left.name < right.name ? -1 : left.name > right.name ? 1 : 0))\n .map(({ name, fields, sections }) => ({ name, fields, sections })),\n ),\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","definitionOf","state","type","undefined","Object","hasOwn","types","modelTypes","identity","snapshot","version","verifiedWith","structuredClone","values","sort","left","right","name","map","fields","sections","cached","sameModel"],"mappings":"AAsCA,OAAO,MAAMA,WAAuB;IAAEC,QAAQ;IAAeC,QAAQ;AAAe,EAAE;AACtF,OAAO,SAASC,aAAaC,KAAiB,EAAEC,IAAwB;IACtE,IAAID,MAAMH,MAAM,KAAK,iBAAiBI,SAASC,WAAW,OAAOA;IACjE,OAAOC,OAAOC,MAAM,CAACJ,MAAMK,KAAK,EAAEJ,QAAQD,MAAMK,KAAK,CAACJ,KAAK,GAAGC;AAChE;AACA,OAAO,SAASI,WAAWN,KAAiB;IAC1C,OAAOA,MAAMH,MAAM,KAAK,gBACpB;QAAE,GAAGG,KAAK;IAAC,IACX;QACEH,QAAQG,MAAMH,MAAM;QACpBU,UAAUP,MAAMQ,QAAQ,CAACD,QAAQ;QACjCE,SAAST,MAAMQ,QAAQ,CAACC,OAAO;QAC/BC,cAAc;YAAE,GAAGV,MAAMU,YAAY;QAAC;QACtCL,OAAOM,gBACLR,OAAOS,MAAM,CAACZ,MAAMK,KAAK,EACtBQ,IAAI,CAAC,CAACC,MAAMC,QAAWD,KAAKE,IAAI,GAAGD,MAAMC,IAAI,GAAG,CAAC,IAAIF,KAAKE,IAAI,GAAGD,MAAMC,IAAI,GAAG,IAAI,GAClFC,GAAG,CAAC,CAAC,EAAED,IAAI,EAAEE,MAAM,EAAEC,QAAQ,EAAE,GAAM,CAAA;gBAAEH;gBAAME;gBAAQC;YAAS,CAAA;IAErE;AACN;AACA,OAAO,SAASC,OAAOpB,KAAiB;IACtC,OAAOA,MAAMH,MAAM,KAAK,gBAAgBG,QAAQ;QAAE,GAAGA,KAAK;QAAEH,QAAQ;IAAS;AAC/E;AACA,OAAO,SAASwB,UAAUP,IAAmB,EAAEC,KAAoB;IACjE,OAAOD,KAAKP,QAAQ,KAAKQ,MAAMR,QAAQ,IAAIO,KAAKL,OAAO,KAAKM,MAAMN,OAAO;AAC3E"}
package/dist/store.js CHANGED
@@ -11,7 +11,7 @@ const CONVERSATIONS = 'conversations';
11
11
  const MESSAGES = 'messages';
12
12
  const CHAT_DRAFTS = 'chatDrafts';
13
13
  const CURRENT = 'current';
14
- const SCHEMA = 13;
14
+ const SCHEMA = 14;
15
15
  function settled(request) {
16
16
  return new Promise((resolve, reject)=>{
17
17
  request.onsuccess = ()=>resolve(request.result);
package/dist/store.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/store.ts"],"sourcesContent":["import type { ModelState } from './model.js';\nimport type {\n Capability,\n Discovery,\n OperationScopes,\n ProviderLimit,\n ReplicaAdmission,\n TypedSelection,\n} from './adapter.js';\nimport type { AcceptedMessage } from './adapter.js';\nimport type { ChangeBatch } from './change.js';\nimport type { ChatDraftFile } from './file.js';\nimport type { Submission, SubmissionOutcome } from './outcome.js';\nimport type { RoomDraftRecord, SavedDraft } from './room-draft.js';\n\nconst DATABASE = 'mdruntime';\nconst ROOMS = 'rooms';\nconst DOCUMENTS = 'documents';\nconst BINARY_TARGETS = 'binaryTargets';\nconst PENDING_CHANGES = 'pendingChanges';\nconst OUTCOMES = 'outcomes';\nconst DECLARATIONS = 'declarations';\nconst ROOM_DRAFTS = 'roomDrafts';\nconst PRESENTATION = 'presentation';\nconst CONVERSATIONS = 'conversations';\nconst MESSAGES = 'messages';\nconst CHAT_DRAFTS = 'chatDrafts';\nconst CURRENT = 'current';\nconst SCHEMA = 13;\n\nexport type ReplicaRecord = {\n collectionRoot: string;\n locator: string;\n name: string;\n operations: OperationScopes;\n replica: ReplicaAdmission;\n model: ModelState;\n attachedModel: import('./model.js').ModelIdentity | null;\n typedSelection: TypedSelection | null;\n selectionModel: ModelState;\n providerOwnedPaths: readonly string[];\n roomVersion: string;\n documents: Readonly<Record<string, string>>;\n binaryTargets: readonly string[];\n revisions: Readonly<Record<string, string>>;\n};\n\ntype RoomRecord = Omit<ReplicaRecord, 'documents' | 'binaryTargets' | 'revisions'> & {\n order: readonly string[];\n};\n\ntype DocumentRecord = {\n locator: string;\n path: string;\n content: string;\n revision: string | null;\n};\n\ntype BinaryTargetRecord = { locator: string; path: string; revision: string | null };\n\nexport type PendingState = {\n readonly drafts: readonly SavedDraft[];\n readonly submission: Submission;\n readonly lost: boolean;\n readonly upload?: unknown;\n};\n\ntype PendingChangeRecord = PendingState & {\n locator: string;\n id: string;\n batch: ChangeBatch;\n};\n\nexport type OutcomeRecord = {\n locator: string;\n id: string;\n outcome: SubmissionOutcome;\n};\n\ntype DeclarationRecord = {\n lastCompleted: string | null;\n generation: string | null;\n providerLimits: readonly ProviderLimit[];\n capabilities: readonly Capability[];\n slots: NonNullable<Discovery['slots']>;\n};\n\nexport type QueueRecord = {\n locator: string;\n pending: readonly { batch: ChangeBatch; state: PendingState }[];\n};\n\nexport type PresentationRecord = {\n app: string;\n value: unknown;\n};\n\ntype ConversationRecord = {\n conversation: string;\n read: string | null;\n};\n\ntype MessageRecord = AcceptedMessage & { conversation: string };\n\nexport type HeldConversation = {\n conversation: string;\n read: string | null | undefined;\n messages: readonly AcceptedMessage[];\n};\n\nexport type ConversationWrite = {\n conversation: string;\n messages: readonly AcceptedMessage[];\n read?: string | null;\n sealed?: boolean;\n};\n\nexport type ChatDraftRecord = {\n conversation: string;\n text: string;\n files: readonly ChatDraftFile[];\n turn: string | null;\n};\n\nexport type RecordWrite = {\n next: ReplicaRecord;\n previous: ReplicaRecord | null;\n queue: readonly ChangeBatch[];\n previousQueue?: readonly ChangeBatch[];\n saved?: readonly SavedDraft[];\n outcomes?: readonly { id: string; outcome: SubmissionOutcome | null }[];\n roomDrafts?: readonly RoomDraftRecord[];\n consumedRoomDrafts?: readonly string[];\n};\n\nexport type RuntimeStore = {\n all(): Promise<readonly ReplicaRecord[]>;\n write(input: RecordWrite): Promise<void>;\n revokeModels(\n records: readonly { record: ReplicaRecord; queue: readonly ChangeBatch[] }[],\n ): Promise<void>;\n lastCompleted(): Promise<string | null>;\n complete(at: string): Promise<void>;\n providerLimits(): Promise<readonly ProviderLimit[]>;\n capabilities(): Promise<readonly Capability[]>;\n slots(): Promise<NonNullable<Discovery['slots']>>;\n declare(\n limits: readonly ProviderLimit[],\n capabilities: readonly Capability[],\n slots: NonNullable<Discovery['slots']>,\n ): Promise<void>;\n queues(): Promise<readonly QueueRecord[]>;\n outcomes(): Promise<readonly OutcomeRecord[]>;\n submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;\n keepUpload(locator: string, id: string, upload: unknown): Promise<void>;\n roomDrafts(): Promise<readonly RoomDraftRecord[]>;\n presentation(): Promise<readonly PresentationRecord[]>;\n present(record: PresentationRecord): Promise<void>;\n conversations(): Promise<readonly HeldConversation[]>;\n keepMessages(write: ConversationWrite): Promise<void>;\n dropConversations(conversations: readonly string[]): Promise<void>;\n chatDrafts(): Promise<readonly ChatDraftRecord[]>;\n keepChatDraft(record: ChatDraftRecord): Promise<void>;\n dropChatDraft(conversation: string): Promise<void>;\n keepRoomDraft(record: RoomDraftRecord): Promise<void>;\n discardRoomDraft(locator: string, path: string): Promise<void>;\n dropRooms(locators: readonly string[]): Promise<void>;\n generation(): Promise<string | null>;\n rememberGeneration(value: string): Promise<void>;\n close(): void;\n};\n\nfunction settled<T>(request: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n}\n\nfunction completed(transaction: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error);\n transaction.onabort = () => reject(transaction.error);\n });\n}\n\nconst EMPTY_DECLARATIONS: DeclarationRecord = {\n lastCompleted: null,\n generation: null,\n providerLimits: [],\n capabilities: [],\n slots: [],\n};\n\nfunction declaration(database: IDBDatabase): Promise<DeclarationRecord> {\n const transaction = database.transaction(DECLARATIONS, 'readonly');\n return settled<DeclarationRecord | undefined>(\n transaction.objectStore(DECLARATIONS).get(CURRENT),\n ).then((record) => record ?? EMPTY_DECLARATIONS);\n}\n\nfunction updateDeclaration(\n database: IDBDatabase,\n update: (record: DeclarationRecord) => DeclarationRecord,\n): Promise<void> {\n const transaction = database.transaction(DECLARATIONS, 'readwrite');\n const store = transaction.objectStore(DECLARATIONS);\n const prior = store.get(CURRENT);\n prior.onsuccess = () => {\n store.put(\n update((prior.result as DeclarationRecord | undefined) ?? EMPTY_DECLARATIONS),\n CURRENT,\n );\n };\n return completed(transaction);\n}\n\nfunction amendPending(\n database: IDBDatabase,\n locator: string,\n id: string,\n amendment: Partial<PendingState>,\n): Promise<void> {\n const transaction = database.transaction(PENDING_CHANGES, 'readwrite');\n const pending = transaction.objectStore(PENDING_CHANGES);\n const request = pending.get([locator, id]);\n request.onsuccess = () => {\n const record = request.result as PendingChangeRecord | undefined;\n if (record !== undefined) pending.put({ ...record, ...amendment });\n };\n return completed(transaction);\n}\n\nfunction roomRecord(record: ReplicaRecord, queue: readonly ChangeBatch[]): RoomRecord {\n const { documents, binaryTargets, revisions, ...room } = record;\n return { ...room, order: queue.map((batch) => batch.id) };\n}\n\nfunction removeRoomEntries(store: IDBObjectStore, locator: string) {\n const keys = store.getAllKeys();\n keys.onsuccess = () => {\n for (const key of keys.result) {\n if (Array.isArray(key) && key[0] === locator) store.delete(key);\n }\n };\n}\n\nexport function removeRuntimeStore(): Promise<void> {\n return new Promise((resolve, reject) => {\n const removal = indexedDB.deleteDatabase(DATABASE);\n removal.onsuccess = () => resolve();\n removal.onerror = () => reject(removal.error);\n });\n}\n\nexport async function openRuntimeStore(): Promise<RuntimeStore> {\n const opening = indexedDB.open(DATABASE, SCHEMA);\n opening.onupgradeneeded = () => {\n const database = opening.result;\n for (const name of [...database.objectStoreNames]) database.deleteObjectStore(name);\n database.createObjectStore(ROOMS, { keyPath: 'locator' });\n database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });\n database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });\n database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });\n const outcomes = database.createObjectStore(OUTCOMES, { keyPath: 'id' });\n outcomes.createIndex('locator', 'locator');\n database.createObjectStore(DECLARATIONS);\n database.createObjectStore(ROOM_DRAFTS, { keyPath: ['locator', 'path'] });\n database.createObjectStore(PRESENTATION, { keyPath: 'app' });\n database.createObjectStore(CONVERSATIONS, { keyPath: 'conversation' });\n const messages = database.createObjectStore(MESSAGES, {\n keyPath: ['conversation', 'identity'],\n });\n messages.createIndex('conversation', 'conversation');\n database.createObjectStore(CHAT_DRAFTS, { keyPath: 'conversation' });\n };\n const database = await settled(opening);\n return {\n async all() {\n const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS], 'readonly');\n const [rooms, documents, targets] = await Promise.all([\n settled<RoomRecord[]>(transaction.objectStore(ROOMS).getAll()),\n settled<DocumentRecord[]>(transaction.objectStore(DOCUMENTS).getAll()),\n settled<BinaryTargetRecord[]>(transaction.objectStore(BINARY_TARGETS).getAll()),\n ]);\n const byRoom = new Map<string, ReplicaRecord>();\n for (const { order, ...room } of rooms) {\n byRoom.set(room.locator, { ...room, documents: {}, revisions: {}, binaryTargets: [] });\n }\n for (const document of documents) {\n const room = byRoom.get(document.locator);\n if (room === undefined) continue;\n (room.documents as Record<string, string>)[document.path] = document.content;\n if (document.revision !== null) {\n (room.revisions as Record<string, string>)[document.path] = document.revision;\n }\n }\n for (const target of targets) {\n const room = byRoom.get(target.locator);\n if (room === undefined) continue;\n (room.binaryTargets as string[]).push(target.path);\n if (target.revision !== null) {\n (room.revisions as Record<string, string>)[target.path] = target.revision;\n }\n }\n return [...byRoom.values()];\n },\n async write({\n next,\n previous,\n queue,\n previousQueue,\n saved,\n outcomes,\n roomDrafts,\n consumedRoomDrafts,\n }) {\n const transaction = database.transaction(\n [ROOMS, DOCUMENTS, BINARY_TARGETS, PENDING_CHANGES, OUTCOMES, ROOM_DRAFTS],\n 'readwrite',\n );\n transaction.objectStore(ROOMS).put(roomRecord(next, queue));\n const documents = transaction.objectStore(DOCUMENTS);\n for (const path of Object.keys(previous?.documents ?? {})) {\n if (next.documents[path] === undefined) documents.delete([next.locator, path]);\n }\n for (const [path, content] of Object.entries(next.documents)) {\n if (\n previous?.documents[path] === content &&\n previous.revisions[path] === next.revisions[path]\n )\n continue;\n documents.put({\n locator: next.locator,\n path,\n content,\n revision: next.revisions[path] ?? null,\n } satisfies DocumentRecord);\n }\n const targets = transaction.objectStore(BINARY_TARGETS);\n const beforeTargets = new Set(previous?.binaryTargets ?? []);\n const afterTargets = new Set(next.binaryTargets);\n for (const path of beforeTargets) {\n if (!afterTargets.has(path)) targets.delete([next.locator, path]);\n }\n for (const path of afterTargets) {\n if (!beforeTargets.has(path) || previous?.revisions[path] !== next.revisions[path]) {\n targets.put({\n locator: next.locator,\n path,\n revision: next.revisions[path] ?? null,\n });\n }\n }\n if (previousQueue !== undefined) {\n const pending = transaction.objectStore(PENDING_CHANGES);\n const before = new Set(previousQueue.map((batch) => batch.id));\n const after = new Set(queue.map((batch) => batch.id));\n for (const id of before) {\n if (!after.has(id)) pending.delete([next.locator, id]);\n }\n for (const batch of queue) {\n if (!before.has(batch.id)) {\n pending.put({\n locator: next.locator,\n id: batch.id,\n batch,\n drafts: saved ?? [],\n submission: { state: 'waiting' },\n lost: false,\n } satisfies PendingChangeRecord);\n }\n }\n }\n const outcomeStore = transaction.objectStore(OUTCOMES);\n for (const entry of outcomes ?? []) {\n if (entry.outcome === null) outcomeStore.delete(entry.id);\n else outcomeStore.put({ locator: next.locator, id: entry.id, outcome: entry.outcome });\n }\n const draftStore = transaction.objectStore(ROOM_DRAFTS);\n for (const path of consumedRoomDrafts ?? []) draftStore.delete([next.locator, path]);\n for (const record of roomDrafts ?? []) draftStore.put(record);\n await completed(transaction);\n },\n async revokeModels(records) {\n const transaction = database.transaction(ROOMS, 'readwrite');\n const rooms = transaction.objectStore(ROOMS);\n const revoked: ModelState = { status: 'unavailable', reason: 'revoked' };\n for (const { record, queue } of records) {\n rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }, queue));\n }\n await completed(transaction);\n },\n async lastCompleted() {\n return (await declaration(database)).lastCompleted;\n },\n complete(at) {\n return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));\n },\n async providerLimits() {\n return (await declaration(database)).providerLimits;\n },\n async capabilities() {\n return (await declaration(database)).capabilities;\n },\n async slots() {\n return (await declaration(database)).slots;\n },\n declare(limits, capabilities, slots) {\n return updateDeclaration(database, (record) => ({\n ...record,\n providerLimits: limits,\n capabilities,\n slots,\n }));\n },\n async queues() {\n const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');\n const [rooms, pending] = await Promise.all([\n settled<RoomRecord[]>(transaction.objectStore(ROOMS).getAll()),\n settled<PendingChangeRecord[]>(transaction.objectStore(PENDING_CHANGES).getAll()),\n ]);\n const byId = new Map(pending.map((record) => [`${record.locator}\\0${record.id}`, record]));\n return rooms.map((room) => ({\n locator: room.locator,\n pending: room.order.map((id) => {\n const record = byId.get(`${room.locator}\\0${id}`);\n if (record === undefined) throw new Error(`Missing Pending Change ${room.locator}/${id}`);\n const { batch, drafts, submission, lost, upload } = record;\n return { batch, state: { drafts, submission, lost, upload } };\n }),\n }));\n },\n async outcomes() {\n const transaction = database.transaction(OUTCOMES, 'readonly');\n return settled<OutcomeRecord[]>(transaction.objectStore(OUTCOMES).getAll());\n },\n submit(locator, id, submission, lost) {\n return amendPending(database, locator, id, { submission, lost });\n },\n keepUpload(locator, id, upload) {\n return amendPending(database, locator, id, { upload });\n },\n async roomDrafts() {\n const transaction = database.transaction(ROOM_DRAFTS, 'readonly');\n return settled<RoomDraftRecord[]>(transaction.objectStore(ROOM_DRAFTS).getAll());\n },\n async presentation() {\n const transaction = database.transaction(PRESENTATION, 'readonly');\n return settled<PresentationRecord[]>(transaction.objectStore(PRESENTATION).getAll());\n },\n async present(record) {\n const transaction = database.transaction(PRESENTATION, 'readwrite');\n transaction.objectStore(PRESENTATION).put(record);\n await completed(transaction);\n },\n async conversations() {\n const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');\n const [reads, messages] = await Promise.all([\n settled<ConversationRecord[]>(transaction.objectStore(CONVERSATIONS).getAll()),\n settled<MessageRecord[]>(transaction.objectStore(MESSAGES).getAll()),\n ]);\n const held = new Map<string, HeldConversation & { messages: AcceptedMessage[] }>();\n for (const { conversation, read } of reads) {\n held.set(conversation, { conversation, read, messages: [] });\n }\n for (const { conversation, ...message } of messages) {\n const entry = held.get(conversation) ?? { conversation, read: undefined, messages: [] };\n entry.messages.push(message);\n held.set(conversation, entry);\n }\n return [...held.values()];\n },\n async keepMessages({ conversation, messages, read, sealed }) {\n const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');\n const stored = transaction.objectStore(MESSAGES);\n for (const message of messages) {\n stored.put({ ...message, conversation } satisfies MessageRecord);\n }\n if (read !== undefined) {\n transaction\n .objectStore(CONVERSATIONS)\n .put({ conversation, read } satisfies ConversationRecord);\n }\n if (sealed === true) transaction.objectStore(CHAT_DRAFTS).delete(conversation);\n await completed(transaction);\n },\n async dropConversations(conversations) {\n const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');\n const messages = transaction.objectStore(MESSAGES);\n for (const conversation of conversations) {\n transaction.objectStore(CONVERSATIONS).delete(conversation);\n transaction.objectStore(CHAT_DRAFTS).delete(conversation);\n const keys = messages.index('conversation').getAllKeys(conversation);\n keys.onsuccess = () => {\n for (const key of keys.result) messages.delete(key);\n };\n }\n await completed(transaction);\n },\n async chatDrafts() {\n const transaction = database.transaction(CHAT_DRAFTS, 'readonly');\n return settled<ChatDraftRecord[]>(transaction.objectStore(CHAT_DRAFTS).getAll());\n },\n async keepChatDraft(record) {\n const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');\n transaction.objectStore(CHAT_DRAFTS).put(record);\n await completed(transaction);\n },\n async dropChatDraft(conversation) {\n const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');\n transaction.objectStore(CHAT_DRAFTS).delete(conversation);\n await completed(transaction);\n },\n async keepRoomDraft(record) {\n const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');\n transaction.objectStore(ROOM_DRAFTS).put(record);\n await completed(transaction);\n },\n async discardRoomDraft(locator, path) {\n const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');\n transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);\n await completed(transaction);\n },\n async dropRooms(locators) {\n const transaction = database.transaction(\n [ROOMS, DOCUMENTS, BINARY_TARGETS, PENDING_CHANGES, OUTCOMES, ROOM_DRAFTS],\n 'readwrite',\n );\n for (const locator of locators) {\n transaction.objectStore(ROOMS).delete(locator);\n for (const name of [DOCUMENTS, BINARY_TARGETS, PENDING_CHANGES, ROOM_DRAFTS]) {\n removeRoomEntries(transaction.objectStore(name), locator);\n }\n const outcomes = transaction.objectStore(OUTCOMES);\n const ids = outcomes.index('locator').getAllKeys(locator);\n ids.onsuccess = () => {\n for (const id of ids.result) outcomes.delete(id);\n };\n }\n await completed(transaction);\n },\n async generation() {\n return (await declaration(database)).generation;\n },\n rememberGeneration(value) {\n return updateDeclaration(database, (record) => ({ ...record, generation: value }));\n },\n close() {\n database.close();\n },\n };\n}\n"],"names":["DATABASE","ROOMS","DOCUMENTS","BINARY_TARGETS","PENDING_CHANGES","OUTCOMES","DECLARATIONS","ROOM_DRAFTS","PRESENTATION","CONVERSATIONS","MESSAGES","CHAT_DRAFTS","CURRENT","SCHEMA","settled","request","Promise","resolve","reject","onsuccess","result","onerror","error","completed","transaction","oncomplete","onabort","EMPTY_DECLARATIONS","lastCompleted","generation","providerLimits","capabilities","slots","declaration","database","objectStore","get","then","record","updateDeclaration","update","store","prior","put","amendPending","locator","id","amendment","pending","undefined","roomRecord","queue","documents","binaryTargets","revisions","room","order","map","batch","removeRoomEntries","keys","getAllKeys","key","Array","isArray","delete","removeRuntimeStore","removal","indexedDB","deleteDatabase","openRuntimeStore","opening","open","onupgradeneeded","name","objectStoreNames","deleteObjectStore","createObjectStore","keyPath","outcomes","createIndex","messages","all","rooms","targets","getAll","byRoom","Map","set","document","path","content","revision","target","push","values","write","next","previous","previousQueue","saved","roomDrafts","consumedRoomDrafts","Object","entries","beforeTargets","Set","afterTargets","has","before","after","drafts","submission","state","lost","outcomeStore","entry","outcome","draftStore","revokeModels","records","revoked","status","reason","model","selectionModel","complete","at","declare","limits","queues","byId","Error","upload","submit","keepUpload","presentation","present","conversations","reads","held","conversation","read","message","keepMessages","sealed","stored","dropConversations","index","chatDrafts","keepChatDraft","dropChatDraft","keepRoomDraft","discardRoomDraft","dropRooms","locators","ids","rememberGeneration","value","close"],"mappings":"AAeA,MAAMA,WAAW;AACjB,MAAMC,QAAQ;AACd,MAAMC,YAAY;AAClB,MAAMC,iBAAiB;AACvB,MAAMC,kBAAkB;AACxB,MAAMC,WAAW;AACjB,MAAMC,eAAe;AACrB,MAAMC,cAAc;AACpB,MAAMC,eAAe;AACrB,MAAMC,gBAAgB;AACtB,MAAMC,WAAW;AACjB,MAAMC,cAAc;AACpB,MAAMC,UAAU;AAChB,MAAMC,SAAS;AAgJf,SAASC,QAAWC,OAAsB;IACxC,OAAO,IAAIC,QAAQ,CAACC,SAASC;QA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CAAC;gBAACpB;gBAAS6C;aAAK;YAC3D,MAAMnE,UAAUC;QAClB;QACA,MAAMkI,WAAUC,QAAQ;YACtB,MAAMnI,cAAcU,SAASV,WAAW,CACtC;gBAACvB;gBAAOC;gBAAWC;gBAAgBC;gBAAiBC;gBAAUE;aAAY,EAC1E;YAEF,KAAK,MAAMsC,WAAW8G,SAAU;gBAC9BnI,YAAYW,WAAW,CAAClC,OAAOgE,MAAM,CAACpB;gBACtC,KAAK,MAAM6B,QAAQ;oBAACxE;oBAAWC;oBAAgBC;oBAAiBG;iBAAY,CAAE;oBAC5EoD,kBAAkBnC,YAAYW,WAAW,CAACuC,OAAO7B;gBACnD;gBACA,MAAMkC,WAAWvD,YAAYW,WAAW,CAAC9B;gBACzC,MAAMuJ,MAAM7E,SAASqE,KAAK,CAAC,WAAWvF,UAAU,CAAChB;gBACjD+G,IAAIzI,SAAS,GAAG;oBACd,KAAK,MAAM2B,MAAM8G,IAAIxI,MAAM,CAAE2D,SAASd,MAAM,CAACnB;gBAC/C;YACF;YACA,MAAMvB,UAAUC;QAClB;QACA,MAAMK;YACJ,OAAO,AAAC,CAAA,MAAMI,YAAYC,SAAQ,EAAGL,UAAU;QACjD;QACAgI,oBAAmBC,KAAK;YACtB,OAAOvH,kBAAkBL,UAAU,CAACI,SAAY,CAAA;oBAAE,GAAGA,MAAM;oBAAET,YAAYiI;gBAAM,CAAA;QACjF;QACAC;YACE7H,SAAS6H,KAAK;QAChB;IACF;AACF"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/store.ts"],"sourcesContent":["import type { ModelState } from './model.js';\nimport type {\n Capability,\n Discovery,\n OperationScopes,\n ProviderLimit,\n ReplicaAdmission,\n TypedSelection,\n} from './adapter.js';\nimport type { AcceptedMessage } from './adapter.js';\nimport type { ChangeBatch } from './change.js';\nimport type { ChatDraftFile } from './file.js';\nimport type { Submission, SubmissionOutcome } from './outcome.js';\nimport type { RoomDraftRecord, SavedDraft } from './room-draft.js';\n\nconst DATABASE = 'mdruntime';\nconst ROOMS = 'rooms';\nconst DOCUMENTS = 'documents';\nconst BINARY_TARGETS = 'binaryTargets';\nconst PENDING_CHANGES = 'pendingChanges';\nconst OUTCOMES = 'outcomes';\nconst DECLARATIONS = 'declarations';\nconst ROOM_DRAFTS = 'roomDrafts';\nconst PRESENTATION = 'presentation';\nconst CONVERSATIONS = 'conversations';\nconst MESSAGES = 'messages';\nconst CHAT_DRAFTS = 'chatDrafts';\nconst CURRENT = 'current';\nconst SCHEMA = 14;\n\nexport type ReplicaRecord = {\n collectionRoot: string;\n locator: string;\n name: string;\n operations: OperationScopes;\n replica: ReplicaAdmission;\n model: ModelState;\n attachedModel: import('./model.js').ModelIdentity | null;\n typedSelection: TypedSelection | null;\n selectionModel: ModelState;\n providerOwnedPaths: readonly string[];\n roomVersion: string;\n documents: Readonly<Record<string, string>>;\n binaryTargets: readonly string[];\n revisions: Readonly<Record<string, string>>;\n};\n\ntype RoomRecord = Omit<ReplicaRecord, 'documents' | 'binaryTargets' | 'revisions'> & {\n order: readonly string[];\n};\n\ntype DocumentRecord = {\n locator: string;\n path: string;\n content: string;\n revision: string | null;\n};\n\ntype BinaryTargetRecord = { locator: string; path: string; revision: string | null };\n\nexport type PendingState = {\n readonly drafts: readonly SavedDraft[];\n readonly submission: Submission;\n readonly lost: boolean;\n readonly upload?: unknown;\n};\n\ntype PendingChangeRecord = PendingState & {\n locator: string;\n id: string;\n batch: ChangeBatch;\n};\n\nexport type OutcomeRecord = {\n locator: string;\n id: string;\n outcome: SubmissionOutcome;\n};\n\ntype DeclarationRecord = {\n lastCompleted: string | null;\n generation: string | null;\n providerLimits: readonly ProviderLimit[];\n capabilities: readonly Capability[];\n slots: NonNullable<Discovery['slots']>;\n};\n\nexport type QueueRecord = {\n locator: string;\n pending: readonly { batch: ChangeBatch; state: PendingState }[];\n};\n\nexport type PresentationRecord = {\n app: string;\n value: unknown;\n};\n\ntype ConversationRecord = {\n conversation: string;\n read: string | null;\n};\n\ntype MessageRecord = AcceptedMessage & { conversation: string };\n\nexport type HeldConversation = {\n conversation: string;\n read: string | null | undefined;\n messages: readonly AcceptedMessage[];\n};\n\nexport type ConversationWrite = {\n conversation: string;\n messages: readonly AcceptedMessage[];\n read?: string | null;\n sealed?: boolean;\n};\n\nexport type ChatDraftRecord = {\n conversation: string;\n text: string;\n files: readonly ChatDraftFile[];\n turn: string | null;\n};\n\nexport type RecordWrite = {\n next: ReplicaRecord;\n previous: ReplicaRecord | null;\n queue: readonly ChangeBatch[];\n previousQueue?: readonly ChangeBatch[];\n saved?: readonly SavedDraft[];\n outcomes?: readonly { id: string; outcome: SubmissionOutcome | null }[];\n roomDrafts?: readonly RoomDraftRecord[];\n consumedRoomDrafts?: readonly string[];\n};\n\nexport type RuntimeStore = {\n all(): Promise<readonly ReplicaRecord[]>;\n write(input: RecordWrite): Promise<void>;\n revokeModels(\n records: readonly { record: ReplicaRecord; queue: readonly ChangeBatch[] }[],\n ): Promise<void>;\n lastCompleted(): Promise<string | null>;\n complete(at: string): Promise<void>;\n providerLimits(): Promise<readonly ProviderLimit[]>;\n capabilities(): Promise<readonly Capability[]>;\n slots(): Promise<NonNullable<Discovery['slots']>>;\n declare(\n limits: readonly ProviderLimit[],\n capabilities: readonly Capability[],\n slots: NonNullable<Discovery['slots']>,\n ): Promise<void>;\n queues(): Promise<readonly QueueRecord[]>;\n outcomes(): Promise<readonly OutcomeRecord[]>;\n submit(locator: string, id: string, submission: Submission, lost: boolean): Promise<void>;\n keepUpload(locator: string, id: string, upload: unknown): Promise<void>;\n roomDrafts(): Promise<readonly RoomDraftRecord[]>;\n presentation(): Promise<readonly PresentationRecord[]>;\n present(record: PresentationRecord): Promise<void>;\n conversations(): Promise<readonly HeldConversation[]>;\n keepMessages(write: ConversationWrite): Promise<void>;\n dropConversations(conversations: readonly string[]): Promise<void>;\n chatDrafts(): Promise<readonly ChatDraftRecord[]>;\n keepChatDraft(record: ChatDraftRecord): Promise<void>;\n dropChatDraft(conversation: string): Promise<void>;\n keepRoomDraft(record: RoomDraftRecord): Promise<void>;\n discardRoomDraft(locator: string, path: string): Promise<void>;\n dropRooms(locators: readonly string[]): Promise<void>;\n generation(): Promise<string | null>;\n rememberGeneration(value: string): Promise<void>;\n close(): void;\n};\n\nfunction settled<T>(request: IDBRequest<T>): Promise<T> {\n return new Promise((resolve, reject) => {\n request.onsuccess = () => resolve(request.result);\n request.onerror = () => reject(request.error);\n });\n}\n\nfunction completed(transaction: IDBTransaction): Promise<void> {\n return new Promise((resolve, reject) => {\n transaction.oncomplete = () => resolve();\n transaction.onerror = () => reject(transaction.error);\n transaction.onabort = () => reject(transaction.error);\n });\n}\n\nconst EMPTY_DECLARATIONS: DeclarationRecord = {\n lastCompleted: null,\n generation: null,\n providerLimits: [],\n capabilities: [],\n slots: [],\n};\n\nfunction declaration(database: IDBDatabase): Promise<DeclarationRecord> {\n const transaction = database.transaction(DECLARATIONS, 'readonly');\n return settled<DeclarationRecord | undefined>(\n transaction.objectStore(DECLARATIONS).get(CURRENT),\n ).then((record) => record ?? EMPTY_DECLARATIONS);\n}\n\nfunction updateDeclaration(\n database: IDBDatabase,\n update: (record: DeclarationRecord) => DeclarationRecord,\n): Promise<void> {\n const transaction = database.transaction(DECLARATIONS, 'readwrite');\n const store = transaction.objectStore(DECLARATIONS);\n const prior = store.get(CURRENT);\n prior.onsuccess = () => {\n store.put(\n update((prior.result as DeclarationRecord | undefined) ?? EMPTY_DECLARATIONS),\n CURRENT,\n );\n };\n return completed(transaction);\n}\n\nfunction amendPending(\n database: IDBDatabase,\n locator: string,\n id: string,\n amendment: Partial<PendingState>,\n): Promise<void> {\n const transaction = database.transaction(PENDING_CHANGES, 'readwrite');\n const pending = transaction.objectStore(PENDING_CHANGES);\n const request = pending.get([locator, id]);\n request.onsuccess = () => {\n const record = request.result as PendingChangeRecord | undefined;\n if (record !== undefined) pending.put({ ...record, ...amendment });\n };\n return completed(transaction);\n}\n\nfunction roomRecord(record: ReplicaRecord, queue: readonly ChangeBatch[]): RoomRecord {\n const { documents, binaryTargets, revisions, ...room } = record;\n return { ...room, order: queue.map((batch) => batch.id) };\n}\n\nfunction removeRoomEntries(store: IDBObjectStore, locator: string) {\n const keys = store.getAllKeys();\n keys.onsuccess = () => {\n for (const key of keys.result) {\n if (Array.isArray(key) && key[0] === locator) store.delete(key);\n }\n };\n}\n\nexport function removeRuntimeStore(): Promise<void> {\n return new Promise((resolve, reject) => {\n const removal = indexedDB.deleteDatabase(DATABASE);\n removal.onsuccess = () => resolve();\n removal.onerror = () => reject(removal.error);\n });\n}\n\nexport async function openRuntimeStore(): Promise<RuntimeStore> {\n const opening = indexedDB.open(DATABASE, SCHEMA);\n opening.onupgradeneeded = () => {\n const database = opening.result;\n for (const name of [...database.objectStoreNames]) database.deleteObjectStore(name);\n database.createObjectStore(ROOMS, { keyPath: 'locator' });\n database.createObjectStore(DOCUMENTS, { keyPath: ['locator', 'path'] });\n database.createObjectStore(BINARY_TARGETS, { keyPath: ['locator', 'path'] });\n database.createObjectStore(PENDING_CHANGES, { keyPath: ['locator', 'id'] });\n const outcomes = database.createObjectStore(OUTCOMES, { keyPath: 'id' });\n outcomes.createIndex('locator', 'locator');\n database.createObjectStore(DECLARATIONS);\n database.createObjectStore(ROOM_DRAFTS, { keyPath: ['locator', 'path'] });\n database.createObjectStore(PRESENTATION, { keyPath: 'app' });\n database.createObjectStore(CONVERSATIONS, { keyPath: 'conversation' });\n const messages = database.createObjectStore(MESSAGES, {\n keyPath: ['conversation', 'identity'],\n });\n messages.createIndex('conversation', 'conversation');\n database.createObjectStore(CHAT_DRAFTS, { keyPath: 'conversation' });\n };\n const database = await settled(opening);\n return {\n async all() {\n const transaction = database.transaction([ROOMS, DOCUMENTS, BINARY_TARGETS], 'readonly');\n const [rooms, documents, targets] = await Promise.all([\n settled<RoomRecord[]>(transaction.objectStore(ROOMS).getAll()),\n settled<DocumentRecord[]>(transaction.objectStore(DOCUMENTS).getAll()),\n settled<BinaryTargetRecord[]>(transaction.objectStore(BINARY_TARGETS).getAll()),\n ]);\n const byRoom = new Map<string, ReplicaRecord>();\n for (const { order, ...room } of rooms) {\n byRoom.set(room.locator, { ...room, documents: {}, revisions: {}, binaryTargets: [] });\n }\n for (const document of documents) {\n const room = byRoom.get(document.locator);\n if (room === undefined) continue;\n (room.documents as Record<string, string>)[document.path] = document.content;\n if (document.revision !== null) {\n (room.revisions as Record<string, string>)[document.path] = document.revision;\n }\n }\n for (const target of targets) {\n const room = byRoom.get(target.locator);\n if (room === undefined) continue;\n (room.binaryTargets as string[]).push(target.path);\n if (target.revision !== null) {\n (room.revisions as Record<string, string>)[target.path] = target.revision;\n }\n }\n return [...byRoom.values()];\n },\n async write({\n next,\n previous,\n queue,\n previousQueue,\n saved,\n outcomes,\n roomDrafts,\n consumedRoomDrafts,\n }) {\n const transaction = database.transaction(\n [ROOMS, DOCUMENTS, BINARY_TARGETS, PENDING_CHANGES, OUTCOMES, ROOM_DRAFTS],\n 'readwrite',\n );\n transaction.objectStore(ROOMS).put(roomRecord(next, queue));\n const documents = transaction.objectStore(DOCUMENTS);\n for (const path of Object.keys(previous?.documents ?? {})) {\n if (next.documents[path] === undefined) documents.delete([next.locator, path]);\n }\n for (const [path, content] of Object.entries(next.documents)) {\n if (\n previous?.documents[path] === content &&\n previous.revisions[path] === next.revisions[path]\n )\n continue;\n documents.put({\n locator: next.locator,\n path,\n content,\n revision: next.revisions[path] ?? null,\n } satisfies DocumentRecord);\n }\n const targets = transaction.objectStore(BINARY_TARGETS);\n const beforeTargets = new Set(previous?.binaryTargets ?? []);\n const afterTargets = new Set(next.binaryTargets);\n for (const path of beforeTargets) {\n if (!afterTargets.has(path)) targets.delete([next.locator, path]);\n }\n for (const path of afterTargets) {\n if (!beforeTargets.has(path) || previous?.revisions[path] !== next.revisions[path]) {\n targets.put({\n locator: next.locator,\n path,\n revision: next.revisions[path] ?? null,\n });\n }\n }\n if (previousQueue !== undefined) {\n const pending = transaction.objectStore(PENDING_CHANGES);\n const before = new Set(previousQueue.map((batch) => batch.id));\n const after = new Set(queue.map((batch) => batch.id));\n for (const id of before) {\n if (!after.has(id)) pending.delete([next.locator, id]);\n }\n for (const batch of queue) {\n if (!before.has(batch.id)) {\n pending.put({\n locator: next.locator,\n id: batch.id,\n batch,\n drafts: saved ?? [],\n submission: { state: 'waiting' },\n lost: false,\n } satisfies PendingChangeRecord);\n }\n }\n }\n const outcomeStore = transaction.objectStore(OUTCOMES);\n for (const entry of outcomes ?? []) {\n if (entry.outcome === null) outcomeStore.delete(entry.id);\n else outcomeStore.put({ locator: next.locator, id: entry.id, outcome: entry.outcome });\n }\n const draftStore = transaction.objectStore(ROOM_DRAFTS);\n for (const path of consumedRoomDrafts ?? []) draftStore.delete([next.locator, path]);\n for (const record of roomDrafts ?? []) draftStore.put(record);\n await completed(transaction);\n },\n async revokeModels(records) {\n const transaction = database.transaction(ROOMS, 'readwrite');\n const rooms = transaction.objectStore(ROOMS);\n const revoked: ModelState = { status: 'unavailable', reason: 'revoked' };\n for (const { record, queue } of records) {\n rooms.put(roomRecord({ ...record, model: revoked, selectionModel: revoked }, queue));\n }\n await completed(transaction);\n },\n async lastCompleted() {\n return (await declaration(database)).lastCompleted;\n },\n complete(at) {\n return updateDeclaration(database, (record) => ({ ...record, lastCompleted: at }));\n },\n async providerLimits() {\n return (await declaration(database)).providerLimits;\n },\n async capabilities() {\n return (await declaration(database)).capabilities;\n },\n async slots() {\n return (await declaration(database)).slots;\n },\n declare(limits, capabilities, slots) {\n return updateDeclaration(database, (record) => ({\n ...record,\n providerLimits: limits,\n capabilities,\n slots,\n }));\n },\n async queues() {\n const transaction = database.transaction([ROOMS, PENDING_CHANGES], 'readonly');\n const [rooms, pending] = await Promise.all([\n settled<RoomRecord[]>(transaction.objectStore(ROOMS).getAll()),\n settled<PendingChangeRecord[]>(transaction.objectStore(PENDING_CHANGES).getAll()),\n ]);\n const byId = new Map(pending.map((record) => [`${record.locator}\\0${record.id}`, record]));\n return rooms.map((room) => ({\n locator: room.locator,\n pending: room.order.map((id) => {\n const record = byId.get(`${room.locator}\\0${id}`);\n if (record === undefined) throw new Error(`Missing Pending Change ${room.locator}/${id}`);\n const { batch, drafts, submission, lost, upload } = record;\n return { batch, state: { drafts, submission, lost, upload } };\n }),\n }));\n },\n async outcomes() {\n const transaction = database.transaction(OUTCOMES, 'readonly');\n return settled<OutcomeRecord[]>(transaction.objectStore(OUTCOMES).getAll());\n },\n submit(locator, id, submission, lost) {\n return amendPending(database, locator, id, { submission, lost });\n },\n keepUpload(locator, id, upload) {\n return amendPending(database, locator, id, { upload });\n },\n async roomDrafts() {\n const transaction = database.transaction(ROOM_DRAFTS, 'readonly');\n return settled<RoomDraftRecord[]>(transaction.objectStore(ROOM_DRAFTS).getAll());\n },\n async presentation() {\n const transaction = database.transaction(PRESENTATION, 'readonly');\n return settled<PresentationRecord[]>(transaction.objectStore(PRESENTATION).getAll());\n },\n async present(record) {\n const transaction = database.transaction(PRESENTATION, 'readwrite');\n transaction.objectStore(PRESENTATION).put(record);\n await completed(transaction);\n },\n async conversations() {\n const transaction = database.transaction([CONVERSATIONS, MESSAGES], 'readonly');\n const [reads, messages] = await Promise.all([\n settled<ConversationRecord[]>(transaction.objectStore(CONVERSATIONS).getAll()),\n settled<MessageRecord[]>(transaction.objectStore(MESSAGES).getAll()),\n ]);\n const held = new Map<string, HeldConversation & { messages: AcceptedMessage[] }>();\n for (const { conversation, read } of reads) {\n held.set(conversation, { conversation, read, messages: [] });\n }\n for (const { conversation, ...message } of messages) {\n const entry = held.get(conversation) ?? { conversation, read: undefined, messages: [] };\n entry.messages.push(message);\n held.set(conversation, entry);\n }\n return [...held.values()];\n },\n async keepMessages({ conversation, messages, read, sealed }) {\n const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');\n const stored = transaction.objectStore(MESSAGES);\n for (const message of messages) {\n stored.put({ ...message, conversation } satisfies MessageRecord);\n }\n if (read !== undefined) {\n transaction\n .objectStore(CONVERSATIONS)\n .put({ conversation, read } satisfies ConversationRecord);\n }\n if (sealed === true) transaction.objectStore(CHAT_DRAFTS).delete(conversation);\n await completed(transaction);\n },\n async dropConversations(conversations) {\n const transaction = database.transaction([CONVERSATIONS, MESSAGES, CHAT_DRAFTS], 'readwrite');\n const messages = transaction.objectStore(MESSAGES);\n for (const conversation of conversations) {\n transaction.objectStore(CONVERSATIONS).delete(conversation);\n transaction.objectStore(CHAT_DRAFTS).delete(conversation);\n const keys = messages.index('conversation').getAllKeys(conversation);\n keys.onsuccess = () => {\n for (const key of keys.result) messages.delete(key);\n };\n }\n await completed(transaction);\n },\n async chatDrafts() {\n const transaction = database.transaction(CHAT_DRAFTS, 'readonly');\n return settled<ChatDraftRecord[]>(transaction.objectStore(CHAT_DRAFTS).getAll());\n },\n async keepChatDraft(record) {\n const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');\n transaction.objectStore(CHAT_DRAFTS).put(record);\n await completed(transaction);\n },\n async dropChatDraft(conversation) {\n const transaction = database.transaction(CHAT_DRAFTS, 'readwrite');\n transaction.objectStore(CHAT_DRAFTS).delete(conversation);\n await completed(transaction);\n },\n async keepRoomDraft(record) {\n const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');\n transaction.objectStore(ROOM_DRAFTS).put(record);\n await completed(transaction);\n },\n async discardRoomDraft(locator, path) {\n const transaction = database.transaction(ROOM_DRAFTS, 'readwrite');\n transaction.objectStore(ROOM_DRAFTS).delete([locator, path]);\n await completed(transaction);\n },\n async dropRooms(locators) {\n const transaction = database.transaction(\n [ROOMS, DOCUMENTS, BINARY_TARGETS, PENDING_CHANGES, OUTCOMES, ROOM_DRAFTS],\n 'readwrite',\n );\n for (const locator of locators) {\n transaction.objectStore(ROOMS).delete(locator);\n for (const name of [DOCUMENTS, BINARY_TARGETS, PENDING_CHANGES, ROOM_DRAFTS]) {\n removeRoomEntries(transaction.objectStore(name), locator);\n }\n const outcomes = transaction.objectStore(OUTCOMES);\n const ids = outcomes.index('locator').getAllKeys(locator);\n ids.onsuccess = () => {\n for (const id of ids.result) outcomes.delete(id);\n };\n }\n await completed(transaction);\n },\n async generation() {\n return (await declaration(database)).generation;\n },\n rememberGeneration(value) {\n return updateDeclaration(database, (record) => ({ ...record, generation: value }));\n },\n close() {\n database.close();\n },\n };\n}\n"],"names":["DATABASE","ROOMS","DOCUMENTS","BINARY_TARGETS","PENDING_CHANGES","OUTCOMES","DECLARATIONS","ROOM_DRAFTS","PRESENTATION","CONVERSATIONS","MESSAGES","CHAT_DRAFTS","CURRENT","SCHEMA","settled","request","Promise","resolve","reject","onsuccess","result","onerror","error","completed","transaction","oncomplete","onabort","EMPTY_DECLARATIONS","lastCompleted","generation","providerLimits","capabilities","slots","declaration","database","objectStore","get","then","record","updateDeclaration","update","store","prior","put","amendPending","locator","id","amendment","pending","undefined","roomRecord","queue","documents","binaryTargets","revisions","room","order","map","batch","removeRoomEntries","keys","getAllKeys","key","Array","isArray","delete","removeRuntimeStore","removal","indexedDB","deleteDatabase","openRuntimeStore","opening","open","onupgradeneeded","name","objectStoreNames","deleteObjectStore","createObjectStore","keyPath","outcomes","createIndex","messages","all","rooms","targets","getAll","byRoom","Map","set","document","path","content","revision","target","push","values","write","next","previous","previousQueue","saved","roomDrafts","consumedRoomDrafts","Object","entries","beforeTargets","Set","afterTargets","has","before","after","drafts","submission","state","lost","outcomeStore","entry","outcome","draftStore","revokeModels","records","revoked","status","reason","model","selectionModel","complete","at","declare","limits","queues","byId","Error","upload","submit","keepUpload","presentation","present","conversations","reads","held","conversation","read","message","keepMessages","sealed","stored","dropConversations","index","chatDrafts","keepChatDraft","dropChatDraft","keepRoomDraft","discardRoomDraft","dropRooms","locators","ids","rememberGeneration","value","close"],"mappings":"AAeA,MAAMA,WAAW;AACjB,MAAMC,QAAQ;AACd,MAAMC,YAAY;AAClB,MAAMC,iBAAiB;AACvB,MAAMC,kBAAkB;AACxB,MAAMC,WAAW;AACjB,MAAMC,eAAe;AACrB,MAAMC,cAAc;AACpB,MAAMC,eAAe;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AACL;YACzC,MAAMf,UAAUC;QAClB;QACA,MAAMiI,kBAAiB5G,OAAO,EAAE6C,IAAI;YAClC,MAAMlE,cAAcU,SAASV,WAAW,CAACjB,aAAa;YACtDiB,YAAYW,WAAW,CAAC5B,aAAa0D,MAAM,CAAC;gBAACpB;gBAAS6C;aAAK;YAC3D,MAAMnE,UAAUC;QAClB;QACA,MAAMkI,WAAUC,QAAQ;YACtB,MAAMnI,cAAcU,SAASV,WAAW,CACtC;gBAACvB;gBAAOC;gBAAWC;gBAAgBC;gBAAiBC;gBAAUE;aAAY,EAC1E;YAEF,KAAK,MAAMsC,WAAW8G,SAAU;gBAC9BnI,YAAYW,WAAW,CAAClC,OAAOgE,MAAM,CAACpB;gBACtC,KAAK,MAAM6B,QAAQ;oBAACxE;oBAAWC;oBAAgBC;oBAAiBG;iBAAY,CAAE;oBAC5EoD,kBAAkBnC,YAAYW,WAAW,CAACuC,OAAO7B;gBACnD;gBACA,MAAMkC,WAAWvD,YAAYW,WAAW,CAAC9B;gBACzC,MAAMuJ,MAAM7E,SAASqE,KAAK,CAAC,WAAWvF,UAAU,CAAChB;gBACjD+G,IAAIzI,SAAS,GAAG;oBACd,KAAK,MAAM2B,MAAM8G,IAAIxI,MAAM,CAAE2D,SAASd,MAAM,CAACnB;gBAC/C;YACF;YACA,MAAMvB,UAAUC;QAClB;QACA,MAAMK;YACJ,OAAO,AAAC,CAAA,MAAMI,YAAYC,SAAQ,EAAGL,UAAU;QACjD;QACAgI,oBAAmBC,KAAK;YACtB,OAAOvH,kBAAkBL,UAAU,CAACI,SAAY,CAAA;oBAAE,GAAGA,MAAM;oBAAET,YAAYiI;gBAAM,CAAA;QACjF;QACAC;YACE7H,SAAS6H,KAAK;QAChB;IACF;AACF"}
package/dist/wire.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { ConnectionRefusal } from './connection.js';
2
- export declare const RUNTIME_WIRE_PROTOCOL = 7;
2
+ export declare const RUNTIME_WIRE_PROTOCOL = 8;
3
3
  export declare const PROTOCOL_MISMATCH: ConnectionRefusal;
4
4
  export type RuntimePort = {
5
5
  postMessage(message: unknown): void;
@@ -8,8 +8,8 @@ export type RuntimePort = {
8
8
  }) => void): void;
9
9
  start(): void;
10
10
  };
11
- declare const MEMBERS: readonly ['rooms', 'slots', 'query', 'search', 'types', 'syncStatus', 'save', 'outcome', 'history', 'call', 'log', 'storageLoss', 'persistence', 'deploymentFacts', 'reauthorize', 'roomDraft.list', 'roomDraft.read', 'roomDraft.write', 'roomDraft.discard', 'presentation.read', 'presentation.write', 'conversation.list', 'conversation.read', 'conversation.create', 'conversation.send', 'conversation.answer', 'conversation.interrupt', 'conversation.kill', 'conversation.cancel', 'conversation.delete', 'chatDraft.write', 'chatDraft.discard'];
12
- declare const TOPICS: readonly ['rooms', 'connection-refusal', 'storage-loss', 'deployment-facts', 'sync-status', 'query', 'queue', 'room-drafts', 'presentation', 'conversation'];
11
+ declare const MEMBERS: readonly ['rooms', 'slots', 'query', 'search', 'types', 'syncStatus', 'serviceMode', 'save', 'outcome', 'history', 'call', 'log', 'storageLoss', 'persistence', 'deploymentFacts', 'reauthorize', 'roomDraft.list', 'roomDraft.read', 'roomDraft.write', 'roomDraft.discard', 'presentation.read', 'presentation.write', 'conversation.list', 'conversation.read', 'conversation.create', 'conversation.send', 'conversation.answer', 'conversation.interrupt', 'conversation.kill', 'conversation.cancel', 'conversation.delete', 'chatDraft.write', 'chatDraft.discard'];
12
+ declare const TOPICS: readonly ['rooms', 'connection-refusal', 'storage-loss', 'deployment-facts', 'sync-status', 'service-mode', 'query', 'queue', 'room-drafts', 'presentation', 'conversation'];
13
13
  export type WireMember = (typeof MEMBERS)[number];
14
14
  export type WireTopic = (typeof TOPICS)[number];
15
15
  export type WireRequest = {
@@ -1 +1 @@
1
- {"version":3,"file":"wire.d.ts","sourceRoot":"","sources":["../src/wire.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AA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,MAAM,CAAC;IAAC,OAAO,EAAE,WAAW,GAAG,UAAU,CAAA;CAAE,CAAC;AAEpF,MAAM,MAAM,OAAO,GAAG;IAAE,QAAQ,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,CAAC;AAE9D,wBAAgB,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,UAAU,GAAG,YAAY,CAExE;AAED,wBAAgB,OAAO,CAAC,IAAI,EAAE,OAAO,GAAG,OAAO,GAAG,IAAI,CAIrD;AAQD,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW,GAAG,IAAI,CAyB5D;AAED,wBAAgB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,GAAG,IAAI,CAe1D"}
package/dist/wire.js CHANGED
@@ -1,4 +1,4 @@
1
- export const RUNTIME_WIRE_PROTOCOL = 7;
1
+ export const RUNTIME_WIRE_PROTOCOL = 8;
2
2
  export const PROTOCOL_MISMATCH = {
3
3
  reason: 'client-host-protocol-mismatch',
4
4
  reauthorizationOffered: false,
@@ -11,6 +11,7 @@ const MEMBERS = [
11
11
  'search',
12
12
  'types',
13
13
  'syncStatus',
14
+ 'serviceMode',
14
15
  'save',
15
16
  'outcome',
16
17
  'history',
@@ -44,6 +45,7 @@ const TOPICS = [
44
45
  'storage-loss',
45
46
  'deployment-facts',
46
47
  'sync-status',
48
+ 'service-mode',
47
49
  'query',
48
50
  'queue',
49
51
  'room-drafts',
package/dist/wire.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["/workspace/packages/mdruntime/src/wire.ts"],"sourcesContent":["import type { ConnectionRefusal } from './connection.js';\n\nexport const RUNTIME_WIRE_PROTOCOL = 7;\n\nexport const PROTOCOL_MISMATCH: ConnectionRefusal = {\n reason: 'client-host-protocol-mismatch',\n reauthorizationOffered: false,\n refusal: null,\n};\n\nexport type RuntimePort = {\n postMessage(message: unknown): void;\n addEventListener(type: 'message' | 'close', listener: (event: { data?: unknown }) => void): void;\n start(): void;\n};\n\nconst MEMBERS = [\n 'rooms',\n 'slots',\n 'query',\n 'search',\n 'types',\n 'syncStatus',\n 'save',\n 'outcome',\n 'history',\n 'call',\n 'log',\n 'storageLoss',\n 'persistence',\n 'deploymentFacts',\n 'reauthorize',\n 'roomDraft.list',\n 'roomDraft.read',\n 'roomDraft.write',\n 'roomDraft.discard',\n 'presentation.read',\n 'presentation.write',\n 'conversation.list',\n 'conversation.read',\n 'conversation.create',\n 'conversation.send',\n 'conversation.answer',\n 'conversation.interrupt',\n 'conversation.kill',\n 'conversation.cancel',\n 'conversation.delete',\n 'chatDraft.write',\n 'chatDraft.discard',\n] as const;\n\nconst TOPICS = [\n 'rooms',\n 'connection-refusal',\n 'storage-loss',\n 'deployment-facts',\n 'sync-status',\n 'query',\n 'queue',\n 'room-drafts',\n 'presentation',\n 'conversation',\n] as const;\n\nexport type WireMember = (typeof MEMBERS)[number];\nexport type WireTopic = (typeof TOPICS)[number];\n\nexport type WireRequest =\n | { kind: 'hello' }\n | { kind: 'call'; id: number; member: WireMember; input: readonly unknown[] }\n | { kind: 'observe'; id: number; topic: WireTopic; input: readonly unknown[] }\n | { kind: 'stop'; id: number };\n\nexport type WireAnswer =\n | { kind: 'result'; id: number; value: unknown }\n | { kind: 'failure'; id: number; message: string }\n | { kind: 'event'; id: number; value: unknown }\n | { kind: 'refusal'; refusal: ConnectionRefusal }\n | { kind: 'ended' };\n\nexport const AUTHORIZATION_ENDED = 'the host authorization ended';\n\nexport const PORT_CLOSED = 'the port closed';\n\nexport type WireEnvelope = { mdRuntime: number; message: WireRequest | WireAnswer };\n\nexport type Carried = { matching: boolean; message: unknown };\n\nexport function envelope(message: WireRequest | WireAnswer): WireEnvelope {\n return { mdRuntime: RUNTIME_WIRE_PROTOCOL, message };\n}\n\nexport function carried(data: unknown): Carried | null {\n if (typeof data !== 'object' || data === null || !('mdRuntime' in data)) return null;\n const record = data as { mdRuntime: unknown; message?: unknown };\n return { matching: record.mdRuntime === RUNTIME_WIRE_PROTOCOL, message: record.message };\n}\n\nfunction body(message: unknown): { kind: unknown; id: unknown } | null {\n if (typeof message !== 'object' || message === null) return null;\n const record = message as { kind?: unknown; id?: unknown };\n return { kind: record.kind, id: record.id };\n}\n\nexport function request(message: unknown): WireRequest | null {\n const shape = body(message);\n if (shape === null) return null;\n if (shape.kind === 'hello') return { kind: 'hello' };\n if (typeof shape.id !== 'number') return null;\n const record = message as { input?: unknown; member?: unknown; topic?: unknown };\n if (shape.kind === 'stop') return { kind: 'stop', id: shape.id };\n if (!Array.isArray(record.input)) return null;\n if (shape.kind === 'call' && MEMBERS.includes(record.member as WireMember)) {\n return {\n kind: 'call',\n id: shape.id,\n member: record.member as WireMember,\n input: record.input as readonly unknown[],\n };\n }\n if (shape.kind === 'observe' && TOPICS.includes(record.topic as WireTopic)) {\n return {\n kind: 'observe',\n id: shape.id,\n topic: record.topic as WireTopic,\n input: record.input as readonly unknown[],\n };\n }\n return null;\n}\n\nexport function answer(message: unknown): WireAnswer | null {\n const shape = body(message);\n if (shape === null) return null;\n const record = message as { value?: unknown; message?: unknown; refusal?: unknown };\n if (shape.kind === 'refusal') {\n return { kind: 'refusal', refusal: record.refusal as ConnectionRefusal };\n }\n if (shape.kind === 'ended') return { kind: 'ended' };\n if (typeof shape.id !== 'number') return null;\n if (shape.kind === 'result') return { kind: 'result', id: shape.id, value: record.value };\n if (shape.kind === 'event') return { kind: 'event', id: shape.id, value: record.value };\n if (shape.kind === 'failure' && typeof record.message === 'string') {\n return { kind: 'failure', id: shape.id, message: record.message };\n }\n return null;\n}\n"],"names":["RUNTIME_WIRE_PROTOCOL","PROTOCOL_MISMATCH","reason","reauthorizationOffered","refusal","MEMBERS","TOPICS","AUTHORIZATION_ENDED","PORT_CLOSED","envelope","message","mdRuntime","carried","data","record","matching","body","kind","id","request","shape","Array","isArray","input","includes","member","topic","answer","value"],"mappings":"AAEA,OAAO,MAAMA,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,oB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cesContent":["import type { ConnectionRefusal } from './connection.js';\n\nexport const RUNTIME_WIRE_PROTOCOL = 8;\n\nexport const PROTOCOL_MISMATCH: ConnectionRefusal = {\n reason: 'client-host-protocol-mismatch',\n reauthorizationOffered: false,\n refusal: null,\n};\n\nexport type RuntimePort = {\n postMessage(message: unknown): void;\n addEventListener(type: 'message' | 'close', listener: (event: { data?: unknown }) => void): void;\n start(): void;\n};\n\nconst MEMBERS = [\n 'rooms',\n 'slots',\n 'query',\n 'search',\n 'types',\n 'syncStatus',\n 'serviceMode',\n 'save',\n 'outcome',\n 'history',\n 'call',\n 'log',\n 'storageLoss',\n 'persistence',\n 'deploymentFacts',\n 'reauthorize',\n 'roomDraft.list',\n 'roomDraft.read',\n 'roomDraft.write',\n 'roomDraft.discard',\n 'presentation.read',\n 'presentation.write',\n 'conversation.list',\n 'conversation.read',\n 'conversation.create',\n 'conversation.send',\n 'conversation.answer',\n 'conversation.interrupt',\n 'conversation.kill',\n 'conversation.cancel',\n 'conversation.delete',\n 'chatDraft.write',\n 'chatDraft.discard',\n] as const;\n\nconst TOPICS = [\n 'rooms',\n 'connection-refusal',\n 'storage-loss',\n 'deployment-facts',\n 'sync-status',\n 'service-mode',\n 'query',\n 'queue',\n 'room-drafts',\n 'presentation',\n 'conversation',\n] as const;\n\nexport type WireMember = (typeof MEMBERS)[number];\nexport type WireTopic = (typeof TOPICS)[number];\n\nexport type WireRequest =\n | { kind: 'hello' }\n | { kind: 'call'; id: number; member: WireMember; input: readonly unknown[] }\n | { kind: 'observe'; id: number; topic: WireTopic; input: readonly unknown[] }\n | { kind: 'stop'; id: number };\n\nexport type WireAnswer =\n | { kind: 'result'; id: number; value: unknown }\n | { kind: 'failure'; id: number; message: string }\n | { kind: 'event'; id: number; value: unknown }\n | { kind: 'refusal'; refusal: ConnectionRefusal }\n | { kind: 'ended' };\n\nexport const AUTHORIZATION_ENDED = 'the host authorization ended';\n\nexport const PORT_CLOSED = 'the port closed';\n\nexport type WireEnvelope = { mdRuntime: number; message: WireRequest | WireAnswer };\n\nexport type Carried = { matching: boolean; message: unknown };\n\nexport function envelope(message: WireRequest | WireAnswer): WireEnvelope {\n return { mdRuntime: RUNTIME_WIRE_PROTOCOL, message };\n}\n\nexport function carried(data: unknown): Carried | null {\n if (typeof data !== 'object' || data === null || !('mdRuntime' in data)) return null;\n const record = data as { mdRuntime: unknown; message?: unknown };\n return { matching: record.mdRuntime === RUNTIME_WIRE_PROTOCOL, message: record.message };\n}\n\nfunction body(message: unknown): { kind: unknown; id: unknown } | null {\n if (typeof message !== 'object' || message === null) return null;\n const record = message as { kind?: unknown; id?: unknown };\n return { kind: record.kind, id: record.id };\n}\n\nexport function request(message: unknown): WireRequest | null {\n const shape = body(message);\n if (shape === null) return null;\n if (shape.kind === 'hello') return { kind: 'hello' };\n if (typeof shape.id !== 'number') return null;\n const record = message as { input?: unknown; member?: unknown; topic?: unknown };\n if (shape.kind === 'stop') return { kind: 'stop', id: shape.id };\n if (!Array.isArray(record.input)) return null;\n if (shape.kind === 'call' && MEMBERS.includes(record.member as WireMember)) {\n return {\n kind: 'call',\n id: shape.id,\n member: record.member as WireMember,\n input: record.input as readonly unknown[],\n };\n }\n if (shape.kind === 'observe' && TOPICS.includes(record.topic as WireTopic)) {\n return {\n kind: 'observe',\n id: shape.id,\n topic: record.topic as WireTopic,\n input: record.input as readonly unknown[],\n };\n }\n return null;\n}\n\nexport function answer(message: unknown): WireAnswer | null {\n const shape = body(message);\n if (shape === null) return null;\n const record = message as { value?: unknown; message?: unknown; refusal?: unknown };\n if (shape.kind === 'refusal') {\n return { kind: 'refusal', refusal: record.refusal as ConnectionRefusal };\n }\n if (shape.kind === 'ended') return { kind: 'ended' };\n if (typeof shape.id !== 'number') return null;\n if (shape.kind === 'result') return { kind: 'result', id: shape.id, value: record.value };\n if (shape.kind === 'event') return { kind: 'event', id: shape.id, value: record.value };\n if (shape.kind === 'failure' && typeof record.message === 'string') {\n return { kind: 'failure', id: shape.id, message: record.message };\n }\n return null;\n}\n"],"names":["RUNTIME_WIRE_PROTOCOL","PROTOCOL_MISMATCH","reason","reauthorizationOffered","refusal","MEMBERS","TOPICS","AUTHORIZATION_ENDED","PORT_CLOSED","envelope","message","mdRuntime","carried","data","record","matching","body","kind","id","request","shape","Array","isArray","input","includes","member","topic","answer","value"],"mappings":"AAEA,OAAO,MAAMA,wBAAwB,EAAE;AAEvC,OAAO,MAAMC,oBAAuC;IAClDC,QAAQ;IACRC,wBAAwB;IACxBC,SAAS;AACX,EAAE;AAQF,MAAMC,UAAU;IACd;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAED,MAAMC,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAkBD,OAAO,MAAMC,sBAAsB,+BAA+B;AAElE,OAAO,MAAMC,cAAc,kBAAkB;AAM7C,OAAO,SAASC,SAASC,OAAiC;IACxD,OAAO;QAAEC,WAAWX;QAAuBU;IAAQ;AACrD;AAEA,OAAO,SAASE,QAAQC,IAAa;IACnC,IAAI,OAAOA,SAAS,YAAYA,SAAS,QAAQ,CAAE,CAAA,eAAeA,IAAG,GAAI,OAAO;IAChF,MAAMC,SAASD;IACf,OAAO;QAAEE,UAAUD,OAAOH,SAAS,KAAKX;QAAuBU,SAASI,OAAOJ,OAAO;IAAC;AACzF;AAEA,SAASM,KAAKN,OAAgB;IAC5B,IAAI,OAAOA,YAAY,YAAYA,YAAY,MAAM,OAAO;IAC5D,MAAMI,SAASJ;IACf,OAAO;QAAEO,MAAMH,OAAOG,IAAI;QAAEC,IAAIJ,OAAOI,EAAE;IAAC;AAC5C;AAEA,OAAO,SAASC,QAAQT,OAAgB;IACtC,MAAMU,QAAQJ,KAAKN;IACnB,IAAIU,UAAU,MAAM,OAAO;IAC3B,IAAI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E;QAAEU,OAAOd,OAAOc,KAAK;IAAC;IACtF,IAAIR,MAAMH,IAAI,KAAK,aAAa,OAAOH,OAAOJ,OAAO,KAAK,UAAU;QAClE,OAAO;YAAEO,MAAM;YAAWC,IAAIE,MAAMF,EAAE;YAAER,SAASI,OAAOJ,OAAO;QAAC;IAClE;IACA,OAAO;AACT"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentshouse/mdruntime",
3
- "version": "0.1.0-alpha.37",
3
+ "version": "0.1.0-alpha.39",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -37,7 +37,7 @@
37
37
  "LICENSE"
38
38
  ],
39
39
  "dependencies": {
40
- "@agentshouse/mdmodel": "0.1.0-alpha.15",
40
+ "@agentshouse/mdmodel": "0.1.0-alpha.17",
41
41
  "@tanstack/db": "0.9.2",
42
42
  "minisearch": "7.2.0"
43
43
  }