mem0ai 2.1.0 → 2.1.2
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 +9 -9
- package/dist/index.d.ts +9 -9
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/oss/index.d.mts +8 -2
- package/dist/oss/index.d.ts +8 -2
- package/dist/oss/index.js +61 -17
- package/dist/oss/index.js.map +1 -1
- package/dist/oss/index.mjs +61 -17
- package/dist/oss/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -3,7 +3,7 @@ import axios from "axios";
|
|
|
3
3
|
|
|
4
4
|
// src/client/telemetry.browser.ts
|
|
5
5
|
var version = "1.0.20";
|
|
6
|
-
var MEM0_TELEMETRY =
|
|
6
|
+
var MEM0_TELEMETRY = true;
|
|
7
7
|
var POSTHOG_API_KEY = "phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX";
|
|
8
8
|
var POSTHOG_HOST = "https://us.i.posthog.com";
|
|
9
9
|
async function generateHash(input) {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/client/mem0.ts","../src/client/telemetry.browser.ts","../src/client/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n AllUsers,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryOptions,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n SearchOptions,\n Webhook,\n WebhookPayload,\n} from \"./mem0.types\";\nimport { captureClientEvent, generateHash } from \"./telemetry\";\n\nclass APIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"APIError\";\n }\n}\n\ninterface ClientOptions {\n apiKey: string;\n host?: string;\n organizationName?: string;\n projectName?: string;\n organizationId?: string;\n projectId?: string;\n}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n organizationName: string | null;\n projectName: string | null;\n organizationId: string | number | null;\n projectId: string | number | null;\n headers: Record<string, string>;\n client: any;\n telemetryId: string;\n\n _validateApiKey(): any {\n if (!this.apiKey) {\n throw new Error(\"Mem0 API key is required\");\n }\n if (typeof this.apiKey !== \"string\") {\n throw new Error(\"Mem0 API key must be a string\");\n }\n if (this.apiKey.trim() === \"\") {\n throw new Error(\"Mem0 API key cannot be empty\");\n }\n }\n\n _validateOrgProject(): void {\n // Check for organizationName/projectName pair\n if (\n (this.organizationName === null && this.projectName !== null) ||\n (this.organizationName !== null && this.projectName === null)\n ) {\n console.warn(\n \"Warning: Both organizationName and projectName must be provided together when using either. This will be removedfrom the version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId.\",\n );\n }\n\n // Check for organizationId/projectId pair\n if (\n (this.organizationId === null && this.projectId !== null) ||\n (this.organizationId !== null && this.projectId === null)\n ) {\n console.warn(\n \"Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.\",\n );\n }\n }\n\n constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationName = options.organizationName || null;\n this.projectName = options.projectName || null;\n this.organizationId = options.organizationId || null;\n this.projectId = options.projectId || null;\n\n this.headers = {\n Authorization: `Token ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n };\n\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n this._validateOrgProject();\n\n // Initialize with a temporary ID that will be updated\n this.telemetryId = \"\";\n\n // Initialize the client\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n // do this only in browser\n if (typeof window !== \"undefined\") {\n this.telemetryId = await generateHash(this.apiKey);\n await captureClientEvent(\"init\", this);\n }\n\n // Wrap methods after initialization\n this.add = this.wrapMethod(\"add\", this.add);\n this.get = this.wrapMethod(\"get\", this.get);\n this.getAll = this.wrapMethod(\"get_all\", this.getAll);\n this.search = this.wrapMethod(\"search\", this.search);\n this.delete = this.wrapMethod(\"delete\", this.delete);\n this.deleteAll = this.wrapMethod(\"delete_all\", this.deleteAll);\n this.history = this.wrapMethod(\"history\", this.history);\n this.users = this.wrapMethod(\"users\", this.users);\n this.deleteUser = this.wrapMethod(\"delete_user\", this.deleteUser);\n this.deleteUsers = this.wrapMethod(\"delete_users\", this.deleteUsers);\n this.batchUpdate = this.wrapMethod(\"batch_update\", this.batchUpdate);\n this.batchDelete = this.wrapMethod(\"batch_delete\", this.batchDelete);\n this.getProject = this.wrapMethod(\"get_project\", this.getProject);\n this.updateProject = this.wrapMethod(\n \"update_project\",\n this.updateProject,\n );\n this.getWebhooks = this.wrapMethod(\"get_webhook\", this.getWebhooks);\n this.createWebhook = this.wrapMethod(\n \"create_webhook\",\n this.createWebhook,\n );\n this.updateWebhook = this.wrapMethod(\n \"update_webhook\",\n this.updateWebhook,\n );\n this.deleteWebhook = this.wrapMethod(\n \"delete_webhook\",\n this.deleteWebhook,\n );\n } catch (error) {\n console.error(\"Failed to initialize client:\", error);\n }\n }\n\n wrapMethod(methodName: any, method: any) {\n return async function (...args: any) {\n // @ts-ignore\n await captureClientEvent(methodName, this);\n // @ts-ignore\n return method.apply(this, args);\n }.bind(this);\n }\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, options);\n if (!response.ok) {\n const errorData = await response.text();\n throw new APIError(`API request failed: ${errorData}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse;\n }\n\n _preparePayload(\n messages: string | Array<{ role: string; content: string }>,\n options: MemoryOptions,\n ): object {\n const payload: any = {};\n if (typeof messages === \"string\") {\n payload.messages = [{ role: \"user\", content: messages }];\n } else if (Array.isArray(messages)) {\n payload.messages = messages;\n }\n return { ...payload, ...options };\n }\n\n _prepareParams(options: MemoryOptions): object {\n return Object.fromEntries(\n Object.entries(options).filter(([_, v]) => v != null),\n );\n }\n\n async add(\n messages: string | Array<{ role: string; content: string }>,\n options: MemoryOptions = {},\n ): Promise<Array<Memory>> {\n this._validateOrgProject();\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n\n const payload = this._preparePayload(messages, options);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async update(memoryId: string, message: string): Promise<Array<Memory>> {\n this._validateOrgProject();\n const payload = {\n text: message,\n };\n const response = await this._fetchWithErrorHandling(\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 return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n headers: this.headers,\n },\n );\n }\n\n async getAll(options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, page, page_size, ...otherOptions } = options!;\n if (this.organizationName != null && this.projectName != null) {\n otherOptions.org_name = this.organizationName;\n otherOptions.project_name = this.projectName;\n }\n\n let appendedParams = \"\";\n let paginated_response = false;\n\n if (page && page_size) {\n appendedParams += `page=${page}&page_size=${page_size}`;\n paginated_response = true;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n otherOptions.org_id = this.organizationId;\n otherOptions.project_id = this.projectId;\n\n if (otherOptions.org_name) delete otherOptions.org_name;\n if (otherOptions.project_name) delete otherOptions.project_name;\n }\n\n if (api_version === \"v2\") {\n let url = paginated_response\n ? `${this.host}/v2/memories/?${appendedParams}`\n : `${this.host}/v2/memories/`;\n return this._fetchWithErrorHandling(url, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(otherOptions),\n });\n } else {\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(otherOptions));\n const url = paginated_response\n ? `${this.host}/v1/memories/?${params}&${appendedParams}`\n : `${this.host}/v1/memories/?${params}`;\n return this._fetchWithErrorHandling(url, {\n headers: this.headers,\n });\n }\n }\n\n async search(query: string, options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, ...otherOptions } = options!;\n const payload = { query, ...otherOptions };\n if (this.organizationName != null && this.projectName != null) {\n payload.org_name = this.organizationName;\n payload.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n payload.org_id = this.organizationId;\n payload.project_id = this.projectId;\n\n if (payload.org_name) delete payload.org_name;\n if (payload.project_name) delete payload.project_name;\n }\n const endpoint =\n api_version === \"v2\" ? \"/v2/memories/search/\" : \"/v1/memories/search/\";\n const response = await this._fetchWithErrorHandling(\n `${this.host}${endpoint}`,\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 return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n }\n\n async deleteAll(options: MemoryOptions = {}): Promise<{ message: string }> {\n this._validateOrgProject();\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(options));\n const response = await this._fetchWithErrorHandling(\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 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(): Promise<AllUsers> {\n this._validateOrgProject();\n const options: MemoryOptions = {};\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(options);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/?${params}`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUser(\n entityId: string,\n entity: { type: string } = { type: \"user\" },\n ): Promise<{ message: string }> {\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/${entity.type}/${entityId}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUsers(): Promise<{ message: string }> {\n this._validateOrgProject();\n const entities = await this.users();\n\n for (const entity of entities.results) {\n let options: MemoryOptions = {};\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n await this.client.delete(`/v1/entities/${entity.type}/${entity.id}/`, {\n params: options,\n });\n }\n return { message: \"All users, agents, and sessions deleted.\" };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory.memoryId,\n text: memory.text,\n }));\n const response = await this._fetchWithErrorHandling(\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 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 this._validateOrgProject();\n\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\", 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 this._validateOrgProject();\n\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(prompts),\n },\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\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: WebhookPayload): Promise<Webhook> {\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(webhook),\n },\n );\n return response;\n }\n\n async updateWebhook(webhook: WebhookPayload): Promise<{ message: string }> {\n const project_id = webhook.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify({\n ...webhook,\n projectId: project_id,\n }),\n },\n );\n return response;\n }\n\n async deleteWebhook(data: {\n webhookId: string;\n }): Promise<{ message: string }> {\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\nexport { MemoryClient };\n","// @ts-nocheck\nimport type { PostHog } from \"posthog-js\";\nimport type { TelemetryClient } from \"./telemetry.types\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = process.env.MEM0_TELEMETRY !== \"false\";\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com\";\n\n// Browser-specific hash function using Web Crypto API\nasync function generateHash(input: string): Promise<string> {\n const msgBuffer = new TextEncoder().encode(input);\n const hashBuffer = await window.crypto.subtle.digest(\"SHA-256\", msgBuffer);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nclass BrowserTelemetry implements TelemetryClient {\n client: PostHog | null = null;\n\n constructor(projectApiKey: string, host: string) {\n if (MEM0_TELEMETRY) {\n this.initializeClient(projectApiKey, host);\n }\n }\n\n private async initializeClient(projectApiKey: string, host: string) {\n try {\n const posthog = await import(\"posthog-js\").catch(() => null);\n if (posthog) {\n posthog.init(projectApiKey, { api_host: host });\n this.client = posthog;\n }\n } catch (error) {\n // Silently fail if posthog-js is not available\n this.client = null;\n }\n }\n\n async captureEvent(distinctId: string, eventName: string, properties = {}) {\n if (!this.client || !MEM0_TELEMETRY) return;\n\n const eventProperties = {\n client_source: \"browser\",\n client_version: getVersion(),\n browser: window.navigator.userAgent,\n ...properties,\n };\n\n try {\n this.client.capture(eventName, eventProperties);\n } catch (error) {\n // Silently fail if telemetry fails\n }\n }\n\n async shutdown() {\n // No shutdown needed for browser client\n }\n}\n\nfunction getVersion() {\n return version;\n}\n\nconst telemetry = new BrowserTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);\n\nasync function captureClientEvent(\n eventName: string,\n instance: any,\n additionalData = {},\n) {\n const eventData = {\n function: `${instance.constructor.name}`,\n ...additionalData,\n };\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData,\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash };\n","import { MemoryClient } from \"./mem0\";\nimport type { TelemetryClient, TelemetryInstance } from \"./telemetry.types\";\nimport {\n telemetry,\n captureClientEvent,\n generateHash,\n} from \"./telemetry.browser\";\nimport type * as MemoryTypes from \"./mem0.types\";\n\n// Re-export all types from mem0.types\nexport type {\n MemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n SearchOptions,\n Webhook,\n WebhookPayload,\n Messages,\n Message,\n AllUsers,\n User,\n} from \"./mem0.types\";\n\n// Export telemetry types\nexport type { TelemetryClient, TelemetryInstance };\n\n// Export telemetry implementation\nexport { telemetry, captureClientEvent, generateHash };\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;\n"],"mappings":";AAAA,OAAO,WAAW;;;ACIlB,IAAI,UAAU;AAEd,IAAM,iBAAiB,QAAQ,IAAI,mBAAmB;AACtD,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,eAAe,aAAa,OAAgC;AAC1D,QAAM,YAAY,IAAI,YAAY,EAAE,OAAO,KAAK;AAChD,QAAM,aAAa,MAAM,OAAO,OAAO,OAAO,OAAO,WAAW,SAAS;AACzE,QAAM,YAAY,MAAM,KAAK,IAAI,WAAW,UAAU,CAAC;AACvD,SAAO,UAAU,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACtE;AAEA,IAAM,mBAAN,MAAkD;AAAA,EAGhD,YAAY,eAAuB,MAAc;AAFjD,kBAAyB;AAGvB,QAAI,gB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9B;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,MAAM,YAAY,MAAwD;AACxE,UAAM,cAAa,6BAAM,cAAa,KAAK;AAC3C,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI,6BAA6B,UAAU;AAAA,MACnD;AAAA,QACE,SAAS,KAAK;AAAA,MAChB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,SAA2C;AAC7D,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI,6BAA6B,KAAK,SAAS;AAAA,MACvD;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,QACd,MAAM,KAAK,UAAU,OAAO;AAAA,MAC9B;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,SAAuD;AACzE,UAAM,aAAa,QAAQ,aAAa,KAAK;AAC7C,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI,oBAAoB,QAAQ,SAAS;AAAA,MACjD;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,QACd,MAAM,KAAK,UAAU;AAAA,UACnB,GAAG;AAAA,UACH,WAAW;AAAA,QACb,CAAC;AAAA,MACH;AAAA,IACF;AACA,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,cAAc,MAEa;AAC/B,UAAM,aAAa,KAAK,aAAa;AACrC,UAAM,WAAW,MAAM,KAAK;AAAA,MAC1B,GAAG,KAAK,IAAI,oBAAoB,UAAU;AAAA,MAC1C;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,MAChB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AE1gBA,IAAO,gBAAQ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/client/mem0.ts","../src/client/telemetry.browser.ts","../src/client/index.ts"],"sourcesContent":["import axios from \"axios\";\nimport {\n AllUsers,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryOptions,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n SearchOptions,\n Webhook,\n WebhookPayload,\n Message,\n} from \"./mem0.types\";\nimport { captureClientEvent, generateHash } from \"./telemetry\";\n\nclass APIError extends Error {\n constructor(message: string) {\n super(message);\n this.name = \"APIError\";\n }\n}\n\ninterface ClientOptions {\n apiKey: string;\n host?: string;\n organizationName?: string;\n projectName?: string;\n organizationId?: string;\n projectId?: string;\n}\n\nexport default class MemoryClient {\n apiKey: string;\n host: string;\n organizationName: string | null;\n projectName: string | null;\n organizationId: string | number | null;\n projectId: string | number | null;\n headers: Record<string, string>;\n client: any;\n telemetryId: string;\n\n _validateApiKey(): any {\n if (!this.apiKey) {\n throw new Error(\"Mem0 API key is required\");\n }\n if (typeof this.apiKey !== \"string\") {\n throw new Error(\"Mem0 API key must be a string\");\n }\n if (this.apiKey.trim() === \"\") {\n throw new Error(\"Mem0 API key cannot be empty\");\n }\n }\n\n _validateOrgProject(): void {\n // Check for organizationName/projectName pair\n if (\n (this.organizationName === null && this.projectName !== null) ||\n (this.organizationName !== null && this.projectName === null)\n ) {\n console.warn(\n \"Warning: Both organizationName and projectName must be provided together when using either. This will be removedfrom the version 1.0.40. Note that organizationName/projectName are being deprecated in favor of organizationId/projectId.\",\n );\n }\n\n // Check for organizationId/projectId pair\n if (\n (this.organizationId === null && this.projectId !== null) ||\n (this.organizationId !== null && this.projectId === null)\n ) {\n console.warn(\n \"Warning: Both organizationId and projectId must be provided together when using either. This will be removedfrom the version 1.0.40.\",\n );\n }\n }\n\n constructor(options: ClientOptions) {\n this.apiKey = options.apiKey;\n this.host = options.host || \"https://api.mem0.ai\";\n this.organizationName = options.organizationName || null;\n this.projectName = options.projectName || null;\n this.organizationId = options.organizationId || null;\n this.projectId = options.projectId || null;\n\n this.headers = {\n Authorization: `Token ${this.apiKey}`,\n \"Content-Type\": \"application/json\",\n };\n\n this.client = axios.create({\n baseURL: this.host,\n headers: { Authorization: `Token ${this.apiKey}` },\n timeout: 60000,\n });\n\n this._validateApiKey();\n this._validateOrgProject();\n\n // Initialize with a temporary ID that will be updated\n this.telemetryId = \"\";\n\n // Initialize the client\n this._initializeClient();\n }\n\n private async _initializeClient() {\n try {\n // do this only in browser\n if (typeof window !== \"undefined\") {\n this.telemetryId = await generateHash(this.apiKey);\n await captureClientEvent(\"init\", this);\n }\n\n // Wrap methods after initialization\n this.add = this.wrapMethod(\"add\", this.add);\n this.get = this.wrapMethod(\"get\", this.get);\n this.getAll = this.wrapMethod(\"get_all\", this.getAll);\n this.search = this.wrapMethod(\"search\", this.search);\n this.delete = this.wrapMethod(\"delete\", this.delete);\n this.deleteAll = this.wrapMethod(\"delete_all\", this.deleteAll);\n this.history = this.wrapMethod(\"history\", this.history);\n this.users = this.wrapMethod(\"users\", this.users);\n this.deleteUser = this.wrapMethod(\"delete_user\", this.deleteUser);\n this.deleteUsers = this.wrapMethod(\"delete_users\", this.deleteUsers);\n this.batchUpdate = this.wrapMethod(\"batch_update\", this.batchUpdate);\n this.batchDelete = this.wrapMethod(\"batch_delete\", this.batchDelete);\n this.getProject = this.wrapMethod(\"get_project\", this.getProject);\n this.updateProject = this.wrapMethod(\n \"update_project\",\n this.updateProject,\n );\n this.getWebhooks = this.wrapMethod(\"get_webhook\", this.getWebhooks);\n this.createWebhook = this.wrapMethod(\n \"create_webhook\",\n this.createWebhook,\n );\n this.updateWebhook = this.wrapMethod(\n \"update_webhook\",\n this.updateWebhook,\n );\n this.deleteWebhook = this.wrapMethod(\n \"delete_webhook\",\n this.deleteWebhook,\n );\n } catch (error) {\n console.error(\"Failed to initialize client:\", error);\n }\n }\n\n wrapMethod(methodName: any, method: any) {\n return async function (...args: any) {\n // @ts-ignore\n await captureClientEvent(methodName, this);\n // @ts-ignore\n return method.apply(this, args);\n }.bind(this);\n }\n\n async _fetchWithErrorHandling(url: string, options: any): Promise<any> {\n const response = await fetch(url, options);\n if (!response.ok) {\n const errorData = await response.text();\n throw new APIError(`API request failed: ${errorData}`);\n }\n const jsonResponse = await response.json();\n return jsonResponse;\n }\n\n _preparePayload(\n messages: string | Array<Message>,\n options: MemoryOptions,\n ): object {\n const payload: any = {};\n if (typeof messages === \"string\") {\n payload.messages = [{ role: \"user\", content: messages }];\n } else if (Array.isArray(messages)) {\n payload.messages = messages;\n }\n return { ...payload, ...options };\n }\n\n _prepareParams(options: MemoryOptions): object {\n return Object.fromEntries(\n Object.entries(options).filter(([_, v]) => v != null),\n );\n }\n\n async add(\n messages: string | Array<Message>,\n options: MemoryOptions = {},\n ): Promise<Array<Memory>> {\n this._validateOrgProject();\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n\n const payload = this._preparePayload(messages, options);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/memories/`,\n {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(payload),\n },\n );\n return response;\n }\n\n async update(memoryId: string, message: string): Promise<Array<Memory>> {\n this._validateOrgProject();\n const payload = {\n text: message,\n };\n const response = await this._fetchWithErrorHandling(\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 return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n headers: this.headers,\n },\n );\n }\n\n async getAll(options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, page, page_size, ...otherOptions } = options!;\n if (this.organizationName != null && this.projectName != null) {\n otherOptions.org_name = this.organizationName;\n otherOptions.project_name = this.projectName;\n }\n\n let appendedParams = \"\";\n let paginated_response = false;\n\n if (page && page_size) {\n appendedParams += `page=${page}&page_size=${page_size}`;\n paginated_response = true;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n otherOptions.org_id = this.organizationId;\n otherOptions.project_id = this.projectId;\n\n if (otherOptions.org_name) delete otherOptions.org_name;\n if (otherOptions.project_name) delete otherOptions.project_name;\n }\n\n if (api_version === \"v2\") {\n let url = paginated_response\n ? `${this.host}/v2/memories/?${appendedParams}`\n : `${this.host}/v2/memories/`;\n return this._fetchWithErrorHandling(url, {\n method: \"POST\",\n headers: this.headers,\n body: JSON.stringify(otherOptions),\n });\n } else {\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(otherOptions));\n const url = paginated_response\n ? `${this.host}/v1/memories/?${params}&${appendedParams}`\n : `${this.host}/v1/memories/?${params}`;\n return this._fetchWithErrorHandling(url, {\n headers: this.headers,\n });\n }\n }\n\n async search(query: string, options?: SearchOptions): Promise<Array<Memory>> {\n this._validateOrgProject();\n const { api_version, ...otherOptions } = options!;\n const payload = { query, ...otherOptions };\n if (this.organizationName != null && this.projectName != null) {\n payload.org_name = this.organizationName;\n payload.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n payload.org_id = this.organizationId;\n payload.project_id = this.projectId;\n\n if (payload.org_name) delete payload.org_name;\n if (payload.project_name) delete payload.project_name;\n }\n const endpoint =\n api_version === \"v2\" ? \"/v2/memories/search/\" : \"/v1/memories/search/\";\n const response = await this._fetchWithErrorHandling(\n `${this.host}${endpoint}`,\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 return this._fetchWithErrorHandling(\n `${this.host}/v1/memories/${memoryId}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n }\n\n async deleteAll(options: MemoryOptions = {}): Promise<{ message: string }> {\n this._validateOrgProject();\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(this._prepareParams(options));\n const response = await this._fetchWithErrorHandling(\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 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(): Promise<AllUsers> {\n this._validateOrgProject();\n const options: MemoryOptions = {};\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n // @ts-ignore\n const params = new URLSearchParams(options);\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/?${params}`,\n {\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUser(\n entityId: string,\n entity: { type: string } = { type: \"user\" },\n ): Promise<{ message: string }> {\n const response = await this._fetchWithErrorHandling(\n `${this.host}/v1/entities/${entity.type}/${entityId}/`,\n {\n method: \"DELETE\",\n headers: this.headers,\n },\n );\n return response;\n }\n\n async deleteUsers(): Promise<{ message: string }> {\n this._validateOrgProject();\n const entities = await this.users();\n\n for (const entity of entities.results) {\n let options: MemoryOptions = {};\n if (this.organizationName != null && this.projectName != null) {\n options.org_name = this.organizationName;\n options.project_name = this.projectName;\n }\n\n if (this.organizationId != null && this.projectId != null) {\n options.org_id = this.organizationId;\n options.project_id = this.projectId;\n\n if (options.org_name) delete options.org_name;\n if (options.project_name) delete options.project_name;\n }\n await this.client.delete(`/v1/entities/${entity.type}/${entity.id}/`, {\n params: options,\n });\n }\n return { message: \"All users, agents, and sessions deleted.\" };\n }\n\n async batchUpdate(memories: Array<MemoryUpdateBody>): Promise<string> {\n const memoriesBody = memories.map((memory) => ({\n memory_id: memory.memoryId,\n text: memory.text,\n }));\n const response = await this._fetchWithErrorHandling(\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 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 this._validateOrgProject();\n\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\", 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 this._validateOrgProject();\n\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(prompts),\n },\n );\n return response;\n }\n\n // WebHooks\n async getWebhooks(data?: { projectId?: string }): Promise<Array<Webhook>> {\n const project_id = data?.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\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: WebhookPayload): Promise<Webhook> {\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(webhook),\n },\n );\n return response;\n }\n\n async updateWebhook(webhook: WebhookPayload): Promise<{ message: string }> {\n const project_id = webhook.projectId || this.projectId;\n const response = await this._fetchWithErrorHandling(\n `${this.host}/api/v1/webhooks/${webhook.webhookId}/`,\n {\n method: \"PUT\",\n headers: this.headers,\n body: JSON.stringify({\n ...webhook,\n projectId: project_id,\n }),\n },\n );\n return response;\n }\n\n async deleteWebhook(data: {\n webhookId: string;\n }): Promise<{ message: string }> {\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\nexport { MemoryClient };\n","// @ts-nocheck\nimport type { PostHog } from \"posthog-js\";\nimport type { TelemetryClient } from \"./telemetry.types\";\n\nlet version = \"1.0.20\";\n\nconst MEM0_TELEMETRY = true;\nconst POSTHOG_API_KEY = \"phc_hgJkUVJFYtmaJqrvf6CYN67TIQ8yhXAkWzUn9AMU4yX\";\nconst POSTHOG_HOST = \"https://us.i.posthog.com\";\n\n// Browser-specific hash function using Web Crypto API\nasync function generateHash(input: string): Promise<string> {\n const msgBuffer = new TextEncoder().encode(input);\n const hashBuffer = await window.crypto.subtle.digest(\"SHA-256\", msgBuffer);\n const hashArray = Array.from(new Uint8Array(hashBuffer));\n return hashArray.map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");\n}\n\nclass BrowserTelemetry implements TelemetryClient {\n client: PostHog | null = null;\n\n constructor(projectApiKey: string, host: string) {\n if (MEM0_TELEMETRY) {\n this.initializeClient(projectApiKey, host);\n }\n }\n\n private async initializeClient(projectApiKey: string, host: string) {\n try {\n const posthog = await import(\"posthog-js\").catch(() => null);\n if (posthog) {\n posthog.init(projectApiKey, { api_host: host });\n this.client = posthog;\n }\n } catch (error) {\n // Silently fail if posthog-js is not available\n this.client = null;\n }\n }\n\n async captureEvent(distinctId: string, eventName: string, properties = {}) {\n if (!this.client || !MEM0_TELEMETRY) return;\n\n const eventProperties = {\n client_source: \"browser\",\n client_version: getVersion(),\n browser: window.navigator.userAgent,\n ...properties,\n };\n\n try {\n this.client.capture(eventName, eventProperties);\n } catch (error) {\n // Silently fail if telemetry fails\n }\n }\n\n async shutdown() {\n // No shutdown needed for browser client\n }\n}\n\nfunction getVersion() {\n return version;\n}\n\nconst telemetry = new BrowserTelemetry(POSTHOG_API_KEY, POSTHOG_HOST);\n\nasync function captureClientEvent(\n eventName: string,\n instance: any,\n additionalData = {},\n) {\n const eventData = {\n function: `${instance.constructor.name}`,\n ...additionalData,\n };\n await telemetry.captureEvent(\n instance.telemetryId,\n `client.${eventName}`,\n eventData,\n );\n}\n\nexport { telemetry, captureClientEvent, generateHash };\n","import { MemoryClient } from \"./mem0\";\nimport type { TelemetryClient, TelemetryInstance } from \"./telemetry.types\";\nimport {\n telemetry,\n captureClientEvent,\n generateHash,\n} from \"./telemetry.browser\";\nimport type * as MemoryTypes from \"./mem0.types\";\n\n// Re-export all types from mem0.types\nexport type {\n MemoryOptions,\n ProjectOptions,\n Memory,\n MemoryHistory,\n MemoryUpdateBody,\n ProjectResponse,\n PromptUpdatePayload,\n SearchOptions,\n Webhook,\n WebhookPayload,\n Messages,\n Message,\n AllUsers,\n User,\n} from \"./mem0.types\";\n\n// Export telemetry types\nexport type { TelemetryClient, TelemetryInstance };\n\n// Export telemetry implementation\nexport { telemetry, captureClientEvent, generateHash };\n\n// Export the main client\nexport { MemoryClient };\nexport default MemoryClient;\n"],"mappings":";AAAA,OAAO,WAAW;;;ACIlB,IAAI,UAAU;AAEd,IAAM,iBAAiB;AACvB,IAAM,kBAAkB;AACxB,IAAM,eAAe;AAGrB,eAAe,aAAa,OAAgC;AAC1D,QAAM,YAAY,IAAI,YAAY,EAAE,OAAO,KAAK;AAChD,QAAM,aAAa,MAAM,OAAO,OAAO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,KAAK,IAAI,oBAAoB,UAAU;AAAA,MAC1C;AAAA,QACE,QAAQ;AAAA,QACR,SAAS,KAAK;AAAA,MAChB;AAAA,IACF;AACA,WAAO;AAAA,EACT;AACF;;;AE3gBA,IAAO,gBAAQ;","names":[]}
|
package/dist/oss/index.d.mts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
3
3
|
|
|
4
|
+
interface MultiModalMessages {
|
|
5
|
+
type: "image_url";
|
|
6
|
+
image_url: {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
4
10
|
interface Message {
|
|
5
11
|
role: string;
|
|
6
|
-
content: string;
|
|
12
|
+
content: string | MultiModalMessages;
|
|
7
13
|
}
|
|
8
14
|
interface EmbeddingConfig {
|
|
9
15
|
apiKey: string;
|
|
@@ -509,4 +515,4 @@ declare class VectorStoreFactory {
|
|
|
509
515
|
static create(provider: string, config: VectorStoreConfig): VectorStore;
|
|
510
516
|
}
|
|
511
517
|
|
|
512
|
-
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type Neo4jConfig, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
518
|
+
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type MultiModalMessages, type Neo4jConfig, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
package/dist/oss/index.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import { QdrantClient } from '@qdrant/js-client-rest';
|
|
3
3
|
|
|
4
|
+
interface MultiModalMessages {
|
|
5
|
+
type: "image_url";
|
|
6
|
+
image_url: {
|
|
7
|
+
url: string;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
4
10
|
interface Message {
|
|
5
11
|
role: string;
|
|
6
|
-
content: string;
|
|
12
|
+
content: string | MultiModalMessages;
|
|
7
13
|
}
|
|
8
14
|
interface EmbeddingConfig {
|
|
9
15
|
apiKey: string;
|
|
@@ -509,4 +515,4 @@ declare class VectorStoreFactory {
|
|
|
509
515
|
static create(provider: string, config: VectorStoreConfig): VectorStore;
|
|
510
516
|
}
|
|
511
517
|
|
|
512
|
-
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type Neo4jConfig, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
|
518
|
+
export { type AddMemoryOptions, AnthropicLLM, type DeleteAllMemoryOptions, type Embedder, EmbedderFactory, type EmbeddingConfig, type Entity, type GetAllMemoryOptions, type GraphStoreConfig, GroqLLM, type LLM, type LLMConfig, LLMFactory, type LLMResponse, Memory, type MemoryConfig, MemoryConfigSchema, type MemoryItem, MemoryVectorStore, type Message, type MultiModalMessages, type Neo4jConfig, OpenAIEmbedder, OpenAILLM, OpenAIStructuredLLM, Qdrant, RedisDB, type SearchFilters, type SearchMemoryOptions, type SearchResult, type VectorStore, type VectorStoreConfig, VectorStoreFactory, type VectorStoreResult };
|
package/dist/oss/index.js
CHANGED
|
@@ -121,14 +121,17 @@ var import_openai2 = __toESM(require("openai"));
|
|
|
121
121
|
var OpenAILLM = class {
|
|
122
122
|
constructor(config) {
|
|
123
123
|
this.openai = new import_openai2.default({ apiKey: config.apiKey });
|
|
124
|
-
this.model = config.model || "gpt-
|
|
124
|
+
this.model = config.model || "gpt-4o-mini";
|
|
125
125
|
}
|
|
126
126
|
async generateResponse(messages, responseFormat, tools) {
|
|
127
127
|
const completion = await this.openai.chat.completions.create({
|
|
128
|
-
messages: messages.map((msg) =>
|
|
129
|
-
role
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
messages: messages.map((msg) => {
|
|
129
|
+
const role = msg.role;
|
|
130
|
+
return {
|
|
131
|
+
role,
|
|
132
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
133
|
+
};
|
|
134
|
+
}),
|
|
132
135
|
model: this.model,
|
|
133
136
|
response_format: responseFormat,
|
|
134
137
|
...tools && { tools, tool_choice: "auto" }
|
|
@@ -148,10 +151,13 @@ var OpenAILLM = class {
|
|
|
148
151
|
}
|
|
149
152
|
async generateChat(messages) {
|
|
150
153
|
const completion = await this.openai.chat.completions.create({
|
|
151
|
-
messages: messages.map((msg) =>
|
|
152
|
-
role
|
|
153
|
-
|
|
154
|
-
|
|
154
|
+
messages: messages.map((msg) => {
|
|
155
|
+
const role = msg.role;
|
|
156
|
+
return {
|
|
157
|
+
role,
|
|
158
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
159
|
+
};
|
|
160
|
+
}),
|
|
155
161
|
model: this.model
|
|
156
162
|
});
|
|
157
163
|
const response = completion.choices[0].message;
|
|
@@ -173,7 +179,7 @@ var OpenAIStructuredLLM = class {
|
|
|
173
179
|
const completion = await this.openai.chat.completions.create({
|
|
174
180
|
messages: messages.map((msg) => ({
|
|
175
181
|
role: msg.role,
|
|
176
|
-
content: msg.content
|
|
182
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
177
183
|
})),
|
|
178
184
|
model: this.model,
|
|
179
185
|
...tools ? {
|
|
@@ -209,7 +215,7 @@ var OpenAIStructuredLLM = class {
|
|
|
209
215
|
const completion = await this.openai.chat.completions.create({
|
|
210
216
|
messages: messages.map((msg) => ({
|
|
211
217
|
role: msg.role,
|
|
212
|
-
content: msg.content
|
|
218
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
213
219
|
})),
|
|
214
220
|
model: this.model
|
|
215
221
|
});
|
|
@@ -239,9 +245,9 @@ var AnthropicLLM = class {
|
|
|
239
245
|
model: this.model,
|
|
240
246
|
messages: otherMessages.map((msg) => ({
|
|
241
247
|
role: msg.role,
|
|
242
|
-
content: msg.content
|
|
248
|
+
content: typeof msg.content === "string" ? msg.content : msg.content.image_url.url
|
|
243
249
|
})),
|
|
244
|
-
system: systemMessage == null ? void 0 : systemMessage.content,
|
|
250
|
+
system: typeof (systemMessage == null ? void 0 : systemMessage.content) === "string" ? systemMessage.content : void 0,
|
|
245
251
|
max_tokens: 4096
|
|
246
252
|
});
|
|
247
253
|
return response.content[0].text;
|
|
@@ -271,7 +277,7 @@ var GroqLLM = class {
|
|
|
271
277
|
model: this.model,
|
|
272
278
|
messages: messages.map((msg) => ({
|
|
273
279
|
role: msg.role,
|
|
274
|
-
content: msg.content
|
|
280
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
275
281
|
})),
|
|
276
282
|
response_format: responseFormat
|
|
277
283
|
});
|
|
@@ -282,7 +288,7 @@ var GroqLLM = class {
|
|
|
282
288
|
model: this.model,
|
|
283
289
|
messages: messages.map((msg) => ({
|
|
284
290
|
role: msg.role,
|
|
285
|
-
content: msg.content
|
|
291
|
+
content: typeof msg.content === "string" ? msg.content : JSON.stringify(msg.content)
|
|
286
292
|
}))
|
|
287
293
|
});
|
|
288
294
|
const message = response.choices[0].message;
|
|
@@ -2195,6 +2201,43 @@ Text: ${data}`
|
|
|
2195
2201
|
}
|
|
2196
2202
|
};
|
|
2197
2203
|
|
|
2204
|
+
// src/oss/src/utils/memory.ts
|
|
2205
|
+
var get_image_description = async (image_url) => {
|
|
2206
|
+
const llm = new OpenAILLM({
|
|
2207
|
+
apiKey: process.env.OPENAI_API_KEY
|
|
2208
|
+
});
|
|
2209
|
+
const response = await llm.generateResponse([
|
|
2210
|
+
{
|
|
2211
|
+
role: "user",
|
|
2212
|
+
content: "Provide a description of the image and do not include any additional text."
|
|
2213
|
+
},
|
|
2214
|
+
{
|
|
2215
|
+
role: "user",
|
|
2216
|
+
content: { type: "image_url", image_url: { url: image_url } }
|
|
2217
|
+
}
|
|
2218
|
+
]);
|
|
2219
|
+
return response;
|
|
2220
|
+
};
|
|
2221
|
+
var parse_vision_messages = async (messages) => {
|
|
2222
|
+
const parsed_messages = [];
|
|
2223
|
+
for (const message of messages) {
|
|
2224
|
+
let new_message = {
|
|
2225
|
+
role: message.role,
|
|
2226
|
+
content: ""
|
|
2227
|
+
};
|
|
2228
|
+
if (message.role !== "system") {
|
|
2229
|
+
if (typeof message.content === "object" && message.content.type === "image_url") {
|
|
2230
|
+
const description = await get_image_description(
|
|
2231
|
+
message.content.image_url.url
|
|
2232
|
+
);
|
|
2233
|
+
new_message.content = typeof description === "string" ? description : JSON.stringify(description);
|
|
2234
|
+
parsed_messages.push(new_message);
|
|
2235
|
+
} else parsed_messages.push(message);
|
|
2236
|
+
}
|
|
2237
|
+
}
|
|
2238
|
+
return parsed_messages;
|
|
2239
|
+
};
|
|
2240
|
+
|
|
2198
2241
|
// src/oss/src/memory/index.ts
|
|
2199
2242
|
var Memory = class _Memory {
|
|
2200
2243
|
constructor(config = {}) {
|
|
@@ -2247,8 +2290,9 @@ var Memory = class _Memory {
|
|
|
2247
2290
|
);
|
|
2248
2291
|
}
|
|
2249
2292
|
const parsedMessages = Array.isArray(messages) ? messages : [{ role: "user", content: messages }];
|
|
2293
|
+
const final_parsedMessages = await parse_vision_messages(parsedMessages);
|
|
2250
2294
|
const vectorStoreResult = await this.addToVectorStore(
|
|
2251
|
-
|
|
2295
|
+
final_parsedMessages,
|
|
2252
2296
|
metadata,
|
|
2253
2297
|
filters
|
|
2254
2298
|
);
|
|
@@ -2256,7 +2300,7 @@ var Memory = class _Memory {
|
|
|
2256
2300
|
if (this.graphMemory) {
|
|
2257
2301
|
try {
|
|
2258
2302
|
graphResult = await this.graphMemory.add(
|
|
2259
|
-
|
|
2303
|
+
final_parsedMessages.map((m) => m.content).join("\n"),
|
|
2260
2304
|
filters
|
|
2261
2305
|
);
|
|
2262
2306
|
} catch (error) {
|