"use strict";
// SPDX-License-Identifier: AGPL-3.0-or-later
// Copyright (C) 2024-2026 Gracker (Chris)
// This file is part of SmartPerfetto. See LICENSE for details.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.runConfigInitCommand = runConfigInitCommand;
const fs = __importStar(require("fs"));
const path = __importStar(require("path"));
const bootstrap_1 = require("../bootstrap");
const ENV_TEMPLATE = `# SmartPerfetto CLI user environment
# This file is loaded after backend/.env when no --env-file is passed.
#
# First setup: choose ONE provider path. Do not enable Claude-compatible and
# OpenAI-compatible blocks together.

# Default runtime keeps Claude Agent SDK behavior. Claude local login fallback
# is valid when no explicit Anthropic/Bedrock/Vertex credentials are set.
# Leave model envs unset to use SmartPerfetto defaults, or set provider-specific
# model names when your provider requires them.
# SMARTPERFETTO_AGENT_RUNTIME=claude-agent-sdk
# CLAUDE_MODEL=
# CLAUDE_LIGHT_MODEL=
# ANTHROPIC_API_KEY=
# ANTHROPIC_BASE_URL=
# ANTHROPIC_AUTH_TOKEN=

# OpenAI / OpenAI-compatible runtime.
# SMARTPERFETTO_AGENT_RUNTIME=openai-agents-sdk
# OPENAI_API_KEY=
# OPENAI_BASE_URL=https://api.openai.com/v1
# OPENAI_MODEL=
# OPENAI_LIGHT_MODEL=
# OPENAI_AGENTS_PROTOCOL=responses

# Ollama / local OpenAI-compatible endpoint example.
# SMARTPERFETTO_AGENT_RUNTIME=openai-agents-sdk
# OPENAI_BASE_URL=http://localhost:11434/v1
# OPENAI_API_KEY=ollama
# OPENAI_MODEL=qwen3:8b
# OPENAI_AGENTS_PROTOCOL=chat_completions

# Output language for AI analysis.
# SMARTPERFETTO_OUTPUT_LANGUAGE=zh-CN
`;
async function runConfigInitCommand(args) {
    const { paths } = (0, bootstrap_1.bootstrap)({ envFile: args.envFile, sessionDir: args.sessionDir, requireLlm: false });
    const envPath = path.join(paths.home, 'env');
    const format = args.format ?? 'text';
    if (fs.existsSync(envPath) && !args.force) {
        writeOutput(format, {
            ok: false,
            path: envPath,
            error: 'config already exists; pass --force to overwrite',
        });
        return 1;
    }
    fs.mkdirSync(paths.home, { recursive: true });
    fs.writeFileSync(envPath, ENV_TEMPLATE, { encoding: 'utf-8', mode: 0o600 });
    writeOutput(format, {
        ok: true,
        path: envPath,
        overwritten: args.force,
    });
    return 0;
}
function writeOutput(format, payload) {
    if (format === 'json' || format === 'ndjson') {
        console.log(JSON.stringify(payload, null, format === 'json' ? 2 : 0));
        return;
    }
    if (payload.ok) {
        console.log(`Created SmartPerfetto CLI config: ${payload.path}`);
    }
    else {
        console.error(`Error: ${payload.error}`);
        console.error(`Path: ${payload.path}`);
    }
}
//# sourceMappingURL=config.js.map