@agentshouse/mdruntime 0.1.0-alpha.24 → 0.1.0-alpha.25

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/AGENTS.md +36 -0
  2. package/dist/change-set.d.ts +4 -11
  3. package/dist/change-set.d.ts.map +1 -1
  4. package/dist/change-set.js +8 -16
  5. package/dist/change-set.js.map +1 -1
  6. package/dist/client.d.ts +7 -3
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +2 -2
  9. package/dist/client.js.map +1 -1
  10. package/dist/collection.d.ts +0 -2
  11. package/dist/collection.d.ts.map +1 -1
  12. package/dist/collection.js +0 -5
  13. package/dist/collection.js.map +1 -1
  14. package/dist/connection.d.ts +7 -5
  15. package/dist/connection.d.ts.map +1 -1
  16. package/dist/connection.js +52 -68
  17. package/dist/connection.js.map +1 -1
  18. package/dist/conversation.d.ts +4 -4
  19. package/dist/conversation.d.ts.map +1 -1
  20. package/dist/conversation.js +12 -6
  21. package/dist/conversation.js.map +1 -1
  22. package/dist/host.d.ts.map +1 -1
  23. package/dist/host.js.map +1 -1
  24. package/dist/index.d.ts +1 -2
  25. package/dist/index.d.ts.map +1 -1
  26. package/dist/index.js.map +1 -1
  27. package/dist/paths.d.ts +1 -0
  28. package/dist/paths.d.ts.map +1 -1
  29. package/dist/paths.js +8 -0
  30. package/dist/paths.js.map +1 -1
  31. package/dist/query.d.ts +199 -10
  32. package/dist/query.d.ts.map +1 -1
  33. package/dist/query.js +450 -14
  34. package/dist/query.js.map +1 -1
  35. package/dist/read-side.d.ts +10 -0
  36. package/dist/read-side.d.ts.map +1 -0
  37. package/dist/read-side.js +374 -0
  38. package/dist/read-side.js.map +1 -0
  39. package/dist/rows.d.ts +39 -0
  40. package/dist/rows.d.ts.map +1 -0
  41. package/dist/rows.js +85 -0
  42. package/dist/rows.js.map +1 -0
  43. package/dist/wire.d.ts +1 -1
  44. package/dist/wire.js +1 -1
  45. package/dist/wire.js.map +1 -1
  46. package/package.json +2 -2
package/dist/rows.js ADDED
@@ -0,0 +1,85 @@
1
+ import { governing } from './collection.js';
2
+ import { definitionOf } from './model.js';
3
+ import { target } from './paths.js';
4
+ function keyOf(...parts) {
5
+ return `${parts.join('\u0000')}\u0000`;
6
+ }
7
+ export function documentKey(room, path) {
8
+ return keyOf('d', room, path);
9
+ }
10
+ function referenceField(spec) {
11
+ return spec?.kind === 'reference' || spec?.kind === 'list' && spec.of.kind === 'reference';
12
+ }
13
+ function targetOf(path, value) {
14
+ return typeof value === 'string' ? target(path, value) : null;
15
+ }
16
+ function resolved(path, value) {
17
+ if (value === null) return null;
18
+ if (!Array.isArray(value)) return targetOf(path, value) ?? undefined;
19
+ return value.map((item)=>targetOf(path, item)).filter((item)=>item !== null);
20
+ }
21
+ function directoriesOf(path) {
22
+ const parts = path.split('/').slice(0, -1);
23
+ return [
24
+ '',
25
+ ...parts.map((_, index)=>parts.slice(0, index + 1).join('/'))
26
+ ];
27
+ }
28
+ export function rowsOf(room, path, document, composition) {
29
+ if (!path.endsWith('.md')) return [];
30
+ const type = document.type ?? 'any';
31
+ const definition = definitionOf(governing(composition, path), document.type);
32
+ const key = documentKey(room, path);
33
+ const values = {};
34
+ const sizes = {};
35
+ const references = [];
36
+ for (const [name, value] of Object.entries(document.fields)){
37
+ const reference = referenceField(definition?.fields[name]);
38
+ const compared = reference ? resolved(path, value) : value;
39
+ if (compared !== undefined) values[name] = compared;
40
+ if (Array.isArray(value)) sizes[name] = value.length;
41
+ if (!reference) continue;
42
+ const targets = [
43
+ compared
44
+ ].flat().filter((found)=>typeof found === 'string');
45
+ for (const found of new Set(targets)){
46
+ references.push({
47
+ key: keyOf('r', room, path, name, found),
48
+ kind: 'reference',
49
+ room,
50
+ source: key,
51
+ target: documentKey(room, found),
52
+ field: name,
53
+ path,
54
+ type
55
+ });
56
+ }
57
+ }
58
+ const body = keyOf('b', room, path);
59
+ return [
60
+ {
61
+ key,
62
+ kind: 'document',
63
+ room,
64
+ path,
65
+ type,
66
+ fields: document.fields,
67
+ values,
68
+ sizes,
69
+ directories: directoriesOf(path),
70
+ body
71
+ },
72
+ {
73
+ key: body,
74
+ kind: 'body',
75
+ room,
76
+ path,
77
+ preamble: document.preamble,
78
+ sections: document.sections,
79
+ markdown: document.content
80
+ },
81
+ ...references
82
+ ];
83
+ }
84
+
85
+ //# sourceMappingURL=rows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/rows.ts"],"sourcesContent":["import type { Document, FieldSpec } from '@agentshouse/mdmodel';\nimport { governing, type Composition } from './collection.js';\nimport { definitionOf } from './model.js';\nimport { target } from './paths.js';\n\ntype Fields = Readonly<Record<string, unknown>>;\n\nexport type DocumentRow = {\n key: string;\n kind: 'document';\n room: string;\n path: string;\n type: string;\n fields: Fields;\n values: Fields;\n sizes: Readonly<Record<string, number>>;\n directories: readonly string[];\n body: string;\n};\n\nexport type BodyRow = {\n key: string;\n kind: 'body';\n room: string;\n path: string;\n preamble: string;\n sections: Readonly<Record<string, string>>;\n markdown: string;\n};\n\nexport type ReferenceRow = {\n key: string;\n kind: 'reference';\n room: string;\n source: string;\n target: string;\n field: string;\n path: string;\n type: string;\n};\n\nexport type Row = DocumentRow | BodyRow | ReferenceRow;\n\nfunction keyOf(...parts: readonly string[]): string {\n return `${parts.join('\\u0000')}\\u0000`;\n}\n\nexport function documentKey(room: string, path: string): string {\n return keyOf('d', room, path);\n}\n\nfunction referenceField(spec: FieldSpec | undefined): boolean {\n return spec?.kind === 'reference' || (spec?.kind === 'list' && spec.of.kind === 'reference');\n}\n\nfunction targetOf(path: string, value: unknown): string | null {\n return typeof value === 'string' ? target(path, value) : null;\n}\n\nfunction resolved(path: string, value: unknown): unknown {\n if (value === null) return null;\n if (!Array.isArray(value)) return targetOf(path, value) ?? undefined;\n return value.map((item) => targetOf(path, item)).filter((item) => item !== null);\n}\n\nfunction directoriesOf(path: string): readonly string[] {\n const parts = path.split('/').slice(0, -1);\n return ['', ...parts.map((_, index) => parts.slice(0, index + 1).join('/'))];\n}\n\nexport function rowsOf(\n room: string,\n path: string,\n document: Document,\n composition: Composition,\n): readonly Row[] {\n if (!path.endsWith('.md')) return [];\n const type = document.type ?? 'any';\n const definition = definitionOf(governing(composition, path), document.type);\n const key = documentKey(room, path);\n const values: Record<string, unknown> = {};\n const sizes: Record<string, number> = {};\n const references: ReferenceRow[] = [];\n for (const [name, value] of Object.entries(document.fields)) {\n const reference = referenceField(definition?.fields[name]);\n const compared = reference ? resolved(path, value) : value;\n if (compared !== undefined) values[name] = compared;\n if (Array.isArray(value)) sizes[name] = value.length;\n if (!reference) continue;\n const targets = [compared].flat().filter((found) => typeof found === 'string');\n for (const found of new Set(targets)) {\n references.push({\n key: keyOf('r', room, path, name, found),\n kind: 'reference',\n room,\n source: key,\n target: documentKey(room, found),\n field: name,\n path,\n type,\n });\n }\n }\n const body = keyOf('b', room, path);\n return [\n {\n key,\n kind: 'document',\n room,\n path,\n type,\n fields: document.fields,\n values,\n sizes,\n directories: directoriesOf(path),\n body,\n },\n {\n key: body,\n kind: 'body',\n room,\n path,\n preamble: document.preamble,\n sections: document.sections,\n markdown: document.content,\n },\n ...references,\n ];\n}\n"],"names":["governing","definitionOf","target","keyOf","parts","join","documentKey","room","path","referenceField","spec","kind","of","targetOf","value","resolved","Array","isArray","undefined","map","item","filter","directoriesOf","split","slice","_","index","rowsOf","document","composition","endsWith","type","definition","key","values","sizes","references","name","Object","entries","fields","reference","compared","length","targets","flat","found","Set","push","source","field","body","directories","preamble","sections","markdown","content"],"mappings":"AACA,SAASA,SAAS,QAA0B,kBAAkB;AAC9D,SAASC,YAAY,QAAQ,aAAa;AAC1C,SAASC,MAAM,QAAQ,aAAa;AAwCpC,SAASC,MAAM,GAAGC,KAAwB;IACxC,OAAO,GAAGA,MAAMC,IAAI,CAAC,UAAU,MAAM,CAAC;AACxC;AAEA,OAAO,SAASC,YAAYC,IAAY,EAAEC,IAAY;IACpD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K;QACzD,MAAMK,WAAWD,YAAY1B,SAASP,MAAMM,SAASA;QACrD,IAAI4B,aAAaxB,WAAWgB,MAAM,CAACG,KAAK,GAAGK;QAC3C,IAAI1B,MAAMC,OAAO,CAACH,QAAQqB,KAAK,CAACE,KAAK,GAAGvB,MAAM6B,MAAM;QACpD,IAAI,CAACF,WAAW;QAChB,MAAMG,UAAU;YAACF;SAAS,CAACG,IAAI,GAAGxB,MAAM,CAAC,CAACyB,QAAU,OAAOA,UAAU;QACrE,KAAK,MAAMA,SAAS,IAAIC,IAAIH,SAAU;YACpCR,WAAWY,IAAI,CAAC;gBACdf,KAAK9B,MAAM,KAAKI,MAAMC,MAAM6B,MAAMS;gBAClCnC,MAAM;gBACNJ;gBACA0C,QAAQhB;gBACR/B,QAAQI,YAAYC,MAAMuC;gBAC1BI,OAAOb;gBACP7B;gBACAuB;YACF;QACF;IACF;IACA,MAAMoB,OAAOhD,MAAM,KAAKI,MAAMC;IAC9B,OAAO;QACL;YACEyB;YACAtB,MAAM;YACNJ;YACAC;YACAuB;YACAS,QAAQZ,SAASY,MAAM;YACvBN;YACAC;YACAiB,aAAa9B,cAAcd;YAC3B2C;QACF;QACA;YACElB,KAAKkB;YACLxC,MAAM;YACNJ;YACAC;YACA6C,UAAUzB,SAASyB,QAAQ;YAC3BC,UAAU1B,SAAS0B,QAAQ;YAC3BC,UAAU3B,SAAS4B,OAAO;QAC5B;WACGpB;KACJ;AACH"}
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 = 4;
2
+ export declare const RUNTIME_WIRE_PROTOCOL = 5;
3
3
  export declare const PROTOCOL_MISMATCH: ConnectionRefusal;
4
4
  export type RuntimePort = {
5
5
  postMessage(message: unknown): void;
package/dist/wire.js CHANGED
@@ -1,4 +1,4 @@
1
- export const RUNTIME_WIRE_PROTOCOL = 4;
1
+ export const RUNTIME_WIRE_PROTOCOL = 5;
2
2
  export const PROTOCOL_MISMATCH = {
3
3
  reason: 'client-host-protocol-mismatch',
4
4
  reauthorizationOffered: false,
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 = 4;\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 '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 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","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;CACD;AAED,MAAMC,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAkBD,OAAO,MAAMC,sBAAsB,+BAA+B;AAMlE,OAAO,SAASC,SAASC,OAAiC;IACxD,OAAO;QAAEC,WAAWV;QAAuBS;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,KAAKV;QAAuBS,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,KAA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S,OAAO;QAAEA,MAAM;QAASC,IAAIE,MAAMF,EAAE;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"}
1
+ {"version":3,"sources":["/workspace/packages/mdruntime/src/wire.ts"],"sourcesContent":["import type { ConnectionRefusal } from './connection.js';\n\nexport const RUNTIME_WIRE_PROTOCOL = 5;\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 '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 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","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;CACD;AAED,MAAMC,SAAS;IACb;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACA;CACD;AAkBD,OAAO,MAAMC,sBAAsB,+BAA+B;AAMlE,OAAO,SAASC,SAASC,OAAiC;IACxD,OAAO;QAAEC,WAAWV;QAAuBS;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,KAAKV;QAAuBS,SAASI,OAAOJ,OAAO;IAAC;AACzF;AAEA,SAASM,KAAKN,OAAgB;IAC5B,IAAI,OAAOA,YAAY,YAAYA,YAAY,MAAM,OAAO;IAC5D,MAAMI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AIE,MAAMH,IAAI,KAAK,UAAU,OAAO;QAAEA,MAAM;QAAUC,IAAIE,MAAMF,EAAE;QAAEU,OAAOd,OAAOc,KAAK;IAAC;IACxF,IAAIR,MAAMH,IAAI,KAAK,SAAS,OAAO;QAAEA,MAAM;QAASC,IAAIE,MAAMF,EAAE;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.24",
3
+ "version": "0.1.0-alpha.25",
4
4
  "description": "The headless core of MD App",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -46,6 +46,6 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@agentshouse/mdmodel": "0.1.0-alpha.14",
49
- "@agentshouse/query": "0.1.0-alpha.12"
49
+ "@tanstack/db": "0.9.2"
50
50
  }
51
51
  }