hebbrix 2.0.2 → 2.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/LICENSE +21 -0
- package/README.md +23 -0
- package/dist/index.d.mts +234 -15
- package/dist/index.d.ts +234 -15
- package/dist/index.js +218 -12
- package/dist/index.mjs +213 -11
- package/package.json +8 -5
package/dist/index.d.ts
CHANGED
|
@@ -17,7 +17,7 @@ interface User {
|
|
|
17
17
|
full_name: string;
|
|
18
18
|
is_active: boolean;
|
|
19
19
|
is_verified: boolean;
|
|
20
|
-
tier:
|
|
20
|
+
tier: "free" | "starter" | "pro" | "enterprise";
|
|
21
21
|
}
|
|
22
22
|
interface Collection {
|
|
23
23
|
id: string;
|
|
@@ -57,6 +57,49 @@ interface SearchResponse {
|
|
|
57
57
|
total: number;
|
|
58
58
|
search_type: string;
|
|
59
59
|
processing_time_ms: number;
|
|
60
|
+
no_match: boolean;
|
|
61
|
+
abstain_recommended: boolean;
|
|
62
|
+
query_confidence: number;
|
|
63
|
+
grounding: GroundingReceipt;
|
|
64
|
+
evidence_ids: string[];
|
|
65
|
+
evidence_claims?: EvidenceClaim[];
|
|
66
|
+
safety_contract_version: string;
|
|
67
|
+
degraded?: boolean;
|
|
68
|
+
sdk_safety_reason?: string;
|
|
69
|
+
proof_context?: ProofContext;
|
|
70
|
+
}
|
|
71
|
+
interface GroundingReceipt {
|
|
72
|
+
status: string;
|
|
73
|
+
reason?: string;
|
|
74
|
+
contract_version?: string;
|
|
75
|
+
[key: string]: unknown;
|
|
76
|
+
}
|
|
77
|
+
interface EvidenceClaim {
|
|
78
|
+
memory_id: string;
|
|
79
|
+
claims: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
interface ProofContext {
|
|
82
|
+
schema_version: "proofloop-context-v1";
|
|
83
|
+
context_id: string;
|
|
84
|
+
token: string;
|
|
85
|
+
manifest_digest: string;
|
|
86
|
+
evidence_manifest: Record<string, any>;
|
|
87
|
+
trace_id?: string;
|
|
88
|
+
issued_at: string;
|
|
89
|
+
expires_at: string;
|
|
90
|
+
}
|
|
91
|
+
interface ProofLoopCandidate {
|
|
92
|
+
action_key: string;
|
|
93
|
+
description?: string;
|
|
94
|
+
features?: Record<string, any>;
|
|
95
|
+
}
|
|
96
|
+
interface ProofLoopDecisionParams {
|
|
97
|
+
policy_key: string;
|
|
98
|
+
candidates: ProofLoopCandidate[];
|
|
99
|
+
proof_context?: ProofContext | string;
|
|
100
|
+
collection_id?: string;
|
|
101
|
+
user_id?: string;
|
|
102
|
+
[key: string]: any;
|
|
60
103
|
}
|
|
61
104
|
interface ReasoningSource {
|
|
62
105
|
memory_id: string;
|
|
@@ -64,9 +107,18 @@ interface ReasoningSource {
|
|
|
64
107
|
score: number;
|
|
65
108
|
}
|
|
66
109
|
interface ReasoningResponse {
|
|
67
|
-
answer: string;
|
|
110
|
+
answer: string | null;
|
|
68
111
|
sources: ReasoningSource[];
|
|
69
112
|
metadata: Record<string, any>;
|
|
113
|
+
no_match: boolean;
|
|
114
|
+
abstain_recommended: boolean;
|
|
115
|
+
query_confidence: number;
|
|
116
|
+
grounding: GroundingReceipt;
|
|
117
|
+
evidence_ids: string[];
|
|
118
|
+
evidence_claims?: EvidenceClaim[];
|
|
119
|
+
safety_contract_version: string;
|
|
120
|
+
degraded?: boolean;
|
|
121
|
+
sdk_safety_reason?: string;
|
|
70
122
|
reasoning_context?: Record<string, any>;
|
|
71
123
|
}
|
|
72
124
|
interface CreateCollectionParams {
|
|
@@ -80,35 +132,137 @@ interface UpdateCollectionParams {
|
|
|
80
132
|
metadata?: Record<string, any>;
|
|
81
133
|
}
|
|
82
134
|
interface CreateMemoryParams {
|
|
83
|
-
collection_id
|
|
84
|
-
content
|
|
135
|
+
collection_id?: string;
|
|
136
|
+
content?: string;
|
|
137
|
+
messages?: Array<{
|
|
138
|
+
role: string;
|
|
139
|
+
content: string;
|
|
140
|
+
}>;
|
|
85
141
|
importance?: number;
|
|
86
142
|
source_type?: string;
|
|
87
143
|
source_reference?: string;
|
|
88
144
|
metadata?: Record<string, any>;
|
|
145
|
+
infer?: boolean;
|
|
146
|
+
user_id?: string;
|
|
147
|
+
agent_id?: string;
|
|
148
|
+
run_id?: string;
|
|
149
|
+
app_id?: string;
|
|
150
|
+
namespace?: string;
|
|
151
|
+
wait_for_index?: boolean;
|
|
152
|
+
async_dispatch?: boolean;
|
|
153
|
+
title?: string;
|
|
154
|
+
tags?: string[];
|
|
155
|
+
source?: string;
|
|
156
|
+
/** Stable retry key sent as the Idempotency-Key transport header. */
|
|
157
|
+
idempotency_key?: string;
|
|
158
|
+
}
|
|
159
|
+
interface MemoryAddResult {
|
|
160
|
+
id: string;
|
|
161
|
+
memory_id?: string;
|
|
162
|
+
event: "ADD" | "UPDATE" | "NOOP" | string;
|
|
163
|
+
memory?: string;
|
|
164
|
+
reason?: string;
|
|
165
|
+
}
|
|
166
|
+
interface MemoryAddResponse {
|
|
167
|
+
results: MemoryAddResult[];
|
|
168
|
+
collection_id?: string;
|
|
169
|
+
processing_status: string;
|
|
170
|
+
searchable: boolean;
|
|
171
|
+
outbox_event_id?: string;
|
|
172
|
+
status_url?: string;
|
|
173
|
+
job_id?: string;
|
|
174
|
+
created_count: number;
|
|
175
|
+
updated_count: number;
|
|
176
|
+
skipped_count: number;
|
|
89
177
|
}
|
|
90
178
|
interface UpdateMemoryParams {
|
|
91
179
|
content?: string;
|
|
92
180
|
importance?: number;
|
|
93
181
|
metadata?: Record<string, any>;
|
|
182
|
+
wait_for_index?: boolean;
|
|
94
183
|
}
|
|
95
184
|
interface SearchParams {
|
|
96
185
|
query: string;
|
|
97
186
|
collection_id?: string;
|
|
98
187
|
limit?: number;
|
|
99
|
-
search_type?:
|
|
188
|
+
search_type?: "hybrid" | "vector" | "bm25" | "graph";
|
|
100
189
|
filters?: Record<string, any>;
|
|
190
|
+
user_id?: string;
|
|
191
|
+
agent_id?: string;
|
|
192
|
+
run_id?: string;
|
|
193
|
+
fast?: boolean;
|
|
194
|
+
threshold?: number;
|
|
195
|
+
include_low_confidence?: boolean;
|
|
196
|
+
group_by_source?: boolean;
|
|
197
|
+
debug?: boolean;
|
|
101
198
|
}
|
|
102
199
|
interface ReasonParams {
|
|
103
200
|
query: string;
|
|
104
201
|
collection_id?: string;
|
|
105
|
-
provider?:
|
|
202
|
+
provider?: "gemini" | "openai" | "anthropic";
|
|
106
203
|
include_steps?: boolean;
|
|
204
|
+
user_id?: string;
|
|
205
|
+
agent_id?: string;
|
|
206
|
+
run_id?: string;
|
|
207
|
+
facets?: string[];
|
|
107
208
|
}
|
|
108
209
|
interface ListParams {
|
|
109
210
|
skip?: number;
|
|
110
211
|
limit?: number;
|
|
111
212
|
}
|
|
213
|
+
interface MemoryListParams {
|
|
214
|
+
collection_id?: string;
|
|
215
|
+
user_id?: string;
|
|
216
|
+
agent_id?: string;
|
|
217
|
+
run_id?: string;
|
|
218
|
+
scope?: "all";
|
|
219
|
+
cursor?: string;
|
|
220
|
+
limit?: number;
|
|
221
|
+
include_superseded?: boolean;
|
|
222
|
+
}
|
|
223
|
+
interface CursorPage<T> {
|
|
224
|
+
items: T[];
|
|
225
|
+
next_cursor?: string | null;
|
|
226
|
+
has_more: boolean;
|
|
227
|
+
total_count: number;
|
|
228
|
+
}
|
|
229
|
+
interface MemoryJobReceipt {
|
|
230
|
+
job_id?: string;
|
|
231
|
+
status: string;
|
|
232
|
+
[key: string]: any;
|
|
233
|
+
}
|
|
234
|
+
interface CorrectionCreateParams {
|
|
235
|
+
corrected_content: string;
|
|
236
|
+
correction_type?: "preference" | "factual" | "procedural" | string;
|
|
237
|
+
original_content?: string;
|
|
238
|
+
context?: string;
|
|
239
|
+
memory_id?: string;
|
|
240
|
+
collection_id?: string;
|
|
241
|
+
user_id?: string;
|
|
242
|
+
agent_id?: string;
|
|
243
|
+
confidence?: number;
|
|
244
|
+
metadata?: Record<string, any>;
|
|
245
|
+
idempotency_key?: string;
|
|
246
|
+
}
|
|
247
|
+
interface CorrectionSearchParams {
|
|
248
|
+
query: string;
|
|
249
|
+
correction_type?: string;
|
|
250
|
+
collection_id?: string;
|
|
251
|
+
user_id?: string;
|
|
252
|
+
agent_id?: string;
|
|
253
|
+
include_global?: boolean;
|
|
254
|
+
limit?: number;
|
|
255
|
+
}
|
|
256
|
+
interface ProofLoopMetricParams {
|
|
257
|
+
policy_key: string;
|
|
258
|
+
metric_key: string;
|
|
259
|
+
name: string;
|
|
260
|
+
min_value: number;
|
|
261
|
+
max_value: number;
|
|
262
|
+
collection_id?: string;
|
|
263
|
+
user_id?: string;
|
|
264
|
+
[key: string]: any;
|
|
265
|
+
}
|
|
112
266
|
interface APIKeyResponse {
|
|
113
267
|
id: string;
|
|
114
268
|
name: string;
|
|
@@ -169,13 +323,13 @@ declare class MemoriesResource extends BaseResource {
|
|
|
169
323
|
/**
|
|
170
324
|
* Create a new memory
|
|
171
325
|
*/
|
|
172
|
-
create(params: CreateMemoryParams): Promise<
|
|
326
|
+
create(params: CreateMemoryParams): Promise<MemoryAddResponse>;
|
|
173
327
|
/**
|
|
174
328
|
* List memories
|
|
175
329
|
*/
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
330
|
+
listPage(params?: MemoryListParams): Promise<CursorPage<Memory>>;
|
|
331
|
+
/** Back-compatible one-page convenience; use listPage for cursor metadata. */
|
|
332
|
+
list(params?: MemoryListParams): Promise<Memory[]>;
|
|
179
333
|
/**
|
|
180
334
|
* Get a specific memory
|
|
181
335
|
*/
|
|
@@ -189,11 +343,26 @@ declare class MemoriesResource extends BaseResource {
|
|
|
189
343
|
*/
|
|
190
344
|
delete(memoryId: string): Promise<void>;
|
|
191
345
|
}
|
|
346
|
+
declare class MemoryJobsResource extends BaseResource {
|
|
347
|
+
get(jobId: string): Promise<MemoryJobReceipt>;
|
|
348
|
+
wait(jobId: string, options?: {
|
|
349
|
+
timeoutMs?: number;
|
|
350
|
+
pollIntervalMs?: number;
|
|
351
|
+
}): Promise<MemoryJobReceipt>;
|
|
352
|
+
}
|
|
353
|
+
declare class CorrectionsResource extends BaseResource {
|
|
354
|
+
create(params: CorrectionCreateParams): Promise<Record<string, any>>;
|
|
355
|
+
relevant(params: CorrectionSearchParams): Promise<Array<Record<string, any>>>;
|
|
356
|
+
get(correctionId: string): Promise<Record<string, any>>;
|
|
357
|
+
delete(correctionId: string): Promise<Record<string, any>>;
|
|
358
|
+
}
|
|
192
359
|
declare class SearchResource extends BaseResource {
|
|
193
360
|
/**
|
|
194
361
|
* Search memories
|
|
195
362
|
*/
|
|
196
363
|
search(params: SearchParams): Promise<SearchResult[]>;
|
|
364
|
+
/** Search while preserving the automatic ProofLoop evidence context. */
|
|
365
|
+
searchWithProof(params: SearchParams): Promise<SearchResponse>;
|
|
197
366
|
/**
|
|
198
367
|
* Find similar memories
|
|
199
368
|
*/
|
|
@@ -203,6 +372,36 @@ declare class SearchResource extends BaseResource {
|
|
|
203
372
|
*/
|
|
204
373
|
reason(params: ReasonParams): Promise<ReasoningResponse>;
|
|
205
374
|
}
|
|
375
|
+
declare class ProofLoopResource extends BaseResource {
|
|
376
|
+
/** Create a causal decision bound to search/chat evidence automatically. */
|
|
377
|
+
decide(params: ProofLoopDecisionParams): Promise<Record<string, any>>;
|
|
378
|
+
recordOutcome(decisionId: string, body: {
|
|
379
|
+
observations?: Record<string, any>[];
|
|
380
|
+
reward?: number;
|
|
381
|
+
success?: boolean;
|
|
382
|
+
idempotency_key?: string;
|
|
383
|
+
}): Promise<Record<string, any>>;
|
|
384
|
+
getDecision(decisionId: string): Promise<Record<string, any>>;
|
|
385
|
+
defineMetric(params: ProofLoopMetricParams): Promise<Record<string, any>>;
|
|
386
|
+
listMetrics(params?: {
|
|
387
|
+
policy_key?: string;
|
|
388
|
+
collection_id?: string;
|
|
389
|
+
user_id?: string;
|
|
390
|
+
}): Promise<Record<string, any>>;
|
|
391
|
+
policyInsights(policyKey: string, params?: {
|
|
392
|
+
collection_id?: string;
|
|
393
|
+
user_id?: string;
|
|
394
|
+
action_keys?: string[];
|
|
395
|
+
context?: Record<string, any>;
|
|
396
|
+
}): Promise<Record<string, any>>;
|
|
397
|
+
evaluatePolicy(policyKey: string, params?: {
|
|
398
|
+
collection_id?: string;
|
|
399
|
+
user_id?: string;
|
|
400
|
+
limit?: number;
|
|
401
|
+
}): Promise<Record<string, any>>;
|
|
402
|
+
proof(decisionId: string): Promise<Record<string, any>>;
|
|
403
|
+
publicKey(keyId?: string): Promise<Record<string, any>>;
|
|
404
|
+
}
|
|
206
405
|
declare class RLResource extends BaseResource {
|
|
207
406
|
/**
|
|
208
407
|
* Train the Memory Manager agent using RL
|
|
@@ -372,10 +571,6 @@ declare class WorldModelResource extends BaseResource {
|
|
|
372
571
|
plan(goal: string, collectionId?: string): Promise<any>;
|
|
373
572
|
}
|
|
374
573
|
|
|
375
|
-
/**
|
|
376
|
-
* Main Hebbrix client
|
|
377
|
-
*/
|
|
378
|
-
|
|
379
574
|
declare class MemoryClient {
|
|
380
575
|
private apiKey?;
|
|
381
576
|
private baseUrl;
|
|
@@ -383,6 +578,8 @@ declare class MemoryClient {
|
|
|
383
578
|
auth: AuthResource;
|
|
384
579
|
collections: CollectionsResource;
|
|
385
580
|
memories: MemoriesResource;
|
|
581
|
+
memoryJobs: MemoryJobsResource;
|
|
582
|
+
corrections: CorrectionsResource;
|
|
386
583
|
private searchResource;
|
|
387
584
|
rl: RLResource;
|
|
388
585
|
procedural: ProceduralResource;
|
|
@@ -391,6 +588,7 @@ declare class MemoryClient {
|
|
|
391
588
|
consolidation: ConsolidationResource;
|
|
392
589
|
memoryTools: MemoryToolsResource;
|
|
393
590
|
worldModel: WorldModelResource;
|
|
591
|
+
proofloop: ProofLoopResource;
|
|
394
592
|
constructor(config?: ClientConfig);
|
|
395
593
|
private getHeaders;
|
|
396
594
|
private handleError;
|
|
@@ -400,6 +598,7 @@ declare class MemoryClient {
|
|
|
400
598
|
patch<T = any>(path: string, body?: any): Promise<T>;
|
|
401
599
|
delete<T = any>(path: string): Promise<T>;
|
|
402
600
|
search(params: SearchParams): Promise<SearchResult[]>;
|
|
601
|
+
searchWithProof(params: SearchParams): Promise<SearchResponse>;
|
|
403
602
|
reason(params: ReasonParams): Promise<ReasoningResponse>;
|
|
404
603
|
}
|
|
405
604
|
|
|
@@ -427,4 +626,24 @@ declare class ServerError extends HebbrixError {
|
|
|
427
626
|
constructor(message?: string);
|
|
428
627
|
}
|
|
429
628
|
|
|
430
|
-
|
|
629
|
+
interface SafetyEnvelope {
|
|
630
|
+
no_match: boolean;
|
|
631
|
+
abstain_recommended: boolean;
|
|
632
|
+
query_confidence: number;
|
|
633
|
+
grounding: GroundingReceipt;
|
|
634
|
+
evidence_ids: string[];
|
|
635
|
+
evidence_claims?: unknown[];
|
|
636
|
+
safety_contract_version: string;
|
|
637
|
+
degraded?: boolean;
|
|
638
|
+
sdk_safety_reason?: string;
|
|
639
|
+
[key: string]: unknown;
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Validate the API-owned grounding receipt before exposing evidence to an agent.
|
|
643
|
+
* A malformed, degraded, abstaining, or ungrounded response is converted into
|
|
644
|
+
* one deterministic no-match envelope. This prevents SDK/API contract drift
|
|
645
|
+
* from turning a nearest neighbour into verified evidence.
|
|
646
|
+
*/
|
|
647
|
+
declare function enforceSearchSafety<T extends object>(response: T, rowsKey?: "results" | "sources"): T & SafetyEnvelope;
|
|
648
|
+
|
|
649
|
+
export { type APIKeyResponse, AuthResource, type AuthResponse, AuthenticationError, type ClientConfig, type Collection, CollectionsResource, ConsolidationResource, type CorrectionCreateParams, type CorrectionSearchParams, CorrectionsResource, type CreateCollectionParams, type CreateMemoryParams, type CursorPage, type EvidenceClaim, type GroundingReceipt, HebbrixError, type ListParams, MemoriesResource, type Memory, type MemoryAddResponse, type MemoryAddResult, MemoryClient, type MemoryJobReceipt, MemoryJobsResource, type MemoryListParams, MemoryToolsResource, type MemoryWithMetadata, NotFoundError, ProceduralResource, type ProofContext, type ProofLoopCandidate, type ProofLoopDecisionParams, type ProofLoopMetricParams, ProofLoopResource, RLResource, RateLimitError, type ReasonParams, type ReasoningResponse, type ReasoningSource, type SafetyEnvelope, type SearchParams, SearchResource, type SearchResponse, type SearchResult, ServerError, TemporalResource, type UpdateCollectionParams, type UpdateMemoryParams, type User, ValidationError, WorkingMemoryResource, WorldModelResource, enforceSearchSafety };
|
package/dist/index.js
CHANGED
|
@@ -24,12 +24,15 @@ __export(index_exports, {
|
|
|
24
24
|
AuthenticationError: () => AuthenticationError,
|
|
25
25
|
CollectionsResource: () => CollectionsResource,
|
|
26
26
|
ConsolidationResource: () => ConsolidationResource,
|
|
27
|
+
CorrectionsResource: () => CorrectionsResource,
|
|
27
28
|
HebbrixError: () => HebbrixError,
|
|
28
29
|
MemoriesResource: () => MemoriesResource,
|
|
29
30
|
MemoryClient: () => MemoryClient,
|
|
31
|
+
MemoryJobsResource: () => MemoryJobsResource,
|
|
30
32
|
MemoryToolsResource: () => MemoryToolsResource,
|
|
31
33
|
NotFoundError: () => NotFoundError,
|
|
32
34
|
ProceduralResource: () => ProceduralResource,
|
|
35
|
+
ProofLoopResource: () => ProofLoopResource,
|
|
33
36
|
RLResource: () => RLResource,
|
|
34
37
|
RateLimitError: () => RateLimitError,
|
|
35
38
|
SearchResource: () => SearchResource,
|
|
@@ -37,10 +40,63 @@ __export(index_exports, {
|
|
|
37
40
|
TemporalResource: () => TemporalResource,
|
|
38
41
|
ValidationError: () => ValidationError,
|
|
39
42
|
WorkingMemoryResource: () => WorkingMemoryResource,
|
|
40
|
-
WorldModelResource: () => WorldModelResource
|
|
43
|
+
WorldModelResource: () => WorldModelResource,
|
|
44
|
+
enforceSearchSafety: () => enforceSearchSafety
|
|
41
45
|
});
|
|
42
46
|
module.exports = __toCommonJS(index_exports);
|
|
43
47
|
|
|
48
|
+
// src/safety.ts
|
|
49
|
+
var REQUIRED_FIELDS = [
|
|
50
|
+
"no_match",
|
|
51
|
+
"abstain_recommended",
|
|
52
|
+
"query_confidence",
|
|
53
|
+
"grounding",
|
|
54
|
+
"evidence_ids",
|
|
55
|
+
"safety_contract_version"
|
|
56
|
+
];
|
|
57
|
+
function enforceSearchSafety(response, rowsKey = "results") {
|
|
58
|
+
const data = { ...response };
|
|
59
|
+
const rawRows = data[rowsKey];
|
|
60
|
+
const rows = Array.isArray(rawRows) ? rawRows.filter((row) => typeof row === "object" && row !== null) : [];
|
|
61
|
+
const missing = REQUIRED_FIELDS.filter(
|
|
62
|
+
(field) => !Object.prototype.hasOwnProperty.call(data, field)
|
|
63
|
+
);
|
|
64
|
+
let reason;
|
|
65
|
+
if (missing.length > 0) {
|
|
66
|
+
reason = `missing_safety_fields:${missing.join(",")}`;
|
|
67
|
+
} else if (typeof data.no_match !== "boolean" || typeof data.abstain_recommended !== "boolean") {
|
|
68
|
+
reason = "invalid_abstention_fields";
|
|
69
|
+
} else if (typeof data.query_confidence !== "number" || !Number.isFinite(data.query_confidence) || data.query_confidence < 0 || data.query_confidence > 1) {
|
|
70
|
+
reason = "invalid_query_confidence";
|
|
71
|
+
} else if (typeof data.grounding !== "object" || data.grounding === null || Array.isArray(data.grounding)) {
|
|
72
|
+
reason = "invalid_grounding_receipt";
|
|
73
|
+
} else if (!Array.isArray(data.evidence_ids)) {
|
|
74
|
+
reason = "invalid_evidence_ids";
|
|
75
|
+
} else {
|
|
76
|
+
const evidenceIds = new Set(data.evidence_ids.map(String));
|
|
77
|
+
const rowIds = rows.map((row) => row.memory_id ?? row.id).filter((value) => typeof value === "string" && value.length > 0);
|
|
78
|
+
if (rowIds.some((value) => !evidenceIds.has(value))) {
|
|
79
|
+
reason = "rows_not_bound_to_evidence_ids";
|
|
80
|
+
} else if (data.no_match && (rowIds.length > 0 || evidenceIds.size > 0)) {
|
|
81
|
+
reason = "no_match_contains_evidence";
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (reason || data.degraded === true || data.no_match === true || data.abstain_recommended === true) {
|
|
85
|
+
data[rowsKey] = [];
|
|
86
|
+
if (rowsKey === "results") data.total = 0;
|
|
87
|
+
data.no_match = true;
|
|
88
|
+
data.abstain_recommended = true;
|
|
89
|
+
data.query_confidence = 0;
|
|
90
|
+
data.evidence_ids = [];
|
|
91
|
+
data.evidence_claims = [];
|
|
92
|
+
if (reason) {
|
|
93
|
+
data.sdk_safety_reason = reason;
|
|
94
|
+
data.grounding = { status: "no_grounded_match", reason };
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
return data;
|
|
98
|
+
}
|
|
99
|
+
|
|
44
100
|
// src/resources.ts
|
|
45
101
|
var BaseResource = class {
|
|
46
102
|
constructor(client) {
|
|
@@ -120,14 +176,32 @@ var MemoriesResource = class extends BaseResource {
|
|
|
120
176
|
* Create a new memory
|
|
121
177
|
*/
|
|
122
178
|
async create(params) {
|
|
123
|
-
|
|
179
|
+
if (!params.content?.trim() && !params.messages?.length) {
|
|
180
|
+
throw new TypeError("content or messages must be provided");
|
|
181
|
+
}
|
|
182
|
+
const { idempotency_key, ...input } = params;
|
|
183
|
+
return this.client.request("POST", "/v1/memories", {
|
|
184
|
+
headers: idempotency_key ? { "Idempotency-Key": idempotency_key } : void 0,
|
|
185
|
+
body: JSON.stringify({
|
|
186
|
+
source_type: "text",
|
|
187
|
+
metadata: {},
|
|
188
|
+
infer: false,
|
|
189
|
+
wait_for_index: false,
|
|
190
|
+
...input
|
|
191
|
+
})
|
|
192
|
+
});
|
|
124
193
|
}
|
|
125
194
|
/**
|
|
126
195
|
* List memories
|
|
127
196
|
*/
|
|
128
|
-
async
|
|
197
|
+
async listPage(params = {}) {
|
|
129
198
|
return this.client.get("/v1/memories", params);
|
|
130
199
|
}
|
|
200
|
+
/** Back-compatible one-page convenience; use listPage for cursor metadata. */
|
|
201
|
+
async list(params = {}) {
|
|
202
|
+
const page = await this.listPage(params);
|
|
203
|
+
return page.items;
|
|
204
|
+
}
|
|
131
205
|
/**
|
|
132
206
|
* Get a specific memory
|
|
133
207
|
*/
|
|
@@ -147,19 +221,79 @@ var MemoriesResource = class extends BaseResource {
|
|
|
147
221
|
await this.client.delete(`/v1/memories/${memoryId}`);
|
|
148
222
|
}
|
|
149
223
|
};
|
|
224
|
+
var MemoryJobsResource = class extends BaseResource {
|
|
225
|
+
async get(jobId) {
|
|
226
|
+
return this.client.get(`/v1/memory-jobs/${jobId}`);
|
|
227
|
+
}
|
|
228
|
+
async wait(jobId, options = {}) {
|
|
229
|
+
const timeoutMs = Math.max(0, options.timeoutMs ?? 6e4);
|
|
230
|
+
const pollIntervalMs = Math.max(50, options.pollIntervalMs ?? 500);
|
|
231
|
+
const deadline = Date.now() + timeoutMs;
|
|
232
|
+
while (true) {
|
|
233
|
+
const receipt = await this.get(jobId);
|
|
234
|
+
const status = String(receipt.status || "").toLowerCase();
|
|
235
|
+
if (["completed", "failed", "cancelled", "canceled"].includes(status)) {
|
|
236
|
+
return receipt;
|
|
237
|
+
}
|
|
238
|
+
if (Date.now() >= deadline) {
|
|
239
|
+
throw new Error(`memory job ${jobId} did not finish in ${timeoutMs}ms`);
|
|
240
|
+
}
|
|
241
|
+
await new Promise((resolve) => setTimeout(resolve, pollIntervalMs));
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
};
|
|
245
|
+
var CorrectionsResource = class extends BaseResource {
|
|
246
|
+
async create(params) {
|
|
247
|
+
const { idempotency_key, ...body } = params;
|
|
248
|
+
return this.client.request("POST", "/v1/corrections", {
|
|
249
|
+
headers: idempotency_key ? { "Idempotency-Key": idempotency_key } : void 0,
|
|
250
|
+
body: JSON.stringify({
|
|
251
|
+
correction_type: "preference",
|
|
252
|
+
confidence: 1,
|
|
253
|
+
...body
|
|
254
|
+
})
|
|
255
|
+
});
|
|
256
|
+
}
|
|
257
|
+
async relevant(params) {
|
|
258
|
+
return this.client.get("/v1/corrections/relevant", {
|
|
259
|
+
include_global: false,
|
|
260
|
+
limit: 10,
|
|
261
|
+
...params
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
async get(correctionId) {
|
|
265
|
+
return this.client.get(`/v1/corrections/${correctionId}`);
|
|
266
|
+
}
|
|
267
|
+
async delete(correctionId) {
|
|
268
|
+
return this.client.delete(`/v1/corrections/${correctionId}`);
|
|
269
|
+
}
|
|
270
|
+
};
|
|
150
271
|
var SearchResource = class extends BaseResource {
|
|
151
272
|
/**
|
|
152
273
|
* Search memories
|
|
153
274
|
*/
|
|
154
275
|
async search(params) {
|
|
276
|
+
const response = await this.searchWithProof(params);
|
|
277
|
+
return response.results;
|
|
278
|
+
}
|
|
279
|
+
/** Search while preserving the automatic ProofLoop evidence context. */
|
|
280
|
+
async searchWithProof(params) {
|
|
155
281
|
const response = await this.client.post("/v1/search", {
|
|
156
282
|
query: params.query,
|
|
157
283
|
collection_id: params.collection_id,
|
|
284
|
+
user_id: params.user_id,
|
|
285
|
+
agent_id: params.agent_id,
|
|
286
|
+
run_id: params.run_id,
|
|
158
287
|
limit: params.limit || 10,
|
|
159
288
|
search_type: params.search_type || "hybrid",
|
|
160
|
-
filters: params.filters || {}
|
|
289
|
+
filters: params.filters || {},
|
|
290
|
+
fast: params.fast,
|
|
291
|
+
threshold: params.threshold,
|
|
292
|
+
include_low_confidence: params.include_low_confidence ?? false,
|
|
293
|
+
group_by_source: params.group_by_source ?? true,
|
|
294
|
+
debug: params.debug ?? false
|
|
161
295
|
});
|
|
162
|
-
return response
|
|
296
|
+
return enforceSearchSafety(response);
|
|
163
297
|
}
|
|
164
298
|
/**
|
|
165
299
|
* Find similar memories
|
|
@@ -175,11 +309,69 @@ var SearchResource = class extends BaseResource {
|
|
|
175
309
|
* Perform reasoning over memories
|
|
176
310
|
*/
|
|
177
311
|
async reason(params) {
|
|
178
|
-
|
|
179
|
-
|
|
312
|
+
const response = await this.client.post(
|
|
313
|
+
"/v1/search/reason",
|
|
314
|
+
{
|
|
315
|
+
query: params.query,
|
|
316
|
+
collection_id: params.collection_id,
|
|
317
|
+
provider: params.provider,
|
|
318
|
+
include_steps: params.include_steps ?? false,
|
|
319
|
+
user_id: params.user_id,
|
|
320
|
+
agent_id: params.agent_id,
|
|
321
|
+
run_id: params.run_id,
|
|
322
|
+
facets: params.facets ?? []
|
|
323
|
+
}
|
|
324
|
+
);
|
|
325
|
+
return enforceSearchSafety(response, "sources");
|
|
326
|
+
}
|
|
327
|
+
};
|
|
328
|
+
var ProofLoopResource = class extends BaseResource {
|
|
329
|
+
/** Create a causal decision bound to search/chat evidence automatically. */
|
|
330
|
+
async decide(params) {
|
|
331
|
+
const context = params.proof_context;
|
|
332
|
+
const token = typeof context === "string" ? context : context?.token;
|
|
333
|
+
const { proof_context: _context, ...body } = params;
|
|
334
|
+
return this.client.post("/v1/learning/decisions", {
|
|
335
|
+
...body,
|
|
336
|
+
...token ? { proof_context_token: token } : {}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
async recordOutcome(decisionId, body) {
|
|
340
|
+
return this.client.post(`/v1/learning/decisions/${decisionId}/outcomes`, {
|
|
341
|
+
observations: [],
|
|
342
|
+
...body
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
async getDecision(decisionId) {
|
|
346
|
+
return this.client.get(`/v1/learning/decisions/${decisionId}`);
|
|
347
|
+
}
|
|
348
|
+
async defineMetric(params) {
|
|
349
|
+
return this.client.post("/v1/learning/metrics", params);
|
|
350
|
+
}
|
|
351
|
+
async listMetrics(params = {}) {
|
|
352
|
+
return this.client.get("/v1/learning/metrics", params);
|
|
353
|
+
}
|
|
354
|
+
async policyInsights(policyKey, params = {}) {
|
|
355
|
+
return this.client.get(`/v1/learning/policies/${policyKey}/insights`, {
|
|
356
|
+
collection_id: params.collection_id,
|
|
357
|
+
user_id: params.user_id,
|
|
358
|
+
action_key: params.action_keys,
|
|
359
|
+
context: params.context ? JSON.stringify(params.context) : void 0
|
|
360
|
+
});
|
|
361
|
+
}
|
|
362
|
+
async evaluatePolicy(policyKey, params = {}) {
|
|
363
|
+
return this.client.post(`/v1/learning/policies/${policyKey}/evaluate`, {
|
|
180
364
|
collection_id: params.collection_id,
|
|
181
|
-
|
|
182
|
-
|
|
365
|
+
user_id: params.user_id,
|
|
366
|
+
limit: params.limit ?? 500
|
|
367
|
+
});
|
|
368
|
+
}
|
|
369
|
+
async proof(decisionId) {
|
|
370
|
+
return this.client.get(`/v1/learning/decisions/${decisionId}/proof`);
|
|
371
|
+
}
|
|
372
|
+
async publicKey(keyId) {
|
|
373
|
+
return this.client.get("/v1/learning/proof-key", {
|
|
374
|
+
key_id: keyId
|
|
183
375
|
});
|
|
184
376
|
}
|
|
185
377
|
};
|
|
@@ -477,6 +669,8 @@ var MemoryClient = class {
|
|
|
477
669
|
this.auth = new AuthResource(this);
|
|
478
670
|
this.collections = new CollectionsResource(this);
|
|
479
671
|
this.memories = new MemoriesResource(this);
|
|
672
|
+
this.memoryJobs = new MemoryJobsResource(this);
|
|
673
|
+
this.corrections = new CorrectionsResource(this);
|
|
480
674
|
this.searchResource = new SearchResource(this);
|
|
481
675
|
this.rl = new RLResource(this);
|
|
482
676
|
this.procedural = new ProceduralResource(this);
|
|
@@ -485,11 +679,12 @@ var MemoryClient = class {
|
|
|
485
679
|
this.consolidation = new ConsolidationResource(this);
|
|
486
680
|
this.memoryTools = new MemoryToolsResource(this);
|
|
487
681
|
this.worldModel = new WorldModelResource(this);
|
|
682
|
+
this.proofloop = new ProofLoopResource(this);
|
|
488
683
|
}
|
|
489
684
|
getHeaders() {
|
|
490
685
|
const headers = {
|
|
491
686
|
"Content-Type": "application/json",
|
|
492
|
-
"User-Agent": "hebbrix-typescript/2.
|
|
687
|
+
"User-Agent": "hebbrix-typescript/2.2.0"
|
|
493
688
|
};
|
|
494
689
|
if (this.apiKey) {
|
|
495
690
|
headers["Authorization"] = `Bearer ${this.apiKey}`;
|
|
@@ -543,7 +738,11 @@ var MemoryClient = class {
|
|
|
543
738
|
const searchParams = new URLSearchParams();
|
|
544
739
|
Object.entries(params).forEach(([key, value]) => {
|
|
545
740
|
if (value !== void 0 && value !== null) {
|
|
546
|
-
|
|
741
|
+
if (Array.isArray(value)) {
|
|
742
|
+
value.forEach((item) => searchParams.append(key, String(item)));
|
|
743
|
+
} else {
|
|
744
|
+
searchParams.append(key, String(value));
|
|
745
|
+
}
|
|
547
746
|
}
|
|
548
747
|
});
|
|
549
748
|
url += `?${searchParams.toString()}`;
|
|
@@ -567,6 +766,9 @@ var MemoryClient = class {
|
|
|
567
766
|
async search(params) {
|
|
568
767
|
return this.searchResource.search(params);
|
|
569
768
|
}
|
|
769
|
+
async searchWithProof(params) {
|
|
770
|
+
return this.searchResource.searchWithProof(params);
|
|
771
|
+
}
|
|
570
772
|
async reason(params) {
|
|
571
773
|
return this.searchResource.reason(params);
|
|
572
774
|
}
|
|
@@ -577,12 +779,15 @@ var MemoryClient = class {
|
|
|
577
779
|
AuthenticationError,
|
|
578
780
|
CollectionsResource,
|
|
579
781
|
ConsolidationResource,
|
|
782
|
+
CorrectionsResource,
|
|
580
783
|
HebbrixError,
|
|
581
784
|
MemoriesResource,
|
|
582
785
|
MemoryClient,
|
|
786
|
+
MemoryJobsResource,
|
|
583
787
|
MemoryToolsResource,
|
|
584
788
|
NotFoundError,
|
|
585
789
|
ProceduralResource,
|
|
790
|
+
ProofLoopResource,
|
|
586
791
|
RLResource,
|
|
587
792
|
RateLimitError,
|
|
588
793
|
SearchResource,
|
|
@@ -590,5 +795,6 @@ var MemoryClient = class {
|
|
|
590
795
|
TemporalResource,
|
|
591
796
|
ValidationError,
|
|
592
797
|
WorkingMemoryResource,
|
|
593
|
-
WorldModelResource
|
|
798
|
+
WorldModelResource,
|
|
799
|
+
enforceSearchSafety
|
|
594
800
|
});
|