"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.orchestrateAnalyzeWrite = 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 transformAnalyzeWriteHistories_1 = require("./histories/transformAnalyzeWriteHistories");
const orchestrateAnalyzeWrite = (ctx, props) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b;
    const { file, progress, promptCacheKey } = props;
    const pointer = {
        value: null,
    };
    const { tokenUsage } = yield ctx.conversate({
        source: "analyzeWrite",
        controller: createController({
            model: ctx.model,
            pointer,
        }),
        histories: (0, transformAnalyzeWriteHistories_1.transformAnalyzeWriteHistories)(ctx, props),
        enforceFunctionCall: true,
        promptCacheKey,
        message: "Write requirement analysis report.",
    });
    if (pointer.value === null)
        throw new Error("The Analyze Agent failed to create the document.");
    const event = {
        type: "analyzeWrite",
        id: (0, uuid_1.v7)(),
        file: Object.assign(Object.assign({}, file), { content: pointer.value.content }),
        tokenUsage: tokenUsage,
        step: ((_b = (_a = ctx.state().analyze) === null || _a === void 0 ? void 0 : _a.step) !== null && _b !== void 0 ? _b : -1) + 1,
        total: progress.total,
        completed: ++progress.completed,
        created_at: new Date().toISOString(),
    };
    ctx.dispatch(event);
    return event;
});
exports.orchestrateAnalyzeWrite = orchestrateAnalyzeWrite;
function createController(props) {
    (0, assertSchemaModel_1.assertSchemaModel)(props.model);
    const application = collection[props.model];
    return {
        protocol: "class",
        name: "Planning",
        application,
        execute: {
            write: (input) => __awaiter(this, void 0, void 0, function* () {
                props.pointer.value = input;
            }),
        },
    };
}
const claude = {
    model: "claude",
    options: {
        reference: true,
        separate: null
    },
    functions: [
        {
            name: "write",
            parameters: {
                description: " - The properties containing the document plan and initial\ncontent\n\n------------------------------\n\nCurrent Type: {@link IAutoBeAnalyzeWriteApplication.IProps}",
                type: "object",
                properties: {
                    plan: {
                        description: "Step 1 (CoT: Plan Phase) - Document Planning Structure\n\nThe document planning structure that outlines what needs to be written.\n\nThis includes:\n\n- Document title and purpose\n- Table of contents structure\n- Key sections to be covered\n- Relationships with other documents\n- Target audience (backend developers)\n\nThe plan serves as a roadmap for the AI agent to ensure all necessary\ntopics are covered in the documentation process.\n\nExample plan structure:\n\n- Service overview with business model\n- User roles and authentication requirements\n- Functional requirements with EARS format\n- Non-functional requirements\n- Business requirements in natural language\n- User scenarios and use cases",
                        type: "string"
                    },
                    content: {
                        description: "Step 2 (CoT: Write Phase) - Document Content Creation\n\nThe initial content or context for the document being written.\n\nThis may include:\n\n- User requirements and business goals\n- Existing documentation to build upon\n- Specific scenarios or use cases to document\n- Technical constraints or preferences\n- Related documents for reference\n\nThe content provides the raw material that the AI agent will transform\ninto structured, developer-ready documentation following the planning\nguidelines.\n\nThe AI agent will expand this content into comprehensive documentation\nthat:\n\n- Removes all ambiguity for backend developers\n- Provides specific, measurable requirements in natural language\n- Focuses on business logic and requirements, NOT technical implementation\n- STRICTLY PROHIBITED: Do NOT write database schemas, ERD, or API\n  specifications\n- Uses EARS format for all applicable requirements\n- Follows proper document linking conventions\n- Includes Mermaid diagrams with proper syntax (double quotes mandatory)",
                        type: "string"
                    }
                },
                required: [
                    "plan",
                    "content"
                ],
                additionalProperties: false,
                $defs: {}
            },
            description: "Creates or updates planning documentation based on the provided plan and\ncontent structure.\n\nThis function is called by the AI agent to write detailed planning\ndocuments that will be used by backend developers to understand what needs\nto be built, why it's being built, and how it should function.",
            validate: (() => { const _io0 = input => "string" === typeof input.plan && "string" === typeof input.content; const _vo0 = (input, _path, _exceptionable = true) => ["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: "IAutoBeAnalyzeWriteApplication.IProps",
                        value: input
                    })) && _vo0(input, _path + "", true) || _report(true, {
                        path: _path + "",
                        expected: "IAutoBeAnalyzeWriteApplication.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: "write",
                parameters: {
                    description: " - The properties containing the document plan and initial\ncontent\n\n------------------------------\n\nCurrent Type: {@link IAutoBeAnalyzeWriteApplication.IProps}",
                    type: "object",
                    properties: {
                        plan: {
                            description: "Step 1 (CoT: Plan Phase) - Document Planning Structure\n\nThe document planning structure that outlines what needs to be written.\n\nThis includes:\n\n- Document title and purpose\n- Table of contents structure\n- Key sections to be covered\n- Relationships with other documents\n- Target audience (backend developers)\n\nThe plan serves as a roadmap for the AI agent to ensure all necessary\ntopics are covered in the documentation process.\n\nExample plan structure:\n\n- Service overview with business model\n- User roles and authentication requirements\n- Functional requirements with EARS format\n- Non-functional requirements\n- Business requirements in natural language\n- User scenarios and use cases",
                            type: "string"
                        },
                        content: {
                            description: "Step 2 (CoT: Write Phase) - Document Content Creation\n\nThe initial content or context for the document being written.\n\nThis may include:\n\n- User requirements and business goals\n- Existing documentation to build upon\n- Specific scenarios or use cases to document\n- Technical constraints or preferences\n- Related documents for reference\n\nThe content provides the raw material that the AI agent will transform\ninto structured, developer-ready documentation following the planning\nguidelines.\n\nThe AI agent will expand this content into comprehensive documentation\nthat:\n\n- Removes all ambiguity for backend developers\n- Provides specific, measurable requirements in natural language\n- Focuses on business logic and requirements, NOT technical implementation\n- STRICTLY PROHIBITED: Do NOT write database schemas, ERD, or API\n  specifications\n- Uses EARS format for all applicable requirements\n- Follows proper document linking conventions\n- Includes Mermaid diagrams with proper syntax (double quotes mandatory)",
                            type: "string"
                        }
                    },
                    required: [
                        "plan",
                        "content"
                    ],
                    additionalProperties: false,
                    $defs: {}
                },
                description: "Creates or updates planning documentation based on the provided plan and\ncontent structure.\n\nThis function is called by the AI agent to write detailed planning\ndocuments that will be used by backend developers to understand what needs\nto be built, why it's being built, and how it should function.",
                validate: (() => { const _io0 = input => "string" === typeof input.plan && "string" === typeof input.content; const _vo0 = (input, _path, _exceptionable = true) => ["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: "IAutoBeAnalyzeWriteApplication.IProps",
                            value: input
                        })) && _vo0(input, _path + "", true) || _report(true, {
                            path: _path + "",
                            expected: "IAutoBeAnalyzeWriteApplication.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=orchestrateAnalyzeWrite.js.map