feat: Memory Exports (#3117)
This commit is contained in:
@@ -13,6 +13,8 @@ import {
|
||||
WebhookPayload,
|
||||
Message,
|
||||
FeedbackPayload,
|
||||
CreateMemoryExportPayload,
|
||||
GetMemoryExportPayload,
|
||||
} from "./mem0.types";
|
||||
import { captureClientEvent, generateHash } from "./telemetry";
|
||||
|
||||
@@ -705,6 +707,57 @@ export default class MemoryClient {
|
||||
);
|
||||
return response;
|
||||
}
|
||||
|
||||
async createMemoryExport(
|
||||
data: CreateMemoryExportPayload,
|
||||
): Promise<{ message: string; id: string }> {
|
||||
if (this.telemetryId === "") await this.ping();
|
||||
this._captureEvent("create_memory_export", []);
|
||||
|
||||
// Return if missing filters or schema
|
||||
if (!data.filters || !data.schema) {
|
||||
throw new Error("Missing filters or schema");
|
||||
}
|
||||
|
||||
// Add Org and Project ID
|
||||
data.org_id = this.organizationId?.toString() || null;
|
||||
data.project_id = this.projectId?.toString() || null;
|
||||
|
||||
const response = await this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/exports/`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: this.headers,
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
|
||||
return response;
|
||||
}
|
||||
|
||||
async getMemoryExport(
|
||||
data: GetMemoryExportPayload,
|
||||
): Promise<{ message: string; id: string }> {
|
||||
if (this.telemetryId === "") await this.ping();
|
||||
this._captureEvent("get_memory_export", []);
|
||||
|
||||
if (!data.memory_export_id && !data.filters) {
|
||||
throw new Error("Missing memory_export_id or filters");
|
||||
}
|
||||
|
||||
data.org_id = this.organizationId?.toString() || "";
|
||||
data.project_id = this.projectId?.toString() || "";
|
||||
|
||||
const response = await this._fetchWithErrorHandling(
|
||||
`${this.host}/v1/exports/get/`,
|
||||
{
|
||||
method: "POST",
|
||||
headers: this.headers,
|
||||
body: JSON.stringify(data),
|
||||
},
|
||||
);
|
||||
return response;
|
||||
}
|
||||
}
|
||||
|
||||
export { MemoryClient };
|
||||
|
||||
@@ -1,3 +1,8 @@
|
||||
interface Common {
|
||||
project_id?: string | null;
|
||||
org_id?: string | null;
|
||||
}
|
||||
|
||||
export interface MemoryOptions {
|
||||
api_version?: API_VERSION | string;
|
||||
version?: API_VERSION | string;
|
||||
@@ -187,3 +192,14 @@ export interface FeedbackPayload {
|
||||
feedback?: Feedback | null;
|
||||
feedback_reason?: string | null;
|
||||
}
|
||||
|
||||
export interface CreateMemoryExportPayload extends Common {
|
||||
schema: Record<string, any>;
|
||||
filters: Record<string, any>;
|
||||
export_instructions?: string;
|
||||
}
|
||||
|
||||
export interface GetMemoryExportPayload extends Common {
|
||||
filters?: Record<string, any>;
|
||||
memory_export_id?: string;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// @ts-nocheck
|
||||
import type { TelemetryClient, TelemetryOptions } from "./telemetry.types";
|
||||
|
||||
let version = "2.1.33";
|
||||
let version = "2.1.35";
|
||||
|
||||
// Safely check for process.env in different environments
|
||||
let MEM0_TELEMETRY = true;
|
||||
|
||||
Reference in New Issue
Block a user