"use strict";
/**
 * Type definitions and interfaces for CLI tools
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.OLLAMA_MODEL_PATTERN = exports.VIBE_LOCAL_CONTEXT_WINDOW_MAX = exports.VIBE_LOCAL_CONTEXT_WINDOW_MIN = exports.CLI_TOOL_DISPLAY_NAMES = exports.CLI_TOOL_IDS = void 0;
exports.isCliToolType = isCliToolType;
exports.getCliToolDisplayName = getCliToolDisplayName;
exports.getCliToolDisplayNameSafe = getCliToolDisplayNameSafe;
exports.isValidVibeLocalContextWindow = isValidVibeLocalContextWindow;
exports.isImageCapableCLITool = isImageCapableCLITool;
/**
 * CLI Tool IDs constant array
 * T2.1: Single source of truth for CLI tool IDs
 * CLIToolType is derived from this constant (DRY principle)
 */
exports.CLI_TOOL_IDS = ['claude', 'codex', 'gemini', 'vibe-local', 'opencode'];
/**
 * CLI tool display names for UI rendering
 * Issue #368: Centralized display name mapping
 *
 * Usage: UI display (tab headers, message lists, settings).
 * For internal logs/debug, use tool.name (BaseCLITool.name) instead.
 */
exports.CLI_TOOL_DISPLAY_NAMES = {
    claude: 'Claude',
    codex: 'Codex',
    gemini: 'Gemini',
    'vibe-local': 'Vibe Local',
    opencode: 'OpenCode',
};
/**
 * Check if a string is a valid CLIToolType
 * Issue #368: Type guard for safe casting of untrusted CLI tool ID strings
 *
 * @param value - String to check
 * @returns True if value is a valid CLIToolType
 */
function isCliToolType(value) {
    return exports.CLI_TOOL_IDS.includes(value);
}
/**
 * Get the display name for a CLI tool ID
 * Issue #368: Centralized display name function for DRY compliance
 *
 * @param id - CLI tool type identifier
 * @returns Human-readable display name
 */
function getCliToolDisplayName(id) {
    return exports.CLI_TOOL_DISPLAY_NAMES[id] ?? id;
}
/**
 * Get the display name for a CLI tool ID string, with fallback for unknown IDs
 * Issue #368: Safe wrapper for UI components receiving untyped cliToolId strings
 *
 * Unlike getCliToolDisplayName(), this accepts optional/untyped strings and
 * returns a fallback value ('Assistant') for null, undefined, or unknown IDs.
 *
 * @param cliToolId - Optional CLI tool ID string (may be untyped)
 * @param fallback - Fallback display name for missing/unknown IDs (default: 'Assistant')
 * @returns Human-readable display name or fallback
 */
function getCliToolDisplayNameSafe(cliToolId, fallback = 'Assistant') {
    if (!cliToolId)
        return fallback;
    if (isCliToolType(cliToolId))
        return getCliToolDisplayName(cliToolId);
    return fallback;
}
/**
 * Minimum context window size for vibe-local.
 * [S1-007] Lower bound rationale: Ollama's actual minimum context window is
 * typically 2048+, but 128 is set as a permissive lower bound to accommodate
 * custom models or future models with smaller contexts. Users are recommended
 * to use practical values (e.g., 2048+).
 * [S1-004] vibe-local specific constant. If more vibe-local constants are added,
 * consider extracting to src/lib/cli-tools/vibe-local-config.ts.
 * [SEC-002] Used to prevent unreasonable values in CLI arguments.
 */
exports.VIBE_LOCAL_CONTEXT_WINDOW_MIN = 128;
/**
 * Maximum context window size for vibe-local (2M tokens).
 * Shared between API validation and defense-in-depth (DRY principle).
 * [S1-004] vibe-local specific constant. If more vibe-local constants are added,
 * consider extracting to src/lib/cli-tools/vibe-local-config.ts.
 * [SEC-002] Used to prevent unreasonable values in CLI arguments.
 */
exports.VIBE_LOCAL_CONTEXT_WINDOW_MAX = 2097152;
/**
 * Validate vibe-local context window value.
 * Shared between API layer and CLI layer (defense-in-depth).
 * [S1-001] DRY: Single source of truth for context window validation.
 *
 * @param value - Value to validate (accepts unknown for type guard usage)
 * @returns True if value is a valid context window size (integer between MIN and MAX)
 */
function isValidVibeLocalContextWindow(value) {
    return (typeof value === 'number' &&
        Number.isInteger(value) &&
        value >= exports.VIBE_LOCAL_CONTEXT_WINDOW_MIN &&
        value <= exports.VIBE_LOCAL_CONTEXT_WINDOW_MAX);
}
/**
 * Ollama model name validation pattern (API/DB layer).
 * Requires alphanumeric first character, followed by alphanumeric, dots, underscores,
 * colons, slashes, hyphens. No explicit length limit (DB schema handles storage limits).
 *
 * [SEC-001] Shared between API route validation and CLI command construction.
 *
 * Note: opencode-config.ts has a separate OLLAMA_MODEL_PATTERN with a 100-character
 * length limit (`{1,100}`) for DoS protection when parsing Ollama API responses.
 * The patterns are intentionally different: this one enforces first-character constraints
 * for user-facing validation, while the opencode-config version adds length limits
 * for untrusted external API data.
 */
exports.OLLAMA_MODEL_PATTERN = /^[a-zA-Z0-9][a-zA-Z0-9._:/-]*$/;
/**
 * Type guard to check if a CLI tool supports image sending
 * Issue #474: Used by send/route.ts to determine sending strategy
 *
 * @param tool - CLI tool instance to check
 * @returns True if the tool implements IImageCapableCLITool
 */
function isImageCapableCLITool(tool) {
    const candidate = tool;
    return typeof candidate.supportsImage === 'function'
        && candidate.supportsImage() === true;
}
