velixar-mcp-server 0.2.4 → 1.2.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.
- package/README.md +120 -64
- package/dist/api.d.ts +64 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +405 -0
- package/dist/api.js.map +1 -0
- package/dist/errors.d.ts +19 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +52 -0
- package/dist/errors.js.map +1 -0
- package/dist/justify.d.ts +9 -0
- package/dist/justify.d.ts.map +1 -0
- package/dist/justify.js +114 -0
- package/dist/justify.js.map +1 -0
- package/dist/prompts.d.ts +88 -0
- package/dist/prompts.d.ts.map +1 -0
- package/dist/prompts.js +693 -0
- package/dist/prompts.js.map +1 -0
- package/dist/resources.d.ts +25 -0
- package/dist/resources.d.ts.map +1 -0
- package/dist/resources.js +278 -0
- package/dist/resources.js.map +1 -0
- package/dist/server.d.ts +3 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +392 -0
- package/dist/server.js.map +1 -0
- package/dist/simulation/personas.d.ts +41 -0
- package/dist/simulation/personas.d.ts.map +1 -0
- package/dist/simulation/personas.js +173 -0
- package/dist/simulation/personas.js.map +1 -0
- package/dist/simulation/report.d.ts +28 -0
- package/dist/simulation/report.d.ts.map +1 -0
- package/dist/simulation/report.js +105 -0
- package/dist/simulation/report.js.map +1 -0
- package/dist/simulation/runner.d.ts +63 -0
- package/dist/simulation/runner.d.ts.map +1 -0
- package/dist/simulation/runner.js +167 -0
- package/dist/simulation/runner.js.map +1 -0
- package/dist/temporal_merge.d.ts +70 -0
- package/dist/temporal_merge.d.ts.map +1 -0
- package/dist/temporal_merge.js +258 -0
- package/dist/temporal_merge.js.map +1 -0
- package/dist/tools/clairvoyance.d.ts +9 -0
- package/dist/tools/clairvoyance.d.ts.map +1 -0
- package/dist/tools/clairvoyance.js +321 -0
- package/dist/tools/clairvoyance.js.map +1 -0
- package/dist/tools/cognitive.d.ts +10 -0
- package/dist/tools/cognitive.d.ts.map +1 -0
- package/dist/tools/cognitive.js +462 -0
- package/dist/tools/cognitive.js.map +1 -0
- package/dist/tools/construction.d.ts +9 -0
- package/dist/tools/construction.d.ts.map +1 -0
- package/dist/tools/construction.js +350 -0
- package/dist/tools/construction.js.map +1 -0
- package/dist/tools/graph.d.ts +14 -0
- package/dist/tools/graph.d.ts.map +1 -0
- package/dist/tools/graph.js +263 -0
- package/dist/tools/graph.js.map +1 -0
- package/dist/tools/graph_sanitizer.d.ts +24 -0
- package/dist/tools/graph_sanitizer.d.ts.map +1 -0
- package/dist/tools/graph_sanitizer.js +79 -0
- package/dist/tools/graph_sanitizer.js.map +1 -0
- package/dist/tools/lifecycle.d.ts +9 -0
- package/dist/tools/lifecycle.d.ts.map +1 -0
- package/dist/tools/lifecycle.js +1091 -0
- package/dist/tools/lifecycle.js.map +1 -0
- package/dist/tools/livedata.d.ts +9 -0
- package/dist/tools/livedata.d.ts.map +1 -0
- package/dist/tools/livedata.js +222 -0
- package/dist/tools/livedata.js.map +1 -0
- package/dist/tools/memory.d.ts +10 -0
- package/dist/tools/memory.d.ts.map +1 -0
- package/dist/tools/memory.js +275 -0
- package/dist/tools/memory.js.map +1 -0
- package/dist/tools/recall.d.ts +9 -0
- package/dist/tools/recall.d.ts.map +1 -0
- package/dist/tools/recall.js +206 -0
- package/dist/tools/recall.js.map +1 -0
- package/dist/tools/retrieval.d.ts +9 -0
- package/dist/tools/retrieval.d.ts.map +1 -0
- package/dist/tools/retrieval.js +338 -0
- package/dist/tools/retrieval.js.map +1 -0
- package/dist/tools/system.d.ts +12 -0
- package/dist/tools/system.d.ts.map +1 -0
- package/dist/tools/system.js +228 -0
- package/dist/tools/system.js.map +1 -0
- package/dist/types.d.ts +234 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +5 -0
- package/dist/types.js.map +1 -0
- package/dist/validate.d.ts +79 -0
- package/dist/validate.d.ts.map +1 -0
- package/dist/validate.js +174 -0
- package/dist/validate.js.map +1 -0
- package/dist/validate_retrieval.d.ts +33 -0
- package/dist/validate_retrieval.d.ts.map +1 -0
- package/dist/validate_retrieval.js +97 -0
- package/dist/validate_retrieval.js.map +1 -0
- package/package.json +22 -6
- package/server.json +2 -2
- package/.github/workflows/ci.yml +0 -18
- package/.mcpregistry_github_token +0 -1
- package/.mcpregistry_registry_token +0 -1
- package/src/index.js +0 -262
- package/tests/server.test.js +0 -193
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
export type ResponseStatus = 'ok' | 'partial' | 'stale' | 'error';
|
|
2
|
+
export interface ResponseMeta {
|
|
3
|
+
workspace_id: string;
|
|
4
|
+
confidence: number;
|
|
5
|
+
staleness: 'fresh' | 'recent' | 'stale';
|
|
6
|
+
contradictions_present: boolean;
|
|
7
|
+
data_absent: boolean;
|
|
8
|
+
absence_reason?: AbsenceReason;
|
|
9
|
+
partial_context: boolean;
|
|
10
|
+
request_ms: number;
|
|
11
|
+
cached?: boolean;
|
|
12
|
+
sufficient_answer?: boolean;
|
|
13
|
+
}
|
|
14
|
+
export interface VelixarResponse<T> {
|
|
15
|
+
status: ResponseStatus;
|
|
16
|
+
data: T;
|
|
17
|
+
meta: ResponseMeta;
|
|
18
|
+
}
|
|
19
|
+
export interface VelixarError {
|
|
20
|
+
status: 'error';
|
|
21
|
+
error: {
|
|
22
|
+
code: string;
|
|
23
|
+
message: string;
|
|
24
|
+
retryable: boolean;
|
|
25
|
+
details?: Record<string, unknown>;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
export type MemoryType = 'episodic' | 'semantic';
|
|
29
|
+
export type SourceType = 'user' | 'distill' | 'inferred' | 'imported';
|
|
30
|
+
export type AuthorType = 'user' | 'agent' | 'pipeline' | 'distill';
|
|
31
|
+
export interface Author {
|
|
32
|
+
type: AuthorType;
|
|
33
|
+
agent_id?: string;
|
|
34
|
+
session_id?: string;
|
|
35
|
+
}
|
|
36
|
+
export interface Provenance {
|
|
37
|
+
created_at: string;
|
|
38
|
+
updated_at: string;
|
|
39
|
+
derived_from?: string[];
|
|
40
|
+
last_touched: string;
|
|
41
|
+
}
|
|
42
|
+
export interface MemoryItem {
|
|
43
|
+
id: string;
|
|
44
|
+
workspace_id: string;
|
|
45
|
+
content: string;
|
|
46
|
+
summary?: string;
|
|
47
|
+
tags: string[];
|
|
48
|
+
memory_type: MemoryType;
|
|
49
|
+
source_type: SourceType;
|
|
50
|
+
author: Author;
|
|
51
|
+
relevance?: number;
|
|
52
|
+
confidence?: number;
|
|
53
|
+
provenance: Provenance;
|
|
54
|
+
contradiction_flags?: string[];
|
|
55
|
+
}
|
|
56
|
+
export interface GraphEntity {
|
|
57
|
+
id: string;
|
|
58
|
+
entity_type: string;
|
|
59
|
+
label: string;
|
|
60
|
+
properties?: Record<string, unknown>;
|
|
61
|
+
relevance?: number;
|
|
62
|
+
confidence?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface GraphRelation {
|
|
65
|
+
source: string;
|
|
66
|
+
target: string;
|
|
67
|
+
relationship: string;
|
|
68
|
+
direction: 'outbound' | 'inbound' | 'bidirectional';
|
|
69
|
+
relevance?: number;
|
|
70
|
+
confidence?: number;
|
|
71
|
+
}
|
|
72
|
+
export interface GraphTraversalResult {
|
|
73
|
+
root: GraphEntity;
|
|
74
|
+
relations: GraphRelation[];
|
|
75
|
+
connected_entities: GraphEntity[];
|
|
76
|
+
depth_reached: number;
|
|
77
|
+
}
|
|
78
|
+
export interface IdentityProfile {
|
|
79
|
+
preferences: Record<string, string | string[]>;
|
|
80
|
+
expertise: string[];
|
|
81
|
+
communication_style?: string;
|
|
82
|
+
recurring_goals: string[];
|
|
83
|
+
stable_constraints: string[];
|
|
84
|
+
shifts: IdentityShift[];
|
|
85
|
+
contradictions: IdentityContradiction[];
|
|
86
|
+
snapshot_count: number;
|
|
87
|
+
}
|
|
88
|
+
export interface IdentityShift {
|
|
89
|
+
field: string;
|
|
90
|
+
from: string;
|
|
91
|
+
to: string;
|
|
92
|
+
timestamp?: string;
|
|
93
|
+
}
|
|
94
|
+
export interface IdentityContradiction {
|
|
95
|
+
existing: string;
|
|
96
|
+
new: string;
|
|
97
|
+
severity?: string;
|
|
98
|
+
}
|
|
99
|
+
export interface ContradictionResult {
|
|
100
|
+
id: string;
|
|
101
|
+
statement_a: string;
|
|
102
|
+
statement_b: string;
|
|
103
|
+
memory_id_a?: string;
|
|
104
|
+
memory_id_b?: string;
|
|
105
|
+
severity: 'low' | 'medium' | 'high';
|
|
106
|
+
confidence: number;
|
|
107
|
+
explanation?: string;
|
|
108
|
+
workspace_id: string;
|
|
109
|
+
detected_at: string;
|
|
110
|
+
}
|
|
111
|
+
export interface TimelineEntry {
|
|
112
|
+
id: string;
|
|
113
|
+
content: string;
|
|
114
|
+
summary?: string;
|
|
115
|
+
timestamp: string;
|
|
116
|
+
memory_type: MemoryType;
|
|
117
|
+
chain_position: number;
|
|
118
|
+
tags: string[];
|
|
119
|
+
}
|
|
120
|
+
export interface PatternResult {
|
|
121
|
+
name: string;
|
|
122
|
+
problem_signature: string;
|
|
123
|
+
prior_solution: string;
|
|
124
|
+
confidence: number;
|
|
125
|
+
supporting_memories: string[];
|
|
126
|
+
occurrence_count: number;
|
|
127
|
+
}
|
|
128
|
+
export type EvidenceClass = 'direct' | 'aggregated' | 'relational' | 'temporal' | 'contradictory' | 'weak';
|
|
129
|
+
export type ClaimType = 'retrieved_fact' | 'synthesized_summary' | 'pattern_inference' | 'relational_inference' | 'temporal_inference' | 'hypothesis';
|
|
130
|
+
export type ConfidenceLevel = 'high' | 'medium' | 'low' | 'unstable' | 'conflicting';
|
|
131
|
+
export type PresentationMode = 'assertive' | 'confident_summary' | 'tentative_synthesis' | 'cautious' | 'exploratory' | 'do_not_assert';
|
|
132
|
+
export interface EvidenceItem {
|
|
133
|
+
id: string;
|
|
134
|
+
source_type: string;
|
|
135
|
+
evidence_class: EvidenceClass;
|
|
136
|
+
relevance: number;
|
|
137
|
+
freshness: 'recent' | 'aging' | 'stale';
|
|
138
|
+
workspace_id: string;
|
|
139
|
+
}
|
|
140
|
+
export interface ConfidenceProfile {
|
|
141
|
+
level: ConfidenceLevel;
|
|
142
|
+
score: number;
|
|
143
|
+
evidence_strength: number;
|
|
144
|
+
evidence_consistency: number;
|
|
145
|
+
evidence_freshness: number;
|
|
146
|
+
derivation_distance: number;
|
|
147
|
+
contradiction_pressure: number;
|
|
148
|
+
pattern_stability?: number;
|
|
149
|
+
reason: string;
|
|
150
|
+
}
|
|
151
|
+
export interface JustificationResult {
|
|
152
|
+
claim: string;
|
|
153
|
+
claim_type: ClaimType;
|
|
154
|
+
workspace_scope: 'workspace_local' | 'user_global' | 'session_local';
|
|
155
|
+
support: {
|
|
156
|
+
evidence_count: number;
|
|
157
|
+
evidence_types: EvidenceClass[];
|
|
158
|
+
items: EvidenceItem[];
|
|
159
|
+
};
|
|
160
|
+
confidence: ConfidenceProfile;
|
|
161
|
+
uncertainty_flags: string[];
|
|
162
|
+
contradiction_flags: string[];
|
|
163
|
+
derived_from: string[];
|
|
164
|
+
presentation_mode: PresentationMode;
|
|
165
|
+
}
|
|
166
|
+
export interface DistillationCandidate {
|
|
167
|
+
content: string;
|
|
168
|
+
rationale: string;
|
|
169
|
+
tags: string[];
|
|
170
|
+
confidence: number;
|
|
171
|
+
memory_type: MemoryType;
|
|
172
|
+
source_type: SourceType;
|
|
173
|
+
duplicate_detected: boolean;
|
|
174
|
+
contradiction_detected: boolean;
|
|
175
|
+
stored_id?: string;
|
|
176
|
+
}
|
|
177
|
+
export interface DistillationResult {
|
|
178
|
+
candidates: DistillationCandidate[];
|
|
179
|
+
stored_count: number;
|
|
180
|
+
skipped_count: number;
|
|
181
|
+
contradictions_found: string[];
|
|
182
|
+
}
|
|
183
|
+
export interface HealthResult {
|
|
184
|
+
connected: boolean;
|
|
185
|
+
workspace_id: string;
|
|
186
|
+
backend_reachable: boolean;
|
|
187
|
+
latency_ms: number;
|
|
188
|
+
version: string;
|
|
189
|
+
}
|
|
190
|
+
export interface DebugResult {
|
|
191
|
+
workspace_id: string;
|
|
192
|
+
workspace_source: 'env' | 'git' | 'config' | 'none';
|
|
193
|
+
memory_count?: number;
|
|
194
|
+
cache_state: Record<string, {
|
|
195
|
+
cached: boolean;
|
|
196
|
+
age_ms?: number;
|
|
197
|
+
}>;
|
|
198
|
+
last_api_timings: Record<string, number>;
|
|
199
|
+
retry_count: number;
|
|
200
|
+
fallback_count: number;
|
|
201
|
+
}
|
|
202
|
+
export interface CapabilitiesResult {
|
|
203
|
+
tools: string[];
|
|
204
|
+
resources: string[];
|
|
205
|
+
prompts: string[];
|
|
206
|
+
features: {
|
|
207
|
+
workspace_isolation: boolean;
|
|
208
|
+
identity: boolean;
|
|
209
|
+
graph: boolean;
|
|
210
|
+
contradictions: boolean;
|
|
211
|
+
timeline: boolean;
|
|
212
|
+
patterns: boolean;
|
|
213
|
+
distill: boolean;
|
|
214
|
+
justification: boolean;
|
|
215
|
+
};
|
|
216
|
+
security_mode?: string;
|
|
217
|
+
}
|
|
218
|
+
export type AbsenceReason = 'no_data' | 'low_confidence' | 'partial' | 'conflict' | 'stale' | 'backend_error';
|
|
219
|
+
export interface ApiConfig {
|
|
220
|
+
apiKey: string;
|
|
221
|
+
apiBase: string;
|
|
222
|
+
userId: string;
|
|
223
|
+
workspaceId: string;
|
|
224
|
+
workspaceSource: 'env' | 'git' | 'config' | 'none';
|
|
225
|
+
timeoutMs: number;
|
|
226
|
+
debug: boolean;
|
|
227
|
+
}
|
|
228
|
+
export interface ApiTiming {
|
|
229
|
+
endpoint: string;
|
|
230
|
+
duration_ms: number;
|
|
231
|
+
timestamp: number;
|
|
232
|
+
cached: boolean;
|
|
233
|
+
}
|
|
234
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,cAAc,GAAG,IAAI,GAAG,SAAS,G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"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,4DAA4D;AAC5D,qDAAqD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
export declare class SchemaError extends Error {
|
|
2
|
+
endpoint: string;
|
|
3
|
+
field: string;
|
|
4
|
+
expected: string;
|
|
5
|
+
got: unknown;
|
|
6
|
+
constructor(endpoint: string, field: string, expected: string, got: unknown);
|
|
7
|
+
}
|
|
8
|
+
export interface ValidatedRawMemory {
|
|
9
|
+
id: string;
|
|
10
|
+
content: string;
|
|
11
|
+
score?: number;
|
|
12
|
+
tier?: number;
|
|
13
|
+
type?: string | null;
|
|
14
|
+
tags?: string[];
|
|
15
|
+
salience?: number;
|
|
16
|
+
created_at?: string;
|
|
17
|
+
updated_at?: string;
|
|
18
|
+
previous_memory_id?: string | null;
|
|
19
|
+
}
|
|
20
|
+
export interface ValidatedStoreResult {
|
|
21
|
+
id: string;
|
|
22
|
+
}
|
|
23
|
+
export interface ValidatedSearchResult {
|
|
24
|
+
memories: ValidatedRawMemory[];
|
|
25
|
+
count?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface ValidatedListResult {
|
|
28
|
+
memories: ValidatedRawMemory[];
|
|
29
|
+
count?: number;
|
|
30
|
+
cursor?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ValidatedGraphResult {
|
|
33
|
+
nodes: Array<{
|
|
34
|
+
id: string;
|
|
35
|
+
label: string;
|
|
36
|
+
entity_type?: string;
|
|
37
|
+
properties?: Record<string, unknown>;
|
|
38
|
+
relevance?: number;
|
|
39
|
+
}>;
|
|
40
|
+
edges: Array<{
|
|
41
|
+
source: string;
|
|
42
|
+
target: string;
|
|
43
|
+
relationship?: string;
|
|
44
|
+
direction?: string;
|
|
45
|
+
relevance?: number;
|
|
46
|
+
}>;
|
|
47
|
+
hops?: number;
|
|
48
|
+
}
|
|
49
|
+
export interface ValidatedIdentityResult {
|
|
50
|
+
identity?: Record<string, unknown>;
|
|
51
|
+
shifts?: Array<{
|
|
52
|
+
field: string;
|
|
53
|
+
from: string;
|
|
54
|
+
to: string;
|
|
55
|
+
timestamp?: string;
|
|
56
|
+
}>;
|
|
57
|
+
contradictions?: Array<{
|
|
58
|
+
existing: string;
|
|
59
|
+
new: string;
|
|
60
|
+
severity?: string;
|
|
61
|
+
}>;
|
|
62
|
+
snapshot_count?: number;
|
|
63
|
+
}
|
|
64
|
+
export interface ValidatedOverviewResult {
|
|
65
|
+
total_memories?: number;
|
|
66
|
+
cortex_nodes?: number;
|
|
67
|
+
temporal_chains?: number;
|
|
68
|
+
system_mode?: string;
|
|
69
|
+
}
|
|
70
|
+
export declare function validateStoreResponse(raw: unknown, endpoint: string): ValidatedStoreResult;
|
|
71
|
+
export declare function validateSearchResponse(raw: unknown, endpoint: string): ValidatedSearchResult;
|
|
72
|
+
export declare function validateListResponse(raw: unknown, endpoint: string): ValidatedListResult;
|
|
73
|
+
export declare function validateGraphResponse(raw: unknown, endpoint: string): ValidatedGraphResult;
|
|
74
|
+
export declare function validateIdentityResponse(raw: unknown, endpoint: string): ValidatedIdentityResult;
|
|
75
|
+
export declare function validateOverviewResponse(raw: unknown, endpoint: string): ValidatedOverviewResult;
|
|
76
|
+
export declare function validateMutationResponse(raw: unknown, endpoint: string): {
|
|
77
|
+
error?: string;
|
|
78
|
+
};
|
|
79
|
+
//# sourceMappingURL=validate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.ts","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AASA,qBAAa,WAAY,SAAQ,KAAK;IACjB,QAAQ,EAAE,MAAM;IAAS,KAAK,EAAE,MAAM;IAAS,QAAQ,EAAE,MAAM;IAAS,GAAG,EAAE,OAAO;gBAApF,QAAQ,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,EAAS,QAAQ,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QAAQ,EAAE,MAAM,GAAG,uBAAuB,CAShG;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAK3F"}
|
package/dist/validate.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
// ── Runtime Schema Validation ──
|
|
2
|
+
// Lightweight validators for backend API responses.
|
|
3
|
+
// No external deps — just shape checks that return typed data or throw.
|
|
4
|
+
// NOTE: Must not import from api.ts to avoid circular dependency.
|
|
5
|
+
function warnSchema(endpoint, reason, got) {
|
|
6
|
+
console.error(`[velixar] warn: schema_skip_memory ${JSON.stringify({ endpoint, reason, got })}`);
|
|
7
|
+
}
|
|
8
|
+
export class SchemaError extends Error {
|
|
9
|
+
endpoint;
|
|
10
|
+
field;
|
|
11
|
+
expected;
|
|
12
|
+
got;
|
|
13
|
+
constructor(endpoint, field, expected, got) {
|
|
14
|
+
super(`Schema mismatch on ${endpoint}: ${field} expected ${expected}, got ${typeof got} (${String(got).slice(0, 50)})`);
|
|
15
|
+
this.endpoint = endpoint;
|
|
16
|
+
this.field = field;
|
|
17
|
+
this.expected = expected;
|
|
18
|
+
this.got = got;
|
|
19
|
+
this.name = 'SchemaError';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
// ── Helpers ──
|
|
23
|
+
function has(obj, key) {
|
|
24
|
+
return obj !== null && typeof obj === 'object' && key in obj;
|
|
25
|
+
}
|
|
26
|
+
function str(v) {
|
|
27
|
+
return typeof v === 'string' ? v : undefined;
|
|
28
|
+
}
|
|
29
|
+
function num(v) {
|
|
30
|
+
return typeof v === 'number' ? v : undefined;
|
|
31
|
+
}
|
|
32
|
+
function arr(v) {
|
|
33
|
+
return Array.isArray(v) ? v : undefined;
|
|
34
|
+
}
|
|
35
|
+
// ── Validators ──
|
|
36
|
+
function validateRawMemory(m, endpoint) {
|
|
37
|
+
if (!m || typeof m !== 'object')
|
|
38
|
+
return null;
|
|
39
|
+
const o = m;
|
|
40
|
+
const id = str(o.id);
|
|
41
|
+
const content = str(o.content);
|
|
42
|
+
if (!id || !content) {
|
|
43
|
+
warnSchema(endpoint, 'missing id or content', JSON.stringify(o).slice(0, 100));
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
id,
|
|
48
|
+
content,
|
|
49
|
+
score: num(o.score),
|
|
50
|
+
tier: num(o.tier),
|
|
51
|
+
type: str(o.type) ?? null,
|
|
52
|
+
tags: arr(o.tags)?.filter((t) => typeof t === 'string'),
|
|
53
|
+
salience: num(o.salience),
|
|
54
|
+
created_at: str(o.created_at),
|
|
55
|
+
updated_at: str(o.updated_at),
|
|
56
|
+
previous_memory_id: str(o.previous_memory_id) ?? null,
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
export function validateStoreResponse(raw, endpoint) {
|
|
60
|
+
if (!raw || typeof raw !== 'object')
|
|
61
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
62
|
+
const o = raw;
|
|
63
|
+
if (o.error)
|
|
64
|
+
throw new Error(String(o.error));
|
|
65
|
+
const id = str(o.id);
|
|
66
|
+
if (!id)
|
|
67
|
+
throw new SchemaError(endpoint, 'id', 'string', o.id);
|
|
68
|
+
return { id };
|
|
69
|
+
}
|
|
70
|
+
export function validateSearchResponse(raw, endpoint) {
|
|
71
|
+
if (!raw || typeof raw !== 'object')
|
|
72
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
73
|
+
const o = raw;
|
|
74
|
+
if (o.error)
|
|
75
|
+
throw new Error(String(o.error));
|
|
76
|
+
const rawMems = arr(o.memories) || [];
|
|
77
|
+
const memories = rawMems.map(m => validateRawMemory(m, endpoint)).filter((m) => m !== null);
|
|
78
|
+
return { memories, count: num(o.count) };
|
|
79
|
+
}
|
|
80
|
+
export function validateListResponse(raw, endpoint) {
|
|
81
|
+
if (!raw || typeof raw !== 'object')
|
|
82
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
83
|
+
const o = raw;
|
|
84
|
+
if (o.error)
|
|
85
|
+
throw new Error(String(o.error));
|
|
86
|
+
const rawMems = arr(o.memories) || [];
|
|
87
|
+
const memories = rawMems.map(m => validateRawMemory(m, endpoint)).filter((m) => m !== null);
|
|
88
|
+
return { memories, count: num(o.count), cursor: str(o.cursor) };
|
|
89
|
+
}
|
|
90
|
+
export function validateGraphResponse(raw, endpoint) {
|
|
91
|
+
if (!raw || typeof raw !== 'object')
|
|
92
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
93
|
+
const o = raw;
|
|
94
|
+
if (o.error)
|
|
95
|
+
throw new Error(String(o.error));
|
|
96
|
+
const rawNodes = arr(o.nodes) || [];
|
|
97
|
+
const nodes = rawNodes.map(n => {
|
|
98
|
+
if (!n || typeof n !== 'object')
|
|
99
|
+
return null;
|
|
100
|
+
const node = n;
|
|
101
|
+
const id = str(node.id);
|
|
102
|
+
const label = str(node.label) || str(node.name) || str(node.id) || '';
|
|
103
|
+
if (!id)
|
|
104
|
+
return null;
|
|
105
|
+
return {
|
|
106
|
+
id,
|
|
107
|
+
label,
|
|
108
|
+
entity_type: str(node.entity_type) || str(node.type),
|
|
109
|
+
properties: (typeof node.properties === 'object' && node.properties !== null) ? node.properties : undefined,
|
|
110
|
+
relevance: num(node.relevance),
|
|
111
|
+
};
|
|
112
|
+
}).filter((n) => n !== null);
|
|
113
|
+
const rawEdges = arr(o.edges) || [];
|
|
114
|
+
const edges = rawEdges.map(e => {
|
|
115
|
+
if (!e || typeof e !== 'object')
|
|
116
|
+
return null;
|
|
117
|
+
const edge = e;
|
|
118
|
+
const source = str(edge.source) || str(edge.from);
|
|
119
|
+
const target = str(edge.target) || str(edge.to);
|
|
120
|
+
if (!source || !target)
|
|
121
|
+
return null;
|
|
122
|
+
return {
|
|
123
|
+
source,
|
|
124
|
+
target,
|
|
125
|
+
relationship: str(edge.relationship) || str(edge.relation_type) || str(edge.label),
|
|
126
|
+
direction: str(edge.direction),
|
|
127
|
+
relevance: num(edge.relevance),
|
|
128
|
+
};
|
|
129
|
+
}).filter((e) => e !== null);
|
|
130
|
+
return { nodes, edges, hops: num(o.hops) };
|
|
131
|
+
}
|
|
132
|
+
export function validateIdentityResponse(raw, endpoint) {
|
|
133
|
+
if (!raw || typeof raw !== 'object')
|
|
134
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
135
|
+
const o = raw;
|
|
136
|
+
if (o.error)
|
|
137
|
+
throw new Error(String(o.error));
|
|
138
|
+
const identity = (typeof o.identity === 'object' && o.identity !== null) ? o.identity : {};
|
|
139
|
+
const rawShifts = arr(o.shifts) || [];
|
|
140
|
+
const shifts = rawShifts.map(s => {
|
|
141
|
+
if (!s || typeof s !== 'object')
|
|
142
|
+
return null;
|
|
143
|
+
const shift = s;
|
|
144
|
+
return { field: str(shift.field) || '', from: str(shift.from) || '', to: str(shift.to) || '', timestamp: str(shift.timestamp) };
|
|
145
|
+
}).filter((s) => s !== null);
|
|
146
|
+
const rawContradictions = arr(o.contradictions) || [];
|
|
147
|
+
const contradictions = rawContradictions.map(c => {
|
|
148
|
+
if (!c || typeof c !== 'object')
|
|
149
|
+
return null;
|
|
150
|
+
const con = c;
|
|
151
|
+
return { existing: str(con.existing) || '', new: str(con.new) || '', severity: str(con.severity) };
|
|
152
|
+
}).filter((c) => c !== null);
|
|
153
|
+
return { identity, shifts, contradictions, snapshot_count: num(o.snapshot_count) };
|
|
154
|
+
}
|
|
155
|
+
export function validateOverviewResponse(raw, endpoint) {
|
|
156
|
+
if (!raw || typeof raw !== 'object')
|
|
157
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
158
|
+
const o = raw;
|
|
159
|
+
return {
|
|
160
|
+
total_memories: num(o.total_memories),
|
|
161
|
+
cortex_nodes: num(o.cortex_nodes),
|
|
162
|
+
temporal_chains: num(o.temporal_chains),
|
|
163
|
+
system_mode: str(o.system_mode),
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
export function validateMutationResponse(raw, endpoint) {
|
|
167
|
+
if (!raw || typeof raw !== 'object')
|
|
168
|
+
throw new SchemaError(endpoint, 'response', 'object', raw);
|
|
169
|
+
const o = raw;
|
|
170
|
+
if (o.error)
|
|
171
|
+
throw new Error(String(o.error));
|
|
172
|
+
return {};
|
|
173
|
+
}
|
|
174
|
+
//# sourceMappingURL=validate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.js","sourceRoot":"","sources":["../src/validate.ts"],"names":[],"mappings":"AAAA,kCAAkC;AAClC,oDAAoD;AACpD,wEAAwE;AACxE,kEAAkE;AAElE,SAAS,UAAU,CAAC,QAAgB,EAAE,MAAc,EAAE,GAAW;IAC/D,OAAO,CAAC,KAAK,CAAC,sCAAsC,IAAI,CAAC,SAAS,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC;AACnG,CAAC;AAED,MAAM,OAAO,WAAY,SAAQ,KAAK;IACjB;IAAyB;IAAsB;IAAyB;IAA3F,YAAmB,QAAgB,EAAS,KAAa,EAAS,QAAgB,EAAS,GAAY;QACrG,KAAK,CAAC,sBAAsB,QAAQ,KAAK,KAAK,aAAa,QAAQ,SAAS,OAAO,GAAG,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC;QADvG,aAAQ,GAAR,QAAQ,CAAQ;QAAS,UAAK,GAAL,KAAK,CAAQ;QAAS,aAAQ,GAAR,QAAQ,CAAQ;QAAS,QAAG,GAAH,GAAG,CAAS;QAErG,IAAI,CAAC,IAAI,GAAG,aAAa,CAAC;IAC5B,CAAC;CACF;AAED,gBAAgB;AAEhB,SAAS,GAAG,CAAC,GAAY,EAAE,GAAW;IACpC,OAAO,GAAG,KAAK,IAAI,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,IAAK,GAA+B,C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C;IACzC,IAAI,CAAC,CAAC,KAAK;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IAC9C,OAAO,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ValidatedRawMemory } from './validate.js';
|
|
2
|
+
export interface ValidatedMultiSearchResult {
|
|
3
|
+
results: Array<{
|
|
4
|
+
query: string;
|
|
5
|
+
memories: ValidatedRawMemory[];
|
|
6
|
+
count: number;
|
|
7
|
+
error?: string;
|
|
8
|
+
}>;
|
|
9
|
+
total_queries: number;
|
|
10
|
+
}
|
|
11
|
+
export declare function validateMultiSearchResponse(raw: unknown, endpoint: string): ValidatedMultiSearchResult;
|
|
12
|
+
export interface ValidatedCoverageResult {
|
|
13
|
+
topic: string;
|
|
14
|
+
total_relevant: number;
|
|
15
|
+
retrieved_count: number;
|
|
16
|
+
coverage_ratio: number;
|
|
17
|
+
gaps: Array<{
|
|
18
|
+
id: string;
|
|
19
|
+
preview: string;
|
|
20
|
+
relevance: number;
|
|
21
|
+
}>;
|
|
22
|
+
uncovered_entities: string[];
|
|
23
|
+
suggested_queries: string[];
|
|
24
|
+
}
|
|
25
|
+
export declare function validateCoverageResponse(raw: unknown, endpoint: string): ValidatedCoverageResult;
|
|
26
|
+
export interface ValidatedNeighborhoodResult {
|
|
27
|
+
anchor_id: string;
|
|
28
|
+
anchor_embedding: 'stored' | 'generated';
|
|
29
|
+
neighbors: ValidatedRawMemory[];
|
|
30
|
+
isolation_signal: boolean;
|
|
31
|
+
}
|
|
32
|
+
export declare function validateNeighborhoodResponse(raw: unknown, endpoint: string): ValidatedNeighborhoodResult;
|
|
33
|
+
//# sourceMappingURL=validate_retrieval.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate_retrieval.d.ts","sourceRoot":"","sources":["../src/validate_retrieval.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAiCxD,MAAM,WAAW,0BAA0B;IACzC,OAAO,EAAE,KAAK,CAAC;QACb,KAAK,EAAE,MAAM,CAAC;QACd,QAAQ,EAAE,kBAAkB,EAAE,CAAC;QAC/B,KAAK,EAAE,MAAM,CAAC;QACd,KAAK,CAAC,EAAE,MAAM,CAAC;KAChB,CAAC,CAAC;IACH,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,0BAA0B,CAoBtG;AAID,MAAM,WAAW,uBAAuB;IACtC,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,MAAM,CAAC;IACvB,IAAI,EAAE,KAAK,CAAC;QACV,EAAE,EAAE,MAAM,CAAC;QACX,OAAO,EAAE,MAAM,CAAC;QAChB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC,CAAC;IACH,kBAAkB,EAAE,MAAM,EAAE,CAAC;IAC7B,iBAAiB,EAAE,MAAM,EAAE,CAAC;CAC7B;AAED,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,uBAAuB,CA2BhG;AAID,MAAM,WAAW,2BAA2B;IAC1C,SAAS,EAAE,MAAM,CAAC;IAClB,gBAAgB,EAAE,QAAQ,GAAG,WAAW,CAAC;IACzC,SAAS,EAAE,kBAAkB,EAAE,CAAC;IAChC,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,GAAG,2BAA2B,CAcxG"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// ── Retrieval Response Validators ──
|
|
2
|
+
// Validators for new retrieval endpoints: multi_search, search_by_vector, coverage.
|
|
3
|
+
// Same pattern as validate.ts — no api.ts imports (avoid circular deps).
|
|
4
|
+
// ── Helpers (duplicated from validate.ts to avoid coupling) ──
|
|
5
|
+
function str(v) {
|
|
6
|
+
return typeof v === 'string' ? v : undefined;
|
|
7
|
+
}
|
|
8
|
+
function num(v) {
|
|
9
|
+
return typeof v === 'number' ? v : undefined;
|
|
10
|
+
}
|
|
11
|
+
function arr(v) {
|
|
12
|
+
return Array.isArray(v) ? v : undefined;
|
|
13
|
+
}
|
|
14
|
+
function validateRawMemory(m, endpoint) {
|
|
15
|
+
if (!m || typeof m !== 'object')
|
|
16
|
+
return null;
|
|
17
|
+
const o = m;
|
|
18
|
+
const id = str(o.id);
|
|
19
|
+
const content = str(o.content);
|
|
20
|
+
if (!id || !content)
|
|
21
|
+
return null;
|
|
22
|
+
return {
|
|
23
|
+
id, content,
|
|
24
|
+
score: num(o.score), tier: num(o.tier), type: str(o.type) ?? null,
|
|
25
|
+
tags: arr(o.tags)?.filter((t) => typeof t === 'string'),
|
|
26
|
+
salience: num(o.salience), created_at: str(o.created_at), updated_at: str(o.updated_at),
|
|
27
|
+
previous_memory_id: str(o.previous_memory_id) ?? null,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
export function validateMultiSearchResponse(raw, endpoint) {
|
|
31
|
+
if (!raw || typeof raw !== 'object')
|
|
32
|
+
throw new Error(`Schema mismatch on ${endpoint}: expected object`);
|
|
33
|
+
const o = raw;
|
|
34
|
+
if (o.error)
|
|
35
|
+
throw new Error(String(o.error));
|
|
36
|
+
const rawResults = arr(o.results) || [];
|
|
37
|
+
const results = rawResults.map(r => {
|
|
38
|
+
if (!r || typeof r !== 'object')
|
|
39
|
+
return { query: '', memories: [], count: 0 };
|
|
40
|
+
const item = r;
|
|
41
|
+
const rawMems = arr(item.memories) || [];
|
|
42
|
+
const memories = rawMems.map(m => validateRawMemory(m, endpoint)).filter((m) => m !== null);
|
|
43
|
+
return {
|
|
44
|
+
query: str(item.query) || '',
|
|
45
|
+
memories,
|
|
46
|
+
count: memories.length,
|
|
47
|
+
error: str(item.error),
|
|
48
|
+
};
|
|
49
|
+
});
|
|
50
|
+
return { results, total_queries: results.length };
|
|
51
|
+
}
|
|
52
|
+
export function validateCoverageResponse(raw, endpoint) {
|
|
53
|
+
if (!raw || typeof raw !== 'object')
|
|
54
|
+
throw new Error(`Schema mismatch on ${endpoint}: expected object`);
|
|
55
|
+
const o = raw;
|
|
56
|
+
if (o.error)
|
|
57
|
+
throw new Error(String(o.error));
|
|
58
|
+
const rawGaps = arr(o.gaps) || [];
|
|
59
|
+
const gaps = rawGaps.map(g => {
|
|
60
|
+
if (!g || typeof g !== 'object')
|
|
61
|
+
return null;
|
|
62
|
+
const gap = g;
|
|
63
|
+
const id = str(gap.id);
|
|
64
|
+
if (!id)
|
|
65
|
+
return null;
|
|
66
|
+
return {
|
|
67
|
+
id,
|
|
68
|
+
preview: str(gap.preview) || str(gap.content)?.slice(0, 200) || '',
|
|
69
|
+
relevance: num(gap.relevance) ?? 0,
|
|
70
|
+
};
|
|
71
|
+
}).filter((g) => g !== null);
|
|
72
|
+
return {
|
|
73
|
+
topic: str(o.topic) || '',
|
|
74
|
+
total_relevant: num(o.total_relevant) ?? 0,
|
|
75
|
+
retrieved_count: num(o.retrieved_count) ?? 0,
|
|
76
|
+
coverage_ratio: num(o.coverage_ratio) ?? 0,
|
|
77
|
+
gaps,
|
|
78
|
+
uncovered_entities: (arr(o.uncovered_entities) || []).filter((e) => typeof e === 'string'),
|
|
79
|
+
suggested_queries: (arr(o.suggested_queries) || []).filter((q) => typeof q === 'string'),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
export function validateNeighborhoodResponse(raw, endpoint) {
|
|
83
|
+
if (!raw || typeof raw !== 'object')
|
|
84
|
+
throw new Error(`Schema mismatch on ${endpoint}: expected object`);
|
|
85
|
+
const o = raw;
|
|
86
|
+
if (o.error)
|
|
87
|
+
throw new Error(String(o.error));
|
|
88
|
+
const rawNeighbors = arr(o.neighbors) || arr(o.memories) || [];
|
|
89
|
+
const neighbors = rawNeighbors.map(m => validateRawMemory(m, endpoint)).filter((m) => m !== null);
|
|
90
|
+
return {
|
|
91
|
+
anchor_id: str(o.anchor_id) || str(o.memory_id) || '',
|
|
92
|
+
anchor_embedding: str(o.anchor_embedding) === 'generated' ? 'generated' : 'stored',
|
|
93
|
+
neighbors,
|
|
94
|
+
isolation_signal: neighbors.length === 0,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
//# sourceMappingURL=validate_retrieval.js.map
|