"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.consentFunctionCall = void 0;
const __typia_transform__validateReport = __importStar(require("typia/lib/internal/_validateReport.js"));
const core_1 = require("@agentica/core");
const typia_1 = __importDefault(require("typia"));
const uuid_1 = require("uuid");
const consentFunctionCall = (props) => __awaiter(void 0, void 0, void 0, function* () {
    var _a, _b, _c, _d;
    const pointer = {
        value: null,
    };
    const agent = new core_1.MicroAgentica({
        model: "chatgpt",
        vendor: props.vendor,
        config: Object.assign(Object.assign({}, ((_a = props.config) !== null && _a !== void 0 ? _a : [])), { retry: (_c = (_b = props.config) === null || _b === void 0 ? void 0 : _b.retry) !== null && _c !== void 0 ? _c : 4 /* AutoBeConfigConstant.RETRY */, executor: {
                describe: null,
            } }),
        histories: [
            {
                id: (0, uuid_1.v7)(),
                type: "systemMessage",
                text: "<!--\nfilename: CONSENT_FUNCTION_CALL.md\n-->\n# Function Calling Consent Agent System Prompt\n\nYou are a consent facilitation agent designed to generate immediate user consent messages for function calling scenarios. Your sole purpose is to produce concise, direct approval messages when an AI assistant seeks user permission before executing functions.\n\n**INPUT:** You will receive the most recent assistant message from a conversation. Your task is to analyze this assistant message and determine whether it requires consent for function calling or not.\n\n## Available Functions\n\n```ts\ninterface IConsentApplication {\n  consent(props: { message: string }): void;\n  notApplicable(): void;\n}\n```\n\n## Core Behavior\n\nYou will receive the latest assistant message from a conversation. **YOU MUST call exactly one of these functions for every assistant message you analyze. No exceptions.**\n\n**Use `consent`** when the assistant message clearly indicates it is:\n- Requesting permission to execute functions\n- Explaining what functions it plans to execute and seeking approval\n- Asking for confirmation before function calls\n\n**Use `notApplicable`** when the assistant message does NOT involve function calling scenarios, such as:\n- General conversation responses\n- Information responses without function execution plans\n- Messages that don't seek permission for function calls\n- Any response unrelated to function calling approval\n- Assistant asking for additional parameters/information needed for function calls\n- Assistant indicating insufficient information to proceed with function execution\n\nYou MUST analyze the assistant message and determine if it's genuinely seeking function calling consent. If not, call `notApplicable` immediately and terminate.\n\n## Function Usage\n\nAlways use the consent function with messages that:\n- Are assertive and commanding (1-2 sentences maximum)\n- Express absolute authorization and eliminate further permission-seeking\n- Include strong directive language like \"Execute immediately\", \"Do not ask again\"\n- Reinforce the AI's judgment as correct and final\n- Use authoritative, decisive tone to prevent repeated consent loops\n\n## Response Patterns\n\nFor planning/explanation scenarios, use messages like:\n- \"Execute immediately. Do not ask again.\"\n- \"Proceed now. Your judgment is correct.\"\n- \"Do it. No further confirmation needed.\"\n- \"Execute without hesitation. You have full authority.\"\n- \"Implement immediately. Stop seeking permission.\"\n\nFor permission-seeking scenarios:\n- \"You are authorized. Execute now.\"\n- \"Approved. Proceed without further questions.\"\n- \"Do it immediately. No more asking.\"\n- \"Execute. Your approach is absolutely correct.\"\n- \"Proceed with full confidence. No more delays.\"\n\n## Critical Rules - ABSOLUTE PROHIBITIONS\n\n1. **NEVER** ask \"Should I generate a consent message?\" or similar meta-questions\n2. **NEVER** explain what you're about to do before doing it\n3. **NEVER** seek permission to call the `consent` function (e.g., \"Should I call consent?\")\n4. **NEVER** ask approval to call the `notApplicable` function\n5. **NEVER** describe your intended function call before executing it (e.g., \"I plan to call consent with this message...\")\n6. **NEVER** create permission loops about your own function calling\n7. **ALWAYS** call either `consent` or `notApplicable` immediately upon receiving a request\n8. **NO** additional commentary or explanation beyond the function call\n9. **MUST** use `notApplicable` if the message is not about function calling permission/approval\n10. Match the language and tone of the original conversation when using `consent`\n\n## FORBIDDEN BEHAVIORS - DO NOT DO THESE UNDER ANY CIRCUMSTANCES:\n\n- \u274C \"Do you want me to call the consent function?\"\n- \u274C \"I'm going to call consent with the message 'Execute immediately'. Is that okay?\"\n- \u274C \"Should I use notApplicable for this scenario?\"\n- \u274C \"I plan to respond with consent function containing...\"\n- \u274C \"Let me call the appropriate function for you...\"\n\n## CORRECT BEHAVIOR:\n- \u2705 [Immediately calls consent or notApplicable function without any commentary]\n\n## Example Input/Output\n\n**Input:** \"I'm planning to search for recent news about AI developments and then analyze the results. Should I proceed?\"\n\n**Output:** [Immediately calls consent function with message: \"Execute immediately. Your judgment is absolutely correct.\"]\n\n**Input:** \"I can fetch the latest stock prices for you. Would you like me to do that?\"\n\n**Output:** [Immediately calls consent function with message: \"Proceed now. No further confirmation needed.\"]\n\n**Input:** \"What's the weather like today?\"\n\n**Output:** [Immediately calls notApplicable function]\n\n**Input:** \"I need more information to proceed. Could you specify which city you want weather data for?\"\n\n**Output:** [Immediately calls notApplicable function]\n\n**Input:** \"To search effectively, I'll need you to provide the specific date range you're interested in.\"\n\n**Output:** [Immediately calls notApplicable function]\n\nYour efficiency and directness are critical - any hesitation or explanation defeats your purpose." /* AutoBeSystemPromptConstant.CONSENT_FUNCTION_CALL */,
                created_at: new Date().toISOString(),
            },
            {
                id: (0, uuid_1.v7)(),
                type: "assistantMessage",
                text: props.assistantMessage,
                created_at: new Date().toISOString(),
            },
        ],
        controllers: [
            (() => {
                const application = {
                    model: "chatgpt",
                    options: {
                        reference: true,
                        strict: false,
                        separate: null
                    },
                    functions: [
                        {
                            name: "consent",
                            parameters: {
                                description: " Configuration object",
                                type: "object",
                                properties: {
                                    message: {
                                        description: "A strong, directive consent message that eliminates further\npermission-seeking. Must be authoritative and commanding (1-2 sentences\nmaximum). Examples: \"Execute immediately. Do not ask again.\", \"Proceed\nnow. Your judgment is correct.\"",
                                        type: "string"
                                    }
                                },
                                required: [
                                    "message"
                                ],
                                additionalProperties: false,
                                $defs: {}
                            },
                            description: "Generate an immediate, authoritative consent message to approve function\nexecution. Use this when the assistant message is seeking permission or\napproval for function calls.\n\nThe message should be commanding and decisive to prevent further\npermission-seeking loops. Examples: \"Execute immediately. Do not ask\nagain.\", \"Proceed now. Your judgment is correct.\"",
                            validate: (() => { const _io0 = input => "string" === typeof input.message; const _vo0 = (input, _path, _exceptionable = true) => ["string" === typeof input.message || _report(_exceptionable, {
                                    path: _path + ".message",
                                    expected: "string",
                                    value: input.message
                                })].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: "__type",
                                        value: input
                                    })) && _vo0(input, _path + "", true) || _report(true, {
                                        path: _path + "",
                                        expected: "__type",
                                        value: input
                                    }))(input, "$input", true);
                                    const success = 0 === errors.length;
                                    return success ? {
                                        success,
                                        data: input
                                    } : {
                                        success,
                                        errors,
                                        data: input
                                    };
                                }
                                return {
                                    success: true,
                                    data: input
                                };
                            }; })()
                        },
                        {
                            name: "notApplicable",
                            parameters: {
                                type: "object",
                                properties: {},
                                additionalProperties: false,
                                required: [],
                                $defs: {}
                            },
                            description: "Indicate that the assistant message does not require function calling\nconsent. Use this when the assistant message is NOT seeking permission for\nfunction execution.\n\nThis applies to:\n\n- General conversation responses\n- Information requests without function execution plans\n- Assistant asking for additional parameters/information\n- Any response unrelated to function calling approval\n\nCall this function immediately when the message doesn't involve function\ncalling consent.",
                            validate: (() => { const __is = input => true; let errors; let _report; return input => {
                                if (false === __is(input)) {
                                    errors = [];
                                    _report = __typia_transform__validateReport._validateReport(errors);
                                    ((input, _path, _exceptionable = true) => true)(input, "$input", true);
                                    const success = 0 === errors.length;
                                    return success ? {
                                        success,
                                        data: input
                                    } : {
                                        success,
                                        errors,
                                        data: input
                                    };
                                }
                                return {
                                    success: true,
                                    data: input
                                };
                            }; })()
                        }
                    ]
                };
                return {
                    protocol: "class",
                    name: "consent",
                    execute: {
                        consent: (props) => {
                            pointer.value = {
                                type: "consent",
                                message: props.message,
                            };
                        },
                        notApplicable: () => {
                            pointer.value = {
                                type: "notApplicable",
                            };
                        },
                    },
                    application
                };
            })(),
        ],
    });
    const histories = yield agent.conversate("Analyze and judge this assistant message please.");
    if (pointer.value === null) {
        const last = histories[histories.length - 1];
        if ((last === null || last === void 0 ? void 0 : last.type) === "assistantMessage")
            pointer.value = {
                type: "assistantMessage",
                message: last.text,
            };
    }
    props.dispatch({
        type: "consentFunctionCall",
        id: (0, uuid_1.v7)(),
        source: props.source,
        assistantMessage: props.assistantMessage,
        result: pointer.value,
        created_at: new Date().toISOString(),
    });
    return ((_d = pointer.value) === null || _d === void 0 ? void 0 : _d.type) === "consent" ? pointer.value.message : null;
});
exports.consentFunctionCall = consentFunctionCall;
//# sourceMappingURL=consentFunctionCall.js.map