import { AgentExecuteCodeMode } from '../../contracts/agent-execute-code.js';
import { TOOLS_BY_MODE_NAMES } from '../host-tools/mode-host-tools.js';
import { buildShortcutXLApiReferenceSection } from './api-reference.js';
import { ACTION_EXECUTION_PROMPT, buildActionModeMainSection } from './modes/action.js';
import { buildAskModeMainSection } from './modes/ask.js';
import { buildManageModeMainSection } from './modes/manage.js';
import { buildPlanModeMainSection } from './modes/plan.js';
import { buildReviewModeMainSection } from './modes/review.js';
import { buildShortyModeMainSection } from './modes/shorty.js';
import { AGENT_PHILOSOPHY_SECTION, API_HIERARCHY_SECTION, CLOUD_WORKFLOWS, COMMUNICATION_SECTION, DATA_EXPLORATION_READ_ONLY_SECTION, DATA_FORMATTING_SECTION, MARKDOWN_PROGRESS_SECTION, SANDBOX_FILESYSTEM, buildShortcutXLPerUserSection, getPlatformIdentity } from './sections.js';
export { AgentExecuteCodeMode as ShortcutXLPromptMode };
function assertNeverMode(value) {
    throw new Error(`Unhandled ShortcutXL prompt mode: ${String(value)}`);
}
function buildApiReference(mode, platform) {
    return buildShortcutXLApiReferenceSection({
        apiSpec: platform.getApiSpec(),
        clientSpecificPrompt: platform.getClientSpecificPrompt(),
        mode,
        platformName: platform.name
    });
}
function buildModeSections(mode, platform) {
    const currentDate = new Date().toISOString().slice(0, 10);
    const platformIdentity = getPlatformIdentity(platform.name);
    const apiReference = buildApiReference(mode, platform);
    switch (mode) {
        case AgentExecuteCodeMode.Action:
            return [
                buildActionModeMainSection(platformIdentity, currentDate),
                AGENT_PHILOSOPHY_SECTION,
                COMMUNICATION_SECTION,
                CLOUD_WORKFLOWS,
                SANDBOX_FILESYSTEM,
                MARKDOWN_PROGRESS_SECTION,
                DATA_FORMATTING_SECTION,
                ACTION_EXECUTION_PROMPT,
                API_HIERARCHY_SECTION,
                apiReference
            ];
        case AgentExecuteCodeMode.Ask:
            return [
                buildAskModeMainSection(platformIdentity, currentDate),
                COMMUNICATION_SECTION,
                SANDBOX_FILESYSTEM,
                DATA_EXPLORATION_READ_ONLY_SECTION,
                API_HIERARCHY_SECTION,
                apiReference
            ];
        case AgentExecuteCodeMode.Plan:
            return [
                buildPlanModeMainSection(currentDate),
                SANDBOX_FILESYSTEM,
                DATA_EXPLORATION_READ_ONLY_SECTION,
                API_HIERARCHY_SECTION,
                apiReference
            ];
        case AgentExecuteCodeMode.Manage:
            return [buildManageModeMainSection(currentDate)];
        case AgentExecuteCodeMode.Shorty:
            return [
                buildShortyModeMainSection(platformIdentity, currentDate),
                COMMUNICATION_SECTION,
                SANDBOX_FILESYSTEM,
                DATA_EXPLORATION_READ_ONLY_SECTION,
                API_HIERARCHY_SECTION,
                apiReference
            ];
        case AgentExecuteCodeMode.Review:
            return [buildReviewModeMainSection(currentDate)];
    }
    return assertNeverMode(mode);
}
/** Assemble the full system prompt for the given platform and mode. */
export function buildShortcutXLAgentSystemPrompt(platform, mode = AgentExecuteCodeMode.Action) {
    const perUserSection = buildShortcutXLPerUserSection({
        aiRules: platform.getAiRules?.(),
        memoryPrompt: platform.getMemoryPrompt?.(),
        skillsPrompt: platform.getSkillsPrompt?.(),
        activeConnections: platform.getActiveConnections?.()
    });
    const sections = [...buildModeSections(mode, platform), perUserSection].filter((section) => section.length > 0);
    // Trim trailing newlines so the join separator is exactly `\n\n`,
    // then append a single trailing newline (backend's prompt ends with `\n`).
    return sections.map((section) => section.replace(/\n+$/, '')).join('\n\n') + '\n';
}
/** Default `AgentConfiguration` for a ShortcutXL session (prompt + tools). */
export function createShortcutXLAgentConfiguration(platform, options = {}) {
    const mode = options.mode ?? AgentExecuteCodeMode.Action;
    return {
        systemPrompt: options.systemPrompt ?? buildShortcutXLAgentSystemPrompt(platform, mode),
        toolNames: [...TOOLS_BY_MODE_NAMES[mode]],
        agentMode: mode
    };
}
//# sourceMappingURL=build.js.map