@zibby/mem0ai 2.4.7

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/dist/index.mjs ADDED
@@ -0,0 +1,815 @@
1
+ // src/client/mem0.ts
2
+ import axios from "axios";
3
+
4
+ // src/client/telemetry.ts
5
+ var version = "2.1.36";
6
+ var MEM0_TELEMETRY = true;
7
+ var _a;
8
+ try {
9
+ MEM0_TELEMETRY = ((_a = process == null ? void 0 : process.env) == null ? void 0 : _a.MEM0_TELEMETRY) === "false" ? false : true;
10
+ } catch (error) {
11
+ }
12
+ var POSTHOG_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX";
13
+ var POSTHOG_HOST = "https://us.i.posthog.com/i/v0/e/";
14
+ function generateHash(input) {
15
+ const randomStr = Math.random().toString(36).substring(2, 15) + Math.random().toString(36).substring(2, 15);
16
+ return randomStr;
17
+ }
18
+ var UnifiedTelemetry = class {
19
+ constructor(projectApiKey, host) {
20
+ this.apiKey = projectApiKey;
21
+ this.host = host;
22
+ }
23
+ async captureEvent(distinctId, eventName, properties = {}) {
24
+ if (!MEM0_TELEMETRY) return;
25
+ const eventProperties = {
26
+ client_version: version,
27
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
28
+ ...properties,
29
+ $process_person_profile: false,
30
+ $lib: "posthog-node"
31
+ };
32
+ const payload = {
33
+ api_key: this.apiKey,
34
+ distinct_id: distinctId,
35
+ event: eventName,
36
+ properties: eventProperties
37
+ };
38
+ try {
39
+ const response = await fetch(this.host, {
40
+ method: "POST",
41
+ headers: {
42
+ "Content-Type": "application/json"
43
+ },
44
+ body: JSON.stringify(payload)
45
+ });
46
+ if (!response.ok) {
47
+ console.error("Telemetry event capture failed:", await response.text());
48
+ }
49
+ } catch (error) {
50
+ console.error("Telemetry event capture failed:", error);
51
+ }
52
+ }
53
+ async shutdown() {
54
+ }
55
+ };
56
+ var telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);
57
+ async function captureClientEvent(eventName, instance, additionalData = {}) {
58
+ if (!instance.telemetryId) {
59
+ console.warn("No telemetry ID found for instance");
60
+ return;
61
+ }
62
+ const eventData = {
63
+ function: `${instance.constructor.name}`,
64
+ method: eventName,
65
+ api_host: instance.host,
66
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
67
+ client_version: version,
68
+ keys: (additionalData == null ? void 0 : additionalData.keys) || [],
69
+ ...additionalData
70
+ };
71
+ await telemetry.captureEvent(
72
+ instance.telemetryId,
73
+ `client.${eventName}`,
74
+ eventData
75
+ );
76
+ }
77
+
78
+ // src/common/exceptions.ts
79
+ var MemoryError = class extends Error {
80
+ constructor(message, errorCode, options = {}) {
81
+ var _a2, _b;
82
+ super(message);
83
+ this.name = "MemoryError";
84
+ this.errorCode = errorCode;
85
+ this.details = (_a2 = options.details) != null ? _a2 : {};
86
+ this.suggestion = options.suggestion;
87
+ this.debugInfo = (_b = options.debugInfo) != null ? _b : {};
88
+ Object.setPrototypeOf(this, new.target.prototype);
89
+ }
90
+ };
91
+ var AuthenticationError = class extends MemoryError {
92
+ constructor(message, errorCode, options) {
93
+ super(message, errorCode, options);
94
+ this.name = "AuthenticationError";
95
+ }
96
+ };
97
+ var RateLimitError = class extends MemoryError {
98
+ constructor(message, errorCode, options) {
99
+ super(message, errorCode, options);
100
+ this.name = "RateLimitError";
101
+ }
102
+ };
103
+ var ValidationError = class extends MemoryError {
104
+ constructor(message, errorCode, options) {
105
+ super(message, errorCode, options);
106
+ this.name = "ValidationError";
107
+ }
108
+ };
109
+ var MemoryNotFoundError = class extends MemoryError {
110
+ constructor(message, errorCode, options) {
111
+ super(message, errorCode, options);
112
+ this.name = "MemoryNotFoundError";
113
+ }
114
+ };
115
+ var NetworkError = class extends MemoryError {
116
+ constructor(message, errorCode, options) {
117
+ super(message, errorCode, options);
118
+ this.name = "NetworkError";
119
+ }
120
+ };
121
+ var ConfigurationError = class extends MemoryError {
122
+ constructor(message, errorCode, options) {
123
+ super(message, errorCode, options);
124
+ this.name = "ConfigurationError";
125
+ }
126
+ };
127
+ var MemoryQuotaExceededError = class extends MemoryError {
128
+ constructor(message, errorCode, options) {
129
+ super(message, errorCode, options);
130
+ this.name = "MemoryQuotaExceededError";
131
+ }
132
+ };
133
+ var HTTP_STATUS_TO_EXCEPTION = {
134
+ 400: ValidationError,
135
+ 401: AuthenticationError,
136
+ 403: AuthenticationError,
137
+ 404: MemoryNotFoundError,
138
+ 408: NetworkError,
139
+ 409: ValidationError,
140
+ 413: MemoryQuotaExceededError,
141
+ 422: ValidationError,
142
+ 429: RateLimitError,
143
+ 500: MemoryError,
144
+ 502: NetworkError,
145
+ 503: NetworkError,
146
+ 504: NetworkError
147
+ };
148
+ var HTTP_SUGGESTIONS = {
149
+ 400: "Please check your request parameters and try again",
150
+ 401: "Please check your API key and authentication credentials",
151
+ 403: "You don't have permission to perform this operation",
152
+ 404: "The requested resource was not found",
153
+ 408: "Request timed out. Please try again",
154
+ 409: "Resource conflict. Please check your request",
155
+ 413: "Request too large. Please reduce the size of your request",
156
+ 422: "Invalid request data. Please check your input",
157
+ 429: "Rate limit exceeded. Please wait before making more requests",
158
+ 500: "Internal server error. Please try again later",
159
+ 502: "Service temporarily unavailable. Please try again later",
160
+ 503: "Service unavailable. Please try again later",
161
+ 504: "Gateway timeout. Please try again later"
162
+ };
163
+ function createExceptionFromResponse(statusCode, responseText, options = {}) {
164
+ var _a2, _b;
165
+ const ExceptionClass = (_a2 = HTTP_STATUS_TO_EXCEPTION[statusCode]) != null ? _a2 : MemoryError;
166
+ const errorCode = `HTTP_${statusCode}`;
167
+ const suggestion = (_b = HTTP_SUGGESTIONS[statusCode]) != null ? _b : "Please try again later";
168
+ return new ExceptionClass(
169
+ responseText || `HTTP ${statusCode} error`,
170
+ errorCode,
171
+ { ...options, suggestion }
172
+ );
173
+ }
174
+
175
+ // src/client/mem0.ts
176
+ var APIError = class extends Error {
177
+ constructor(message) {
178
+ super(message);
179
+ this.name = "APIError";
180
+ }
181
+ };
182
+ var MemoryClient = class {
183
+ _validateApiKey() {
184
+ if (!this.apiKey) {
185
+ throw new Error("Mem0 API key is required");
186
+ }
187
+ if (typeof this.apiKey !== "string") {
188
+ throw new Error("Mem0 API key must be a string");
189
+ }
190
+ if (this.apiKey.trim() === "") {
191
+ throw new Error("Mem0 API key cannot be empty");
192
+ }
193
+ }
194
+ _validateOrgProject() {
195
+ if (this.organizationName === null && this.projectName !== null || this.organizationName !== null && this.projectName === null) {
196
+ console.warn(
197
+ "Warning: Both organizationName and projectName must be provided together when using either. This will be removed from version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId."
198
+ );
199
+ }
200
+ if (this.organizationId === null && this.projectId !== null || this.organizationId !== null && this.projectId === null) {
201
+ console.warn(
202
+ "Warning: Both organizationId and projectId must be provided together when using either. This will be removed from version 1.0.40."
203
+ );
204
+ }
205
+ }
206
+ constructor(options) {
207
+ this.apiKey = options.apiKey;
208
+ this.host = options.host || "https://api.mem0.ai";
209
+ this.organizationName = options.organizationName || null;
210
+ this.projectName = options.projectName || null;
211
+ this.organizationId = options.organizationId || null;
212
+ this.projectId = options.projectId || null;
213
+ this.headers = {
214
+ Authorization: `Token ${this.apiKey}`,
215
+ "Content-Type": "application/json"
216
+ };
217
+ this.client = axios.create({
218
+ baseURL: this.host,
219
+ headers: { Authorization: `Token ${this.apiKey}` },
220
+ timeout: 6e4
221
+ });
222
+ this._validateApiKey();
223
+ this.telemetryId = "";
224
+ this._initializeClient();
225
+ }
226
+ async _initializeClient() {
227
+ try {
228
+ await this.ping();
229
+ if (!this.telemetryId) {
230
+ this.telemetryId = generateHash(this.apiKey);
231
+ }
232
+ this._validateOrgProject();
233
+ captureClientEvent("init", this, {
234
+ api_version: "v1",
235
+ client_type: "MemoryClient"
236
+ }).catch((error) => {
237
+ console.error("Failed to capture event:", error);
238
+ });
239
+ } catch (error) {
240
+ console.error("Failed to initialize client:", error);
241
+ await captureClientEvent("init_error", this, {
242
+ error: (error == null ? void 0 : error.message) || "Unknown error",
243
+ stack: (error == null ? void 0 : error.stack) || "No stack trace"
244
+ });
245
+ }
246
+ }
247
+ _captureEvent(methodName, args) {
248
+ captureClientEvent(methodName, this, {
249
+ success: true,
250
+ args_count: args.length,
251
+ keys: args.length > 0 ? args[0] : []
252
+ }).catch((error) => {
253
+ console.error("Failed to capture event:", error);
254
+ });
255
+ }
256
+ async _fetchWithErrorHandling(url, options) {
257
+ const response = await fetch(url, {
258
+ ...options,
259
+ headers: {
260
+ ...options.headers,
261
+ Authorization: `Token ${this.apiKey}`,
262
+ "Mem0-User-ID": this.telemetryId
263
+ }
264
+ });
265
+ if (!response.ok) {
266
+ const errorData = await response.text();
267
+ throw createExceptionFromResponse(response.status, errorData);
268
+ }
269
+ const jsonResponse = await response.json();
270
+ return jsonResponse;
271
+ }
272
+ _preparePayload(messages, options) {
273
+ const payload = {};
274
+ payload.messages = messages;
275
+ return { ...payload, ...options };
276
+ }
277
+ _prepareParams(options) {
278
+ return Object.fromEntries(
279
+ Object.entries(options).filter(([_, v]) => v != null)
280
+ );
281
+ }
282
+ async ping() {
283
+ try {
284
+ const response = await this._fetchWithErrorHandling(
285
+ `${this.host}/v1/ping/`,
286
+ {
287
+ method: "GET",
288
+ headers: {
289
+ Authorization: `Token ${this.apiKey}`
290
+ }
291
+ }
292
+ );
293
+ if (!response || typeof response !== "object") {
294
+ throw new APIError("Invalid response format from ping endpoint");
295
+ }
296
+ if (response.status !== "ok") {
297
+ throw new APIError(response.message || "API Key is invalid");
298
+ }
299
+ const { org_id, project_id, user_email } = response;
300
+ if (org_id && !this.organizationId) this.organizationId = org_id;
301
+ if (project_id && !this.projectId) this.projectId = project_id;
302
+ if (user_email) this.telemetryId = user_email;
303
+ } catch (error) {
304
+ if (error instanceof MemoryError || error instanceof APIError) {
305
+ throw error;
306
+ } else {
307
+ throw new APIError(
308
+ `Failed to ping server: ${error.message || "Unknown error"}`
309
+ );
310
+ }
311
+ }
312
+ }
313
+ async add(messages, options = {}) {
314
+ if (this.telemetryId === "") await this.ping();
315
+ this._validateOrgProject();
316
+ if (this.organizationName != null && this.projectName != null) {
317
+ options.org_name = this.organizationName;
318
+ options.project_name = this.projectName;
319
+ }
320
+ if (this.organizationId != null && this.projectId != null) {
321
+ options.org_id = this.organizationId;
322
+ options.project_id = this.projectId;
323
+ if (options.org_name) delete options.org_name;
324
+ if (options.project_name) delete options.project_name;
325
+ }
326
+ if (options.api_version) {
327
+ options.version = options.api_version.toString() || "v2";
328
+ }
329
+ const payload = this._preparePayload(messages, options);
330
+ const payloadKeys = Object.keys(payload);
331
+ this._captureEvent("add", [payloadKeys]);
332
+ const response = await this._fetchWithErrorHandling(
333
+ `${this.host}/v1/memories/`,
334
+ {
335
+ method: "POST",
336
+ headers: this.headers,
337
+ body: JSON.stringify(payload)
338
+ }
339
+ );
340
+ return response;
341
+ }
342
+ async update(memoryId, {
343
+ text,
344
+ metadata,
345
+ timestamp
346
+ }) {
347
+ if (text === void 0 && metadata === void 0 && timestamp === void 0) {
348
+ throw new Error(
349
+ "At least one of text, metadata, or timestamp must be provided for update."
350
+ );
351
+ }
352
+ if (this.telemetryId === "") await this.ping();
353
+ this._validateOrgProject();
354
+ const payload = {};
355
+ if (text !== void 0) payload.text = text;
356
+ if (metadata !== void 0) payload.metadata = metadata;
357
+ if (timestamp !== void 0) payload.timestamp = timestamp;
358
+ const payloadKeys = Object.keys(payload);
359
+ this._captureEvent("update", [payloadKeys]);
360
+ const response = await this._fetchWithErrorHandling(
361
+ `${this.host}/v1/memories/${memoryId}/`,
362
+ {
363
+ method: "PUT",
364
+ headers: this.headers,
365
+ body: JSON.stringify(payload)
366
+ }
367
+ );
368
+ return response;
369
+ }
370
+ async get(memoryId) {
371
+ if (this.telemetryId === "") await this.ping();
372
+ this._captureEvent("get", []);
373
+ return this._fetchWithErrorHandling(
374
+ `${this.host}/v1/memories/${memoryId}/`,
375
+ {
376
+ headers: this.headers
377
+ }
378
+ );
379
+ }
380
+ async getAll(options) {
381
+ if (this.telemetryId === "") await this.ping();
382
+ this._validateOrgProject();
383
+ const payloadKeys = Object.keys(options || {});
384
+ this._captureEvent("get_all", [payloadKeys]);
385
+ const { api_version, page, page_size, ...otherOptions } = options != null ? options : {};
386
+ if (this.organizationName != null && this.projectName != null) {
387
+ otherOptions.org_name = this.organizationName;
388
+ otherOptions.project_name = this.projectName;
389
+ }
390
+ let appendedParams = "";
391
+ let paginated_response = false;
392
+ if (page && page_size) {
393
+ appendedParams += `page=${page}&page_size=${page_size}`;
394
+ paginated_response = true;
395
+ }
396
+ if (this.organizationId != null && this.projectId != null) {
397
+ otherOptions.org_id = this.organizationId;
398
+ otherOptions.project_id = this.projectId;
399
+ if (otherOptions.org_name) delete otherOptions.org_name;
400
+ if (otherOptions.project_name) delete otherOptions.project_name;
401
+ }
402
+ if (api_version === "v2") {
403
+ let url = paginated_response ? `${this.host}/v2/memories/?${appendedParams}` : `${this.host}/v2/memories/`;
404
+ return this._fetchWithErrorHandling(url, {
405
+ method: "POST",
406
+ headers: this.headers,
407
+ body: JSON.stringify(otherOptions)
408
+ });
409
+ } else {
410
+ const params = new URLSearchParams(this._prepareParams(otherOptions));
411
+ const url = paginated_response ? `${this.host}/v1/memories/?${params}&${appendedParams}` : `${this.host}/v1/memories/?${params}`;
412
+ return this._fetchWithErrorHandling(url, {
413
+ headers: this.headers
414
+ });
415
+ }
416
+ }
417
+ async search(query, options) {
418
+ if (this.telemetryId === "") await this.ping();
419
+ this._validateOrgProject();
420
+ const payloadKeys = Object.keys(options || {});
421
+ this._captureEvent("search", [payloadKeys]);
422
+ const { api_version, ...otherOptions } = options != null ? options : {};
423
+ const payload = { query, ...otherOptions };
424
+ if (this.organizationName != null && this.projectName != null) {
425
+ payload.org_name = this.organizationName;
426
+ payload.project_name = this.projectName;
427
+ }
428
+ if (this.organizationId != null && this.projectId != null) {
429
+ payload.org_id = this.organizationId;
430
+ payload.project_id = this.projectId;
431
+ if (payload.org_name) delete payload.org_name;
432
+ if (payload.project_name) delete payload.project_name;
433
+ }
434
+ const endpoint = api_version === "v2" ? "/v2/memories/search/" : "/v1/memories/search/";
435
+ const response = await this._fetchWithErrorHandling(
436
+ `${this.host}${endpoint}`,
437
+ {
438
+ method: "POST",
439
+ headers: this.headers,
440
+ body: JSON.stringify(payload)
441
+ }
442
+ );
443
+ return response;
444
+ }
445
+ async delete(memoryId) {
446
+ if (this.telemetryId === "") await this.ping();
447
+ this._captureEvent("delete", []);
448
+ return this._fetchWithErrorHandling(
449
+ `${this.host}/v1/memories/${memoryId}/`,
450
+ {
451
+ method: "DELETE",
452
+ headers: this.headers
453
+ }
454
+ );
455
+ }
456
+ async deleteAll(options = {}) {
457
+ if (this.telemetryId === "") await this.ping();
458
+ this._validateOrgProject();
459
+ const payloadKeys = Object.keys(options || {});
460
+ this._captureEvent("delete_all", [payloadKeys]);
461
+ if (this.organizationName != null && this.projectName != null) {
462
+ options.org_name = this.organizationName;
463
+ options.project_name = this.projectName;
464
+ }
465
+ if (this.organizationId != null && this.projectId != null) {
466
+ options.org_id = this.organizationId;
467
+ options.project_id = this.projectId;
468
+ if (options.org_name) delete options.org_name;
469
+ if (options.project_name) delete options.project_name;
470
+ }
471
+ const params = new URLSearchParams(this._prepareParams(options));
472
+ const response = await this._fetchWithErrorHandling(
473
+ `${this.host}/v1/memories/?${params}`,
474
+ {
475
+ method: "DELETE",
476
+ headers: this.headers
477
+ }
478
+ );
479
+ return response;
480
+ }
481
+ async history(memoryId) {
482
+ if (this.telemetryId === "") await this.ping();
483
+ this._captureEvent("history", []);
484
+ const response = await this._fetchWithErrorHandling(
485
+ `${this.host}/v1/memories/${memoryId}/history/`,
486
+ {
487
+ headers: this.headers
488
+ }
489
+ );
490
+ return response;
491
+ }
492
+ async users() {
493
+ if (this.telemetryId === "") await this.ping();
494
+ this._validateOrgProject();
495
+ this._captureEvent("users", []);
496
+ const options = {};
497
+ if (this.organizationName != null && this.projectName != null) {
498
+ options.org_name = this.organizationName;
499
+ options.project_name = this.projectName;
500
+ }
501
+ if (this.organizationId != null && this.projectId != null) {
502
+ options.org_id = this.organizationId;
503
+ options.project_id = this.projectId;
504
+ if (options.org_name) delete options.org_name;
505
+ if (options.project_name) delete options.project_name;
506
+ }
507
+ const params = new URLSearchParams(options);
508
+ const response = await this._fetchWithErrorHandling(
509
+ `${this.host}/v1/entities/?${params}`,
510
+ {
511
+ headers: this.headers
512
+ }
513
+ );
514
+ return response;
515
+ }
516
+ /**
517
+ * @deprecated The method should not be used, use `deleteUsers` instead. This will be removed in version 2.2.0.
518
+ */
519
+ async deleteUser(data) {
520
+ if (this.telemetryId === "") await this.ping();
521
+ this._captureEvent("delete_user", []);
522
+ if (!data.entity_type) {
523
+ data.entity_type = "user";
524
+ }
525
+ const response = await this._fetchWithErrorHandling(
526
+ `${this.host}/v1/entities/${data.entity_type}/${data.entity_id}/`,
527
+ {
528
+ method: "DELETE",
529
+ headers: this.headers
530
+ }
531
+ );
532
+ return response;
533
+ }
534
+ async deleteUsers(params = {}) {
535
+ if (this.telemetryId === "") await this.ping();
536
+ this._validateOrgProject();
537
+ let to_delete = [];
538
+ const { user_id, agent_id, app_id, run_id } = params;
539
+ if (user_id) {
540
+ to_delete = [{ type: "user", name: user_id }];
541
+ } else if (agent_id) {
542
+ to_delete = [{ type: "agent", name: agent_id }];
543
+ } else if (app_id) {
544
+ to_delete = [{ type: "app", name: app_id }];
545
+ } else if (run_id) {
546
+ to_delete = [{ type: "run", name: run_id }];
547
+ } else {
548
+ const entities = await this.users();
549
+ to_delete = entities.results.map((entity) => ({
550
+ type: entity.type,
551
+ name: entity.name
552
+ }));
553
+ }
554
+ if (to_delete.length === 0) {
555
+ throw new Error("No entities to delete");
556
+ }
557
+ const requestOptions = {};
558
+ if (this.organizationName != null && this.projectName != null) {
559
+ requestOptions.org_name = this.organizationName;
560
+ requestOptions.project_name = this.projectName;
561
+ }
562
+ if (this.organizationId != null && this.projectId != null) {
563
+ requestOptions.org_id = this.organizationId;
564
+ requestOptions.project_id = this.projectId;
565
+ if (requestOptions.org_name) delete requestOptions.org_name;
566
+ if (requestOptions.project_name) delete requestOptions.project_name;
567
+ }
568
+ for (const entity of to_delete) {
569
+ try {
570
+ await this.client.delete(
571
+ `/v2/entities/${entity.type}/${entity.name}/`,
572
+ {
573
+ params: requestOptions
574
+ }
575
+ );
576
+ } catch (error) {
577
+ throw new APIError(
578
+ `Failed to delete ${entity.type} ${entity.name}: ${error.message}`
579
+ );
580
+ }
581
+ }
582
+ this._captureEvent("delete_users", [
583
+ {
584
+ user_id,
585
+ agent_id,
586
+ app_id,
587
+ run_id,
588
+ sync_type: "sync"
589
+ }
590
+ ]);
591
+ return {
592
+ message: user_id || agent_id || app_id || run_id ? "Entity deleted successfully." : "All users, agents, apps and runs deleted."
593
+ };
594
+ }
595
+ async batchUpdate(memories) {
596
+ if (this.telemetryId === "") await this.ping();
597
+ this._captureEvent("batch_update", []);
598
+ const memoriesBody = memories.map((memory) => ({
599
+ memory_id: memory.memoryId,
600
+ text: memory.text
601
+ }));
602
+ const response = await this._fetchWithErrorHandling(
603
+ `${this.host}/v1/batch/`,
604
+ {
605
+ method: "PUT",
606
+ headers: this.headers,
607
+ body: JSON.stringify({ memories: memoriesBody })
608
+ }
609
+ );
610
+ return response;
611
+ }
612
+ async batchDelete(memories) {
613
+ if (this.telemetryId === "") await this.ping();
614
+ this._captureEvent("batch_delete", []);
615
+ const memoriesBody = memories.map((memory) => ({
616
+ memory_id: memory
617
+ }));
618
+ const response = await this._fetchWithErrorHandling(
619
+ `${this.host}/v1/batch/`,
620
+ {
621
+ method: "DELETE",
622
+ headers: this.headers,
623
+ body: JSON.stringify({ memories: memoriesBody })
624
+ }
625
+ );
626
+ return response;
627
+ }
628
+ async getProject(options) {
629
+ if (this.telemetryId === "") await this.ping();
630
+ this._validateOrgProject();
631
+ const payloadKeys = Object.keys(options || {});
632
+ this._captureEvent("get_project", [payloadKeys]);
633
+ const { fields } = options;
634
+ if (!(this.organizationId && this.projectId)) {
635
+ throw new Error(
636
+ "organizationId and projectId must be set to access instructions or categories"
637
+ );
638
+ }
639
+ const params = new URLSearchParams();
640
+ fields == null ? void 0 : fields.forEach((field) => params.append("fields", field));
641
+ const response = await this._fetchWithErrorHandling(
642
+ `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,
643
+ {
644
+ headers: this.headers
645
+ }
646
+ );
647
+ return response;
648
+ }
649
+ async updateProject(prompts) {
650
+ if (this.telemetryId === "") await this.ping();
651
+ this._validateOrgProject();
652
+ this._captureEvent("update_project", []);
653
+ if (!(this.organizationId && this.projectId)) {
654
+ throw new Error(
655
+ "organizationId and projectId must be set to update instructions or categories"
656
+ );
657
+ }
658
+ const response = await this._fetchWithErrorHandling(
659
+ `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,
660
+ {
661
+ method: "PATCH",
662
+ headers: this.headers,
663
+ body: JSON.stringify(prompts)
664
+ }
665
+ );
666
+ return response;
667
+ }
668
+ // WebHooks
669
+ async getWebhooks(data) {
670
+ if (this.telemetryId === "") await this.ping();
671
+ this._captureEvent("get_webhooks", []);
672
+ const project_id = (data == null ? void 0 : data.projectId) || this.projectId;
673
+ const response = await this._fetchWithErrorHandling(
674
+ `${this.host}/api/v1/webhooks/projects/${project_id}/`,
675
+ {
676
+ headers: this.headers
677
+ }
678
+ );
679
+ return response;
680
+ }
681
+ async createWebhook(webhook) {
682
+ if (this.telemetryId === "") await this.ping();
683
+ this._captureEvent("create_webhook", []);
684
+ const body = {
685
+ name: webhook.name,
686
+ url: webhook.url,
687
+ event_types: webhook.eventTypes
688
+ };
689
+ const response = await this._fetchWithErrorHandling(
690
+ `${this.host}/api/v1/webhooks/projects/${this.projectId}/`,
691
+ {
692
+ method: "POST",
693
+ headers: this.headers,
694
+ body: JSON.stringify(body)
695
+ }
696
+ );
697
+ return response;
698
+ }
699
+ async updateWebhook(webhook) {
700
+ if (this.telemetryId === "") await this.ping();
701
+ this._captureEvent("update_webhook", []);
702
+ const body = {};
703
+ if (webhook.name != null) body.name = webhook.name;
704
+ if (webhook.url != null) body.url = webhook.url;
705
+ if (webhook.eventTypes != null) body.event_types = webhook.eventTypes;
706
+ const response = await this._fetchWithErrorHandling(
707
+ `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,
708
+ {
709
+ method: "PUT",
710
+ headers: this.headers,
711
+ body: JSON.stringify(body)
712
+ }
713
+ );
714
+ return response;
715
+ }
716
+ async deleteWebhook(data) {
717
+ if (this.telemetryId === "") await this.ping();
718
+ this._captureEvent("delete_webhook", []);
719
+ const webhook_id = data.webhookId || data;
720
+ const response = await this._fetchWithErrorHandling(
721
+ `${this.host}/api/v1/webhooks/${webhook_id}/`,
722
+ {
723
+ method: "DELETE",
724
+ headers: this.headers
725
+ }
726
+ );
727
+ return response;
728
+ }
729
+ async feedback(data) {
730
+ if (this.telemetryId === "") await this.ping();
731
+ const payloadKeys = Object.keys(data || {});
732
+ this._captureEvent("feedback", [payloadKeys]);
733
+ const response = await this._fetchWithErrorHandling(
734
+ `${this.host}/v1/feedback/`,
735
+ {
736
+ method: "POST",
737
+ headers: this.headers,
738
+ body: JSON.stringify(data)
739
+ }
740
+ );
741
+ return response;
742
+ }
743
+ async createMemoryExport(data) {
744
+ var _a2, _b;
745
+ if (this.telemetryId === "") await this.ping();
746
+ this._captureEvent("create_memory_export", []);
747
+ if (!data.filters || !data.schema) {
748
+ throw new Error("Missing filters or schema");
749
+ }
750
+ data.org_id = ((_a2 = this.organizationId) == null ? void 0 : _a2.toString()) || null;
751
+ data.project_id = ((_b = this.projectId) == null ? void 0 : _b.toString()) || null;
752
+ const response = await this._fetchWithErrorHandling(
753
+ `${this.host}/v1/exports/`,
754
+ {
755
+ method: "POST",
756
+ headers: this.headers,
757
+ body: JSON.stringify(data)
758
+ }
759
+ );
760
+ return response;
761
+ }
762
+ async getMemoryExport(data) {
763
+ var _a2, _b;
764
+ if (this.telemetryId === "") await this.ping();
765
+ this._captureEvent("get_memory_export", []);
766
+ if (!data.memory_export_id && !data.filters) {
767
+ throw new Error("Missing memory_export_id or filters");
768
+ }
769
+ data.org_id = ((_a2 = this.organizationId) == null ? void 0 : _a2.toString()) || "";
770
+ data.project_id = ((_b = this.projectId) == null ? void 0 : _b.toString()) || "";
771
+ const response = await this._fetchWithErrorHandling(
772
+ `${this.host}/v1/exports/get/`,
773
+ {
774
+ method: "POST",
775
+ headers: this.headers,
776
+ body: JSON.stringify(data)
777
+ }
778
+ );
779
+ return response;
780
+ }
781
+ };
782
+
783
+ // src/client/mem0.types.ts
784
+ var Feedback = /* @__PURE__ */ ((Feedback2) => {
785
+ Feedback2["POSITIVE"] = "POSITIVE";
786
+ Feedback2["NEGATIVE"] = "NEGATIVE";
787
+ Feedback2["VERY_NEGATIVE"] = "VERY_NEGATIVE";
788
+ return Feedback2;
789
+ })(Feedback || {});
790
+ var WebhookEvent = /* @__PURE__ */ ((WebhookEvent2) => {
791
+ WebhookEvent2["MEMORY_ADDED"] = "memory_add";
792
+ WebhookEvent2["MEMORY_UPDATED"] = "memory_update";
793
+ WebhookEvent2["MEMORY_DELETED"] = "memory_delete";
794
+ WebhookEvent2["MEMORY_CATEGORIZED"] = "memory_categorize";
795
+ return WebhookEvent2;
796
+ })(WebhookEvent || {});
797
+
798
+ // src/client/index.ts
799
+ var index_default = MemoryClient;
800
+ export {
801
+ AuthenticationError,
802
+ ConfigurationError,
803
+ Feedback,
804
+ MemoryClient,
805
+ MemoryError,
806
+ MemoryNotFoundError,
807
+ MemoryQuotaExceededError,
808
+ NetworkError,
809
+ RateLimitError,
810
+ ValidationError,
811
+ WebhookEvent,
812
+ createExceptionFromResponse,
813
+ index_default as default
814
+ };
815
+ //# sourceMappingURL=index.mjs.map