/**
 * @license
 * Copyright 2026 HopCode Team Team
 * SPDX-License-Identifier: Apache-2.0
 */
import { AuthType } from '@hoptrendy/hopcode-core';
import { z } from 'zod';
/**
 * ACP model IDs are represented as `${modelId}(${authType})` in the ACP protocol.
 *
 * NOTE: The VSCode webview side mirrors this encoding contract in
 * `packages/vscode-ide-companion/src/webview/utils/discontinuedModel.ts` to
 * detect discontinued Qwen OAuth registry models without changing the wire
 * format. If the encoding here evolves (new authTypes, runtime prefix changes,
 * etc.), update that file too.
 */
export function formatAcpModelId(modelId, authType) {
    return `${modelId}(${authType})`;
}
/**
 * Extracts the base model id from an ACP model id string.
 *
 * If the string ends with `(...)`, the suffix is removed; otherwise returns the
 * trimmed input as-is.
 */
export function parseAcpBaseModelId(value) {
    const trimmed = value.trim();
    const closeIdx = trimmed.lastIndexOf(')');
    const openIdx = trimmed.lastIndexOf('(');
    if (openIdx >= 0 && closeIdx === trimmed.length - 1 && openIdx < closeIdx) {
        return trimmed.slice(0, openIdx);
    }
    return trimmed;
}
/**
 * Parses an ACP model option string into `{ modelId, authType? }`.
 *
 * Supports the following formats:
 * - `${modelId}(${authType})` - Standard registry model (e.g., "gpt-4(USE_OPENAI)")
 * - `${snapshotId}(${authType})` - Runtime model snapshot (e.g., "$runtime|USE_OPENAI|gpt-4(USE_OPENAI)")
 *   where snapshotId is in format `$runtime|${authType}|${modelId}`
 * - Plain model ID - Returns as-is with no authType
 *
 * If the string ends with `(...)` and `...` is a valid `AuthType`, returns both;
 * otherwise returns the trimmed input as `modelId` only.
 */
export function parseAcpModelOption(input) {
    const trimmed = input.trim();
    const closeIdx = trimmed.lastIndexOf(')');
    const openIdx = trimmed.lastIndexOf('(');
    if (openIdx >= 0 && closeIdx === trimmed.length - 1 && openIdx < closeIdx) {
        const maybeModelId = trimmed.slice(0, openIdx);
        const maybeAuthType = trimmed.slice(openIdx + 1, closeIdx);
        const parsedAuthType = z.nativeEnum(AuthType).safeParse(maybeAuthType);
        if (parsedAuthType.success) {
            return { modelId: maybeModelId, authType: parsedAuthType.data };
        }
    }
    return { modelId: trimmed };
}
//# sourceMappingURL=acpModelUtils.js.map