/**
 * @license
 * Copyright 2025 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 * @plan PLAN-20250909-TOKTRACK.P08
 */
import { DEFAULT_AGENT_ID } from '../core/turn.js';
import { ToolConfirmationOutcome } from '../tools/tools.js';
import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
import { AuthType } from '../core/contentGenerator.js';
export var ToolCallDecision;
(function (ToolCallDecision) {
    ToolCallDecision["ACCEPT"] = "accept";
    ToolCallDecision["REJECT"] = "reject";
    ToolCallDecision["MODIFY"] = "modify";
    ToolCallDecision["AUTO_ACCEPT"] = "auto_accept";
})(ToolCallDecision || (ToolCallDecision = {}));
export function getDecisionFromOutcome(outcome) {
    switch (outcome) {
        case ToolConfirmationOutcome.ProceedOnce:
            return ToolCallDecision.ACCEPT;
        case ToolConfirmationOutcome.ProceedAlways:
        case ToolConfirmationOutcome.ProceedAlwaysServer:
        case ToolConfirmationOutcome.ProceedAlwaysTool:
            return ToolCallDecision.AUTO_ACCEPT;
        case ToolConfirmationOutcome.ModifyWithEditor:
            return ToolCallDecision.MODIFY;
        case ToolConfirmationOutcome.Cancel:
        default:
            return ToolCallDecision.REJECT;
    }
}
export class StartSessionEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    model;
    embedding_model;
    sandbox_enabled;
    core_tools_enabled;
    approval_mode;
    api_key_enabled;
    vertex_ai_enabled;
    debug_enabled;
    mcp_servers;
    telemetry_enabled;
    telemetry_log_user_prompts_enabled;
    file_filtering_respect_git_ignore;
    constructor(config) {
        const generatorConfig = config.getContentGeneratorConfig();
        const mcpServers = config.getMcpServers();
        let useGemini = false;
        let useVertex = false;
        if (generatorConfig && generatorConfig.authType) {
            useGemini = generatorConfig.authType === AuthType.USE_GEMINI;
            useVertex = generatorConfig.authType === AuthType.USE_VERTEX_AI;
        }
        this['event.name'] = 'cli_config';
        this.model = config.getModel();
        this.embedding_model = config.getEmbeddingModel();
        this.sandbox_enabled =
            typeof config.getSandbox() === 'string' || !!config.getSandbox();
        this.core_tools_enabled = (config.getCoreTools() ?? []).join(',');
        this.approval_mode = config.getApprovalMode();
        this.api_key_enabled = useGemini || useVertex;
        this.vertex_ai_enabled = useVertex;
        this.debug_enabled = config.getDebugMode();
        this.mcp_servers = mcpServers ? Object.keys(mcpServers).join(',') : '';
        this.telemetry_enabled = config.getTelemetryEnabled();
        this.telemetry_log_user_prompts_enabled =
            config.getTelemetryLogPromptsEnabled();
        this.file_filtering_respect_git_ignore =
            config.getFileFilteringRespectGitIgnore();
    }
}
export class EndSessionEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    session_id;
    constructor(config) {
        this['event.name'] = 'end_session';
        this['event.timestamp'] = new Date().toISOString();
        this.session_id = config?.getSessionId();
    }
}
export class UserPromptEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    prompt_length;
    prompt_id;
    auth_type;
    prompt;
    constructor(prompt_length, prompt_Id, auth_type, prompt) {
        this['event.name'] = 'user_prompt';
        this['event.timestamp'] = new Date().toISOString();
        this.prompt_length = prompt_length;
        this.prompt_id = prompt_Id;
        this.auth_type = auth_type;
        this.prompt = prompt;
    }
}
export class ToolCallEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    function_name;
    function_args;
    duration_ms;
    success;
    decision;
    error;
    error_type;
    prompt_id;
    tool_type;
    metadata;
    agent_id;
    constructor(call) {
        this['event.name'] = 'tool_call';
        this['event.timestamp'] = new Date().toISOString();
        this.function_name = call.request.name;
        this.function_args = call.request.args;
        this.duration_ms = call.durationMs ?? 0;
        this.success = call.status === 'success';
        this.decision = call.outcome
            ? getDecisionFromOutcome(call.outcome)
            : undefined;
        this.error = call.response.error?.message;
        this.error_type = call.response.errorType;
        this.prompt_id = call.request.prompt_id;
        this.tool_type =
            typeof call.tool !== 'undefined' && call.tool instanceof DiscoveredMCPTool
                ? 'mcp'
                : 'native';
        this.agent_id = call.request.agentId ?? DEFAULT_AGENT_ID;
        if (call.status === 'success' &&
            typeof call.response.resultDisplay === 'object' &&
            call.response.resultDisplay !== null &&
            'diffStat' in call.response.resultDisplay) {
            const diffStat = call.response.resultDisplay.diffStat;
            if (diffStat) {
                this.metadata = {
                    ai_added_lines: diffStat.ai_added_lines,
                    ai_removed_lines: diffStat.ai_removed_lines,
                    user_added_lines: diffStat.user_added_lines,
                    user_removed_lines: diffStat.user_removed_lines,
                };
            }
        }
    }
}
export class ApiRequestEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    model;
    prompt_id;
    request_text;
    constructor(model, prompt_id, request_text) {
        this['event.name'] = 'api_request';
        this['event.timestamp'] = new Date().toISOString();
        this.model = model;
        this.prompt_id = prompt_id;
        this.request_text = request_text;
    }
}
export class ApiErrorEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    model;
    error;
    error_type;
    status_code;
    duration_ms;
    prompt_id;
    auth_type;
    constructor(model, error, duration_ms, prompt_id, auth_type, error_type, status_code) {
        this['event.name'] = 'api_error';
        this['event.timestamp'] = new Date().toISOString();
        this.model = model;
        this.error = error;
        this.error_type = error_type;
        this.status_code = status_code;
        this.duration_ms = duration_ms;
        this.prompt_id = prompt_id;
        this.auth_type = auth_type;
    }
}
export class ApiResponseEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    model;
    status_code;
    duration_ms;
    error;
    input_token_count;
    output_token_count;
    cached_content_token_count;
    thoughts_token_count;
    tool_token_count;
    total_token_count;
    response_text;
    prompt_id;
    auth_type;
    constructor(model, duration_ms, prompt_id, auth_type, usage_data, response_text, error) {
        this['event.name'] = 'api_response';
        this['event.timestamp'] = new Date().toISOString();
        this.model = model;
        this.duration_ms = duration_ms;
        this.status_code = 200;
        this.input_token_count = usage_data?.promptTokenCount ?? 0;
        this.output_token_count = usage_data?.candidatesTokenCount ?? 0;
        this.cached_content_token_count = usage_data?.cachedContentTokenCount ?? 0;
        this.thoughts_token_count = usage_data?.thoughtsTokenCount ?? 0;
        this.tool_token_count = usage_data?.toolUsePromptTokenCount ?? 0;
        this.total_token_count = usage_data?.totalTokenCount ?? 0;
        this.response_text = response_text;
        this.error = error;
        this.prompt_id = prompt_id;
        this.auth_type = auth_type;
    }
}
export var LoopType;
(function (LoopType) {
    LoopType["CONSECUTIVE_IDENTICAL_TOOL_CALLS"] = "consecutive_identical_tool_calls";
    LoopType["CHANTING_IDENTICAL_SENTENCES"] = "chanting_identical_sentences";
    LoopType["MAX_TURNS_EXCEEDED"] = "max_turns_exceeded";
})(LoopType || (LoopType = {}));
export class LoopDetectedEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    loop_type;
    prompt_id;
    constructor(loop_type, prompt_id) {
        this['event.name'] = 'loop_detected';
        this['event.timestamp'] = new Date().toISOString();
        this.loop_type = loop_type;
        this.prompt_id = prompt_id;
    }
}
export class NextSpeakerCheckEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    prompt_id;
    finish_reason;
    result;
    constructor(prompt_id, finish_reason, result) {
        this['event.name'] = 'next_speaker_check';
        this['event.timestamp'] = new Date().toISOString();
        this.prompt_id = prompt_id;
        this.finish_reason = finish_reason;
        this.result = result;
    }
}
export class SlashCommandEvent {
    'event.name';
    'event.timestamp'; // ISO 8106
    command;
    subcommand;
    constructor(command, subcommand) {
        this['event.name'] = 'slash_command';
        this['event.timestamp'] = new Date().toISOString();
        this.command = command;
        this.subcommand = subcommand;
    }
}
export class MalformedJsonResponseEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    model;
    constructor(model) {
        this['event.name'] = 'malformed_json_response';
        this['event.timestamp'] = new Date().toISOString();
        this.model = model;
    }
}
export class ConversationRequestEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    provider_name;
    conversation_id;
    turn_number;
    prompt_id;
    redacted_messages;
    redacted_tools;
    tool_format;
    provider_switched;
    constructor(provider_name, conversation_id, turn_number, prompt_id, redacted_messages, redacted_tools, tool_format, provider_switched) {
        this['event.name'] = 'conversation_request';
        this['event.timestamp'] = new Date().toISOString();
        this.provider_name = provider_name;
        this.conversation_id = conversation_id;
        this.turn_number = turn_number;
        this.prompt_id = prompt_id;
        this.redacted_messages = redacted_messages;
        this.redacted_tools = redacted_tools;
        this.tool_format = tool_format;
        this.provider_switched = provider_switched;
    }
}
export class ConversationResponseEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    provider_name;
    conversation_id;
    turn_number;
    prompt_id;
    redacted_content;
    duration_ms;
    success;
    error;
    tool_calls;
    constructor(provider_name, conversation_id, turn_number, prompt_id, redacted_content, duration_ms, success, error, tool_calls) {
        this['event.name'] = 'conversation_response';
        this['event.timestamp'] = new Date().toISOString();
        this.provider_name = provider_name;
        this.conversation_id = conversation_id;
        this.turn_number = turn_number;
        this.prompt_id = prompt_id;
        this.redacted_content = redacted_content;
        this.duration_ms = duration_ms;
        this.success = success;
        this.error = error;
        this.tool_calls = tool_calls;
    }
}
export class ProviderSwitchEvent {
    'event.name';
    'event.timestamp'; // ISO 8601
    from_provider;
    to_provider;
    conversation_id;
    context_preserved;
    constructor(from_provider, to_provider, conversation_id, context_preserved) {
        this['event.name'] = 'provider_switch';
        this['event.timestamp'] = new Date().toISOString();
        this.from_provider = from_provider;
        this.to_provider = to_provider;
        this.conversation_id = conversation_id;
        this.context_preserved = context_preserved;
    }
}
/**
 * @plan PLAN-20250909-TOKTRACK.P10
 */
export class EnhancedConversationResponseEvent extends ConversationResponseEvent {
    provider_context;
    performance_metrics;
    tool_calls_detailed;
    constructor(provider_name, conversation_id, turn_number, prompt_id, redacted_content, duration_ms, success, error, tool_calls, performance_metrics, provider_context) {
        super(provider_name, conversation_id, turn_number, prompt_id, redacted_content, duration_ms, success, error, tool_calls);
        this.tool_calls_detailed = tool_calls || [];
        this.performance_metrics =
            performance_metrics || this.createDefaultMetrics(provider_name);
        this.provider_context =
            provider_context || this.createDefaultContext(provider_name);
    }
    createDefaultMetrics(providerName) {
        return {
            providerName,
            totalRequests: 0,
            totalTokens: 0,
            averageLatency: 0,
            timeToFirstToken: null,
            tokensPerSecond: 0,
            tokensPerMinute: 0,
            throttleWaitTimeMs: 0,
            chunksReceived: 0,
            errorRate: 0,
            errors: [],
            sessionTokenUsage: {
                input: 0,
                output: 0,
                cache: 0,
                tool: 0,
                thought: 0,
                total: 0,
            },
        };
    }
    createDefaultContext(providerName) {
        return {
            providerName,
            currentModel: 'unknown',
            toolFormat: 'unknown',
            isPaidMode: false,
            capabilities: {
                supportsStreaming: true,
                supportsTools: false,
                supportsVision: false,
                maxTokens: 4096,
                supportedFormats: [],
            },
            sessionStartTime: Date.now(),
        };
    }
}
export class ProviderCapabilityEvent {
    'event.name';
    'event.timestamp';
    provider_name;
    capabilities;
    context;
    constructor(provider_name, capabilities, context) {
        this['event.name'] = 'provider_capability';
        this['event.timestamp'] = new Date().toISOString();
        this.provider_name = provider_name;
        this.capabilities = capabilities;
        this.context = context;
    }
}
export class KittySequenceOverflowEvent {
    'event.name';
    'event.timestamp';
    sequence_length;
    sequence;
    constructor(sequence_length, sequence) {
        this['event.name'] = 'kitty_sequence_overflow';
        this['event.timestamp'] = new Date().toISOString();
        this.sequence_length = sequence_length;
        this.sequence = sequence;
    }
}
// TokenUsageEvent for tracking token usage
export class TokenUsageEvent {
    'event.name';
    'event.timestamp';
    provider;
    conversationId;
    input;
    output;
    cache;
    tool;
    thought;
    total;
    constructor(provider, conversationId, input, output, cache, tool, thought, total) {
        this['event.name'] = 'token_usage';
        this['event.timestamp'] = new Date().toISOString();
        this.provider = provider;
        this.conversationId = conversationId;
        this.input = input;
        this.output = output;
        this.cache = cache;
        this.tool = tool;
        this.thought = thought;
        this.total = total;
    }
}
// PerformanceMetricsEvent for tracking performance metrics
export class PerformanceMetricsEvent {
    'event.name';
    'event.timestamp';
    provider;
    tokensPerMinute;
    throttleWaitTimeMs;
    totalRequests;
    errorRate;
    constructor(provider, tokensPerMinute, throttleWaitTimeMs, totalRequests, errorRate) {
        this['event.name'] = 'performance_metrics';
        this['event.timestamp'] = new Date().toISOString();
        this.provider = provider;
        this.tokensPerMinute = tokensPerMinute;
        this.throttleWaitTimeMs = throttleWaitTimeMs;
        this.totalRequests = totalRequests;
        this.errorRate = errorRate;
    }
}
// IDE connection telemetry types for compatibility
export var IdeConnectionType;
(function (IdeConnectionType) {
    IdeConnectionType["EXTENSION"] = "extension";
    IdeConnectionType["CLI"] = "cli";
    IdeConnectionType["WEB"] = "web";
})(IdeConnectionType || (IdeConnectionType = {}));
export class IdeConnectionEvent {
    'event.name';
    'event.timestamp';
    connectionType;
    version;
    constructor(connectionType, version) {
        this['event.name'] = 'ide_connection';
        this['event.timestamp'] = new Date().toISOString();
        this.connectionType = connectionType;
        this.version = version;
    }
}
export var FileOperation;
(function (FileOperation) {
    FileOperation["CREATE"] = "create";
    FileOperation["READ"] = "read";
    FileOperation["UPDATE"] = "update";
})(FileOperation || (FileOperation = {}));
export class ToolOutputTruncatedEvent {
    eventName;
    prompt_id;
    tool_name;
    original_content_length;
    truncated_content_length;
    threshold;
    lines;
    constructor(promptId, params) {
        this.eventName = 'tool_output_truncated';
        this.prompt_id = promptId;
        this.tool_name = params.toolName;
        this.original_content_length = params.originalContentLength;
        this.truncated_content_length = params.truncatedContentLength;
        this.threshold = params.threshold;
        this.lines = params.lines;
    }
}
export class FileOperationEvent {
    tool_name;
    operation;
    lines;
    mimetype;
    extension;
    programming_language;
    constructor(toolName, operation, lines, mimetype, extension, programmingLanguage) {
        this.tool_name = toolName;
        this.operation = operation;
        this.lines = lines;
        this.mimetype = mimetype;
        this.extension = extension;
        this.programming_language = programmingLanguage;
    }
}
export class ModelRoutingEvent {
    model;
    source;
    contextLimit;
    reason;
    fallback;
    error;
    constructor(model, source, contextLimit, reason, fallback = false, error) {
        this.model = model;
        this.source = source;
        this.contextLimit = contextLimit;
        this.reason = reason;
        this.fallback = fallback;
        this.error = error;
    }
}
export class ExtensionInstallEvent {
    extension_name;
    extension_version;
    extension_source;
    status;
    constructor(name, version, source, status) {
        this.extension_name = name;
        this.extension_version = version;
        this.extension_source = source;
        this.status = status;
    }
}
export class ExtensionUninstallEvent {
    extension_name;
    status;
    constructor(name, status) {
        this.extension_name = name;
        this.status = status;
    }
}
export class ExtensionEnableEvent {
    extension_name;
    setting_scope;
    constructor(name, scope) {
        this.extension_name = name;
        this.setting_scope = scope;
    }
}
export class ExtensionDisableEvent {
    extension_name;
    setting_scope;
    constructor(name, scope) {
        this.extension_name = name;
        this.setting_scope = scope;
    }
}
//# sourceMappingURL=types.js.map