@slashml/memory 1.0.13 → 1.0.15
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 +29 -1
- package/bin/cli.js +881 -113
- package/dist/index.d.ts +188 -6
- package/dist/index.js +439 -76
- package/dist/index.mjs +1 -0
- package/package.json +2 -2
- package/src/index.ts +727 -89
package/src/index.ts
CHANGED
|
@@ -8,6 +8,51 @@ export const DEFAULT_BASE_URL = "https://api.slashml.ai";
|
|
|
8
8
|
export const DEFAULT_MODEL = "slashml-1.5-fast";
|
|
9
9
|
export const DEFAULT_TIMEOUT_MS = 30_000;
|
|
10
10
|
|
|
11
|
+
export type RedactBucket =
|
|
12
|
+
| "SECRET"
|
|
13
|
+
| "PCI_FINANCIAL"
|
|
14
|
+
| "PII"
|
|
15
|
+
| "PHI"
|
|
16
|
+
| "COMMERCIAL_MNPI"
|
|
17
|
+
| "LEGAL_HR"
|
|
18
|
+
| "SECURITY_EXPLOIT";
|
|
19
|
+
|
|
20
|
+
export type RedactPreset =
|
|
21
|
+
| "off"
|
|
22
|
+
| "tier1_secrets"
|
|
23
|
+
| "soc2_coding"
|
|
24
|
+
| "gdpr"
|
|
25
|
+
| "hipaa"
|
|
26
|
+
| "enterprise_strict";
|
|
27
|
+
|
|
28
|
+
export type RedactPolicy = RedactPreset | RedactBucket[] | string | string[];
|
|
29
|
+
export type RedactScope = "memorize_and_recall" | "recall_only";
|
|
30
|
+
export type AccessMode = "read_write" | "read_only";
|
|
31
|
+
|
|
32
|
+
function normalizeRedactPolicy(
|
|
33
|
+
value: RedactPolicy | null | undefined,
|
|
34
|
+
): string | string[] | null {
|
|
35
|
+
if (value === undefined || value === null) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
if (Array.isArray(value)) {
|
|
39
|
+
const cleaned = value.map((v) => String(v).trim()).filter(Boolean);
|
|
40
|
+
return cleaned.length > 0 ? cleaned : null;
|
|
41
|
+
}
|
|
42
|
+
const raw = String(value).trim();
|
|
43
|
+
if (!raw) {
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
if (raw.includes(",")) {
|
|
47
|
+
const parts = raw
|
|
48
|
+
.split(",")
|
|
49
|
+
.map((p) => p.trim())
|
|
50
|
+
.filter(Boolean);
|
|
51
|
+
return parts.length > 0 ? parts : null;
|
|
52
|
+
}
|
|
53
|
+
return raw;
|
|
54
|
+
}
|
|
55
|
+
|
|
11
56
|
export interface MemoryClientOptions {
|
|
12
57
|
apiKey?: string;
|
|
13
58
|
api_key?: string;
|
|
@@ -19,6 +64,14 @@ export interface MemoryClientOptions {
|
|
|
19
64
|
org_id?: string;
|
|
20
65
|
projectId?: string;
|
|
21
66
|
project_id?: string;
|
|
67
|
+
agentId?: string;
|
|
68
|
+
agent_id?: string;
|
|
69
|
+
callerAgentId?: string;
|
|
70
|
+
caller_agent_id?: string;
|
|
71
|
+
redactPolicy?: RedactPolicy;
|
|
72
|
+
redact_policy?: RedactPolicy;
|
|
73
|
+
redactScope?: RedactScope;
|
|
74
|
+
redact_scope?: RedactScope;
|
|
22
75
|
model?: string;
|
|
23
76
|
timeoutMs?: number;
|
|
24
77
|
fetchImpl?: typeof fetch;
|
|
@@ -35,6 +88,12 @@ export interface MemoryFilters {
|
|
|
35
88
|
runId?: string | null;
|
|
36
89
|
metadata?: Record<string, unknown> | null;
|
|
37
90
|
filters?: Record<string, unknown> | null;
|
|
91
|
+
redact_policy?: RedactPolicy;
|
|
92
|
+
redactPolicy?: RedactPolicy;
|
|
93
|
+
redact_scope?: RedactScope;
|
|
94
|
+
redactScope?: RedactScope;
|
|
95
|
+
caller_agent_id?: string | null;
|
|
96
|
+
callerAgentId?: string | null;
|
|
38
97
|
}
|
|
39
98
|
|
|
40
99
|
export interface AddMemoryOptions extends MemoryFilters {
|
|
@@ -54,16 +113,99 @@ export interface IngestOptions {
|
|
|
54
113
|
namespace?: string;
|
|
55
114
|
model?: string;
|
|
56
115
|
metadata?: Record<string, unknown>;
|
|
116
|
+
redact_policy?: RedactPolicy;
|
|
117
|
+
redactPolicy?: RedactPolicy;
|
|
118
|
+
redact_scope?: RedactScope;
|
|
119
|
+
redactScope?: RedactScope;
|
|
120
|
+
caller_agent_id?: string;
|
|
121
|
+
callerAgentId?: string;
|
|
57
122
|
}
|
|
58
123
|
|
|
59
124
|
export interface QueryOptions {
|
|
60
125
|
namespace?: string;
|
|
61
126
|
model?: string;
|
|
62
127
|
top_k?: number;
|
|
128
|
+
redact_policy?: RedactPolicy;
|
|
129
|
+
redactPolicy?: RedactPolicy;
|
|
130
|
+
redact_scope?: RedactScope;
|
|
131
|
+
redactScope?: RedactScope;
|
|
132
|
+
caller_agent_id?: string;
|
|
133
|
+
callerAgentId?: string;
|
|
63
134
|
}
|
|
64
135
|
|
|
65
136
|
export interface ForgetOptions {
|
|
66
137
|
namespace?: string;
|
|
138
|
+
purge?: boolean;
|
|
139
|
+
reason?: string;
|
|
140
|
+
caller_agent_id?: string;
|
|
141
|
+
callerAgentId?: string;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export interface RedactOptions {
|
|
145
|
+
text?: string;
|
|
146
|
+
memory_id?: string;
|
|
147
|
+
memoryId?: string;
|
|
148
|
+
redact_policy?: RedactPolicy;
|
|
149
|
+
redactPolicy?: RedactPolicy;
|
|
150
|
+
explicit_spans?: Array<Record<string, unknown>>;
|
|
151
|
+
explicitSpans?: Array<Record<string, unknown>>;
|
|
152
|
+
dry_run?: boolean;
|
|
153
|
+
dryRun?: boolean;
|
|
154
|
+
caller_agent_id?: string;
|
|
155
|
+
callerAgentId?: string;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export interface PurgeOptions {
|
|
159
|
+
dry_run?: boolean;
|
|
160
|
+
dryRun?: boolean;
|
|
161
|
+
reason?: string;
|
|
162
|
+
caller_agent_id?: string;
|
|
163
|
+
callerAgentId?: string;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export interface UndoOptions {
|
|
167
|
+
caller_agent_id?: string;
|
|
168
|
+
callerAgentId?: string;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export interface UpdateRedactionPolicyOptions {
|
|
172
|
+
redact_policy?: RedactPolicy;
|
|
173
|
+
redactPolicy?: RedactPolicy;
|
|
174
|
+
redact_scope?: RedactScope;
|
|
175
|
+
redactScope?: RedactScope;
|
|
176
|
+
access_mode?: AccessMode;
|
|
177
|
+
accessMode?: AccessMode;
|
|
178
|
+
allow_write?: boolean;
|
|
179
|
+
allowWrite?: boolean;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export interface PreviewRedactionOptions {
|
|
183
|
+
text?: string;
|
|
184
|
+
agent_id?: string;
|
|
185
|
+
agentId?: string;
|
|
186
|
+
redact_policy?: RedactPolicy;
|
|
187
|
+
redactPolicy?: RedactPolicy;
|
|
188
|
+
redact_scope?: RedactScope;
|
|
189
|
+
redactScope?: RedactScope;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export interface ConfigureAgentOptions {
|
|
193
|
+
agent_id?: string;
|
|
194
|
+
agentId?: string;
|
|
195
|
+
name?: string | null;
|
|
196
|
+
access_mode?: AccessMode;
|
|
197
|
+
accessMode?: AccessMode;
|
|
198
|
+
allow_write?: boolean;
|
|
199
|
+
allowWrite?: boolean;
|
|
200
|
+
redact_policy?: RedactPolicy;
|
|
201
|
+
redactPolicy?: RedactPolicy;
|
|
202
|
+
redact_scope?: RedactScope;
|
|
203
|
+
redactScope?: RedactScope;
|
|
204
|
+
inherit_policy?: boolean;
|
|
205
|
+
inheritPolicy?: boolean;
|
|
206
|
+
inherit_access?: boolean;
|
|
207
|
+
inheritAccess?: boolean;
|
|
208
|
+
metadata?: Record<string, unknown>;
|
|
67
209
|
}
|
|
68
210
|
|
|
69
211
|
export interface InterveneOptions {
|
|
@@ -94,6 +236,12 @@ export interface InterveneOptions {
|
|
|
94
236
|
commitWrites?: boolean;
|
|
95
237
|
top_k?: number;
|
|
96
238
|
topK?: number;
|
|
239
|
+
redact_policy?: RedactPolicy;
|
|
240
|
+
redactPolicy?: RedactPolicy;
|
|
241
|
+
redact_scope?: RedactScope;
|
|
242
|
+
redactScope?: RedactScope;
|
|
243
|
+
caller_agent_id?: string | null;
|
|
244
|
+
callerAgentId?: string | null;
|
|
97
245
|
client_raw_tokens_delta?: number;
|
|
98
246
|
clientRawTokensDelta?: number;
|
|
99
247
|
client_dropped_tokens_delta?: number;
|
|
@@ -115,12 +263,14 @@ export interface StatusOptions {
|
|
|
115
263
|
|
|
116
264
|
export class SlashMLAPIError extends Error {
|
|
117
265
|
public readonly statusCode: number;
|
|
266
|
+
public readonly status: number;
|
|
118
267
|
public readonly details: Record<string, unknown>;
|
|
119
268
|
|
|
120
269
|
constructor(statusCode: number, message: string, details: Record<string, unknown> = {}) {
|
|
121
270
|
super(`SlashMLAPIError (${statusCode}): ${message}`);
|
|
122
271
|
this.name = "SlashMLAPIError";
|
|
123
272
|
this.statusCode = statusCode;
|
|
273
|
+
this.status = statusCode;
|
|
124
274
|
this.details = details;
|
|
125
275
|
}
|
|
126
276
|
}
|
|
@@ -133,6 +283,13 @@ function getEnv(name: string): string | undefined {
|
|
|
133
283
|
return undefined;
|
|
134
284
|
}
|
|
135
285
|
|
|
286
|
+
function wrapResults(res: unknown): Record<string, unknown> {
|
|
287
|
+
if (Array.isArray(res)) {
|
|
288
|
+
return { results: res };
|
|
289
|
+
}
|
|
290
|
+
return (res as Record<string, unknown>) ?? {};
|
|
291
|
+
}
|
|
292
|
+
|
|
136
293
|
export class ProjectManager {
|
|
137
294
|
private readonly client: MemoryClient;
|
|
138
295
|
|
|
@@ -258,14 +415,75 @@ export class ProjectManager {
|
|
|
258
415
|
}
|
|
259
416
|
}
|
|
260
417
|
|
|
418
|
+
export class AgentsManager {
|
|
419
|
+
private readonly client: MemoryClient;
|
|
420
|
+
|
|
421
|
+
constructor(client: MemoryClient) {
|
|
422
|
+
this.client = client;
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
public async list(): Promise<Record<string, unknown>> {
|
|
426
|
+
const res = await this.client.request<unknown>("GET", "/v1/agents/");
|
|
427
|
+
return Array.isArray(res) ? { agents: res } : ((res as Record<string, unknown>) ?? {});
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
public async configure(
|
|
431
|
+
agentIdOrOptions: string | ConfigureAgentOptions,
|
|
432
|
+
options: ConfigureAgentOptions = {},
|
|
433
|
+
): Promise<Record<string, unknown>> {
|
|
434
|
+
const isObj = typeof agentIdOrOptions === "object" && agentIdOrOptions !== null;
|
|
435
|
+
const opts: ConfigureAgentOptions = isObj ? agentIdOrOptions : options;
|
|
436
|
+
const resolvedAgentId = isObj
|
|
437
|
+
? (opts.agent_id ?? opts.agentId ?? "")
|
|
438
|
+
: agentIdOrOptions;
|
|
439
|
+
const payload: Record<string, unknown> = {
|
|
440
|
+
agent_id: String(resolvedAgentId).trim(),
|
|
441
|
+
};
|
|
442
|
+
if (opts.name !== undefined) payload.name = opts.name;
|
|
443
|
+
const accessMode = opts.access_mode ?? opts.accessMode;
|
|
444
|
+
if (accessMode !== undefined) payload.access_mode = accessMode;
|
|
445
|
+
const allowWrite = opts.allow_write ?? opts.allowWrite;
|
|
446
|
+
if (allowWrite !== undefined) payload.allow_write = Boolean(allowWrite);
|
|
447
|
+
const redactPolicy = opts.redact_policy ?? opts.redactPolicy;
|
|
448
|
+
if (redactPolicy !== undefined) {
|
|
449
|
+
payload.redact_policy = normalizeRedactPolicy(redactPolicy);
|
|
450
|
+
}
|
|
451
|
+
const redactScope = opts.redact_scope ?? opts.redactScope;
|
|
452
|
+
if (redactScope !== undefined) payload.redact_scope = redactScope;
|
|
453
|
+
if (opts.inherit_policy ?? opts.inheritPolicy) payload.inherit_policy = true;
|
|
454
|
+
if (opts.inherit_access ?? opts.inheritAccess) payload.inherit_access = true;
|
|
455
|
+
if (opts.metadata !== undefined) payload.metadata = opts.metadata;
|
|
456
|
+
return this.client.request("POST", "/v1/agents/", { jsonBody: payload });
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
public async upsert(
|
|
460
|
+
agentIdOrOptions: string | ConfigureAgentOptions,
|
|
461
|
+
options: ConfigureAgentOptions = {},
|
|
462
|
+
): Promise<Record<string, unknown>> {
|
|
463
|
+
return this.configure(agentIdOrOptions, options);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
public async delete(agentId: string): Promise<Record<string, unknown>> {
|
|
467
|
+
return this.client.request(
|
|
468
|
+
"DELETE",
|
|
469
|
+
`/v1/agents/${encodeURIComponent(String(agentId).trim())}/`,
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
261
474
|
export class MemoryClient {
|
|
262
475
|
public readonly apiKey: string;
|
|
263
476
|
public readonly baseUrl: string;
|
|
264
477
|
public readonly orgId: string | null;
|
|
265
478
|
public readonly projectId: string | null;
|
|
479
|
+
public readonly agentId: string | null;
|
|
480
|
+
public readonly callerAgentId: string | null;
|
|
481
|
+
public readonly redactPolicy: string | string[] | null;
|
|
482
|
+
public readonly redactScope: RedactScope | null;
|
|
266
483
|
public readonly model: string;
|
|
267
484
|
public readonly timeoutMs: number;
|
|
268
485
|
public readonly project: ProjectManager;
|
|
486
|
+
public readonly agents: AgentsManager;
|
|
269
487
|
private readonly fetchImpl: typeof fetch;
|
|
270
488
|
|
|
271
489
|
constructor(options: MemoryClientOptions = {}) {
|
|
@@ -287,15 +505,71 @@ export class MemoryClient {
|
|
|
287
505
|
options.model ||
|
|
288
506
|
getEnv("SLASHML_MODEL") ||
|
|
289
507
|
DEFAULT_MODEL;
|
|
508
|
+
const rawAgentId =
|
|
509
|
+
options.agentId ??
|
|
510
|
+
options.agent_id ??
|
|
511
|
+
options.callerAgentId ??
|
|
512
|
+
options.caller_agent_id ??
|
|
513
|
+
getEnv("SLASHML_AGENT_ID") ??
|
|
514
|
+
null;
|
|
515
|
+
const rawRedactPolicy =
|
|
516
|
+
options.redactPolicy ??
|
|
517
|
+
options.redact_policy ??
|
|
518
|
+
getEnv("SLASHML_REDACT_POLICY") ??
|
|
519
|
+
null;
|
|
520
|
+
const rawRedactScope =
|
|
521
|
+
options.redactScope ??
|
|
522
|
+
options.redact_scope ??
|
|
523
|
+
(getEnv("SLASHML_REDACT_SCOPE") as RedactScope | undefined) ??
|
|
524
|
+
null;
|
|
290
525
|
|
|
291
526
|
this.apiKey = resolvedKey;
|
|
292
527
|
this.baseUrl = resolvedUrl.replace(/\/+$/, "");
|
|
293
528
|
this.orgId = options.orgId || options.org_id || getEnv("SLASHML_ORG_ID") || null;
|
|
294
529
|
this.projectId = options.projectId || options.project_id || getEnv("SLASHML_PROJECT_ID") || null;
|
|
530
|
+
this.agentId = rawAgentId && String(rawAgentId).trim() ? String(rawAgentId).trim() : null;
|
|
531
|
+
this.callerAgentId = this.agentId;
|
|
532
|
+
this.redactPolicy = normalizeRedactPolicy(rawRedactPolicy);
|
|
533
|
+
this.redactScope =
|
|
534
|
+
rawRedactScope && String(rawRedactScope).trim()
|
|
535
|
+
? (String(rawRedactScope).trim() as RedactScope)
|
|
536
|
+
: null;
|
|
295
537
|
this.model = resolvedModel;
|
|
296
538
|
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
297
539
|
this.fetchImpl = options.fetchImpl ?? globalThis.fetch;
|
|
298
540
|
this.project = new ProjectManager(this);
|
|
541
|
+
this.agents = new AgentsManager(this);
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
private applyLifecycleDefaults(
|
|
545
|
+
payload?: Record<string, unknown>,
|
|
546
|
+
opts: {
|
|
547
|
+
redactPolicy?: RedactPolicy;
|
|
548
|
+
redactScope?: RedactScope;
|
|
549
|
+
callerAgentId?: string | null;
|
|
550
|
+
} = {},
|
|
551
|
+
): Record<string, string> | undefined {
|
|
552
|
+
const effPolicy =
|
|
553
|
+
opts.redactPolicy !== undefined
|
|
554
|
+
? normalizeRedactPolicy(opts.redactPolicy)
|
|
555
|
+
: this.redactPolicy;
|
|
556
|
+
const effScope = opts.redactScope ?? this.redactScope;
|
|
557
|
+
const effCaller =
|
|
558
|
+
opts.callerAgentId !== undefined && opts.callerAgentId !== null
|
|
559
|
+
? String(opts.callerAgentId).trim()
|
|
560
|
+
: this.agentId;
|
|
561
|
+
if (payload) {
|
|
562
|
+
if (effPolicy !== null && payload.redact_policy === undefined) {
|
|
563
|
+
payload.redact_policy = effPolicy;
|
|
564
|
+
}
|
|
565
|
+
if (effScope && payload.redact_scope === undefined) {
|
|
566
|
+
payload.redact_scope = effScope;
|
|
567
|
+
}
|
|
568
|
+
if (effCaller && payload.caller_agent_id === undefined) {
|
|
569
|
+
payload.caller_agent_id = effCaller;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return effCaller ? { "X-SlashML-Agent-Id": effCaller } : undefined;
|
|
299
573
|
}
|
|
300
574
|
|
|
301
575
|
public async request<T = Record<string, unknown>>(
|
|
@@ -304,6 +578,7 @@ export class MemoryClient {
|
|
|
304
578
|
options: {
|
|
305
579
|
params?: Record<string, unknown>;
|
|
306
580
|
jsonBody?: Record<string, unknown>;
|
|
581
|
+
headers?: Record<string, string>;
|
|
307
582
|
} = {},
|
|
308
583
|
): Promise<T> {
|
|
309
584
|
if (!this.apiKey) {
|
|
@@ -330,7 +605,7 @@ export class MemoryClient {
|
|
|
330
605
|
const headers: Record<string, string> = {
|
|
331
606
|
Accept: "application/json",
|
|
332
607
|
"Content-Type": "application/json",
|
|
333
|
-
"User-Agent": "slashml-memory-ts/1.0.
|
|
608
|
+
"User-Agent": "slashml-memory-ts/1.0.15",
|
|
334
609
|
};
|
|
335
610
|
if (this.apiKey) {
|
|
336
611
|
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
@@ -342,6 +617,14 @@ export class MemoryClient {
|
|
|
342
617
|
if (this.projectId) {
|
|
343
618
|
headers["X-SlashML-Project-Id"] = this.projectId;
|
|
344
619
|
}
|
|
620
|
+
if (this.agentId) {
|
|
621
|
+
headers["X-SlashML-Agent-Id"] = this.agentId;
|
|
622
|
+
}
|
|
623
|
+
if (options.headers) {
|
|
624
|
+
for (const [hk, hv] of Object.entries(options.headers)) {
|
|
625
|
+
if (hv) headers[hk] = hv;
|
|
626
|
+
}
|
|
627
|
+
}
|
|
345
628
|
|
|
346
629
|
const controller = new AbortController();
|
|
347
630
|
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
@@ -395,40 +678,254 @@ export class MemoryClient {
|
|
|
395
678
|
options: IngestOptions = {},
|
|
396
679
|
): Promise<Record<string, unknown>> {
|
|
397
680
|
const docs = typeof documents === "string" ? [documents] : Array.from(documents);
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
681
|
+
const payload: Record<string, unknown> = {
|
|
682
|
+
namespace: options.namespace ?? "default",
|
|
683
|
+
model: options.model ?? this.model,
|
|
684
|
+
documents: docs,
|
|
685
|
+
metadata: options.metadata ?? {},
|
|
686
|
+
};
|
|
687
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
688
|
+
redactPolicy: options.redact_policy ?? options.redactPolicy,
|
|
689
|
+
redactScope: options.redact_scope ?? options.redactScope,
|
|
690
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
405
691
|
});
|
|
692
|
+
return this.request("POST", "/v1/memory/ingest", { jsonBody: payload, headers });
|
|
406
693
|
}
|
|
407
694
|
|
|
408
695
|
public async query(
|
|
409
696
|
prompt: string,
|
|
410
697
|
options: QueryOptions = {},
|
|
411
698
|
): Promise<Record<string, unknown>> {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
699
|
+
const payload: Record<string, unknown> = {
|
|
700
|
+
namespace: options.namespace ?? "default",
|
|
701
|
+
model: options.model ?? this.model,
|
|
702
|
+
prompt,
|
|
703
|
+
top_k: options.top_k ?? 5,
|
|
704
|
+
};
|
|
705
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
706
|
+
redactPolicy: options.redact_policy ?? options.redactPolicy,
|
|
707
|
+
redactScope: options.redact_scope ?? options.redactScope,
|
|
708
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
419
709
|
});
|
|
710
|
+
return this.request("POST", "/v1/memory/query", { jsonBody: payload, headers });
|
|
420
711
|
}
|
|
421
712
|
|
|
422
713
|
public async forget(
|
|
423
714
|
target: string,
|
|
424
715
|
options: ForgetOptions = {},
|
|
425
716
|
): Promise<Record<string, unknown>> {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
}
|
|
717
|
+
if (options.purge) {
|
|
718
|
+
return this.purge(target, {
|
|
719
|
+
reason: options.reason,
|
|
720
|
+
caller_agent_id: options.caller_agent_id ?? options.callerAgentId,
|
|
721
|
+
});
|
|
722
|
+
}
|
|
723
|
+
const payload: Record<string, unknown> = {
|
|
724
|
+
namespace: options.namespace ?? "default",
|
|
725
|
+
target,
|
|
726
|
+
};
|
|
727
|
+
if (options.reason !== undefined) {
|
|
728
|
+
payload.reason = options.reason;
|
|
729
|
+
}
|
|
730
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
731
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
732
|
+
});
|
|
733
|
+
return this.request("POST", "/v1/memory/forget", { jsonBody: payload, headers });
|
|
734
|
+
}
|
|
735
|
+
|
|
736
|
+
public async redact(
|
|
737
|
+
textOrOptions: string | RedactOptions,
|
|
738
|
+
options: RedactOptions = {},
|
|
739
|
+
): Promise<Record<string, unknown>> {
|
|
740
|
+
const opts: RedactOptions =
|
|
741
|
+
typeof textOrOptions === "string"
|
|
742
|
+
? { ...options, text: options.text ?? textOrOptions }
|
|
743
|
+
: { ...textOrOptions, ...options };
|
|
744
|
+
const payload: Record<string, unknown> = {};
|
|
745
|
+
if (opts.text !== undefined) {
|
|
746
|
+
payload.text = opts.text;
|
|
747
|
+
}
|
|
748
|
+
const memId = opts.memory_id ?? opts.memoryId;
|
|
749
|
+
if (memId) {
|
|
750
|
+
payload.memory_id = memId;
|
|
751
|
+
}
|
|
752
|
+
const explicitSpans = opts.explicit_spans ?? opts.explicitSpans;
|
|
753
|
+
if (explicitSpans !== undefined) {
|
|
754
|
+
payload.explicit_spans = explicitSpans;
|
|
755
|
+
}
|
|
756
|
+
const dryRun = opts.dry_run ?? opts.dryRun;
|
|
757
|
+
if (dryRun !== undefined) {
|
|
758
|
+
payload.dry_run = Boolean(dryRun);
|
|
759
|
+
}
|
|
760
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
761
|
+
redactPolicy: opts.redact_policy ?? opts.redactPolicy,
|
|
762
|
+
callerAgentId: opts.caller_agent_id ?? opts.callerAgentId,
|
|
763
|
+
});
|
|
764
|
+
return this.request("POST", "/v1/memory/redact", { jsonBody: payload, headers });
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
public async purge(
|
|
768
|
+
memoryIds: string | string[],
|
|
769
|
+
options: PurgeOptions = {},
|
|
770
|
+
): Promise<Record<string, unknown>> {
|
|
771
|
+
const ids = typeof memoryIds === "string" ? [memoryIds] : Array.from(memoryIds);
|
|
772
|
+
const payload: Record<string, unknown> = {
|
|
773
|
+
memory_ids: ids,
|
|
774
|
+
};
|
|
775
|
+
const dryRun = options.dry_run ?? options.dryRun;
|
|
776
|
+
if (dryRun !== undefined) {
|
|
777
|
+
payload.dry_run = Boolean(dryRun);
|
|
778
|
+
}
|
|
779
|
+
if (options.reason !== undefined) {
|
|
780
|
+
payload.reason = options.reason;
|
|
781
|
+
}
|
|
782
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
783
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
784
|
+
});
|
|
785
|
+
return this.request("POST", "/v1/memory/purge", { jsonBody: payload, headers });
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
public async undo(
|
|
789
|
+
undoToken: string,
|
|
790
|
+
options: UndoOptions = {},
|
|
791
|
+
): Promise<Record<string, unknown>> {
|
|
792
|
+
const payload: Record<string, unknown> = {
|
|
793
|
+
undo_token: undoToken,
|
|
794
|
+
};
|
|
795
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
796
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
431
797
|
});
|
|
798
|
+
return this.request("POST", "/v1/memory/undo", { jsonBody: payload, headers });
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
public async getRedactionPolicy(): Promise<Record<string, unknown>> {
|
|
802
|
+
return this.request("GET", "/v1/memory/redact/policy");
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
public async get_redaction_policy(): Promise<Record<string, unknown>> {
|
|
806
|
+
return this.getRedactionPolicy();
|
|
807
|
+
}
|
|
808
|
+
|
|
809
|
+
public async updateRedactionPolicy(
|
|
810
|
+
options: UpdateRedactionPolicyOptions = {},
|
|
811
|
+
): Promise<Record<string, unknown>> {
|
|
812
|
+
const payload: Record<string, unknown> = {};
|
|
813
|
+
const redactPolicy = options.redact_policy ?? options.redactPolicy;
|
|
814
|
+
if (redactPolicy !== undefined) {
|
|
815
|
+
payload.redact_policy = normalizeRedactPolicy(redactPolicy);
|
|
816
|
+
}
|
|
817
|
+
const redactScope = options.redact_scope ?? options.redactScope;
|
|
818
|
+
if (redactScope !== undefined) {
|
|
819
|
+
payload.redact_scope = redactScope;
|
|
820
|
+
}
|
|
821
|
+
const accessMode = options.access_mode ?? options.accessMode;
|
|
822
|
+
if (accessMode !== undefined) {
|
|
823
|
+
payload.access_mode = accessMode;
|
|
824
|
+
}
|
|
825
|
+
const allowWrite = options.allow_write ?? options.allowWrite;
|
|
826
|
+
if (allowWrite !== undefined) {
|
|
827
|
+
payload.allow_write = Boolean(allowWrite);
|
|
828
|
+
}
|
|
829
|
+
return this.request("PUT", "/v1/memory/redact/policy", { jsonBody: payload });
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
public async update_redaction_policy(
|
|
833
|
+
options: UpdateRedactionPolicyOptions = {},
|
|
834
|
+
): Promise<Record<string, unknown>> {
|
|
835
|
+
return this.updateRedactionPolicy(options);
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
public async previewRedaction(
|
|
839
|
+
textOrOptions: string | PreviewRedactionOptions,
|
|
840
|
+
options: PreviewRedactionOptions = {},
|
|
841
|
+
): Promise<Record<string, unknown>> {
|
|
842
|
+
const opts: PreviewRedactionOptions =
|
|
843
|
+
typeof textOrOptions === "string"
|
|
844
|
+
? { ...options, text: options.text ?? textOrOptions }
|
|
845
|
+
: { ...textOrOptions, ...options };
|
|
846
|
+
const payload: Record<string, unknown> = {
|
|
847
|
+
text: opts.text ?? "",
|
|
848
|
+
};
|
|
849
|
+
const agentId = opts.agent_id ?? opts.agentId;
|
|
850
|
+
if (agentId) {
|
|
851
|
+
payload.agent_id = agentId;
|
|
852
|
+
}
|
|
853
|
+
const redactPolicy = opts.redact_policy ?? opts.redactPolicy;
|
|
854
|
+
if (redactPolicy !== undefined) {
|
|
855
|
+
payload.redact_policy = normalizeRedactPolicy(redactPolicy);
|
|
856
|
+
}
|
|
857
|
+
const redactScope = opts.redact_scope ?? opts.redactScope;
|
|
858
|
+
if (redactScope !== undefined) {
|
|
859
|
+
payload.redact_scope = redactScope;
|
|
860
|
+
}
|
|
861
|
+
return this.request("POST", "/v1/memory/redact/preview", { jsonBody: payload });
|
|
862
|
+
}
|
|
863
|
+
|
|
864
|
+
public async preview_redaction(
|
|
865
|
+
textOrOptions: string | PreviewRedactionOptions,
|
|
866
|
+
options: PreviewRedactionOptions = {},
|
|
867
|
+
): Promise<Record<string, unknown>> {
|
|
868
|
+
return this.previewRedaction(textOrOptions, options);
|
|
869
|
+
}
|
|
870
|
+
|
|
871
|
+
public async listAgents(): Promise<Record<string, unknown>> {
|
|
872
|
+
return this.agents.list();
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
public async listAgentPolicies(): Promise<Record<string, unknown>> {
|
|
876
|
+
return this.agents.list();
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
public async list_agents(): Promise<Record<string, unknown>> {
|
|
880
|
+
return this.agents.list();
|
|
881
|
+
}
|
|
882
|
+
|
|
883
|
+
public async list_agent_policies(): Promise<Record<string, unknown>> {
|
|
884
|
+
return this.agents.list();
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
public async configureAgent(
|
|
888
|
+
agentIdOrOptions: string | ConfigureAgentOptions,
|
|
889
|
+
options: ConfigureAgentOptions = {},
|
|
890
|
+
): Promise<Record<string, unknown>> {
|
|
891
|
+
return this.agents.configure(agentIdOrOptions, options);
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
public async upsertAgentPolicy(
|
|
895
|
+
agentIdOrOptions: string | ConfigureAgentOptions,
|
|
896
|
+
options: ConfigureAgentOptions = {},
|
|
897
|
+
): Promise<Record<string, unknown>> {
|
|
898
|
+
return this.agents.configure(agentIdOrOptions, options);
|
|
899
|
+
}
|
|
900
|
+
|
|
901
|
+
public async configure_agent(
|
|
902
|
+
agentIdOrOptions: string | ConfigureAgentOptions,
|
|
903
|
+
options: ConfigureAgentOptions = {},
|
|
904
|
+
): Promise<Record<string, unknown>> {
|
|
905
|
+
return this.agents.configure(agentIdOrOptions, options);
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
public async upsert_agent_policy(
|
|
909
|
+
agentIdOrOptions: string | ConfigureAgentOptions,
|
|
910
|
+
options: ConfigureAgentOptions = {},
|
|
911
|
+
): Promise<Record<string, unknown>> {
|
|
912
|
+
return this.agents.configure(agentIdOrOptions, options);
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
public async deleteAgent(agentId: string): Promise<Record<string, unknown>> {
|
|
916
|
+
return this.agents.delete(agentId);
|
|
917
|
+
}
|
|
918
|
+
|
|
919
|
+
public async deleteAgentPolicy(agentId: string): Promise<Record<string, unknown>> {
|
|
920
|
+
return this.agents.delete(agentId);
|
|
921
|
+
}
|
|
922
|
+
|
|
923
|
+
public async delete_agent(agentId: string): Promise<Record<string, unknown>> {
|
|
924
|
+
return this.agents.delete(agentId);
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
public async delete_agent_policy(agentId: string): Promise<Record<string, unknown>> {
|
|
928
|
+
return this.agents.delete(agentId);
|
|
432
929
|
}
|
|
433
930
|
|
|
434
931
|
public async intervene(
|
|
@@ -449,30 +946,34 @@ export class MemoryClient {
|
|
|
449
946
|
opts.stop_hook_active ?? opts.stopHookActive ?? undefined;
|
|
450
947
|
const whisperedIds =
|
|
451
948
|
opts.whispered_memory_ids ?? opts.whisperedMemoryIds ?? undefined;
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
client_dropped_tokens_delta
|
|
471
|
-
|
|
472
|
-
client_dropped_events_delta
|
|
473
|
-
|
|
474
|
-
|
|
949
|
+
const payload: Record<string, unknown> = {
|
|
950
|
+
hook_event_name: opts.hook_event_name ?? opts.hookEventName ?? "UserPromptSubmit",
|
|
951
|
+
prompt: opts.prompt ?? resolvedText,
|
|
952
|
+
text: resolvedText,
|
|
953
|
+
...(lastAssistantMsg !== undefined ? { last_assistant_message: lastAssistantMsg } : {}),
|
|
954
|
+
...(stopHookActive !== undefined ? { stop_hook_active: Boolean(stopHookActive) } : {}),
|
|
955
|
+
...(whisperedIds && whisperedIds.length > 0 ? { whispered_memory_ids: whisperedIds } : {}),
|
|
956
|
+
tool_name: opts.tool_name ?? opts.toolName ?? null,
|
|
957
|
+
tool_input: opts.tool_input ?? opts.toolInput ?? null,
|
|
958
|
+
tool_response: opts.tool_response ?? opts.toolResponse ?? null,
|
|
959
|
+
user_id: opts.user_id ?? opts.userId ?? "default",
|
|
960
|
+
...(resolvedProjectId ? { project_id: resolvedProjectId } : {}),
|
|
961
|
+
...(resolvedSessionId ? { session_id: resolvedSessionId } : {}),
|
|
962
|
+
model: resolvedModel,
|
|
963
|
+
commit_writes: opts.commit_writes ?? opts.commitWrites ?? true,
|
|
964
|
+
top_k: opts.top_k ?? opts.topK ?? 5,
|
|
965
|
+
client_raw_tokens_delta: opts.client_raw_tokens_delta ?? opts.clientRawTokensDelta ?? 0,
|
|
966
|
+
client_dropped_tokens_delta:
|
|
967
|
+
opts.client_dropped_tokens_delta ?? opts.clientDroppedTokensDelta ?? 0,
|
|
968
|
+
client_dropped_events_delta:
|
|
969
|
+
opts.client_dropped_events_delta ?? opts.clientDroppedEventsDelta ?? 0,
|
|
970
|
+
};
|
|
971
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
972
|
+
redactPolicy: opts.redact_policy ?? opts.redactPolicy,
|
|
973
|
+
redactScope: opts.redact_scope ?? opts.redactScope,
|
|
974
|
+
callerAgentId: opts.caller_agent_id ?? opts.callerAgentId,
|
|
475
975
|
});
|
|
976
|
+
return this.request("POST", "/v1/memory/intervene", { jsonBody: payload, headers });
|
|
476
977
|
}
|
|
477
978
|
|
|
478
979
|
public async status(options: StatusOptions = {}): Promise<Record<string, unknown>> {
|
|
@@ -527,7 +1028,14 @@ export class MemoryClient {
|
|
|
527
1028
|
payload.memory_id = memId;
|
|
528
1029
|
payload.id = memId;
|
|
529
1030
|
}
|
|
530
|
-
|
|
1031
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
1032
|
+
redactPolicy: options.redact_policy ?? options.redactPolicy,
|
|
1033
|
+
redactScope: options.redact_scope ?? options.redactScope,
|
|
1034
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
1035
|
+
});
|
|
1036
|
+
return wrapResults(
|
|
1037
|
+
await this.request<unknown>("POST", "/v1/memories", { jsonBody: payload, headers }),
|
|
1038
|
+
);
|
|
531
1039
|
}
|
|
532
1040
|
|
|
533
1041
|
public async search(
|
|
@@ -538,20 +1046,26 @@ export class MemoryClient {
|
|
|
538
1046
|
const query = isObj ? queryOrOptions.query : queryOrOptions;
|
|
539
1047
|
const opts: SearchMemoryOptions = isObj ? queryOrOptions : options;
|
|
540
1048
|
const effectiveLimit = opts.top_k ?? opts.topK ?? opts.limit ?? 5;
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
1049
|
+
const payload: Record<string, unknown> = {
|
|
1050
|
+
query,
|
|
1051
|
+
user_id: opts.user_id ?? opts.userId ?? null,
|
|
1052
|
+
agent_id: opts.agent_id ?? opts.agentId ?? null,
|
|
1053
|
+
app_id: opts.app_id ?? opts.appId ?? null,
|
|
1054
|
+
run_id: opts.run_id ?? opts.runId ?? null,
|
|
1055
|
+
limit: effectiveLimit,
|
|
1056
|
+
top_k: effectiveLimit,
|
|
1057
|
+
filters: opts.filters ?? opts.metadata ?? null,
|
|
1058
|
+
threshold: opts.threshold ?? null,
|
|
1059
|
+
model: this.model,
|
|
1060
|
+
};
|
|
1061
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
1062
|
+
redactPolicy: opts.redact_policy ?? opts.redactPolicy,
|
|
1063
|
+
redactScope: opts.redact_scope ?? opts.redactScope,
|
|
1064
|
+
callerAgentId: opts.caller_agent_id ?? opts.callerAgentId,
|
|
554
1065
|
});
|
|
1066
|
+
return wrapResults(
|
|
1067
|
+
await this.request<unknown>("POST", "/v1/memories/search", { jsonBody: payload, headers }),
|
|
1068
|
+
);
|
|
555
1069
|
}
|
|
556
1070
|
|
|
557
1071
|
public async recall(
|
|
@@ -564,15 +1078,27 @@ export class MemoryClient {
|
|
|
564
1078
|
public async getAll(
|
|
565
1079
|
options: MemoryFilters & { limit?: number } = {},
|
|
566
1080
|
): Promise<Record<string, unknown>> {
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
limit: options.limit ?? 100,
|
|
574
|
-
},
|
|
1081
|
+
const effPolicy = normalizeRedactPolicy(
|
|
1082
|
+
options.redact_policy ?? options.redactPolicy ?? this.redactPolicy,
|
|
1083
|
+
);
|
|
1084
|
+
const effScope = options.redact_scope ?? options.redactScope ?? this.redactScope;
|
|
1085
|
+
const headers = this.applyLifecycleDefaults(undefined, {
|
|
1086
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
575
1087
|
});
|
|
1088
|
+
return wrapResults(
|
|
1089
|
+
await this.request<unknown>("GET", "/v1/memories", {
|
|
1090
|
+
params: {
|
|
1091
|
+
user_id: options.user_id ?? options.userId ?? undefined,
|
|
1092
|
+
agent_id: options.agent_id ?? options.agentId ?? undefined,
|
|
1093
|
+
app_id: options.app_id ?? options.appId ?? undefined,
|
|
1094
|
+
run_id: options.run_id ?? options.runId ?? undefined,
|
|
1095
|
+
limit: options.limit ?? 100,
|
|
1096
|
+
redact_policy: Array.isArray(effPolicy) ? effPolicy.join(",") : (effPolicy ?? undefined),
|
|
1097
|
+
redact_scope: effScope ?? undefined,
|
|
1098
|
+
},
|
|
1099
|
+
headers,
|
|
1100
|
+
}),
|
|
1101
|
+
);
|
|
576
1102
|
}
|
|
577
1103
|
|
|
578
1104
|
public async get_all(
|
|
@@ -581,9 +1107,32 @@ export class MemoryClient {
|
|
|
581
1107
|
return this.getAll(options);
|
|
582
1108
|
}
|
|
583
1109
|
|
|
584
|
-
public async get(
|
|
1110
|
+
public async get(
|
|
1111
|
+
memoryId: string,
|
|
1112
|
+
options: {
|
|
1113
|
+
redact_policy?: RedactPolicy;
|
|
1114
|
+
redactPolicy?: RedactPolicy;
|
|
1115
|
+
redact_scope?: RedactScope;
|
|
1116
|
+
redactScope?: RedactScope;
|
|
1117
|
+
caller_agent_id?: string;
|
|
1118
|
+
callerAgentId?: string;
|
|
1119
|
+
} = {},
|
|
1120
|
+
): Promise<Record<string, unknown> | null> {
|
|
1121
|
+
const effPolicy = normalizeRedactPolicy(
|
|
1122
|
+
options.redact_policy ?? options.redactPolicy ?? this.redactPolicy,
|
|
1123
|
+
);
|
|
1124
|
+
const effScope = options.redact_scope ?? options.redactScope ?? this.redactScope;
|
|
1125
|
+
const headers = this.applyLifecycleDefaults(undefined, {
|
|
1126
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
1127
|
+
});
|
|
585
1128
|
try {
|
|
586
|
-
return await this.request("GET", `/v1/memories/${encodeURIComponent(memoryId)}
|
|
1129
|
+
return await this.request("GET", `/v1/memories/${encodeURIComponent(memoryId)}`, {
|
|
1130
|
+
params: {
|
|
1131
|
+
redact_policy: Array.isArray(effPolicy) ? effPolicy.join(",") : (effPolicy ?? undefined),
|
|
1132
|
+
redact_scope: effScope ?? undefined,
|
|
1133
|
+
},
|
|
1134
|
+
headers,
|
|
1135
|
+
});
|
|
587
1136
|
} catch (err) {
|
|
588
1137
|
if (err instanceof SlashMLAPIError && err.statusCode === 404) {
|
|
589
1138
|
return null;
|
|
@@ -594,22 +1143,65 @@ export class MemoryClient {
|
|
|
594
1143
|
|
|
595
1144
|
public async update(
|
|
596
1145
|
memoryId: string,
|
|
597
|
-
data:
|
|
1146
|
+
data:
|
|
1147
|
+
| string
|
|
1148
|
+
| {
|
|
1149
|
+
text?: string;
|
|
1150
|
+
metadata?: Record<string, unknown>;
|
|
1151
|
+
redact_policy?: RedactPolicy;
|
|
1152
|
+
redactPolicy?: RedactPolicy;
|
|
1153
|
+
redact_scope?: RedactScope;
|
|
1154
|
+
redactScope?: RedactScope;
|
|
1155
|
+
caller_agent_id?: string;
|
|
1156
|
+
callerAgentId?: string;
|
|
1157
|
+
},
|
|
1158
|
+
options: {
|
|
1159
|
+
redact_policy?: RedactPolicy;
|
|
1160
|
+
redactPolicy?: RedactPolicy;
|
|
1161
|
+
redact_scope?: RedactScope;
|
|
1162
|
+
redactScope?: RedactScope;
|
|
1163
|
+
caller_agent_id?: string;
|
|
1164
|
+
callerAgentId?: string;
|
|
1165
|
+
} = {},
|
|
598
1166
|
): Promise<Record<string, unknown>> {
|
|
599
|
-
const
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
1167
|
+
const isStr = typeof data === "string";
|
|
1168
|
+
const body: Record<string, unknown> = isStr
|
|
1169
|
+
? { text: data }
|
|
1170
|
+
: { text: data.text ?? "", metadata: data.metadata };
|
|
1171
|
+
const headers = this.applyLifecycleDefaults(body, {
|
|
1172
|
+
redactPolicy:
|
|
1173
|
+
options.redact_policy ??
|
|
1174
|
+
options.redactPolicy ??
|
|
1175
|
+
(!isStr ? (data.redact_policy ?? data.redactPolicy) : undefined),
|
|
1176
|
+
redactScope:
|
|
1177
|
+
options.redact_scope ??
|
|
1178
|
+
options.redactScope ??
|
|
1179
|
+
(!isStr ? (data.redact_scope ?? data.redactScope) : undefined),
|
|
1180
|
+
callerAgentId:
|
|
1181
|
+
options.caller_agent_id ??
|
|
1182
|
+
options.callerAgentId ??
|
|
1183
|
+
(!isStr ? (data.caller_agent_id ?? data.callerAgentId) : undefined),
|
|
1184
|
+
});
|
|
603
1185
|
return this.request("PUT", `/v1/memories/${encodeURIComponent(memoryId)}`, {
|
|
604
1186
|
jsonBody: body,
|
|
1187
|
+
headers,
|
|
605
1188
|
});
|
|
606
1189
|
}
|
|
607
1190
|
|
|
608
|
-
public async delete(
|
|
609
|
-
|
|
1191
|
+
public async delete(
|
|
1192
|
+
memoryId: string,
|
|
1193
|
+
options: { caller_agent_id?: string; callerAgentId?: string } = {},
|
|
1194
|
+
): Promise<Record<string, unknown>> {
|
|
1195
|
+
const headers = this.applyLifecycleDefaults(undefined, {
|
|
1196
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
1197
|
+
});
|
|
1198
|
+
return this.request("DELETE", `/v1/memories/${encodeURIComponent(memoryId)}`, { headers });
|
|
610
1199
|
}
|
|
611
1200
|
|
|
612
1201
|
public async deleteAll(options: MemoryFilters = {}): Promise<Record<string, unknown>> {
|
|
1202
|
+
const headers = this.applyLifecycleDefaults(undefined, {
|
|
1203
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
1204
|
+
});
|
|
613
1205
|
return this.request("DELETE", "/v1/memories", {
|
|
614
1206
|
params: {
|
|
615
1207
|
user_id: options.user_id ?? options.userId ?? undefined,
|
|
@@ -617,6 +1209,7 @@ export class MemoryClient {
|
|
|
617
1209
|
app_id: options.app_id ?? options.appId ?? undefined,
|
|
618
1210
|
run_id: options.run_id ?? options.runId ?? undefined,
|
|
619
1211
|
},
|
|
1212
|
+
headers,
|
|
620
1213
|
});
|
|
621
1214
|
}
|
|
622
1215
|
|
|
@@ -645,42 +1238,76 @@ export class MemoryClient {
|
|
|
645
1238
|
return [];
|
|
646
1239
|
}
|
|
647
1240
|
|
|
648
|
-
public async batchUpdate(
|
|
1241
|
+
public async batchUpdate(
|
|
1242
|
+
memories: Array<Record<string, unknown>>,
|
|
1243
|
+
options: {
|
|
1244
|
+
redact_policy?: RedactPolicy;
|
|
1245
|
+
redactPolicy?: RedactPolicy;
|
|
1246
|
+
redact_scope?: RedactScope;
|
|
1247
|
+
redactScope?: RedactScope;
|
|
1248
|
+
caller_agent_id?: string;
|
|
1249
|
+
callerAgentId?: string;
|
|
1250
|
+
} = {},
|
|
1251
|
+
): Promise<Record<string, unknown>> {
|
|
649
1252
|
const normalized = memories.map((m) => ({
|
|
650
1253
|
...m,
|
|
651
1254
|
memory_id: m.memory_id ?? m.memoryId ?? m.id,
|
|
652
1255
|
}));
|
|
653
|
-
|
|
1256
|
+
const payload: Record<string, unknown> = { memories: normalized };
|
|
1257
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
1258
|
+
redactPolicy: options.redact_policy ?? options.redactPolicy,
|
|
1259
|
+
redactScope: options.redact_scope ?? options.redactScope,
|
|
1260
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
1261
|
+
});
|
|
1262
|
+
return this.request("PUT", "/v1/batch", { jsonBody: payload, headers });
|
|
654
1263
|
}
|
|
655
1264
|
|
|
656
|
-
public async batch_update(
|
|
657
|
-
|
|
1265
|
+
public async batch_update(
|
|
1266
|
+
memories: Array<Record<string, unknown>>,
|
|
1267
|
+
options: {
|
|
1268
|
+
redact_policy?: RedactPolicy;
|
|
1269
|
+
redactPolicy?: RedactPolicy;
|
|
1270
|
+
redact_scope?: RedactScope;
|
|
1271
|
+
redactScope?: RedactScope;
|
|
1272
|
+
caller_agent_id?: string;
|
|
1273
|
+
callerAgentId?: string;
|
|
1274
|
+
} = {},
|
|
1275
|
+
): Promise<Record<string, unknown>> {
|
|
1276
|
+
return this.batchUpdate(memories, options);
|
|
658
1277
|
}
|
|
659
1278
|
|
|
660
1279
|
public async batchDelete(
|
|
661
1280
|
memories: Array<string | Record<string, unknown>>,
|
|
1281
|
+
options: { caller_agent_id?: string; callerAgentId?: string } = {},
|
|
662
1282
|
): Promise<Record<string, unknown>> {
|
|
663
1283
|
const normalized = memories.map((m) =>
|
|
664
1284
|
typeof m === "string"
|
|
665
1285
|
? { memory_id: m, id: m }
|
|
666
1286
|
: { ...m, memory_id: m.memory_id ?? m.memoryId ?? m.id },
|
|
667
1287
|
);
|
|
668
|
-
|
|
1288
|
+
const payload: Record<string, unknown> = { memories: normalized };
|
|
1289
|
+
const headers = this.applyLifecycleDefaults(payload, {
|
|
1290
|
+
callerAgentId: options.caller_agent_id ?? options.callerAgentId,
|
|
1291
|
+
});
|
|
1292
|
+
return this.request("DELETE", "/v1/batch", { jsonBody: payload, headers });
|
|
669
1293
|
}
|
|
670
1294
|
|
|
671
1295
|
public async batch_delete(
|
|
672
1296
|
memories: Array<string | Record<string, unknown>>,
|
|
1297
|
+
options: { caller_agent_id?: string; callerAgentId?: string } = {},
|
|
673
1298
|
): Promise<Record<string, unknown>> {
|
|
674
|
-
return this.batchDelete(memories);
|
|
1299
|
+
return this.batchDelete(memories, options);
|
|
675
1300
|
}
|
|
676
1301
|
|
|
677
1302
|
public async users(): Promise<Record<string, unknown>> {
|
|
678
|
-
return
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
1303
|
+
return wrapResults(
|
|
1304
|
+
await this.request<unknown>("GET", "/v1/entities", {
|
|
1305
|
+
params: {
|
|
1306
|
+
org_id: this.orgId ?? undefined,
|
|
1307
|
+
project_id: this.projectId ?? undefined,
|
|
1308
|
+
},
|
|
1309
|
+
}),
|
|
1310
|
+
);
|
|
684
1311
|
}
|
|
685
1312
|
|
|
686
1313
|
public async deleteUsers(options: MemoryFilters = {}): Promise<Record<string, unknown>> {
|
|
@@ -740,9 +1367,11 @@ export class MemoryClient {
|
|
|
740
1367
|
}
|
|
741
1368
|
|
|
742
1369
|
public async getWebhooks(projectId?: string): Promise<Record<string, unknown>> {
|
|
743
|
-
return
|
|
744
|
-
|
|
745
|
-
|
|
1370
|
+
return wrapResults(
|
|
1371
|
+
await this.request<unknown>("GET", "/v1/webhooks", {
|
|
1372
|
+
params: { project_id: projectId ?? this.projectId ?? undefined },
|
|
1373
|
+
}),
|
|
1374
|
+
);
|
|
746
1375
|
}
|
|
747
1376
|
|
|
748
1377
|
public async get_webhooks(projectId?: string): Promise<Record<string, unknown>> {
|
|
@@ -878,6 +1507,15 @@ export class Memory extends MemoryClient {
|
|
|
878
1507
|
(configDict.host as string),
|
|
879
1508
|
orgId: (configDict.org_id as string) || (configDict.orgId as string),
|
|
880
1509
|
projectId: (configDict.project_id as string) || (configDict.projectId as string),
|
|
1510
|
+
agentId:
|
|
1511
|
+
(configDict.agent_id as string) ||
|
|
1512
|
+
(configDict.agentId as string) ||
|
|
1513
|
+
(configDict.caller_agent_id as string) ||
|
|
1514
|
+
(configDict.callerAgentId as string),
|
|
1515
|
+
redactPolicy:
|
|
1516
|
+
(configDict.redact_policy as RedactPolicy) || (configDict.redactPolicy as RedactPolicy),
|
|
1517
|
+
redactScope:
|
|
1518
|
+
(configDict.redact_scope as RedactScope) || (configDict.redactScope as RedactScope),
|
|
881
1519
|
model: configDict.model as string,
|
|
882
1520
|
timeoutMs: configDict.timeoutMs as number,
|
|
883
1521
|
}) as InstanceType<T>;
|