'use server';
import { resolve } from '../../lib/server-container.js';
import { revalidatePath } from 'next/cache';
import { requireFeatureFlag } from '../../lib/feature-flags.js';
export async function createCustomAgent(input) {
    try {
        requireFeatureFlag('collaboration');
        const useCase = resolve('CreateCustomAgentUseCase');
        const seedPrompt = input.initialPromptId?.trim() && input.initialPromptBody?.length
            ? { promptId: input.initialPromptId.trim(), body: input.initialPromptBody }
            : undefined;
        const result = await useCase.execute({
            agentType: input.agentType,
            name: input.name,
            description: input.description,
            ...(seedPrompt !== undefined && { initialPrompt: seedPrompt }),
        });
        revalidatePath('/agents');
        revalidatePath(`/agents/${result.agent.agentType}`);
        return { ok: true, agentType: result.agent.agentType };
    }
    catch (error) {
        return {
            ok: false,
            error: error instanceof Error ? error.message : 'Failed to create agent',
        };
    }
}
export async function deleteCustomAgent(input) {
    try {
        requireFeatureFlag('collaboration');
        const useCase = resolve('DeleteCustomAgentUseCase');
        await useCase.execute(input);
        revalidatePath('/agents');
        return { ok: true };
    }
    catch (error) {
        return {
            ok: false,
            error: error instanceof Error ? error.message : 'Failed to delete agent',
        };
    }
}
