mem0ai 1.0.37 → 1.0.39
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.d.mts +25 -1
- package/dist/index.d.ts +25 -2
- package/dist/index.js +28 -78
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +23 -69
- package/dist/index.mjs.map +1 -1
- package/package.json +43 -5
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PostHog } from 'posthog-js';
|
|
2
|
+
|
|
1
3
|
interface MemoryOptions {
|
|
2
4
|
user_id?: string;
|
|
3
5
|
agent_id?: string;
|
|
@@ -205,4 +207,26 @@ declare class MemoryClient {
|
|
|
205
207
|
}>;
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
|
|
210
|
+
interface TelemetryClient {
|
|
211
|
+
captureEvent(distinctId: string, eventName: string, properties?: Record<string, any>): Promise<void>;
|
|
212
|
+
shutdown(): Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
interface TelemetryInstance {
|
|
215
|
+
telemetryId: string;
|
|
216
|
+
constructor: {
|
|
217
|
+
name: string;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
declare function generateHash(input: string): Promise<string>;
|
|
222
|
+
declare class BrowserTelemetry implements TelemetryClient {
|
|
223
|
+
client: PostHog | null;
|
|
224
|
+
constructor(projectApiKey: string, host: string);
|
|
225
|
+
private initializeClient;
|
|
226
|
+
captureEvent(distinctId: string, eventName: string, properties?: {}): Promise<void>;
|
|
227
|
+
shutdown(): Promise<void>;
|
|
228
|
+
}
|
|
229
|
+
declare const telemetry: BrowserTelemetry;
|
|
230
|
+
declare function captureClientEvent(eventName: string, instance: any, additionalData?: {}): Promise<void>;
|
|
231
|
+
|
|
232
|
+
export { type AllUsers, type Memory, MemoryClient, type MemoryHistory, type MemoryOptions, type MemoryUpdateBody, type Message, type Messages, type ProjectOptions, type ProjectResponse, type PromptUpdatePayload, type SearchOptions, type TelemetryClient, type TelemetryInstance, type User, type Webhook, type WebhookPayload, captureClientEvent, MemoryClient as default, generateHash, telemetry };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PostHog } from 'posthog-js';
|
|
2
|
+
|
|
1
3
|
interface MemoryOptions {
|
|
2
4
|
user_id?: string;
|
|
3
5
|
agent_id?: string;
|
|
@@ -205,5 +207,26 @@ declare class MemoryClient {
|
|
|
205
207
|
}>;
|
|
206
208
|
}
|
|
207
209
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
+
interface TelemetryClient {
|
|
211
|
+
captureEvent(distinctId: string, eventName: string, properties?: Record<string, any>): Promise<void>;
|
|
212
|
+
shutdown(): Promise<void>;
|
|
213
|
+
}
|
|
214
|
+
interface TelemetryInstance {
|
|
215
|
+
telemetryId: string;
|
|
216
|
+
constructor: {
|
|
217
|
+
name: string;
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
declare function generateHash(input: string): Promise<string>;
|
|
222
|
+
declare class BrowserTelemetry implements TelemetryClient {
|
|
223
|
+
client: PostHog | null;
|
|
224
|
+
constructor(projectApiKey: string, host: string);
|
|
225
|
+
private initializeClient;
|
|
226
|
+
captureEvent(distinctId: string, eventName: string, properties?: {}): Promise<void>;
|
|
227
|
+
shutdown(): Promise<void>;
|
|
228
|
+
}
|
|
229
|
+
declare const telemetry: BrowserTelemetry;
|
|
230
|
+
declare function captureClientEvent(eventName: string, instance: any, additionalData?: {}): Promise<void>;
|
|
231
|
+
|
|
232
|
+
export { type AllUsers, type Memory, MemoryClient, type MemoryHistory, type MemoryOptions, type MemoryUpdateBody, type Message, type Messages, type ProjectOptions, type ProjectResponse, type PromptUpdatePayload, type SearchOptions, type TelemetryClient, type TelemetryInstance, type User, type Webhook, type WebhookPayload, captureClientEvent, MemoryClient as default, generateHash, telemetry };
|
package/dist/index.js
CHANGED
|
@@ -30,108 +30,69 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// src/index.ts
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
|
-
API_VERSION: () => API_VERSION,
|
|
34
33
|
MemoryClient: () => MemoryClient,
|
|
35
|
-
|
|
34
|
+
captureClientEvent: () => captureClientEvent,
|
|
35
|
+
default: () => index_default,
|
|
36
|
+
generateHash: () => generateHash,
|
|
37
|
+
telemetry: () => telemetry
|
|
36
38
|
});
|
|
37
39
|
module.exports = __toCommonJS(index_exports);
|
|
38
40
|
|
|
39
41
|
// src/mem0.ts
|
|
40
42
|
var import_axios = __toESM(require("axios"));
|
|
41
43
|
|
|
42
|
-
// src/telemetry.ts
|
|
44
|
+
// src/telemetry.browser.ts
|
|
43
45
|
var version = "1.0.20";
|
|
44
46
|
var MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== "false";
|
|
45
47
|
var POSTHOG_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX";
|
|
46
48
|
var POSTHOG_HOST = "https://us.i.posthog.com";
|
|
47
49
|
async function generateHash(input) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
53
|
-
} else {
|
|
54
|
-
const crypto = await import("crypto");
|
|
55
|
-
return crypto.createHash("sha256").update(input).digest("hex");
|
|
56
|
-
}
|
|
50
|
+
const msgBuffer = new TextEncoder().encode(input);
|
|
51
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgBuffer);
|
|
52
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
53
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
57
54
|
}
|
|
58
|
-
var
|
|
55
|
+
var BrowserTelemetry = class {
|
|
59
56
|
constructor(projectApiKey, host) {
|
|
60
57
|
this.client = null;
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
detectNodeEnvironment() {
|
|
65
|
-
return typeof process !== "undefined" && process.versions != null && process.versions.node != null && typeof window === "undefined";
|
|
58
|
+
if (MEM0_TELEMETRY) {
|
|
59
|
+
this.initializeClient(projectApiKey, host);
|
|
60
|
+
}
|
|
66
61
|
}
|
|
67
62
|
async initializeClient(projectApiKey, host) {
|
|
68
63
|
try {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
this.client = new PostHog(projectApiKey, { host, flushAt: 1 });
|
|
72
|
-
} else {
|
|
73
|
-
const posthog = await import("posthog-js");
|
|
64
|
+
const posthog = await import("posthog-js").catch(() => null);
|
|
65
|
+
if (posthog) {
|
|
74
66
|
posthog.init(projectApiKey, { api_host: host });
|
|
75
67
|
this.client = posthog;
|
|
76
68
|
}
|
|
77
69
|
} catch (error) {
|
|
78
|
-
console.warn("Failed to initialize PostHog client:", error);
|
|
79
70
|
this.client = null;
|
|
80
71
|
}
|
|
81
72
|
}
|
|
82
73
|
async captureEvent(distinctId, eventName, properties = {}) {
|
|
83
|
-
if (!this.client) return;
|
|
74
|
+
if (!this.client || !MEM0_TELEMETRY) return;
|
|
84
75
|
const eventProperties = {
|
|
85
|
-
client_source:
|
|
76
|
+
client_source: "browser",
|
|
86
77
|
client_version: getVersion(),
|
|
87
|
-
|
|
78
|
+
browser: window.navigator.userAgent,
|
|
88
79
|
...properties
|
|
89
80
|
};
|
|
90
81
|
try {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
properties: eventProperties
|
|
96
|
-
});
|
|
97
|
-
} else {
|
|
98
|
-
this.client.capture(
|
|
99
|
-
eventName,
|
|
100
|
-
eventProperties
|
|
101
|
-
);
|
|
102
|
-
}
|
|
82
|
+
this.client.capture(
|
|
83
|
+
eventName,
|
|
84
|
+
eventProperties
|
|
85
|
+
);
|
|
103
86
|
} catch (error) {
|
|
104
|
-
console.error("Error capturing event:", error);
|
|
105
87
|
}
|
|
106
88
|
}
|
|
107
|
-
async getEnvironmentInfo() {
|
|
108
|
-
if (this.isNode) {
|
|
109
|
-
try {
|
|
110
|
-
const os = await import("os");
|
|
111
|
-
return {
|
|
112
|
-
node_version: process.version,
|
|
113
|
-
os: process.platform,
|
|
114
|
-
os_version: os.release(),
|
|
115
|
-
os_arch: os.arch()
|
|
116
|
-
};
|
|
117
|
-
} catch (error) {
|
|
118
|
-
return {};
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
return {
|
|
122
|
-
browser: typeof window !== "undefined" ? window.navigator.userAgent : "unknown"
|
|
123
|
-
};
|
|
124
|
-
}
|
|
125
89
|
async shutdown() {
|
|
126
|
-
if (this.client && this.isNode) {
|
|
127
|
-
return this.client.shutdown();
|
|
128
|
-
}
|
|
129
90
|
}
|
|
130
91
|
};
|
|
131
92
|
function getVersion() {
|
|
132
93
|
return version;
|
|
133
94
|
}
|
|
134
|
-
var telemetry = new
|
|
95
|
+
var telemetry = new BrowserTelemetry(
|
|
135
96
|
POSTHOG_API_KEY,
|
|
136
97
|
POSTHOG_HOST
|
|
137
98
|
);
|
|
@@ -509,24 +470,13 @@ var MemoryClient = class {
|
|
|
509
470
|
}
|
|
510
471
|
};
|
|
511
472
|
|
|
512
|
-
// src/mem0.types.ts
|
|
513
|
-
var API_VERSION = /* @__PURE__ */ ((API_VERSION2) => {
|
|
514
|
-
API_VERSION2["V1"] = "v1";
|
|
515
|
-
API_VERSION2["V2"] = "v2";
|
|
516
|
-
return API_VERSION2;
|
|
517
|
-
})(API_VERSION || {});
|
|
518
|
-
|
|
519
473
|
// src/index.ts
|
|
520
474
|
var index_default = MemoryClient;
|
|
521
475
|
// Annotate the CommonJS export names for ESM import in node:
|
|
522
476
|
0 && (module.exports = {
|
|
523
|
-
|
|
524
|
-
|
|
477
|
+
MemoryClient,
|
|
478
|
+
captureClientEvent,
|
|
479
|
+
generateHash,
|
|
480
|
+
telemetry
|
|
525
481
|
});
|
|
526
|
-
//# sourceMappingURL=index.js.map
|
|
527
|
-
// fix-cjs-exports
|
|
528
|
-
if (module.exports.default) {
|
|
529
|
-
Object.assign(module.exports.default, module.exports);
|
|
530
|
-
module.exports = module.exports.default;
|
|
531
|
-
delete module.exports.default;
|
|
532
|
-
}
|
|
482
|
+
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/mem0.ts","../src/telemetry.ts","../src/mem0.types.ts"],"sourcesContent":["import {MemoryClient} from \"./mem0\";\n\nexport { MemoryClient } from './mem0';\nexport * from './mem0.types';\nexport default MemoryClient;","import axios from 'axios';\nimport { AllUsers, ProjectOptions, Memory, MemoryHistory, MemoryOptions, MemoryUpdateBody, ProjectResponse, PromptUpdatePayload, SearchOptions, Webhook, WebhookPayload } from './mem0.types';\nimport { captureClientEvent, generateHash } from './telemetry';\n\nclass APIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'APIError';\n }\n}\n\ninterface ClientOptions{\n apiKey: string;\n host?: string;\n organizationName?: string;\n projectName?: string;\n organizationId?: string;\n projectId?: string;\n}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n organizationName: string | null;\n projectName: string | null;\n organizationId: string | number | null;\n projectId: string | number | null;\n headers: Record<string, string>;\n client: any;\n telemetryId: string;\n\n _validateApiKey(): any {\n if (!this.apiKey) {\n throw new Error('Mem0 API key is required');\n }\n if (typeof this.apiKey !== 'string') {\n throw new Error('Mem0 API key must be a string');\n }\n if (this.apiKey.trim() === '') {\n throw new Error('Mem0 API key cannot be empty');\n }\n }\n\n _validateOrgProject(): void {\n // Check for organizationName/projectName pair\n if ((this.organizationName === null && this.projectName !== null) || \n (this.organizationName !== null && this.projectName === null)) {\n console.warn('Warning: Both organizationName and projectName must be provided together when using either. This will be removedfrom the version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId.');\n }\n\n // Check for organizationId/projectId pair\n if ((this.organizationId === null && this.projectId !== null) || \n (this.organizationId !== null && this.projectId === null)) {\n console.warn('Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.');\n }\n }\n\n constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationName = options.organizationName || null;\n this.projectName = options.projectName || null;\n this.organizationId = options.organizationId || null;\n this.projectId = options.projectId || null;\n\n this.headers = {\n 'Authorization': `Token ${this.apiKey}`,\n 'Content-Type': 'application/json'\n };\n\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n this._validateOrgProject();\n\n // Initialize with a temporary ID that will be updated\n this.telemetryId = '';\n \n // Initialize the client\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n this.telemetryId = await generateHash(this.apiKey);\n await captureClientEvent('init', this);\n\n // Wrap methods after initialization\n this.add = this.wrapMethod('add', this.add);\n this.get = this.wrapMethod('get', this.get);\n this.getAll = this.wrapMethod('get_all', this.getAll);\n this.search = this.wrapMethod('search', this.search);\n this.delete = this.wrapMethod('delete', this.delete);\n this.deleteAll = this.wrapMethod('delete_all', this.deleteAll);\n this.history = this.wrapMethod('history', this.history);\n this.users = this.wrapMethod('users', this.users);\n this.deleteUser = this.wrapMethod('delete_user', this.deleteUser);\n this.deleteUsers = this.wrapMethod('delete_users', this.deleteUsers);\n this.batchUpdate = this.wrapMethod('batch_update', this.batchUpdate);\n this.batchDelete = this.wrapMethod('batch_delete', this.batchDelete);\n this.getProject = this.wrapMethod('get_project', this.getProject);\n this.updateProject = this.wrapMethod('update_project', this.updateProject);\n this.getWebhooks = this.wrapMethod('get_webhook', this.getWebhooks);\n this.createWebhook = this.wrapMethod('create_webhook', this.createWebhook);\n this.updateWebhook = this.wrapMethod('update_webhook', this.updateWebhook);\n this.deleteWebhook = this.wrapMethod('delete_webhook', this.deleteWebhook);\n } catch (error) {\n console.error('Failed to initialize client:', error);\n }\n }\n\n wrapMethod(methodName: any, method: any) {\n return async function (...args: any) {\n // @ts-ignore\n await captureClientEvent(methodName, this);\n // @ts-ignore\n return method.apply(this, args);\n }.bind(this);\n}\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, options);\n if (!response.ok) {\n const errorData = await response.text();\n throw new APIError(`API request failed: ${errorData}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse;\n }\n\n _preparePayload(messages: string | Array<{ role: string; content: string }>,\n options: MemoryOptions): object {\n const payload: any = {};\n if (typeof messages === 'string') {\n payload.messages = [{ role: 'user', content: messages }];\n } else if (Array.isArray(messages)) {\n payload.messages = messages;\n }\n return { ...payload, ...options };\n }\n\n _prepareParams(options: MemoryOptions): object {\n return Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null));\n }\n\n async add(messages: string | Array<{ role: string; content: string }>, options:MemoryOptions = {}): Promise<Array<Memory>> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n\n const payload = this._preparePayload(messages, options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async update(memoryId: string, message: string): Promise<Array<Memory>> {\n this._validateOrgProject();\n const payload = {\n text: message\n }\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n async getAll(options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, page, page_size, ...otherOptions } = options!;\n if(this.organizationName != null && this.projectName != null){\n otherOptions.org_name = this.organizationName;\n otherOptions.project_name = this.projectName;\n }\n\n let appendedParams = \"\";\n let paginated_response = false;\n\n if(page && page_size){\n appendedParams += `page=${page}&page_size=${page_size}`\n paginated_response = true;\n }\n\n if(this.organizationId != null && this.projectId != null){\n otherOptions.org_id = this.organizationId;\n otherOptions.project_id = this.projectId;\n\n if (otherOptions.org_name) delete otherOptions.org_name;\n if(otherOptions.project_name) delete otherOptions.project_name;\n }\n\n if (api_version === 'v2') {\n let url = paginated_response ? `${this.host}/v2/memories/?${appendedParams}` : `${this.host}/v2/memories/`;\n return this._fetchWithErrorHandling(url, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(otherOptions)\n });\n } else {\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(otherOptions));\n const url = paginated_response ? `${this.host}/v1/memories/?${params}&${appendedParams}` : `${this.host}/v1/memories/?${params}`;\n return this._fetchWithErrorHandling(url, {\n headers: this.headers\n });\n }\n }\n\n async search(query: string, options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, ...otherOptions } = options!;\n const payload = { query, ...otherOptions };\n if(this.organizationName != null && this.projectName != null){\n payload.org_name = this.organizationName;\n payload.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n payload.org_id = this.organizationId;\n payload.project_id = this.projectId;\n\n if (payload.org_name) delete payload.org_name;\n if(payload.project_name) delete payload.project_name;\n }\n const endpoint = api_version === 'v2' ? '/v2/memories/search/' : '/v1/memories/search/';\n const response = await this._fetchWithErrorHandling(`${this.host}${endpoint}`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async delete(memoryId: string): Promise<{ message: string }> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n }\n\n async deleteAll(options: MemoryOptions = {}): Promise<{ message: string }> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(options));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/?${params}`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/history/`, {\n headers: this.headers\n });\n return response;\n }\n\n async users(): Promise<AllUsers>{\n this._validateOrgProject();\n const options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/?${params}`, {\n headers: this.headers\n });\n return response;\n }\n\n async deleteUser(entityId: string, entity: { type: string } = { type: 'user' }): Promise<{ message: string }> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/${entity.type}/${entityId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async deleteUsers(): Promise<{ message: string }> {\n this._validateOrgProject();\n const entities = await this.users();\n \n for (const entity of entities.results) {\n let options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n \n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n \n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n await this.client.delete(`/v1/entities/${entity.type}/${entity.id}/`, { params: options });\n }\n return { message: \"All users, agents, and sessions deleted.\" };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory.memoryId,\n text: memory.text\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'DELETE',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n this._validateOrgProject();\n\n const { fields } = options;\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to access instructions or categories\");\n }\n\n const params = new URLSearchParams();\n fields?.forEach(field => params.append('fields', field));\n \n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,\n {\n headers: this.headers\n }\n );\n return response;\n }\n\n async updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>> {\n this._validateOrgProject();\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to update instructions or categories\");\n }\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,\n {\n method: 'PATCH',\n headers: this.headers,\n body: JSON.stringify(prompts)\n }\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: {projectId?: string}): Promise<Array<Webhook>> {\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${project_id}/`, {\n headers: this.headers\n });\n return response;\n }\n\n async createWebhook(webhook: WebhookPayload): Promise<Webhook> {\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${this.projectId}/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(webhook)\n });\n return response;\n }\n\n async updateWebhook(webhook: WebhookPayload): Promise<{ message: string }> {\n const project_id = webhook.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook.webhookId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({\n ...webhook,\n projectId: project_id\n })\n });\n return response;\n }\n\n async deleteWebhook(data: {webhookId: string}): Promise<{ message: string }> {\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook_id}/`, {\n method: 'DELETE', \n headers: this.headers\n });\n return response;\n }\n}\n\nexport {MemoryClient};","// @ts-nocheck\nimport type { PostHog as PostHogJS } from \"posthog-js\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com\";\n\n// Utility function to generate hash in both environments\nasync function generateHash(input: string): Promise<string> {\n if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle) {\n // Browser environment - use Web Crypto API\n const msgBuffer = new TextEncoder().encode(input);\n const hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n } else {\n // Node.js environment - use crypto module\n // Dynamic import to avoid bundling issues\n const crypto = await import('crypto');\n return crypto.createHash('sha256').update(input).digest('hex');\n }\n}\n\nclass AnonymousTelemetry {\n client: any = null;\n isNode: boolean;\n\n constructor(projectApiKey: string, host: string) {\n this.isNode = this.detectNodeEnvironment();\n this.initializeClient(projectApiKey, host);\n }\n\n private detectNodeEnvironment(): boolean {\n return typeof process !== 'undefined' && \n process.versions != null && \n process.versions.node != null &&\n typeof window === 'undefined';\n }\n\n private async initializeClient(projectApiKey: string, host: string) {\n try {\n if (this.isNode) {\n // Dynamic import for Node environment\n const { PostHog } = await import('posthog-node');\n this.client = new PostHog(projectApiKey, { host, flushAt: 1 });\n } else {\n // Browser environment\n const posthog = await import('posthog-js');\n posthog.init(projectApiKey, { api_host: host });\n this.client = posthog;\n }\n } catch (error) {\n console.warn('Failed to initialize PostHog client:', error);\n this.client = null;\n }\n }\n\n async captureEvent(distinctId: string, eventName: string, properties = {}) {\n if (!this.client) return;\n\n const eventProperties = {\n client_source: this.isNode ? \"nodejs\" : \"browser\",\n client_version: getVersion(),\n ...this.getEnvironmentInfo(),\n ...properties,\n };\n\n try {\n if (this.isNode) {\n this.client.capture({\n distinctId,\n event: eventName,\n properties: eventProperties,\n });\n } else {\n this.client.capture(\n eventName,\n eventProperties\n );\n }\n } catch (error) {\n console.error(\"Error capturing event:\", error);\n }\n }\n\n private async getEnvironmentInfo() {\n if (this.isNode) {\n try {\n const os = await import('os');\n return {\n node_version: process.version,\n os: process.platform,\n os_version: os.release(),\n os_arch: os.arch(),\n };\n } catch (error) {\n return {};\n }\n }\n return {\n browser: typeof window !== 'undefined' ? window.navigator.userAgent : 'unknown',\n };\n }\n\n async shutdown() {\n if (this.client && this.isNode) {\n return this.client.shutdown();\n }\n }\n}\n\nfunction getVersion() {\n return version;\n}\n\n// Create telemetry instance only if we're in a browser or if we're in Node.js\nconst telemetry = new AnonymousTelemetry(\n POSTHOG_API_KEY,\n POSTHOG_HOST\n);\n\nasync function captureClientEvent(eventName: string, instance: any, additionalData = {}) {\n const eventData = {\n function: `${instance.constructor.name}`,\n ...additionalData,\n };\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash };","export interface MemoryOptions {\n user_id?: string;\n agent_id?: string;\n app_id?: string;\n run_id?: string;\n metadata?: Record<string, any>;\n filters?: Record<string, any>;\n org_name?: string | null; // Deprecated\n project_name?: string | null; // Deprecated\n org_id?: string | number | null;\n project_id?: string | number | null;\n infer?: boolean;\n page?: number;\n page_size?: number;\n includes?: string;\n excludes?: string;\n enable_graph?: boolean;\n start_date?: string;\n end_date?: string;\n}\n\nexport interface ProjectOptions {\n fields?: string[];\n}\n\nexport enum API_VERSION {\n V1 = \"v1\",\n V2 = \"v2\",\n}\n\nexport interface Messages {\n role: string;\n content: string;\n}\n\nexport interface Message extends Messages {}\n\nexport interface MemoryHistory {\n id: string;\n memory_id: string;\n input: Array<Messages>;\n old_memory: string | null;\n new_memory: string | null;\n user_id: string;\n categories: Array<string>;\n event: Event | string;\n created_at: Date;\n updated_at: Date;\n}\n\nexport interface SearchOptions extends MemoryOptions {\n api_version?: API_VERSION | string;\n limit?: number;\n enable_graph?: boolean;\n threshold?: number;\n top_k?: number;\n only_metadata_based_search?: boolean;\n keyword_search?: boolean;\n fields?: string[];\n categories?: string[];\n rerank?: boolean;\n}\n\nenum Event {\n ADD = \"ADD\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n NOOP = \"NOOP\",\n}\n\nexport interface MemoryData {\n memory: string;\n}\n\nexport interface Memory {\n id: string;\n messages?: Array<Messages>;\n event?: Event | string;\n data?: MemoryData | null;\n memory?: string;\n user_id?: string;\n hash?: string;\n categories?: Array<string>;\n created_at?: Date;\n updated_at?: Date;\n memory_type?: string;\n score?: number;\n metadata?: any | null;\n}\n\nexport interface MemoryUpdateBody {\n memoryId: string;\n text: string;\n}\n\nexport interface User {\n id: string;\n name: string;\n created_at: Date;\n updated_at: Date;\n total_memories: number;\n owner: string;\n type: string;\n}\n\nexport interface AllUsers {\n count: number;\n results: Array<User>;\n next: any;\n previous: any;\n}\n\nexport interface ProjectResponse {\n custom_instructions?: string;\n custom_categories?: string[];\n [key: string]: any;\n}\n\ninterface custom_categories {\n [key: string]: any;\n}\n\nexport interface PromptUpdatePayload {\n custom_instructions?: string;\n custom_categories?: custom_categories[];\n [key: string]: any;\n}\n\nenum WebhookEvent {\n MEMORY_ADDED = \"memory_add\",\n MEMORY_UPDATED = \"memory_update\",\n MEMORY_DELETED = \"memory_delete\",\n}\n\nexport interface Webhook {\n webhook_id?: string;\n name: string;\n url: string;\n project?: string;\n created_at?: Date;\n updated_at?: Date;\n is_active?: boolean;\n event_types?: WebhookEvent[];\n}\n\nexport interface WebhookPayload {\n eventTypes: WebhookEvent[];\n projectId: string;\n webhookId: string;\n name: string;\n url: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACGlB,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AACtD,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,eAAe,aAAa,OAAgC;AAC1D,MAAI,OAAO,WAAW,eAAe,OAAO,UAAU,OAAO,OAAO,QAAQ;AAE1E,UAAM,YAAY,IAAI,YAAY,EAAE,OAAO,KAAK;AAChD,UAAM,aAAa,MAAM,OAAO,OAAO,OAAO,OAAO,WAAW,SAAS;AACzE,UAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AACvD,WAAO,UAAU,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AAAA,EACpE,OAAO;AAGL,UAAM,SAAS,MAAM,OAAO,QAAQ;AACpC,WAAO,OAAO,WAAW,QAAQ,EAAE,OAAO,KAAK,EAAE,OAAO,KAAK;AAAA,EAC/D;AACF;AAEA,IAAM,qBAAN,MAAyB;AAAA,EAIvB,YAAY,eAAuB,MAAc;AAHjD,kBAAc;AAIZ,SAAK,SAAS,KAAK,sBAAsB;AACzC,SAAK,iBAAiB,eAAe,IAAI;AAAA,EAC3C;AAAA,EAEQ,wBAAiC;AACvC,WAAO,OAAO,YAAY,eACnB,QAAQ,YAAY,QACpB,QAAQ,SAAS,QAAQ,QACz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,UAAU;AAAA,QACnB,GAAG;AAAA,QACH,WAAW;AAAA,MACb,CAAC;AAAA,IACH,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,MAAyD;AAC3E,UAAM,aAAa,KAAK,aAAa;AACrC,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,oBAAoB,UAAU,KAAK;AAAA,MACjG,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,IAChB,CAAC;AACD,WAAO;AAAA,EACT;AACF;;;AE3aO,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,QAAK;AACL,EAAAA,aAAA,QAAK;AAFK,SAAAA;AAAA,GAAA;;;AHrBZ,IAAO,gBAAQ;","names":["axios","API_VERSION"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/mem0.ts","../src/telemetry.browser.ts"],"sourcesContent":["import { MemoryClient } from \"./mem0\";\nimport type { TelemetryClient, TelemetryInstance } from './telemetry.types';\nimport { telemetry, captureClientEvent, generateHash } from './telemetry.browser';\nimport type * as MemoryTypes from './mem0.types';\n\n// Re-export all types from mem0.types\nexport type {\n MemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n SearchOptions,\n Webhook,\n WebhookPayload,\n Messages,\n Message,\n AllUsers,\n User\n} from './mem0.types';\n\n// Export telemetry types\nexport type { TelemetryClient, TelemetryInstance };\n\n// Export telemetry implementation\nexport { telemetry, captureClientEvent, generateHash };\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;","import axios from 'axios';\nimport { AllUsers, ProjectOptions, Memory, MemoryHistory, MemoryOptions, MemoryUpdateBody, ProjectResponse, PromptUpdatePayload, SearchOptions, Webhook, WebhookPayload } from './mem0.types';\nimport { captureClientEvent, generateHash } from './telemetry';\n\nclass APIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'APIError';\n }\n}\n\ninterface ClientOptions{\n apiKey: string;\n host?: string;\n organizationName?: string;\n projectName?: string;\n organizationId?: string;\n projectId?: string;\n}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n organizationName: string | null;\n projectName: string | null;\n organizationId: string | number | null;\n projectId: string | number | null;\n headers: Record<string, string>;\n client: any;\n telemetryId: string;\n\n _validateApiKey(): any {\n if (!this.apiKey) {\n throw new Error('Mem0 API key is required');\n }\n if (typeof this.apiKey !== 'string') {\n throw new Error('Mem0 API key must be a string');\n }\n if (this.apiKey.trim() === '') {\n throw new Error('Mem0 API key cannot be empty');\n }\n }\n\n _validateOrgProject(): void {\n // Check for organizationName/projectName pair\n if ((this.organizationName === null && this.projectName !== null) || \n (this.organizationName !== null && this.projectName === null)) {\n console.warn('Warning: Both organizationName and projectName must be provided together when using either. This will be removedfrom the version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId.');\n }\n\n // Check for organizationId/projectId pair\n if ((this.organizationId === null && this.projectId !== null) || \n (this.organizationId !== null && this.projectId === null)) {\n console.warn('Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.');\n }\n }\n\n constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationName = options.organizationName || null;\n this.projectName = options.projectName || null;\n this.organizationId = options.organizationId || null;\n this.projectId = options.projectId || null;\n\n this.headers = {\n 'Authorization': `Token ${this.apiKey}`,\n 'Content-Type': 'application/json'\n };\n\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n this._validateOrgProject();\n\n // Initialize with a temporary ID that will be updated\n this.telemetryId = '';\n \n // Initialize the client\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n this.telemetryId = await generateHash(this.apiKey);\n await captureClientEvent('init', this);\n\n // Wrap methods after initialization\n this.add = this.wrapMethod('add', this.add);\n this.get = this.wrapMethod('get', this.get);\n this.getAll = this.wrapMethod('get_all', this.getAll);\n this.search = this.wrapMethod('search', this.search);\n this.delete = this.wrapMethod('delete', this.delete);\n this.deleteAll = this.wrapMethod('delete_all', this.deleteAll);\n this.history = this.wrapMethod('history', this.history);\n this.users = this.wrapMethod('users', this.users);\n this.deleteUser = this.wrapMethod('delete_user', this.deleteUser);\n this.deleteUsers = this.wrapMethod('delete_users', this.deleteUsers);\n this.batchUpdate = this.wrapMethod('batch_update', this.batchUpdate);\n this.batchDelete = this.wrapMethod('batch_delete', this.batchDelete);\n this.getProject = this.wrapMethod('get_project', this.getProject);\n this.updateProject = this.wrapMethod('update_project', this.updateProject);\n this.getWebhooks = this.wrapMethod('get_webhook', this.getWebhooks);\n this.createWebhook = this.wrapMethod('create_webhook', this.createWebhook);\n this.updateWebhook = this.wrapMethod('update_webhook', this.updateWebhook);\n this.deleteWebhook = this.wrapMethod('delete_webhook', this.deleteWebhook);\n } catch (error) {\n console.error('Failed to initialize client:', error);\n }\n }\n\n wrapMethod(methodName: any, method: any) {\n return async function (...args: any) {\n // @ts-ignore\n await captureClientEvent(methodName, this);\n // @ts-ignore\n return method.apply(this, args);\n }.bind(this);\n}\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, options);\n if (!response.ok) {\n const errorData = await response.text();\n throw new APIError(`API request failed: ${errorData}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse;\n }\n\n _preparePayload(messages: string | Array<{ role: string; content: string }>,\n options: MemoryOptions): object {\n const payload: any = {};\n if (typeof messages === 'string') {\n payload.messages = [{ role: 'user', content: messages }];\n } else if (Array.isArray(messages)) {\n payload.messages = messages;\n }\n return { ...payload, ...options };\n }\n\n _prepareParams(options: MemoryOptions): object {\n return Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null));\n }\n\n async add(messages: string | Array<{ role: string; content: string }>, options:MemoryOptions = {}): Promise<Array<Memory>> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n\n const payload = this._preparePayload(messages, options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async update(memoryId: string, message: string): Promise<Array<Memory>> {\n this._validateOrgProject();\n const payload = {\n text: message\n }\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n async getAll(options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, page, page_size, ...otherOptions } = options!;\n if(this.organizationName != null && this.projectName != null){\n otherOptions.org_name = this.organizationName;\n otherOptions.project_name = this.projectName;\n }\n\n let appendedParams = \"\";\n let paginated_response = false;\n\n if(page && page_size){\n appendedParams += `page=${page}&page_size=${page_size}`\n paginated_response = true;\n }\n\n if(this.organizationId != null && this.projectId != null){\n otherOptions.org_id = this.organizationId;\n otherOptions.project_id = this.projectId;\n\n if (otherOptions.org_name) delete otherOptions.org_name;\n if(otherOptions.project_name) delete otherOptions.project_name;\n }\n\n if (api_version === 'v2') {\n let url = paginated_response ? `${this.host}/v2/memories/?${appendedParams}` : `${this.host}/v2/memories/`;\n return this._fetchWithErrorHandling(url, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(otherOptions)\n });\n } else {\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(otherOptions));\n const url = paginated_response ? `${this.host}/v1/memories/?${params}&${appendedParams}` : `${this.host}/v1/memories/?${params}`;\n return this._fetchWithErrorHandling(url, {\n headers: this.headers\n });\n }\n }\n\n async search(query: string, options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, ...otherOptions } = options!;\n const payload = { query, ...otherOptions };\n if(this.organizationName != null && this.projectName != null){\n payload.org_name = this.organizationName;\n payload.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n payload.org_id = this.organizationId;\n payload.project_id = this.projectId;\n\n if (payload.org_name) delete payload.org_name;\n if(payload.project_name) delete payload.project_name;\n }\n const endpoint = api_version === 'v2' ? '/v2/memories/search/' : '/v1/memories/search/';\n const response = await this._fetchWithErrorHandling(`${this.host}${endpoint}`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async delete(memoryId: string): Promise<{ message: string }> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n }\n\n async deleteAll(options: MemoryOptions = {}): Promise<{ message: string }> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(options));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/?${params}`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/history/`, {\n headers: this.headers\n });\n return response;\n }\n\n async users(): Promise<AllUsers>{\n this._validateOrgProject();\n const options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/?${params}`, {\n headers: this.headers\n });\n return response;\n }\n\n async deleteUser(entityId: string, entity: { type: string } = { type: 'user' }): Promise<{ message: string }> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/${entity.type}/${entityId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async deleteUsers(): Promise<{ message: string }> {\n this._validateOrgProject();\n const entities = await this.users();\n \n for (const entity of entities.results) {\n let options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n \n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n \n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n await this.client.delete(`/v1/entities/${entity.type}/${entity.id}/`, { params: options });\n }\n return { message: \"All users, agents, and sessions deleted.\" };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory.memoryId,\n text: memory.text\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'DELETE',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n this._validateOrgProject();\n\n const { fields } = options;\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to access instructions or categories\");\n }\n\n const params = new URLSearchParams();\n fields?.forEach(field => params.append('fields', field));\n \n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,\n {\n headers: this.headers\n }\n );\n return response;\n }\n\n async updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>> {\n this._validateOrgProject();\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to update instructions or categories\");\n }\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,\n {\n method: 'PATCH',\n headers: this.headers,\n body: JSON.stringify(prompts)\n }\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: {projectId?: string}): Promise<Array<Webhook>> {\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${project_id}/`, {\n headers: this.headers\n });\n return response;\n }\n\n async createWebhook(webhook: WebhookPayload): Promise<Webhook> {\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${this.projectId}/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(webhook)\n });\n return response;\n }\n\n async updateWebhook(webhook: WebhookPayload): Promise<{ message: string }> {\n const project_id = webhook.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook.webhookId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({\n ...webhook,\n projectId: project_id\n })\n });\n return response;\n }\n\n async deleteWebhook(data: {webhookId: string}): Promise<{ message: string }> {\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook_id}/`, {\n method: 'DELETE', \n headers: this.headers\n });\n return response;\n }\n}\n\nexport {MemoryClient};","// @ts-nocheck\nimport type { PostHog } from \"posthog-js\";\nimport type { TelemetryClient } from \"./telemetry.types\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com\";\n\n// Browser-specific hash function using Web Crypto API\nasync function generateHash(input: string): Promise<string> {\n const msgBuffer = new TextEncoder().encode(input);\n const hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n}\n\nclass BrowserTelemetry implements TelemetryClient {\n client: PostHog | null = null;\n\n constructor(projectApiKey: string, host: string) {\n if (MEM0_TELEMETRY) {\n this.initializeClient(projectApiKey, host);\n }\n }\n\n private async initializeClient(projectApiKey: string, host: string) {\n try {\n const posthog = await import('posthog-js').catch(() => null);\n if (posthog) {\n posthog.init(projectApiKey, { api_host: host });\n this.client = posthog;\n }\n } catch (error) {\n // Silently fail if posthog-js is not available\n this.client = null;\n }\n }\n\n async captureEvent(distinctId: string, eventName: string, properties = {}) {\n if (!this.client || !MEM0_TELEMETRY) return;\n\n const eventProperties = {\n client_source: \"browser\",\n client_version: getVersion(),\n browser: window.navigator.userAgent,\n ...properties,\n };\n\n try {\n this.client.capture(\n eventName,\n eventProperties\n );\n } catch (error) {\n // Silently fail if telemetry fails\n }\n }\n\n async shutdown() {\n // No shutdown needed for browser client\n }\n}\n\nfunction getVersion() {\n return version;\n}\n\nconst telemetry = new BrowserTelemetry(\n POSTHOG_API_KEY,\n POSTHOG_HOST\n);\n\nasync function captureClientEvent(eventName: string, instance: any, additionalData = {}) {\n const eventData = {\n function: `${instance.constructor.name}`,\n ...additionalData,\n };\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash }; "],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACIlB,IAAI,UAAU;AAEd,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WAAO;AAAA,EACT;AACF;;;ADraA,IAAO,gBAAQ;","names":["axios"]}
|
package/dist/index.mjs
CHANGED
|
@@ -1,99 +1,58 @@
|
|
|
1
1
|
// src/mem0.ts
|
|
2
2
|
import axios from "axios";
|
|
3
3
|
|
|
4
|
-
// src/telemetry.ts
|
|
4
|
+
// src/telemetry.browser.ts
|
|
5
5
|
var version = "1.0.20";
|
|
6
6
|
var MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== "false";
|
|
7
7
|
var POSTHOG_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX";
|
|
8
8
|
var POSTHOG_HOST = "https://us.i.posthog.com";
|
|
9
9
|
async function generateHash(input) {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
15
|
-
} else {
|
|
16
|
-
const crypto = await import("crypto");
|
|
17
|
-
return crypto.createHash("sha256").update(input).digest("hex");
|
|
18
|
-
}
|
|
10
|
+
const msgBuffer = new TextEncoder().encode(input);
|
|
11
|
+
const hashBuffer = await window.crypto.subtle.digest("SHA-256", msgBuffer);
|
|
12
|
+
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
|
13
|
+
return hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
19
14
|
}
|
|
20
|
-
var
|
|
15
|
+
var BrowserTelemetry = class {
|
|
21
16
|
constructor(projectApiKey, host) {
|
|
22
17
|
this.client = null;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
detectNodeEnvironment() {
|
|
27
|
-
return typeof process !== "undefined" && process.versions != null && process.versions.node != null && typeof window === "undefined";
|
|
18
|
+
if (MEM0_TELEMETRY) {
|
|
19
|
+
this.initializeClient(projectApiKey, host);
|
|
20
|
+
}
|
|
28
21
|
}
|
|
29
22
|
async initializeClient(projectApiKey, host) {
|
|
30
23
|
try {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
this.client = new PostHog(projectApiKey, { host, flushAt: 1 });
|
|
34
|
-
} else {
|
|
35
|
-
const posthog = await import("posthog-js");
|
|
24
|
+
const posthog = await import("posthog-js").catch(() => null);
|
|
25
|
+
if (posthog) {
|
|
36
26
|
posthog.init(projectApiKey, { api_host: host });
|
|
37
27
|
this.client = posthog;
|
|
38
28
|
}
|
|
39
29
|
} catch (error) {
|
|
40
|
-
console.warn("Failed to initialize PostHog client:", error);
|
|
41
30
|
this.client = null;
|
|
42
31
|
}
|
|
43
32
|
}
|
|
44
33
|
async captureEvent(distinctId, eventName, properties = {}) {
|
|
45
|
-
if (!this.client) return;
|
|
34
|
+
if (!this.client || !MEM0_TELEMETRY) return;
|
|
46
35
|
const eventProperties = {
|
|
47
|
-
client_source:
|
|
36
|
+
client_source: "browser",
|
|
48
37
|
client_version: getVersion(),
|
|
49
|
-
|
|
38
|
+
browser: window.navigator.userAgent,
|
|
50
39
|
...properties
|
|
51
40
|
};
|
|
52
41
|
try {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
properties: eventProperties
|
|
58
|
-
});
|
|
59
|
-
} else {
|
|
60
|
-
this.client.capture(
|
|
61
|
-
eventName,
|
|
62
|
-
eventProperties
|
|
63
|
-
);
|
|
64
|
-
}
|
|
42
|
+
this.client.capture(
|
|
43
|
+
eventName,
|
|
44
|
+
eventProperties
|
|
45
|
+
);
|
|
65
46
|
} catch (error) {
|
|
66
|
-
console.error("Error capturing event:", error);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
async getEnvironmentInfo() {
|
|
70
|
-
if (this.isNode) {
|
|
71
|
-
try {
|
|
72
|
-
const os = await import("os");
|
|
73
|
-
return {
|
|
74
|
-
node_version: process.version,
|
|
75
|
-
os: process.platform,
|
|
76
|
-
os_version: os.release(),
|
|
77
|
-
os_arch: os.arch()
|
|
78
|
-
};
|
|
79
|
-
} catch (error) {
|
|
80
|
-
return {};
|
|
81
|
-
}
|
|
82
47
|
}
|
|
83
|
-
return {
|
|
84
|
-
browser: typeof window !== "undefined" ? window.navigator.userAgent : "unknown"
|
|
85
|
-
};
|
|
86
48
|
}
|
|
87
49
|
async shutdown() {
|
|
88
|
-
if (this.client && this.isNode) {
|
|
89
|
-
return this.client.shutdown();
|
|
90
|
-
}
|
|
91
50
|
}
|
|
92
51
|
};
|
|
93
52
|
function getVersion() {
|
|
94
53
|
return version;
|
|
95
54
|
}
|
|
96
|
-
var telemetry = new
|
|
55
|
+
var telemetry = new BrowserTelemetry(
|
|
97
56
|
POSTHOG_API_KEY,
|
|
98
57
|
POSTHOG_HOST
|
|
99
58
|
);
|
|
@@ -471,18 +430,13 @@ var MemoryClient = class {
|
|
|
471
430
|
}
|
|
472
431
|
};
|
|
473
432
|
|
|
474
|
-
// src/mem0.types.ts
|
|
475
|
-
var API_VERSION = /* @__PURE__ */ ((API_VERSION2) => {
|
|
476
|
-
API_VERSION2["V1"] = "v1";
|
|
477
|
-
API_VERSION2["V2"] = "v2";
|
|
478
|
-
return API_VERSION2;
|
|
479
|
-
})(API_VERSION || {});
|
|
480
|
-
|
|
481
433
|
// src/index.ts
|
|
482
434
|
var index_default = MemoryClient;
|
|
483
435
|
export {
|
|
484
|
-
API_VERSION,
|
|
485
436
|
MemoryClient,
|
|
486
|
-
|
|
437
|
+
captureClientEvent,
|
|
438
|
+
index_default as default,
|
|
439
|
+
generateHash,
|
|
440
|
+
telemetry
|
|
487
441
|
};
|
|
488
442
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/mem0.ts","../src/telemetry.ts","../src/mem0.types.ts","../src/index.ts"],"sourcesContent":["import axios from 'axios';\nimport { AllUsers, ProjectOptions, Memory, MemoryHistory, MemoryOptions, MemoryUpdateBody, ProjectResponse, PromptUpdatePayload, SearchOptions, Webhook, WebhookPayload } from './mem0.types';\nimport { captureClientEvent, generateHash } from './telemetry';\n\nclass APIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'APIError';\n }\n}\n\ninterface ClientOptions{\n apiKey: string;\n host?: string;\n organizationName?: string;\n projectName?: string;\n organizationId?: string;\n projectId?: string;\n}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n organizationName: string | null;\n projectName: string | null;\n organizationId: string | number | null;\n projectId: string | number | null;\n headers: Record<string, string>;\n client: any;\n telemetryId: string;\n\n _validateApiKey(): any {\n if (!this.apiKey) {\n throw new Error('Mem0 API key is required');\n }\n if (typeof this.apiKey !== 'string') {\n throw new Error('Mem0 API key must be a string');\n }\n if (this.apiKey.trim() === '') {\n throw new Error('Mem0 API key cannot be empty');\n }\n }\n\n _validateOrgProject(): void {\n // Check for organizationName/projectName pair\n if ((this.organizationName === null && this.projectName !== null) || \n (this.organizationName !== null && this.projectName === null)) {\n console.warn('Warning: Both organizationName and projectName must be provided together when using either. This will be removedfrom the version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId.');\n }\n\n // Check for organizationId/projectId pair\n if ((this.organizationId === null && this.projectId !== null) || \n (this.organizationId !== null && this.projectId === null)) {\n console.warn('Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.');\n }\n }\n\n constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationName = options.organizationName || null;\n this.projectName = options.projectName || null;\n this.organizationId = options.organizationId || null;\n this.projectId = options.projectId || null;\n\n this.headers = {\n 'Authorization': `Token ${this.apiKey}`,\n 'Content-Type': 'application/json'\n };\n\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n this._validateOrgProject();\n\n // Initialize with a temporary ID that will be updated\n this.telemetryId = '';\n \n // Initialize the client\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n this.telemetryId = await generateHash(this.apiKey);\n await captureClientEvent('init', this);\n\n // Wrap methods after initialization\n this.add = this.wrapMethod('add', this.add);\n this.get = this.wrapMethod('get', this.get);\n this.getAll = this.wrapMethod('get_all', this.getAll);\n this.search = this.wrapMethod('search', this.search);\n this.delete = this.wrapMethod('delete', this.delete);\n this.deleteAll = this.wrapMethod('delete_all', this.deleteAll);\n this.history = this.wrapMethod('history', this.history);\n this.users = this.wrapMethod('users', this.users);\n this.deleteUser = this.wrapMethod('delete_user', this.deleteUser);\n this.deleteUsers = this.wrapMethod('delete_users', this.deleteUsers);\n this.batchUpdate = this.wrapMethod('batch_update', this.batchUpdate);\n this.batchDelete = this.wrapMethod('batch_delete', this.batchDelete);\n this.getProject = this.wrapMethod('get_project', this.getProject);\n this.updateProject = this.wrapMethod('update_project', this.updateProject);\n this.getWebhooks = this.wrapMethod('get_webhook', this.getWebhooks);\n this.createWebhook = this.wrapMethod('create_webhook', this.createWebhook);\n this.updateWebhook = this.wrapMethod('update_webhook', this.updateWebhook);\n this.deleteWebhook = this.wrapMethod('delete_webhook', this.deleteWebhook);\n } catch (error) {\n console.error('Failed to initialize client:', error);\n }\n }\n\n wrapMethod(methodName: any, method: any) {\n return async function (...args: any) {\n // @ts-ignore\n await captureClientEvent(methodName, this);\n // @ts-ignore\n return method.apply(this, args);\n }.bind(this);\n}\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, options);\n if (!response.ok) {\n const errorData = await response.text();\n throw new APIError(`API request failed: ${errorData}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse;\n }\n\n _preparePayload(messages: string | Array<{ role: string; content: string }>,\n options: MemoryOptions): object {\n const payload: any = {};\n if (typeof messages === 'string') {\n payload.messages = [{ role: 'user', content: messages }];\n } else if (Array.isArray(messages)) {\n payload.messages = messages;\n }\n return { ...payload, ...options };\n }\n\n _prepareParams(options: MemoryOptions): object {\n return Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null));\n }\n\n async add(messages: string | Array<{ role: string; content: string }>, options:MemoryOptions = {}): Promise<Array<Memory>> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n\n const payload = this._preparePayload(messages, options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async update(memoryId: string, message: string): Promise<Array<Memory>> {\n this._validateOrgProject();\n const payload = {\n text: message\n }\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n async getAll(options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, page, page_size, ...otherOptions } = options!;\n if(this.organizationName != null && this.projectName != null){\n otherOptions.org_name = this.organizationName;\n otherOptions.project_name = this.projectName;\n }\n\n let appendedParams = \"\";\n let paginated_response = false;\n\n if(page && page_size){\n appendedParams += `page=${page}&page_size=${page_size}`\n paginated_response = true;\n }\n\n if(this.organizationId != null && this.projectId != null){\n otherOptions.org_id = this.organizationId;\n otherOptions.project_id = this.projectId;\n\n if (otherOptions.org_name) delete otherOptions.org_name;\n if(otherOptions.project_name) delete otherOptions.project_name;\n }\n\n if (api_version === 'v2') {\n let url = paginated_response ? `${this.host}/v2/memories/?${appendedParams}` : `${this.host}/v2/memories/`;\n return this._fetchWithErrorHandling(url, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(otherOptions)\n });\n } else {\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(otherOptions));\n const url = paginated_response ? `${this.host}/v1/memories/?${params}&${appendedParams}` : `${this.host}/v1/memories/?${params}`;\n return this._fetchWithErrorHandling(url, {\n headers: this.headers\n });\n }\n }\n\n async search(query: string, options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, ...otherOptions } = options!;\n const payload = { query, ...otherOptions };\n if(this.organizationName != null && this.projectName != null){\n payload.org_name = this.organizationName;\n payload.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n payload.org_id = this.organizationId;\n payload.project_id = this.projectId;\n\n if (payload.org_name) delete payload.org_name;\n if(payload.project_name) delete payload.project_name;\n }\n const endpoint = api_version === 'v2' ? '/v2/memories/search/' : '/v1/memories/search/';\n const response = await this._fetchWithErrorHandling(`${this.host}${endpoint}`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async delete(memoryId: string): Promise<{ message: string }> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n }\n\n async deleteAll(options: MemoryOptions = {}): Promise<{ message: string }> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(options));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/?${params}`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/history/`, {\n headers: this.headers\n });\n return response;\n }\n\n async users(): Promise<AllUsers>{\n this._validateOrgProject();\n const options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/?${params}`, {\n headers: this.headers\n });\n return response;\n }\n\n async deleteUser(entityId: string, entity: { type: string } = { type: 'user' }): Promise<{ message: string }> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/${entity.type}/${entityId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async deleteUsers(): Promise<{ message: string }> {\n this._validateOrgProject();\n const entities = await this.users();\n \n for (const entity of entities.results) {\n let options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n \n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n \n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n await this.client.delete(`/v1/entities/${entity.type}/${entity.id}/`, { params: options });\n }\n return { message: \"All users, agents, and sessions deleted.\" };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory.memoryId,\n text: memory.text\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'DELETE',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n this._validateOrgProject();\n\n const { fields } = options;\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to access instructions or categories\");\n }\n\n const params = new URLSearchParams();\n fields?.forEach(field => params.append('fields', field));\n \n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,\n {\n headers: this.headers\n }\n );\n return response;\n }\n\n async updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>> {\n this._validateOrgProject();\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to update instructions or categories\");\n }\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,\n {\n method: 'PATCH',\n headers: this.headers,\n body: JSON.stringify(prompts)\n }\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: {projectId?: string}): Promise<Array<Webhook>> {\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${project_id}/`, {\n headers: this.headers\n });\n return response;\n }\n\n async createWebhook(webhook: WebhookPayload): Promise<Webhook> {\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${this.projectId}/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(webhook)\n });\n return response;\n }\n\n async updateWebhook(webhook: WebhookPayload): Promise<{ message: string }> {\n const project_id = webhook.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook.webhookId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({\n ...webhook,\n projectId: project_id\n })\n });\n return response;\n }\n\n async deleteWebhook(data: {webhookId: string}): Promise<{ message: string }> {\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook_id}/`, {\n method: 'DELETE', \n headers: this.headers\n });\n return response;\n }\n}\n\nexport {MemoryClient};","// @ts-nocheck\nimport type { PostHog as PostHogJS } from \"posthog-js\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com\";\n\n// Utility function to generate hash in both environments\nasync function generateHash(input: string): Promise<string> {\n if (typeof window !== 'undefined' && window.crypto && window.crypto.subtle) {\n // Browser environment - use Web Crypto API\n const msgBuffer = new TextEncoder().encode(input);\n const hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n } else {\n // Node.js environment - use crypto module\n // Dynamic import to avoid bundling issues\n const crypto = await import('crypto');\n return crypto.createHash('sha256').update(input).digest('hex');\n }\n}\n\nclass AnonymousTelemetry {\n client: any = null;\n isNode: boolean;\n\n constructor(projectApiKey: string, host: string) {\n this.isNode = this.detectNodeEnvironment();\n this.initializeClient(projectApiKey, host);\n }\n\n private detectNodeEnvironment(): boolean {\n return typeof process !== 'undefined' && \n process.versions != null && \n process.versions.node != null &&\n typeof window === 'undefined';\n }\n\n private async initializeClient(projectApiKey: string, host: string) {\n try {\n if (this.isNode) {\n // Dynamic import for Node environment\n const { PostHog } = await import('posthog-node');\n this.client = new PostHog(projectApiKey, { host, flushAt: 1 });\n } else {\n // Browser environment\n const posthog = await import('posthog-js');\n posthog.init(projectApiKey, { api_host: host });\n this.client = posthog;\n }\n } catch (error) {\n console.warn('Failed to initialize PostHog client:', error);\n this.client = null;\n }\n }\n\n async captureEvent(distinctId: string, eventName: string, properties = {}) {\n if (!this.client) return;\n\n const eventProperties = {\n client_source: this.isNode ? \"nodejs\" : \"browser\",\n client_version: getVersion(),\n ...this.getEnvironmentInfo(),\n ...properties,\n };\n\n try {\n if (this.isNode) {\n this.client.capture({\n distinctId,\n event: eventName,\n properties: eventProperties,\n });\n } else {\n this.client.capture(\n eventName,\n eventProperties\n );\n }\n } catch (error) {\n console.error(\"Error capturing event:\", error);\n }\n }\n\n private async getEnvironmentInfo() {\n if (this.isNode) {\n try {\n const os = await import('os');\n return {\n node_version: process.version,\n os: process.platform,\n os_version: os.release(),\n os_arch: os.arch(),\n };\n } catch (error) {\n return {};\n }\n }\n return {\n browser: typeof window !== 'undefined' ? window.navigator.userAgent : 'unknown',\n };\n }\n\n async shutdown() {\n if (this.client && this.isNode) {\n return this.client.shutdown();\n }\n }\n}\n\nfunction getVersion() {\n return version;\n}\n\n// Create telemetry instance only if we're in a browser or if we're in Node.js\nconst telemetry = new AnonymousTelemetry(\n POSTHOG_API_KEY,\n POSTHOG_HOST\n);\n\nasync function captureClientEvent(eventName: string, instance: any, additionalData = {}) {\n const eventData = {\n function: `${instance.constructor.name}`,\n ...additionalData,\n };\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash };","export interface MemoryOptions {\n user_id?: string;\n agent_id?: string;\n app_id?: string;\n run_id?: string;\n metadata?: Record<string, any>;\n filters?: Record<string, any>;\n org_name?: string | null; // Deprecated\n project_name?: string | null; // Deprecated\n org_id?: string | number | null;\n project_id?: string | number | null;\n infer?: boolean;\n page?: number;\n page_size?: number;\n includes?: string;\n excludes?: string;\n enable_graph?: boolean;\n start_date?: string;\n end_date?: string;\n}\n\nexport interface ProjectOptions {\n fields?: string[];\n}\n\nexport enum API_VERSION {\n V1 = \"v1\",\n V2 = \"v2\",\n}\n\nexport interface Messages {\n role: string;\n content: string;\n}\n\nexport interface Message extends Messages {}\n\nexport interface MemoryHistory {\n id: string;\n memory_id: string;\n input: Array<Messages>;\n old_memory: string | null;\n new_memory: string | null;\n user_id: string;\n categories: Array<string>;\n event: Event | string;\n created_at: Date;\n updated_at: Date;\n}\n\nexport interface SearchOptions extends MemoryOptions {\n api_version?: API_VERSION | string;\n limit?: number;\n enable_graph?: boolean;\n threshold?: number;\n top_k?: number;\n only_metadata_based_search?: boolean;\n keyword_search?: boolean;\n fields?: string[];\n categories?: string[];\n rerank?: boolean;\n}\n\nenum Event {\n ADD = \"ADD\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n NOOP = \"NOOP\",\n}\n\nexport interface MemoryData {\n memory: string;\n}\n\nexport interface Memory {\n id: string;\n messages?: Array<Messages>;\n event?: Event | string;\n data?: MemoryData | null;\n memory?: string;\n user_id?: string;\n hash?: string;\n categories?: Array<string>;\n created_at?: Date;\n updated_at?: Date;\n memory_type?: string;\n score?: number;\n metadata?: any | null;\n}\n\nexport interface MemoryUpdateBody {\n memoryId: string;\n text: string;\n}\n\nexport interface User {\n id: string;\n name: string;\n created_at: Date;\n updated_at: Date;\n total_memories: number;\n owner: string;\n type: string;\n}\n\nexport interface AllUsers {\n count: number;\n results: Array<User>;\n next: any;\n previous: any;\n}\n\nexport interface ProjectResponse {\n custom_instructions?: string;\n custom_categories?: string[];\n [key: string]: any;\n}\n\ninterface custom_categories {\n [key: string]: any;\n}\n\nexport interface PromptUpdatePayload {\n custom_instructions?: string;\n custom_categories?: custom_categories[];\n [key: string]: any;\n}\n\nenum WebhookEvent {\n MEMORY_ADDED = \"memory_add\",\n MEMORY_UPDATED = \"memory_update\",\n MEMORY_DELETED = \"memory_delete\",\n}\n\nexport interface Webhook {\n webhook_id?: string;\n name: string;\n url: string;\n project?: string;\n created_at?: Date;\n updated_at?: Date;\n is_active?: boolean;\n event_types?: WebhookEvent[];\n}\n\nexport interface WebhookPayload {\n eventTypes: WebhookEvent[];\n projectId: string;\n webhookId: string;\n name: string;\n url: string;\n}\n","import {MemoryClient} from \"./mem0\";\n\nexport { MemoryClient } from './mem0';\nexport * from './mem0.types';\nexport default MemoryClient;"],"mappings":";AAAA,OAAO,WAAW;;;ACGlB,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AACtD,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,eAAe,aAAa,OAAgC;AAC1D,MAAI,OAAO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esContent":["import axios from 'axios';\nimport { AllUsers, ProjectOptions, Memory, MemoryHistory, MemoryOptions, MemoryUpdateBody, ProjectResponse, PromptUpdatePayload, SearchOptions, Webhook, WebhookPayload } from './mem0.types';\nimport { captureClientEvent, generateHash } from './telemetry';\n\nclass APIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = 'APIError';\n }\n}\n\ninterface ClientOptions{\n apiKey: string;\n host?: string;\n organizationName?: string;\n projectName?: string;\n organizationId?: string;\n projectId?: string;\n}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n organizationName: string | null;\n projectName: string | null;\n organizationId: string | number | null;\n projectId: string | number | null;\n headers: Record<string, string>;\n client: any;\n telemetryId: string;\n\n _validateApiKey(): any {\n if (!this.apiKey) {\n throw new Error('Mem0 API key is required');\n }\n if (typeof this.apiKey !== 'string') {\n throw new Error('Mem0 API key must be a string');\n }\n if (this.apiKey.trim() === '') {\n throw new Error('Mem0 API key cannot be empty');\n }\n }\n\n _validateOrgProject(): void {\n // Check for organizationName/projectName pair\n if ((this.organizationName === null && this.projectName !== null) || \n (this.organizationName !== null && this.projectName === null)) {\n console.warn('Warning: Both organizationName and projectName must be provided together when using either. This will be removedfrom the version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId.');\n }\n\n // Check for organizationId/projectId pair\n if ((this.organizationId === null && this.projectId !== null) || \n (this.organizationId !== null && this.projectId === null)) {\n console.warn('Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.');\n }\n }\n\n constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationName = options.organizationName || null;\n this.projectName = options.projectName || null;\n this.organizationId = options.organizationId || null;\n this.projectId = options.projectId || null;\n\n this.headers = {\n 'Authorization': `Token ${this.apiKey}`,\n 'Content-Type': 'application/json'\n };\n\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n this._validateOrgProject();\n\n // Initialize with a temporary ID that will be updated\n this.telemetryId = '';\n \n // Initialize the client\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n this.telemetryId = await generateHash(this.apiKey);\n await captureClientEvent('init', this);\n\n // Wrap methods after initialization\n this.add = this.wrapMethod('add', this.add);\n this.get = this.wrapMethod('get', this.get);\n this.getAll = this.wrapMethod('get_all', this.getAll);\n this.search = this.wrapMethod('search', this.search);\n this.delete = this.wrapMethod('delete', this.delete);\n this.deleteAll = this.wrapMethod('delete_all', this.deleteAll);\n this.history = this.wrapMethod('history', this.history);\n this.users = this.wrapMethod('users', this.users);\n this.deleteUser = this.wrapMethod('delete_user', this.deleteUser);\n this.deleteUsers = this.wrapMethod('delete_users', this.deleteUsers);\n this.batchUpdate = this.wrapMethod('batch_update', this.batchUpdate);\n this.batchDelete = this.wrapMethod('batch_delete', this.batchDelete);\n this.getProject = this.wrapMethod('get_project', this.getProject);\n this.updateProject = this.wrapMethod('update_project', this.updateProject);\n this.getWebhooks = this.wrapMethod('get_webhook', this.getWebhooks);\n this.createWebhook = this.wrapMethod('create_webhook', this.createWebhook);\n this.updateWebhook = this.wrapMethod('update_webhook', this.updateWebhook);\n this.deleteWebhook = this.wrapMethod('delete_webhook', this.deleteWebhook);\n } catch (error) {\n console.error('Failed to initialize client:', error);\n }\n }\n\n wrapMethod(methodName: any, method: any) {\n return async function (...args: any) {\n // @ts-ignore\n await captureClientEvent(methodName, this);\n // @ts-ignore\n return method.apply(this, args);\n }.bind(this);\n}\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, options);\n if (!response.ok) {\n const errorData = await response.text();\n throw new APIError(`API request failed: ${errorData}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse;\n }\n\n _preparePayload(messages: string | Array<{ role: string; content: string }>,\n options: MemoryOptions): object {\n const payload: any = {};\n if (typeof messages === 'string') {\n payload.messages = [{ role: 'user', content: messages }];\n } else if (Array.isArray(messages)) {\n payload.messages = messages;\n }\n return { ...payload, ...options };\n }\n\n _prepareParams(options: MemoryOptions): object {\n return Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null));\n }\n\n async add(messages: string | Array<{ role: string; content: string }>, options:MemoryOptions = {}): Promise<Array<Memory>> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n\n const payload = this._preparePayload(messages, options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async update(memoryId: string, message: string): Promise<Array<Memory>> {\n this._validateOrgProject();\n const payload = {\n text: message\n }\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n async getAll(options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, page, page_size, ...otherOptions } = options!;\n if(this.organizationName != null && this.projectName != null){\n otherOptions.org_name = this.organizationName;\n otherOptions.project_name = this.projectName;\n }\n\n let appendedParams = \"\";\n let paginated_response = false;\n\n if(page && page_size){\n appendedParams += `page=${page}&page_size=${page_size}`\n paginated_response = true;\n }\n\n if(this.organizationId != null && this.projectId != null){\n otherOptions.org_id = this.organizationId;\n otherOptions.project_id = this.projectId;\n\n if (otherOptions.org_name) delete otherOptions.org_name;\n if(otherOptions.project_name) delete otherOptions.project_name;\n }\n\n if (api_version === 'v2') {\n let url = paginated_response ? `${this.host}/v2/memories/?${appendedParams}` : `${this.host}/v2/memories/`;\n return this._fetchWithErrorHandling(url, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(otherOptions)\n });\n } else {\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(otherOptions));\n const url = paginated_response ? `${this.host}/v1/memories/?${params}&${appendedParams}` : `${this.host}/v1/memories/?${params}`;\n return this._fetchWithErrorHandling(url, {\n headers: this.headers\n });\n }\n }\n\n async search(query: string, options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, ...otherOptions } = options!;\n const payload = { query, ...otherOptions };\n if(this.organizationName != null && this.projectName != null){\n payload.org_name = this.organizationName;\n payload.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n payload.org_id = this.organizationId;\n payload.project_id = this.projectId;\n\n if (payload.org_name) delete payload.org_name;\n if(payload.project_name) delete payload.project_name;\n }\n const endpoint = api_version === 'v2' ? '/v2/memories/search/' : '/v1/memories/search/';\n const response = await this._fetchWithErrorHandling(`${this.host}${endpoint}`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(payload)\n });\n return response;\n }\n\n async delete(memoryId: string): Promise<{ message: string }> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n }\n\n async deleteAll(options: MemoryOptions = {}): Promise<{ message: string }> {\n this._validateOrgProject();\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(options));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/?${params}`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/history/`, {\n headers: this.headers\n });\n return response;\n }\n\n async users(): Promise<AllUsers>{\n this._validateOrgProject();\n const options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(options);\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/?${params}`, {\n headers: this.headers\n });\n return response;\n }\n\n async deleteUser(entityId: string, entity: { type: string } = { type: 'user' }): Promise<{ message: string }> {\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/entities/${entity.type}/${entityId}/`, {\n method: 'DELETE',\n headers: this.headers\n });\n return response;\n }\n\n async deleteUsers(): Promise<{ message: string }> {\n this._validateOrgProject();\n const entities = await this.users();\n \n for (const entity of entities.results) {\n let options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n \n if(this.organizationId != null && this.projectId != null){\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n \n if (options.org_name) delete options.org_name;\n if(options.project_name) delete options.project_name;\n }\n await this.client.delete(`/v1/entities/${entity.type}/${entity.id}/`, { params: options });\n }\n return { message: \"All users, agents, and sessions deleted.\" };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory.memoryId,\n text: memory.text\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n const memoriesBody = memories.map(memory => ({\n memory_id: memory\n }));\n const response = await this._fetchWithErrorHandling(`${this.host}/v1/batch/`, {\n method: 'DELETE',\n headers: this.headers,\n body: JSON.stringify({memories: memoriesBody})\n });\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n this._validateOrgProject();\n\n const { fields } = options;\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to access instructions or categories\");\n }\n\n const params = new URLSearchParams();\n fields?.forEach(field => params.append('fields', field));\n \n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,\n {\n headers: this.headers\n }\n );\n return response;\n }\n\n async updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>> {\n this._validateOrgProject();\n \n if (!(this.organizationId && this.projectId)) {\n throw new Error(\"organizationId and projectId must be set to update instructions or categories\");\n }\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,\n {\n method: 'PATCH',\n headers: this.headers,\n body: JSON.stringify(prompts)\n }\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: {projectId?: string}): Promise<Array<Webhook>> {\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${project_id}/`, {\n headers: this.headers\n });\n return response;\n }\n\n async createWebhook(webhook: WebhookPayload): Promise<Webhook> {\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/projects/${this.projectId}/`, {\n method: 'POST',\n headers: this.headers,\n body: JSON.stringify(webhook)\n });\n return response;\n }\n\n async updateWebhook(webhook: WebhookPayload): Promise<{ message: string }> {\n const project_id = webhook.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook.webhookId}/`, {\n method: 'PUT',\n headers: this.headers,\n body: JSON.stringify({\n ...webhook,\n projectId: project_id\n })\n });\n return response;\n }\n\n async deleteWebhook(data: {webhookId: string}): Promise<{ message: string }> {\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(`${this.host}/api/v1/webhooks/${webhook_id}/`, {\n method: 'DELETE', \n headers: this.headers\n });\n return response;\n }\n}\n\nexport {MemoryClient};","// @ts-nocheck\nimport type { PostHog } from \"posthog-js\";\nimport type { TelemetryClient } from \"./telemetry.types\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com\";\n\n// Browser-specific hash function using Web Crypto API\nasync function generateHash(input: string): Promise<string> {\n const msgBuffer = new TextEncoder().encode(input);\n const hashBuffer = await window.crypto.subtle.digest('SHA-256', msgBuffer);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map(b => b.toString(16).padStart(2, '0')).join('');\n}\n\nclass BrowserTelemetry implements TelemetryClient {\n client: PostHog | null = null;\n\n constructor(projectApiKey: string, host: string) {\n if (MEM0_TELEMETRY) {\n this.initializeClient(projectApiKey, host);\n }\n }\n\n private async initializeClient(projectApiKey: string, host: string) {\n try {\n const posthog = await import('posthog-js').catch(() => null);\n if (posthog) {\n posthog.init(projectApiKey, { api_host: host });\n this.client = posthog;\n }\n } catch (error) {\n // Silently fail if posthog-js is not available\n this.client = null;\n }\n }\n\n async captureEvent(distinctId: string, eventName: string, properties = {}) {\n if (!this.client || !MEM0_TELEMETRY) return;\n\n const eventProperties = {\n client_source: \"browser\",\n client_version: getVersion(),\n browser: window.navigator.userAgent,\n ...properties,\n };\n\n try {\n this.client.capture(\n eventName,\n eventProperties\n );\n } catch (error) {\n // Silently fail if telemetry fails\n }\n }\n\n async shutdown() {\n // No shutdown needed for browser client\n }\n}\n\nfunction getVersion() {\n return version;\n}\n\nconst telemetry = new BrowserTelemetry(\n POSTHOG_API_KEY,\n POSTHOG_HOST\n);\n\nasync function captureClientEvent(eventName: string, instance: any, additionalData = {}) {\n const eventData = {\n function: `${instance.constructor.name}`,\n ...additionalData,\n };\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash }; ","import { MemoryClient } from \"./mem0\";\nimport type { TelemetryClient, TelemetryInstance } from './telemetry.types';\nimport { telemetry, captureClientEvent, generateHash } from './telemetry.browser';\nimport type * as MemoryTypes from './mem0.types';\n\n// Re-export all types from mem0.types\nexport type {\n MemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n SearchOptions,\n Webhook,\n WebhookPayload,\n Messages,\n Message,\n AllUsers,\n User\n} from './mem0.types';\n\n// Export telemetry types\nexport type { TelemetryClient, TelemetryInstance };\n\n// Export telemetry implementation\nexport { telemetry, captureClientEvent, generateHash };\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;"],"mappings":";AAAA,OAAO,WAAW;;;ACIlB,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AACtD,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,eAAe,aAAa,OAAgC;AAC1D,QAAM,YAAY,IAAI,YAAY,EAAE,OAAO,KAAK;AAChD,QAAM,aAAa,MAAM,OAAO,OAAO,OAAO,OAAO,WAAW,SAAS;AACzE,QAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AACvD,SAAO,UAAU,IAAI,OAAK,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACpE;AAEA,IAAM,mBAAN,MAAkD;AAAA,EAGhD,YAAY,eAAuB,MAAc;AAFjD,kBAAyB;AAGvB,QAAI,gBAAgB;AAClB,WAAK,iBAAiB,eAAe,IAAI;AAAA,IAC3C;AAAA,EACF;AAAA,EAEA,MAAc,iBAAiB,eAAuB,MAAc;AAClE,QAAI;AACF,YAAM,UAAU,MAAM,OAAO,YAAY,EAAE,MAAM,MAAM,IAAI;AAC3D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ACd,MAAM,KAAK,UAAU,OAAO;AAAA,IAC9B,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,SAAuD;AACzE,UAAM,aAAa,QAAQ,aAAa,KAAK;AAC7C,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,oBAAoB,QAAQ,SAAS,KAAK;AAAA,MACxG,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU;AAAA,QACnB,GAAG;AAAA,QACH,WAAW;AAAA,MACb,CAAC;AAAA,IACH,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,MAAyD;AAC3E,UAAM,aAAa,KAAK,aAAa;AACrC,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,oBAAoB,UAAU,KAAK;AAAA,MACjG,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,IAChB,CAAC;AACD,WAAO;AAAA,EACT;AACF;;;AEraA,IAAO,gBAAQ;","names":[]}
|
package/package.json
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mem0ai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.39",
|
|
4
4
|
"description": "The Memory Layer For Your AI Apps",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
7
7
|
"types": "./dist/index.d.ts",
|
|
8
|
+
"typesVersions": {
|
|
9
|
+
"*": {
|
|
10
|
+
"*": ["./dist/index.d.ts"]
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"exports": {
|
|
14
|
+
".": {
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"require": "./dist/index.js",
|
|
17
|
+
"import": "./dist/index.mjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
8
20
|
"files": [
|
|
9
|
-
"dist
|
|
21
|
+
"dist"
|
|
10
22
|
],
|
|
11
23
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"build": "
|
|
24
|
+
"clean": "rm -rf dist",
|
|
25
|
+
"build": "npm run clean && tsup",
|
|
14
26
|
"dev": "nodemon"
|
|
15
27
|
},
|
|
28
|
+
"tsup": {
|
|
29
|
+
"entry": ["src/index.ts"],
|
|
30
|
+
"format": ["cjs", "esm"],
|
|
31
|
+
"dts": {
|
|
32
|
+
"resolve": true
|
|
33
|
+
},
|
|
34
|
+
"splitting": false,
|
|
35
|
+
"sourcemap": true,
|
|
36
|
+
"clean": true,
|
|
37
|
+
"treeshake": true,
|
|
38
|
+
"minify": false
|
|
39
|
+
},
|
|
16
40
|
"keywords": [
|
|
17
41
|
"mem0",
|
|
18
42
|
"api",
|
|
@@ -35,9 +59,23 @@
|
|
|
35
59
|
"dependencies": {
|
|
36
60
|
"axios": "^1.7.7",
|
|
37
61
|
"fix-tsup-cjs": "^1.2.0",
|
|
38
|
-
"posthog-js": "^1.116.6",
|
|
39
62
|
"ts-node": "^10.9.2"
|
|
40
63
|
},
|
|
64
|
+
"peerDependencies": {
|
|
65
|
+
"posthog-js": "^1.0.0",
|
|
66
|
+
"posthog-node": "^4.0.0"
|
|
67
|
+
},
|
|
68
|
+
"peerDependenciesMeta": {
|
|
69
|
+
"posthog-node": {
|
|
70
|
+
"optional": true
|
|
71
|
+
},
|
|
72
|
+
"posthog-js": {
|
|
73
|
+
"optional": true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"optionalDependencies": {
|
|
77
|
+
"posthog-js": "^1.116.6"
|
|
78
|
+
},
|
|
41
79
|
"engines": {
|
|
42
80
|
"node": ">=18"
|
|
43
81
|
},
|