"use strict";
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;
    };
})();
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.orchestrateAnalyzeReview = void 0;
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
const typia_1 = __importDefault(require("typia"));
const uuid_1 = require("uuid");
const assertSchemaModel_1 = require("../../context/assertSchemaModel");
const transformAnalyzeReviewHistories_1 = require("./histories/transformAnalyzeReviewHistories");
const orchestrateAnalyzeReview = (ctx, props) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b;
    const pointer = {
        value: null,
    };
    const { tokenUsage } = yield ctx.conversate({
        source: "analyzeReview",
        controller: createController({
            model: ctx.model,
            pointer,
        }),
        histories: [
            ...(0, transformAnalyzeReviewHistories_1.transformAnalyzeReviewHistories)(ctx, props.scenario, props.allFiles, props.myFile),
        ],
        enforceFunctionCall: true,
        promptCacheKey: props.promptCacheKey,
        message: "Review the requirement document",
    });
    if (pointer.value === null)
        throw new Error("Failed to extract review information.");
    const event = {
        type: "analyzeReview",
        id: (0, uuid_1.v7)(),
        file: props.myFile,
        plan: pointer.value.plan,
        review: pointer.value.review,
        content: pointer.value.content,
        tokenUsage,
        total: props.progress.total,
        completed: ++props.progress.completed,
        step: ((_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : -1) + 1,
        created_at: new Date().toISOString(),
    };
    ctx.dispatch(event);
    return event;
});
exports.orchestrateAnalyzeReview = orchestrateAnalyzeReview;
function createController(props) {
    (0, assertSchemaModel_1.assertSchemaModel)(props.model);
    const application = collection[props.model === "chatgpt" ? "chatgpt" : "claude"];
    return {
        protocol: "class",
        name: "Reviewer",
        application,
        execute: {
            review: (input) => {
                props.pointer.value = input;
            },
        },
    };
}
const claude = {
    model: "claude",
    options: {
        reference: true,
        separate: null
    },
    functions: [
        {
            name: "review",
            parameters: {
                description: " - The properties containing the document to enhance along with\nplan and review criteria for guidance\n\n------------------------------\n\nCurrent Type: {@link IAutoBeAnalyzeReviewApplication.IProps}",
                type: "object",
                properties: {
                    review: {
                        description: "Step 1 (CoT: Review Phase) - Enhancement Criteria\n\nThe enhancement criteria and guidelines that the agent must follow.\n\nThis includes:\n\n- Minimum document length requirements\n- Section completeness checks\n- Link validation rules\n- Mermaid syntax validation (especially parentheses in labels)\n- Content specificity requirements\n- EARS format compliance\n\nThe review criteria ensure that documentation is implementation-ready and\nremoves all ambiguity for backend developers.\n\nCritical review points:\n\n- DO: Use double quotes for ALL labels in Mermaid diagrams\n- DO NOT: Use spaces between brackets and quotes in Mermaid\n- DO: Make requirements specific and measurable in natural language\n- DO: Focus on business requirements and user scenarios\n- DO NOT: Accept documents containing database schemas or API specifications\n- DO: Describe business model and authentication requirements in natural language",
                        type: "string"
                    },
                    plan: {
                        description: "Step 2 (CoT: Plan Phase) - Original Document Plan\n\nThe document plan that was used to create the content.\n\nThis helps the reviewer understand:\n\n- What sections should be present\n- The intended structure and organization\n- The target audience and purpose\n- Expected level of detail\n\nThe enhancer uses this to ensure the improved content aligns with the\noriginal plan and covers all required topics comprehensively.",
                        type: "string"
                    },
                    content: {
                        description: "Step 3 (CoT: Content Phase) - Complete Document Content\n\nThe actual markdown document content that incorporates review feedback.\n\nThis field contains a COMPLETE MARKDOWN DOCUMENT that has already \nincorporated the review criteria and plan requirements.\n\nDO: Treat this as the final, production-ready document.\nDO NOT: Treat this as raw input to be reviewed.\n\nThis content represents:\n- A fully-formed markdown document (.md file)\n- The result of applying review criteria to the original plan\n- A production-ready document for immediate deployment\n- Complete business requirements ready for developers\n\nThe enhancer should treat this as the actual document content:\n\n- Length and completeness (minimum 2,000 characters, more for technical\n  docs)\n- All sections from the plan are fully written\n- No vague or abstract statements\n- Proper use of EARS format for requirements\n- Correct Mermaid diagram syntax (double quotes mandatory)\n- Appropriate level of detail for backend implementation\n- Proper document linking (descriptive text, not raw filenames)\n\nThe enhancer outputs the document itself:\n\n- If content is provided, it represents the actual document\n- The enhancer outputs the enhanced version AS the document itself\n- No meta-commentary or review feedback should be in the output\n- The output becomes the saved .md file directly\n\nExample of what this field contains:\n\"# Service Overview\\n## Vision\\nThe service provides...\" (actual document)\nNOT: \"This document should cover service overview...\" (review comment)",
                        type: "string"
                    }
                },
                required: [
                    "review",
                    "plan",
                    "content"
                ],
                additionalProperties: false,
                $defs: {}
            },
            description: "Enhances planning documentation to meet all quality standards and requirements.\n\nThis function receives a document and outputs an improved version directly.\nThe output IS the enhanced document itself, NOT review comments or feedback.\n\nThe enhancement process includes:\n- Expanding sections that are too brief\n- Converting vague statements to specific EARS format requirements\n- Fixing Mermaid diagram syntax errors\n- Adding missing business processes and workflows\n- Ensuring proper document structure and completeness\n\nDO: Output the actual document content that will be saved.\nDO NOT: Output review comments or analysis of the document.\n\nNote: Any text output becomes part of the final document.",
            validate: (() => { const _io0 = input => "string" === typeof input.review && "string" === typeof input.plan && "string" === typeof input.content; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.review || _report(_exceptionable, {
                    path: _path + ".review",
                    expected: "string",
                    value: input.review
                }), "string" === typeof input.plan || _report(_exceptionable, {
                    path: _path + ".plan",
                    expected: "string",
                    value: input.plan
                }), "string" === typeof input.content || _report(_exceptionable, {
                    path: _path + ".content",
                    expected: "string",
                    value: input.content
                })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => {
                if (false === __is(input)) {
                    errors = [];
                    _report = __typia_transform__validateReport._validateReport(errors);
                    ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeAnalyzeReviewApplication.IProps",
                        value: input
                    })) && _vo0(input, _path + "", true) || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeAnalyzeReviewApplication.IProps",
                        value: input
                    }))(input, "$input", true);
                    const success = 0 === errors.length;
                    return success ? {
                        success,
                        data: input
                    } : {
                        success,
                        errors,
                        data: input
                    };
                }
                return {
                    success: true,
                    data: input
                };
            }; })()
        }
    ]
};
const collection = {
    chatgpt: {
        model: "chatgpt",
        options: {
            reference: true,
            strict: false,
            separate: null
        },
        functions: [
            {
                name: "review",
                parameters: {
                    description: " - The properties containing the document to enhance along with\nplan and review criteria for guidance\n\n------------------------------\n\nCurrent Type: {@link IAutoBeAnalyzeReviewApplication.IProps}",
                    type: "object",
                    properties: {
                        review: {
                            description: "Step 1 (CoT: Review Phase) - Enhancement Criteria\n\nThe enhancement criteria and guidelines that the agent must follow.\n\nThis includes:\n\n- Minimum document length requirements\n- Section completeness checks\n- Link validation rules\n- Mermaid syntax validation (especially parentheses in labels)\n- Content specificity requirements\n- EARS format compliance\n\nThe review criteria ensure that documentation is implementation-ready and\nremoves all ambiguity for backend developers.\n\nCritical review points:\n\n- DO: Use double quotes for ALL labels in Mermaid diagrams\n- DO NOT: Use spaces between brackets and quotes in Mermaid\n- DO: Make requirements specific and measurable in natural language\n- DO: Focus on business requirements and user scenarios\n- DO NOT: Accept documents containing database schemas or API specifications\n- DO: Describe business model and authentication requirements in natural language",
                            type: "string"
                        },
                        plan: {
                            description: "Step 2 (CoT: Plan Phase) - Original Document Plan\n\nThe document plan that was used to create the content.\n\nThis helps the reviewer understand:\n\n- What sections should be present\n- The intended structure and organization\n- The target audience and purpose\n- Expected level of detail\n\nThe enhancer uses this to ensure the improved content aligns with the\noriginal plan and covers all required topics comprehensively.",
                            type: "string"
                        },
                        content: {
                            description: "Step 3 (CoT: Content Phase) - Complete Document Content\n\nThe actual markdown document content that incorporates review feedback.\n\nThis field contains a COMPLETE MARKDOWN DOCUMENT that has already \nincorporated the review criteria and plan requirements.\n\nDO: Treat this as the final, production-ready document.\nDO NOT: Treat this as raw input to be reviewed.\n\nThis content represents:\n- A fully-formed markdown document (.md file)\n- The result of applying review criteria to the original plan\n- A production-ready document for immediate deployment\n- Complete business requirements ready for developers\n\nThe enhancer should treat this as the actual document content:\n\n- Length and completeness (minimum 2,000 characters, more for technical\n  docs)\n- All sections from the plan are fully written\n- No vague or abstract statements\n- Proper use of EARS format for requirements\n- Correct Mermaid diagram syntax (double quotes mandatory)\n- Appropriate level of detail for backend implementation\n- Proper document linking (descriptive text, not raw filenames)\n\nThe enhancer outputs the document itself:\n\n- If content is provided, it represents the actual document\n- The enhancer outputs the enhanced version AS the document itself\n- No meta-commentary or review feedback should be in the output\n- The output becomes the saved .md file directly\n\nExample of what this field contains:\n\"# Service Overview\\n## Vision\\nThe service provides...\" (actual document)\nNOT: \"This document should cover service overview...\" (review comment)",
                            type: "string"
                        }
                    },
                    required: [
                        "review",
                        "plan",
                        "content"
                    ],
                    additionalProperties: false,
                    $defs: {}
                },
                description: "Enhances planning documentation to meet all quality standards and requirements.\n\nThis function receives a document and outputs an improved version directly.\nThe output IS the enhanced document itself, NOT review comments or feedback.\n\nThe enhancement process includes:\n- Expanding sections that are too brief\n- Converting vague statements to specific EARS format requirements\n- Fixing Mermaid diagram syntax errors\n- Adding missing business processes and workflows\n- Ensuring proper document structure and completeness\n\nDO: Output the actual document content that will be saved.\nDO NOT: Output review comments or analysis of the document.\n\nNote: Any text output becomes part of the final document.",
                validate: (() => { const _io0 = input => "string" === typeof input.review && "string" === typeof input.plan && "string" === typeof input.content; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.review || _report(_exceptionable, {
                        path: _path + ".review",
                        expected: "string",
                        value: input.review
                    }), "string" === typeof input.plan || _report(_exceptionable, {
                        path: _path + ".plan",
                        expected: "string",
                        value: input.plan
                    }), "string" === typeof input.content || _report(_exceptionable, {
                        path: _path + ".content",
                        expected: "string",
                        value: input.content
                    })].every(flag => flag); const __is = input => "object" === typeof input && null !== input && _io0(input); let errors; let _report; return input => {
                    if (false === __is(input)) {
                        errors = [];
                        _report = __typia_transform__validateReport._validateReport(errors);
                        ((input, _path, _exceptionable = true) => ("object" === typeof input && null !== input || _report(true, {
                            path: _path + "",
                            expected: "IAutoBeAnalyzeReviewApplication.IProps",
                            value: input
                        })) && _vo0(input, _path + "", true) || _report(true, {
                            path: _path + "",
                            expected: "IAutoBeAnalyzeReviewApplication.IProps",
                            value: input
                        }))(input, "$input", true);
                        const success = 0 === errors.length;
                        return success ? {
                            success,
                            data: input
                        } : {
                            success,
                            errors,
                            data: input
                        };
                    }
                    return {
                        success: true,
                        data: input
                    };
                }; })()
            }
        ]
    },
    claude,
    llama: claude,
    deepseek: claude,
    "3.1": claude,
};
//# sourceMappingURL=orchestrateAnalyzeReview.js.map