/**
 * Tool call recorder middleware.
 *
 * Creates a middleware that records tool executions passing through
 * the tool registry. Follows the existing ToolMiddleware pattern.
 */
/**
 * Creates a tool recording middleware.
 *
 * This middleware wraps tool execution to record inputs, outputs,
 * errors, and timing information.
 *
 * @param recorder - The RecordingManager instance
 * @returns A ToolMiddleware that records tool executions
 *
 * @example
 * ```typescript
 * const recordingMiddleware = createToolRecordingMiddleware(recorder);
 * registry.addMiddleware(recordingMiddleware);
 * ```
 */
export function createToolRecordingMiddleware(recorder) {
    return (tool) => {
        return {
            ...tool,
            execute: async (input, options) => {
                // If recording is not enabled, just execute normally
                if (!recorder.isEnabled()) {
                    return tool.execute(input, options);
                }
                const startTime = Date.now();
                try {
                    const output = await tool.execute(input, options);
                    recorder.recordTool({
                        toolName: tool.name,
                        toolCallId: options?.toolCallId ?? "",
                        input,
                        output,
                        durationMs: Date.now() - startTime,
                    });
                    return output;
                }
                catch (error) {
                    recorder.recordTool({
                        toolName: tool.name,
                        toolCallId: options?.toolCallId ?? "",
                        input,
                        output: null,
                        error: error instanceof Error ? error.message : String(error),
                        durationMs: Date.now() - startTime,
                    });
                    throw error;
                }
            },
        };
    };
}
//# sourceMappingURL=tool-recorder.js.map