import { type IAgentRuntime, Service } from "@elizaos/core"; type TrajectoryStatus = "active" | "completed" | "error" | "timeout"; interface TrajectoryListOptions { limit?: number; offset?: number; source?: string; status?: TrajectoryStatus; startDate?: string; endDate?: string; search?: string; scenarioId?: string; batchId?: string; isTrainingData?: boolean; } interface TrajectoryListItem { id: string; agentId: string; source: string; status: TrajectoryStatus; startTime: number; endTime: number | null; durationMs: number | null; stepCount: number; llmCallCount: number; providerAccessCount: number; totalPromptTokens: number; totalCompletionTokens: number; createdAt: string; metadata?: Record; } interface TrajectoryListResult { trajectories: TrajectoryListItem[]; total: number; offset: number; limit: number; } interface TrajectoryStep { stepId?: string; timestamp: number; llmCalls?: Array<{ callId?: string; timestamp?: number; model?: string; systemPrompt?: string; userPrompt?: string; response?: string; temperature?: number; maxTokens?: number; purpose?: string; actionType?: string; latencyMs?: number; promptTokens?: number; completionTokens?: number; }>; providerAccesses?: Array<{ providerId?: string; providerName?: string; purpose?: string; data?: Record; query?: Record; timestamp?: number; }>; } interface Trajectory { trajectoryId: string; agentId: string; startTime: number; endTime?: number; durationMs?: number; steps?: TrajectoryStep[]; metrics?: { finalStatus?: string; }; metadata?: Record; stepsJson?: string; } type TrajectoryExportFormat = "json" | "csv" | "art"; interface TrajectoryExportOptions { format: TrajectoryExportFormat; includePrompts?: boolean; trajectoryIds?: string[]; startDate?: string; endDate?: string; scenarioId?: string; batchId?: string; } interface TrajectoryExportResult { filename: string; data: string | Uint8Array; mimeType: string; } type StartStepOptions = { runtime: IAgentRuntime; stepId: string; source?: string; metadata?: Record; }; type CompleteStepOptions = { runtime: IAgentRuntime; stepId: string; status?: TrajectoryStatus; source?: string; metadata?: Record; }; /** @internal Exported for testing. */ export declare function shouldRunObservationExtraction(runtime: IAgentRuntime): boolean; /** @internal Exported for testing. */ export declare function truncateField(value: string, limit?: number): string; /** @internal Exported for testing. */ export declare function truncateRecord(obj: Record, limit?: number): Record; /** @internal Exported for testing. */ export declare function extractInsightsFromResponse(response: string, purpose: string): string[]; interface BufferedExchange { userPrompt: string; response: string; trajectoryId: string; timestamp: number; } /** @internal Exported for testing. */ export declare function pushChatExchange(runtime: IAgentRuntime, exchange: BufferedExchange): void; /** @internal Exported for testing. */ export declare function flushObservationBuffer(runtime: IAgentRuntime): Promise; /** @internal Exported for testing. */ export declare function extractRows(result: unknown): unknown[]; /** @internal Exported for testing. */ export declare function computeBySource(runtime: IAgentRuntime): Promise>; /** * Read orchestrator trajectory context from the runtime, if set. * The coding agent orchestrator plugin sets `__orchestratorTrajectoryCtx` on * the runtime around `useModel()` calls so we can tag them here. */ /** @internal Exported for testing. */ export declare function readOrchestratorTrajectoryContext(runtime: unknown): { source: "orchestrator"; decisionType: string; sessionId?: string; taskLabel?: string; repo?: string; workdir?: string; originalTask?: string; } | undefined; export declare function installDatabaseTrajectoryLogger(runtime: IAgentRuntime): void; export declare function startTrajectoryStepInDatabase({ runtime, stepId, source, metadata, }: StartStepOptions): Promise; export declare function completeTrajectoryStepInDatabase({ runtime, stepId, status, source, metadata, }: CompleteStepOptions): Promise; export declare function loadPersistedTrajectoryRows(runtime: IAgentRuntime, maxRows?: number): Promise[] | null>; export declare function deletePersistedTrajectoryRows(runtime: IAgentRuntime, trajectoryIds: string[]): Promise; export declare function clearPersistedTrajectoryRows(runtime: IAgentRuntime): Promise; /** * Archive and then delete trajectories older than `maxAgeDays`. * Summary rows (without steps_json) are copied to `trajectory_archive` * before the heavy raw data is removed. Returns the number of rows * pruned, or null if the DB is unavailable. */ export declare function pruneOldTrajectories(runtime: IAgentRuntime, maxAgeDays?: number): Promise; /** * Wait for all pending trajectory writes to complete. * Useful for tests to ensure writes are flushed before assertions. */ export declare function flushTrajectoryWrites(runtime: IAgentRuntime): Promise; /** * Database-backed trajectory logger service that implements the full API * expected by trajectory-routes.ts. This service reads from and writes to * the database for trajectory persistence. */ export declare class DatabaseTrajectoryLogger extends Service { static serviceType: string; capabilityDescription: string; private enabled; /** * Static start method required by @elizaos/core runtime. */ static start(runtime: IAgentRuntime): Promise; initialize(): Promise; stop(): Promise; isEnabled(): boolean; setEnabled(enabled: boolean): void; /** * Start a new trajectory for tracking LLM interactions. * Supports both legacy (stepId, {agentId}) and new (agentId, options) signatures. */ startTrajectory(stepIdOrAgentId: string, options?: { agentId?: string; roomId?: string; entityId?: string; source?: string; metadata?: Record; }): Promise; /** * Start a new step within an existing trajectory. */ startStep(_trajectoryId: string): string; /** * End a trajectory and mark it with the given status. */ endTrajectory(stepIdOrTrajectoryId: string, status?: TrajectoryStatus): Promise; logLlmCall(params: Record): void; logProviderAccess(params: Record): void; getLlmCallLogs(): readonly unknown[]; getProviderAccessLogs(): readonly unknown[]; listTrajectories(options: TrajectoryListOptions): Promise; getTrajectoryDetail(trajectoryId: string): Promise; getStats(): Promise; deleteTrajectories(trajectoryIds: string[]): Promise; clearAllTrajectories(): Promise; exportTrajectories(options: TrajectoryExportOptions): Promise; } /** * Create and register a database-backed trajectory logger service on the runtime. * This replaces any existing trajectory_logger service with one that persists to the database. */ export declare function createDatabaseTrajectoryLogger(runtime: IAgentRuntime): DatabaseTrajectoryLogger; export declare function shouldEnableTrajectoryLoggingByDefault(): boolean; export {}; //# sourceMappingURL=trajectory-persistence.d.ts.map