mem0ai 1.0.30 → 1.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -0
- package/dist/index.d.mts +24 -1
- package/dist/index.d.ts +24 -1
- package/dist/index.js +54 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +54 -0
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -2
package/README.md
CHANGED
|
@@ -198,6 +198,21 @@ client.get("memory-id-here")
|
|
|
198
198
|
.catch(error => console.error(error));
|
|
199
199
|
```
|
|
200
200
|
|
|
201
|
+
#### Get all memories with pagination
|
|
202
|
+
|
|
203
|
+
```javascript
|
|
204
|
+
// Get memories with pagination (50 items per page)
|
|
205
|
+
client.getAll({ user_id: "alex", page: 1, page_size: 50 })
|
|
206
|
+
.then(memories => console.log(memories))
|
|
207
|
+
.catch(error => console.error(error));
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
The paginated response includes:
|
|
211
|
+
- `count`: Total number of memories
|
|
212
|
+
- `next`: URL for the next page (null if no more pages)
|
|
213
|
+
- `previous`: URL for the previous page (null if on first page)
|
|
214
|
+
- `results`: Array of memories for the current page
|
|
215
|
+
|
|
201
216
|
### 4.4 Get all users
|
|
202
217
|
|
|
203
218
|
Get all users for which you have memories.
|
package/dist/index.d.mts
CHANGED
|
@@ -13,6 +13,12 @@ interface MemoryOptions {
|
|
|
13
13
|
page_size?: number;
|
|
14
14
|
includes?: string;
|
|
15
15
|
excludes?: string;
|
|
16
|
+
enable_graph?: boolean;
|
|
17
|
+
start_date?: string;
|
|
18
|
+
end_date?: string;
|
|
19
|
+
}
|
|
20
|
+
interface ProjectOptions {
|
|
21
|
+
fields?: string[];
|
|
16
22
|
}
|
|
17
23
|
declare enum API_VERSION {
|
|
18
24
|
V1 = "v1",
|
|
@@ -37,6 +43,7 @@ interface MemoryHistory {
|
|
|
37
43
|
interface SearchOptions extends MemoryOptions {
|
|
38
44
|
api_version?: API_VERSION | string;
|
|
39
45
|
limit?: number;
|
|
46
|
+
enable_graph?: boolean;
|
|
40
47
|
}
|
|
41
48
|
declare enum Event {
|
|
42
49
|
ADD = "ADD",
|
|
@@ -81,6 +88,19 @@ interface AllUsers {
|
|
|
81
88
|
next: any;
|
|
82
89
|
previous: any;
|
|
83
90
|
}
|
|
91
|
+
interface ProjectResponse {
|
|
92
|
+
custom_instructions?: string;
|
|
93
|
+
custom_categories?: string[];
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
}
|
|
96
|
+
interface custom_categories {
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
}
|
|
99
|
+
interface PromptUpdatePayload {
|
|
100
|
+
custom_instructions?: string;
|
|
101
|
+
custom_categories?: custom_categories[];
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
}
|
|
84
104
|
|
|
85
105
|
interface ClientOptions {
|
|
86
106
|
apiKey: string;
|
|
@@ -101,6 +121,7 @@ declare class MemoryClient {
|
|
|
101
121
|
client: any;
|
|
102
122
|
telemetryId: string;
|
|
103
123
|
_validateApiKey(): any;
|
|
124
|
+
_validateOrgProject(): void;
|
|
104
125
|
constructor(options: ClientOptions);
|
|
105
126
|
wrapMethod(methodName: any, method: any): (...args: any) => Promise<any>;
|
|
106
127
|
_fetchWithErrorHandling(url: string, options: any): Promise<any>;
|
|
@@ -134,6 +155,8 @@ declare class MemoryClient {
|
|
|
134
155
|
}>;
|
|
135
156
|
batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string>;
|
|
136
157
|
batchDelete(memories: Array<string>): Promise<string>;
|
|
158
|
+
getProject(options: ProjectOptions): Promise<ProjectResponse>;
|
|
159
|
+
updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>>;
|
|
137
160
|
}
|
|
138
161
|
|
|
139
|
-
export { API_VERSION, type AllUsers, type Memory, MemoryClient, type MemoryData, type MemoryHistory, type MemoryOptions, type MemoryUpdateBody, type Messages, type SearchOptions, type User, MemoryClient as default };
|
|
162
|
+
export { API_VERSION, type AllUsers, type Memory, MemoryClient, type MemoryData, type MemoryHistory, type MemoryOptions, type MemoryUpdateBody, type Messages, type ProjectOptions, type ProjectResponse, type PromptUpdatePayload, type SearchOptions, type User, MemoryClient as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -13,6 +13,12 @@ interface MemoryOptions {
|
|
|
13
13
|
page_size?: number;
|
|
14
14
|
includes?: string;
|
|
15
15
|
excludes?: string;
|
|
16
|
+
enable_graph?: boolean;
|
|
17
|
+
start_date?: string;
|
|
18
|
+
end_date?: string;
|
|
19
|
+
}
|
|
20
|
+
interface ProjectOptions {
|
|
21
|
+
fields?: string[];
|
|
16
22
|
}
|
|
17
23
|
declare enum API_VERSION {
|
|
18
24
|
V1 = "v1",
|
|
@@ -37,6 +43,7 @@ interface MemoryHistory {
|
|
|
37
43
|
interface SearchOptions extends MemoryOptions {
|
|
38
44
|
api_version?: API_VERSION | string;
|
|
39
45
|
limit?: number;
|
|
46
|
+
enable_graph?: boolean;
|
|
40
47
|
}
|
|
41
48
|
declare enum Event {
|
|
42
49
|
ADD = "ADD",
|
|
@@ -81,6 +88,19 @@ interface AllUsers {
|
|
|
81
88
|
next: any;
|
|
82
89
|
previous: any;
|
|
83
90
|
}
|
|
91
|
+
interface ProjectResponse {
|
|
92
|
+
custom_instructions?: string;
|
|
93
|
+
custom_categories?: string[];
|
|
94
|
+
[key: string]: any;
|
|
95
|
+
}
|
|
96
|
+
interface custom_categories {
|
|
97
|
+
[key: string]: any;
|
|
98
|
+
}
|
|
99
|
+
interface PromptUpdatePayload {
|
|
100
|
+
custom_instructions?: string;
|
|
101
|
+
custom_categories?: custom_categories[];
|
|
102
|
+
[key: string]: any;
|
|
103
|
+
}
|
|
84
104
|
|
|
85
105
|
interface ClientOptions {
|
|
86
106
|
apiKey: string;
|
|
@@ -101,6 +121,7 @@ declare class MemoryClient {
|
|
|
101
121
|
client: any;
|
|
102
122
|
telemetryId: string;
|
|
103
123
|
_validateApiKey(): any;
|
|
124
|
+
_validateOrgProject(): void;
|
|
104
125
|
constructor(options: ClientOptions);
|
|
105
126
|
wrapMethod(methodName: any, method: any): (...args: any) => Promise<any>;
|
|
106
127
|
_fetchWithErrorHandling(url: string, options: any): Promise<any>;
|
|
@@ -134,7 +155,9 @@ declare class MemoryClient {
|
|
|
134
155
|
}>;
|
|
135
156
|
batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string>;
|
|
136
157
|
batchDelete(memories: Array<string>): Promise<string>;
|
|
158
|
+
getProject(options: ProjectOptions): Promise<ProjectResponse>;
|
|
159
|
+
updateProject(prompts: PromptUpdatePayload): Promise<Record<string, any>>;
|
|
137
160
|
}
|
|
138
161
|
|
|
139
|
-
export { API_VERSION, type AllUsers, type Memory, MemoryClient, type MemoryData, type MemoryHistory, type MemoryOptions, type MemoryUpdateBody, type Messages, type SearchOptions, type User, MemoryClient as default };
|
|
162
|
+
export { API_VERSION, type AllUsers, type Memory, MemoryClient, type MemoryData, type MemoryHistory, type MemoryOptions, type MemoryUpdateBody, type Messages, type ProjectOptions, type ProjectResponse, type PromptUpdatePayload, type SearchOptions, type User, MemoryClient as default };
|
|
140
163
|
export = MemoryClient
|
package/dist/index.js
CHANGED
|
@@ -111,6 +111,14 @@ var MemoryClient = class {
|
|
|
111
111
|
throw new Error("Mem0 API key cannot be empty");
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
|
+
_validateOrgProject() {
|
|
115
|
+
if (this.organizationName === null && this.projectName !== null || this.organizationName !== null && this.projectName === null) {
|
|
116
|
+
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.");
|
|
117
|
+
}
|
|
118
|
+
if (this.organizationId === null && this.projectId !== null || this.organizationId !== null && this.projectId === null) {
|
|
119
|
+
console.warn("Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.");
|
|
120
|
+
}
|
|
121
|
+
}
|
|
114
122
|
constructor(options) {
|
|
115
123
|
this.apiKey = options.apiKey;
|
|
116
124
|
this.host = options.host || "https://api.mem0.ai";
|
|
@@ -128,6 +136,7 @@ var MemoryClient = class {
|
|
|
128
136
|
timeout: 6e4
|
|
129
137
|
});
|
|
130
138
|
this._validateApiKey();
|
|
139
|
+
this._validateOrgProject();
|
|
131
140
|
this.telemetryId = import_crypto.default.createHash("md5").update(this.apiKey).digest("hex");
|
|
132
141
|
captureClientEvent("init", this);
|
|
133
142
|
this.add = this.wrapMethod("add", this.add);
|
|
@@ -142,6 +151,14 @@ var MemoryClient = class {
|
|
|
142
151
|
this.deleteUsers = this.wrapMethod("delete_users", this.deleteUsers);
|
|
143
152
|
this.batchUpdate = this.wrapMethod("batch_update", this.batchUpdate);
|
|
144
153
|
this.batchDelete = this.wrapMethod("batch_delete", this.batchDelete);
|
|
154
|
+
this.getProject = this.wrapMethod(
|
|
155
|
+
"get_project",
|
|
156
|
+
this.getProject
|
|
157
|
+
);
|
|
158
|
+
this.updateProject = this.wrapMethod(
|
|
159
|
+
"update_project",
|
|
160
|
+
this.updateProject
|
|
161
|
+
);
|
|
145
162
|
}
|
|
146
163
|
wrapMethod(methodName, method) {
|
|
147
164
|
return async function(...args) {
|
|
@@ -171,6 +188,7 @@ var MemoryClient = class {
|
|
|
171
188
|
return Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null));
|
|
172
189
|
}
|
|
173
190
|
async add(messages, options = {}) {
|
|
191
|
+
this._validateOrgProject();
|
|
174
192
|
if (this.organizationName != null && this.projectName != null) {
|
|
175
193
|
options.org_name = this.organizationName;
|
|
176
194
|
options.project_name = this.projectName;
|
|
@@ -195,6 +213,7 @@ var MemoryClient = class {
|
|
|
195
213
|
});
|
|
196
214
|
}
|
|
197
215
|
getAll(options) {
|
|
216
|
+
this._validateOrgProject();
|
|
198
217
|
const { api_version, page, page_size, ...otherOptions } = options;
|
|
199
218
|
if (this.organizationName != null && this.projectName != null) {
|
|
200
219
|
otherOptions.org_name = this.organizationName;
|
|
@@ -228,6 +247,7 @@ var MemoryClient = class {
|
|
|
228
247
|
}
|
|
229
248
|
}
|
|
230
249
|
async search(query, options) {
|
|
250
|
+
this._validateOrgProject();
|
|
231
251
|
const { api_version, ...otherOptions } = options;
|
|
232
252
|
const payload = { query, ...otherOptions };
|
|
233
253
|
if (this.organizationName != null && this.projectName != null) {
|
|
@@ -255,6 +275,7 @@ var MemoryClient = class {
|
|
|
255
275
|
});
|
|
256
276
|
}
|
|
257
277
|
async deleteAll(options = {}) {
|
|
278
|
+
this._validateOrgProject();
|
|
258
279
|
if (this.organizationName != null && this.projectName != null) {
|
|
259
280
|
options.org_name = this.organizationName;
|
|
260
281
|
options.project_name = this.projectName;
|
|
@@ -279,6 +300,7 @@ var MemoryClient = class {
|
|
|
279
300
|
return response;
|
|
280
301
|
}
|
|
281
302
|
async users() {
|
|
303
|
+
this._validateOrgProject();
|
|
282
304
|
const options = {};
|
|
283
305
|
if (this.organizationName != null && this.projectName != null) {
|
|
284
306
|
options.org_name = this.organizationName;
|
|
@@ -304,6 +326,7 @@ var MemoryClient = class {
|
|
|
304
326
|
return response;
|
|
305
327
|
}
|
|
306
328
|
async deleteUsers() {
|
|
329
|
+
this._validateOrgProject();
|
|
307
330
|
const entities = await this.users();
|
|
308
331
|
for (const entity of entities.results) {
|
|
309
332
|
let options = {};
|
|
@@ -344,6 +367,37 @@ var MemoryClient = class {
|
|
|
344
367
|
});
|
|
345
368
|
return response;
|
|
346
369
|
}
|
|
370
|
+
async getProject(options) {
|
|
371
|
+
this._validateOrgProject();
|
|
372
|
+
const { fields } = options;
|
|
373
|
+
if (!(this.organizationId && this.projectId)) {
|
|
374
|
+
throw new Error("organizationId and projectId must be set to access instructions or categories");
|
|
375
|
+
}
|
|
376
|
+
const params = new URLSearchParams();
|
|
377
|
+
fields == null ? void 0 : fields.forEach((field) => params.append("fields", field));
|
|
378
|
+
const response = await this._fetchWithErrorHandling(
|
|
379
|
+
`${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,
|
|
380
|
+
{
|
|
381
|
+
headers: this.headers
|
|
382
|
+
}
|
|
383
|
+
);
|
|
384
|
+
return response;
|
|
385
|
+
}
|
|
386
|
+
async updateProject(prompts) {
|
|
387
|
+
this._validateOrgProject();
|
|
388
|
+
if (!(this.organizationId && this.projectId)) {
|
|
389
|
+
throw new Error("organizationId and projectId must be set to update instructions or categories");
|
|
390
|
+
}
|
|
391
|
+
const response = await this._fetchWithErrorHandling(
|
|
392
|
+
`${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,
|
|
393
|
+
{
|
|
394
|
+
method: "PATCH",
|
|
395
|
+
headers: this.headers,
|
|
396
|
+
body: JSON.stringify(prompts)
|
|
397
|
+
}
|
|
398
|
+
);
|
|
399
|
+
return response;
|
|
400
|
+
}
|
|
347
401
|
};
|
|
348
402
|
|
|
349
403
|
// src/mem0.types.ts
|
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, Memory, MemoryHistory, MemoryOptions, MemoryUpdateBody, SearchOptions } from './mem0.types';\nimport { captureClientEvent } from './telemetry';\nimport crypto from 'crypto';\nimport util from \"util\";\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 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\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n\n this.telemetryId = crypto.createHash('md5').update(this.apiKey).digest('hex');\n\n captureClientEvent('init', this);\n\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 }\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 if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n getAll(options?: SearchOptions): Promise<Array<Memory>> {\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 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 // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 const options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 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 // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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}\n\nexport {MemoryClient};","// @ts-nocheck\nimport { PostHog } from \"posthog-node\";\nimport os from \"os\";\nimport path from \"path\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\n\nclass AnonymousTelemetry {\n constructor(projectApiKey, host) {\n this.client = new PostHog(projectApiKey, { host, flushAt: 1 });\n }\n async captureEvent(distinctId, eventName, properties = {}) {\n const eventProperties = {\n client_source: \"nodejs\",\n client_version: getVersion(),\n node_version: process.version,\n os: process.platform,\n os_version: os.release(),\n os_arch: os.arch(),\n ...properties,\n };\n try {\n this.client.capture({\n distinctId: distinctId,\n event: eventName,\n properties: eventProperties,\n });\n } catch (error) {\n console.error(\"Error capturing event:\", error);\n }\n }\n async shutdown() {\n return this.client.shutdown();\n }\n}\nfunction getVersion() {\n return version;\n}\nconst telemetry = new AnonymousTelemetry(\n \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\",\n \"https://us.i.posthog.com\"\n);\nasync function captureClientEvent(eventName, instance, 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}\nexport { telemetry, captureClientEvent };","export interface MemoryOptions {\n user_id?: string;\n agent_id?: string;\n app_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}\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 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}\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACClB,0BAAwB;AACxB,gBAAe;AAGf,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AAEtD,IAAM,qBAAN,MAAyB;AAAA,EACvB,YAAY,eAAe,MAAM;AAC/B,SAAK,SAAS,IAAI,4BAAQ,eAAe,EAAE,MAAM,SAAS,EAAE,CAAC;AAAA,EAC/D;AAAA,EACA,MAAM,aAAa,YAAY,WAAW,aAAa,CAAC,GAAG;AACzD,UAAM,kBAAkB;AAAA,MACtB,eAAe;AAAA,MACf,gBAAgB,WAAW;AAAA,MAC3B,cAAc,QAAQ;AAAA,MACtB,IAAI,QAAQ;AAAA,MACZ,YAAY,UAAAA,QAAG,QAAQ;AAAA,MACvB,SAAS,UAAAA,QAAG,KAAK;AAAA,MACjB,GAAG;AAAA,IACL;AACA,QAAI;AACF,WAAK,OAAO,QAAQ;AAAA,QAClB;AAAA,QACA,OAAO;AA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KAAK,aAAa,MAAK;AACvD,gBAAQ,SAAS,KAAK;AACtB,gBAAQ,aAAa,KAAK;AAE1B,YAAI,QAAQ,SAAU,QAAO,QAAQ;AACrC,YAAG,QAAQ,aAAc,QAAO,QAAQ;AAAA,MAC1C;AACA,YAAM,KAAK,OAAO,OAAO,gBAAgB,OAAO,IAAI,IAAI,OAAO,EAAE,KAAK,EAAE,QAAQ,QAAQ,CAAC;AAAA,IAC7F;AACA,WAAO,EAAE,SAAS,2CAA2C;AAAA,EAC/D;AAAA,EAEA,MAAM,YAAY,UAAoD;AACpE,UAAM,eAAe,SAAS,IAAI,aAAW;AAAA,MAC3C,WAAW,OAAO;AAAA,MAClB,MAAM,OAAO;AAAA,IACf,EAAE;AACF,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,cAAc;AAAA,MAC1E,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU,EAAC,UAAU,aAAY,CAAC;AAAA,IACjD,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,UAAM,eAAe,SAAS,IAAI,aAAW;AAAA,MAC3C,WAAW;AAAA,IACb,EAAE;AACF,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,cAAc;AAAA,MAC1E,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU,EAAC,UAAU,aAAY,CAAC;AAAA,IACjD,CAAC;AACD,WAAO;AAAA,EACT;AAEF;;;AExTO,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,QAAK;AACL,EAAAA,aAAA,QAAK;AAFK,SAAAA;AAAA,GAAA;;;AHbZ,IAAO,cAAQ;","names":["os","axios","crypto","API_VERSION"]}
|
|
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 } from './mem0.types';\nimport { captureClientEvent } from './telemetry';\nimport crypto from 'crypto';\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 this.telemetryId = crypto.createHash('md5').update(this.apiKey).digest('hex');\n\n captureClientEvent('init', this);\n\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(\n 'get_project', \n this.getProject\n );\n this.updateProject = this.wrapMethod(\n 'update_project', \n this.updateProject\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 get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n 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}\n\nexport {MemoryClient};","// @ts-nocheck\nimport { PostHog } from \"posthog-node\";\nimport os from \"os\";\nimport path from \"path\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\n\nclass AnonymousTelemetry {\n constructor(projectApiKey, host) {\n this.client = new PostHog(projectApiKey, { host, flushAt: 1 });\n }\n async captureEvent(distinctId, eventName, properties = {}) {\n const eventProperties = {\n client_source: \"nodejs\",\n client_version: getVersion(),\n node_version: process.version,\n os: process.platform,\n os_version: os.release(),\n os_arch: os.arch(),\n ...properties,\n };\n try {\n this.client.capture({\n distinctId: distinctId,\n event: eventName,\n properties: eventProperties,\n });\n } catch (error) {\n console.error(\"Error capturing event:\", error);\n }\n }\n async shutdown() {\n return this.client.shutdown();\n }\n}\nfunction getVersion() {\n return version;\n}\nconst telemetry = new AnonymousTelemetry(\n \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\",\n \"https://us.i.posthog.com\"\n);\nasync function captureClientEvent(eventName, instance, 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}\nexport { telemetry, captureClientEvent };","export interface MemoryOptions {\n user_id?: string;\n agent_id?: string;\n app_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 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}\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}"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACClB,0BAAwB;AACxB,gBAAe;AAGf,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AAEtD,IAAM,qBAAN,MAAyB;AAAA,EACvB,YAAY,eAAe,MAAM;AAC/B,SAAK,S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AI,EAAE,KAAK,kBAAkB,KAAK,YAAY;AAC5C,YAAM,IAAI,MAAM,+EAA+E;AAAA,IACjG;AAEA,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI,8BAA8B,KAAK,cAAc,aAAa,KAAK,SAAS;AAAA,MACxF;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,QACd,MAAM,KAAK,UAAU,OAAO;AAAA,MAC9B;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAEF;;;AE/WO,IAAK,cAAL,kBAAKC,iBAAL;AACL,EAAAA,aAAA,QAAK;AACL,EAAAA,aAAA,QAAK;AAFK,SAAAA;AAAA,GAAA;;;AHpBZ,IAAO,cAAQ;","names":["os","axios","crypto","API_VERSION"]}
|
package/dist/index.mjs
CHANGED
|
@@ -73,6 +73,14 @@ var MemoryClient = class {
|
|
|
73
73
|
throw new Error("Mem0 API key cannot be empty");
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
|
+
_validateOrgProject() {
|
|
77
|
+
if (this.organizationName === null && this.projectName !== null || this.organizationName !== null && this.projectName === null) {
|
|
78
|
+
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.");
|
|
79
|
+
}
|
|
80
|
+
if (this.organizationId === null && this.projectId !== null || this.organizationId !== null && this.projectId === null) {
|
|
81
|
+
console.warn("Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.");
|
|
82
|
+
}
|
|
83
|
+
}
|
|
76
84
|
constructor(options) {
|
|
77
85
|
this.apiKey = options.apiKey;
|
|
78
86
|
this.host = options.host || "https://api.mem0.ai";
|
|
@@ -90,6 +98,7 @@ var MemoryClient = class {
|
|
|
90
98
|
timeout: 6e4
|
|
91
99
|
});
|
|
92
100
|
this._validateApiKey();
|
|
101
|
+
this._validateOrgProject();
|
|
93
102
|
this.telemetryId = crypto.createHash("md5").update(this.apiKey).digest("hex");
|
|
94
103
|
captureClientEvent("init", this);
|
|
95
104
|
this.add = this.wrapMethod("add", this.add);
|
|
@@ -104,6 +113,14 @@ var MemoryClient = class {
|
|
|
104
113
|
this.deleteUsers = this.wrapMethod("delete_users", this.deleteUsers);
|
|
105
114
|
this.batchUpdate = this.wrapMethod("batch_update", this.batchUpdate);
|
|
106
115
|
this.batchDelete = this.wrapMethod("batch_delete", this.batchDelete);
|
|
116
|
+
this.getProject = this.wrapMethod(
|
|
117
|
+
"get_project",
|
|
118
|
+
this.getProject
|
|
119
|
+
);
|
|
120
|
+
this.updateProject = this.wrapMethod(
|
|
121
|
+
"update_project",
|
|
122
|
+
this.updateProject
|
|
123
|
+
);
|
|
107
124
|
}
|
|
108
125
|
wrapMethod(methodName, method) {
|
|
109
126
|
return async function(...args) {
|
|
@@ -133,6 +150,7 @@ var MemoryClient = class {
|
|
|
133
150
|
return Object.fromEntries(Object.entries(options).filter(([_, v]) => v != null));
|
|
134
151
|
}
|
|
135
152
|
async add(messages, options = {}) {
|
|
153
|
+
this._validateOrgProject();
|
|
136
154
|
if (this.organizationName != null && this.projectName != null) {
|
|
137
155
|
options.org_name = this.organizationName;
|
|
138
156
|
options.project_name = this.projectName;
|
|
@@ -157,6 +175,7 @@ var MemoryClient = class {
|
|
|
157
175
|
});
|
|
158
176
|
}
|
|
159
177
|
getAll(options) {
|
|
178
|
+
this._validateOrgProject();
|
|
160
179
|
const { api_version, page, page_size, ...otherOptions } = options;
|
|
161
180
|
if (this.organizationName != null && this.projectName != null) {
|
|
162
181
|
otherOptions.org_name = this.organizationName;
|
|
@@ -190,6 +209,7 @@ var MemoryClient = class {
|
|
|
190
209
|
}
|
|
191
210
|
}
|
|
192
211
|
async search(query, options) {
|
|
212
|
+
this._validateOrgProject();
|
|
193
213
|
const { api_version, ...otherOptions } = options;
|
|
194
214
|
const payload = { query, ...otherOptions };
|
|
195
215
|
if (this.organizationName != null && this.projectName != null) {
|
|
@@ -217,6 +237,7 @@ var MemoryClient = class {
|
|
|
217
237
|
});
|
|
218
238
|
}
|
|
219
239
|
async deleteAll(options = {}) {
|
|
240
|
+
this._validateOrgProject();
|
|
220
241
|
if (this.organizationName != null && this.projectName != null) {
|
|
221
242
|
options.org_name = this.organizationName;
|
|
222
243
|
options.project_name = this.projectName;
|
|
@@ -241,6 +262,7 @@ var MemoryClient = class {
|
|
|
241
262
|
return response;
|
|
242
263
|
}
|
|
243
264
|
async users() {
|
|
265
|
+
this._validateOrgProject();
|
|
244
266
|
const options = {};
|
|
245
267
|
if (this.organizationName != null && this.projectName != null) {
|
|
246
268
|
options.org_name = this.organizationName;
|
|
@@ -266,6 +288,7 @@ var MemoryClient = class {
|
|
|
266
288
|
return response;
|
|
267
289
|
}
|
|
268
290
|
async deleteUsers() {
|
|
291
|
+
this._validateOrgProject();
|
|
269
292
|
const entities = await this.users();
|
|
270
293
|
for (const entity of entities.results) {
|
|
271
294
|
let options = {};
|
|
@@ -306,6 +329,37 @@ var MemoryClient = class {
|
|
|
306
329
|
});
|
|
307
330
|
return response;
|
|
308
331
|
}
|
|
332
|
+
async getProject(options) {
|
|
333
|
+
this._validateOrgProject();
|
|
334
|
+
const { fields } = options;
|
|
335
|
+
if (!(this.organizationId && this.projectId)) {
|
|
336
|
+
throw new Error("organizationId and projectId must be set to access instructions or categories");
|
|
337
|
+
}
|
|
338
|
+
const params = new URLSearchParams();
|
|
339
|
+
fields == null ? void 0 : fields.forEach((field) => params.append("fields", field));
|
|
340
|
+
const response = await this._fetchWithErrorHandling(
|
|
341
|
+
`${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/?${params.toString()}`,
|
|
342
|
+
{
|
|
343
|
+
headers: this.headers
|
|
344
|
+
}
|
|
345
|
+
);
|
|
346
|
+
return response;
|
|
347
|
+
}
|
|
348
|
+
async updateProject(prompts) {
|
|
349
|
+
this._validateOrgProject();
|
|
350
|
+
if (!(this.organizationId && this.projectId)) {
|
|
351
|
+
throw new Error("organizationId and projectId must be set to update instructions or categories");
|
|
352
|
+
}
|
|
353
|
+
const response = await this._fetchWithErrorHandling(
|
|
354
|
+
`${this.host}/api/v1/orgs/organizations/${this.organizationId}/projects/${this.projectId}/`,
|
|
355
|
+
{
|
|
356
|
+
method: "PATCH",
|
|
357
|
+
headers: this.headers,
|
|
358
|
+
body: JSON.stringify(prompts)
|
|
359
|
+
}
|
|
360
|
+
);
|
|
361
|
+
return response;
|
|
362
|
+
}
|
|
309
363
|
};
|
|
310
364
|
|
|
311
365
|
// src/mem0.types.ts
|
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, Memory, MemoryHistory, MemoryOptions, MemoryUpdateBody, SearchOptions } from './mem0.types';\nimport { captureClientEvent } from './telemetry';\nimport crypto from 'crypto';\nimport util from \"util\";\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 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\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n\n this.telemetryId = crypto.createHash('md5').update(this.apiKey).digest('hex');\n\n captureClientEvent('init', this);\n\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 }\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 if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n getAll(options?: SearchOptions): Promise<Array<Memory>> {\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 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 // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 const options: MemoryOptions = {};\n if(this.organizationName != null && this.projectName != null){\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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 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 // console.warn(\"organizationName and projectName is deprecated. Please use organizationId and projectId instead.\")\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}\n\nexport {MemoryClient};","// @ts-nocheck\nimport { PostHog } from \"posthog-node\";\nimport os from \"os\";\nimport path from \"path\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\n\nclass AnonymousTelemetry {\n constructor(projectApiKey, host) {\n this.client = new PostHog(projectApiKey, { host, flushAt: 1 });\n }\n async captureEvent(distinctId, eventName, properties = {}) {\n const eventProperties = {\n client_source: \"nodejs\",\n client_version: getVersion(),\n node_version: process.version,\n os: process.platform,\n os_version: os.release(),\n os_arch: os.arch(),\n ...properties,\n };\n try {\n this.client.capture({\n distinctId: distinctId,\n event: eventName,\n properties: eventProperties,\n });\n } catch (error) {\n console.error(\"Error capturing event:\", error);\n }\n }\n async shutdown() {\n return this.client.shutdown();\n }\n}\nfunction getVersion() {\n return version;\n}\nconst telemetry = new AnonymousTelemetry(\n \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\",\n \"https://us.i.posthog.com\"\n);\nasync function captureClientEvent(eventName, instance, 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}\nexport { telemetry, captureClientEvent };","export interface MemoryOptions {\n user_id?: string;\n agent_id?: string;\n app_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}\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 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}\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","import {MemoryClient} from \"./mem0\";\n\nexport { MemoryClient } from './mem0';\nexport * from './mem0.types';\nexport default MemoryClient;"],"mappings":";AAAA,OAAO,WAAW;;;ACClB,SAAS,eAAe;AACxB,OAAO,QAAQ;AAGf,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AAEtD,IAAM,qBAAN,MAAyB;AAAA,EACvB,YAAY,eAAe,MAAM;AAC/B,SAAK,SAAS,IAAI,QAAQ,eAAe,EAAE,MAAM,SAAS,EAAE,CAAC;AAAA,EAC/D;AAAA,EACA,MAAM,aAAa,YAAY,WAAW,aAAa,CAAC,GAAG;AACzD,UAAM,kBAAkB;AAAA,MACtB,eAAe;AAAA,MACf,gBAAgB,WAAW;AAAA,MAC3B,cAAc,QAAQ;AAAA,MACtB,IAAI,QAAQ;AAAA,MACZ,YAAY,GAAG,QAAQ;AAAA,MACvB,SAAS,GAAG,KAAK;AAAA,MACjB,GAAG;AAAA,IACL;AACA,QAAI;AACF,WAAK,OAAO,QAAQ;AAAA,QAClB;AAAA,QACA,OAAO;AAAA,QACP,YAAY;AAAA,MACd,CAAC;AAAA,IACH,SAAS,OAAO;AACd,cAAQ,MAAM,0BAA0B,KAAK;AAAA,IAC/C;AAAA,EACF;AAAA,EACA,MAAM,WAAW;AACf,WAAO,KAAK,OAAO,SAAS;AAAA,EAC9B;AACF;AACA,SAAS,aAAa;AACpB,SAAO;AACT;AACA,IAAM,YAAY,IAAI;AAAA,EACpB;AAAA,EACA;AACF;AACA,eAAe,mBAAmB,WAAW,UAAU,iBAAiB,CAAC,GAA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,EAEA,MAAM,YAAY,UAAoD;AACpE,UAAM,eAAe,SAAS,IAAI,aAAW;AAAA,MAC3C,WAAW,OAAO;AAAA,MAClB,MAAM,OAAO;AAAA,IACf,EAAE;AACF,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,cAAc;AAAA,MAC1E,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU,EAAC,UAAU,aAAY,CAAC;AAAA,IACjD,CAAC;AACD,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,YAAY,UAA0C;AAC1D,UAAM,eAAe,SAAS,IAAI,aAAW;AAAA,MAC3C,WAAW;AAAA,IACb,EAAE;AACF,UAAM,WAAW,MAAM,KAAK,wBAAwB,GAAG,KAAK,IAAI,cAAc;AAAA,MAC1E,QAAQ;AAAA,MACR,SAAS,KAAK;AAAA,MACd,MAAM,KAAK,UAAU,EAAC,UAAU,aAAY,CAAC;AAAA,IACjD,CAAC;AACD,WAAO;AAAA,EACT;AAEF;;;AExTO,IAAK,cAAL,kBAAKA,iBAAL;AACL,EAAAA,aAAA,QAAK;AACL,EAAAA,aAAA,QAAK;AAFK,SAAAA;AAAA,GAAA;;;ACbZ,IAAO,cAAQ;","names":["API_VERSION"]}
|
|
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 } from './mem0.types';\nimport { captureClientEvent } from './telemetry';\nimport crypto from 'crypto';\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 this.telemetryId = crypto.createHash('md5').update(this.apiKey).digest('hex');\n\n captureClientEvent('init', this);\n\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(\n 'get_project', \n this.getProject\n );\n this.updateProject = this.wrapMethod(\n 'update_project', \n this.updateProject\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 get(memoryId: string):Promise<Memory> {\n return this._fetchWithErrorHandling(`${this.host}/v1/memories/${memoryId}/`, {\n headers: this.headers\n });\n }\n\n 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}\n\nexport {MemoryClient};","// @ts-nocheck\nimport { PostHog } from \"posthog-node\";\nimport os from \"os\";\nimport path from \"path\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\n\nclass AnonymousTelemetry {\n constructor(projectApiKey, host) {\n this.client = new PostHog(projectApiKey, { host, flushAt: 1 });\n }\n async captureEvent(distinctId, eventName, properties = {}) {\n const eventProperties = {\n client_source: \"nodejs\",\n client_version: getVersion(),\n node_version: process.version,\n os: process.platform,\n os_version: os.release(),\n os_arch: os.arch(),\n ...properties,\n };\n try {\n this.client.capture({\n distinctId: distinctId,\n event: eventName,\n properties: eventProperties,\n });\n } catch (error) {\n console.error(\"Error capturing event:\", error);\n }\n }\n async shutdown() {\n return this.client.shutdown();\n }\n}\nfunction getVersion() {\n return version;\n}\nconst telemetry = new AnonymousTelemetry(\n \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\",\n \"https://us.i.posthog.com\"\n);\nasync function captureClientEvent(eventName, instance, 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}\nexport { telemetry, captureClientEvent };","export interface MemoryOptions {\n user_id?: string;\n agent_id?: string;\n app_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 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}\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}","import {MemoryClient} from \"./mem0\";\n\nexport { MemoryClient } from './mem0';\nexport * from './mem0.types';\nexport default MemoryClient;"],"mappings":";AAAA,OAAO,WAAW;;;ACClB,SAAS,eAAe;AACxB,OAAO,QAAQ;AAGf,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AAEtD,IAAM,qBAAN,MAAyB;AAAA,EACvB,YAAY,eAAe,MAAM;AAC/B,SAAK,SAAS,IAAI,QAAQ,eAAe,EAAE,MAAM,SAAS,EAAE,CAAC;AAAA,EAC/D;AAAA,EACA,MAAM,aAAa,YAAY,WAAW,aAAa,CAAC,GAAG;AACzD,UAAM,kBAAkB;AAAA,MACtB,eAAe;AAAA,MACf,gBAAgB,WAAW;AAAA,MAC3B,cAAc,QAAQ;AAAA,MACtB,IAAI,QAAQ;AAAA,MACZ,YAAY,GAAG,QAAQ;AAAA,MACvB,SAAS,GAAG,KAAK;AAAA,MACjB,GAAG;AAAA,IACL;AACA,QAAI;AACF,WAAK,OAAO,QAAQ;AAAA,QAClB;AAAA,QACA,OAAO;AAAA,QACP,Y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AA;;;ACpBZ,IAAO,cAAQ;","names":["API_VERSION"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mem0ai",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.32",
|
|
4
4
|
"description": "The Memory Layer For Your AI Apps",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|
|
@@ -36,7 +36,6 @@
|
|
|
36
36
|
"axios": "^1.7.7",
|
|
37
37
|
"crypto": "^1.0.1",
|
|
38
38
|
"fix-tsup-cjs": "^1.2.0",
|
|
39
|
-
"mem0ai": "^1.0.29",
|
|
40
39
|
"posthog-node": "^4.2.1",
|
|
41
40
|
"ts-node": "^10.9.2"
|
|
42
41
|
},
|