@revealui/ai 0.2.9 → 0.4.0

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 (82) hide show
  1. package/README.md +200 -26
  2. package/dist/a2a/handler.d.ts +3 -1
  3. package/dist/a2a/handler.d.ts.map +1 -1
  4. package/dist/a2a/handler.js +24 -7
  5. package/dist/a2a/task-store.d.ts.map +1 -1
  6. package/dist/a2a/task-store.js +5 -1
  7. package/dist/client/hooks/useAgentStream.d.ts +84 -1
  8. package/dist/client/hooks/useAgentStream.d.ts.map +1 -1
  9. package/dist/client/hooks/useAgentStream.js +106 -10
  10. package/dist/index.d.ts +4 -6
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +4 -15
  13. package/dist/ingestion/admin-indexer.js +1 -1
  14. package/dist/ingestion/pipeline.d.ts +1 -1
  15. package/dist/ingestion/pipeline.d.ts.map +1 -1
  16. package/dist/llm/client.d.ts +33 -10
  17. package/dist/llm/client.d.ts.map +1 -1
  18. package/dist/llm/client.js +70 -57
  19. package/dist/llm/key-validator.d.ts.map +1 -1
  20. package/dist/llm/key-validator.js +0 -27
  21. package/dist/llm/providers/inference-snaps.d.ts +7 -5
  22. package/dist/llm/providers/inference-snaps.d.ts.map +1 -1
  23. package/dist/llm/providers/inference-snaps.js +7 -5
  24. package/dist/llm/providers/openai-compat.d.ts +1 -1
  25. package/dist/llm/providers/openai-compat.js +1 -1
  26. package/dist/llm/response-cache.d.ts +1 -2
  27. package/dist/llm/response-cache.d.ts.map +1 -1
  28. package/dist/llm/response-cache.js +1 -2
  29. package/dist/llm/server.d.ts +1 -1
  30. package/dist/llm/server.d.ts.map +1 -1
  31. package/dist/llm/server.js +3 -1
  32. package/dist/memory/crdt/lww-register.js +1 -1
  33. package/dist/memory/preferences/user-preferences-manager.d.ts.map +1 -1
  34. package/dist/memory/preferences/user-preferences-manager.js +1 -1
  35. package/dist/memory/services/index.d.ts +2 -0
  36. package/dist/memory/services/index.d.ts.map +1 -1
  37. package/dist/memory/services/index.js +1 -0
  38. package/dist/memory/services/reconciliation-service.d.ts +64 -0
  39. package/dist/memory/services/reconciliation-service.d.ts.map +1 -0
  40. package/dist/memory/services/reconciliation-service.js +127 -0
  41. package/dist/memory/stores/working-memory.d.ts.map +1 -1
  42. package/dist/memory/stores/working-memory.js +1 -1
  43. package/dist/memory/utils/index.d.ts +1 -2
  44. package/dist/memory/utils/index.d.ts.map +1 -1
  45. package/dist/memory/utils/index.js +1 -2
  46. package/dist/memory/utils/sql-helpers.d.ts +21 -66
  47. package/dist/memory/utils/sql-helpers.d.ts.map +1 -1
  48. package/dist/memory/utils/sql-helpers.js +34 -169
  49. package/dist/memory/vector/vector-memory-service.d.ts.map +1 -1
  50. package/dist/memory/vector/vector-memory-service.js +6 -1
  51. package/dist/orchestration/runtime.d.ts +30 -1
  52. package/dist/orchestration/runtime.d.ts.map +1 -1
  53. package/dist/orchestration/runtime.js +20 -3
  54. package/dist/orchestration/streaming-runtime.d.ts +48 -1
  55. package/dist/orchestration/streaming-runtime.d.ts.map +1 -1
  56. package/dist/orchestration/ticket-agent.d.ts +10 -1
  57. package/dist/orchestration/ticket-agent.d.ts.map +1 -1
  58. package/dist/orchestration/ticket-agent.js +11 -2
  59. package/dist/skills/catalog/vercel-catalog.d.ts.map +1 -1
  60. package/dist/skills/catalog/vercel-catalog.js +13 -7
  61. package/dist/tools/mcp-adapter.d.ts +192 -1
  62. package/dist/tools/mcp-adapter.d.ts.map +1 -1
  63. package/dist/tools/mcp-adapter.js +434 -1
  64. package/dist/tools/mcp-elicitation.d.ts +128 -0
  65. package/dist/tools/mcp-elicitation.d.ts.map +1 -0
  66. package/dist/tools/mcp-elicitation.js +121 -0
  67. package/dist/tools/mcp-events.d.ts +270 -0
  68. package/dist/tools/mcp-events.d.ts.map +1 -0
  69. package/dist/tools/mcp-events.js +165 -0
  70. package/dist/tools/mcp-sampling.d.ts +155 -0
  71. package/dist/tools/mcp-sampling.d.ts.map +1 -0
  72. package/dist/tools/mcp-sampling.js +171 -0
  73. package/dist/tools/ticket-tools.d.ts +35 -2
  74. package/dist/tools/ticket-tools.d.ts.map +1 -1
  75. package/dist/tools/ticket-tools.js +32 -2
  76. package/package.json +38 -12
  77. package/dist/llm/providers/vultr.d.ts +0 -18
  78. package/dist/llm/providers/vultr.d.ts.map +0 -1
  79. package/dist/llm/providers/vultr.js +0 -169
  80. package/dist/memory/utils/deep-clone.d.ts +0 -10
  81. package/dist/memory/utils/deep-clone.d.ts.map +0 -1
  82. package/dist/memory/utils/deep-clone.js +0 -9
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/services/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/services/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,YAAY,EACV,aAAa,EACb,gBAAgB,EAChB,oBAAoB,EACpB,eAAe,GAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,yBAAyB,EACzB,2BAA2B,EAC3B,kBAAkB,GACnB,MAAM,6BAA6B,CAAC"}
@@ -4,3 +4,4 @@
4
4
  * Business logic services for memory operations.
5
5
  */
6
6
  export { NodeIdService } from './node-id-service.js';
7
+ export { buildReconciliationPrompt, parseReconciliationResponse, reconcileHeuristic, } from './reconciliation-service.js';
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Reconciliation Service - Fact resolution for multi-agent memory.
3
+ *
4
+ * Reads shared facts from a coordination session, groups related facts,
5
+ * deduplicates, and resolves contradictions. Produces reconciled memories
6
+ * for Layer 3.
7
+ *
8
+ * Layer 3 of the multi-agent shared memory architecture.
9
+ *
10
+ * LICENSING BOUNDARY:
11
+ * - `reconcileHeuristic()` is the production path — no external API calls,
12
+ * safe for all tiers including free customers.
13
+ * - `buildReconciliationPrompt()` and `parseReconciliationResponse()` are
14
+ * reference implementations for internal/developer use only. They build
15
+ * a prompt string but DO NOT call any LLM API. If wired to an LLM provider,
16
+ * the caller is responsible for API pricing and usage compliance.
17
+ * - Customer-facing reconciliation MUST use the heuristic path or a
18
+ * self-hosted model (e.g. Ollama). Do not proxy third-party LLM APIs
19
+ * to end users without a commercial API agreement with the provider.
20
+ */
21
+ export interface SharedFactInput {
22
+ id: string;
23
+ agentId: string;
24
+ content: string;
25
+ factType: string;
26
+ confidence: number;
27
+ tags: string[];
28
+ sourceRef?: Record<string, unknown> | null;
29
+ }
30
+ export interface ReconciledMemory {
31
+ content: string;
32
+ type: string;
33
+ sourceFactIds: string[];
34
+ confidence: number;
35
+ }
36
+ export interface Contradiction {
37
+ factIds: string[];
38
+ description: string;
39
+ resolution: string;
40
+ }
41
+ export interface ReconciliationResult {
42
+ canonicalFacts: ReconciledMemory[];
43
+ contradictions: Contradiction[];
44
+ duplicates: string[][];
45
+ summary: string;
46
+ }
47
+ /**
48
+ * Build the reconciliation prompt for an LLM.
49
+ * The prompt asks the model to analyze facts from multiple agents and
50
+ * produce a structured reconciliation result.
51
+ */
52
+ export declare function buildReconciliationPrompt(facts: SharedFactInput[], scratchpadContent?: Record<string, unknown>): string;
53
+ /**
54
+ * Parse the LLM response into a structured reconciliation result.
55
+ * Maps 1-based fact indices back to actual fact IDs.
56
+ */
57
+ export declare function parseReconciliationResponse(response: string, facts: SharedFactInput[]): ReconciliationResult;
58
+ /**
59
+ * Simple heuristic reconciliation (no LLM required).
60
+ * Deduplicates by normalized content and groups by type.
61
+ * Use this as a fallback when no LLM provider is configured.
62
+ */
63
+ export declare function reconcileHeuristic(facts: SharedFactInput[]): ReconciliationResult;
64
+ //# sourceMappingURL=reconciliation-service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reconciliation-service.d.ts","sourceRoot":"","sources":["../../../src/memory/services/reconciliation-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,MAAM,WAAW,eAAe;IAC9B,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;CAC5C;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,EAAE,MAAM,EAAE,CAAC;IACxB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,cAAc,EAAE,gBAAgB,EAAE,CAAC;IACnC,cAAc,EAAE,aAAa,EAAE,CAAC;IAChC,UAAU,EAAE,MAAM,EAAE,EAAE,CAAC;IACvB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,KAAK,EAAE,eAAe,EAAE,EACxB,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1C,MAAM,CAuCR;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CACzC,QAAQ,EAAE,MAAM,EAChB,KAAK,EAAE,eAAe,EAAE,GACvB,oBAAoB,CAsCtB;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,EAAE,GAAG,oBAAoB,CAsCjF"}
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Reconciliation Service - Fact resolution for multi-agent memory.
3
+ *
4
+ * Reads shared facts from a coordination session, groups related facts,
5
+ * deduplicates, and resolves contradictions. Produces reconciled memories
6
+ * for Layer 3.
7
+ *
8
+ * Layer 3 of the multi-agent shared memory architecture.
9
+ *
10
+ * LICENSING BOUNDARY:
11
+ * - `reconcileHeuristic()` is the production path — no external API calls,
12
+ * safe for all tiers including free customers.
13
+ * - `buildReconciliationPrompt()` and `parseReconciliationResponse()` are
14
+ * reference implementations for internal/developer use only. They build
15
+ * a prompt string but DO NOT call any LLM API. If wired to an LLM provider,
16
+ * the caller is responsible for API pricing and usage compliance.
17
+ * - Customer-facing reconciliation MUST use the heuristic path or a
18
+ * self-hosted model (e.g. Ollama). Do not proxy third-party LLM APIs
19
+ * to end users without a commercial API agreement with the provider.
20
+ */
21
+ /**
22
+ * Build the reconciliation prompt for an LLM.
23
+ * The prompt asks the model to analyze facts from multiple agents and
24
+ * produce a structured reconciliation result.
25
+ */
26
+ export function buildReconciliationPrompt(facts, scratchpadContent) {
27
+ const factList = facts
28
+ .map((f, i) => `${i + 1}. [${f.factType}] (agent: ${f.agentId}, confidence: ${f.confidence}) ${f.content}` +
29
+ (f.tags.length > 0 ? ` [tags: ${f.tags.join(', ')}]` : ''))
30
+ .join('\n');
31
+ const scratchpadSection = scratchpadContent
32
+ ? `\n\nShared scratchpad content:\n${JSON.stringify(scratchpadContent, null, 2)}`
33
+ : '';
34
+ return `You are reconciling discoveries from multiple AI agents working on the same task.
35
+
36
+ Facts discovered by agents:
37
+ ${factList}
38
+ ${scratchpadSection}
39
+
40
+ Analyze these facts and produce a JSON response with:
41
+ 1. "canonicalFacts": Array of canonical truths. For each:
42
+ - "content": The canonical fact statement
43
+ - "type": One of: fact, preference, decision, warning, skill
44
+ - "sourceFactIds": Array of source fact indices (1-based) that support this
45
+ - "confidence": 0-1 confidence score
46
+ 2. "contradictions": Array of contradictions found. For each:
47
+ - "factIndices": The conflicting fact indices
48
+ - "description": What contradicts
49
+ - "resolution": How to resolve (which is correct and why)
50
+ 3. "duplicates": Array of arrays of fact indices that say the same thing
51
+ 4. "summary": One-sentence summary of the reconciliation
52
+
53
+ Rules:
54
+ - Merge duplicate facts into one canonical fact
55
+ - When facts contradict, determine which is correct based on confidence and specificity
56
+ - Preserve the most specific and actionable version of each fact
57
+ - Do not invent facts not supported by the inputs
58
+
59
+ Respond with ONLY valid JSON, no markdown fencing.`;
60
+ }
61
+ /**
62
+ * Parse the LLM response into a structured reconciliation result.
63
+ * Maps 1-based fact indices back to actual fact IDs.
64
+ */
65
+ export function parseReconciliationResponse(response, facts) {
66
+ const parsed = JSON.parse(response);
67
+ const mapIndices = (indices) => indices
68
+ .filter((i) => i >= 1 && i <= facts.length)
69
+ .map((i) => facts[i - 1]?.id)
70
+ .filter((id) => id !== undefined);
71
+ return {
72
+ canonicalFacts: (parsed.canonicalFacts ?? []).map((cf) => ({
73
+ content: cf.content,
74
+ type: cf.type,
75
+ sourceFactIds: mapIndices(cf.sourceFactIds ?? []),
76
+ confidence: cf.confidence ?? 1.0,
77
+ })),
78
+ contradictions: (parsed.contradictions ?? []).map((c) => ({
79
+ factIds: mapIndices(c.factIndices ?? []),
80
+ description: c.description ?? '',
81
+ resolution: c.resolution ?? '',
82
+ })),
83
+ duplicates: (parsed.duplicates ?? []).map((group) => mapIndices(group)),
84
+ summary: parsed.summary ?? 'Reconciliation complete.',
85
+ };
86
+ }
87
+ /**
88
+ * Simple heuristic reconciliation (no LLM required).
89
+ * Deduplicates by normalized content and groups by type.
90
+ * Use this as a fallback when no LLM provider is configured.
91
+ */
92
+ export function reconcileHeuristic(facts) {
93
+ const seen = new Map();
94
+ const canonicalFacts = [];
95
+ const duplicates = [];
96
+ for (const fact of facts) {
97
+ const normalized = fact.content.toLowerCase().trim();
98
+ const existing = seen.get(normalized);
99
+ if (existing) {
100
+ existing.push(fact.id);
101
+ }
102
+ else {
103
+ seen.set(normalized, [fact.id]);
104
+ }
105
+ }
106
+ for (const [, ids] of seen) {
107
+ if (ids.length > 1) {
108
+ duplicates.push(ids);
109
+ }
110
+ const sourceFact = facts.find((f) => f.id === ids[0]);
111
+ if (sourceFact) {
112
+ const memoryType = sourceFact.factType === 'bug' || sourceFact.factType === 'warning' ? 'warning' : 'fact';
113
+ canonicalFacts.push({
114
+ content: sourceFact.content,
115
+ type: memoryType,
116
+ sourceFactIds: ids,
117
+ confidence: sourceFact.confidence,
118
+ });
119
+ }
120
+ }
121
+ return {
122
+ canonicalFacts,
123
+ contradictions: [],
124
+ duplicates,
125
+ summary: `Reconciled ${facts.length} facts into ${canonicalFacts.length} canonical facts (${duplicates.length} duplicates).`,
126
+ };
127
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"working-memory.d.ts","sourceRoot":"","sources":["../../../src/memory/stores/working-memory.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,EAAe,KAAK,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAC5E,OAAO,EAAS,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAO3D,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,QAAQ,GAAG,QAAQ,GAAG,WAAW,CAAC;IAC1C,KAAK,CAAC,EAAE;QACN,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;KACtB,CAAC;IACF,WAAW,CAAC,EAAE;QACZ,EAAE,EAAE,MAAM,CAAC;QACX,WAAW,EAAE,MAAM,CAAC;QACp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IAgB3B;;;;OAIG;IACH,MAAM,IAAI,iBAAiB;IAU3B;;;;;;OAMG;IACH,MAAM,CAAC,QAAQ,CACb,IAAI,EAAE,iBAAiB,EACvB,WAAW,CAAC,EAAE,eAAe,EAC7B,WAAW,CAAC,EAAE,WAAW,GACxB,aAAa;IAQhB;;;;OAIG;IACH,KAAK,IAAI,aAAa;IAItB;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,SAAS,IAAI,MAAM;IAInB;;;;;OAKG;IACH,mBAAmB,IAAI,MAAM;CAG9B"}
@@ -8,9 +8,9 @@
8
8
  * - Active Agents: ORSet for collection of active agent configurations
9
9
  * - Session State: LWWRegister for session metadata
10
10
  */
11
+ import { deepClone } from '@revealui/core/utils/deep-clone';
11
12
  import { LWWRegister } from '../crdt/lww-register.js';
12
13
  import { ORSet } from '../crdt/or-set.js';
13
- import { deepClone } from '../utils/deep-clone.js';
14
14
  // =============================================================================
15
15
  // Working Memory
16
16
  // =============================================================================
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * Utility functions
3
3
  */
4
- export { deepClone } from './deep-clone.js';
5
- export { findAgentContextById, findAgentMemoriesByUserId, findAgentMemoryById, findNodeIdMappingByEntity, findNodeIdMappingByHash, findUserById, } from './sql-helpers.js';
4
+ export { findAgentContextById, findNodeIdMappingByEntity, findNodeIdMappingByHash, findUserById, } from './sql-helpers.js';
6
5
  export { estimateObjectSize, hasCircularReference, validateContext, validateContextKey, validateContextSize, validateContextValue, validateObjectDepth, } from './validation.js';
7
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,mBAAmB,EACnB,yBAAyB,EACzB,uBAAuB,EACvB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/memory/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,uBAAuB,EACvB,YAAY,GACb,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC"}
@@ -1,6 +1,5 @@
1
1
  /**
2
2
  * Utility functions
3
3
  */
4
- export { deepClone } from './deep-clone.js';
5
- export { findAgentContextById, findAgentMemoriesByUserId, findAgentMemoryById, findNodeIdMappingByEntity, findNodeIdMappingByHash, findUserById, } from './sql-helpers.js';
4
+ export { findAgentContextById, findNodeIdMappingByEntity, findNodeIdMappingByHash, findUserById, } from './sql-helpers.js';
6
5
  export { estimateObjectSize, hasCircularReference, validateContext, validateContextKey, validateContextSize, validateContextValue, validateObjectDepth, } from './validation.js';
@@ -1,15 +1,21 @@
1
1
  /**
2
- * SQL Helper Utilities
3
- *
4
- * Provides type-safe raw SQL query helpers to work around Neon HTTP driver
5
- * compatibility issues with Drizzle's relational query builder.
6
- *
7
- * These helpers use Drizzle's sql tagged template for type safety and
8
- * SQL injection prevention.
2
+ * Memory-layer query helpers
3
+ *
4
+ * Small, typed helpers for lookups performed by the agent-memory persistence
5
+ * layer. Every helper returns a Drizzle-inferred row shape — no manual
6
+ * snake_case → camelCase transformation needed.
7
+ *
8
+ * History: originally written with `db.execute(sql`…`)` + hand-rolled result
9
+ * unwrapping as a defensive posture against an early Neon HTTP driver
10
+ * incompatibility with Drizzle's relational query builder (`db.query.*`).
11
+ * Ported to the core query builder (`db.select().from(…).where(…).limit(1)`)
12
+ * in Phase 6.1 — the same callers already use `.update()` and `.insert()`
13
+ * against the same tables on the same Database client without issue, and the
14
+ * core builder is a different code path from the relational one.
9
15
  */
10
- import type { AgentMemory } from '@revealui/contracts/agents';
11
16
  import type { NodeIdMappingsRow } from '@revealui/contracts/generated';
12
17
  import type { Database } from '@revealui/db/client';
18
+ import type { AgentContext, User } from '@revealui/db/schema';
13
19
  /**
14
20
  * Finds a node ID mapping by hash (primary key).
15
21
  *
@@ -19,7 +25,7 @@ import type { Database } from '@revealui/db/client';
19
25
  */
20
26
  export declare function findNodeIdMappingByHash(db: Database, hash: string): Promise<NodeIdMappingsRow | undefined>;
21
27
  /**
22
- * Finds a node ID mapping by entity ID and type.
28
+ * Finds a node ID mapping by entity type + entity ID.
23
29
  *
24
30
  * @param db - Database client
25
31
  * @param entityType - Type of entity ('session' or 'user')
@@ -28,70 +34,19 @@ export declare function findNodeIdMappingByHash(db: Database, hash: string): Pro
28
34
  */
29
35
  export declare function findNodeIdMappingByEntity(db: Database, entityType: 'session' | 'user', entityId: string): Promise<NodeIdMappingsRow | undefined>;
30
36
  /**
31
- * Finds an agent memory by ID (returns raw database record format).
32
- *
33
- * @deprecated Use VectorMemoryService.getById() instead. This function queries
34
- * agent_memories which is now in the vector database (Supabase), not REST database.
35
- * If you need to query memories, use VectorMemoryService which uses the correct database.
36
- *
37
- * @param db - Database client (NOTE: Should be vector client, but type doesn't enforce this)
38
- * @param memoryId - Memory identifier
39
- * @returns Raw database memory record or undefined if not found
40
- */
41
- export declare function findAgentMemoryById(db: Database, memoryId: string): Promise<{
42
- id: string;
43
- version: number;
44
- content: string;
45
- type: string;
46
- source: unknown;
47
- embedding: number[] | null;
48
- embeddingMetadata: unknown;
49
- metadata: unknown;
50
- accessCount: number | null;
51
- accessedAt: Date | null;
52
- verified: boolean | null;
53
- createdAt: Date;
54
- expiresAt: Date | null;
55
- } | undefined>;
56
- /**
57
- * Finds agent memories by user ID.
58
- *
59
- * @deprecated Use VectorMemoryService.searchSimilar() or VectorMemoryService with filters instead.
60
- * This function queries agent_memories which is now in the vector database (Supabase).
61
- * If you need to query memories, use VectorMemoryService which uses the correct database.
62
- *
63
- * @param db - Database client (NOTE: Should be vector client, but type doesn't enforce this)
64
- * @param userId - User identifier
65
- * @returns Array of agent memories
66
- */
67
- export declare function findAgentMemoriesByUserId(db: Database, userId: string): Promise<AgentMemory[]>;
68
- /**
69
- * Finds an agent context by CRDT ID (returns raw database record format).
37
+ * Finds an agent context by CRDT ID.
70
38
  *
71
39
  * @param db - Database client
72
40
  * @param crdtId - CRDT identifier (format: sessionId:agentId)
73
- * @returns Raw database context record or undefined if not found
41
+ * @returns Agent context row or undefined if not found
74
42
  */
75
- export declare function findAgentContextById(db: Database, crdtId: string): Promise<{
76
- id: string;
77
- version: number;
78
- sessionId: string;
79
- agentId: string;
80
- context: unknown;
81
- priority: number | null;
82
- embedding: number[] | null;
83
- createdAt: Date;
84
- updatedAt: Date;
85
- } | undefined>;
43
+ export declare function findAgentContextById(db: Database, crdtId: string): Promise<AgentContext | undefined>;
86
44
  /**
87
- * Finds a user by ID.
45
+ * Finds a user by ID, returning only the columns the memory layer needs.
88
46
  *
89
47
  * @param db - Database client
90
48
  * @param userId - User identifier
91
- * @returns User record or undefined if not found
49
+ * @returns User record (id + preferences) or undefined if not found
92
50
  */
93
- export declare function findUserById(db: Database, userId: string): Promise<{
94
- id: string;
95
- preferences: unknown;
96
- } | undefined>;
51
+ export declare function findUserById(db: Database, userId: string): Promise<Pick<User, 'id' | 'preferences'> | undefined>;
97
52
  //# sourceMappingURL=sql-helpers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"sql-helpers.d.ts","sourceRoot":"","sources":["../../../src/memory/utils/sql-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAC9D,OAAO,KAAK,EAAE,iBAAi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QAAQ,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,YAAY,GAAG,SAAS,CAAC,CAGnC;AAMD;;;;;;GAMG;AACH,wBAAsB,YAAY,CAChC,EAAE,EAAE,QAAQ,EACZ,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,GAAG,aAAa,CAAC,GAAG,SAAS,CAAC,CAOvD"}
@@ -1,22 +1,20 @@
1
1
  /**
2
- * SQL Helper Utilities
2
+ * Memory-layer query helpers
3
3
  *
4
- * Provides type-safe raw SQL query helpers to work around Neon HTTP driver
5
- * compatibility issues with Drizzle's relational query builder.
4
+ * Small, typed helpers for lookups performed by the agent-memory persistence
5
+ * layer. Every helper returns a Drizzle-inferred row shape — no manual
6
+ * snake_case → camelCase transformation needed.
6
7
  *
7
- * These helpers use Drizzle's sql tagged template for type safety and
8
- * SQL injection prevention.
8
+ * History: originally written with `db.execute(sql`…`)` + hand-rolled result
9
+ * unwrapping as a defensive posture against an early Neon HTTP driver
10
+ * incompatibility with Drizzle's relational query builder (`db.query.*`).
11
+ * Ported to the core query builder (`db.select().from(…).where(…).limit(1)`)
12
+ * in Phase 6.1 — the same callers already use `.update()` and `.insert()`
13
+ * against the same tables on the same Database client without issue, and the
14
+ * core builder is a different code path from the relational one.
9
15
  */
10
- import { sql } from 'drizzle-orm';
11
- const getRows = (result) => {
12
- if (Array.isArray(result)) {
13
- return result;
14
- }
15
- if (result && typeof result === 'object' && Array.isArray(result.rows)) {
16
- return result.rows;
17
- }
18
- return [];
19
- };
16
+ import { agentContexts, nodeIdMappings, users } from '@revealui/db/schema';
17
+ import { and, eq } from 'drizzle-orm';
20
18
  // =============================================================================
21
19
  // Node ID Mappings Queries
22
20
  // =============================================================================
@@ -28,27 +26,11 @@ const getRows = (result) => {
28
26
  * @returns Node ID mapping or undefined if not found
29
27
  */
30
28
  export async function findNodeIdMappingByHash(db, hash) {
31
- const result = await db.execute(sql `SELECT id, entity_type, entity_id, node_id, created_at, updated_at
32
- FROM node_id_mappings
33
- WHERE id = ${hash}
34
- LIMIT 1`);
35
- // Handle different result formats (Neon HTTP vs direct Postgres)
36
- const rows = getRows(result);
37
- if (!rows[0])
38
- return undefined;
39
- // Transform snake_case to camelCase to match NodeIdMappingsRow type
40
- const row = rows[0];
41
- return {
42
- id: row.id,
43
- entityType: row.entity_type,
44
- entityId: row.entity_id,
45
- nodeId: row.node_id,
46
- createdAt: row.created_at,
47
- updatedAt: row.updated_at,
48
- };
29
+ const [row] = await db.select().from(nodeIdMappings).where(eq(nodeIdMappings.id, hash)).limit(1);
30
+ return row;
49
31
  }
50
32
  /**
51
- * Finds a node ID mapping by entity ID and type.
33
+ * Finds a node ID mapping by entity type + entity ID.
52
34
  *
53
35
  * @param db - Database client
54
36
  * @param entityType - Type of entity ('session' or 'user')
@@ -56,159 +38,42 @@ export async function findNodeIdMappingByHash(db, hash) {
56
38
  * @returns Node ID mapping or undefined if not found
57
39
  */
58
40
  export async function findNodeIdMappingByEntity(db, entityType, entityId) {
59
- const result = await db.execute(sql `SELECT id, entity_type, entity_id, node_id, created_at, updated_at
60
- FROM node_id_mappings
61
- WHERE entity_type = ${entityType} AND entity_id = ${entityId}
62
- LIMIT 1`);
63
- const rows = getRows(result);
64
- if (!rows[0])
65
- return undefined;
66
- // Transform snake_case to camelCase to match NodeIdMappingsRow type
67
- const row = rows[0];
68
- return {
69
- id: row.id,
70
- entityType: row.entity_type,
71
- entityId: row.entity_id,
72
- nodeId: row.node_id,
73
- createdAt: row.created_at,
74
- updatedAt: row.updated_at,
75
- };
76
- }
77
- // =============================================================================
78
- // Agent Memories Queries
79
- // =============================================================================
80
- /**
81
- * Finds an agent memory by ID (returns raw database record format).
82
- *
83
- * @deprecated Use VectorMemoryService.getById() instead. This function queries
84
- * agent_memories which is now in the vector database (Supabase), not REST database.
85
- * If you need to query memories, use VectorMemoryService which uses the correct database.
86
- *
87
- * @param db - Database client (NOTE: Should be vector client, but type doesn't enforce this)
88
- * @param memoryId - Memory identifier
89
- * @returns Raw database memory record or undefined if not found
90
- */
91
- export async function findAgentMemoryById(db, memoryId) {
92
- // NOTE: This queries agent_memories which is in vector database
93
- // Using raw SQL so it works, but caller must use vector client
94
- const result = await db.execute(sql `SELECT id, version, content, type, source, embedding, embedding_metadata,
95
- metadata, access_count, accessed_at, verified, verified_by,
96
- verified_at, site_id, agent_id, created_at, expires_at
97
- FROM agent_memories
98
- WHERE id = ${memoryId}
99
- LIMIT 1`);
100
- const rows = getRows(result);
101
- if (!rows[0])
102
- return undefined;
103
- const row = rows[0];
104
- return {
105
- id: row.id,
106
- version: row.version || 1,
107
- content: row.content,
108
- type: row.type,
109
- source: row.source,
110
- embedding: row.embedding,
111
- embeddingMetadata: row.embedding_metadata,
112
- metadata: row.metadata,
113
- accessCount: row.access_count,
114
- accessedAt: row.accessed_at,
115
- verified: row.verified,
116
- createdAt: row.created_at,
117
- expiresAt: row.expires_at,
118
- };
119
- }
120
- /**
121
- * Finds agent memories by user ID.
122
- *
123
- * @deprecated Use VectorMemoryService.searchSimilar() or VectorMemoryService with filters instead.
124
- * This function queries agent_memories which is now in the vector database (Supabase).
125
- * If you need to query memories, use VectorMemoryService which uses the correct database.
126
- *
127
- * @param db - Database client (NOTE: Should be vector client, but type doesn't enforce this)
128
- * @param userId - User identifier
129
- * @returns Array of agent memories
130
- */
131
- export async function findAgentMemoriesByUserId(db, userId) {
132
- const result = await db.execute(sql `SELECT id, version, content, type, source, embedding, embedding_metadata,
133
- metadata, access_count, accessed_at, verified, verified_by,
134
- verified_at, site_id, agent_id, created_at, expires_at
135
- FROM agent_memories
136
- WHERE (source->>'id')::text = ${userId}
137
- ORDER BY created_at DESC`);
138
- const rows = getRows(result);
139
- return rows.map((row) => {
140
- const record = row;
141
- const metadata = record.embedding_metadata;
142
- return {
143
- id: record.id,
144
- version: record.version || 1,
145
- content: record.content,
146
- type: record.type,
147
- source: record.source,
148
- embedding: metadata
149
- ? {
150
- model: metadata.model,
151
- vector: record.embedding || metadata.vector,
152
- dimension: metadata.dimension,
153
- generatedAt: metadata.generatedAt,
154
- }
155
- : undefined,
156
- metadata: (record.metadata || {}),
157
- accessedAt: record.accessed_at?.toISOString() || new Date().toISOString(),
158
- accessCount: record.access_count || 0,
159
- verified: record.verified ?? false,
160
- createdAt: record.created_at,
161
- expiresAt: record.expires_at,
162
- };
163
- });
41
+ const [row] = await db
42
+ .select()
43
+ .from(nodeIdMappings)
44
+ .where(and(eq(nodeIdMappings.entityType, entityType), eq(nodeIdMappings.entityId, entityId)))
45
+ .limit(1);
46
+ return row;
164
47
  }
165
48
  // =============================================================================
166
49
  // Agent Contexts Queries
167
50
  // =============================================================================
168
51
  /**
169
- * Finds an agent context by CRDT ID (returns raw database record format).
52
+ * Finds an agent context by CRDT ID.
170
53
  *
171
54
  * @param db - Database client
172
55
  * @param crdtId - CRDT identifier (format: sessionId:agentId)
173
- * @returns Raw database context record or undefined if not found
56
+ * @returns Agent context row or undefined if not found
174
57
  */
175
58
  export async function findAgentContextById(db, crdtId) {
176
- const result = await db.execute(sql `SELECT id, version, session_id, agent_id, context, priority,
177
- embedding, created_at, updated_at
178
- FROM agent_contexts
179
- WHERE id = ${crdtId}
180
- LIMIT 1`);
181
- const rows = getRows(result);
182
- if (!rows[0])
183
- return undefined;
184
- const row = rows[0];
185
- return {
186
- id: row.id,
187
- version: row.version || 1,
188
- sessionId: row.session_id,
189
- agentId: row.agent_id,
190
- context: row.context || {},
191
- priority: row.priority || 0.5,
192
- embedding: row.embedding,
193
- createdAt: row.created_at,
194
- updatedAt: row.updated_at,
195
- };
59
+ const [row] = await db.select().from(agentContexts).where(eq(agentContexts.id, crdtId)).limit(1);
60
+ return row;
196
61
  }
197
62
  // =============================================================================
198
63
  // Users Queries
199
64
  // =============================================================================
200
65
  /**
201
- * Finds a user by ID.
66
+ * Finds a user by ID, returning only the columns the memory layer needs.
202
67
  *
203
68
  * @param db - Database client
204
69
  * @param userId - User identifier
205
- * @returns User record or undefined if not found
70
+ * @returns User record (id + preferences) or undefined if not found
206
71
  */
207
72
  export async function findUserById(db, userId) {
208
- const result = await db.execute(sql `SELECT id, preferences
209
- FROM users
210
- WHERE id = ${userId}
211
- LIMIT 1`);
212
- const rows = getRows(result);
213
- return rows[0];
73
+ const [row] = await db
74
+ .select({ id: users.id, preferences: users.preferences })
75
+ .from(users)
76
+ .where(eq(users.id, userId))
77
+ .limit(1);
78
+ return row;
214
79
  }
@@ -1 +1 @@
1
- {"version":3,"file":"vector-memory-service.d.ts","sourceRoot":"","sources":["../../../src/memory/vector/vector-memory-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAM9D,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAmD;IAC9D,OAAO,CAAC,OAAO,CAAiD;IAEhE;;;OAGG;IACH,OAAO,KAAK,EAAE,GAKb;IAED,+DAA+D;IAC/D,OAAO,KAAK,MAAM,GAKjB;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,aAAa,CACjB,cAAc,EAAE,MAAM,EAAE,EACxB,OAAO,GAAE,mBAAwB,GAChC,OAAO,CAAC,kBAAkB,EAAE,CAAC;IA2GhC;;;;;OAKG;IACG,MAAM,CACV,MAAM,EAAE,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,WAAW,GAAG,YAAY,CAAC,GAAG;QAC7D,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,GACA,OAAO,CAAC,WAAW,CAAC;IA4EvB;;;;;;OAMG;IACG,MAAM,CACV,EAAE,EAAE,MAAM,EACV,OAAO,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,GAAG,WAAW,CAAC,CAAC,GACtD,OAAO,CAAC,WAAW,CAAC;IAyEvB;;;;;OAKG;IACG,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK1C;;;;;OAKG;IACG,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;CA8CvD"}
1
+ {"version":3,"file":"vector-memory-service.d.ts","sourceRoot":"","sources":["../../../src/memory/vector/vector-memory-service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AAM9D,MAAM,WAAW,mBAAmB;IAClC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,WAAW,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAmD;IAC9D,OAAO,CAAC,OAAO,CAAiD;IAEhE;;;OAGG;IACH,OAAO,KAAK,EAAE,GAKb;IAED,+DAA+D;IAC/D,OAAO,KAAK,MAAM,GAKjB;IAED;;;;;;;;;;;;;;;;OAgBG;IACG,aAAa,CACjB,cAAc,EAAE,MAAM,EAAE,EACxB,OAAO,GAAE,mBAAwB,GAChC,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