/**
 * Proxy Self-Serve Onboarding (W4.4 of F-NEW-PRODUCT-AGENT-VISIBILITY-CLUSTER-2026-05-12).
 *
 * Generates the customer-side onboarding payload for the already-shipped
 * F-NEW-PRODUCT-PROXY-TIER Mode A v1 (PRs #696-#715, all 8 LLM providers).
 * Customer signs up, picks a provider, gets a copy-paste snippet that swaps
 * one URL/header to start routing through governed.my-cc.io. Zero infra.
 *
 * Honors the existing Mode A invariants:
 *   - Customer's LLM API key flows per-request via X-LLM-API-Key
 *   - Keys never persist on our side
 *   - Pass-through if our proxy degrades (Invariant 2)
 *
 * @connexum/ai-governance  F-NEW-PRODUCT-PROXY-SELFSERVE-ONBOARDING
 */
const DEFAULT_PROXY_HOST = 'proxy.my-cc.io';
function providerLabel(p) {
    return p
        .split('-')
        .map((w) => w.charAt(0).toUpperCase() + w.slice(1))
        .join(' ');
}
function snippetFor(provider, language, proxyBaseUrl, tenantId) {
    if (language === 'typescript') {
        switch (provider) {
            case 'anthropic':
                return tsAnthropic(proxyBaseUrl, tenantId);
            case 'openai':
                return tsOpenai(proxyBaseUrl, tenantId);
            case 'azure-openai':
                return tsAzureOpenai(proxyBaseUrl, tenantId);
            case 'bedrock':
                return tsBedrock(proxyBaseUrl, tenantId);
            case 'gemini-aistudio':
                return tsGeminiAistudio(proxyBaseUrl, tenantId);
            case 'gemini-vertex':
                return tsGeminiVertex(proxyBaseUrl, tenantId);
            case 'deepseek':
                return tsDeepseek(proxyBaseUrl, tenantId);
            case 'replicate':
                return tsReplicate(proxyBaseUrl, tenantId);
            case 'huggingface':
                return tsHuggingface(proxyBaseUrl, tenantId);
        }
    }
    // python
    switch (provider) {
        case 'anthropic':
            return pyAnthropic(proxyBaseUrl, tenantId);
        case 'openai':
            return pyOpenai(proxyBaseUrl, tenantId);
        case 'azure-openai':
            return pyAzureOpenai(proxyBaseUrl, tenantId);
        case 'bedrock':
            return pyBedrock(proxyBaseUrl, tenantId);
        case 'gemini-aistudio':
            return pyGeminiAistudio(proxyBaseUrl, tenantId);
        case 'gemini-vertex':
            return pyGeminiVertex(proxyBaseUrl, tenantId);
        case 'deepseek':
            return pyDeepseek(proxyBaseUrl, tenantId);
        case 'replicate':
            return pyReplicate(proxyBaseUrl, tenantId);
        case 'huggingface':
            return pyHuggingface(proxyBaseUrl, tenantId);
    }
}
function tsAnthropic(host, tenant) {
    return `import Anthropic from '@anthropic-ai/sdk';

const client = new Anthropic({
  apiKey: 'governed-by-my-cc',                       // placeholder; real key in header
  baseURL: '${host}/anthropic',
  defaultHeaders: {
    'X-LLM-API-Key': process.env.ANTHROPIC_API_KEY!,
    'X-Connexum-Tenant': '${tenant}',
  },
});
// Use client.messages.create(...) as usual.`;
}
function tsOpenai(host, tenant) {
    return `import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'governed-by-my-cc',
  baseURL: '${host}/openai/v1',
  defaultHeaders: {
    'X-LLM-API-Key': process.env.OPENAI_API_KEY!,
    'X-Connexum-Tenant': '${tenant}',
  },
});`;
}
function tsAzureOpenai(host, tenant) {
    return `import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'governed-by-my-cc',
  baseURL: '${host}/azure-openai',
  defaultHeaders: {
    'X-LLM-API-Key': process.env.AZURE_OPENAI_KEY!,
    'X-Azure-Resource': process.env.AZURE_RESOURCE_NAME!,
    'X-Connexum-Tenant': '${tenant}',
  },
});`;
}
function tsBedrock(host, tenant) {
    return `// AWS Bedrock — keep your SigV4 creds local; we route via proxy:
const client = new BedrockRuntimeClient({
  endpoint: '${host}/bedrock',
  credentials: { /* your local SigV4 creds */ },
  customUserAgent: 'x-connexum-tenant/${tenant}',
});`;
}
function tsGeminiAistudio(host, tenant) {
    return `import { GoogleGenerativeAI } from '@google/generative-ai';

const proxy = '${host}/gemini-aistudio';
// Use fetch directly or wrap the SDK with baseUrl=proxy + headers:
//   X-LLM-API-Key: <your GEMINI_API_KEY>
//   X-Connexum-Tenant: ${tenant}`;
}
function tsGeminiVertex(host, tenant) {
    return `// Gemini Vertex AI via proxy:
const url = '${host}/gemini-vertex/v1/projects/<project>/locations/<region>/publishers/google/models/<model>:generateContent';
// Headers:
//   X-LLM-API-Key: <Vertex access token>
//   X-Connexum-Tenant: ${tenant}`;
}
function tsDeepseek(host, tenant) {
    return `import OpenAI from 'openai';

const client = new OpenAI({
  apiKey: 'governed-by-my-cc',
  baseURL: '${host}/deepseek/v1',
  defaultHeaders: {
    'X-LLM-API-Key': process.env.DEEPSEEK_API_KEY!,
    'X-Connexum-Tenant': '${tenant}',
  },
});`;
}
function tsReplicate(host, tenant) {
    return `import Replicate from 'replicate';

const client = new Replicate({
  auth: 'governed-by-my-cc',
  baseUrl: '${host}/replicate',
  // headers via fetch override:
  //   Authorization: Token <REPLICATE_API_TOKEN>   -> we extract to X-LLM-API-Key
  //   X-Connexum-Tenant: ${tenant}
});`;
}
function tsHuggingface(host, tenant) {
    return `// Hugging Face Inference API via proxy:
const url = '${host}/huggingface/v1/chat/completions';
// Headers:
//   Authorization: Bearer <HF_TOKEN>   -> we extract to X-LLM-API-Key
//   X-Connexum-Tenant: ${tenant}`;
}
function pyAnthropic(host, tenant) {
    return `from anthropic import Anthropic

client = Anthropic(
    api_key="governed-by-my-cc",
    base_url="${host}/anthropic",
    default_headers={
        "X-LLM-API-Key": os.environ["ANTHROPIC_API_KEY"],
        "X-Connexum-Tenant": "${tenant}",
    },
)`;
}
function pyOpenai(host, tenant) {
    return `from openai import OpenAI

client = OpenAI(
    api_key="governed-by-my-cc",
    base_url="${host}/openai/v1",
    default_headers={
        "X-LLM-API-Key": os.environ["OPENAI_API_KEY"],
        "X-Connexum-Tenant": "${tenant}",
    },
)`;
}
function pyAzureOpenai(host, tenant) {
    return `from openai import OpenAI

client = OpenAI(
    api_key="governed-by-my-cc",
    base_url="${host}/azure-openai",
    default_headers={
        "X-LLM-API-Key": os.environ["AZURE_OPENAI_KEY"],
        "X-Azure-Resource": os.environ["AZURE_RESOURCE_NAME"],
        "X-Connexum-Tenant": "${tenant}",
    },
)`;
}
function pyBedrock(host, tenant) {
    return `# Bedrock via proxy — keep SigV4 local:
import boto3
client = boto3.client(
    "bedrock-runtime",
    endpoint_url="${host}/bedrock",
)
# Headers via botocore event-handler: X-Connexum-Tenant: ${tenant}`;
}
function pyGeminiAistudio(host, tenant) {
    return `# Gemini AI Studio via proxy:
url = "${host}/gemini-aistudio"
# Headers:
#   X-LLM-API-Key: <GEMINI_API_KEY>
#   X-Connexum-Tenant: ${tenant}`;
}
function pyGeminiVertex(host, tenant) {
    return `# Gemini Vertex AI via proxy:
url = "${host}/gemini-vertex/v1/projects/<project>/locations/<region>/publishers/google/models/<model>:generateContent"
# Headers:
#   X-LLM-API-Key: <Vertex access token>
#   X-Connexum-Tenant: ${tenant}`;
}
function pyDeepseek(host, tenant) {
    return `from openai import OpenAI

client = OpenAI(
    api_key="governed-by-my-cc",
    base_url="${host}/deepseek/v1",
    default_headers={
        "X-LLM-API-Key": os.environ["DEEPSEEK_API_KEY"],
        "X-Connexum-Tenant": "${tenant}",
    },
)`;
}
function pyReplicate(host, tenant) {
    return `import replicate

# Set base_url + extract Token to X-LLM-API-Key in your http client:
client = replicate.Client(api_token="governed-by-my-cc")
client.base_url = "${host}/replicate"
# Headers via session.headers:
#   Authorization: Token <REPLICATE_API_TOKEN>
#   X-Connexum-Tenant: ${tenant}`;
}
function pyHuggingface(host, tenant) {
    return `# Hugging Face Inference API via proxy:
url = "${host}/huggingface/v1/chat/completions"
# Headers:
#   Authorization: Bearer <HF_TOKEN>
#   X-Connexum-Tenant: ${tenant}`;
}
function envVarsFor(provider) {
    switch (provider) {
        case 'anthropic':
            return { ANTHROPIC_API_KEY: 'your Anthropic key — never sent to our backend' };
        case 'openai':
            return { OPENAI_API_KEY: 'your OpenAI key — never sent to our backend' };
        case 'azure-openai':
            return {
                AZURE_OPENAI_KEY: 'your Azure OpenAI key',
                AZURE_RESOURCE_NAME: 'your Azure OpenAI resource name',
            };
        case 'bedrock':
            return { AWS_ACCESS_KEY_ID: 'your AWS access key', AWS_SECRET_ACCESS_KEY: 'your AWS secret', AWS_REGION: 'us-east-1' };
        case 'gemini-aistudio':
            return { GEMINI_API_KEY: 'your Gemini AI Studio key' };
        case 'gemini-vertex':
            return { GOOGLE_APPLICATION_CREDENTIALS: 'path to your Vertex SA key' };
        case 'deepseek':
            return { DEEPSEEK_API_KEY: 'your DeepSeek key' };
        case 'replicate':
            return { REPLICATE_API_TOKEN: 'your Replicate token' };
        case 'huggingface':
            return { HF_TOKEN: 'your Hugging Face token' };
    }
}
export function buildProxyOnboardingPayload(input) {
    if (!input.tenantId || input.tenantId.trim() === '') {
        throw new Error('buildProxyOnboardingPayload: tenantId is required');
    }
    const language = input.language ?? 'typescript';
    const proxyHost = input.proxyHost ?? DEFAULT_PROXY_HOST;
    const proxyBaseUrl = `https://${proxyHost}`;
    return {
        tenantId: input.tenantId,
        provider: input.provider,
        language,
        proxyBaseUrl,
        apiKeyHeader: 'X-LLM-API-Key',
        envVars: envVarsFor(input.provider),
        snippet: snippetFor(input.provider, language, proxyBaseUrl, input.tenantId),
        firstEventEndpoint: `${proxyBaseUrl}/api/v1/onboarding/first-event?tenant=${encodeURIComponent(input.tenantId)}`,
    };
}
export const SUPPORTED_PROVIDERS = [
    'anthropic',
    'openai',
    'gemini-aistudio',
    'gemini-vertex',
    'bedrock',
    'azure-openai',
    'deepseek',
    'replicate',
    'huggingface',
].map((p) => ({ id: p, label: providerLabel(p) }));
//# sourceMappingURL=proxy-onboarding.js.map