UNPKG

@struktoai/mirage-core

Version:

A Unified Virtual Filesystem For AI Agents

65 lines • 2.55 kB
import { z } from 'zod'; import { timeoutShape } from "../../core/api/config.js"; import { DEFAULT_TIMEOUT } from "../../core/api/constants.js"; import { rstripSlash } from "../../utils/slash.js"; import { secretStr } from "../secrets.js"; export const Mem0Config = z.object({ ...timeoutShape, apiKey: secretStr().describe('Mem0 Platform API key.'), host: z .string() .optional() .meta({ description: 'Mem0 API base URL.', default: 'https://api.mem0.ai' }), userId: z .string() .optional() .describe("Mount this user's memories. Set exactly one of `userId`, `agentId` and `runId`."), agentId: z .string() .optional() .describe("Mount this agent's memories. Set exactly one of `userId`, `agentId` and `runId`."), runId: z .string() .optional() .describe("Mount this run's memories. Set exactly one of `userId`, `agentId` and `runId`."), defaultPageSize: z.number().optional().meta({ description: 'Memories fetched per request while listing the scope.', default: 100, }), defaultSearchLimit: z.number().optional().meta({ description: 'How many results `search` returns unless the line sets `top_k`.', default: 10, }), }); function positive(value, fallback, name) { const resolved = value ?? fallback; if (!Number.isInteger(resolved) || resolved <= 0) throw new Error(`${name} must be positive`); return resolved; } export function resolveMem0Config(config) { const scopes = [ ['user_id', config.userId], ['agent_id', config.agentId], ['run_id', config.runId], ].filter((scope) => scope[1] !== undefined); if (scopes.length !== 1) { throw new Error('Mem0Config requires exactly one of userId, agentId, runId'); } const scope = scopes[0]; if (scope?.[1]?.trim() === '' || scope?.[1] === undefined) { throw new Error('Mem0 scope id cannot be empty'); } return { timeout: config.timeout ?? DEFAULT_TIMEOUT, apiKey: config.apiKey, host: rstripSlash(config.host ?? 'https://api.mem0.ai'), userId: config.userId ?? null, agentId: config.agentId ?? null, runId: config.runId ?? null, defaultPageSize: positive(config.defaultPageSize, 100, 'defaultPageSize'), defaultSearchLimit: positive(config.defaultSearchLimit, 10, 'defaultSearchLimit'), scopeFilter: { [scope[0]]: scope[1] }, }; } //# sourceMappingURL=config.js.map