mem0ai 3.0.4 → 3.0.5

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 CHANGED
@@ -33,6 +33,14 @@ interface GetAllMemoryOptions {
33
33
  }
34
34
  interface DeleteAllMemoryOptions extends EntityOptions {
35
35
  }
36
+ interface DeleteMemoryOptions {
37
+ /**
38
+ * When `true`, also delete the older memories this one superseded (the v3
39
+ * linked chain), transitively — the delete-side counterpart of `latestOnly`.
40
+ * Off by default. Serialized as `delete_linked`.
41
+ */
42
+ deleteLinked?: boolean;
43
+ }
36
44
  interface ProjectOptions {
37
45
  fields?: string[];
38
46
  }
@@ -217,7 +225,7 @@ declare class MemoryClient {
217
225
  search(query: string, options?: SearchMemoryOptions): Promise<{
218
226
  results: Array<Memory>;
219
227
  }>;
220
- delete(memoryId: string): Promise<{
228
+ delete(memoryId: string, options?: DeleteMemoryOptions): Promise<{
221
229
  message: string;
222
230
  }>;
223
231
  deleteAll(options?: DeleteAllMemoryOptions): Promise<{
package/dist/index.d.ts CHANGED
@@ -33,6 +33,14 @@ interface GetAllMemoryOptions {
33
33
  }
34
34
  interface DeleteAllMemoryOptions extends EntityOptions {
35
35
  }
36
+ interface DeleteMemoryOptions {
37
+ /**
38
+ * When `true`, also delete the older memories this one superseded (the v3
39
+ * linked chain), transitively — the delete-side counterpart of `latestOnly`.
40
+ * Off by default. Serialized as `delete_linked`.
41
+ */
42
+ deleteLinked?: boolean;
43
+ }
36
44
  interface ProjectOptions {
37
45
  fields?: string[];
38
46
  }
@@ -217,7 +225,7 @@ declare class MemoryClient {
217
225
  search(query: string, options?: SearchMemoryOptions): Promise<{
218
226
  results: Array<Memory>;
219
227
  }>;
220
- delete(memoryId: string): Promise<{
228
+ delete(memoryId: string, options?: DeleteMemoryOptions): Promise<{
221
229
  message: string;
222
230
  }>;
223
231
  deleteAll(options?: DeleteAllMemoryOptions): Promise<{
package/dist/index.js CHANGED
@@ -50,7 +50,7 @@ module.exports = __toCommonJS(index_exports);
50
50
  var import_axios = __toESM(require("axios"));
51
51
 
52
52
  // src/client/telemetry.ts
53
- var version = true ? "3.0.4" : "dev";
53
+ var version = true ? "3.0.5" : "dev";
54
54
  var MEM0_TELEMETRY = true;
55
55
  var _a;
56
56
  try {
@@ -660,11 +660,13 @@ var MemoryClient = class {
660
660
  );
661
661
  return response;
662
662
  }
663
- async delete(memoryId) {
663
+ async delete(memoryId, options = {}) {
664
664
  if (this.telemetryId === "") await this.ping();
665
- this._captureEvent("delete", []);
665
+ this._captureEvent("delete", [Object.keys(options || {})]);
666
+ const snakeOptions = camelToSnakeKeys(this._prepareParams(options));
667
+ const query = new URLSearchParams(snakeOptions).toString();
666
668
  return this._fetchWithErrorHandling(
667
- `${this.host}/v1/memories/${memoryId}/`,
669
+ `${this.host}/v1/memories/${memoryId}/${query ? `?${query}` : ""}`,
668
670
  {
669
671
  method: "DELETE",
670
672
  headers: this.headers
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/index.ts","../src/client/mem0.ts","../src/client/telemetry.ts","../src/client/config.ts","../src/client/utils.ts","../src/common/exceptions.ts","../src/client/mem0.types.ts"],"sourcesContent":["import { MemoryClient } from \"./mem0\";\nimport type * as MemoryTypes from \"./mem0.types\";\n\n// Re-export all types from mem0.types\nexport type {\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Messages,\n Message,\n AllUsers,\n User,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\n\n// Re-export enums as values (not type-only)\nexport { Feedback, WebhookEvent } from \"./mem0.types\";\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;\n\n// Export structured exceptions\nexport {\n MemoryError,\n AuthenticationError,\n RateLimitError,\n ValidationError,\n MemoryNotFoundError,\n NetworkError,\n ConfigurationError,\n MemoryQuotaExceededError,\n createExceptionFromResponse,\n} from \"../common/exceptions\";\n\nexport type { MemoryErrorOptions } from \"../common/exceptions\";\n","import axios from \"axios\";\nimport {\n AllUsers,\n PaginatedMemories,\n ProjectOptions,\n Memory,\n MemoryHistory,\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Message,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\nimport {\n captureClientEvent,\n generateHash,\n isTelemetryEnabled,\n telemetry,\n} from \"./telemetry\";\nimport {\n getOrCreateMem0UserId,\n isMem0Aliased,\n markMem0Aliased,\n readMem0AnonIds,\n} from \"./config\";\nimport { camelToSnake, camelToSnakeKeys, snakeToCamelKeys } from \"./utils\";\nimport { createExceptionFromResponse, MemoryError } from \"../common/exceptions\";\n\n// Entity params that must be passed via filters - check both snake_case and camelCase\nconst ENTITY_PARAMS = [\n \"user_id\",\n \"agent_id\",\n \"app_id\",\n \"run_id\",\n \"userId\",\n \"agentId\",\n \"appId\",\n \"runId\",\n];\n\n/**\n * Validates that no top-level entity parameters are passed.\n * @throws Error if entity params are found at top level\n */\nfunction rejectTopLevelEntityParams(\n options: Record<string, any> | undefined,\n methodName: string,\n): void {\n const invalidKeys = Object.keys(options ?? {}).filter((k) =>\n ENTITY_PARAMS.includes(k),\n );\n if (invalidKeys.length > 0) {\n throw new Error(\n `Top-level entity parameters [${invalidKeys.join(\", \")}] are not supported in ${methodName}(). ` +\n `Use filters: { user_id: \"...\" } instead.`,\n );\n }\n}\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}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n private organizationId: string | number | null;\n private 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 constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationId = null;\n this.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.telemetryId = \"\";\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n await this.ping();\n\n if (!this.telemetryId) {\n this.telemetryId = generateHash(this.apiKey);\n }\n\n await this._maybeAliasAnonToEmail();\n\n captureClientEvent(\"init\", this, {\n client_type: \"MemoryClient\",\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n } catch (error: any) {\n console.error(\"Failed to initialize client:\", error);\n await captureClientEvent(\"init_error\", this, {\n error: error?.message || \"Unknown error\",\n stack: error?.stack || \"No stack trace\",\n });\n }\n }\n\n private async _maybeAliasAnonToEmail(): Promise<void> {\n if (!isTelemetryEnabled()) return;\n try {\n const email = this.telemetryId;\n if (!email || !email.includes(\"@\")) return;\n const sharedAnonId = await getOrCreateMem0UserId();\n const anonIds = await readMem0AnonIds();\n if (!anonIds && !sharedAnonId) return;\n const candidates = [anonIds?.oss || sharedAnonId, anonIds?.cli].filter(\n (id): id is string => !!id && id !== email,\n );\n const seen = new Set<string>();\n for (const anonId of candidates) {\n if (seen.has(anonId) || (await isMem0Aliased(anonId, email))) continue;\n seen.add(anonId);\n if (await telemetry.captureIdentify(anonId, email)) {\n await markMem0Aliased(anonId, email);\n }\n }\n } catch (error: any) {\n console.error(\"Failed to alias telemetry identity:\", error);\n }\n }\n\n private _captureEvent(methodName: string, args: any[]) {\n captureClientEvent(methodName, this, {\n success: true,\n args_count: args.length,\n keys: args.length > 0 ? args[0] : [],\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n }\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Token ${this.apiKey}`,\n \"Mem0-User-ID\": this.telemetryId,\n },\n });\n if (!response.ok) {\n const errorData = await response.text();\n throw createExceptionFromResponse(response.status, errorData);\n }\n const jsonResponse = await response.json();\n return snakeToCamelKeys(jsonResponse);\n }\n\n _preparePayload(\n messages: Array<Message>,\n options: Record<string, any>,\n ): object {\n const payload: any = {};\n payload.messages = messages;\n return camelToSnakeKeys({ ...payload, ...options });\n }\n\n _prepareParams(options: Record<string, any>): object {\n return Object.fromEntries(\n Object.entries(options).filter(([_, v]) => v != null),\n );\n }\n\n async ping(): Promise<void> {\n try {\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/ping/`,\n {\n method: \"GET\",\n headers: {\n Authorization: `Token ${this.apiKey}`,\n },\n },\n );\n\n if (!response || typeof response !== \"object\") {\n throw new APIError(\"Invalid response format from ping endpoint\");\n }\n\n if (response.status !== \"ok\") {\n throw new APIError(response.message || \"API Key is invalid\");\n }\n\n const { orgId, projectId, userEmail } = response;\n\n if (orgId) this.organizationId = orgId;\n if (projectId) this.projectId = projectId;\n if (userEmail) this.telemetryId = userEmail;\n } catch (error: any) {\n // Pass through structured exceptions and APIError\n if (error instanceof MemoryError || error instanceof APIError) {\n throw error;\n } else {\n throw new APIError(\n `Failed to ping server: ${error.message || \"Unknown error\"}`,\n );\n }\n }\n }\n\n async add(\n messages: Array<Message>,\n options: AddMemoryOptions & Record<string, any> = {},\n ): Promise<Array<Memory>> {\n if (this.telemetryId === \"\") await this.ping();\n\n const payload = this._preparePayload(messages, options);\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"add\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/add/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async update(\n memoryId: string,\n {\n text,\n metadata,\n timestamp,\n }: {\n text?: string;\n metadata?: Record<string, any>;\n timestamp?: number | string;\n },\n ): Promise<Array<Memory>> {\n if (\n text === undefined &&\n metadata === undefined &&\n timestamp === undefined\n ) {\n throw new Error(\n \"At least one of text, metadata, or timestamp must be provided for update.\",\n );\n }\n\n if (this.telemetryId === \"\") await this.ping();\n const payload: Record<string, any> = {};\n if (text !== undefined) payload.text = text;\n if (metadata !== undefined) payload.metadata = metadata;\n if (timestamp !== undefined) payload.timestamp = timestamp;\n\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"update\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async get(memoryId: string): Promise<Memory> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get\", []);\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n headers: this.headers,\n },\n );\n }\n\n async getAll(options?: GetAllMemoryOptions): Promise<PaginatedMemories> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"getAll\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_all\", [payloadKeys]);\n const { page, pageSize, filters, ...rest } = options ?? {};\n const body: Record<string, any> = {\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n let url = `${this.host}/v3/memories/`;\n if (page && pageSize) {\n url += `?page=${page}&page_size=${pageSize}`;\n }\n\n const response = await this._fetchWithErrorHandling(url, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n });\n return response;\n }\n\n async search(\n query: string,\n options?: SearchMemoryOptions,\n ): Promise<{ results: Array<Memory> }> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"search\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"search\", [payloadKeys]);\n const { filters, ...rest } = options ?? {};\n const payload: Record<string, any> = {\n query,\n output_format: \"v1.1\",\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/search/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async delete(memoryId: string): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete\", []);\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n }\n\n async deleteAll(\n options: DeleteAllMemoryOptions = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"delete_all\", [payloadKeys]);\n const snakeOptions = camelToSnakeKeys(this._prepareParams(options));\n // @ts-ignore\n const params = new URLSearchParams(snakeOptions);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/?${params}`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"history\", []);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/history/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async users(options?: {\n page?: number;\n pageSize?: number;\n }): Promise<AllUsers> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"users\", []);\n let url = `${this.host}/v1/entities/`;\n const params: string[] = [];\n if (options?.page) params.push(`page=${options.page}`);\n if (options?.pageSize) params.push(`page_size=${options.pageSize}`);\n if (params.length) url += `?${params.join(\"&\")}`;\n const response = await this._fetchWithErrorHandling(url, {\n headers: this.headers,\n });\n return response;\n }\n\n /**\n * @deprecated The method should not be used, use `deleteUsers` instead. This will be removed in version 2.2.0.\n */\n async deleteUser(data: {\n entity_id: number;\n entity_type: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_user\", []);\n if (!data.entity_type) {\n data.entity_type = \"user\";\n }\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/${data.entity_type}/${data.entity_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUsers(\n params: {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n } = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n\n let to_delete: Array<{ type: string; name: string }> = [];\n const { userId, agentId, appId, runId } = params;\n\n if (userId) {\n to_delete = [{ type: \"user\", name: userId }];\n } else if (agentId) {\n to_delete = [{ type: \"agent\", name: agentId }];\n } else if (appId) {\n to_delete = [{ type: \"app\", name: appId }];\n } else if (runId) {\n to_delete = [{ type: \"run\", name: runId }];\n } else {\n const entities = await this.users();\n to_delete = entities.results.map((entity) => ({\n type: entity.type,\n name: entity.name,\n }));\n }\n\n if (to_delete.length === 0) {\n throw new Error(\"No entities to delete\");\n }\n\n for (const entity of to_delete) {\n try {\n await this.client.delete(`/v2/entities/${entity.type}/${entity.name}/`);\n } catch (error: any) {\n throw new APIError(\n `Failed to delete ${entity.type} ${entity.name}: ${error.message}`,\n );\n }\n }\n\n this._captureEvent(\"delete_users\", [\n { userId, agentId, appId, runId, sync_type: \"sync\" },\n ]);\n\n return {\n message:\n userId || agentId || appId || runId\n ? \"Entity deleted successfully.\"\n : \"All users, agents, apps and runs deleted.\",\n };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_update\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory.memoryId,\n text: memory.text,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_delete\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_project\", [payloadKeys]);\n const { fields } = options;\n\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to access instructions or categories\",\n );\n }\n\n const params = new URLSearchParams();\n fields?.forEach((field) => params.append(\"fields\", camelToSnake(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(\n prompts: PromptUpdatePayload,\n ): Promise<Record<string, any>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_project\", []);\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to update instructions or categories\",\n );\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(camelToSnakeKeys(prompts)),\n },\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_webhooks\", []);\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${project_id}/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async createWebhook(webhook: WebhookCreatePayload): Promise<Webhook> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_webhook\", []);\n const body = {\n name: webhook.name,\n url: webhook.url,\n event_types: webhook.eventTypes,\n };\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${this.projectId}/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async updateWebhook(\n webhook: WebhookUpdatePayload,\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_webhook\", []);\n const body: Record<string, any> = {};\n if (webhook.name != null) body.name = webhook.name;\n if (webhook.url != null) body.url = webhook.url;\n if (webhook.eventTypes != null) body.event_types = webhook.eventTypes;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async deleteWebhook(data: {\n webhookId: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_webhook\", []);\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async feedback(data: FeedbackPayload): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(data || {});\n this._captureEvent(\"feedback\", [payloadKeys]);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/feedback/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(camelToSnakeKeys(data)),\n },\n );\n return response;\n }\n\n async createMemoryExport(\n data: CreateMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_memory_export\", []);\n\n if (!data.filters || !data.schema) {\n throw new Error(\"Missing filters or schema\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n filters,\n }),\n },\n );\n\n return response;\n }\n\n async getMemoryExport(\n data: GetMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_memory_export\", []);\n\n if (!data.memoryExportId && !data.filters) {\n throw new Error(\"Missing memoryExportId or filters\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/get/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n }),\n },\n );\n return response;\n }\n}\n\nexport { MemoryClient };\n","// @ts-nocheck\nimport type { TelemetryClient, TelemetryOptions } from \"./telemetry.types\";\n\n// __MEM0_SDK_VERSION__ is inlined by tsup/esbuild's `define` at build time from\n// package.json. In unbundled environments (ts-jest, jest globalSetup) the\n// identifier is not defined, so guard with typeof to fall back safely.\nlet version =\n typeof __MEM0_SDK_VERSION__ !== \"undefined\" ? __MEM0_SDK_VERSION__ : \"dev\";\n\n// Safely check for process.env in different environments\nlet MEM0_TELEMETRY = true;\ntry {\n MEM0_TELEMETRY = process?.env?.MEM0_TELEMETRY === \"false\" ? false : true;\n} catch (error) {}\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com/i/v0/e/\";\n\n// Simple hash function using random strings\nfunction generateHash(input: string): string {\n const randomStr =\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15);\n return randomStr;\n}\n\nclass UnifiedTelemetry implements TelemetryClient {\n private apiKey: string;\n private host: string;\n\n constructor(projectApiKey: string, host: string) {\n this.apiKey = projectApiKey;\n this.host = host;\n }\n\n async captureEvent(\n distinctId: string,\n eventName: string,\n properties = {},\n ): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n\n const eventProperties = {\n client_version: version,\n timestamp: new Date().toISOString(),\n ...properties,\n $process_person_profile: false,\n $lib: \"posthog-node\",\n };\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: distinctId,\n event: eventName,\n properties: eventProperties,\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\"Telemetry event capture failed:\", await response.text());\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry event capture failed:\", error);\n return false;\n }\n }\n\n async captureIdentify(anonId: string, email: string): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n if (!anonId || !email || anonId === email) return false;\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: email,\n event: \"$identify\",\n properties: {\n $anon_distinct_id: anonId,\n client_source: \"typescript\",\n $lib: \"posthog-node\",\n },\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\n \"Telemetry identify capture failed:\",\n await response.text(),\n );\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry identify capture failed:\", error);\n return false;\n }\n }\n\n async shutdown() {\n // No shutdown needed for direct API calls\n }\n}\n\nfunction isTelemetryEnabled(): boolean {\n return MEM0_TELEMETRY;\n}\n\nconst telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);\n\nasync function captureClientEvent(\n eventName: string,\n instance: any,\n additionalData = {},\n) {\n if (!instance.telemetryId) {\n console.warn(\"No telemetry ID found for instance\");\n return;\n }\n\n const eventData = {\n function: `${instance.constructor.name}`,\n method: eventName,\n api_host: instance.host,\n timestamp: new Date().toISOString(),\n client_version: version,\n keys: additionalData?.keys || [],\n ...additionalData,\n };\n\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData,\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash, isTelemetryEnabled };\n","/**\n * Best-effort read/write of ~/.mem0/config.json from the TS SDK.\n *\n * Used to stitch PostHog identities: SDKs and CLIs persist anonymous\n * distinct_id values here, and the TS MemoryClient reads those on init to\n * fire $identify and merge them into the email identity.\n *\n * Node-only. Browsers (no `process.versions.node`) no-op.\n */\n\nexport interface Mem0AnonIds {\n oss?: string;\n cli?: string;\n aliasedPairs: string[];\n}\n\ninterface NodeFs {\n fs: typeof import(\"fs\");\n path: typeof import(\"path\");\n crypto: typeof import(\"crypto\");\n configPath: string;\n}\n\nasync function getNodeFs(): Promise<NodeFs | null> {\n if (typeof process === \"undefined\" || !process.versions?.node) return null;\n try {\n const [fs, path, os, crypto] = await Promise.all([\n import(\"fs\"),\n import(\"path\"),\n import(\"os\"),\n import(\"crypto\"),\n ]);\n const fsMod = (fs as any).default ?? fs;\n const pathMod = (path as any).default ?? path;\n const osMod = (os as any).default ?? os;\n const cryptoMod = (crypto as any).default ?? crypto;\n const dir = process.env.MEM0_DIR || pathMod.join(osMod.homedir(), \".mem0\");\n return {\n fs: fsMod,\n path: pathMod,\n crypto: cryptoMod,\n configPath: pathMod.join(dir, \"config.json\"),\n };\n } catch {\n return null;\n }\n}\n\nfunction loadConfig(node: NodeFs): Record<string, any> | null {\n try {\n if (!node.fs.existsSync(node.configPath)) return null;\n const parsed = JSON.parse(node.fs.readFileSync(node.configPath, \"utf8\"));\n return parsed && typeof parsed === \"object\" ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction writeConfig(node: NodeFs, config: Record<string, any>): void {\n node.fs.mkdirSync(node.path.dirname(node.configPath), { recursive: true });\n node.fs.writeFileSync(node.configPath, JSON.stringify(config, null, 4));\n}\n\nfunction aliasPairMarker(node: NodeFs, anonId: string, email: string): string {\n return node.crypto\n .createHash(\"sha256\")\n .update(`${anonId}\\0${email}`, \"utf8\")\n .digest(\"hex\");\n}\n\nfunction randomUserId(node: NodeFs): string {\n if (typeof node.crypto.randomUUID === \"function\") {\n return node.crypto.randomUUID();\n }\n return (\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n );\n}\n\nexport async function getOrCreateMem0UserId(): Promise<string | null> {\n const node = await getNodeFs();\n if (!node) return null;\n try {\n const config = loadConfig(node) ?? {};\n if (typeof config.user_id === \"string\" && config.user_id) {\n return config.user_id;\n }\n const userId = randomUserId(node);\n config.user_id = userId;\n writeConfig(node, config);\n return userId;\n } catch {\n return null;\n }\n}\n\nexport async function readMem0AnonIds(): Promise<Mem0AnonIds | null> {\n const node = await getNodeFs();\n if (!node) return null;\n const config = loadConfig(node);\n if (!config) return null;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n return {\n oss: typeof config.user_id === \"string\" ? config.user_id : undefined,\n cli:\n typeof telemetry.anonymous_id === \"string\"\n ? telemetry.anonymous_id\n : undefined,\n aliasedPairs: Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs.filter(\n (item: unknown) => typeof item === \"string\",\n )\n : [],\n };\n}\n\nexport async function isMem0Aliased(\n anonId: string,\n email: string,\n): Promise<boolean> {\n if (!anonId || !email) return false;\n const node = await getNodeFs();\n if (!node) return false;\n const config = loadConfig(node);\n if (!config) return false;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n return aliasedPairs.includes(aliasPairMarker(node, anonId, email));\n}\n\nexport async function markMem0Aliased(\n anonId: string,\n email: string,\n): Promise<void> {\n const node = await getNodeFs();\n if (!node) return;\n try {\n const config = loadConfig(node) ?? {};\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n const marker = aliasPairMarker(node, anonId, email);\n if (!aliasedPairs.includes(marker)) {\n aliasedPairs.push(marker);\n }\n telemetry.aliased_pairs = aliasedPairs;\n config.telemetry = telemetry;\n writeConfig(node, config);\n } catch {\n // Best-effort: read-only filesystems and unwritable paths just skip.\n }\n}\n","/**\n * Converts a camelCase string to snake_case.\n */\nexport function camelToSnake(str: string): string {\n // Skip all-uppercase keys (e.g. OR, AND, NOT — logical operators)\n if (str === str.toUpperCase()) return str;\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n}\n\n/**\n * Converts a snake_case string to camelCase.\n */\nfunction snakeToCamel(str: string): string {\n return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Recursively converts all keys of an object from camelCase to snake_case.\n * Used for converting user-facing camelCase params to API snake_case payloads.\n */\nexport function camelToSnakeKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(camelToSnakeKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n camelToSnake(key),\n camelToSnakeKeys(value),\n ]),\n );\n}\n\n/**\n * Recursively converts all keys of an object from snake_case to camelCase.\n * Used for converting API snake_case responses to user-facing camelCase.\n */\nexport function snakeToCamelKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(snakeToCamelKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n snakeToCamel(key),\n snakeToCamelKeys(value),\n ]),\n );\n}\n","/**\n * Structured exception classes for mem0 TypeScript SDK.\n *\n * Provides specific, actionable exceptions with error codes, suggestions,\n * and debug information. Maps HTTP status codes to appropriate exception types.\n *\n * @example\n * ```typescript\n * import { RateLimitError, MemoryNotFoundError } from 'mem0ai'\n *\n * try {\n * await client.get(memoryId)\n * } catch (e) {\n * if (e instanceof MemoryNotFoundError) {\n * console.log(e.suggestion) // \"The requested resource was not found\"\n * } else if (e instanceof RateLimitError) {\n * await sleep(e.debugInfo.retryAfter ?? 60)\n * }\n * }\n * ```\n */\n\nexport interface MemoryErrorOptions {\n details?: Record<string, unknown>;\n suggestion?: string;\n debugInfo?: Record<string, unknown>;\n}\n\n/**\n * Base exception for all memory-related errors.\n *\n * Every mem0 exception includes an error code for programmatic handling,\n * optional details, a user-friendly suggestion, and debug information.\n */\nexport class MemoryError extends Error {\n readonly errorCode: string;\n readonly details: Record<string, unknown>;\n readonly suggestion?: string;\n readonly debugInfo: Record<string, unknown>;\n\n constructor(\n message: string,\n errorCode: string,\n options: MemoryErrorOptions = {},\n ) {\n super(message);\n this.name = \"MemoryError\";\n this.errorCode = errorCode;\n this.details = options.details ?? {};\n this.suggestion = options.suggestion;\n this.debugInfo = options.debugInfo ?? {};\n\n // Fix prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Raised when authentication fails (401, 403). */\nexport class AuthenticationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"AuthenticationError\";\n }\n}\n\n/** Raised when rate limits are exceeded (429). */\nexport class RateLimitError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"RateLimitError\";\n }\n}\n\n/** Raised when input validation fails (400, 409, 422). */\nexport class ValidationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ValidationError\";\n }\n}\n\n/** Raised when a memory is not found (404). */\nexport class MemoryNotFoundError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryNotFoundError\";\n }\n}\n\n/** Raised when network connectivity issues occur (408, 502, 503, 504). */\nexport class NetworkError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"NetworkError\";\n }\n}\n\n/** Raised when client configuration is invalid. */\nexport class ConfigurationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ConfigurationError\";\n }\n}\n\n/** Raised when memory quota is exceeded (413). */\nexport class MemoryQuotaExceededError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryQuotaExceededError\";\n }\n}\n\n// ─── HTTP Status → Exception Mapping ─────────────────────\n\ntype MemoryErrorConstructor = new (\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n) => MemoryError;\n\nexport const HTTP_STATUS_TO_EXCEPTION: Record<number, MemoryErrorConstructor> =\n {\n 400: ValidationError,\n 401: AuthenticationError,\n 403: AuthenticationError,\n 404: MemoryNotFoundError,\n 408: NetworkError,\n 409: ValidationError,\n 413: MemoryQuotaExceededError,\n 422: ValidationError,\n 429: RateLimitError,\n 500: MemoryError,\n 502: NetworkError,\n 503: NetworkError,\n 504: NetworkError,\n };\n\nconst HTTP_SUGGESTIONS: Record<number, string> = {\n 400: \"Please check your request parameters and try again\",\n 401: \"Please check your API key and authentication credentials\",\n 403: \"You don't have permission to perform this operation\",\n 404: \"The requested resource was not found\",\n 408: \"Request timed out. Please try again\",\n 409: \"Resource conflict. Please check your request\",\n 413: \"Request too large. Please reduce the size of your request\",\n 422: \"Invalid request data. Please check your input\",\n 429: \"Rate limit exceeded. Please wait before making more requests\",\n 500: \"Internal server error. Please try again later\",\n 502: \"Service temporarily unavailable. Please try again later\",\n 503: \"Service unavailable. Please try again later\",\n 504: \"Gateway timeout. Please try again later\",\n};\n\n/**\n * Create an appropriate exception based on HTTP response status code.\n *\n * @param statusCode - HTTP status code from the response\n * @param responseText - Response body text\n * @param options - Additional error context (details, debugInfo)\n * @returns An instance of the appropriate MemoryError subclass\n */\nexport function createExceptionFromResponse(\n statusCode: number,\n responseText: string,\n options: Omit<MemoryErrorOptions, \"suggestion\"> = {},\n): MemoryError {\n const ExceptionClass = HTTP_STATUS_TO_EXCEPTION[statusCode] ?? MemoryError;\n const errorCode = `HTTP_${statusCode}`;\n const suggestion = HTTP_SUGGESTIONS[statusCode] ?? \"Please try again later\";\n\n return new ExceptionClass(\n responseText || `HTTP ${statusCode} error`,\n errorCode,\n { ...options, suggestion },\n );\n}\n","// ─── Entity Options (for add/delete — top-level identity) ───\nexport interface EntityOptions {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n}\n\n// ─── Per-Method Options ─────────────────────────────────────\nexport interface AddMemoryOptions extends EntityOptions {\n metadata?: Record<string, any>;\n infer?: boolean;\n customCategories?: custom_categories[];\n customInstructions?: string;\n timestamp?: number;\n structuredDataSchema?: Record<string, any>;\n}\n\nexport interface SearchMemoryOptions {\n filters?: Record<string, any>;\n metadata?: Record<string, any>;\n topK?: number;\n threshold?: number;\n rerank?: boolean;\n latestOnly?: boolean;\n fields?: string[];\n categories?: string[];\n}\n\nexport interface GetAllMemoryOptions {\n filters?: Record<string, any>;\n page?: number;\n pageSize?: number;\n startDate?: string;\n endDate?: string;\n latestOnly?: boolean;\n categories?: string[];\n}\n\nexport interface DeleteAllMemoryOptions extends EntityOptions {}\n\n// ─── Project Options ────────────────────────────────────────\nexport interface ProjectOptions {\n fields?: string[];\n}\n\nexport interface PromptUpdatePayload {\n customInstructions?: string;\n customCategories?: custom_categories[];\n retrievalCriteria?: any[];\n version?: string;\n memoryDepth?: string | null;\n usecaseSetting?: string | number;\n multilingual?: boolean;\n /**\n * Toggle Memory Decay for this project. When `true`, search-time ranking\n * boosts recently-used memories and gently dampens stale ones; when `false`,\n * ranking is restored to the pre-decay behaviour. Off by default.\n * See https://docs.mem0.ai/platform/features/memory-decay\n */\n decay?: boolean;\n [key: string]: any;\n}\n\n// ─── Enums ──────────────────────────────────────────────────\nexport enum Feedback {\n POSITIVE = \"POSITIVE\",\n NEGATIVE = \"NEGATIVE\",\n VERY_NEGATIVE = \"VERY_NEGATIVE\",\n}\n\n// ─── Message Types ──────────────────────────────────────────\nexport interface MultiModalMessages {\n type: \"image_url\";\n image_url: {\n url: string;\n };\n}\n\nexport interface Messages {\n role: \"user\" | \"assistant\";\n content: string | MultiModalMessages;\n}\n\nexport interface Message extends Messages {}\n\n// ─── Response Types (camelCase — converted from API snake_case) ─────\nexport interface MemoryData {\n memory: string;\n}\n\nenum Event {\n ADD = \"ADD\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n NOOP = \"NOOP\",\n}\n\nexport interface Memory {\n id: string;\n messages?: Array<Messages>;\n event?: Event | string;\n data?: MemoryData | null;\n memory?: string;\n userId?: string;\n hash?: string;\n categories?: Array<string>;\n createdAt?: Date;\n updatedAt?: Date;\n memoryType?: string;\n score?: number;\n metadata?: any | null;\n owner?: string | null;\n agentId?: string | null;\n appId?: string | null;\n runId?: string | null;\n}\n\nexport interface MemoryHistory {\n id: string;\n memoryId: string;\n input: Array<Messages>;\n oldMemory: string | null;\n newMemory: string | null;\n userId: string;\n categories: Array<string>;\n event: Event | string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface MemoryUpdateBody {\n memoryId: string;\n text: string;\n}\n\nexport interface User {\n id: string;\n name: string;\n createdAt: Date;\n updatedAt: Date;\n totalMemories: 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 PaginatedMemories {\n count: number;\n next: string | null;\n previous: string | null;\n results: Array<Memory>;\n}\n\nexport interface ProjectResponse {\n customInstructions?: string;\n customCategories?: string[];\n [key: string]: any;\n}\n\ninterface custom_categories {\n [key: string]: any;\n}\n\n// ─── Webhook Types ──────────────────────────────────────────\nexport enum WebhookEvent {\n MEMORY_ADDED = \"memory_add\",\n MEMORY_UPDATED = \"memory_update\",\n MEMORY_DELETED = \"memory_delete\",\n MEMORY_CATEGORIZED = \"memory_categorize\",\n}\n\nexport interface Webhook {\n webhookId?: string;\n name: string;\n url: string;\n project?: string;\n createdAt?: Date;\n updatedAt?: Date;\n isActive?: boolean;\n eventTypes?: WebhookEvent[];\n}\n\nexport interface WebhookCreatePayload {\n name: string;\n url: string;\n eventTypes: WebhookEvent[];\n}\n\nexport interface WebhookUpdatePayload {\n webhookId: string;\n name?: string;\n url?: string;\n eventTypes?: WebhookEvent[];\n}\n\n// ─── Feedback & Export Types ────────────────────────────────\nexport interface FeedbackPayload {\n memoryId: string;\n feedback?: Feedback | null;\n feedbackReason?: string | null;\n}\n\nexport interface CreateMemoryExportPayload {\n schema: Record<string, any>;\n filters: Record<string, any>;\n exportInstructions?: string;\n}\n\nexport interface GetMemoryExportPayload {\n filters?: Record<string, any>;\n memoryExportId?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACMlB,IAAI,UACF,OAA8C,UAAuB;AAGvE,IAAI,iBAAiB;AAVrB;AAWA,IAAI;AACF,qBAAiB,wCAAS,QAAT,mBAAc,oBAAmB,UAAU,QAAQ;AACtE,SAAS,OAAO;AAAC;AACjB,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,SAAS,aAAa,OA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AA,cAAW;AACX,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,mBAAgB;AAHN,SAAAA;AAAA,GAAA;AA0GL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,wBAAqB;AAJX,SAAAA;AAAA,GAAA;;;AN3IZ,IAAO,gBAAQ;","names":["_a","telemetry","_a","axios","Feedback","WebhookEvent"]}
1
+ {"version":3,"sources":["../src/client/index.ts","../src/client/mem0.ts","../src/client/telemetry.ts","../src/client/config.ts","../src/client/utils.ts","../src/common/exceptions.ts","../src/client/mem0.types.ts"],"sourcesContent":["import { MemoryClient } from \"./mem0\";\nimport type * as MemoryTypes from \"./mem0.types\";\n\n// Re-export all types from mem0.types\nexport type {\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Messages,\n Message,\n AllUsers,\n User,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\n\n// Re-export enums as values (not type-only)\nexport { Feedback, WebhookEvent } from \"./mem0.types\";\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;\n\n// Export structured exceptions\nexport {\n MemoryError,\n AuthenticationError,\n RateLimitError,\n ValidationError,\n MemoryNotFoundError,\n NetworkError,\n ConfigurationError,\n MemoryQuotaExceededError,\n createExceptionFromResponse,\n} from \"../common/exceptions\";\n\nexport type { MemoryErrorOptions } from \"../common/exceptions\";\n","import axios from \"axios\";\nimport {\n AllUsers,\n PaginatedMemories,\n ProjectOptions,\n Memory,\n MemoryHistory,\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n DeleteMemoryOptions,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Message,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\nimport {\n captureClientEvent,\n generateHash,\n isTelemetryEnabled,\n telemetry,\n} from \"./telemetry\";\nimport {\n getOrCreateMem0UserId,\n isMem0Aliased,\n markMem0Aliased,\n readMem0AnonIds,\n} from \"./config\";\nimport { camelToSnake, camelToSnakeKeys, snakeToCamelKeys } from \"./utils\";\nimport { createExceptionFromResponse, MemoryError } from \"../common/exceptions\";\n\n// Entity params that must be passed via filters - check both snake_case and camelCase\nconst ENTITY_PARAMS = [\n \"user_id\",\n \"agent_id\",\n \"app_id\",\n \"run_id\",\n \"userId\",\n \"agentId\",\n \"appId\",\n \"runId\",\n];\n\n/**\n * Validates that no top-level entity parameters are passed.\n * @throws Error if entity params are found at top level\n */\nfunction rejectTopLevelEntityParams(\n options: Record<string, any> | undefined,\n methodName: string,\n): void {\n const invalidKeys = Object.keys(options ?? {}).filter((k) =>\n ENTITY_PARAMS.includes(k),\n );\n if (invalidKeys.length > 0) {\n throw new Error(\n `Top-level entity parameters [${invalidKeys.join(\", \")}] are not supported in ${methodName}(). ` +\n `Use filters: { user_id: \"...\" } instead.`,\n );\n }\n}\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}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n private organizationId: string | number | null;\n private 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 constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationId = null;\n this.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.telemetryId = \"\";\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n await this.ping();\n\n if (!this.telemetryId) {\n this.telemetryId = generateHash(this.apiKey);\n }\n\n await this._maybeAliasAnonToEmail();\n\n captureClientEvent(\"init\", this, {\n client_type: \"MemoryClient\",\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n } catch (error: any) {\n console.error(\"Failed to initialize client:\", error);\n await captureClientEvent(\"init_error\", this, {\n error: error?.message || \"Unknown error\",\n stack: error?.stack || \"No stack trace\",\n });\n }\n }\n\n private async _maybeAliasAnonToEmail(): Promise<void> {\n if (!isTelemetryEnabled()) return;\n try {\n const email = this.telemetryId;\n if (!email || !email.includes(\"@\")) return;\n const sharedAnonId = await getOrCreateMem0UserId();\n const anonIds = await readMem0AnonIds();\n if (!anonIds && !sharedAnonId) return;\n const candidates = [anonIds?.oss || sharedAnonId, anonIds?.cli].filter(\n (id): id is string => !!id && id !== email,\n );\n const seen = new Set<string>();\n for (const anonId of candidates) {\n if (seen.has(anonId) || (await isMem0Aliased(anonId, email))) continue;\n seen.add(anonId);\n if (await telemetry.captureIdentify(anonId, email)) {\n await markMem0Aliased(anonId, email);\n }\n }\n } catch (error: any) {\n console.error(\"Failed to alias telemetry identity:\", error);\n }\n }\n\n private _captureEvent(methodName: string, args: any[]) {\n captureClientEvent(methodName, this, {\n success: true,\n args_count: args.length,\n keys: args.length > 0 ? args[0] : [],\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n }\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Token ${this.apiKey}`,\n \"Mem0-User-ID\": this.telemetryId,\n },\n });\n if (!response.ok) {\n const errorData = await response.text();\n throw createExceptionFromResponse(response.status, errorData);\n }\n const jsonResponse = await response.json();\n return snakeToCamelKeys(jsonResponse);\n }\n\n _preparePayload(\n messages: Array<Message>,\n options: Record<string, any>,\n ): object {\n const payload: any = {};\n payload.messages = messages;\n return camelToSnakeKeys({ ...payload, ...options });\n }\n\n _prepareParams(options: Record<string, any>): object {\n return Object.fromEntries(\n Object.entries(options).filter(([_, v]) => v != null),\n );\n }\n\n async ping(): Promise<void> {\n try {\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/ping/`,\n {\n method: \"GET\",\n headers: {\n Authorization: `Token ${this.apiKey}`,\n },\n },\n );\n\n if (!response || typeof response !== \"object\") {\n throw new APIError(\"Invalid response format from ping endpoint\");\n }\n\n if (response.status !== \"ok\") {\n throw new APIError(response.message || \"API Key is invalid\");\n }\n\n const { orgId, projectId, userEmail } = response;\n\n if (orgId) this.organizationId = orgId;\n if (projectId) this.projectId = projectId;\n if (userEmail) this.telemetryId = userEmail;\n } catch (error: any) {\n // Pass through structured exceptions and APIError\n if (error instanceof MemoryError || error instanceof APIError) {\n throw error;\n } else {\n throw new APIError(\n `Failed to ping server: ${error.message || \"Unknown error\"}`,\n );\n }\n }\n }\n\n async add(\n messages: Array<Message>,\n options: AddMemoryOptions & Record<string, any> = {},\n ): Promise<Array<Memory>> {\n if (this.telemetryId === \"\") await this.ping();\n\n const payload = this._preparePayload(messages, options);\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"add\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/add/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async update(\n memoryId: string,\n {\n text,\n metadata,\n timestamp,\n }: {\n text?: string;\n metadata?: Record<string, any>;\n timestamp?: number | string;\n },\n ): Promise<Array<Memory>> {\n if (\n text === undefined &&\n metadata === undefined &&\n timestamp === undefined\n ) {\n throw new Error(\n \"At least one of text, metadata, or timestamp must be provided for update.\",\n );\n }\n\n if (this.telemetryId === \"\") await this.ping();\n const payload: Record<string, any> = {};\n if (text !== undefined) payload.text = text;\n if (metadata !== undefined) payload.metadata = metadata;\n if (timestamp !== undefined) payload.timestamp = timestamp;\n\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"update\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async get(memoryId: string): Promise<Memory> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get\", []);\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n headers: this.headers,\n },\n );\n }\n\n async getAll(options?: GetAllMemoryOptions): Promise<PaginatedMemories> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"getAll\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_all\", [payloadKeys]);\n const { page, pageSize, filters, ...rest } = options ?? {};\n const body: Record<string, any> = {\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n let url = `${this.host}/v3/memories/`;\n if (page && pageSize) {\n url += `?page=${page}&page_size=${pageSize}`;\n }\n\n const response = await this._fetchWithErrorHandling(url, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n });\n return response;\n }\n\n async search(\n query: string,\n options?: SearchMemoryOptions,\n ): Promise<{ results: Array<Memory> }> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"search\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"search\", [payloadKeys]);\n const { filters, ...rest } = options ?? {};\n const payload: Record<string, any> = {\n query,\n output_format: \"v1.1\",\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/search/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async delete(\n memoryId: string,\n options: DeleteMemoryOptions = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete\", [Object.keys(options || {})]);\n const snakeOptions = camelToSnakeKeys(this._prepareParams(options));\n // @ts-ignore\n const query = new URLSearchParams(snakeOptions).toString();\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/${query ? `?${query}` : \"\"}`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n }\n\n async deleteAll(\n options: DeleteAllMemoryOptions = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"delete_all\", [payloadKeys]);\n const snakeOptions = camelToSnakeKeys(this._prepareParams(options));\n // @ts-ignore\n const params = new URLSearchParams(snakeOptions);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/?${params}`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"history\", []);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/history/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async users(options?: {\n page?: number;\n pageSize?: number;\n }): Promise<AllUsers> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"users\", []);\n let url = `${this.host}/v1/entities/`;\n const params: string[] = [];\n if (options?.page) params.push(`page=${options.page}`);\n if (options?.pageSize) params.push(`page_size=${options.pageSize}`);\n if (params.length) url += `?${params.join(\"&\")}`;\n const response = await this._fetchWithErrorHandling(url, {\n headers: this.headers,\n });\n return response;\n }\n\n /**\n * @deprecated The method should not be used, use `deleteUsers` instead. This will be removed in version 2.2.0.\n */\n async deleteUser(data: {\n entity_id: number;\n entity_type: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_user\", []);\n if (!data.entity_type) {\n data.entity_type = \"user\";\n }\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/${data.entity_type}/${data.entity_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUsers(\n params: {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n } = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n\n let to_delete: Array<{ type: string; name: string }> = [];\n const { userId, agentId, appId, runId } = params;\n\n if (userId) {\n to_delete = [{ type: \"user\", name: userId }];\n } else if (agentId) {\n to_delete = [{ type: \"agent\", name: agentId }];\n } else if (appId) {\n to_delete = [{ type: \"app\", name: appId }];\n } else if (runId) {\n to_delete = [{ type: \"run\", name: runId }];\n } else {\n const entities = await this.users();\n to_delete = entities.results.map((entity) => ({\n type: entity.type,\n name: entity.name,\n }));\n }\n\n if (to_delete.length === 0) {\n throw new Error(\"No entities to delete\");\n }\n\n for (const entity of to_delete) {\n try {\n await this.client.delete(`/v2/entities/${entity.type}/${entity.name}/`);\n } catch (error: any) {\n throw new APIError(\n `Failed to delete ${entity.type} ${entity.name}: ${error.message}`,\n );\n }\n }\n\n this._captureEvent(\"delete_users\", [\n { userId, agentId, appId, runId, sync_type: \"sync\" },\n ]);\n\n return {\n message:\n userId || agentId || appId || runId\n ? \"Entity deleted successfully.\"\n : \"All users, agents, apps and runs deleted.\",\n };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_update\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory.memoryId,\n text: memory.text,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_delete\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_project\", [payloadKeys]);\n const { fields } = options;\n\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to access instructions or categories\",\n );\n }\n\n const params = new URLSearchParams();\n fields?.forEach((field) => params.append(\"fields\", camelToSnake(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(\n prompts: PromptUpdatePayload,\n ): Promise<Record<string, any>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_project\", []);\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to update instructions or categories\",\n );\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(camelToSnakeKeys(prompts)),\n },\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_webhooks\", []);\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${project_id}/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async createWebhook(webhook: WebhookCreatePayload): Promise<Webhook> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_webhook\", []);\n const body = {\n name: webhook.name,\n url: webhook.url,\n event_types: webhook.eventTypes,\n };\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${this.projectId}/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async updateWebhook(\n webhook: WebhookUpdatePayload,\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_webhook\", []);\n const body: Record<string, any> = {};\n if (webhook.name != null) body.name = webhook.name;\n if (webhook.url != null) body.url = webhook.url;\n if (webhook.eventTypes != null) body.event_types = webhook.eventTypes;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async deleteWebhook(data: {\n webhookId: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_webhook\", []);\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async feedback(data: FeedbackPayload): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(data || {});\n this._captureEvent(\"feedback\", [payloadKeys]);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/feedback/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(camelToSnakeKeys(data)),\n },\n );\n return response;\n }\n\n async createMemoryExport(\n data: CreateMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_memory_export\", []);\n\n if (!data.filters || !data.schema) {\n throw new Error(\"Missing filters or schema\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n filters,\n }),\n },\n );\n\n return response;\n }\n\n async getMemoryExport(\n data: GetMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_memory_export\", []);\n\n if (!data.memoryExportId && !data.filters) {\n throw new Error(\"Missing memoryExportId or filters\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/get/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n }),\n },\n );\n return response;\n }\n}\n\nexport { MemoryClient };\n","// @ts-nocheck\nimport type { TelemetryClient, TelemetryOptions } from \"./telemetry.types\";\n\n// __MEM0_SDK_VERSION__ is inlined by tsup/esbuild's `define` at build time from\n// package.json. In unbundled environments (ts-jest, jest globalSetup) the\n// identifier is not defined, so guard with typeof to fall back safely.\nlet version =\n typeof __MEM0_SDK_VERSION__ !== \"undefined\" ? __MEM0_SDK_VERSION__ : \"dev\";\n\n// Safely check for process.env in different environments\nlet MEM0_TELEMETRY = true;\ntry {\n MEM0_TELEMETRY = process?.env?.MEM0_TELEMETRY === \"false\" ? false : true;\n} catch (error) {}\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com/i/v0/e/\";\n\n// Simple hash function using random strings\nfunction generateHash(input: string): string {\n const randomStr =\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15);\n return randomStr;\n}\n\nclass UnifiedTelemetry implements TelemetryClient {\n private apiKey: string;\n private host: string;\n\n constructor(projectApiKey: string, host: string) {\n this.apiKey = projectApiKey;\n this.host = host;\n }\n\n async captureEvent(\n distinctId: string,\n eventName: string,\n properties = {},\n ): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n\n const eventProperties = {\n client_version: version,\n timestamp: new Date().toISOString(),\n ...properties,\n $process_person_profile: false,\n $lib: \"posthog-node\",\n };\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: distinctId,\n event: eventName,\n properties: eventProperties,\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\"Telemetry event capture failed:\", await response.text());\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry event capture failed:\", error);\n return false;\n }\n }\n\n async captureIdentify(anonId: string, email: string): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n if (!anonId || !email || anonId === email) return false;\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: email,\n event: \"$identify\",\n properties: {\n $anon_distinct_id: anonId,\n client_source: \"typescript\",\n $lib: \"posthog-node\",\n },\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\n \"Telemetry identify capture failed:\",\n await response.text(),\n );\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry identify capture failed:\", error);\n return false;\n }\n }\n\n async shutdown() {\n // No shutdown needed for direct API calls\n }\n}\n\nfunction isTelemetryEnabled(): boolean {\n return MEM0_TELEMETRY;\n}\n\nconst telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);\n\nasync function captureClientEvent(\n eventName: string,\n instance: any,\n additionalData = {},\n) {\n if (!instance.telemetryId) {\n console.warn(\"No telemetry ID found for instance\");\n return;\n }\n\n const eventData = {\n function: `${instance.constructor.name}`,\n method: eventName,\n api_host: instance.host,\n timestamp: new Date().toISOString(),\n client_version: version,\n keys: additionalData?.keys || [],\n ...additionalData,\n };\n\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData,\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash, isTelemetryEnabled };\n","/**\n * Best-effort read/write of ~/.mem0/config.json from the TS SDK.\n *\n * Used to stitch PostHog identities: SDKs and CLIs persist anonymous\n * distinct_id values here, and the TS MemoryClient reads those on init to\n * fire $identify and merge them into the email identity.\n *\n * Node-only. Browsers (no `process.versions.node`) no-op.\n */\n\nexport interface Mem0AnonIds {\n oss?: string;\n cli?: string;\n aliasedPairs: string[];\n}\n\ninterface NodeFs {\n fs: typeof import(\"fs\");\n path: typeof import(\"path\");\n crypto: typeof import(\"crypto\");\n configPath: string;\n}\n\nasync function getNodeFs(): Promise<NodeFs | null> {\n if (typeof process === \"undefined\" || !process.versions?.node) return null;\n try {\n const [fs, path, os, crypto] = await Promise.all([\n import(\"fs\"),\n import(\"path\"),\n import(\"os\"),\n import(\"crypto\"),\n ]);\n const fsMod = (fs as any).default ?? fs;\n const pathMod = (path as any).default ?? path;\n const osMod = (os as any).default ?? os;\n const cryptoMod = (crypto as any).default ?? crypto;\n const dir = process.env.MEM0_DIR || pathMod.join(osMod.homedir(), \".mem0\");\n return {\n fs: fsMod,\n path: pathMod,\n crypto: cryptoMod,\n configPath: pathMod.join(dir, \"config.json\"),\n };\n } catch {\n return null;\n }\n}\n\nfunction loadConfig(node: NodeFs): Record<string, any> | null {\n try {\n if (!node.fs.existsSync(node.configPath)) return null;\n const parsed = JSON.parse(node.fs.readFileSync(node.configPath, \"utf8\"));\n return parsed && typeof parsed === \"object\" ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction writeConfig(node: NodeFs, config: Record<string, any>): void {\n node.fs.mkdirSync(node.path.dirname(node.configPath), { recursive: true });\n node.fs.writeFileSync(node.configPath, JSON.stringify(config, null, 4));\n}\n\nfunction aliasPairMarker(node: NodeFs, anonId: string, email: string): string {\n return node.crypto\n .createHash(\"sha256\")\n .update(`${anonId}\\0${email}`, \"utf8\")\n .digest(\"hex\");\n}\n\nfunction randomUserId(node: NodeFs): string {\n if (typeof node.crypto.randomUUID === \"function\") {\n return node.crypto.randomUUID();\n }\n return (\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n );\n}\n\nexport async function getOrCreateMem0UserId(): Promise<string | null> {\n const node = await getNodeFs();\n if (!node) return null;\n try {\n const config = loadConfig(node) ?? {};\n if (typeof config.user_id === \"string\" && config.user_id) {\n return config.user_id;\n }\n const userId = randomUserId(node);\n config.user_id = userId;\n writeConfig(node, config);\n return userId;\n } catch {\n return null;\n }\n}\n\nexport async function readMem0AnonIds(): Promise<Mem0AnonIds | null> {\n const node = await getNodeFs();\n if (!node) return null;\n const config = loadConfig(node);\n if (!config) return null;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n return {\n oss: typeof config.user_id === \"string\" ? config.user_id : undefined,\n cli:\n typeof telemetry.anonymous_id === \"string\"\n ? telemetry.anonymous_id\n : undefined,\n aliasedPairs: Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs.filter(\n (item: unknown) => typeof item === \"string\",\n )\n : [],\n };\n}\n\nexport async function isMem0Aliased(\n anonId: string,\n email: string,\n): Promise<boolean> {\n if (!anonId || !email) return false;\n const node = await getNodeFs();\n if (!node) return false;\n const config = loadConfig(node);\n if (!config) return false;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n return aliasedPairs.includes(aliasPairMarker(node, anonId, email));\n}\n\nexport async function markMem0Aliased(\n anonId: string,\n email: string,\n): Promise<void> {\n const node = await getNodeFs();\n if (!node) return;\n try {\n const config = loadConfig(node) ?? {};\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n const marker = aliasPairMarker(node, anonId, email);\n if (!aliasedPairs.includes(marker)) {\n aliasedPairs.push(marker);\n }\n telemetry.aliased_pairs = aliasedPairs;\n config.telemetry = telemetry;\n writeConfig(node, config);\n } catch {\n // Best-effort: read-only filesystems and unwritable paths just skip.\n }\n}\n","/**\n * Converts a camelCase string to snake_case.\n */\nexport function camelToSnake(str: string): string {\n // Skip all-uppercase keys (e.g. OR, AND, NOT — logical operators)\n if (str === str.toUpperCase()) return str;\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n}\n\n/**\n * Converts a snake_case string to camelCase.\n */\nfunction snakeToCamel(str: string): string {\n return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Recursively converts all keys of an object from camelCase to snake_case.\n * Used for converting user-facing camelCase params to API snake_case payloads.\n */\nexport function camelToSnakeKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(camelToSnakeKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n camelToSnake(key),\n camelToSnakeKeys(value),\n ]),\n );\n}\n\n/**\n * Recursively converts all keys of an object from snake_case to camelCase.\n * Used for converting API snake_case responses to user-facing camelCase.\n */\nexport function snakeToCamelKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(snakeToCamelKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n snakeToCamel(key),\n snakeToCamelKeys(value),\n ]),\n );\n}\n","/**\n * Structured exception classes for mem0 TypeScript SDK.\n *\n * Provides specific, actionable exceptions with error codes, suggestions,\n * and debug information. Maps HTTP status codes to appropriate exception types.\n *\n * @example\n * ```typescript\n * import { RateLimitError, MemoryNotFoundError } from 'mem0ai'\n *\n * try {\n * await client.get(memoryId)\n * } catch (e) {\n * if (e instanceof MemoryNotFoundError) {\n * console.log(e.suggestion) // \"The requested resource was not found\"\n * } else if (e instanceof RateLimitError) {\n * await sleep(e.debugInfo.retryAfter ?? 60)\n * }\n * }\n * ```\n */\n\nexport interface MemoryErrorOptions {\n details?: Record<string, unknown>;\n suggestion?: string;\n debugInfo?: Record<string, unknown>;\n}\n\n/**\n * Base exception for all memory-related errors.\n *\n * Every mem0 exception includes an error code for programmatic handling,\n * optional details, a user-friendly suggestion, and debug information.\n */\nexport class MemoryError extends Error {\n readonly errorCode: string;\n readonly details: Record<string, unknown>;\n readonly suggestion?: string;\n readonly debugInfo: Record<string, unknown>;\n\n constructor(\n message: string,\n errorCode: string,\n options: MemoryErrorOptions = {},\n ) {\n super(message);\n this.name = \"MemoryError\";\n this.errorCode = errorCode;\n this.details = options.details ?? {};\n this.suggestion = options.suggestion;\n this.debugInfo = options.debugInfo ?? {};\n\n // Fix prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Raised when authentication fails (401, 403). */\nexport class AuthenticationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"AuthenticationError\";\n }\n}\n\n/** Raised when rate limits are exceeded (429). */\nexport class RateLimitError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"RateLimitError\";\n }\n}\n\n/** Raised when input validation fails (400, 409, 422). */\nexport class ValidationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ValidationError\";\n }\n}\n\n/** Raised when a memory is not found (404). */\nexport class MemoryNotFoundError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryNotFoundError\";\n }\n}\n\n/** Raised when network connectivity issues occur (408, 502, 503, 504). */\nexport class NetworkError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"NetworkError\";\n }\n}\n\n/** Raised when client configuration is invalid. */\nexport class ConfigurationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ConfigurationError\";\n }\n}\n\n/** Raised when memory quota is exceeded (413). */\nexport class MemoryQuotaExceededError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryQuotaExceededError\";\n }\n}\n\n// ─── HTTP Status → Exception Mapping ─────────────────────\n\ntype MemoryErrorConstructor = new (\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n) => MemoryError;\n\nexport const HTTP_STATUS_TO_EXCEPTION: Record<number, MemoryErrorConstructor> =\n {\n 400: ValidationError,\n 401: AuthenticationError,\n 403: AuthenticationError,\n 404: MemoryNotFoundError,\n 408: NetworkError,\n 409: ValidationError,\n 413: MemoryQuotaExceededError,\n 422: ValidationError,\n 429: RateLimitError,\n 500: MemoryError,\n 502: NetworkError,\n 503: NetworkError,\n 504: NetworkError,\n };\n\nconst HTTP_SUGGESTIONS: Record<number, string> = {\n 400: \"Please check your request parameters and try again\",\n 401: \"Please check your API key and authentication credentials\",\n 403: \"You don't have permission to perform this operation\",\n 404: \"The requested resource was not found\",\n 408: \"Request timed out. Please try again\",\n 409: \"Resource conflict. Please check your request\",\n 413: \"Request too large. Please reduce the size of your request\",\n 422: \"Invalid request data. Please check your input\",\n 429: \"Rate limit exceeded. Please wait before making more requests\",\n 500: \"Internal server error. Please try again later\",\n 502: \"Service temporarily unavailable. Please try again later\",\n 503: \"Service unavailable. Please try again later\",\n 504: \"Gateway timeout. Please try again later\",\n};\n\n/**\n * Create an appropriate exception based on HTTP response status code.\n *\n * @param statusCode - HTTP status code from the response\n * @param responseText - Response body text\n * @param options - Additional error context (details, debugInfo)\n * @returns An instance of the appropriate MemoryError subclass\n */\nexport function createExceptionFromResponse(\n statusCode: number,\n responseText: string,\n options: Omit<MemoryErrorOptions, \"suggestion\"> = {},\n): MemoryError {\n const ExceptionClass = HTTP_STATUS_TO_EXCEPTION[statusCode] ?? MemoryError;\n const errorCode = `HTTP_${statusCode}`;\n const suggestion = HTTP_SUGGESTIONS[statusCode] ?? \"Please try again later\";\n\n return new ExceptionClass(\n responseText || `HTTP ${statusCode} error`,\n errorCode,\n { ...options, suggestion },\n );\n}\n","// ─── Entity Options (for add/delete — top-level identity) ───\nexport interface EntityOptions {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n}\n\n// ─── Per-Method Options ─────────────────────────────────────\nexport interface AddMemoryOptions extends EntityOptions {\n metadata?: Record<string, any>;\n infer?: boolean;\n customCategories?: custom_categories[];\n customInstructions?: string;\n timestamp?: number;\n structuredDataSchema?: Record<string, any>;\n}\n\nexport interface SearchMemoryOptions {\n filters?: Record<string, any>;\n metadata?: Record<string, any>;\n topK?: number;\n threshold?: number;\n rerank?: boolean;\n latestOnly?: boolean;\n fields?: string[];\n categories?: string[];\n}\n\nexport interface GetAllMemoryOptions {\n filters?: Record<string, any>;\n page?: number;\n pageSize?: number;\n startDate?: string;\n endDate?: string;\n latestOnly?: boolean;\n categories?: string[];\n}\n\nexport interface DeleteAllMemoryOptions extends EntityOptions {}\n\nexport interface DeleteMemoryOptions {\n /**\n * When `true`, also delete the older memories this one superseded (the v3\n * linked chain), transitively — the delete-side counterpart of `latestOnly`.\n * Off by default. Serialized as `delete_linked`.\n */\n deleteLinked?: boolean;\n}\n\n// ─── Project Options ────────────────────────────────────────\nexport interface ProjectOptions {\n fields?: string[];\n}\n\nexport interface PromptUpdatePayload {\n customInstructions?: string;\n customCategories?: custom_categories[];\n retrievalCriteria?: any[];\n version?: string;\n memoryDepth?: string | null;\n usecaseSetting?: string | number;\n multilingual?: boolean;\n /**\n * Toggle Memory Decay for this project. When `true`, search-time ranking\n * boosts recently-used memories and gently dampens stale ones; when `false`,\n * ranking is restored to the pre-decay behaviour. Off by default.\n * See https://docs.mem0.ai/platform/features/memory-decay\n */\n decay?: boolean;\n [key: string]: any;\n}\n\n// ─── Enums ──────────────────────────────────────────────────\nexport enum Feedback {\n POSITIVE = \"POSITIVE\",\n NEGATIVE = \"NEGATIVE\",\n VERY_NEGATIVE = \"VERY_NEGATIVE\",\n}\n\n// ─── Message Types ──────────────────────────────────────────\nexport interface MultiModalMessages {\n type: \"image_url\";\n image_url: {\n url: string;\n };\n}\n\nexport interface Messages {\n role: \"user\" | \"assistant\";\n content: string | MultiModalMessages;\n}\n\nexport interface Message extends Messages {}\n\n// ─── Response Types (camelCase — converted from API snake_case) ─────\nexport interface MemoryData {\n memory: string;\n}\n\nenum Event {\n ADD = \"ADD\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n NOOP = \"NOOP\",\n}\n\nexport interface Memory {\n id: string;\n messages?: Array<Messages>;\n event?: Event | string;\n data?: MemoryData | null;\n memory?: string;\n userId?: string;\n hash?: string;\n categories?: Array<string>;\n createdAt?: Date;\n updatedAt?: Date;\n memoryType?: string;\n score?: number;\n metadata?: any | null;\n owner?: string | null;\n agentId?: string | null;\n appId?: string | null;\n runId?: string | null;\n}\n\nexport interface MemoryHistory {\n id: string;\n memoryId: string;\n input: Array<Messages>;\n oldMemory: string | null;\n newMemory: string | null;\n userId: string;\n categories: Array<string>;\n event: Event | string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface MemoryUpdateBody {\n memoryId: string;\n text: string;\n}\n\nexport interface User {\n id: string;\n name: string;\n createdAt: Date;\n updatedAt: Date;\n totalMemories: 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 PaginatedMemories {\n count: number;\n next: string | null;\n previous: string | null;\n results: Array<Memory>;\n}\n\nexport interface ProjectResponse {\n customInstructions?: string;\n customCategories?: string[];\n [key: string]: any;\n}\n\ninterface custom_categories {\n [key: string]: any;\n}\n\n// ─── Webhook Types ──────────────────────────────────────────\nexport enum WebhookEvent {\n MEMORY_ADDED = \"memory_add\",\n MEMORY_UPDATED = \"memory_update\",\n MEMORY_DELETED = \"memory_delete\",\n MEMORY_CATEGORIZED = \"memory_categorize\",\n}\n\nexport interface Webhook {\n webhookId?: string;\n name: string;\n url: string;\n project?: string;\n createdAt?: Date;\n updatedAt?: Date;\n isActive?: boolean;\n eventTypes?: WebhookEvent[];\n}\n\nexport interface WebhookCreatePayload {\n name: string;\n url: string;\n eventTypes: WebhookEvent[];\n}\n\nexport interface WebhookUpdatePayload {\n webhookId: string;\n name?: string;\n url?: string;\n eventTypes?: WebhookEvent[];\n}\n\n// ─── Feedback & Export Types ────────────────────────────────\nexport interface FeedbackPayload {\n memoryId: string;\n feedback?: Feedback | null;\n feedbackReason?: string | null;\n}\n\nexport interface CreateMemoryExportPayload {\n schema: Record<string, any>;\n filters: Record<string, any>;\n exportInstructions?: string;\n}\n\nexport interface GetMemoryExportPayload {\n filters?: Record<string, any>;\n memoryExportId?: string;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;;;ACMlB,IAAI,UACF,OAA8C,UAAuB;AAGvE,IAAI,iBAAiB;AAVrB;AAWA,IAAI;AACF,qBAAiB,wCAAS,QAAT,mBAAc,oBAAmB,UAAU,QAAQ;AACtE,SAAS,OAAO;AAAC;AACjB,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,SAAS,aAAa,OAAuB;AAC3C,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,GAAG,iBAAiB,IAAI;AAAA,UACxB,GAAI,WAAW,EAAE,QAAQ;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AKxpBO,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,mBAAgB;AAHN,SAAAA;AAAA,GAAA;AA0GL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,wBAAqB;AAJX,SAAAA;AAAA,GAAA;;;ANpJZ,IAAO,gBAAQ;","names":["_a","telemetry","_a","axios","Feedback","WebhookEvent"]}
package/dist/index.mjs CHANGED
@@ -2,7 +2,7 @@
2
2
  import axios from "axios";
3
3
 
4
4
  // src/client/telemetry.ts
5
- var version = true ? "3.0.4" : "dev";
5
+ var version = true ? "3.0.5" : "dev";
6
6
  var MEM0_TELEMETRY = true;
7
7
  var _a;
8
8
  try {
@@ -612,11 +612,13 @@ var MemoryClient = class {
612
612
  );
613
613
  return response;
614
614
  }
615
- async delete(memoryId) {
615
+ async delete(memoryId, options = {}) {
616
616
  if (this.telemetryId === "") await this.ping();
617
- this._captureEvent("delete", []);
617
+ this._captureEvent("delete", [Object.keys(options || {})]);
618
+ const snakeOptions = camelToSnakeKeys(this._prepareParams(options));
619
+ const query = new URLSearchParams(snakeOptions).toString();
618
620
  return this._fetchWithErrorHandling(
619
- `${this.host}/v1/memories/${memoryId}/`,
621
+ `${this.host}/v1/memories/${memoryId}/${query ? `?${query}` : ""}`,
620
622
  {
621
623
  method: "DELETE",
622
624
  headers: this.headers
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/client/mem0.ts","../src/client/telemetry.ts","../src/client/config.ts","../src/client/utils.ts","../src/common/exceptions.ts","../src/client/mem0.types.ts","../src/client/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n AllUsers,\n PaginatedMemories,\n ProjectOptions,\n Memory,\n MemoryHistory,\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Message,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\nimport {\n captureClientEvent,\n generateHash,\n isTelemetryEnabled,\n telemetry,\n} from \"./telemetry\";\nimport {\n getOrCreateMem0UserId,\n isMem0Aliased,\n markMem0Aliased,\n readMem0AnonIds,\n} from \"./config\";\nimport { camelToSnake, camelToSnakeKeys, snakeToCamelKeys } from \"./utils\";\nimport { createExceptionFromResponse, MemoryError } from \"../common/exceptions\";\n\n// Entity params that must be passed via filters - check both snake_case and camelCase\nconst ENTITY_PARAMS = [\n \"user_id\",\n \"agent_id\",\n \"app_id\",\n \"run_id\",\n \"userId\",\n \"agentId\",\n \"appId\",\n \"runId\",\n];\n\n/**\n * Validates that no top-level entity parameters are passed.\n * @throws Error if entity params are found at top level\n */\nfunction rejectTopLevelEntityParams(\n options: Record<string, any> | undefined,\n methodName: string,\n): void {\n const invalidKeys = Object.keys(options ?? {}).filter((k) =>\n ENTITY_PARAMS.includes(k),\n );\n if (invalidKeys.length > 0) {\n throw new Error(\n `Top-level entity parameters [${invalidKeys.join(\", \")}] are not supported in ${methodName}(). ` +\n `Use filters: { user_id: \"...\" } instead.`,\n );\n }\n}\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}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n private organizationId: string | number | null;\n private 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 constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationId = null;\n this.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.telemetryId = \"\";\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n await this.ping();\n\n if (!this.telemetryId) {\n this.telemetryId = generateHash(this.apiKey);\n }\n\n await this._maybeAliasAnonToEmail();\n\n captureClientEvent(\"init\", this, {\n client_type: \"MemoryClient\",\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n } catch (error: any) {\n console.error(\"Failed to initialize client:\", error);\n await captureClientEvent(\"init_error\", this, {\n error: error?.message || \"Unknown error\",\n stack: error?.stack || \"No stack trace\",\n });\n }\n }\n\n private async _maybeAliasAnonToEmail(): Promise<void> {\n if (!isTelemetryEnabled()) return;\n try {\n const email = this.telemetryId;\n if (!email || !email.includes(\"@\")) return;\n const sharedAnonId = await getOrCreateMem0UserId();\n const anonIds = await readMem0AnonIds();\n if (!anonIds && !sharedAnonId) return;\n const candidates = [anonIds?.oss || sharedAnonId, anonIds?.cli].filter(\n (id): id is string => !!id && id !== email,\n );\n const seen = new Set<string>();\n for (const anonId of candidates) {\n if (seen.has(anonId) || (await isMem0Aliased(anonId, email))) continue;\n seen.add(anonId);\n if (await telemetry.captureIdentify(anonId, email)) {\n await markMem0Aliased(anonId, email);\n }\n }\n } catch (error: any) {\n console.error(\"Failed to alias telemetry identity:\", error);\n }\n }\n\n private _captureEvent(methodName: string, args: any[]) {\n captureClientEvent(methodName, this, {\n success: true,\n args_count: args.length,\n keys: args.length > 0 ? args[0] : [],\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n }\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Token ${this.apiKey}`,\n \"Mem0-User-ID\": this.telemetryId,\n },\n });\n if (!response.ok) {\n const errorData = await response.text();\n throw createExceptionFromResponse(response.status, errorData);\n }\n const jsonResponse = await response.json();\n return snakeToCamelKeys(jsonResponse);\n }\n\n _preparePayload(\n messages: Array<Message>,\n options: Record<string, any>,\n ): object {\n const payload: any = {};\n payload.messages = messages;\n return camelToSnakeKeys({ ...payload, ...options });\n }\n\n _prepareParams(options: Record<string, any>): object {\n return Object.fromEntries(\n Object.entries(options).filter(([_, v]) => v != null),\n );\n }\n\n async ping(): Promise<void> {\n try {\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/ping/`,\n {\n method: \"GET\",\n headers: {\n Authorization: `Token ${this.apiKey}`,\n },\n },\n );\n\n if (!response || typeof response !== \"object\") {\n throw new APIError(\"Invalid response format from ping endpoint\");\n }\n\n if (response.status !== \"ok\") {\n throw new APIError(response.message || \"API Key is invalid\");\n }\n\n const { orgId, projectId, userEmail } = response;\n\n if (orgId) this.organizationId = orgId;\n if (projectId) this.projectId = projectId;\n if (userEmail) this.telemetryId = userEmail;\n } catch (error: any) {\n // Pass through structured exceptions and APIError\n if (error instanceof MemoryError || error instanceof APIError) {\n throw error;\n } else {\n throw new APIError(\n `Failed to ping server: ${error.message || \"Unknown error\"}`,\n );\n }\n }\n }\n\n async add(\n messages: Array<Message>,\n options: AddMemoryOptions & Record<string, any> = {},\n ): Promise<Array<Memory>> {\n if (this.telemetryId === \"\") await this.ping();\n\n const payload = this._preparePayload(messages, options);\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"add\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/add/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async update(\n memoryId: string,\n {\n text,\n metadata,\n timestamp,\n }: {\n text?: string;\n metadata?: Record<string, any>;\n timestamp?: number | string;\n },\n ): Promise<Array<Memory>> {\n if (\n text === undefined &&\n metadata === undefined &&\n timestamp === undefined\n ) {\n throw new Error(\n \"At least one of text, metadata, or timestamp must be provided for update.\",\n );\n }\n\n if (this.telemetryId === \"\") await this.ping();\n const payload: Record<string, any> = {};\n if (text !== undefined) payload.text = text;\n if (metadata !== undefined) payload.metadata = metadata;\n if (timestamp !== undefined) payload.timestamp = timestamp;\n\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"update\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async get(memoryId: string): Promise<Memory> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get\", []);\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n headers: this.headers,\n },\n );\n }\n\n async getAll(options?: GetAllMemoryOptions): Promise<PaginatedMemories> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"getAll\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_all\", [payloadKeys]);\n const { page, pageSize, filters, ...rest } = options ?? {};\n const body: Record<string, any> = {\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n let url = `${this.host}/v3/memories/`;\n if (page && pageSize) {\n url += `?page=${page}&page_size=${pageSize}`;\n }\n\n const response = await this._fetchWithErrorHandling(url, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n });\n return response;\n }\n\n async search(\n query: string,\n options?: SearchMemoryOptions,\n ): Promise<{ results: Array<Memory> }> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"search\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"search\", [payloadKeys]);\n const { filters, ...rest } = options ?? {};\n const payload: Record<string, any> = {\n query,\n output_format: \"v1.1\",\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/search/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async delete(memoryId: string): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete\", []);\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n }\n\n async deleteAll(\n options: DeleteAllMemoryOptions = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"delete_all\", [payloadKeys]);\n const snakeOptions = camelToSnakeKeys(this._prepareParams(options));\n // @ts-ignore\n const params = new URLSearchParams(snakeOptions);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/?${params}`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"history\", []);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/history/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async users(options?: {\n page?: number;\n pageSize?: number;\n }): Promise<AllUsers> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"users\", []);\n let url = `${this.host}/v1/entities/`;\n const params: string[] = [];\n if (options?.page) params.push(`page=${options.page}`);\n if (options?.pageSize) params.push(`page_size=${options.pageSize}`);\n if (params.length) url += `?${params.join(\"&\")}`;\n const response = await this._fetchWithErrorHandling(url, {\n headers: this.headers,\n });\n return response;\n }\n\n /**\n * @deprecated The method should not be used, use `deleteUsers` instead. This will be removed in version 2.2.0.\n */\n async deleteUser(data: {\n entity_id: number;\n entity_type: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_user\", []);\n if (!data.entity_type) {\n data.entity_type = \"user\";\n }\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/${data.entity_type}/${data.entity_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUsers(\n params: {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n } = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n\n let to_delete: Array<{ type: string; name: string }> = [];\n const { userId, agentId, appId, runId } = params;\n\n if (userId) {\n to_delete = [{ type: \"user\", name: userId }];\n } else if (agentId) {\n to_delete = [{ type: \"agent\", name: agentId }];\n } else if (appId) {\n to_delete = [{ type: \"app\", name: appId }];\n } else if (runId) {\n to_delete = [{ type: \"run\", name: runId }];\n } else {\n const entities = await this.users();\n to_delete = entities.results.map((entity) => ({\n type: entity.type,\n name: entity.name,\n }));\n }\n\n if (to_delete.length === 0) {\n throw new Error(\"No entities to delete\");\n }\n\n for (const entity of to_delete) {\n try {\n await this.client.delete(`/v2/entities/${entity.type}/${entity.name}/`);\n } catch (error: any) {\n throw new APIError(\n `Failed to delete ${entity.type} ${entity.name}: ${error.message}`,\n );\n }\n }\n\n this._captureEvent(\"delete_users\", [\n { userId, agentId, appId, runId, sync_type: \"sync\" },\n ]);\n\n return {\n message:\n userId || agentId || appId || runId\n ? \"Entity deleted successfully.\"\n : \"All users, agents, apps and runs deleted.\",\n };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_update\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory.memoryId,\n text: memory.text,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_delete\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_project\", [payloadKeys]);\n const { fields } = options;\n\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to access instructions or categories\",\n );\n }\n\n const params = new URLSearchParams();\n fields?.forEach((field) => params.append(\"fields\", camelToSnake(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(\n prompts: PromptUpdatePayload,\n ): Promise<Record<string, any>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_project\", []);\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to update instructions or categories\",\n );\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(camelToSnakeKeys(prompts)),\n },\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_webhooks\", []);\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${project_id}/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async createWebhook(webhook: WebhookCreatePayload): Promise<Webhook> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_webhook\", []);\n const body = {\n name: webhook.name,\n url: webhook.url,\n event_types: webhook.eventTypes,\n };\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${this.projectId}/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async updateWebhook(\n webhook: WebhookUpdatePayload,\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_webhook\", []);\n const body: Record<string, any> = {};\n if (webhook.name != null) body.name = webhook.name;\n if (webhook.url != null) body.url = webhook.url;\n if (webhook.eventTypes != null) body.event_types = webhook.eventTypes;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async deleteWebhook(data: {\n webhookId: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_webhook\", []);\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async feedback(data: FeedbackPayload): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(data || {});\n this._captureEvent(\"feedback\", [payloadKeys]);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/feedback/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(camelToSnakeKeys(data)),\n },\n );\n return response;\n }\n\n async createMemoryExport(\n data: CreateMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_memory_export\", []);\n\n if (!data.filters || !data.schema) {\n throw new Error(\"Missing filters or schema\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n filters,\n }),\n },\n );\n\n return response;\n }\n\n async getMemoryExport(\n data: GetMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_memory_export\", []);\n\n if (!data.memoryExportId && !data.filters) {\n throw new Error(\"Missing memoryExportId or filters\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/get/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n }),\n },\n );\n return response;\n }\n}\n\nexport { MemoryClient };\n","// @ts-nocheck\nimport type { TelemetryClient, TelemetryOptions } from \"./telemetry.types\";\n\n// __MEM0_SDK_VERSION__ is inlined by tsup/esbuild's `define` at build time from\n// package.json. In unbundled environments (ts-jest, jest globalSetup) the\n// identifier is not defined, so guard with typeof to fall back safely.\nlet version =\n typeof __MEM0_SDK_VERSION__ !== \"undefined\" ? __MEM0_SDK_VERSION__ : \"dev\";\n\n// Safely check for process.env in different environments\nlet MEM0_TELEMETRY = true;\ntry {\n MEM0_TELEMETRY = process?.env?.MEM0_TELEMETRY === \"false\" ? false : true;\n} catch (error) {}\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com/i/v0/e/\";\n\n// Simple hash function using random strings\nfunction generateHash(input: string): string {\n const randomStr =\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15);\n return randomStr;\n}\n\nclass UnifiedTelemetry implements TelemetryClient {\n private apiKey: string;\n private host: string;\n\n constructor(projectApiKey: string, host: string) {\n this.apiKey = projectApiKey;\n this.host = host;\n }\n\n async captureEvent(\n distinctId: string,\n eventName: string,\n properties = {},\n ): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n\n const eventProperties = {\n client_version: version,\n timestamp: new Date().toISOString(),\n ...properties,\n $process_person_profile: false,\n $lib: \"posthog-node\",\n };\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: distinctId,\n event: eventName,\n properties: eventProperties,\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\"Telemetry event capture failed:\", await response.text());\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry event capture failed:\", error);\n return false;\n }\n }\n\n async captureIdentify(anonId: string, email: string): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n if (!anonId || !email || anonId === email) return false;\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: email,\n event: \"$identify\",\n properties: {\n $anon_distinct_id: anonId,\n client_source: \"typescript\",\n $lib: \"posthog-node\",\n },\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\n \"Telemetry identify capture failed:\",\n await response.text(),\n );\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry identify capture failed:\", error);\n return false;\n }\n }\n\n async shutdown() {\n // No shutdown needed for direct API calls\n }\n}\n\nfunction isTelemetryEnabled(): boolean {\n return MEM0_TELEMETRY;\n}\n\nconst telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);\n\nasync function captureClientEvent(\n eventName: string,\n instance: any,\n additionalData = {},\n) {\n if (!instance.telemetryId) {\n console.warn(\"No telemetry ID found for instance\");\n return;\n }\n\n const eventData = {\n function: `${instance.constructor.name}`,\n method: eventName,\n api_host: instance.host,\n timestamp: new Date().toISOString(),\n client_version: version,\n keys: additionalData?.keys || [],\n ...additionalData,\n };\n\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData,\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash, isTelemetryEnabled };\n","/**\n * Best-effort read/write of ~/.mem0/config.json from the TS SDK.\n *\n * Used to stitch PostHog identities: SDKs and CLIs persist anonymous\n * distinct_id values here, and the TS MemoryClient reads those on init to\n * fire $identify and merge them into the email identity.\n *\n * Node-only. Browsers (no `process.versions.node`) no-op.\n */\n\nexport interface Mem0AnonIds {\n oss?: string;\n cli?: string;\n aliasedPairs: string[];\n}\n\ninterface NodeFs {\n fs: typeof import(\"fs\");\n path: typeof import(\"path\");\n crypto: typeof import(\"crypto\");\n configPath: string;\n}\n\nasync function getNodeFs(): Promise<NodeFs | null> {\n if (typeof process === \"undefined\" || !process.versions?.node) return null;\n try {\n const [fs, path, os, crypto] = await Promise.all([\n import(\"fs\"),\n import(\"path\"),\n import(\"os\"),\n import(\"crypto\"),\n ]);\n const fsMod = (fs as any).default ?? fs;\n const pathMod = (path as any).default ?? path;\n const osMod = (os as any).default ?? os;\n const cryptoMod = (crypto as any).default ?? crypto;\n const dir = process.env.MEM0_DIR || pathMod.join(osMod.homedir(), \".mem0\");\n return {\n fs: fsMod,\n path: pathMod,\n crypto: cryptoMod,\n configPath: pathMod.join(dir, \"config.json\"),\n };\n } catch {\n return null;\n }\n}\n\nfunction loadConfig(node: NodeFs): Record<string, any> | null {\n try {\n if (!node.fs.existsSync(node.configPath)) return null;\n const parsed = JSON.parse(node.fs.readFileSync(node.configPath, \"utf8\"));\n return parsed && typeof parsed === \"object\" ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction writeConfig(node: NodeFs, config: Record<string, any>): void {\n node.fs.mkdirSync(node.path.dirname(node.configPath), { recursive: true });\n node.fs.writeFileSync(node.configPath, JSON.stringify(config, null, 4));\n}\n\nfunction aliasPairMarker(node: NodeFs, anonId: string, email: string): string {\n return node.crypto\n .createHash(\"sha256\")\n .update(`${anonId}\\0${email}`, \"utf8\")\n .digest(\"hex\");\n}\n\nfunction randomUserId(node: NodeFs): string {\n if (typeof node.crypto.randomUUID === \"function\") {\n return node.crypto.randomUUID();\n }\n return (\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n );\n}\n\nexport async function getOrCreateMem0UserId(): Promise<string | null> {\n const node = await getNodeFs();\n if (!node) return null;\n try {\n const config = loadConfig(node) ?? {};\n if (typeof config.user_id === \"string\" && config.user_id) {\n return config.user_id;\n }\n const userId = randomUserId(node);\n config.user_id = userId;\n writeConfig(node, config);\n return userId;\n } catch {\n return null;\n }\n}\n\nexport async function readMem0AnonIds(): Promise<Mem0AnonIds | null> {\n const node = await getNodeFs();\n if (!node) return null;\n const config = loadConfig(node);\n if (!config) return null;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n return {\n oss: typeof config.user_id === \"string\" ? config.user_id : undefined,\n cli:\n typeof telemetry.anonymous_id === \"string\"\n ? telemetry.anonymous_id\n : undefined,\n aliasedPairs: Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs.filter(\n (item: unknown) => typeof item === \"string\",\n )\n : [],\n };\n}\n\nexport async function isMem0Aliased(\n anonId: string,\n email: string,\n): Promise<boolean> {\n if (!anonId || !email) return false;\n const node = await getNodeFs();\n if (!node) return false;\n const config = loadConfig(node);\n if (!config) return false;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n return aliasedPairs.includes(aliasPairMarker(node, anonId, email));\n}\n\nexport async function markMem0Aliased(\n anonId: string,\n email: string,\n): Promise<void> {\n const node = await getNodeFs();\n if (!node) return;\n try {\n const config = loadConfig(node) ?? {};\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n const marker = aliasPairMarker(node, anonId, email);\n if (!aliasedPairs.includes(marker)) {\n aliasedPairs.push(marker);\n }\n telemetry.aliased_pairs = aliasedPairs;\n config.telemetry = telemetry;\n writeConfig(node, config);\n } catch {\n // Best-effort: read-only filesystems and unwritable paths just skip.\n }\n}\n","/**\n * Converts a camelCase string to snake_case.\n */\nexport function camelToSnake(str: string): string {\n // Skip all-uppercase keys (e.g. OR, AND, NOT — logical operators)\n if (str === str.toUpperCase()) return str;\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n}\n\n/**\n * Converts a snake_case string to camelCase.\n */\nfunction snakeToCamel(str: string): string {\n return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Recursively converts all keys of an object from camelCase to snake_case.\n * Used for converting user-facing camelCase params to API snake_case payloads.\n */\nexport function camelToSnakeKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(camelToSnakeKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n camelToSnake(key),\n camelToSnakeKeys(value),\n ]),\n );\n}\n\n/**\n * Recursively converts all keys of an object from snake_case to camelCase.\n * Used for converting API snake_case responses to user-facing camelCase.\n */\nexport function snakeToCamelKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(snakeToCamelKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n snakeToCamel(key),\n snakeToCamelKeys(value),\n ]),\n );\n}\n","/**\n * Structured exception classes for mem0 TypeScript SDK.\n *\n * Provides specific, actionable exceptions with error codes, suggestions,\n * and debug information. Maps HTTP status codes to appropriate exception types.\n *\n * @example\n * ```typescript\n * import { RateLimitError, MemoryNotFoundError } from 'mem0ai'\n *\n * try {\n * await client.get(memoryId)\n * } catch (e) {\n * if (e instanceof MemoryNotFoundError) {\n * console.log(e.suggestion) // \"The requested resource was not found\"\n * } else if (e instanceof RateLimitError) {\n * await sleep(e.debugInfo.retryAfter ?? 60)\n * }\n * }\n * ```\n */\n\nexport interface MemoryErrorOptions {\n details?: Record<string, unknown>;\n suggestion?: string;\n debugInfo?: Record<string, unknown>;\n}\n\n/**\n * Base exception for all memory-related errors.\n *\n * Every mem0 exception includes an error code for programmatic handling,\n * optional details, a user-friendly suggestion, and debug information.\n */\nexport class MemoryError extends Error {\n readonly errorCode: string;\n readonly details: Record<string, unknown>;\n readonly suggestion?: string;\n readonly debugInfo: Record<string, unknown>;\n\n constructor(\n message: string,\n errorCode: string,\n options: MemoryErrorOptions = {},\n ) {\n super(message);\n this.name = \"MemoryError\";\n this.errorCode = errorCode;\n this.details = options.details ?? {};\n this.suggestion = options.suggestion;\n this.debugInfo = options.debugInfo ?? {};\n\n // Fix prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Raised when authentication fails (401, 403). */\nexport class AuthenticationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"AuthenticationError\";\n }\n}\n\n/** Raised when rate limits are exceeded (429). */\nexport class RateLimitError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"RateLimitError\";\n }\n}\n\n/** Raised when input validation fails (400, 409, 422). */\nexport class ValidationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ValidationError\";\n }\n}\n\n/** Raised when a memory is not found (404). */\nexport class MemoryNotFoundError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryNotFoundError\";\n }\n}\n\n/** Raised when network connectivity issues occur (408, 502, 503, 504). */\nexport class NetworkError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"NetworkError\";\n }\n}\n\n/** Raised when client configuration is invalid. */\nexport class ConfigurationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ConfigurationError\";\n }\n}\n\n/** Raised when memory quota is exceeded (413). */\nexport class MemoryQuotaExceededError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryQuotaExceededError\";\n }\n}\n\n// ─── HTTP Status → Exception Mapping ─────────────────────\n\ntype MemoryErrorConstructor = new (\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n) => MemoryError;\n\nexport const HTTP_STATUS_TO_EXCEPTION: Record<number, MemoryErrorConstructor> =\n {\n 400: ValidationError,\n 401: AuthenticationError,\n 403: AuthenticationError,\n 404: MemoryNotFoundError,\n 408: NetworkError,\n 409: ValidationError,\n 413: MemoryQuotaExceededError,\n 422: ValidationError,\n 429: RateLimitError,\n 500: MemoryError,\n 502: NetworkError,\n 503: NetworkError,\n 504: NetworkError,\n };\n\nconst HTTP_SUGGESTIONS: Record<number, string> = {\n 400: \"Please check your request parameters and try again\",\n 401: \"Please check your API key and authentication credentials\",\n 403: \"You don't have permission to perform this operation\",\n 404: \"The requested resource was not found\",\n 408: \"Request timed out. Please try again\",\n 409: \"Resource conflict. Please check your request\",\n 413: \"Request too large. Please reduce the size of your request\",\n 422: \"Invalid request data. Please check your input\",\n 429: \"Rate limit exceeded. Please wait before making more requests\",\n 500: \"Internal server error. Please try again later\",\n 502: \"Service temporarily unavailable. Please try again later\",\n 503: \"Service unavailable. Please try again later\",\n 504: \"Gateway timeout. Please try again later\",\n};\n\n/**\n * Create an appropriate exception based on HTTP response status code.\n *\n * @param statusCode - HTTP status code from the response\n * @param responseText - Response body text\n * @param options - Additional error context (details, debugInfo)\n * @returns An instance of the appropriate MemoryError subclass\n */\nexport function createExceptionFromResponse(\n statusCode: number,\n responseText: string,\n options: Omit<MemoryErrorOptions, \"suggestion\"> = {},\n): MemoryError {\n const ExceptionClass = HTTP_STATUS_TO_EXCEPTION[statusCode] ?? MemoryError;\n const errorCode = `HTTP_${statusCode}`;\n const suggestion = HTTP_SUGGESTIONS[statusCode] ?? \"Please try again later\";\n\n return new ExceptionClass(\n responseText || `HTTP ${statusCode} error`,\n errorCode,\n { ...options, suggestion },\n );\n}\n","// ─── Entity Options (for add/delete — top-level identity) ───\nexport interface EntityOptions {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n}\n\n// ─── Per-Method Options ─────────────────────────────────────\nexport interface AddMemoryOptions extends EntityOptions {\n metadata?: Record<string, any>;\n infer?: boolean;\n customCategories?: custom_categories[];\n customInstructions?: string;\n timestamp?: number;\n structuredDataSchema?: Record<string, any>;\n}\n\nexport interface SearchMemoryOptions {\n filters?: Record<string, any>;\n metadata?: Record<string, any>;\n topK?: number;\n threshold?: number;\n rerank?: boolean;\n latestOnly?: boolean;\n fields?: string[];\n categories?: string[];\n}\n\nexport interface GetAllMemoryOptions {\n filters?: Record<string, any>;\n page?: number;\n pageSize?: number;\n startDate?: string;\n endDate?: string;\n latestOnly?: boolean;\n categories?: string[];\n}\n\nexport interface DeleteAllMemoryOptions extends EntityOptions {}\n\n// ─── Project Options ────────────────────────────────────────\nexport interface ProjectOptions {\n fields?: string[];\n}\n\nexport interface PromptUpdatePayload {\n customInstructions?: string;\n customCategories?: custom_categories[];\n retrievalCriteria?: any[];\n version?: string;\n memoryDepth?: string | null;\n usecaseSetting?: string | number;\n multilingual?: boolean;\n /**\n * Toggle Memory Decay for this project. When `true`, search-time ranking\n * boosts recently-used memories and gently dampens stale ones; when `false`,\n * ranking is restored to the pre-decay behaviour. Off by default.\n * See https://docs.mem0.ai/platform/features/memory-decay\n */\n decay?: boolean;\n [key: string]: any;\n}\n\n// ─── Enums ──────────────────────────────────────────────────\nexport enum Feedback {\n POSITIVE = \"POSITIVE\",\n NEGATIVE = \"NEGATIVE\",\n VERY_NEGATIVE = \"VERY_NEGATIVE\",\n}\n\n// ─── Message Types ──────────────────────────────────────────\nexport interface MultiModalMessages {\n type: \"image_url\";\n image_url: {\n url: string;\n };\n}\n\nexport interface Messages {\n role: \"user\" | \"assistant\";\n content: string | MultiModalMessages;\n}\n\nexport interface Message extends Messages {}\n\n// ─── Response Types (camelCase — converted from API snake_case) ─────\nexport interface MemoryData {\n memory: string;\n}\n\nenum Event {\n ADD = \"ADD\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n NOOP = \"NOOP\",\n}\n\nexport interface Memory {\n id: string;\n messages?: Array<Messages>;\n event?: Event | string;\n data?: MemoryData | null;\n memory?: string;\n userId?: string;\n hash?: string;\n categories?: Array<string>;\n createdAt?: Date;\n updatedAt?: Date;\n memoryType?: string;\n score?: number;\n metadata?: any | null;\n owner?: string | null;\n agentId?: string | null;\n appId?: string | null;\n runId?: string | null;\n}\n\nexport interface MemoryHistory {\n id: string;\n memoryId: string;\n input: Array<Messages>;\n oldMemory: string | null;\n newMemory: string | null;\n userId: string;\n categories: Array<string>;\n event: Event | string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface MemoryUpdateBody {\n memoryId: string;\n text: string;\n}\n\nexport interface User {\n id: string;\n name: string;\n createdAt: Date;\n updatedAt: Date;\n totalMemories: 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 PaginatedMemories {\n count: number;\n next: string | null;\n previous: string | null;\n results: Array<Memory>;\n}\n\nexport interface ProjectResponse {\n customInstructions?: string;\n customCategories?: string[];\n [key: string]: any;\n}\n\ninterface custom_categories {\n [key: string]: any;\n}\n\n// ─── Webhook Types ──────────────────────────────────────────\nexport enum WebhookEvent {\n MEMORY_ADDED = \"memory_add\",\n MEMORY_UPDATED = \"memory_update\",\n MEMORY_DELETED = \"memory_delete\",\n MEMORY_CATEGORIZED = \"memory_categorize\",\n}\n\nexport interface Webhook {\n webhookId?: string;\n name: string;\n url: string;\n project?: string;\n createdAt?: Date;\n updatedAt?: Date;\n isActive?: boolean;\n eventTypes?: WebhookEvent[];\n}\n\nexport interface WebhookCreatePayload {\n name: string;\n url: string;\n eventTypes: WebhookEvent[];\n}\n\nexport interface WebhookUpdatePayload {\n webhookId: string;\n name?: string;\n url?: string;\n eventTypes?: WebhookEvent[];\n}\n\n// ─── Feedback & Export Types ────────────────────────────────\nexport interface FeedbackPayload {\n memoryId: string;\n feedback?: Feedback | null;\n feedbackReason?: string | null;\n}\n\nexport interface CreateMemoryExportPayload {\n schema: Record<string, any>;\n filters: Record<string, any>;\n exportInstructions?: string;\n}\n\nexport interface GetMemoryExportPayload {\n filters?: Record<string, any>;\n memoryExportId?: string;\n}\n","import { MemoryClient } from \"./mem0\";\nimport type * as MemoryTypes from \"./mem0.types\";\n\n// Re-export all types from mem0.types\nexport type {\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Messages,\n Message,\n AllUsers,\n User,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\n\n// Re-export enums as values (not type-only)\nexport { Feedback, WebhookEvent } from \"./mem0.types\";\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;\n\n// Export structured exceptions\nexport {\n MemoryError,\n AuthenticationError,\n RateLimitError,\n ValidationError,\n MemoryNotFoundError,\n NetworkError,\n ConfigurationError,\n MemoryQuotaExceededError,\n createExceptionFromResponse,\n} from \"../common/exceptions\";\n\nexport type { MemoryErrorOptions } from \"../common/exceptions\";\n"],"mappings":";AAAA,OAAO,WAAW;;;ACMlB,IAAI,UACF,OAA8C,UAAuB;AAGvE,IAAI,iBAAiB;AAVrB;AAWA,IAAI;AACF,qBAAiB,wCAAS,QAAT,mBAAc,oBAAmB,UAAU,QAAQ;AACtE,SAAS,OAAO;AAAC;AACjB,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,SAAS,aAAa,OAAuB;AAC3C,QAAM,YACJ,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,EAAE,IAC1C,KAAK,OAAO,EAAE,SAAS,EAAE,EAAE,UAAU,GAAG,EAAE;AAC5C,SAAO;AACT;AAEA,IAAM,mBAAN,MAAkD;AAAA,EAIhD,YAAY,eAAuB,MAAc;AAC/C,SAAK,SAAS;AACd,SAAK,OAAO;AAAA,EACd;AAAA,EAEA,MAAM,aACJ,YACA,WACA,aAAa,CAAC,GACI;AAClB,QAAI,CAAC,eAAgB,QAAO;AAE5B,UAAM,kBAAkB;AAAA,MACtB,gBAAgB;AAAA,MAChB,YAAW,oBAAI,KAAK,GAAE,YAAY;AAAA,MAClC,GAAG;AAAA,MACH,yBAAyB;AAAA,MACzB,MAAM;AAAA,IACR;AAEA,UAAM,UAAU;AAAA,MACd,SAAS,KAAK;AAAA,MACd,aAAa;AAAA,MACb,OAAO;AAAA,MACP,YAAY;AAAA,IACd;AAEA,QAAI;AACF,YAAM,WAAW,MAAM,MAAM,KAAK,MAAM;AAAA,QACtC,QAAQ;AAAA,QACR,SAAS;AAAA,UACP,gBAAgB;AAAA,QAClB;AAAA,QACA,MAAM,KAAK,UAAU,OAAO;AAAA,MAC9B,CAAC;AAED,UAAI,CAAC,SAAS,IAAI;AAChB,gBAAQ,MAAM,mCAAmC,MAAM,SAAS,KAAK,CAAC;AACtE,eAAO;AAAA,MACT;AACA,aAAO;AAAA,I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B,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI;AAAA,MACZ;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,QACd,MAAM,KAAK,UAAU;AAAA,UACnB,GAAG,iBAAiB,IAAI;AAAA,UACxB,GAAI,WAAW,EAAE,QAAQ;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AK1pBO,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,mBAAgB;AAHN,SAAAA;AAAA,GAAA;AA0GL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,wBAAqB;AAJX,SAAAA;AAAA,GAAA;;;AC3IZ,IAAO,gBAAQ;","names":["_a","telemetry","_a","Feedback","WebhookEvent"]}
1
+ {"version":3,"sources":["../src/client/mem0.ts","../src/client/telemetry.ts","../src/client/config.ts","../src/client/utils.ts","../src/common/exceptions.ts","../src/client/mem0.types.ts","../src/client/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n AllUsers,\n PaginatedMemories,\n ProjectOptions,\n Memory,\n MemoryHistory,\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n DeleteMemoryOptions,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Message,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\nimport {\n captureClientEvent,\n generateHash,\n isTelemetryEnabled,\n telemetry,\n} from \"./telemetry\";\nimport {\n getOrCreateMem0UserId,\n isMem0Aliased,\n markMem0Aliased,\n readMem0AnonIds,\n} from \"./config\";\nimport { camelToSnake, camelToSnakeKeys, snakeToCamelKeys } from \"./utils\";\nimport { createExceptionFromResponse, MemoryError } from \"../common/exceptions\";\n\n// Entity params that must be passed via filters - check both snake_case and camelCase\nconst ENTITY_PARAMS = [\n \"user_id\",\n \"agent_id\",\n \"app_id\",\n \"run_id\",\n \"userId\",\n \"agentId\",\n \"appId\",\n \"runId\",\n];\n\n/**\n * Validates that no top-level entity parameters are passed.\n * @throws Error if entity params are found at top level\n */\nfunction rejectTopLevelEntityParams(\n options: Record<string, any> | undefined,\n methodName: string,\n): void {\n const invalidKeys = Object.keys(options ?? {}).filter((k) =>\n ENTITY_PARAMS.includes(k),\n );\n if (invalidKeys.length > 0) {\n throw new Error(\n `Top-level entity parameters [${invalidKeys.join(\", \")}] are not supported in ${methodName}(). ` +\n `Use filters: { user_id: \"...\" } instead.`,\n );\n }\n}\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}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n private organizationId: string | number | null;\n private 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 constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationId = null;\n this.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.telemetryId = \"\";\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n await this.ping();\n\n if (!this.telemetryId) {\n this.telemetryId = generateHash(this.apiKey);\n }\n\n await this._maybeAliasAnonToEmail();\n\n captureClientEvent(\"init\", this, {\n client_type: \"MemoryClient\",\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n } catch (error: any) {\n console.error(\"Failed to initialize client:\", error);\n await captureClientEvent(\"init_error\", this, {\n error: error?.message || \"Unknown error\",\n stack: error?.stack || \"No stack trace\",\n });\n }\n }\n\n private async _maybeAliasAnonToEmail(): Promise<void> {\n if (!isTelemetryEnabled()) return;\n try {\n const email = this.telemetryId;\n if (!email || !email.includes(\"@\")) return;\n const sharedAnonId = await getOrCreateMem0UserId();\n const anonIds = await readMem0AnonIds();\n if (!anonIds && !sharedAnonId) return;\n const candidates = [anonIds?.oss || sharedAnonId, anonIds?.cli].filter(\n (id): id is string => !!id && id !== email,\n );\n const seen = new Set<string>();\n for (const anonId of candidates) {\n if (seen.has(anonId) || (await isMem0Aliased(anonId, email))) continue;\n seen.add(anonId);\n if (await telemetry.captureIdentify(anonId, email)) {\n await markMem0Aliased(anonId, email);\n }\n }\n } catch (error: any) {\n console.error(\"Failed to alias telemetry identity:\", error);\n }\n }\n\n private _captureEvent(methodName: string, args: any[]) {\n captureClientEvent(methodName, this, {\n success: true,\n args_count: args.length,\n keys: args.length > 0 ? args[0] : [],\n }).catch((error: any) => {\n console.error(\"Failed to capture event:\", error);\n });\n }\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, {\n ...options,\n headers: {\n ...options.headers,\n Authorization: `Token ${this.apiKey}`,\n \"Mem0-User-ID\": this.telemetryId,\n },\n });\n if (!response.ok) {\n const errorData = await response.text();\n throw createExceptionFromResponse(response.status, errorData);\n }\n const jsonResponse = await response.json();\n return snakeToCamelKeys(jsonResponse);\n }\n\n _preparePayload(\n messages: Array<Message>,\n options: Record<string, any>,\n ): object {\n const payload: any = {};\n payload.messages = messages;\n return camelToSnakeKeys({ ...payload, ...options });\n }\n\n _prepareParams(options: Record<string, any>): object {\n return Object.fromEntries(\n Object.entries(options).filter(([_, v]) => v != null),\n );\n }\n\n async ping(): Promise<void> {\n try {\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/ping/`,\n {\n method: \"GET\",\n headers: {\n Authorization: `Token ${this.apiKey}`,\n },\n },\n );\n\n if (!response || typeof response !== \"object\") {\n throw new APIError(\"Invalid response format from ping endpoint\");\n }\n\n if (response.status !== \"ok\") {\n throw new APIError(response.message || \"API Key is invalid\");\n }\n\n const { orgId, projectId, userEmail } = response;\n\n if (orgId) this.organizationId = orgId;\n if (projectId) this.projectId = projectId;\n if (userEmail) this.telemetryId = userEmail;\n } catch (error: any) {\n // Pass through structured exceptions and APIError\n if (error instanceof MemoryError || error instanceof APIError) {\n throw error;\n } else {\n throw new APIError(\n `Failed to ping server: ${error.message || \"Unknown error\"}`,\n );\n }\n }\n }\n\n async add(\n messages: Array<Message>,\n options: AddMemoryOptions & Record<string, any> = {},\n ): Promise<Array<Memory>> {\n if (this.telemetryId === \"\") await this.ping();\n\n const payload = this._preparePayload(messages, options);\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"add\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/add/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async update(\n memoryId: string,\n {\n text,\n metadata,\n timestamp,\n }: {\n text?: string;\n metadata?: Record<string, any>;\n timestamp?: number | string;\n },\n ): Promise<Array<Memory>> {\n if (\n text === undefined &&\n metadata === undefined &&\n timestamp === undefined\n ) {\n throw new Error(\n \"At least one of text, metadata, or timestamp must be provided for update.\",\n );\n }\n\n if (this.telemetryId === \"\") await this.ping();\n const payload: Record<string, any> = {};\n if (text !== undefined) payload.text = text;\n if (metadata !== undefined) payload.metadata = metadata;\n if (timestamp !== undefined) payload.timestamp = timestamp;\n\n const payloadKeys = Object.keys(payload);\n this._captureEvent(\"update\", [payloadKeys]);\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async get(memoryId: string): Promise<Memory> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get\", []);\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n headers: this.headers,\n },\n );\n }\n\n async getAll(options?: GetAllMemoryOptions): Promise<PaginatedMemories> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"getAll\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_all\", [payloadKeys]);\n const { page, pageSize, filters, ...rest } = options ?? {};\n const body: Record<string, any> = {\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n let url = `${this.host}/v3/memories/`;\n if (page && pageSize) {\n url += `?page=${page}&page_size=${pageSize}`;\n }\n\n const response = await this._fetchWithErrorHandling(url, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n });\n return response;\n }\n\n async search(\n query: string,\n options?: SearchMemoryOptions,\n ): Promise<{ results: Array<Memory> }> {\n // Reject top-level entity params - must use filters instead\n rejectTopLevelEntityParams(options as Record<string, any>, \"search\");\n\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"search\", [payloadKeys]);\n const { filters, ...rest } = options ?? {};\n const payload: Record<string, any> = {\n query,\n output_format: \"v1.1\",\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n };\n\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v3/memories/search/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async delete(\n memoryId: string,\n options: DeleteMemoryOptions = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete\", [Object.keys(options || {})]);\n const snakeOptions = camelToSnakeKeys(this._prepareParams(options));\n // @ts-ignore\n const query = new URLSearchParams(snakeOptions).toString();\n return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/${query ? `?${query}` : \"\"}`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n }\n\n async deleteAll(\n options: DeleteAllMemoryOptions = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"delete_all\", [payloadKeys]);\n const snakeOptions = camelToSnakeKeys(this._prepareParams(options));\n // @ts-ignore\n const params = new URLSearchParams(snakeOptions);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/?${params}`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async history(memoryId: string): Promise<Array<MemoryHistory>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"history\", []);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/history/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async users(options?: {\n page?: number;\n pageSize?: number;\n }): Promise<AllUsers> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"users\", []);\n let url = `${this.host}/v1/entities/`;\n const params: string[] = [];\n if (options?.page) params.push(`page=${options.page}`);\n if (options?.pageSize) params.push(`page_size=${options.pageSize}`);\n if (params.length) url += `?${params.join(\"&\")}`;\n const response = await this._fetchWithErrorHandling(url, {\n headers: this.headers,\n });\n return response;\n }\n\n /**\n * @deprecated The method should not be used, use `deleteUsers` instead. This will be removed in version 2.2.0.\n */\n async deleteUser(data: {\n entity_id: number;\n entity_type: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_user\", []);\n if (!data.entity_type) {\n data.entity_type = \"user\";\n }\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/${data.entity_type}/${data.entity_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUsers(\n params: {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n } = {},\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n\n let to_delete: Array<{ type: string; name: string }> = [];\n const { userId, agentId, appId, runId } = params;\n\n if (userId) {\n to_delete = [{ type: \"user\", name: userId }];\n } else if (agentId) {\n to_delete = [{ type: \"agent\", name: agentId }];\n } else if (appId) {\n to_delete = [{ type: \"app\", name: appId }];\n } else if (runId) {\n to_delete = [{ type: \"run\", name: runId }];\n } else {\n const entities = await this.users();\n to_delete = entities.results.map((entity) => ({\n type: entity.type,\n name: entity.name,\n }));\n }\n\n if (to_delete.length === 0) {\n throw new Error(\"No entities to delete\");\n }\n\n for (const entity of to_delete) {\n try {\n await this.client.delete(`/v2/entities/${entity.type}/${entity.name}/`);\n } catch (error: any) {\n throw new APIError(\n `Failed to delete ${entity.type} ${entity.name}: ${error.message}`,\n );\n }\n }\n\n this._captureEvent(\"delete_users\", [\n { userId, agentId, appId, runId, sync_type: \"sync\" },\n ]);\n\n return {\n message:\n userId || agentId || appId || runId\n ? \"Entity deleted successfully.\"\n : \"All users, agents, apps and runs deleted.\",\n };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_update\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory.memoryId,\n text: memory.text,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async batchDelete(memories: Array<string>): Promise<string> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"batch_delete\", []);\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory,\n }));\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/batch/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n body: JSON.stringify({ memories: memoriesBody }),\n },\n );\n return response;\n }\n\n async getProject(options: ProjectOptions): Promise<ProjectResponse> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(options || {});\n this._captureEvent(\"get_project\", [payloadKeys]);\n const { fields } = options;\n\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to access instructions or categories\",\n );\n }\n\n const params = new URLSearchParams();\n fields?.forEach((field) => params.append(\"fields\", camelToSnake(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(\n prompts: PromptUpdatePayload,\n ): Promise<Record<string, any>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_project\", []);\n if (!(this.organizationId && this.projectId)) {\n throw new Error(\n \"organizationId and projectId must be set to update instructions or categories\",\n );\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(camelToSnakeKeys(prompts)),\n },\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_webhooks\", []);\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${project_id}/`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async createWebhook(webhook: WebhookCreatePayload): Promise<Webhook> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_webhook\", []);\n const body = {\n name: webhook.name,\n url: webhook.url,\n event_types: webhook.eventTypes,\n };\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/projects/${this.projectId}/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async updateWebhook(\n webhook: WebhookUpdatePayload,\n ): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"update_webhook\", []);\n const body: Record<string, any> = {};\n if (webhook.name != null) body.name = webhook.name;\n if (webhook.url != null) body.url = webhook.url;\n if (webhook.eventTypes != null) body.event_types = webhook.eventTypes;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify(body),\n },\n );\n return response;\n }\n\n async deleteWebhook(data: {\n webhookId: string;\n }): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"delete_webhook\", []);\n const webhook_id = data.webhookId || data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook_id}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async feedback(data: FeedbackPayload): Promise<{ message: string }> {\n if (this.telemetryId === \"\") await this.ping();\n const payloadKeys = Object.keys(data || {});\n this._captureEvent(\"feedback\", [payloadKeys]);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/feedback/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(camelToSnakeKeys(data)),\n },\n );\n return response;\n }\n\n async createMemoryExport(\n data: CreateMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"create_memory_export\", []);\n\n if (!data.filters || !data.schema) {\n throw new Error(\"Missing filters or schema\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n filters,\n }),\n },\n );\n\n return response;\n }\n\n async getMemoryExport(\n data: GetMemoryExportPayload,\n ): Promise<{ message: string; id: string }> {\n if (this.telemetryId === \"\") await this.ping();\n this._captureEvent(\"get_memory_export\", []);\n\n if (!data.memoryExportId && !data.filters) {\n throw new Error(\"Missing memoryExportId or filters\");\n }\n\n const { filters, ...rest } = data;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/exports/get/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify({\n ...camelToSnakeKeys(rest),\n ...(filters && { filters }),\n }),\n },\n );\n return response;\n }\n}\n\nexport { MemoryClient };\n","// @ts-nocheck\nimport type { TelemetryClient, TelemetryOptions } from \"./telemetry.types\";\n\n// __MEM0_SDK_VERSION__ is inlined by tsup/esbuild's `define` at build time from\n// package.json. In unbundled environments (ts-jest, jest globalSetup) the\n// identifier is not defined, so guard with typeof to fall back safely.\nlet version =\n typeof __MEM0_SDK_VERSION__ !== \"undefined\" ? __MEM0_SDK_VERSION__ : \"dev\";\n\n// Safely check for process.env in different environments\nlet MEM0_TELEMETRY = true;\ntry {\n MEM0_TELEMETRY = process?.env?.MEM0_TELEMETRY === \"false\" ? false : true;\n} catch (error) {}\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com/i/v0/e/\";\n\n// Simple hash function using random strings\nfunction generateHash(input: string): string {\n const randomStr =\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15);\n return randomStr;\n}\n\nclass UnifiedTelemetry implements TelemetryClient {\n private apiKey: string;\n private host: string;\n\n constructor(projectApiKey: string, host: string) {\n this.apiKey = projectApiKey;\n this.host = host;\n }\n\n async captureEvent(\n distinctId: string,\n eventName: string,\n properties = {},\n ): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n\n const eventProperties = {\n client_version: version,\n timestamp: new Date().toISOString(),\n ...properties,\n $process_person_profile: false,\n $lib: \"posthog-node\",\n };\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: distinctId,\n event: eventName,\n properties: eventProperties,\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\"Telemetry event capture failed:\", await response.text());\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry event capture failed:\", error);\n return false;\n }\n }\n\n async captureIdentify(anonId: string, email: string): Promise<boolean> {\n if (!MEM0_TELEMETRY) return false;\n if (!anonId || !email || anonId === email) return false;\n\n const payload = {\n api_key: this.apiKey,\n distinct_id: email,\n event: \"$identify\",\n properties: {\n $anon_distinct_id: anonId,\n client_source: \"typescript\",\n $lib: \"posthog-node\",\n },\n };\n\n try {\n const response = await fetch(this.host, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/json\",\n },\n body: JSON.stringify(payload),\n });\n\n if (!response.ok) {\n console.error(\n \"Telemetry identify capture failed:\",\n await response.text(),\n );\n return false;\n }\n return true;\n } catch (error) {\n console.error(\"Telemetry identify capture failed:\", error);\n return false;\n }\n }\n\n async shutdown() {\n // No shutdown needed for direct API calls\n }\n}\n\nfunction isTelemetryEnabled(): boolean {\n return MEM0_TELEMETRY;\n}\n\nconst telemetry = new UnifiedTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);\n\nasync function captureClientEvent(\n eventName: string,\n instance: any,\n additionalData = {},\n) {\n if (!instance.telemetryId) {\n console.warn(\"No telemetry ID found for instance\");\n return;\n }\n\n const eventData = {\n function: `${instance.constructor.name}`,\n method: eventName,\n api_host: instance.host,\n timestamp: new Date().toISOString(),\n client_version: version,\n keys: additionalData?.keys || [],\n ...additionalData,\n };\n\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData,\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash, isTelemetryEnabled };\n","/**\n * Best-effort read/write of ~/.mem0/config.json from the TS SDK.\n *\n * Used to stitch PostHog identities: SDKs and CLIs persist anonymous\n * distinct_id values here, and the TS MemoryClient reads those on init to\n * fire $identify and merge them into the email identity.\n *\n * Node-only. Browsers (no `process.versions.node`) no-op.\n */\n\nexport interface Mem0AnonIds {\n oss?: string;\n cli?: string;\n aliasedPairs: string[];\n}\n\ninterface NodeFs {\n fs: typeof import(\"fs\");\n path: typeof import(\"path\");\n crypto: typeof import(\"crypto\");\n configPath: string;\n}\n\nasync function getNodeFs(): Promise<NodeFs | null> {\n if (typeof process === \"undefined\" || !process.versions?.node) return null;\n try {\n const [fs, path, os, crypto] = await Promise.all([\n import(\"fs\"),\n import(\"path\"),\n import(\"os\"),\n import(\"crypto\"),\n ]);\n const fsMod = (fs as any).default ?? fs;\n const pathMod = (path as any).default ?? path;\n const osMod = (os as any).default ?? os;\n const cryptoMod = (crypto as any).default ?? crypto;\n const dir = process.env.MEM0_DIR || pathMod.join(osMod.homedir(), \".mem0\");\n return {\n fs: fsMod,\n path: pathMod,\n crypto: cryptoMod,\n configPath: pathMod.join(dir, \"config.json\"),\n };\n } catch {\n return null;\n }\n}\n\nfunction loadConfig(node: NodeFs): Record<string, any> | null {\n try {\n if (!node.fs.existsSync(node.configPath)) return null;\n const parsed = JSON.parse(node.fs.readFileSync(node.configPath, \"utf8\"));\n return parsed && typeof parsed === \"object\" ? parsed : null;\n } catch {\n return null;\n }\n}\n\nfunction writeConfig(node: NodeFs, config: Record<string, any>): void {\n node.fs.mkdirSync(node.path.dirname(node.configPath), { recursive: true });\n node.fs.writeFileSync(node.configPath, JSON.stringify(config, null, 4));\n}\n\nfunction aliasPairMarker(node: NodeFs, anonId: string, email: string): string {\n return node.crypto\n .createHash(\"sha256\")\n .update(`${anonId}\\0${email}`, \"utf8\")\n .digest(\"hex\");\n}\n\nfunction randomUserId(node: NodeFs): string {\n if (typeof node.crypto.randomUUID === \"function\") {\n return node.crypto.randomUUID();\n }\n return (\n Math.random().toString(36).substring(2, 15) +\n Math.random().toString(36).substring(2, 15)\n );\n}\n\nexport async function getOrCreateMem0UserId(): Promise<string | null> {\n const node = await getNodeFs();\n if (!node) return null;\n try {\n const config = loadConfig(node) ?? {};\n if (typeof config.user_id === \"string\" && config.user_id) {\n return config.user_id;\n }\n const userId = randomUserId(node);\n config.user_id = userId;\n writeConfig(node, config);\n return userId;\n } catch {\n return null;\n }\n}\n\nexport async function readMem0AnonIds(): Promise<Mem0AnonIds | null> {\n const node = await getNodeFs();\n if (!node) return null;\n const config = loadConfig(node);\n if (!config) return null;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n return {\n oss: typeof config.user_id === \"string\" ? config.user_id : undefined,\n cli:\n typeof telemetry.anonymous_id === \"string\"\n ? telemetry.anonymous_id\n : undefined,\n aliasedPairs: Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs.filter(\n (item: unknown) => typeof item === \"string\",\n )\n : [],\n };\n}\n\nexport async function isMem0Aliased(\n anonId: string,\n email: string,\n): Promise<boolean> {\n if (!anonId || !email) return false;\n const node = await getNodeFs();\n if (!node) return false;\n const config = loadConfig(node);\n if (!config) return false;\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n return aliasedPairs.includes(aliasPairMarker(node, anonId, email));\n}\n\nexport async function markMem0Aliased(\n anonId: string,\n email: string,\n): Promise<void> {\n const node = await getNodeFs();\n if (!node) return;\n try {\n const config = loadConfig(node) ?? {};\n const telemetry =\n config.telemetry && typeof config.telemetry === \"object\"\n ? config.telemetry\n : {};\n const aliasedPairs = Array.isArray(telemetry.aliased_pairs)\n ? telemetry.aliased_pairs\n : [];\n const marker = aliasPairMarker(node, anonId, email);\n if (!aliasedPairs.includes(marker)) {\n aliasedPairs.push(marker);\n }\n telemetry.aliased_pairs = aliasedPairs;\n config.telemetry = telemetry;\n writeConfig(node, config);\n } catch {\n // Best-effort: read-only filesystems and unwritable paths just skip.\n }\n}\n","/**\n * Converts a camelCase string to snake_case.\n */\nexport function camelToSnake(str: string): string {\n // Skip all-uppercase keys (e.g. OR, AND, NOT — logical operators)\n if (str === str.toUpperCase()) return str;\n return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);\n}\n\n/**\n * Converts a snake_case string to camelCase.\n */\nfunction snakeToCamel(str: string): string {\n return str.replace(/_([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Recursively converts all keys of an object from camelCase to snake_case.\n * Used for converting user-facing camelCase params to API snake_case payloads.\n */\nexport function camelToSnakeKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(camelToSnakeKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n camelToSnake(key),\n camelToSnakeKeys(value),\n ]),\n );\n}\n\n/**\n * Recursively converts all keys of an object from snake_case to camelCase.\n * Used for converting API snake_case responses to user-facing camelCase.\n */\nexport function snakeToCamelKeys(obj: any): any {\n if (obj === null || obj === undefined || typeof obj !== \"object\") return obj;\n if (Array.isArray(obj)) return obj.map(snakeToCamelKeys);\n if (obj instanceof Date) return obj;\n\n return Object.fromEntries(\n Object.entries(obj).map(([key, value]) => [\n snakeToCamel(key),\n snakeToCamelKeys(value),\n ]),\n );\n}\n","/**\n * Structured exception classes for mem0 TypeScript SDK.\n *\n * Provides specific, actionable exceptions with error codes, suggestions,\n * and debug information. Maps HTTP status codes to appropriate exception types.\n *\n * @example\n * ```typescript\n * import { RateLimitError, MemoryNotFoundError } from 'mem0ai'\n *\n * try {\n * await client.get(memoryId)\n * } catch (e) {\n * if (e instanceof MemoryNotFoundError) {\n * console.log(e.suggestion) // \"The requested resource was not found\"\n * } else if (e instanceof RateLimitError) {\n * await sleep(e.debugInfo.retryAfter ?? 60)\n * }\n * }\n * ```\n */\n\nexport interface MemoryErrorOptions {\n details?: Record<string, unknown>;\n suggestion?: string;\n debugInfo?: Record<string, unknown>;\n}\n\n/**\n * Base exception for all memory-related errors.\n *\n * Every mem0 exception includes an error code for programmatic handling,\n * optional details, a user-friendly suggestion, and debug information.\n */\nexport class MemoryError extends Error {\n readonly errorCode: string;\n readonly details: Record<string, unknown>;\n readonly suggestion?: string;\n readonly debugInfo: Record<string, unknown>;\n\n constructor(\n message: string,\n errorCode: string,\n options: MemoryErrorOptions = {},\n ) {\n super(message);\n this.name = \"MemoryError\";\n this.errorCode = errorCode;\n this.details = options.details ?? {};\n this.suggestion = options.suggestion;\n this.debugInfo = options.debugInfo ?? {};\n\n // Fix prototype chain for instanceof checks\n Object.setPrototypeOf(this, new.target.prototype);\n }\n}\n\n/** Raised when authentication fails (401, 403). */\nexport class AuthenticationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"AuthenticationError\";\n }\n}\n\n/** Raised when rate limits are exceeded (429). */\nexport class RateLimitError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"RateLimitError\";\n }\n}\n\n/** Raised when input validation fails (400, 409, 422). */\nexport class ValidationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ValidationError\";\n }\n}\n\n/** Raised when a memory is not found (404). */\nexport class MemoryNotFoundError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryNotFoundError\";\n }\n}\n\n/** Raised when network connectivity issues occur (408, 502, 503, 504). */\nexport class NetworkError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"NetworkError\";\n }\n}\n\n/** Raised when client configuration is invalid. */\nexport class ConfigurationError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"ConfigurationError\";\n }\n}\n\n/** Raised when memory quota is exceeded (413). */\nexport class MemoryQuotaExceededError extends MemoryError {\n constructor(\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n ) {\n super(message, errorCode, options);\n this.name = \"MemoryQuotaExceededError\";\n }\n}\n\n// ─── HTTP Status → Exception Mapping ─────────────────────\n\ntype MemoryErrorConstructor = new (\n message: string,\n errorCode: string,\n options?: MemoryErrorOptions,\n) => MemoryError;\n\nexport const HTTP_STATUS_TO_EXCEPTION: Record<number, MemoryErrorConstructor> =\n {\n 400: ValidationError,\n 401: AuthenticationError,\n 403: AuthenticationError,\n 404: MemoryNotFoundError,\n 408: NetworkError,\n 409: ValidationError,\n 413: MemoryQuotaExceededError,\n 422: ValidationError,\n 429: RateLimitError,\n 500: MemoryError,\n 502: NetworkError,\n 503: NetworkError,\n 504: NetworkError,\n };\n\nconst HTTP_SUGGESTIONS: Record<number, string> = {\n 400: \"Please check your request parameters and try again\",\n 401: \"Please check your API key and authentication credentials\",\n 403: \"You don't have permission to perform this operation\",\n 404: \"The requested resource was not found\",\n 408: \"Request timed out. Please try again\",\n 409: \"Resource conflict. Please check your request\",\n 413: \"Request too large. Please reduce the size of your request\",\n 422: \"Invalid request data. Please check your input\",\n 429: \"Rate limit exceeded. Please wait before making more requests\",\n 500: \"Internal server error. Please try again later\",\n 502: \"Service temporarily unavailable. Please try again later\",\n 503: \"Service unavailable. Please try again later\",\n 504: \"Gateway timeout. Please try again later\",\n};\n\n/**\n * Create an appropriate exception based on HTTP response status code.\n *\n * @param statusCode - HTTP status code from the response\n * @param responseText - Response body text\n * @param options - Additional error context (details, debugInfo)\n * @returns An instance of the appropriate MemoryError subclass\n */\nexport function createExceptionFromResponse(\n statusCode: number,\n responseText: string,\n options: Omit<MemoryErrorOptions, \"suggestion\"> = {},\n): MemoryError {\n const ExceptionClass = HTTP_STATUS_TO_EXCEPTION[statusCode] ?? MemoryError;\n const errorCode = `HTTP_${statusCode}`;\n const suggestion = HTTP_SUGGESTIONS[statusCode] ?? \"Please try again later\";\n\n return new ExceptionClass(\n responseText || `HTTP ${statusCode} error`,\n errorCode,\n { ...options, suggestion },\n );\n}\n","// ─── Entity Options (for add/delete — top-level identity) ───\nexport interface EntityOptions {\n userId?: string;\n agentId?: string;\n appId?: string;\n runId?: string;\n}\n\n// ─── Per-Method Options ─────────────────────────────────────\nexport interface AddMemoryOptions extends EntityOptions {\n metadata?: Record<string, any>;\n infer?: boolean;\n customCategories?: custom_categories[];\n customInstructions?: string;\n timestamp?: number;\n structuredDataSchema?: Record<string, any>;\n}\n\nexport interface SearchMemoryOptions {\n filters?: Record<string, any>;\n metadata?: Record<string, any>;\n topK?: number;\n threshold?: number;\n rerank?: boolean;\n latestOnly?: boolean;\n fields?: string[];\n categories?: string[];\n}\n\nexport interface GetAllMemoryOptions {\n filters?: Record<string, any>;\n page?: number;\n pageSize?: number;\n startDate?: string;\n endDate?: string;\n latestOnly?: boolean;\n categories?: string[];\n}\n\nexport interface DeleteAllMemoryOptions extends EntityOptions {}\n\nexport interface DeleteMemoryOptions {\n /**\n * When `true`, also delete the older memories this one superseded (the v3\n * linked chain), transitively — the delete-side counterpart of `latestOnly`.\n * Off by default. Serialized as `delete_linked`.\n */\n deleteLinked?: boolean;\n}\n\n// ─── Project Options ────────────────────────────────────────\nexport interface ProjectOptions {\n fields?: string[];\n}\n\nexport interface PromptUpdatePayload {\n customInstructions?: string;\n customCategories?: custom_categories[];\n retrievalCriteria?: any[];\n version?: string;\n memoryDepth?: string | null;\n usecaseSetting?: string | number;\n multilingual?: boolean;\n /**\n * Toggle Memory Decay for this project. When `true`, search-time ranking\n * boosts recently-used memories and gently dampens stale ones; when `false`,\n * ranking is restored to the pre-decay behaviour. Off by default.\n * See https://docs.mem0.ai/platform/features/memory-decay\n */\n decay?: boolean;\n [key: string]: any;\n}\n\n// ─── Enums ──────────────────────────────────────────────────\nexport enum Feedback {\n POSITIVE = \"POSITIVE\",\n NEGATIVE = \"NEGATIVE\",\n VERY_NEGATIVE = \"VERY_NEGATIVE\",\n}\n\n// ─── Message Types ──────────────────────────────────────────\nexport interface MultiModalMessages {\n type: \"image_url\";\n image_url: {\n url: string;\n };\n}\n\nexport interface Messages {\n role: \"user\" | \"assistant\";\n content: string | MultiModalMessages;\n}\n\nexport interface Message extends Messages {}\n\n// ─── Response Types (camelCase — converted from API snake_case) ─────\nexport interface MemoryData {\n memory: string;\n}\n\nenum Event {\n ADD = \"ADD\",\n UPDATE = \"UPDATE\",\n DELETE = \"DELETE\",\n NOOP = \"NOOP\",\n}\n\nexport interface Memory {\n id: string;\n messages?: Array<Messages>;\n event?: Event | string;\n data?: MemoryData | null;\n memory?: string;\n userId?: string;\n hash?: string;\n categories?: Array<string>;\n createdAt?: Date;\n updatedAt?: Date;\n memoryType?: string;\n score?: number;\n metadata?: any | null;\n owner?: string | null;\n agentId?: string | null;\n appId?: string | null;\n runId?: string | null;\n}\n\nexport interface MemoryHistory {\n id: string;\n memoryId: string;\n input: Array<Messages>;\n oldMemory: string | null;\n newMemory: string | null;\n userId: string;\n categories: Array<string>;\n event: Event | string;\n createdAt: Date;\n updatedAt: Date;\n}\n\nexport interface MemoryUpdateBody {\n memoryId: string;\n text: string;\n}\n\nexport interface User {\n id: string;\n name: string;\n createdAt: Date;\n updatedAt: Date;\n totalMemories: 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 PaginatedMemories {\n count: number;\n next: string | null;\n previous: string | null;\n results: Array<Memory>;\n}\n\nexport interface ProjectResponse {\n customInstructions?: string;\n customCategories?: string[];\n [key: string]: any;\n}\n\ninterface custom_categories {\n [key: string]: any;\n}\n\n// ─── Webhook Types ──────────────────────────────────────────\nexport enum WebhookEvent {\n MEMORY_ADDED = \"memory_add\",\n MEMORY_UPDATED = \"memory_update\",\n MEMORY_DELETED = \"memory_delete\",\n MEMORY_CATEGORIZED = \"memory_categorize\",\n}\n\nexport interface Webhook {\n webhookId?: string;\n name: string;\n url: string;\n project?: string;\n createdAt?: Date;\n updatedAt?: Date;\n isActive?: boolean;\n eventTypes?: WebhookEvent[];\n}\n\nexport interface WebhookCreatePayload {\n name: string;\n url: string;\n eventTypes: WebhookEvent[];\n}\n\nexport interface WebhookUpdatePayload {\n webhookId: string;\n name?: string;\n url?: string;\n eventTypes?: WebhookEvent[];\n}\n\n// ─── Feedback & Export Types ────────────────────────────────\nexport interface FeedbackPayload {\n memoryId: string;\n feedback?: Feedback | null;\n feedbackReason?: string | null;\n}\n\nexport interface CreateMemoryExportPayload {\n schema: Record<string, any>;\n filters: Record<string, any>;\n exportInstructions?: string;\n}\n\nexport interface GetMemoryExportPayload {\n filters?: Record<string, any>;\n memoryExportId?: string;\n}\n","import { MemoryClient } from \"./mem0\";\nimport type * as MemoryTypes from \"./mem0.types\";\n\n// Re-export all types from mem0.types\nexport type {\n AddMemoryOptions,\n SearchMemoryOptions,\n GetAllMemoryOptions,\n DeleteAllMemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n Webhook,\n WebhookCreatePayload,\n WebhookUpdatePayload,\n Messages,\n Message,\n AllUsers,\n User,\n FeedbackPayload,\n CreateMemoryExportPayload,\n GetMemoryExportPayload,\n} from \"./mem0.types\";\n\n// Re-export enums as values (not type-only)\nexport { Feedback, WebhookEvent } from \"./mem0.types\";\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;\n\n// Export structured exceptions\nexport {\n MemoryError,\n AuthenticationError,\n RateLimitError,\n ValidationError,\n MemoryNotFoundError,\n NetworkError,\n ConfigurationError,\n MemoryQuotaExceededError,\n createExceptionFromResponse,\n} from \"../common/exceptions\";\n\nexport type { MemoryErrorOptions } from \"../common/exceptions\";\n"],"mappings":";AAAA,OAAO,WAAW;;;ACMlB,IAAI,UACF,OAA8C,UAAuB;AAG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E,SAAS,GAAG,KAAK,IAAI;AAC7B,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI;AAAA,MACZ;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,QACd,MAAM,KAAK,UAAU;AAAA,UACnB,GAAG,iBAAiB,IAAI;AAAA,UACxB,GAAI,WAAW,EAAE,QAAQ;AAAA,QAC3B,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AKxpBO,IAAK,WAAL,kBAAKC,cAAL;AACL,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,cAAW;AACX,EAAAA,UAAA,mBAAgB;AAHN,SAAAA;AAAA,GAAA;AA0GL,IAAK,eAAL,kBAAKC,kBAAL;AACL,EAAAA,cAAA,kBAAe;AACf,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,oBAAiB;AACjB,EAAAA,cAAA,wBAAqB;AAJX,SAAAA;AAAA,GAAA;;;ACpJZ,IAAO,gBAAQ;","names":["_a","telemetry","_a","Feedback","WebhookEvent"]}
package/dist/oss/index.js CHANGED
@@ -5123,7 +5123,7 @@ var parse_vision_messages = async (messages) => {
5123
5123
  };
5124
5124
 
5125
5125
  // src/oss/src/utils/telemetry.ts
5126
- var version = true ? "3.0.4" : "dev";
5126
+ var version = true ? "3.0.5" : "dev";
5127
5127
  var MEM0_TELEMETRY = true;
5128
5128
  var _a;
5129
5129
  try {
@@ -5073,7 +5073,7 @@ var parse_vision_messages = async (messages) => {
5073
5073
  };
5074
5074
 
5075
5075
  // src/oss/src/utils/telemetry.ts
5076
- var version = true ? "3.0.4" : "dev";
5076
+ var version = true ? "3.0.5" : "dev";
5077
5077
  var MEM0_TELEMETRY = true;
5078
5078
  var _a;
5079
5079
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mem0ai",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "The Memory Layer For Your AI Apps",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",