import { z } from 'zod';
import { defineTool, } from '../toolDefinition.js';
import { AgentToolNames } from '../shared/agentToolNames.js';
export const executePreexistingSnippetArgumentsSchema = z.object({
    snippet_id: 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: z.record(z.string(), 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: 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.
 */
export const executePreexistingSnippetClientResponseSchema = z.object({
    success: z.boolean(),
    message: z.string().optional(),
    result: z.any().optional(),
    // Context fields - client should include these after executing the action
    variable_name: z.string().optional().meta({
        description: 'The name of the variable that was created (if save_result_to_variable was specified)',
    }),
    variable_value: z.string().optional().meta({
        description: 'The actual value saved to the variable',
    }),
});
export const ExecutePreexistingSnippetToolDefinition = defineTool({
    name: 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.

**Workflow**:
1. First, use request_snippet_tools to search for snippets relevant to your current task
2. Review the search results to find a snippet that matches your needs
3. Use this tool with the snippet_id from the search results
4. Provide parameters as a JSON object matching the snippet's parameter schema
5. Optionally specify a variable name to save the snippet's result

**Parameter Values**:
- Parameters can be literal values: {"count": "5"}
- Parameters can reference existing variables: {"email": "{{@userEmail}}"}
- Parameter names and requirements are shown in the snippet search results

**Saving Results**:
- If the snippet returns a value, you can save it to a variable for later use
- Use save_result_to_variable to specify the variable name
- The variable can then be referenced in subsequent steps using {{@variableName}} syntax

**Example**:
If request_snippet_tools returns a validation snippet with snippet_id "abc123-sn" that requires a "value" parameter:
{
  "snippet_id": "abc123-sn",
  "parameters": {
    "value": "{{@inputValue}}"
  },
  "save_result_to_variable": "validationResult"
}`,
    argumentsSchema: executePreexistingSnippetArgumentsSchema,
    responseSchema: executePreexistingSnippetClientResponseSchema,
});
//# sourceMappingURL=ExecutePreexistingSnippetDefinition.js.map