import { Connection, Logger, SfProject } from '@salesforce/core';
import { FileProperties } from '@salesforce/source-deploy-retrieve';
import { type ApexLog } from '@salesforce/types/tooling';
import { metric } from './utils';
import type { NgtScorerName } from './ngtScorerCatalog';
/**
 * Exit codes set on SfError when compile() fails due to server HTTP errors.
 * Used by CLI (e.g. agent validate authoring-bundle) for scripting.
 */
export declare const COMPILATION_API_EXIT_CODES: {
    /** Validation/compilation API returned 404 (e.g. endpoint not available) */
    readonly NOT_FOUND: 2;
    /** Validation/compilation API returned 500 (server error) */
    readonly SERVER_ERROR: 3;
};
/**
 * Common preview interface that both ScriptAgent and ProductionAgent implement
 */
export type AgentPreviewInterface = {
    start: (...args: unknown[]) => Promise<AgentPreviewStartResponse>;
    send: (message: string) => Promise<AgentPreviewSendResponse>;
    getAllTraces: () => Promise<PlannerResponse[]>;
    end: (...args: unknown[]) => Promise<AgentPreviewEndResponse>;
    saveSession: (outputDir?: string) => Promise<string>;
    setApexDebugging: (apexDebugging: boolean) => void;
};
export type ContextVariable = {
    name: string;
    type: 'Object' | 'Boolean' | 'DateTime' | 'Money' | 'Number' | 'Text' | 'Ref' | 'List';
    value: string;
};
export type AgentPreviewStartOptions = {
    contextVariables?: ContextVariable[];
};
/**
 * Session metadata type
 */
export type PreviewMetadata = {
    sessionId: string;
    agentId: string;
    startTime: string;
    endTime?: string;
    apexDebugging?: boolean;
    mockMode?: 'Mock' | 'Live Test';
    planIds: string[];
};
export type BaseAgentConfig = {
    connection: Connection;
    logger?: Logger;
};
/**
 * Options for creating instances of agents from an org.
 */
export type AgentOptions = ScriptAgentOptions | ProductionAgentOptions;
export type ScriptAgentOptions = {
    connection: Connection;
    project: SfProject;
    aabName: string;
    agentJson?: AgentJson;
};
export type ProductionAgentOptions = {
    connection: Connection;
    project: SfProject;
    apiNameOrId: string;
};
/**
 * Represents an agent available for preview, either from the org or from a local script file
 */
export type PreviewableAgent = {
    name: string;
    source: AgentSource;
    id?: string;
    developerName?: string;
    aabName?: string;
    label?: string;
};
export type BotMetadata = {
    Id: string;
    IsDeleted: boolean;
    DeveloperName: string;
    MasterLabel: string;
    CreatedDate: string;
    CreatedById: string;
    LastModifiedDate: string;
    LastModifiedById: string;
    SystemModstamp: string;
    BotUserId: string;
    Description: string;
    Type: string;
    AgentType: string;
    AgentTemplate: null | string;
    BotVersions: {
        records: BotVersionMetadata[];
    };
};
export type BotVersionMetadata = {
    Id: string;
    Status: 'Active' | 'Inactive';
    IsDeleted: boolean;
    BotDefinitionId: string;
    DeveloperName: string;
    CreatedDate: string;
    CreatedById: string;
    LastModifiedDate: string;
    LastModifiedById: string;
    SystemModstamp: string;
    VersionNumber: number;
    CopilotPrimaryLanguage: null | string;
    ToneType: AgentTone;
    CopilotSecondaryLanguages: null | string[];
};
export type BotActivationResponse = {
    success: boolean;
    isActivated: boolean;
    messages?: string[];
};
/**
 * An agent job spec is a list of job titles and descriptions
 * to be performed by the agent.
 */
export type AgentJobSpec = AgentJobSpecCreateConfig & {
    topics: DraftAgentTopics;
};
export type ExtendedAgentJobSpec = AgentJobSpec & {
    developerName: string;
    name: string;
};
export type AgentType = 'customer' | 'internal' | 'AGENT';
export type AgentTone = 'casual' | 'formal' | 'neutral';
/**
 * The parameters used to generate an agent spec.
 */
export type AgentJobSpecCreateConfig = {
    /**
     * Internal type is copilots; used by customers' employees.
     * Customer type is agents; used by customers' customers.
     */
    agentType: AgentType;
    role: string;
    companyName: string;
    companyDescription: string;
    companyWebsite?: string;
    /**
     * The maximum number of topics to create in the spec.
     * Default is 10.
     */
    maxNumOfTopics?: number;
    /**
     * Developer name of the prompt template.
     */
    promptTemplateName?: string;
    /**
     * Context info to be used in customized prompt template
     */
    groundingContext?: string;
};
export type AgentCreateConfig = DraftAgentTopicsBody & {
    generationInfo: {
        defaultInfo: {
            /**
             * List of topics from an agent spec.
             */
            preDefinedTopics?: DraftAgentTopics;
        };
    };
    /**
     * Whether to persist the agent creation in the org (true) or preview
     * what would be created (false).
     *
     * Default: false
     */
    saveAgent?: boolean;
    /**
     * Settings for the agent being created. Needed only when saveAgent=true
     */
    agentSettings?: {
        /**
         * The name to use for the Agent metadata to be created.
         */
        agentName: string;
        /**
         * The API name to use for the Agent metadata to be created.
         */
        agentApiName?: string;
        /**
         * The GenAiPlanner metadata ID if already created in the org.
         */
        plannerId?: string;
        /**
         * User ID of an existing user.
         *
         * Determines what this agent can access and do. If your agent uses
         * features or objects that require additional permissions, assign
         * a custom user.
         */
        userId?: string;
        /**
         * Store conversation transcripts, including end-user data, in event logs
         * for this agent for troubleshooting. If false, conversation data is
         * replaced with, "Sensitive data not available."
         *
         * Default: false
         */
        enrichLogs?: boolean;
        /**
         * The conversational style of your agent's responses. Can be one of:
         * formal, casual, or neutral.
         *
         * Default: casual
         */
        tone?: AgentTone;
        /**
         * The language your agent uses in conversations. Agent currently
         * supports English only.
         *
         * Default: en_US
         */
        primaryLanguage?: 'en_US';
    };
};
/**
 * The request body to send to the `draft-agent-topics` API.
 */
export type DraftAgentTopicsBody = {
    agentType: AgentType;
    generationInfo: {
        defaultInfo: {
            role: string;
            companyName: string;
            companyDescription: string;
            companyWebsite?: string;
        };
        customizedInfo?: {
            promptTemplateName: string;
            groundingContext?: string;
        };
    };
    generationSettings: {
        maxNumOfTopics?: number;
    };
};
export type AgentCreateResponse = {
    isSuccess: boolean;
    errorMessage?: string;
    /**
     * If the agent was created with saveAgent=true, these are the
     * IDs that make up an agent; Bot, BotVersion, and GenAiPlanner metadata.
     */
    agentId?: {
        botId: string;
        botVersionId: string;
        plannerId: string;
    };
    agentDefinition: {
        agentDescription: string;
        topics: [
            {
                scope: string;
                topic: string;
                actions: [
                    {
                        actionName: string;
                        exampleOutput: string;
                        actionDescription: string;
                        inputs: [
                            {
                                inputName: string;
                                inputDataType: string;
                                inputDescription: string;
                            }
                        ];
                        outputs: [
                            {
                                outputName: string;
                                outputDataType: string;
                                outputDescription: string;
                            }
                        ];
                    }
                ];
                instructions: string[];
                classificationDescription: string;
            }
        ];
        sampleUtterances: string[];
    };
};
export type DraftAgentTopics = [
    {
        name: string;
        description: string;
    }
];
/**
 * The response from the `draft-agent-topics` API.
 */
export type DraftAgentTopicsResponse = {
    isSuccess: boolean;
    errorMessage?: string;
    topicDrafts: DraftAgentTopics;
};
/**
 * The response from the API call to create an AgentScript.
 */
export type CreateAgentScriptResponse = {
    isSuccess: boolean;
    errorMessage?: string;
    agentScriptContent?: AgentScriptContent;
};
export type AgentTestConfig = {
    /**
     * The API name of an AiEvaluationDefinition or AiTestingDefinition.
     */
    name?: string;
    /**
     * The local file path of an AiEvaluationDefinition or AiTestingDefinition metadata file.
     */
    mdPath?: string;
    /**
     * The local file path of an agent test spec file (legacy YAML or NGT YAML).
     */
    specPath?: string;
    /**
     * The agent test spec data (legacy `TestSpec` or NGT `NgtTestSpec`).
     */
    specData?: TestSpec | NgtTestSpec;
};
export type TestStatus = 'NEW' | 'IN_PROGRESS' | 'COMPLETED' | 'ERROR' | 'TERMINATED';
export type AgentTestStartResponse = {
    runId: string;
    status: TestStatus;
};
export type AgentTestStatusResponse = {
    status: TestStatus;
    startTime: string;
    endTime?: string;
    errorMessage?: string;
};
export type TestCaseResult = {
    status: TestStatus;
    startTime: string;
    endTime?: string;
    inputs: {
        utterance: string;
    };
    generatedData: {
        actionsSequence: string[];
        invokedActions: string;
        sessionId: string;
        outcome: string;
        topic: string;
    };
    testResults: Array<{
        name: string;
        actualValue: string;
        expectedValue: string;
        score: number;
        result: null | 'PASS' | 'FAILURE';
        metricLabel: 'Accuracy' | 'Precision';
        metricExplainability: string;
        status: TestStatus;
        startTime: string;
        endTime?: string;
        errorCode?: string;
        errorMessage?: string;
    }>;
    testNumber: number;
};
export type AgentTestResultsResponse = {
    status: TestStatus;
    startTime: string;
    endTime?: string;
    errorMessage?: string;
    subjectName: string;
    testCases: TestCaseResult[];
};
export type AvailableDefinition = Omit<FileProperties, 'manageableState' | 'namespacePrefix'>;
export type AgentforceStudioTestStartResponse = {
    runId: string;
    status: AgentforceStudioTestStatus;
};
export type AgentforceStudioTestStatus = 'CREATED' | 'IN_PROGRESS' | 'SUCCESS' | 'FAILED' | 'TERMINATED';
export type AgentforceStudioTestStatusResponse = {
    status: string;
    startTime: string;
    endTime?: string;
    errorMessage?: string;
};
export type TestScorerResult = {
    scorerName: string;
    scorerResponse: string;
};
export type AgentforceStudioTestCaseResult = {
    subjectResponse: string;
    testNumber: number;
    testScorerResults: TestScorerResult[];
};
export type AgentforceStudioTestResultsResponse = {
    status: string;
    testCases: AgentforceStudioTestCaseResult[];
};
export type TestCase = {
    utterance: string;
    expectedActions: string[] | undefined;
    expectedOutcome: string | undefined;
    expectedTopic: string | undefined;
    metrics?: Array<(typeof metric)[number]>;
    contextVariables?: Array<{
        name: string;
        value: string;
    }>;
    conversationHistory?: Array<{
        role: 'user';
        message: string;
        index?: number;
    } | {
        role: 'agent';
        message: string;
        topic: string;
        index?: number;
    }>;
    customEvaluations?: Array<{
        label: string;
        name: string;
        parameters: Array<{
            name: 'operator';
            value: string;
            isReference: false;
        } | {
            name: 'actual';
            value: string;
            isReference: true;
        } | {
            name: 'expected';
            value: string;
            isReference: boolean;
        }>;
    }>;
};
export type TestSpec = {
    name: string;
    description?: string;
    subjectType: 'AGENT';
    subjectName: string;
    subjectVersion?: string;
    testCases: TestCase[];
};
export type MetadataMetric = {
    name: string;
};
export type MetadataExpectation = {
    name: 'topic_sequence_match' | 'topic_assertion' | 'action_sequence_match' | 'actions_assertion' | 'bot_response_rating' | 'output_validation';
    expectedValue: string;
};
export type MetadataCustomEvaluation = {
    name: string;
    label: string;
    parameter: Array<{
        name: 'operator';
        value: string;
        isReference: false;
    } | {
        name: 'actual';
        value: string;
        isReference: true;
    } | {
        name: 'expected';
        value: string;
        isReference: boolean;
    }>;
};
export type AiEvaluationDefinition = {
    description?: string;
    name: string;
    subjectType: 'AGENT';
    subjectName: string;
    subjectVersion?: string;
    testCase: Array<{
        expectation: Array<MetadataMetric | MetadataExpectation | MetadataCustomEvaluation>;
        inputs: {
            contextVariable?: Array<{
                variableName: string;
                variableValue: string;
            }>;
            conversationHistory?: Array<{
                role: 'user';
                message: string;
                index: number;
            } | {
                role: 'agent';
                message: string;
                topic: string;
                index: number;
            }>;
            utterance: string;
        };
    }>;
};
export type NgtContextVar = {
    name: string;
    value: string;
};
export type NgtConversationTurn = {
    role: 'user';
    message: string;
    index?: number;
} | {
    role: 'agent';
    message: string;
    topic: string;
    index?: number;
};
export type NgtTestCaseInput = {
    utterance: string;
    contextVariables?: NgtContextVar[];
    conversationHistory?: NgtConversationTurn[];
};
export type NgtTestCaseScorer = {
    name: NgtScorerName;
    expected?: string;
};
export type NgtTestCase = {
    inputs: NgtTestCaseInput[];
    scorers: NgtTestCaseScorer[];
};
export type NgtTestSpec = {
    name: string;
    description?: string;
    subjectType: 'AGENT';
    subjectName: string;
    subjectVersion?: string;
    testCases: NgtTestCase[];
};
export type AiConversationTurnXml = {
    role: 'user';
    message: string;
    index: number;
} | {
    role: 'agent';
    message: string;
    topic: string;
    index: number;
};
export type AiTestCaseInputXml = {
    utterance: string;
    contextVariable?: Array<{
        variableName: string;
        variableValue: string;
    }>;
    conversationHistory?: AiConversationTurnXml[];
};
export type AiTestCaseScorer = {
    name: NgtScorerName;
    expectedValue?: string;
    scorerType?: 'OOTB' | 'Custom';
};
export type AiTestCase = {
    number: number;
    inputs: AiTestCaseInputXml;
    scorer: AiTestCaseScorer[];
};
export type AiTestingDefinition = {
    description?: string;
    name: string;
    subjectName: string;
    subjectType: 'AGENT';
    subjectVersion?: string;
    testCase: AiTestCase[];
};
export type ApiStatus = {
    status: 'UP' | 'DOWN';
};
type Href = {
    href: string;
};
export type AgentPreviewError = {
    status: number;
    path: string;
    requestId: string;
    error: string;
    message: string;
    timestamp: number;
};
export type AgentPreviewMessageLinks = {
    self: Href | null;
    messages: Href | null;
    session: Href | null;
    end: Href | null;
};
export type MessageType = 'Inform' | 'TextChunk' | 'ProgressIndicator' | 'Inquire' | 'Confirm' | 'Failure' | 'Escalate' | 'SessionEnded' | 'EndOfTurn' | 'Error';
export type AgentPreviewMessage = {
    type: MessageType;
    id: string;
    feedbackId: string;
    planId: string;
    isContentSafe: boolean;
    message: string;
    result: {
        type: string;
        property: string;
        value: any;
    };
    citedReferences: {
        type: string;
        value: string;
    };
};
export type AgentPreviewStartResponse = {
    sessionId: string;
    _links: AgentPreviewMessageLinks;
    messages: AgentPreviewMessage[];
};
export type AgentPreviewSendResponse = {
    messages: AgentPreviewMessage[];
    _links: AgentPreviewMessageLinks;
    apexDebugLog?: ApexLog;
};
export type AgentPreviewEndMessage = {
    type: string;
    id: string;
    reason: string;
    feedbackId: string;
};
export type AgentPreviewEndResponse = {
    messages: AgentPreviewEndMessage[];
    _links: AgentPreviewMessageLinks;
};
export type EndReason = 'UserRequest' | 'Transfer' | 'Expiration' | 'Error' | 'Other';
export type AgentTraceStep = UserInputStep | LLMExecutionStep | UpdateTopicStep | EventStep | ReasoningStep | PlannerResponseStep;
export type UserInputStep = {
    type: 'UserInputStep';
    message: string;
};
export type LLMExecutionStep = {
    type: 'LLMExecutionStep';
    promptName: string;
    promptContent: string;
    promptResponse: string;
    executionLatency: number;
    startExecutionTime: number;
    endExecutionTime: number;
};
export type UpdateTopicStep = {
    type: 'UpdateTopicStep';
    topic: string;
    description: string;
    job: string;
    instructions: string[];
    availableFunctions: unknown[];
};
export type EventStep = {
    type: 'EventStep';
    eventName: string;
    isError: boolean;
    payload: {
        oldTopic: string;
        newTopic: string;
    };
};
export type ReasoningStep = {
    type: 'ReasoningStep';
    reason: string;
};
export type PlannerResponseStep = {
    type: 'PlannerResponseStep';
    message: string;
    responseType: string;
    isContentSafe: boolean;
    safetyScore: {
        safety_score: number;
        category_scores: {
            toxicity: number;
            hate: number;
            identity: number;
            violence: number;
            physical: number;
            sexual: number;
            profanity: number;
            biased: number;
        };
    };
};
export type AgentTraceResponse = {
    actions: Array<{
        id: string;
        state: string;
        returnValue: {
            type: string;
            planId: string;
            sessionId: string;
            intent: string;
            topic: string;
            plan: AgentTraceStep[];
        };
        error: unknown[];
    }>;
};
export type PlannerResponse = {
    type: 'PlanSuccessResponse';
    planId: string;
    sessionId: string;
    intent: string;
    topic: string;
    plan: PlanStep[];
};
export type PlanStep = UserInputStep | LLMExecutionStep | UpdateTopicStep | EventStep | FunctionStep | PlannerResponseStep;
export type FunctionStep = {
    type: 'FunctionStep';
    function: {
        name: string;
        input: Record<string, unknown>;
        output: Record<string, unknown>;
    };
    executionLatency: number;
    startExecutionTime: number;
    endExecutionTime: number;
};
export type CompileAgentScriptResponse = AgentCompilationSuccess | AgentCompilationError;
export type AgentCompilationSuccess = {
    status: 'success';
    compiledArtifact: AgentJson;
    errors: [];
    syntacticMap: {
        blocks: [];
    };
    dslVersion: '0.0.3.rc29';
};
export type AgentCompilationError = {
    status: 'failure';
    compiledArtifact: null;
    errors: CompilationError[];
    syntacticMap: {
        blocks: [];
    };
    dslVersion: '0.0.3.rc29';
};
export type CompilationError = {
    errorType: string;
    description: string;
    lineStart: number;
    lineEnd: number;
    colStart: number;
    colEnd: number;
};
export type PublishAgentJsonResponse = {
    botVersionId: string;
    botId: string;
    errorMessage?: string;
};
export type PublishAgent = PublishAgentJsonResponse & {
    developerName: string;
};
export type AgentJson = {
    schemaVersion: string;
    globalConfiguration: {
        developerName: string;
        label: string;
        description: string;
        enableEnhancedEventLogs: boolean;
        agentType: string;
        templateName: string;
        defaultAgentUser: string;
        defaultOutboundRouting: string;
        contextVariables: [];
    };
    agentVersion: {
        developerName: string | null;
        plannerType: string;
        systemMessages: [];
        modalityParameters: {
            voice: {
                inboundModel: null;
                inboundFillerWordsDetection: null;
                outboundVoice: null;
                outboundModel: null;
                outboundSpeed: null;
                outboundStyleExaggeration: null;
            };
            language: {
                defaultLocale: 'en_US';
                additionalLocales: [];
                allAdditionalLocales: boolean;
            };
        };
        additionalParameters: boolean;
        company: string;
        role: string;
        stateVariables: Array<{
            developerName: string;
            label: string;
            description: string;
            dataType: 'string';
            isList: boolean;
            default: boolean;
            visibility: 'Internal';
        }>;
        initialNode: string;
        nodes: Array<{
            type: string;
            reasoningType: string;
            description: string;
            beforeReasoning: string;
            instructions: string;
            focusPrompt: string;
            tools: Array<{
                type: string;
                target: string | null;
                boundInputs: unknown;
                llmInputs: unknown;
                enabled: boolean | null;
                stateUpdates: Array<Record<string, string>> | null;
                name: string;
                description: string;
                inputParameters: unknown;
                forced: boolean | null;
            }>;
            preToolCall: null;
            postToolCall: null;
            afterReasoning: null;
            developerName: string;
            label: string;
            onInit: null;
            transitions: null;
            onExit: null;
            actionDefinitions: [];
        }>;
        knowledgeDefinitions: null;
    };
};
export type AgentScriptContent = string;
export declare enum AgentSource {
    PUBLISHED = "published",
    SCRIPT = "script"
}
export type ScriptAgentType = {
    DeveloperName: string;
    source: AgentSource.SCRIPT;
    path: string;
};
export type ProductionAgentType = {
    Id: string;
    DeveloperName: string;
    source: AgentSource.PUBLISHED;
};
export type NamedUserJwtResponse = {
    access_token: string;
    token_format: 'jwt';
    scope: string;
    token_type: 'Bearer';
    issued_at: number;
    api_instance_url: string;
};
export {};
