import { DEFAULT_BASE_URL } from './agent';
const maskSecret = (secret) => {
    if (!secret)
        return 'Not configured';
    const safeString = String(secret);
    if (safeString.length <= 4)
        return '••••';
    return `••••${safeString.slice(-4)}`;
};
export const anthropicDefaultModelTemplate = {
    provider: 'anthropic',
    label: 'New Anthropic Model',
    model: 'claude-sonnet-4-20250514',
    description: 'A new Anthropic Claude Sonnet 4 configuration',
    baseUrl: DEFAULT_BASE_URL,
    connection: {
        apiKey: '',
        baseUrl: DEFAULT_BASE_URL
    },
    settings: {
        temperature: 0.7,
        maxTokens: 4000,
        topP: 1,
        topK: 0
    }
};
export const anthropicModelDefinition = {
    id: 'anthropic',
    displayName: 'Anthropic Claude',
    badgeClassName: 'bg-amber-100 text-amber-800',
    defaultModelTemplate: anthropicDefaultModelTemplate,
    viewFields: [
        {
            label: 'Model',
            render: (model) => model.model || 'Not set'
        },
        {
            label: 'API Key',
            render: (model) => maskSecret(model.connection?.apiKey)
        },
        {
            label: 'Base URL',
            render: (model) => model.baseUrl || model.connection?.baseUrl || DEFAULT_BASE_URL
        },
        {
            label: 'Temperature',
            render: (model) => model.settings?.temperature ?? 0.7
        },
        {
            label: 'Max Tokens',
            render: (model) => model.settings?.maxTokens ?? 4000
        },
        {
            label: 'Top P',
            render: (model) => model.settings?.topP ?? 1
        },
        {
            label: 'Top K',
            render: (model) => model.settings?.topK ?? 0
        }
    ],
    form: {
        schema: [
            ['label', {
                    type: 'string',
                    label: 'Model Name',
                    required: true,
                    description: 'Display name for this model configuration'
                }],
            ['model', {
                    type: 'string',
                    label: 'Anthropic Model',
                    enum: ['claude-sonnet-4-20250514'],
                    required: true,
                    description: 'Claude Sonnet 4 API identifier (claude-sonnet-4-20250514)'
                }],
            ['description', {
                    type: 'string',
                    label: 'Description',
                    description: 'Optional description for this model configuration'
                }],
            ['apiKey', {
                    type: 'string',
                    label: 'API Key',
                    required: true,
                    description: 'Your Anthropic API key'
                }],
            ['baseUrl', {
                    type: 'string',
                    label: 'Base URL',
                    description: 'Custom API base URL (optional)'
                }],
            ['temperature', {
                    type: 'number',
                    label: 'Temperature',
                    minimum: 0,
                    maximum: 1,
                    description: 'Sampling temperature (0-1)'
                }],
            ['maxTokens', {
                    type: 'integer',
                    label: 'Max Output Tokens',
                    minimum: 1,
                    maximum: 4096,
                    description: 'Maximum number of tokens to generate'
                }],
            ['topP', {
                    type: 'number',
                    label: 'Top P',
                    minimum: 0,
                    maximum: 1,
                    description: 'Nucleus sampling parameter'
                }],
            ['topK', {
                    type: 'number',
                    label: 'Top K',
                    minimum: 0,
                    maximum: 500,
                    description: 'Top-K sampling parameter'
                }]
        ],
        getInitialValues: (model) => ({
            label: model.label,
            model: model.model || 'claude-sonnet-4-20250514',
            description: model.description || '',
            apiKey: model.connection?.apiKey || '',
            baseUrl: model.baseUrl || model.connection?.baseUrl || DEFAULT_BASE_URL,
            temperature: model.settings?.temperature ?? 0.7,
            maxTokens: model.settings?.maxTokens ?? 4000,
            topP: model.settings?.topP ?? 1,
            topK: model.settings?.topK ?? 0
        }),
        transformSubmit: (values, existingModel) => {
            const connection = {
                apiKey: values.apiKey || ''
            };
            const baseUrl = values.baseUrl;
            const trimmedBaseUrl = typeof baseUrl === 'string' && baseUrl.trim() ? baseUrl.trim() : undefined;
            if (trimmedBaseUrl) {
                connection.baseUrl = trimmedBaseUrl;
            }
            return {
                provider: existingModel.provider,
                label: values.label,
                model: values.model,
                description: values.description || undefined,
                baseUrl: trimmedBaseUrl,
                connection,
                settings: {
                    temperature: Number(values.temperature ?? 0.7),
                    maxTokens: Number(values.maxTokens ?? 4000),
                    topP: Number(values.topP ?? 1),
                    topK: Number(values.topK ?? 0)
                }
            };
        },
        submitButtonText: 'Update Model'
    }
};
