// SPEC-597-EXEMPT: canonical mapping (npm-package↔framework, keyword catalogue)
// — must enumerate framework names by design; no detection logic to migrate.
// tools/deploy/deploy-spec.ts — SPEC-478
import { getDeployConfig, recordDeployment } from '../../storage/deploy-config-store.js';
import { deployToVercel } from '../../engine/deploy/providers/vercel.js';
import { trackCost } from '../../engine/cost-tracking/operation-tracker.js';
export async function handleDeploySpec(input) {
    return trackCost(input.projectPath, 'deploy_spec', async () => {
        try {
            const config = await getDeployConfig(input.projectPath, input.provider);
            if (!config) {
                return {
                    content: [
                        {
                            type: 'text',
                            text: `No deploy config for ${input.provider}. Run configure_deploy_target first with your token.`,
                        },
                    ],
                    isError: true,
                };
            }
            if (input.provider !== 'vercel') {
                return {
                    content: [
                        {
                            type: 'text',
                            text: `Provider ${input.provider} not yet implemented. Only 'vercel' is supported in v1.38.`,
                        },
                    ],
                    isError: true,
                };
            }
            const deployment = await deployToVercel(config, {
                environment: input.environment,
            });
            await recordDeployment(input.projectPath, deployment);
            const summary = deployment.status === 'error'
                ? `Deployment failed: ${deployment.errorMessage ?? 'unknown error'}`
                : `Deployment ${deployment.status}: ${deployment.url ?? deployment.id}`;
            return {
                content: [{ type: 'text', text: summary }],
                structuredContent: deployment,
                isError: deployment.status === 'error',
            };
        }
        catch (err) {
            return {
                content: [
                    {
                        type: 'text',
                        text: `Deploy failed: ${err instanceof Error ? err.message : String(err)}`,
                    },
                ],
                isError: true,
            };
        }
    }); // end trackCost
}
//# sourceMappingURL=deploy-spec.js.map