// This file was auto-generated by Fern from our API Definition.

import type * as Vapi from "../index.js";

export interface UpdateCodeToolDto {
    /**
     * These are the messages that will be spoken to the user as the tool is running.
     *
     * For some tools, this is auto-filled based on special fields like `tool.destinations`. For others like the function tool, these can be custom configured.
     */
    messages?: Vapi.UpdateCodeToolDtoMessagesItem[] | undefined;
    /**
     * This determines if the tool is async.
     *
     *   If async, the assistant will move forward without waiting for your server to respond. This is useful if you just want to trigger something on your server.
     *
     *   If sync, the assistant will wait for your server to respond. This is useful if want assistant to respond with the result from your server.
     *
     *   Defaults to synchronous (`false`).
     */
    async?: boolean | undefined;
    /**
     *   This is the server where a `tool-calls` webhook will be sent.
     *
     *   Notes:
     *   - Webhook is sent to this server when a tool call is made.
     *   - Webhook contains the call, assistant, and phone number objects.
     *   - Webhook contains the variables set on the assistant.
     *   - Webhook is sent to the first available URL in this order: {{tool.server.url}}, {{assistant.server.url}}, {{phoneNumber.server.url}}, {{org.server.url}}.
     *   - Webhook expects a response with tool call result.
     */
    server?: Vapi.Server | undefined;
    /** TypeScript code to execute when the tool is called */
    code?: string | undefined;
    /** Environment variables available in code via `env` object */
    environmentVariables?: Vapi.CodeToolEnvironmentVariable[] | undefined;
    /**
     * This is the timeout in seconds for the code execution. Defaults to 10 seconds.
     * Maximum is 30 seconds to prevent abuse.
     *
     * @default 10
     */
    timeoutSeconds?: number | undefined;
    /** Credential ID containing the Val Town API key */
    credentialId?: string | undefined;
    /** Plan to extract variables from the tool response */
    variableExtractionPlan?: Vapi.VariableExtractionPlan | undefined;
    /**
     * This is the plan to reject a tool call based on the conversation state.
     *
     * // Example 1: Reject endCall if user didn't say goodbye
     * ```json
     * {
     *   conditions: [{
     *     type: 'regex',
     *     regex: '(?i)\\b(bye|goodbye|farewell|see you later|take care)\\b',
     *     target: { position: -1, role: 'user' },
     *     negate: true  // Reject if pattern does NOT match
     *   }]
     * }
     * ```
     *
     * // Example 2: Reject transfer if user is actually asking a question
     * ```json
     * {
     *   conditions: [{
     *     type: 'regex',
     *     regex: '\\?',
     *     target: { position: -1, role: 'user' }
     *   }]
     * }
     * ```
     *
     * // Example 3: Reject transfer if user didn't mention transfer recently
     * ```json
     * {
     *   conditions: [{
     *     type: 'liquid',
     *     liquid: `{% assign recentMessages = messages | last: 5 %}
     * {% assign userMessages = recentMessages | where: 'role', 'user' %}
     * {% assign mentioned = false %}
     * {% for msg in userMessages %}
     *   {% if msg.content contains 'transfer' or msg.content contains 'connect' or msg.content contains 'speak to' %}
     *     {% assign mentioned = true %}
     *     {% break %}
     *   {% endif %}
     * {% endfor %}
     * {% if mentioned %}
     *   false
     * {% else %}
     *   true
     * {% endif %}`
     *   }]
     * }
     * ```
     *
     * // Example 4: Reject endCall if the bot is looping and trying to exit
     * ```json
     * {
     *   conditions: [{
     *     type: 'liquid',
     *     liquid: `{% assign recentMessages = messages | last: 6 %}
     * {% assign userMessages = recentMessages | where: 'role', 'user' | reverse %}
     * {% if userMessages.size < 3 %}
     *   false
     * {% else %}
     *   {% assign msg1 = userMessages[0].content | downcase %}
     *   {% assign msg2 = userMessages[1].content | downcase %}
     *   {% assign msg3 = userMessages[2].content | downcase %}
     *   {% comment %} Check for repetitive messages {% endcomment %}
     *   {% if msg1 == msg2 or msg1 == msg3 or msg2 == msg3 %}
     *     true
     *   {% comment %} Check for common loop phrases {% endcomment %}
     *   {% elsif msg1 contains 'cool thanks' or msg2 contains 'cool thanks' or msg3 contains 'cool thanks' %}
     *     true
     *   {% elsif msg1 contains 'okay thanks' or msg2 contains 'okay thanks' or msg3 contains 'okay thanks' %}
     *     true
     *   {% elsif msg1 contains 'got it' or msg2 contains 'got it' or msg3 contains 'got it' %}
     *     true
     *   {% else %}
     *     false
     *   {% endif %}
     * {% endif %}`
     *   }]
     * }
     * ```
     */
    rejectionPlan?: Vapi.ToolRejectionPlan | undefined;
    /**
     * This is the function definition of the tool.
     *
     * For the Code tool, this defines the name, description, and parameters that the model
     * will use to understand when and how to call this tool.
     */
    function?: Vapi.OpenAiFunction | undefined;
}
