@z3rno/sdk 0.0.1 → 0.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 +3 -1
- package/dist/index.cjs +558 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +921 -4
- package/dist/index.d.ts +921 -4
- package/dist/index.js +552 -25
- package/dist/index.js.map +1 -1
- package/package.json +17 -4
package/dist/index.d.cts
CHANGED
|
@@ -2,22 +2,74 @@ import { z } from 'zod';
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Zod schemas and inferred TypeScript types for the Z3rno API.
|
|
5
|
+
*
|
|
6
|
+
* Each export is a dual: a Zod schema (used for runtime validation) and an
|
|
7
|
+
* identically-named TypeScript type (used at compile time). Request schemas
|
|
8
|
+
* validate client-side input; response schemas validate server payloads.
|
|
9
|
+
*
|
|
10
|
+
* @module models
|
|
5
11
|
*/
|
|
6
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Memory type enum.
|
|
15
|
+
*
|
|
16
|
+
* Controls how a memory is stored, indexed, and decayed.
|
|
17
|
+
*
|
|
18
|
+
* - `working` — Short-lived scratchpad memory (high decay rate).
|
|
19
|
+
* - `episodic` — Event-based memory tied to a specific interaction.
|
|
20
|
+
* - `semantic` — Long-term factual knowledge.
|
|
21
|
+
* - `procedural` — How-to or process knowledge.
|
|
22
|
+
*/
|
|
7
23
|
declare const MemoryType: z.ZodEnum<["working", "episodic", "semantic", "procedural"]>;
|
|
24
|
+
/** Memory type: `"working"` | `"episodic"` | `"semantic"` | `"procedural"`. */
|
|
8
25
|
type MemoryType = z.infer<typeof MemoryType>;
|
|
26
|
+
/**
|
|
27
|
+
* Relationship type enum.
|
|
28
|
+
*
|
|
29
|
+
* Describes how two memories are related in the knowledge graph.
|
|
30
|
+
*
|
|
31
|
+
* - `derived_from` — This memory was created from another.
|
|
32
|
+
* - `contradicts` — This memory conflicts with another.
|
|
33
|
+
* - `supports` — This memory reinforces another.
|
|
34
|
+
* - `supersedes` — This memory replaces another.
|
|
35
|
+
* - `related_to` — General association.
|
|
36
|
+
* - `caused_by` — Causal relationship.
|
|
37
|
+
*/
|
|
9
38
|
declare const RelationshipType: z.ZodEnum<["derived_from", "contradicts", "supports", "supersedes", "related_to", "caused_by"]>;
|
|
39
|
+
/** Relationship type between two memories. */
|
|
10
40
|
type RelationshipType = z.infer<typeof RelationshipType>;
|
|
41
|
+
/**
|
|
42
|
+
* Schema for storing a new memory.
|
|
43
|
+
*
|
|
44
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* const request = StoreMemoryRequest.parse({
|
|
47
|
+
* agentId: "550e8400-e29b-41d4-a716-446655440000",
|
|
48
|
+
* content: "User prefers dark mode",
|
|
49
|
+
* memoryType: "semantic",
|
|
50
|
+
* });
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
11
53
|
declare const StoreMemoryRequest: z.ZodObject<{
|
|
54
|
+
/** UUID of the agent that owns this memory. */
|
|
12
55
|
agentId: z.ZodString;
|
|
56
|
+
/** The text content to store (1 to 100,000 characters). */
|
|
13
57
|
content: z.ZodString;
|
|
58
|
+
/** Category of memory. Defaults to `"episodic"`. */
|
|
14
59
|
memoryType: z.ZodDefault<z.ZodEnum<["working", "episodic", "semantic", "procedural"]>>;
|
|
60
|
+
/** Optional UUID of the user associated with this memory. */
|
|
15
61
|
userId: z.ZodOptional<z.ZodString>;
|
|
62
|
+
/** Arbitrary key-value metadata attached to the memory. */
|
|
16
63
|
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
64
|
+
/** Relationships to other memories in the knowledge graph. */
|
|
17
65
|
relationships: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
66
|
+
/** UUID of the target memory. */
|
|
18
67
|
targetMemoryId: z.ZodString;
|
|
68
|
+
/** Type of relationship to the target memory. */
|
|
19
69
|
relationshipType: z.ZodEnum<["derived_from", "contradicts", "supports", "supersedes", "related_to", "caused_by"]>;
|
|
70
|
+
/** Relationship strength from 0 to 1. Defaults to 1.0. */
|
|
20
71
|
weight: z.ZodDefault<z.ZodNumber>;
|
|
72
|
+
/** Arbitrary metadata for the relationship edge. */
|
|
21
73
|
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
22
74
|
}, "strip", z.ZodTypeAny, {
|
|
23
75
|
metadata: Record<string, unknown>;
|
|
@@ -30,7 +82,9 @@ declare const StoreMemoryRequest: z.ZodObject<{
|
|
|
30
82
|
metadata?: Record<string, unknown> | undefined;
|
|
31
83
|
weight?: number | undefined;
|
|
32
84
|
}>, "many">>;
|
|
85
|
+
/** Time-to-live in seconds. Memory auto-deletes after this duration. */
|
|
33
86
|
ttlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
87
|
+
/** Importance score from 0 to 1. Influences recall ranking. */
|
|
34
88
|
importance: z.ZodOptional<z.ZodNumber>;
|
|
35
89
|
}, "strip", z.ZodTypeAny, {
|
|
36
90
|
agentId: string;
|
|
@@ -61,16 +115,32 @@ declare const StoreMemoryRequest: z.ZodObject<{
|
|
|
61
115
|
ttlSeconds?: number | undefined;
|
|
62
116
|
importance?: number | undefined;
|
|
63
117
|
}>;
|
|
118
|
+
/** Parsed type for a store-memory request. */
|
|
64
119
|
type StoreMemoryRequest = z.infer<typeof StoreMemoryRequest>;
|
|
120
|
+
/**
|
|
121
|
+
* Schema for a single memory object returned by the API.
|
|
122
|
+
*
|
|
123
|
+
* Used by {@link Z3rnoClient.store}, {@link Z3rnoClient.getMemory}, and
|
|
124
|
+
* {@link Z3rnoClient.updateMemory}.
|
|
125
|
+
*/
|
|
65
126
|
declare const MemoryResponse: z.ZodObject<{
|
|
127
|
+
/** Unique identifier for this memory. */
|
|
66
128
|
id: z.ZodString;
|
|
129
|
+
/** UUID of the owning agent. */
|
|
67
130
|
agent_id: z.ZodString;
|
|
131
|
+
/** Text content of the memory. */
|
|
68
132
|
content: z.ZodString;
|
|
133
|
+
/** Category of the memory. */
|
|
69
134
|
memory_type: z.ZodString;
|
|
135
|
+
/** Server-computed importance score (0-1). */
|
|
70
136
|
importance_score: z.ZodNumber;
|
|
137
|
+
/** Number of times this memory has been recalled. */
|
|
71
138
|
recall_count: z.ZodNumber;
|
|
139
|
+
/** Name of the embedding model used, if any. */
|
|
72
140
|
embedding_model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
141
|
+
/** ISO 8601 creation timestamp. */
|
|
73
142
|
created_at: z.ZodString;
|
|
143
|
+
/** Arbitrary metadata attached to the memory. */
|
|
74
144
|
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
75
145
|
}, "strip", z.ZodTypeAny, {
|
|
76
146
|
content: string;
|
|
@@ -93,17 +163,34 @@ declare const MemoryResponse: z.ZodObject<{
|
|
|
93
163
|
metadata?: Record<string, unknown> | undefined;
|
|
94
164
|
embedding_model?: string | null | undefined;
|
|
95
165
|
}>;
|
|
166
|
+
/** Parsed type for a memory response. */
|
|
96
167
|
type MemoryResponse = z.infer<typeof MemoryResponse>;
|
|
168
|
+
/**
|
|
169
|
+
* Schema for a single item in recall results.
|
|
170
|
+
*
|
|
171
|
+
* Each item includes similarity, importance, and relevance scores
|
|
172
|
+
* computed by the server's ranking algorithm.
|
|
173
|
+
*/
|
|
97
174
|
declare const RecallResultItem: z.ZodObject<{
|
|
175
|
+
/** Unique identifier of the recalled memory. */
|
|
98
176
|
memory_id: z.ZodString;
|
|
177
|
+
/** Text content of the memory. */
|
|
99
178
|
content: z.ZodString;
|
|
179
|
+
/** Optional server-generated summary. */
|
|
100
180
|
summary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
181
|
+
/** Category of the memory. */
|
|
101
182
|
memory_type: z.ZodString;
|
|
183
|
+
/** Cosine similarity to the query (0-1). */
|
|
102
184
|
similarity_score: z.ZodNumber;
|
|
185
|
+
/** Server-computed importance score (0-1). */
|
|
103
186
|
importance_score: z.ZodNumber;
|
|
187
|
+
/** Combined relevance score used for ranking (0-1). */
|
|
104
188
|
relevance_score: z.ZodNumber;
|
|
189
|
+
/** Number of times this memory has been recalled. */
|
|
105
190
|
recall_count: z.ZodNumber;
|
|
191
|
+
/** ISO 8601 creation timestamp. */
|
|
106
192
|
created_at: z.ZodString;
|
|
193
|
+
/** Arbitrary metadata attached to the memory. */
|
|
107
194
|
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
108
195
|
}, "strip", z.ZodTypeAny, {
|
|
109
196
|
content: string;
|
|
@@ -128,18 +215,35 @@ declare const RecallResultItem: z.ZodObject<{
|
|
|
128
215
|
metadata?: Record<string, unknown> | undefined;
|
|
129
216
|
summary?: string | null | undefined;
|
|
130
217
|
}>;
|
|
218
|
+
/** Parsed type for a single recall result item. */
|
|
131
219
|
type RecallResultItem = z.infer<typeof RecallResultItem>;
|
|
220
|
+
/**
|
|
221
|
+
* Schema for the full recall response.
|
|
222
|
+
*
|
|
223
|
+
* Contains an array of ranked results and the total count of matches.
|
|
224
|
+
*/
|
|
132
225
|
declare const RecallResponse: z.ZodObject<{
|
|
226
|
+
/** Ranked list of matching memories. */
|
|
133
227
|
results: z.ZodArray<z.ZodObject<{
|
|
228
|
+
/** Unique identifier of the recalled memory. */
|
|
134
229
|
memory_id: z.ZodString;
|
|
230
|
+
/** Text content of the memory. */
|
|
135
231
|
content: z.ZodString;
|
|
232
|
+
/** Optional server-generated summary. */
|
|
136
233
|
summary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
234
|
+
/** Category of the memory. */
|
|
137
235
|
memory_type: z.ZodString;
|
|
236
|
+
/** Cosine similarity to the query (0-1). */
|
|
138
237
|
similarity_score: z.ZodNumber;
|
|
238
|
+
/** Server-computed importance score (0-1). */
|
|
139
239
|
importance_score: z.ZodNumber;
|
|
240
|
+
/** Combined relevance score used for ranking (0-1). */
|
|
140
241
|
relevance_score: z.ZodNumber;
|
|
242
|
+
/** Number of times this memory has been recalled. */
|
|
141
243
|
recall_count: z.ZodNumber;
|
|
244
|
+
/** ISO 8601 creation timestamp. */
|
|
142
245
|
created_at: z.ZodString;
|
|
246
|
+
/** Arbitrary metadata attached to the memory. */
|
|
143
247
|
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
144
248
|
}, "strip", z.ZodTypeAny, {
|
|
145
249
|
content: string;
|
|
@@ -164,7 +268,9 @@ declare const RecallResponse: z.ZodObject<{
|
|
|
164
268
|
metadata?: Record<string, unknown> | undefined;
|
|
165
269
|
summary?: string | null | undefined;
|
|
166
270
|
}>, "many">;
|
|
271
|
+
/** Total number of matches (may exceed `topK`). */
|
|
167
272
|
total: z.ZodNumber;
|
|
273
|
+
/** The query that was searched, if any. */
|
|
168
274
|
query: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
169
275
|
}, "strip", z.ZodTypeAny, {
|
|
170
276
|
results: {
|
|
@@ -197,11 +303,21 @@ declare const RecallResponse: z.ZodObject<{
|
|
|
197
303
|
total: number;
|
|
198
304
|
query?: string | null | undefined;
|
|
199
305
|
}>;
|
|
306
|
+
/** Parsed type for a recall response. */
|
|
200
307
|
type RecallResponse = z.infer<typeof RecallResponse>;
|
|
308
|
+
/**
|
|
309
|
+
* Schema for the forget (delete) response.
|
|
310
|
+
*
|
|
311
|
+
* Reports how many memories were deleted and whether cascade was applied.
|
|
312
|
+
*/
|
|
201
313
|
declare const ForgetResponse: z.ZodObject<{
|
|
314
|
+
/** Number of memories deleted. */
|
|
202
315
|
deleted_count: z.ZodNumber;
|
|
316
|
+
/** Whether a hard delete was performed. */
|
|
203
317
|
hard_deleted: z.ZodBoolean;
|
|
318
|
+
/** Number of related memories deleted via cascade. */
|
|
204
319
|
cascade_count: z.ZodNumber;
|
|
320
|
+
/** IDs of all deleted memories. */
|
|
205
321
|
memory_ids: z.ZodArray<z.ZodString, "many">;
|
|
206
322
|
}, "strip", z.ZodTypeAny, {
|
|
207
323
|
deleted_count: number;
|
|
@@ -214,16 +330,31 @@ declare const ForgetResponse: z.ZodObject<{
|
|
|
214
330
|
cascade_count: number;
|
|
215
331
|
memory_ids: string[];
|
|
216
332
|
}>;
|
|
333
|
+
/** Parsed type for a forget response. */
|
|
217
334
|
type ForgetResponse = z.infer<typeof ForgetResponse>;
|
|
335
|
+
/**
|
|
336
|
+
* Schema for a single audit log entry.
|
|
337
|
+
*
|
|
338
|
+
* Audit entries record every operation performed on the agent's memories.
|
|
339
|
+
*/
|
|
218
340
|
declare const AuditEntry: z.ZodObject<{
|
|
341
|
+
/** Auto-incrementing audit entry ID. */
|
|
219
342
|
id: z.ZodNumber;
|
|
343
|
+
/** UUID of the agent, if applicable. */
|
|
220
344
|
agent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
345
|
+
/** UUID of the user, if applicable. */
|
|
221
346
|
user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
347
|
+
/** Operation type (e.g., `"store"`, `"recall"`, `"forget"`). */
|
|
222
348
|
operation: z.ZodString;
|
|
349
|
+
/** UUID of the affected memory, if applicable. */
|
|
223
350
|
memory_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
351
|
+
/** Memory type of the affected memory, if applicable. */
|
|
224
352
|
memory_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
353
|
+
/** Additional details about the operation. */
|
|
225
354
|
details: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
355
|
+
/** IP address of the caller, if available. */
|
|
226
356
|
ip_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
357
|
+
/** ISO 8601 timestamp of the operation. */
|
|
227
358
|
created_at: z.ZodString;
|
|
228
359
|
}, "strip", z.ZodTypeAny, {
|
|
229
360
|
id: number;
|
|
@@ -246,17 +377,33 @@ declare const AuditEntry: z.ZodObject<{
|
|
|
246
377
|
details?: Record<string, unknown> | undefined;
|
|
247
378
|
ip_address?: string | null | undefined;
|
|
248
379
|
}>;
|
|
380
|
+
/** Parsed type for an audit entry. */
|
|
249
381
|
type AuditEntry = z.infer<typeof AuditEntry>;
|
|
382
|
+
/**
|
|
383
|
+
* Schema for a paginated audit log response.
|
|
384
|
+
*
|
|
385
|
+
* Supports cursor-based pagination via `page` and `page_size`.
|
|
386
|
+
*/
|
|
250
387
|
declare const AuditPageResponse: z.ZodObject<{
|
|
388
|
+
/** Audit entries on this page. */
|
|
251
389
|
entries: z.ZodArray<z.ZodObject<{
|
|
390
|
+
/** Auto-incrementing audit entry ID. */
|
|
252
391
|
id: z.ZodNumber;
|
|
392
|
+
/** UUID of the agent, if applicable. */
|
|
253
393
|
agent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
394
|
+
/** UUID of the user, if applicable. */
|
|
254
395
|
user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
396
|
+
/** Operation type (e.g., `"store"`, `"recall"`, `"forget"`). */
|
|
255
397
|
operation: z.ZodString;
|
|
398
|
+
/** UUID of the affected memory, if applicable. */
|
|
256
399
|
memory_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
400
|
+
/** Memory type of the affected memory, if applicable. */
|
|
257
401
|
memory_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
402
|
+
/** Additional details about the operation. */
|
|
258
403
|
details: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
404
|
+
/** IP address of the caller, if available. */
|
|
259
405
|
ip_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
406
|
+
/** ISO 8601 timestamp of the operation. */
|
|
260
407
|
created_at: z.ZodString;
|
|
261
408
|
}, "strip", z.ZodTypeAny, {
|
|
262
409
|
id: number;
|
|
@@ -279,9 +426,13 @@ declare const AuditPageResponse: z.ZodObject<{
|
|
|
279
426
|
details?: Record<string, unknown> | undefined;
|
|
280
427
|
ip_address?: string | null | undefined;
|
|
281
428
|
}>, "many">;
|
|
429
|
+
/** Total number of matching audit entries. */
|
|
282
430
|
total: z.ZodNumber;
|
|
431
|
+
/** Current page number (1-indexed). */
|
|
283
432
|
page: z.ZodNumber;
|
|
433
|
+
/** Number of entries per page. */
|
|
284
434
|
page_size: z.ZodNumber;
|
|
435
|
+
/** Whether more pages are available. */
|
|
285
436
|
has_next: z.ZodBoolean;
|
|
286
437
|
}, "strip", z.ZodTypeAny, {
|
|
287
438
|
entries: {
|
|
@@ -316,12 +467,262 @@ declare const AuditPageResponse: z.ZodObject<{
|
|
|
316
467
|
page_size: number;
|
|
317
468
|
has_next: boolean;
|
|
318
469
|
}>;
|
|
470
|
+
/** Parsed type for a paginated audit response. */
|
|
319
471
|
type AuditPageResponse = z.infer<typeof AuditPageResponse>;
|
|
472
|
+
/**
|
|
473
|
+
* Schema for the batch store response.
|
|
474
|
+
*
|
|
475
|
+
* Returned by {@link Z3rnoClient.storeBatch} after storing multiple memories.
|
|
476
|
+
*/
|
|
477
|
+
declare const BatchStoreResponse: z.ZodObject<{
|
|
478
|
+
/** Array of stored memory objects. */
|
|
479
|
+
results: z.ZodArray<z.ZodObject<{
|
|
480
|
+
/** Unique identifier for this memory. */
|
|
481
|
+
id: z.ZodString;
|
|
482
|
+
/** UUID of the owning agent. */
|
|
483
|
+
agent_id: z.ZodString;
|
|
484
|
+
/** Text content of the memory. */
|
|
485
|
+
content: z.ZodString;
|
|
486
|
+
/** Category of the memory. */
|
|
487
|
+
memory_type: z.ZodString;
|
|
488
|
+
/** Server-computed importance score (0-1). */
|
|
489
|
+
importance_score: z.ZodNumber;
|
|
490
|
+
/** Number of times this memory has been recalled. */
|
|
491
|
+
recall_count: z.ZodNumber;
|
|
492
|
+
/** Name of the embedding model used, if any. */
|
|
493
|
+
embedding_model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
494
|
+
/** ISO 8601 creation timestamp. */
|
|
495
|
+
created_at: z.ZodString;
|
|
496
|
+
/** Arbitrary metadata attached to the memory. */
|
|
497
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
498
|
+
}, "strip", z.ZodTypeAny, {
|
|
499
|
+
content: string;
|
|
500
|
+
metadata: Record<string, unknown>;
|
|
501
|
+
id: string;
|
|
502
|
+
agent_id: string;
|
|
503
|
+
memory_type: string;
|
|
504
|
+
importance_score: number;
|
|
505
|
+
recall_count: number;
|
|
506
|
+
created_at: string;
|
|
507
|
+
embedding_model?: string | null | undefined;
|
|
508
|
+
}, {
|
|
509
|
+
content: string;
|
|
510
|
+
id: string;
|
|
511
|
+
agent_id: string;
|
|
512
|
+
memory_type: string;
|
|
513
|
+
importance_score: number;
|
|
514
|
+
recall_count: number;
|
|
515
|
+
created_at: string;
|
|
516
|
+
metadata?: Record<string, unknown> | undefined;
|
|
517
|
+
embedding_model?: string | null | undefined;
|
|
518
|
+
}>, "many">;
|
|
519
|
+
/** Number of memories successfully stored. */
|
|
520
|
+
stored_count: z.ZodNumber;
|
|
521
|
+
}, "strip", z.ZodTypeAny, {
|
|
522
|
+
results: {
|
|
523
|
+
content: string;
|
|
524
|
+
metadata: Record<string, unknown>;
|
|
525
|
+
id: string;
|
|
526
|
+
agent_id: string;
|
|
527
|
+
memory_type: string;
|
|
528
|
+
importance_score: number;
|
|
529
|
+
recall_count: number;
|
|
530
|
+
created_at: string;
|
|
531
|
+
embedding_model?: string | null | undefined;
|
|
532
|
+
}[];
|
|
533
|
+
stored_count: number;
|
|
534
|
+
}, {
|
|
535
|
+
results: {
|
|
536
|
+
content: string;
|
|
537
|
+
id: string;
|
|
538
|
+
agent_id: string;
|
|
539
|
+
memory_type: string;
|
|
540
|
+
importance_score: number;
|
|
541
|
+
recall_count: number;
|
|
542
|
+
created_at: string;
|
|
543
|
+
metadata?: Record<string, unknown> | undefined;
|
|
544
|
+
embedding_model?: string | null | undefined;
|
|
545
|
+
}[];
|
|
546
|
+
stored_count: number;
|
|
547
|
+
}>;
|
|
548
|
+
/** Parsed type for a batch store response. */
|
|
549
|
+
type BatchStoreResponse = z.infer<typeof BatchStoreResponse>;
|
|
550
|
+
/**
|
|
551
|
+
* Schema for a single version of a memory (temporal versioning).
|
|
552
|
+
*
|
|
553
|
+
* Each version represents the state of a memory during a specific time range.
|
|
554
|
+
*/
|
|
555
|
+
declare const MemoryVersion: z.ZodObject<{
|
|
556
|
+
/** Version identifier. */
|
|
557
|
+
id: z.ZodString;
|
|
558
|
+
/** Text content at this version. */
|
|
559
|
+
content: z.ZodString;
|
|
560
|
+
/** Memory type at this version. */
|
|
561
|
+
memory_type: z.ZodString;
|
|
562
|
+
/** Importance score at this version. */
|
|
563
|
+
importance_score: z.ZodNumber;
|
|
564
|
+
/** ISO 8601 timestamp when this version became active. */
|
|
565
|
+
valid_from: z.ZodString;
|
|
566
|
+
/** ISO 8601 timestamp when this version was superseded, or null if current. */
|
|
567
|
+
valid_to: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
568
|
+
/** Metadata at this version. */
|
|
569
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
570
|
+
}, "strip", z.ZodTypeAny, {
|
|
571
|
+
content: string;
|
|
572
|
+
metadata: Record<string, unknown>;
|
|
573
|
+
id: string;
|
|
574
|
+
memory_type: string;
|
|
575
|
+
importance_score: number;
|
|
576
|
+
valid_from: string;
|
|
577
|
+
valid_to?: string | null | undefined;
|
|
578
|
+
}, {
|
|
579
|
+
content: string;
|
|
580
|
+
id: string;
|
|
581
|
+
memory_type: string;
|
|
582
|
+
importance_score: number;
|
|
583
|
+
valid_from: string;
|
|
584
|
+
metadata?: Record<string, unknown> | undefined;
|
|
585
|
+
valid_to?: string | null | undefined;
|
|
586
|
+
}>;
|
|
587
|
+
/** Parsed type for a memory version. */
|
|
588
|
+
type MemoryVersion = z.infer<typeof MemoryVersion>;
|
|
589
|
+
/**
|
|
590
|
+
* Schema for the memory history response.
|
|
591
|
+
*
|
|
592
|
+
* Contains all temporal versions of a single memory, ordered chronologically.
|
|
593
|
+
*/
|
|
594
|
+
declare const MemoryHistoryResponse: z.ZodObject<{
|
|
595
|
+
/** UUID of the memory. */
|
|
596
|
+
memory_id: z.ZodString;
|
|
597
|
+
/** Chronologically ordered list of versions. */
|
|
598
|
+
versions: z.ZodArray<z.ZodObject<{
|
|
599
|
+
/** Version identifier. */
|
|
600
|
+
id: z.ZodString;
|
|
601
|
+
/** Text content at this version. */
|
|
602
|
+
content: z.ZodString;
|
|
603
|
+
/** Memory type at this version. */
|
|
604
|
+
memory_type: z.ZodString;
|
|
605
|
+
/** Importance score at this version. */
|
|
606
|
+
importance_score: z.ZodNumber;
|
|
607
|
+
/** ISO 8601 timestamp when this version became active. */
|
|
608
|
+
valid_from: z.ZodString;
|
|
609
|
+
/** ISO 8601 timestamp when this version was superseded, or null if current. */
|
|
610
|
+
valid_to: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
611
|
+
/** Metadata at this version. */
|
|
612
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
613
|
+
}, "strip", z.ZodTypeAny, {
|
|
614
|
+
content: string;
|
|
615
|
+
metadata: Record<string, unknown>;
|
|
616
|
+
id: string;
|
|
617
|
+
memory_type: string;
|
|
618
|
+
importance_score: number;
|
|
619
|
+
valid_from: string;
|
|
620
|
+
valid_to?: string | null | undefined;
|
|
621
|
+
}, {
|
|
622
|
+
content: string;
|
|
623
|
+
id: string;
|
|
624
|
+
memory_type: string;
|
|
625
|
+
importance_score: number;
|
|
626
|
+
valid_from: string;
|
|
627
|
+
metadata?: Record<string, unknown> | undefined;
|
|
628
|
+
valid_to?: string | null | undefined;
|
|
629
|
+
}>, "many">;
|
|
630
|
+
/** Total number of versions. */
|
|
631
|
+
total: z.ZodNumber;
|
|
632
|
+
}, "strip", z.ZodTypeAny, {
|
|
633
|
+
memory_id: string;
|
|
634
|
+
total: number;
|
|
635
|
+
versions: {
|
|
636
|
+
content: string;
|
|
637
|
+
metadata: Record<string, unknown>;
|
|
638
|
+
id: string;
|
|
639
|
+
memory_type: string;
|
|
640
|
+
importance_score: number;
|
|
641
|
+
valid_from: string;
|
|
642
|
+
valid_to?: string | null | undefined;
|
|
643
|
+
}[];
|
|
644
|
+
}, {
|
|
645
|
+
memory_id: string;
|
|
646
|
+
total: number;
|
|
647
|
+
versions: {
|
|
648
|
+
content: string;
|
|
649
|
+
id: string;
|
|
650
|
+
memory_type: string;
|
|
651
|
+
importance_score: number;
|
|
652
|
+
valid_from: string;
|
|
653
|
+
metadata?: Record<string, unknown> | undefined;
|
|
654
|
+
valid_to?: string | null | undefined;
|
|
655
|
+
}[];
|
|
656
|
+
}>;
|
|
657
|
+
/** Parsed type for a memory history response. */
|
|
658
|
+
type MemoryHistoryResponse = z.infer<typeof MemoryHistoryResponse>;
|
|
659
|
+
/**
|
|
660
|
+
* Schema for a session response.
|
|
661
|
+
*
|
|
662
|
+
* Sessions group related memory operations (e.g., a conversation turn).
|
|
663
|
+
*/
|
|
664
|
+
declare const SessionResponse: z.ZodObject<{
|
|
665
|
+
/** Unique session identifier. */
|
|
666
|
+
session_id: z.ZodString;
|
|
667
|
+
/** UUID of the agent this session belongs to. */
|
|
668
|
+
agent_id: z.ZodString;
|
|
669
|
+
/** Type of session (e.g., `"conversation"`). */
|
|
670
|
+
session_type: z.ZodString;
|
|
671
|
+
/** ISO 8601 timestamp when the session started. */
|
|
672
|
+
started_at: z.ZodString;
|
|
673
|
+
/** Arbitrary session metadata. */
|
|
674
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
675
|
+
}, "strip", z.ZodTypeAny, {
|
|
676
|
+
metadata: Record<string, unknown>;
|
|
677
|
+
agent_id: string;
|
|
678
|
+
session_id: string;
|
|
679
|
+
session_type: string;
|
|
680
|
+
started_at: string;
|
|
681
|
+
}, {
|
|
682
|
+
agent_id: string;
|
|
683
|
+
session_id: string;
|
|
684
|
+
session_type: string;
|
|
685
|
+
started_at: string;
|
|
686
|
+
metadata?: Record<string, unknown> | undefined;
|
|
687
|
+
}>;
|
|
688
|
+
/** Parsed type for a session response. */
|
|
689
|
+
type SessionResponse = z.infer<typeof SessionResponse>;
|
|
690
|
+
/**
|
|
691
|
+
* Schema for the end-session response.
|
|
692
|
+
*
|
|
693
|
+
* Returned when a session is closed, including summary statistics.
|
|
694
|
+
*/
|
|
695
|
+
declare const EndSessionResponse: z.ZodObject<{
|
|
696
|
+
/** The session that was ended. */
|
|
697
|
+
session_id: z.ZodString;
|
|
698
|
+
/** ISO 8601 timestamp when the session ended. */
|
|
699
|
+
ended_at: z.ZodString;
|
|
700
|
+
/** Total duration of the session in seconds. */
|
|
701
|
+
duration_seconds: z.ZodNumber;
|
|
702
|
+
/** Number of memories created during the session. */
|
|
703
|
+
memory_count: z.ZodNumber;
|
|
704
|
+
}, "strip", z.ZodTypeAny, {
|
|
705
|
+
session_id: string;
|
|
706
|
+
ended_at: string;
|
|
707
|
+
duration_seconds: number;
|
|
708
|
+
memory_count: number;
|
|
709
|
+
}, {
|
|
710
|
+
session_id: string;
|
|
711
|
+
ended_at: string;
|
|
712
|
+
duration_seconds: number;
|
|
713
|
+
memory_count: number;
|
|
714
|
+
}>;
|
|
715
|
+
/** Parsed type for an end-session response. */
|
|
716
|
+
type EndSessionResponse = z.infer<typeof EndSessionResponse>;
|
|
320
717
|
|
|
321
718
|
/**
|
|
322
719
|
* Z3rno TypeScript SDK client.
|
|
323
720
|
*
|
|
324
721
|
* Thin fetch wrapper — no database drivers, no embedding providers.
|
|
722
|
+
* Works in Node.js 18+, Deno, Bun, and modern browsers (any runtime
|
|
723
|
+
* with a global `fetch` and `AbortController`).
|
|
724
|
+
*
|
|
725
|
+
* @module client
|
|
325
726
|
*
|
|
326
727
|
* @example
|
|
327
728
|
* ```ts
|
|
@@ -332,18 +733,176 @@ type AuditPageResponse = z.infer<typeof AuditPageResponse>;
|
|
|
332
733
|
* ```
|
|
333
734
|
*/
|
|
334
735
|
|
|
736
|
+
/**
|
|
737
|
+
* Configuration options for the {@link Z3rnoClient}.
|
|
738
|
+
*
|
|
739
|
+
* All fields are optional. When omitted, the client reads from environment
|
|
740
|
+
* variables (`Z3RNO_BASE_URL`, `Z3RNO_API_KEY`) or uses sensible defaults.
|
|
741
|
+
*/
|
|
335
742
|
interface Z3rnoClientConfig {
|
|
336
|
-
|
|
337
|
-
|
|
743
|
+
/**
|
|
744
|
+
* Base URL of the Z3rno API.
|
|
745
|
+
*
|
|
746
|
+
* Falls back to the `Z3RNO_BASE_URL` environment variable, then
|
|
747
|
+
* to `"https://api.z3rno.dev"`.
|
|
748
|
+
*/
|
|
749
|
+
baseUrl?: string;
|
|
750
|
+
/**
|
|
751
|
+
* API key for authentication.
|
|
752
|
+
*
|
|
753
|
+
* Falls back to the `Z3RNO_API_KEY` environment variable, then to
|
|
754
|
+
* an empty string (unauthenticated).
|
|
755
|
+
*/
|
|
756
|
+
apiKey?: string;
|
|
757
|
+
/**
|
|
758
|
+
* Request timeout in milliseconds.
|
|
759
|
+
*
|
|
760
|
+
* @defaultValue 30000 (30 seconds)
|
|
761
|
+
*/
|
|
338
762
|
timeout?: number;
|
|
763
|
+
/**
|
|
764
|
+
* Maximum number of retry attempts for retryable errors (5xx, 429,
|
|
765
|
+
* network failures, timeouts).
|
|
766
|
+
*
|
|
767
|
+
* @defaultValue 3
|
|
768
|
+
*/
|
|
339
769
|
maxRetries?: number;
|
|
770
|
+
/**
|
|
771
|
+
* Custom fetch implementation.
|
|
772
|
+
*
|
|
773
|
+
* Defaults to `globalThis.fetch`. Override to use `undici`, `node-fetch`,
|
|
774
|
+
* or a test double.
|
|
775
|
+
*
|
|
776
|
+
* @defaultValue globalThis.fetch
|
|
777
|
+
*/
|
|
778
|
+
fetch?: typeof globalThis.fetch;
|
|
779
|
+
/**
|
|
780
|
+
* Intercept outgoing requests before they are sent.
|
|
781
|
+
*
|
|
782
|
+
* Use this to add custom headers, log requests, or collect metrics.
|
|
783
|
+
* The callback receives the URL and the `RequestInit` and must return
|
|
784
|
+
* a (possibly modified) `RequestInit`.
|
|
785
|
+
*/
|
|
786
|
+
onRequest?: (url: string, init: RequestInit) => RequestInit;
|
|
787
|
+
/**
|
|
788
|
+
* Intercept responses before they are processed.
|
|
789
|
+
*
|
|
790
|
+
* Use this for logging, metrics, or response transformation.
|
|
791
|
+
* The callback receives the `Response` and must return a `Response`.
|
|
792
|
+
*/
|
|
793
|
+
onResponse?: (response: Response) => Response;
|
|
340
794
|
}
|
|
795
|
+
/**
|
|
796
|
+
* Client for the Z3rno AI agent memory API.
|
|
797
|
+
*
|
|
798
|
+
* Uses the standard Fetch API under the hood, making it compatible with
|
|
799
|
+
* Node.js 18+, Deno, Bun, and modern browsers. All responses are
|
|
800
|
+
* validated at runtime with Zod schemas.
|
|
801
|
+
*
|
|
802
|
+
* @example
|
|
803
|
+
* ```ts
|
|
804
|
+
* import { Z3rnoClient } from "@z3rno/sdk";
|
|
805
|
+
*
|
|
806
|
+
* const client = new Z3rnoClient({
|
|
807
|
+
* baseUrl: "http://localhost:8000",
|
|
808
|
+
* apiKey: "z3rno_sk_test_...",
|
|
809
|
+
* });
|
|
810
|
+
*
|
|
811
|
+
* // Store a memory
|
|
812
|
+
* const mem = await client.store({
|
|
813
|
+
* agentId: "550e8400-e29b-41d4-a716-446655440000",
|
|
814
|
+
* content: "User prefers dark mode",
|
|
815
|
+
* });
|
|
816
|
+
*
|
|
817
|
+
* // Recall relevant memories
|
|
818
|
+
* const results = await client.recall({
|
|
819
|
+
* agentId: "550e8400-e29b-41d4-a716-446655440000",
|
|
820
|
+
* query: "user preferences",
|
|
821
|
+
* });
|
|
822
|
+
* ```
|
|
823
|
+
*/
|
|
341
824
|
declare class Z3rnoClient {
|
|
342
825
|
private baseUrl;
|
|
343
826
|
private apiKey;
|
|
344
827
|
private timeout;
|
|
345
|
-
|
|
828
|
+
private maxRetries;
|
|
829
|
+
private fetchImpl;
|
|
830
|
+
private onRequest?;
|
|
831
|
+
private onResponse?;
|
|
832
|
+
/**
|
|
833
|
+
* Creates a new Z3rno client instance.
|
|
834
|
+
*
|
|
835
|
+
* @param config - Client configuration options. All fields are optional.
|
|
836
|
+
*
|
|
837
|
+
* @example
|
|
838
|
+
* ```ts
|
|
839
|
+
* // Explicit configuration
|
|
840
|
+
* const client = new Z3rnoClient({
|
|
841
|
+
* baseUrl: "http://localhost:8000",
|
|
842
|
+
* apiKey: "z3rno_sk_test_...",
|
|
843
|
+
* timeout: 10000,
|
|
844
|
+
* maxRetries: 2,
|
|
845
|
+
* });
|
|
846
|
+
*
|
|
847
|
+
* // Or rely on environment variables (Z3RNO_BASE_URL, Z3RNO_API_KEY)
|
|
848
|
+
* const client = new Z3rnoClient();
|
|
849
|
+
* ```
|
|
850
|
+
*/
|
|
851
|
+
constructor(config?: Z3rnoClientConfig);
|
|
852
|
+
/**
|
|
853
|
+
* Stores a new memory for an agent.
|
|
854
|
+
*
|
|
855
|
+
* The server generates an embedding for the content and stores it in
|
|
856
|
+
* the vector database. The memory is immediately available for recall.
|
|
857
|
+
*
|
|
858
|
+
* @param request - The memory to store.
|
|
859
|
+
* @returns The stored memory, including the server-generated ID and scores.
|
|
860
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
861
|
+
* @throws {@link ValidationError} If the request body is invalid.
|
|
862
|
+
* @throws {@link Z3rnoTimeoutError} If the request times out.
|
|
863
|
+
*
|
|
864
|
+
* @example
|
|
865
|
+
* ```ts
|
|
866
|
+
* const memory = await client.store({
|
|
867
|
+
* agentId: "550e8400-e29b-41d4-a716-446655440000",
|
|
868
|
+
* content: "User prefers dark mode",
|
|
869
|
+
* memoryType: "semantic",
|
|
870
|
+
* metadata: { source: "settings-page" },
|
|
871
|
+
* });
|
|
872
|
+
* console.log(memory.id); // "mem-abc123"
|
|
873
|
+
* ```
|
|
874
|
+
*/
|
|
346
875
|
store(request: StoreMemoryRequest): Promise<MemoryResponse>;
|
|
876
|
+
/**
|
|
877
|
+
* Recalls memories by semantic similarity to a query.
|
|
878
|
+
*
|
|
879
|
+
* Returns a ranked list of memories sorted by a combined relevance score
|
|
880
|
+
* that factors in similarity, importance, and recency.
|
|
881
|
+
*
|
|
882
|
+
* @param params - Recall parameters including the query and filters.
|
|
883
|
+
* @param params.agentId - UUID of the agent whose memories to search.
|
|
884
|
+
* @param params.query - Natural-language query for semantic search.
|
|
885
|
+
* @param params.memoryType - Filter by memory type.
|
|
886
|
+
* @param params.filters - Additional metadata filters.
|
|
887
|
+
* @param params.topK - Maximum results to return (default 10).
|
|
888
|
+
* @param params.similarityThreshold - Minimum similarity score (default 0).
|
|
889
|
+
* @returns Ranked recall results with similarity scores.
|
|
890
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
891
|
+
* @throws {@link Z3rnoTimeoutError} If the request times out.
|
|
892
|
+
*
|
|
893
|
+
* @example
|
|
894
|
+
* ```ts
|
|
895
|
+
* const results = await client.recall({
|
|
896
|
+
* agentId: "550e8400-e29b-41d4-a716-446655440000",
|
|
897
|
+
* query: "user preferences",
|
|
898
|
+
* topK: 5,
|
|
899
|
+
* similarityThreshold: 0.7,
|
|
900
|
+
* });
|
|
901
|
+
* for (const item of results.results) {
|
|
902
|
+
* console.log(`${item.content} (score: ${item.relevance_score})`);
|
|
903
|
+
* }
|
|
904
|
+
* ```
|
|
905
|
+
*/
|
|
347
906
|
recall(params: {
|
|
348
907
|
agentId: string;
|
|
349
908
|
query?: string;
|
|
@@ -352,6 +911,35 @@ declare class Z3rnoClient {
|
|
|
352
911
|
topK?: number;
|
|
353
912
|
similarityThreshold?: number;
|
|
354
913
|
}): Promise<RecallResponse>;
|
|
914
|
+
/**
|
|
915
|
+
* Forgets (deletes) one or more memories.
|
|
916
|
+
*
|
|
917
|
+
* By default, performs a soft delete (marks as deleted but retains data).
|
|
918
|
+
* Set `hardDelete: true` for permanent removal. Use `cascade: true` to
|
|
919
|
+
* also delete related memories in the knowledge graph.
|
|
920
|
+
*
|
|
921
|
+
* @param params - Forget parameters.
|
|
922
|
+
* @param params.agentId - UUID of the agent that owns the memories.
|
|
923
|
+
* @param params.memoryId - UUID of a single memory to delete.
|
|
924
|
+
* @param params.memoryIds - UUIDs of multiple memories to delete.
|
|
925
|
+
* @param params.hardDelete - Permanently delete (default false).
|
|
926
|
+
* @param params.cascade - Delete related memories too (default false).
|
|
927
|
+
* @param params.reason - Reason for deletion (stored in audit log).
|
|
928
|
+
* @returns Summary of the deletion operation.
|
|
929
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
930
|
+
* @throws {@link NotFoundError} If the specified memory does not exist.
|
|
931
|
+
*
|
|
932
|
+
* @example
|
|
933
|
+
* ```ts
|
|
934
|
+
* const result = await client.forget({
|
|
935
|
+
* agentId: "550e8400-e29b-41d4-a716-446655440000",
|
|
936
|
+
* memoryId: "mem-abc123",
|
|
937
|
+
* hardDelete: true,
|
|
938
|
+
* reason: "User requested data deletion",
|
|
939
|
+
* });
|
|
940
|
+
* console.log(`Deleted ${result.deleted_count} memories`);
|
|
941
|
+
* ```
|
|
942
|
+
*/
|
|
355
943
|
forget(params: {
|
|
356
944
|
agentId: string;
|
|
357
945
|
memoryId?: string;
|
|
@@ -360,37 +948,366 @@ declare class Z3rnoClient {
|
|
|
360
948
|
cascade?: boolean;
|
|
361
949
|
reason?: string;
|
|
362
950
|
}): Promise<ForgetResponse>;
|
|
951
|
+
/**
|
|
952
|
+
* Retrieves a single memory by its ID.
|
|
953
|
+
*
|
|
954
|
+
* @param memoryId - The unique identifier of the memory to retrieve.
|
|
955
|
+
* @returns The full memory object.
|
|
956
|
+
* @throws {@link NotFoundError} If no memory exists with the given ID.
|
|
957
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
958
|
+
*
|
|
959
|
+
* @example
|
|
960
|
+
* ```ts
|
|
961
|
+
* const memory = await client.getMemory("mem-abc123");
|
|
962
|
+
* console.log(memory.content);
|
|
963
|
+
* console.log(memory.importance_score);
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
getMemory(memoryId: string): Promise<MemoryResponse>;
|
|
967
|
+
/**
|
|
968
|
+
* Stores multiple memories in a single API call.
|
|
969
|
+
*
|
|
970
|
+
* More efficient than calling {@link store} in a loop. All memories are
|
|
971
|
+
* processed atomically on the server.
|
|
972
|
+
*
|
|
973
|
+
* @param memories - Array of memories to store.
|
|
974
|
+
* @returns The stored memories and a count of how many were created.
|
|
975
|
+
* @throws {@link ValidationError} If any memory in the batch is invalid.
|
|
976
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
977
|
+
*
|
|
978
|
+
* @example
|
|
979
|
+
* ```ts
|
|
980
|
+
* const result = await client.storeBatch([
|
|
981
|
+
* { agentId: "agent-1", content: "Fact one" },
|
|
982
|
+
* { agentId: "agent-1", content: "Fact two", memoryType: "semantic" },
|
|
983
|
+
* ]);
|
|
984
|
+
* console.log(`Stored ${result.stored_count} memories`);
|
|
985
|
+
* ```
|
|
986
|
+
*/
|
|
987
|
+
storeBatch(memories: StoreMemoryRequest[]): Promise<BatchStoreResponse>;
|
|
988
|
+
/**
|
|
989
|
+
* Retrieves the full version history of a memory.
|
|
990
|
+
*
|
|
991
|
+
* Z3rno uses temporal versioning — every update creates a new version
|
|
992
|
+
* rather than overwriting. This method returns all versions ordered
|
|
993
|
+
* chronologically.
|
|
994
|
+
*
|
|
995
|
+
* @param memoryId - The unique identifier of the memory.
|
|
996
|
+
* @returns All versions of the memory with validity timestamps.
|
|
997
|
+
* @throws {@link NotFoundError} If no memory exists with the given ID.
|
|
998
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
999
|
+
*
|
|
1000
|
+
* @example
|
|
1001
|
+
* ```ts
|
|
1002
|
+
* const history = await client.getMemoryHistory("mem-abc123");
|
|
1003
|
+
* for (const version of history.versions) {
|
|
1004
|
+
* console.log(`${version.valid_from}: ${version.content}`);
|
|
1005
|
+
* }
|
|
1006
|
+
* ```
|
|
1007
|
+
*/
|
|
1008
|
+
getMemoryHistory(memoryId: string): Promise<MemoryHistoryResponse>;
|
|
1009
|
+
/**
|
|
1010
|
+
* Updates an existing memory's content, metadata, or importance.
|
|
1011
|
+
*
|
|
1012
|
+
* Creates a new temporal version of the memory. The previous version
|
|
1013
|
+
* remains accessible via {@link getMemoryHistory}.
|
|
1014
|
+
*
|
|
1015
|
+
* @param memoryId - The unique identifier of the memory to update.
|
|
1016
|
+
* @param updates - Fields to update (only provided fields are changed).
|
|
1017
|
+
* @param updates.content - New text content.
|
|
1018
|
+
* @param updates.metadata - New metadata (replaces existing metadata).
|
|
1019
|
+
* @param updates.importance - New importance score (0-1).
|
|
1020
|
+
* @returns The updated memory object.
|
|
1021
|
+
* @throws {@link NotFoundError} If no memory exists with the given ID.
|
|
1022
|
+
* @throws {@link ValidationError} If the update values are invalid.
|
|
1023
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
1024
|
+
*
|
|
1025
|
+
* @example
|
|
1026
|
+
* ```ts
|
|
1027
|
+
* const updated = await client.updateMemory("mem-abc123", {
|
|
1028
|
+
* content: "User now prefers light mode",
|
|
1029
|
+
* importance: 0.9,
|
|
1030
|
+
* });
|
|
1031
|
+
* ```
|
|
1032
|
+
*/
|
|
1033
|
+
updateMemory(memoryId: string, updates: {
|
|
1034
|
+
content?: string;
|
|
1035
|
+
metadata?: Record<string, unknown>;
|
|
1036
|
+
importance?: number;
|
|
1037
|
+
}): Promise<MemoryResponse>;
|
|
1038
|
+
/**
|
|
1039
|
+
* Starts a new session for grouping related memory operations.
|
|
1040
|
+
*
|
|
1041
|
+
* Sessions are useful for tracking conversation turns or task boundaries.
|
|
1042
|
+
* Memories created during a session are automatically associated with it.
|
|
1043
|
+
*
|
|
1044
|
+
* @param params - Session parameters.
|
|
1045
|
+
* @param params.agentId - UUID of the agent to start the session for.
|
|
1046
|
+
* @param params.sessionType - Type of session (default `"conversation"`).
|
|
1047
|
+
* @returns The created session with its ID and start time.
|
|
1048
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
1049
|
+
*
|
|
1050
|
+
* @example
|
|
1051
|
+
* ```ts
|
|
1052
|
+
* const session = await client.startSession({ agentId: "agent-1" });
|
|
1053
|
+
* console.log(`Session started: ${session.session_id}`);
|
|
1054
|
+
* // ... perform operations ...
|
|
1055
|
+
* await client.endSession(session.session_id);
|
|
1056
|
+
* ```
|
|
1057
|
+
*/
|
|
1058
|
+
startSession(params: {
|
|
1059
|
+
agentId: string;
|
|
1060
|
+
sessionType?: string;
|
|
1061
|
+
}): Promise<SessionResponse>;
|
|
1062
|
+
/**
|
|
1063
|
+
* Ends an active session.
|
|
1064
|
+
*
|
|
1065
|
+
* Returns summary statistics including the session duration and the
|
|
1066
|
+
* number of memories created during the session.
|
|
1067
|
+
*
|
|
1068
|
+
* @param sessionId - The unique identifier of the session to end.
|
|
1069
|
+
* @returns Session summary with duration and memory count.
|
|
1070
|
+
* @throws {@link NotFoundError} If no active session exists with the given ID.
|
|
1071
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
1072
|
+
*
|
|
1073
|
+
* @example
|
|
1074
|
+
* ```ts
|
|
1075
|
+
* const summary = await client.endSession("sess-abc123");
|
|
1076
|
+
* console.log(`Session lasted ${summary.duration_seconds}s, ${summary.memory_count} memories`);
|
|
1077
|
+
* ```
|
|
1078
|
+
*/
|
|
1079
|
+
endSession(sessionId: string): Promise<EndSessionResponse>;
|
|
1080
|
+
/**
|
|
1081
|
+
* Retrieves a paginated audit log of memory operations.
|
|
1082
|
+
*
|
|
1083
|
+
* The audit log records every store, recall, forget, and update operation
|
|
1084
|
+
* performed by any agent. Useful for compliance, debugging, and analytics.
|
|
1085
|
+
*
|
|
1086
|
+
* @param params - Optional pagination and filter parameters.
|
|
1087
|
+
* @param params.agentId - Filter by agent UUID.
|
|
1088
|
+
* @param params.page - Page number (1-indexed).
|
|
1089
|
+
* @param params.pageSize - Number of entries per page.
|
|
1090
|
+
* @returns A page of audit log entries with pagination metadata.
|
|
1091
|
+
* @throws {@link AuthenticationError} If the API key is invalid.
|
|
1092
|
+
*
|
|
1093
|
+
* @example
|
|
1094
|
+
* ```ts
|
|
1095
|
+
* const page = await client.audit({ agentId: "agent-1", page: 1, pageSize: 20 });
|
|
1096
|
+
* for (const entry of page.entries) {
|
|
1097
|
+
* console.log(`${entry.created_at}: ${entry.operation} on ${entry.memory_id}`);
|
|
1098
|
+
* }
|
|
1099
|
+
* if (page.has_next) {
|
|
1100
|
+
* const nextPage = await client.audit({ agentId: "agent-1", page: 2 });
|
|
1101
|
+
* }
|
|
1102
|
+
* ```
|
|
1103
|
+
*/
|
|
363
1104
|
audit(params?: {
|
|
364
1105
|
agentId?: string;
|
|
365
1106
|
page?: number;
|
|
366
1107
|
pageSize?: number;
|
|
367
1108
|
}): Promise<AuditPageResponse>;
|
|
368
1109
|
private request;
|
|
1110
|
+
private sleep;
|
|
369
1111
|
private handleResponse;
|
|
370
1112
|
}
|
|
371
1113
|
|
|
372
1114
|
/**
|
|
373
1115
|
* Z3rno SDK error hierarchy.
|
|
1116
|
+
*
|
|
1117
|
+
* All errors thrown by the SDK extend {@link Z3rnoError}, which itself extends
|
|
1118
|
+
* the built-in `Error` class. This lets callers catch broadly (`Z3rnoError`)
|
|
1119
|
+
* or narrowly (`AuthenticationError`, `RateLimitError`, etc.).
|
|
1120
|
+
*
|
|
1121
|
+
* @module errors
|
|
1122
|
+
*/
|
|
1123
|
+
/**
|
|
1124
|
+
* Base error class for all Z3rno SDK errors.
|
|
1125
|
+
*
|
|
1126
|
+
* Every error produced by the SDK is an instance of this class, so you can
|
|
1127
|
+
* use a single `catch (e) { if (e instanceof Z3rnoError) ... }` guard to
|
|
1128
|
+
* handle them all.
|
|
1129
|
+
*
|
|
1130
|
+
* @example
|
|
1131
|
+
* ```ts
|
|
1132
|
+
* try {
|
|
1133
|
+
* await client.store({ agentId: "...", content: "..." });
|
|
1134
|
+
* } catch (e) {
|
|
1135
|
+
* if (e instanceof Z3rnoError) {
|
|
1136
|
+
* console.error(`Z3rno error (${e.statusCode}): ${e.message}`);
|
|
1137
|
+
* }
|
|
1138
|
+
* }
|
|
1139
|
+
* ```
|
|
374
1140
|
*/
|
|
375
1141
|
declare class Z3rnoError extends Error {
|
|
1142
|
+
/** HTTP status code returned by the server, if applicable. */
|
|
376
1143
|
statusCode?: number;
|
|
1144
|
+
/**
|
|
1145
|
+
* @param message - Human-readable description of the error.
|
|
1146
|
+
* @param statusCode - HTTP status code associated with the error, if any.
|
|
1147
|
+
*/
|
|
377
1148
|
constructor(message: string, statusCode?: number);
|
|
378
1149
|
}
|
|
1150
|
+
/**
|
|
1151
|
+
* Thrown when the API key is missing, invalid, or revoked (HTTP 401).
|
|
1152
|
+
*
|
|
1153
|
+
* @example
|
|
1154
|
+
* ```ts
|
|
1155
|
+
* try {
|
|
1156
|
+
* await client.store({ agentId: "...", content: "..." });
|
|
1157
|
+
* } catch (e) {
|
|
1158
|
+
* if (e instanceof AuthenticationError) {
|
|
1159
|
+
* console.error("Check your API key");
|
|
1160
|
+
* }
|
|
1161
|
+
* }
|
|
1162
|
+
* ```
|
|
1163
|
+
*/
|
|
379
1164
|
declare class AuthenticationError extends Z3rnoError {
|
|
1165
|
+
/**
|
|
1166
|
+
* @param message - Description of the authentication failure.
|
|
1167
|
+
*/
|
|
380
1168
|
constructor(message: string);
|
|
381
1169
|
}
|
|
1170
|
+
/**
|
|
1171
|
+
* Thrown when the client exceeds the API rate limit (HTTP 429).
|
|
1172
|
+
*
|
|
1173
|
+
* The {@link retryAfter} property indicates how many seconds to wait
|
|
1174
|
+
* before retrying, as reported by the server's `Retry-After` header.
|
|
1175
|
+
*
|
|
1176
|
+
* @example
|
|
1177
|
+
* ```ts
|
|
1178
|
+
* try {
|
|
1179
|
+
* await client.recall({ agentId: "...", query: "..." });
|
|
1180
|
+
* } catch (e) {
|
|
1181
|
+
* if (e instanceof RateLimitError) {
|
|
1182
|
+
* console.log(`Retry after ${e.retryAfter} seconds`);
|
|
1183
|
+
* }
|
|
1184
|
+
* }
|
|
1185
|
+
* ```
|
|
1186
|
+
*/
|
|
382
1187
|
declare class RateLimitError extends Z3rnoError {
|
|
1188
|
+
/** Number of seconds to wait before retrying, per the Retry-After header. */
|
|
383
1189
|
retryAfter: number;
|
|
1190
|
+
/**
|
|
1191
|
+
* @param message - Description of the rate-limit error.
|
|
1192
|
+
* @param retryAfter - Seconds to wait before retrying (defaults to 60).
|
|
1193
|
+
*/
|
|
384
1194
|
constructor(message: string, retryAfter?: number);
|
|
385
1195
|
}
|
|
1196
|
+
/**
|
|
1197
|
+
* Thrown when the server rejects the request due to invalid input (HTTP 400 or 422).
|
|
1198
|
+
*
|
|
1199
|
+
* @example
|
|
1200
|
+
* ```ts
|
|
1201
|
+
* try {
|
|
1202
|
+
* await client.store({ agentId: "not-a-uuid", content: "" });
|
|
1203
|
+
* } catch (e) {
|
|
1204
|
+
* if (e instanceof ValidationError) {
|
|
1205
|
+
* console.error(`Validation failed: ${e.message}`);
|
|
1206
|
+
* }
|
|
1207
|
+
* }
|
|
1208
|
+
* ```
|
|
1209
|
+
*/
|
|
386
1210
|
declare class ValidationError extends Z3rnoError {
|
|
1211
|
+
/**
|
|
1212
|
+
* @param message - Description of the validation failure.
|
|
1213
|
+
* @param statusCode - HTTP status code (400 or 422, defaults to 400).
|
|
1214
|
+
*/
|
|
387
1215
|
constructor(message: string, statusCode?: number);
|
|
388
1216
|
}
|
|
1217
|
+
/**
|
|
1218
|
+
* Thrown when the requested resource does not exist (HTTP 404).
|
|
1219
|
+
*
|
|
1220
|
+
* @example
|
|
1221
|
+
* ```ts
|
|
1222
|
+
* try {
|
|
1223
|
+
* await client.getMemory("non-existent-id");
|
|
1224
|
+
* } catch (e) {
|
|
1225
|
+
* if (e instanceof NotFoundError) {
|
|
1226
|
+
* console.error("Memory not found");
|
|
1227
|
+
* }
|
|
1228
|
+
* }
|
|
1229
|
+
* ```
|
|
1230
|
+
*/
|
|
389
1231
|
declare class NotFoundError extends Z3rnoError {
|
|
1232
|
+
/**
|
|
1233
|
+
* @param message - Description of what was not found.
|
|
1234
|
+
*/
|
|
390
1235
|
constructor(message: string);
|
|
391
1236
|
}
|
|
1237
|
+
/**
|
|
1238
|
+
* Thrown when the Z3rno API returns a server-side error (HTTP 5xx).
|
|
1239
|
+
*
|
|
1240
|
+
* The SDK automatically retries on 5xx errors with exponential backoff.
|
|
1241
|
+
* This error is only thrown after all retries are exhausted.
|
|
1242
|
+
*
|
|
1243
|
+
* @example
|
|
1244
|
+
* ```ts
|
|
1245
|
+
* try {
|
|
1246
|
+
* await client.store({ agentId: "...", content: "..." });
|
|
1247
|
+
* } catch (e) {
|
|
1248
|
+
* if (e instanceof ServerError) {
|
|
1249
|
+
* console.error(`Server error (${e.statusCode}): ${e.message}`);
|
|
1250
|
+
* }
|
|
1251
|
+
* }
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
392
1254
|
declare class ServerError extends Z3rnoError {
|
|
1255
|
+
/**
|
|
1256
|
+
* @param message - Description of the server error.
|
|
1257
|
+
* @param statusCode - HTTP status code (defaults to 500).
|
|
1258
|
+
*/
|
|
393
1259
|
constructor(message: string, statusCode?: number);
|
|
394
1260
|
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Thrown when a request exceeds the configured timeout duration.
|
|
1263
|
+
*
|
|
1264
|
+
* The SDK uses an {@link https://developer.mozilla.org/en-US/docs/Web/API/AbortController | AbortController}
|
|
1265
|
+
* to enforce timeouts. This error is thrown after all retries are exhausted.
|
|
1266
|
+
*
|
|
1267
|
+
* @example
|
|
1268
|
+
* ```ts
|
|
1269
|
+
* const client = new Z3rnoClient({ timeout: 5000 }); // 5 seconds
|
|
1270
|
+
* try {
|
|
1271
|
+
* await client.recall({ agentId: "...", query: "..." });
|
|
1272
|
+
* } catch (e) {
|
|
1273
|
+
* if (e instanceof Z3rnoTimeoutError) {
|
|
1274
|
+
* console.error(`Timed out after ${e.timeout}ms`);
|
|
1275
|
+
* }
|
|
1276
|
+
* }
|
|
1277
|
+
* ```
|
|
1278
|
+
*/
|
|
1279
|
+
declare class Z3rnoTimeoutError extends Z3rnoError {
|
|
1280
|
+
/** The timeout duration in milliseconds that was exceeded. */
|
|
1281
|
+
timeout: number;
|
|
1282
|
+
/**
|
|
1283
|
+
* @param message - Description of the timeout.
|
|
1284
|
+
* @param timeout - The configured timeout value in milliseconds.
|
|
1285
|
+
*/
|
|
1286
|
+
constructor(message: string, timeout: number);
|
|
1287
|
+
}
|
|
1288
|
+
/**
|
|
1289
|
+
* Thrown when the SDK cannot establish a connection to the Z3rno API.
|
|
1290
|
+
*
|
|
1291
|
+
* This typically indicates a network issue, DNS failure, or the server
|
|
1292
|
+
* being unreachable. The SDK retries connection errors with exponential
|
|
1293
|
+
* backoff before throwing this error.
|
|
1294
|
+
*
|
|
1295
|
+
* @example
|
|
1296
|
+
* ```ts
|
|
1297
|
+
* try {
|
|
1298
|
+
* await client.store({ agentId: "...", content: "..." });
|
|
1299
|
+
* } catch (e) {
|
|
1300
|
+
* if (e instanceof Z3rnoConnectionError) {
|
|
1301
|
+
* console.error("Cannot reach Z3rno API — check your network");
|
|
1302
|
+
* }
|
|
1303
|
+
* }
|
|
1304
|
+
* ```
|
|
1305
|
+
*/
|
|
1306
|
+
declare class Z3rnoConnectionError extends Z3rnoError {
|
|
1307
|
+
/**
|
|
1308
|
+
* @param message - Description of the connection failure.
|
|
1309
|
+
*/
|
|
1310
|
+
constructor(message: string);
|
|
1311
|
+
}
|
|
395
1312
|
|
|
396
|
-
export { AuditEntry, AuditPageResponse, AuthenticationError, ForgetResponse, MemoryResponse, MemoryType, NotFoundError, RateLimitError, RecallResponse, RecallResultItem, RelationshipType, ServerError, StoreMemoryRequest, ValidationError, Z3rnoClient, type Z3rnoClientConfig, Z3rnoError };
|
|
1313
|
+
export { AuditEntry, AuditPageResponse, AuthenticationError, BatchStoreResponse, EndSessionResponse, ForgetResponse, MemoryHistoryResponse, MemoryResponse, MemoryType, MemoryVersion, NotFoundError, RateLimitError, RecallResponse, RecallResultItem, RelationshipType, ServerError, SessionResponse, StoreMemoryRequest, ValidationError, Z3rnoClient, type Z3rnoClientConfig, Z3rnoConnectionError, Z3rnoError, Z3rnoTimeoutError };
|