@z3rno/sdk 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +75 -0
- package/dist/index.cjs +292 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +396 -0
- package/dist/index.d.ts +396 -0
- package/dist/index.js +276 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,396 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schemas and inferred TypeScript types for the Z3rno API.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
declare const MemoryType: z.ZodEnum<["working", "episodic", "semantic", "procedural"]>;
|
|
8
|
+
type MemoryType = z.infer<typeof MemoryType>;
|
|
9
|
+
declare const RelationshipType: z.ZodEnum<["derived_from", "contradicts", "supports", "supersedes", "related_to", "caused_by"]>;
|
|
10
|
+
type RelationshipType = z.infer<typeof RelationshipType>;
|
|
11
|
+
declare const StoreMemoryRequest: z.ZodObject<{
|
|
12
|
+
agentId: z.ZodString;
|
|
13
|
+
content: z.ZodString;
|
|
14
|
+
memoryType: z.ZodDefault<z.ZodEnum<["working", "episodic", "semantic", "procedural"]>>;
|
|
15
|
+
userId: z.ZodOptional<z.ZodString>;
|
|
16
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
17
|
+
relationships: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
18
|
+
targetMemoryId: z.ZodString;
|
|
19
|
+
relationshipType: z.ZodEnum<["derived_from", "contradicts", "supports", "supersedes", "related_to", "caused_by"]>;
|
|
20
|
+
weight: z.ZodDefault<z.ZodNumber>;
|
|
21
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
22
|
+
}, "strip", z.ZodTypeAny, {
|
|
23
|
+
metadata: Record<string, unknown>;
|
|
24
|
+
targetMemoryId: string;
|
|
25
|
+
relationshipType: "derived_from" | "contradicts" | "supports" | "supersedes" | "related_to" | "caused_by";
|
|
26
|
+
weight: number;
|
|
27
|
+
}, {
|
|
28
|
+
targetMemoryId: string;
|
|
29
|
+
relationshipType: "derived_from" | "contradicts" | "supports" | "supersedes" | "related_to" | "caused_by";
|
|
30
|
+
metadata?: Record<string, unknown> | undefined;
|
|
31
|
+
weight?: number | undefined;
|
|
32
|
+
}>, "many">>;
|
|
33
|
+
ttlSeconds: z.ZodOptional<z.ZodNumber>;
|
|
34
|
+
importance: z.ZodOptional<z.ZodNumber>;
|
|
35
|
+
}, "strip", z.ZodTypeAny, {
|
|
36
|
+
agentId: string;
|
|
37
|
+
content: string;
|
|
38
|
+
memoryType: "working" | "episodic" | "semantic" | "procedural";
|
|
39
|
+
metadata: Record<string, unknown>;
|
|
40
|
+
relationships: {
|
|
41
|
+
metadata: Record<string, unknown>;
|
|
42
|
+
targetMemoryId: string;
|
|
43
|
+
relationshipType: "derived_from" | "contradicts" | "supports" | "supersedes" | "related_to" | "caused_by";
|
|
44
|
+
weight: number;
|
|
45
|
+
}[];
|
|
46
|
+
userId?: string | undefined;
|
|
47
|
+
ttlSeconds?: number | undefined;
|
|
48
|
+
importance?: number | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
agentId: string;
|
|
51
|
+
content: string;
|
|
52
|
+
memoryType?: "working" | "episodic" | "semantic" | "procedural" | undefined;
|
|
53
|
+
userId?: string | undefined;
|
|
54
|
+
metadata?: Record<string, unknown> | undefined;
|
|
55
|
+
relationships?: {
|
|
56
|
+
targetMemoryId: string;
|
|
57
|
+
relationshipType: "derived_from" | "contradicts" | "supports" | "supersedes" | "related_to" | "caused_by";
|
|
58
|
+
metadata?: Record<string, unknown> | undefined;
|
|
59
|
+
weight?: number | undefined;
|
|
60
|
+
}[] | undefined;
|
|
61
|
+
ttlSeconds?: number | undefined;
|
|
62
|
+
importance?: number | undefined;
|
|
63
|
+
}>;
|
|
64
|
+
type StoreMemoryRequest = z.infer<typeof StoreMemoryRequest>;
|
|
65
|
+
declare const MemoryResponse: z.ZodObject<{
|
|
66
|
+
id: z.ZodString;
|
|
67
|
+
agent_id: z.ZodString;
|
|
68
|
+
content: z.ZodString;
|
|
69
|
+
memory_type: z.ZodString;
|
|
70
|
+
importance_score: z.ZodNumber;
|
|
71
|
+
recall_count: z.ZodNumber;
|
|
72
|
+
embedding_model: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
73
|
+
created_at: z.ZodString;
|
|
74
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
75
|
+
}, "strip", z.ZodTypeAny, {
|
|
76
|
+
content: string;
|
|
77
|
+
metadata: Record<string, unknown>;
|
|
78
|
+
id: string;
|
|
79
|
+
agent_id: string;
|
|
80
|
+
memory_type: string;
|
|
81
|
+
importance_score: number;
|
|
82
|
+
recall_count: number;
|
|
83
|
+
created_at: string;
|
|
84
|
+
embedding_model?: string | null | undefined;
|
|
85
|
+
}, {
|
|
86
|
+
content: string;
|
|
87
|
+
id: string;
|
|
88
|
+
agent_id: string;
|
|
89
|
+
memory_type: string;
|
|
90
|
+
importance_score: number;
|
|
91
|
+
recall_count: number;
|
|
92
|
+
created_at: string;
|
|
93
|
+
metadata?: Record<string, unknown> | undefined;
|
|
94
|
+
embedding_model?: string | null | undefined;
|
|
95
|
+
}>;
|
|
96
|
+
type MemoryResponse = z.infer<typeof MemoryResponse>;
|
|
97
|
+
declare const RecallResultItem: z.ZodObject<{
|
|
98
|
+
memory_id: z.ZodString;
|
|
99
|
+
content: z.ZodString;
|
|
100
|
+
summary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
101
|
+
memory_type: z.ZodString;
|
|
102
|
+
similarity_score: z.ZodNumber;
|
|
103
|
+
importance_score: z.ZodNumber;
|
|
104
|
+
relevance_score: z.ZodNumber;
|
|
105
|
+
recall_count: z.ZodNumber;
|
|
106
|
+
created_at: z.ZodString;
|
|
107
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
108
|
+
}, "strip", z.ZodTypeAny, {
|
|
109
|
+
content: string;
|
|
110
|
+
metadata: Record<string, unknown>;
|
|
111
|
+
memory_type: string;
|
|
112
|
+
importance_score: number;
|
|
113
|
+
recall_count: number;
|
|
114
|
+
created_at: string;
|
|
115
|
+
memory_id: string;
|
|
116
|
+
similarity_score: number;
|
|
117
|
+
relevance_score: number;
|
|
118
|
+
summary?: string | null | undefined;
|
|
119
|
+
}, {
|
|
120
|
+
content: string;
|
|
121
|
+
memory_type: string;
|
|
122
|
+
importance_score: number;
|
|
123
|
+
recall_count: number;
|
|
124
|
+
created_at: string;
|
|
125
|
+
memory_id: string;
|
|
126
|
+
similarity_score: number;
|
|
127
|
+
relevance_score: number;
|
|
128
|
+
metadata?: Record<string, unknown> | undefined;
|
|
129
|
+
summary?: string | null | undefined;
|
|
130
|
+
}>;
|
|
131
|
+
type RecallResultItem = z.infer<typeof RecallResultItem>;
|
|
132
|
+
declare const RecallResponse: z.ZodObject<{
|
|
133
|
+
results: z.ZodArray<z.ZodObject<{
|
|
134
|
+
memory_id: z.ZodString;
|
|
135
|
+
content: z.ZodString;
|
|
136
|
+
summary: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
137
|
+
memory_type: z.ZodString;
|
|
138
|
+
similarity_score: z.ZodNumber;
|
|
139
|
+
importance_score: z.ZodNumber;
|
|
140
|
+
relevance_score: z.ZodNumber;
|
|
141
|
+
recall_count: z.ZodNumber;
|
|
142
|
+
created_at: z.ZodString;
|
|
143
|
+
metadata: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
144
|
+
}, "strip", z.ZodTypeAny, {
|
|
145
|
+
content: string;
|
|
146
|
+
metadata: Record<string, unknown>;
|
|
147
|
+
memory_type: string;
|
|
148
|
+
importance_score: number;
|
|
149
|
+
recall_count: number;
|
|
150
|
+
created_at: string;
|
|
151
|
+
memory_id: string;
|
|
152
|
+
similarity_score: number;
|
|
153
|
+
relevance_score: number;
|
|
154
|
+
summary?: string | null | undefined;
|
|
155
|
+
}, {
|
|
156
|
+
content: string;
|
|
157
|
+
memory_type: string;
|
|
158
|
+
importance_score: number;
|
|
159
|
+
recall_count: number;
|
|
160
|
+
created_at: string;
|
|
161
|
+
memory_id: string;
|
|
162
|
+
similarity_score: number;
|
|
163
|
+
relevance_score: number;
|
|
164
|
+
metadata?: Record<string, unknown> | undefined;
|
|
165
|
+
summary?: string | null | undefined;
|
|
166
|
+
}>, "many">;
|
|
167
|
+
total: z.ZodNumber;
|
|
168
|
+
query: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
169
|
+
}, "strip", z.ZodTypeAny, {
|
|
170
|
+
results: {
|
|
171
|
+
content: string;
|
|
172
|
+
metadata: Record<string, unknown>;
|
|
173
|
+
memory_type: string;
|
|
174
|
+
importance_score: number;
|
|
175
|
+
recall_count: number;
|
|
176
|
+
created_at: string;
|
|
177
|
+
memory_id: string;
|
|
178
|
+
similarity_score: number;
|
|
179
|
+
relevance_score: number;
|
|
180
|
+
summary?: string | null | undefined;
|
|
181
|
+
}[];
|
|
182
|
+
total: number;
|
|
183
|
+
query?: string | null | undefined;
|
|
184
|
+
}, {
|
|
185
|
+
results: {
|
|
186
|
+
content: string;
|
|
187
|
+
memory_type: string;
|
|
188
|
+
importance_score: number;
|
|
189
|
+
recall_count: number;
|
|
190
|
+
created_at: string;
|
|
191
|
+
memory_id: string;
|
|
192
|
+
similarity_score: number;
|
|
193
|
+
relevance_score: number;
|
|
194
|
+
metadata?: Record<string, unknown> | undefined;
|
|
195
|
+
summary?: string | null | undefined;
|
|
196
|
+
}[];
|
|
197
|
+
total: number;
|
|
198
|
+
query?: string | null | undefined;
|
|
199
|
+
}>;
|
|
200
|
+
type RecallResponse = z.infer<typeof RecallResponse>;
|
|
201
|
+
declare const ForgetResponse: z.ZodObject<{
|
|
202
|
+
deleted_count: z.ZodNumber;
|
|
203
|
+
hard_deleted: z.ZodBoolean;
|
|
204
|
+
cascade_count: z.ZodNumber;
|
|
205
|
+
memory_ids: z.ZodArray<z.ZodString, "many">;
|
|
206
|
+
}, "strip", z.ZodTypeAny, {
|
|
207
|
+
deleted_count: number;
|
|
208
|
+
hard_deleted: boolean;
|
|
209
|
+
cascade_count: number;
|
|
210
|
+
memory_ids: string[];
|
|
211
|
+
}, {
|
|
212
|
+
deleted_count: number;
|
|
213
|
+
hard_deleted: boolean;
|
|
214
|
+
cascade_count: number;
|
|
215
|
+
memory_ids: string[];
|
|
216
|
+
}>;
|
|
217
|
+
type ForgetResponse = z.infer<typeof ForgetResponse>;
|
|
218
|
+
declare const AuditEntry: z.ZodObject<{
|
|
219
|
+
id: z.ZodNumber;
|
|
220
|
+
agent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
221
|
+
user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
222
|
+
operation: z.ZodString;
|
|
223
|
+
memory_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
224
|
+
memory_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
225
|
+
details: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
226
|
+
ip_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
227
|
+
created_at: z.ZodString;
|
|
228
|
+
}, "strip", z.ZodTypeAny, {
|
|
229
|
+
id: number;
|
|
230
|
+
created_at: string;
|
|
231
|
+
operation: string;
|
|
232
|
+
details: Record<string, unknown>;
|
|
233
|
+
agent_id?: string | null | undefined;
|
|
234
|
+
memory_type?: string | null | undefined;
|
|
235
|
+
memory_id?: string | null | undefined;
|
|
236
|
+
user_id?: string | null | undefined;
|
|
237
|
+
ip_address?: string | null | undefined;
|
|
238
|
+
}, {
|
|
239
|
+
id: number;
|
|
240
|
+
created_at: string;
|
|
241
|
+
operation: string;
|
|
242
|
+
agent_id?: string | null | undefined;
|
|
243
|
+
memory_type?: string | null | undefined;
|
|
244
|
+
memory_id?: string | null | undefined;
|
|
245
|
+
user_id?: string | null | undefined;
|
|
246
|
+
details?: Record<string, unknown> | undefined;
|
|
247
|
+
ip_address?: string | null | undefined;
|
|
248
|
+
}>;
|
|
249
|
+
type AuditEntry = z.infer<typeof AuditEntry>;
|
|
250
|
+
declare const AuditPageResponse: z.ZodObject<{
|
|
251
|
+
entries: z.ZodArray<z.ZodObject<{
|
|
252
|
+
id: z.ZodNumber;
|
|
253
|
+
agent_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
254
|
+
user_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
255
|
+
operation: z.ZodString;
|
|
256
|
+
memory_id: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
257
|
+
memory_type: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
258
|
+
details: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
259
|
+
ip_address: z.ZodOptional<z.ZodNullable<z.ZodString>>;
|
|
260
|
+
created_at: z.ZodString;
|
|
261
|
+
}, "strip", z.ZodTypeAny, {
|
|
262
|
+
id: number;
|
|
263
|
+
created_at: string;
|
|
264
|
+
operation: string;
|
|
265
|
+
details: Record<string, unknown>;
|
|
266
|
+
agent_id?: string | null | undefined;
|
|
267
|
+
memory_type?: string | null | undefined;
|
|
268
|
+
memory_id?: string | null | undefined;
|
|
269
|
+
user_id?: string | null | undefined;
|
|
270
|
+
ip_address?: string | null | undefined;
|
|
271
|
+
}, {
|
|
272
|
+
id: number;
|
|
273
|
+
created_at: string;
|
|
274
|
+
operation: string;
|
|
275
|
+
agent_id?: string | null | undefined;
|
|
276
|
+
memory_type?: string | null | undefined;
|
|
277
|
+
memory_id?: string | null | undefined;
|
|
278
|
+
user_id?: string | null | undefined;
|
|
279
|
+
details?: Record<string, unknown> | undefined;
|
|
280
|
+
ip_address?: string | null | undefined;
|
|
281
|
+
}>, "many">;
|
|
282
|
+
total: z.ZodNumber;
|
|
283
|
+
page: z.ZodNumber;
|
|
284
|
+
page_size: z.ZodNumber;
|
|
285
|
+
has_next: z.ZodBoolean;
|
|
286
|
+
}, "strip", z.ZodTypeAny, {
|
|
287
|
+
entries: {
|
|
288
|
+
id: number;
|
|
289
|
+
created_at: string;
|
|
290
|
+
operation: string;
|
|
291
|
+
details: Record<string, unknown>;
|
|
292
|
+
agent_id?: string | null | undefined;
|
|
293
|
+
memory_type?: string | null | undefined;
|
|
294
|
+
memory_id?: string | null | undefined;
|
|
295
|
+
user_id?: string | null | undefined;
|
|
296
|
+
ip_address?: string | null | undefined;
|
|
297
|
+
}[];
|
|
298
|
+
total: number;
|
|
299
|
+
page: number;
|
|
300
|
+
page_size: number;
|
|
301
|
+
has_next: boolean;
|
|
302
|
+
}, {
|
|
303
|
+
entries: {
|
|
304
|
+
id: number;
|
|
305
|
+
created_at: string;
|
|
306
|
+
operation: string;
|
|
307
|
+
agent_id?: string | null | undefined;
|
|
308
|
+
memory_type?: string | null | undefined;
|
|
309
|
+
memory_id?: string | null | undefined;
|
|
310
|
+
user_id?: string | null | undefined;
|
|
311
|
+
details?: Record<string, unknown> | undefined;
|
|
312
|
+
ip_address?: string | null | undefined;
|
|
313
|
+
}[];
|
|
314
|
+
total: number;
|
|
315
|
+
page: number;
|
|
316
|
+
page_size: number;
|
|
317
|
+
has_next: boolean;
|
|
318
|
+
}>;
|
|
319
|
+
type AuditPageResponse = z.infer<typeof AuditPageResponse>;
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Z3rno TypeScript SDK client.
|
|
323
|
+
*
|
|
324
|
+
* Thin fetch wrapper — no database drivers, no embedding providers.
|
|
325
|
+
*
|
|
326
|
+
* @example
|
|
327
|
+
* ```ts
|
|
328
|
+
* const client = new Z3rnoClient({ baseUrl: "http://localhost:8000", apiKey: "z3rno_sk_..." });
|
|
329
|
+
* const memory = await client.store({ agentId: "agent-1", content: "User prefers dark mode" });
|
|
330
|
+
* const results = await client.recall({ agentId: "agent-1", query: "user preferences" });
|
|
331
|
+
* await client.forget({ agentId: "agent-1", memoryId: memory.id });
|
|
332
|
+
* ```
|
|
333
|
+
*/
|
|
334
|
+
|
|
335
|
+
interface Z3rnoClientConfig {
|
|
336
|
+
baseUrl: string;
|
|
337
|
+
apiKey: string;
|
|
338
|
+
timeout?: number;
|
|
339
|
+
maxRetries?: number;
|
|
340
|
+
}
|
|
341
|
+
declare class Z3rnoClient {
|
|
342
|
+
private baseUrl;
|
|
343
|
+
private apiKey;
|
|
344
|
+
private timeout;
|
|
345
|
+
constructor(config: Z3rnoClientConfig);
|
|
346
|
+
store(request: StoreMemoryRequest): Promise<MemoryResponse>;
|
|
347
|
+
recall(params: {
|
|
348
|
+
agentId: string;
|
|
349
|
+
query?: string;
|
|
350
|
+
memoryType?: string;
|
|
351
|
+
filters?: Record<string, unknown>;
|
|
352
|
+
topK?: number;
|
|
353
|
+
similarityThreshold?: number;
|
|
354
|
+
}): Promise<RecallResponse>;
|
|
355
|
+
forget(params: {
|
|
356
|
+
agentId: string;
|
|
357
|
+
memoryId?: string;
|
|
358
|
+
memoryIds?: string[];
|
|
359
|
+
hardDelete?: boolean;
|
|
360
|
+
cascade?: boolean;
|
|
361
|
+
reason?: string;
|
|
362
|
+
}): Promise<ForgetResponse>;
|
|
363
|
+
audit(params?: {
|
|
364
|
+
agentId?: string;
|
|
365
|
+
page?: number;
|
|
366
|
+
pageSize?: number;
|
|
367
|
+
}): Promise<AuditPageResponse>;
|
|
368
|
+
private request;
|
|
369
|
+
private handleResponse;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* Z3rno SDK error hierarchy.
|
|
374
|
+
*/
|
|
375
|
+
declare class Z3rnoError extends Error {
|
|
376
|
+
statusCode?: number;
|
|
377
|
+
constructor(message: string, statusCode?: number);
|
|
378
|
+
}
|
|
379
|
+
declare class AuthenticationError extends Z3rnoError {
|
|
380
|
+
constructor(message: string);
|
|
381
|
+
}
|
|
382
|
+
declare class RateLimitError extends Z3rnoError {
|
|
383
|
+
retryAfter: number;
|
|
384
|
+
constructor(message: string, retryAfter?: number);
|
|
385
|
+
}
|
|
386
|
+
declare class ValidationError extends Z3rnoError {
|
|
387
|
+
constructor(message: string, statusCode?: number);
|
|
388
|
+
}
|
|
389
|
+
declare class NotFoundError extends Z3rnoError {
|
|
390
|
+
constructor(message: string);
|
|
391
|
+
}
|
|
392
|
+
declare class ServerError extends Z3rnoError {
|
|
393
|
+
constructor(message: string, statusCode?: number);
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
export { AuditEntry, AuditPageResponse, AuthenticationError, ForgetResponse, MemoryResponse, MemoryType, NotFoundError, RateLimitError, RecallResponse, RecallResultItem, RelationshipType, ServerError, StoreMemoryRequest, ValidationError, Z3rnoClient, type Z3rnoClientConfig, Z3rnoError };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
// src/errors.ts
|
|
4
|
+
var Z3rnoError = class extends Error {
|
|
5
|
+
statusCode;
|
|
6
|
+
constructor(message, statusCode) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = "Z3rnoError";
|
|
9
|
+
this.statusCode = statusCode;
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
var AuthenticationError = class extends Z3rnoError {
|
|
13
|
+
constructor(message) {
|
|
14
|
+
super(message, 401);
|
|
15
|
+
this.name = "AuthenticationError";
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
var RateLimitError = class extends Z3rnoError {
|
|
19
|
+
retryAfter;
|
|
20
|
+
constructor(message, retryAfter = 60) {
|
|
21
|
+
super(message, 429);
|
|
22
|
+
this.name = "RateLimitError";
|
|
23
|
+
this.retryAfter = retryAfter;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var ValidationError = class extends Z3rnoError {
|
|
27
|
+
constructor(message, statusCode = 400) {
|
|
28
|
+
super(message, statusCode);
|
|
29
|
+
this.name = "ValidationError";
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
var NotFoundError = class extends Z3rnoError {
|
|
33
|
+
constructor(message) {
|
|
34
|
+
super(message, 404);
|
|
35
|
+
this.name = "NotFoundError";
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
var ServerError = class extends Z3rnoError {
|
|
39
|
+
constructor(message, statusCode = 500) {
|
|
40
|
+
super(message, statusCode);
|
|
41
|
+
this.name = "ServerError";
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var MemoryType = z.enum([
|
|
45
|
+
"working",
|
|
46
|
+
"episodic",
|
|
47
|
+
"semantic",
|
|
48
|
+
"procedural"
|
|
49
|
+
]);
|
|
50
|
+
var RelationshipType = z.enum([
|
|
51
|
+
"derived_from",
|
|
52
|
+
"contradicts",
|
|
53
|
+
"supports",
|
|
54
|
+
"supersedes",
|
|
55
|
+
"related_to",
|
|
56
|
+
"caused_by"
|
|
57
|
+
]);
|
|
58
|
+
z.object({
|
|
59
|
+
agentId: z.string().uuid(),
|
|
60
|
+
content: z.string().min(1).max(1e5),
|
|
61
|
+
memoryType: MemoryType.default("episodic"),
|
|
62
|
+
userId: z.string().uuid().optional(),
|
|
63
|
+
metadata: z.record(z.unknown()).default({}),
|
|
64
|
+
relationships: z.array(
|
|
65
|
+
z.object({
|
|
66
|
+
targetMemoryId: z.string().uuid(),
|
|
67
|
+
relationshipType: RelationshipType,
|
|
68
|
+
weight: z.number().min(0).max(1).default(1),
|
|
69
|
+
metadata: z.record(z.unknown()).default({})
|
|
70
|
+
})
|
|
71
|
+
).default([]),
|
|
72
|
+
ttlSeconds: z.number().int().positive().optional(),
|
|
73
|
+
importance: z.number().min(0).max(1).optional()
|
|
74
|
+
});
|
|
75
|
+
z.object({
|
|
76
|
+
agentId: z.string().uuid(),
|
|
77
|
+
query: z.string().optional(),
|
|
78
|
+
memoryType: z.string().optional(),
|
|
79
|
+
filters: z.record(z.unknown()).optional(),
|
|
80
|
+
topK: z.number().int().min(1).max(100).default(10),
|
|
81
|
+
similarityThreshold: z.number().min(0).max(1).default(0),
|
|
82
|
+
asOf: z.string().datetime().optional(),
|
|
83
|
+
includeDeleted: z.boolean().default(false)
|
|
84
|
+
});
|
|
85
|
+
z.object({
|
|
86
|
+
agentId: z.string().uuid(),
|
|
87
|
+
memoryId: z.string().uuid().optional(),
|
|
88
|
+
memoryIds: z.array(z.string().uuid()).optional(),
|
|
89
|
+
hardDelete: z.boolean().default(false),
|
|
90
|
+
cascade: z.boolean().default(false),
|
|
91
|
+
reason: z.string().optional()
|
|
92
|
+
});
|
|
93
|
+
var MemoryResponse = z.object({
|
|
94
|
+
id: z.string(),
|
|
95
|
+
agent_id: z.string(),
|
|
96
|
+
content: z.string(),
|
|
97
|
+
memory_type: z.string(),
|
|
98
|
+
importance_score: z.number(),
|
|
99
|
+
recall_count: z.number(),
|
|
100
|
+
embedding_model: z.string().nullable().optional(),
|
|
101
|
+
created_at: z.string(),
|
|
102
|
+
metadata: z.record(z.unknown()).default({})
|
|
103
|
+
});
|
|
104
|
+
var RecallResultItem = z.object({
|
|
105
|
+
memory_id: z.string(),
|
|
106
|
+
content: z.string(),
|
|
107
|
+
summary: z.string().nullable().optional(),
|
|
108
|
+
memory_type: z.string(),
|
|
109
|
+
similarity_score: z.number(),
|
|
110
|
+
importance_score: z.number(),
|
|
111
|
+
relevance_score: z.number(),
|
|
112
|
+
recall_count: z.number(),
|
|
113
|
+
created_at: z.string(),
|
|
114
|
+
metadata: z.record(z.unknown()).default({})
|
|
115
|
+
});
|
|
116
|
+
var RecallResponse = z.object({
|
|
117
|
+
results: z.array(RecallResultItem),
|
|
118
|
+
total: z.number(),
|
|
119
|
+
query: z.string().nullable().optional()
|
|
120
|
+
});
|
|
121
|
+
var ForgetResponse = z.object({
|
|
122
|
+
deleted_count: z.number(),
|
|
123
|
+
hard_deleted: z.boolean(),
|
|
124
|
+
cascade_count: z.number(),
|
|
125
|
+
memory_ids: z.array(z.string())
|
|
126
|
+
});
|
|
127
|
+
var AuditEntry = z.object({
|
|
128
|
+
id: z.number(),
|
|
129
|
+
agent_id: z.string().nullable().optional(),
|
|
130
|
+
user_id: z.string().nullable().optional(),
|
|
131
|
+
operation: z.string(),
|
|
132
|
+
memory_id: z.string().nullable().optional(),
|
|
133
|
+
memory_type: z.string().nullable().optional(),
|
|
134
|
+
details: z.record(z.unknown()).default({}),
|
|
135
|
+
ip_address: z.string().nullable().optional(),
|
|
136
|
+
created_at: z.string()
|
|
137
|
+
});
|
|
138
|
+
var AuditPageResponse = z.object({
|
|
139
|
+
entries: z.array(AuditEntry),
|
|
140
|
+
total: z.number(),
|
|
141
|
+
page: z.number(),
|
|
142
|
+
page_size: z.number(),
|
|
143
|
+
has_next: z.boolean()
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// src/client.ts
|
|
147
|
+
var Z3rnoClient = class {
|
|
148
|
+
baseUrl;
|
|
149
|
+
apiKey;
|
|
150
|
+
timeout;
|
|
151
|
+
constructor(config) {
|
|
152
|
+
this.baseUrl = config.baseUrl.replace(/\/$/, "");
|
|
153
|
+
this.apiKey = config.apiKey;
|
|
154
|
+
this.timeout = config.timeout ?? 3e4;
|
|
155
|
+
}
|
|
156
|
+
// --- Store ---
|
|
157
|
+
async store(request) {
|
|
158
|
+
const body = {
|
|
159
|
+
agent_id: request.agentId,
|
|
160
|
+
content: request.content,
|
|
161
|
+
memory_type: request.memoryType,
|
|
162
|
+
user_id: request.userId,
|
|
163
|
+
metadata: request.metadata,
|
|
164
|
+
relationships: request.relationships?.map((r) => ({
|
|
165
|
+
target_memory_id: r.targetMemoryId,
|
|
166
|
+
relationship_type: r.relationshipType,
|
|
167
|
+
weight: r.weight,
|
|
168
|
+
metadata: r.metadata
|
|
169
|
+
})),
|
|
170
|
+
ttl_seconds: request.ttlSeconds,
|
|
171
|
+
importance: request.importance
|
|
172
|
+
};
|
|
173
|
+
const resp = await this.request("POST", "/v1/memories", body);
|
|
174
|
+
return MemoryResponse.parse(resp);
|
|
175
|
+
}
|
|
176
|
+
// --- Recall ---
|
|
177
|
+
async recall(params) {
|
|
178
|
+
const body = {
|
|
179
|
+
agent_id: params.agentId,
|
|
180
|
+
query: params.query,
|
|
181
|
+
memory_type: params.memoryType,
|
|
182
|
+
filters: params.filters,
|
|
183
|
+
top_k: params.topK ?? 10,
|
|
184
|
+
similarity_threshold: params.similarityThreshold ?? 0
|
|
185
|
+
};
|
|
186
|
+
const resp = await this.request("POST", "/v1/memories/recall", body);
|
|
187
|
+
return RecallResponse.parse(resp);
|
|
188
|
+
}
|
|
189
|
+
// --- Forget ---
|
|
190
|
+
async forget(params) {
|
|
191
|
+
const body = {
|
|
192
|
+
agent_id: params.agentId,
|
|
193
|
+
memory_id: params.memoryId,
|
|
194
|
+
memory_ids: params.memoryIds,
|
|
195
|
+
hard_delete: params.hardDelete ?? false,
|
|
196
|
+
cascade: params.cascade ?? false,
|
|
197
|
+
reason: params.reason
|
|
198
|
+
};
|
|
199
|
+
const resp = await this.request("POST", "/v1/memories/forget", body);
|
|
200
|
+
return ForgetResponse.parse(resp);
|
|
201
|
+
}
|
|
202
|
+
// --- Audit ---
|
|
203
|
+
async audit(params) {
|
|
204
|
+
const searchParams = new URLSearchParams();
|
|
205
|
+
if (params?.agentId) searchParams.set("agent_id", params.agentId);
|
|
206
|
+
if (params?.page) searchParams.set("page", String(params.page));
|
|
207
|
+
if (params?.pageSize)
|
|
208
|
+
searchParams.set("page_size", String(params.pageSize));
|
|
209
|
+
const query = searchParams.toString();
|
|
210
|
+
const path = query ? `/v1/audit?${query}` : "/v1/audit";
|
|
211
|
+
const resp = await this.request("GET", path);
|
|
212
|
+
return AuditPageResponse.parse(resp);
|
|
213
|
+
}
|
|
214
|
+
// --- HTTP layer ---
|
|
215
|
+
async request(method, path, body) {
|
|
216
|
+
const controller = new AbortController();
|
|
217
|
+
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
218
|
+
try {
|
|
219
|
+
const response = await fetch(`${this.baseUrl}${path}`, {
|
|
220
|
+
method,
|
|
221
|
+
headers: {
|
|
222
|
+
Authorization: `Bearer ${this.apiKey}`,
|
|
223
|
+
"Content-Type": "application/json",
|
|
224
|
+
"User-Agent": "@z3rno/sdk/0.0.1"
|
|
225
|
+
},
|
|
226
|
+
body: body ? JSON.stringify(body) : void 0,
|
|
227
|
+
signal: controller.signal
|
|
228
|
+
});
|
|
229
|
+
clearTimeout(timeoutId);
|
|
230
|
+
return this.handleResponse(response);
|
|
231
|
+
} catch (error) {
|
|
232
|
+
clearTimeout(timeoutId);
|
|
233
|
+
if (error instanceof Z3rnoError) throw error;
|
|
234
|
+
throw new Z3rnoError(`Request failed: ${String(error)}`);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
async handleResponse(resp) {
|
|
238
|
+
if (resp.ok) {
|
|
239
|
+
return resp.json();
|
|
240
|
+
}
|
|
241
|
+
let detail = resp.statusText;
|
|
242
|
+
try {
|
|
243
|
+
const body = await resp.json();
|
|
244
|
+
detail = String(body.detail ?? body.error ?? resp.statusText);
|
|
245
|
+
} catch {
|
|
246
|
+
}
|
|
247
|
+
switch (resp.status) {
|
|
248
|
+
case 401:
|
|
249
|
+
throw new AuthenticationError(`Authentication failed: ${detail}`);
|
|
250
|
+
case 404:
|
|
251
|
+
throw new NotFoundError(`Not found: ${detail}`);
|
|
252
|
+
case 429: {
|
|
253
|
+
const retryAfter = parseInt(
|
|
254
|
+
resp.headers.get("Retry-After") ?? "60",
|
|
255
|
+
10
|
|
256
|
+
);
|
|
257
|
+
throw new RateLimitError(`Rate limit exceeded: ${detail}`, retryAfter);
|
|
258
|
+
}
|
|
259
|
+
case 400:
|
|
260
|
+
case 422:
|
|
261
|
+
throw new ValidationError(detail, resp.status);
|
|
262
|
+
default:
|
|
263
|
+
if (resp.status >= 500) {
|
|
264
|
+
throw new ServerError(`Server error: ${detail}`, resp.status);
|
|
265
|
+
}
|
|
266
|
+
throw new Z3rnoError(
|
|
267
|
+
`Unexpected error (${resp.status}): ${detail}`,
|
|
268
|
+
resp.status
|
|
269
|
+
);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
export { AuditEntry, AuditPageResponse, AuthenticationError, ForgetResponse, MemoryResponse, MemoryType, NotFoundError, RateLimitError, RecallResponse, RecallResultItem, RelationshipType, ServerError, ValidationError, Z3rnoClient, Z3rnoError };
|
|
275
|
+
//# sourceMappingURL=index.js.map
|
|
276
|
+
//# sourceMappingURL=index.js.map
|