"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecutePreexistingSnippetToolDefinition = exports.executePreexistingSnippetClientResponseSchema = exports.executePreexistingSnippetArgumentsSchema = void 0;
var zod_1 = require("zod");
var toolDefinition_js_1 = require("../toolDefinition.js");
var agentToolNames_js_1 = require("../shared/agentToolNames.js");
exports.executePreexistingSnippetArgumentsSchema = zod_1.z.object({
    snippet_id: zod_1.z.string().meta({
        description: 'The snippet_id value returned by request_snippet_tools (e.g. "abc123-sn"). Use the snippet ID, not the snippet name. Pass the value exactly as returned — do not add any prefix.',
    }),
    parameters: zod_1.z.record(zod_1.z.string(), zod_1.z.string()).meta({
        description: 'Parameters for the snippet as a JSON object. Keys should match the parameter names from the snippet. Values can reference variables using {{@variableName}} syntax.',
    }),
    save_result_to_variable: zod_1.z.string().optional().meta({
        description: 'Optional variable name to save the snippet result to. Variable names should only contain alphanumeric characters and underscores.',
    }),
});
/**
 * Response schema for execute_preexisting_snippet tool.
 * The client should include any variables created by the snippet
 * to provide context for the next agent decision.
 */
exports.executePreexistingSnippetClientResponseSchema = zod_1.z.object({
    success: zod_1.z.boolean(),
    message: zod_1.z.string().optional(),
    result: zod_1.z.any().optional(),
    // Context fields - client should include these after executing the action
    variable_name: zod_1.z.string().optional().meta({
        description: 'The name of the variable that was created (if save_result_to_variable was specified)',
    }),
    variable_value: zod_1.z.string().optional().meta({
        description: 'The actual value saved to the variable',
    }),
});
exports.ExecutePreexistingSnippetToolDefinition = (0, toolDefinition_js_1.defineTool)({
    name: agentToolNames_js_1.AgentToolNames.ExecutePreexistingSnippet,
    description: "Execute an existing reusable JavaScript snippet. Snippets are saved pieces of JavaScript code that can perform custom logic. If a variable is created, the response will include the variable name and value.\n\n**Workflow**:\n1. First, use request_snippet_tools to search for snippets relevant to your current task\n2. Review the search results to find a snippet that matches your needs\n3. Use this tool with the snippet_id from the search results\n4. Provide parameters as a JSON object matching the snippet's parameter schema\n5. Optionally specify a variable name to save the snippet's result\n\n**Parameter Values**:\n- Parameters can be literal values: {\"count\": \"5\"}\n- Parameters can reference existing variables: {\"email\": \"{{@userEmail}}\"}\n- Parameter names and requirements are shown in the snippet search results\n\n**Saving Results**:\n- If the snippet returns a value, you can save it to a variable for later use\n- Use save_result_to_variable to specify the variable name\n- The variable can then be referenced in subsequent steps using {{@variableName}} syntax\n\n**Example**:\nIf request_snippet_tools returns a validation snippet with snippet_id \"abc123-sn\" that requires a \"value\" parameter:\n{\n  \"snippet_id\": \"abc123-sn\",\n  \"parameters\": {\n    \"value\": \"{{@inputValue}}\"\n  },\n  \"save_result_to_variable\": \"validationResult\"\n}",
    argumentsSchema: exports.executePreexistingSnippetArgumentsSchema,
    responseSchema: exports.executePreexistingSnippetClientResponseSchema,
});
//# sourceMappingURL=ExecutePreexistingSnippetDefinition.js.map