import { Response as Response_2 } from 'node-fetch'; /** * Represents an API error * * @remarks * If the error originates from the Chat API, the code and type property will be present. * * @public */ export declare class ApiError extends Error { /** The error message. */ message: string; /** The request status code */ statusCode?: number; /** The internal API error code. */ apiCode?: number; /** The internal API error type. */ type?: string; /* Excluded from this release type: __constructor */ } /** * AWS Connect handoff credentials. * * @public */ export declare interface AwsConnectCredentials { /** The identifier of an AWS chat session. */ contactId: string; /** The identifier for a chat participant in AWS Connect. */ participantId: string; /** * The token used by the chat participant create connection. * * @remarks * The participant token is valid for the lifetime of a chat participant. */ participantToken: string; } /** * Configurations for AWS Connect handoff. * * @public */ export declare interface AwsConnectHandoff { /** {@inheritdoc AwsConnectCredentials} */ credentials: AwsConnectCredentials; /** The region of The AWS Connect instance. */ region: string; } /** * The configuration options for {@link ChatCore}. * * @public */ export declare interface ChatConfig { /** ID of the bot to interface with. */ botId: string; /** The api key of the Chat experience. */ apiKey: string; /** ID of the account associated with this chat bot. */ businessId?: number; /** * The version of the chat bot configuration. * * @remarks * Default to 'LATEST' in Chat API * * @example * Examples: 'LATEST', 'STAGING', 'PRODUCTION', '42' */ version?: string; /** * Defines the environment of the API domains. * * @remarks * Default to PRODUCTION. */ env?: EnumOrLiteral; /** * The region to send the requests to. * * @remarks * Defaults to 'US'. */ region?: EnumOrLiteral; /** Overrides for the URLs which are used when making requests to the Chat API. */ endpoints?: Endpoints; /** * An optional location override to use instead of the user's provided location. * * @remarks * If provided, Search steps will not attempt to infer the location from * the request data and will use this latitude and longitude instead. */ locationOverride?: { latitude: number; longitude: number; }; } /** * Provide methods for interacting with Chat API. * * @public */ export declare interface ChatCore { /** * Make a request to Chat API to generate the next message. * * @remarks * If rejected, an {@link ApiError} is returned. * * @param request - request to get next message */ getNextMessage(request: MessageRequest): Promise; /** * Make a request to Chat streaming API to generate the next message * and consume its tokens via server-sent events. * * @experimental * * @remarks * If rejected, an {@link ApiError} is returned. * * @param request - request to get next message */ streamNextMessage(request: MessageRequest): Promise; } /* Excluded from this release type: ChatPrompt */ /** * An event that indicates end of Chat stream. * * @public */ export declare interface EndEvent { /** Name of the event. */ event: EnumOrLiteral; /** Full response from Chat API. */ data: MessageResponse; } /** * The URLs which are used when making requests to the Chat API. * * @public */ export declare interface Endpoints { /** Chat API endpoint. */ chat: string; /** Chat streaming API endpoint. */ chatStream: string; } /** * Produces a union type from the enum passed as a generic which * consists of the enum values and the string literals of the enum. * * @public */ export declare type EnumOrLiteral = T | `${T}`; /** * Defines the environment of the API domains. * * @public */ export declare enum Environment { PRODUCTION = "PRODUCTION", SANDBOX = "SANDBOX" } /** * Integration details for the current conversation. * * @public * * @remarks * This is only present when the conversation is integrated with a third-party service, such as AWS Connect and Zendesk. */ export declare interface IntegrationDetails { /** {@inheritdoc AwsConnectHandoff} */ awsConnectHandoff?: AwsConnectHandoff; /** {@inheritdoc ZendeskHandoff} */ zendeskHandoff?: ZendeskHandoff; } /* Excluded from this release type: InternalConfig */ /** * Represents a message within a conversation. * * @public */ export declare interface Message { /** * The response's id in the form of a 26 character ULID. * This is present for message coming from server. */ responseId?: string; /** Time when the message is sent. */ timestamp?: string; /** The sender of the message. */ source: EnumOrLiteral; /** The message's content. */ text: string; } /** * Information relevant to the current state of the conversation, serving as the bot’s * "memory" regarding what work it previously did to help determine future actions. * * @remarks * This data will come from the API. As such, a user’s first request may have this as undefined. * Subsequent requests will use the data of this type from the previous response. * * @public */ export declare interface MessageNotes { /** The goal of the latest message. */ currentGoal?: string; /** The indices to traversed within the nested instruction array to access the target step. */ currentStepIndices?: number[]; /** The query used for Yext Search, REST api, etc. */ searchQuery?: string; /** Data retrieved from Yext Search, REST api, etc. */ queryResult?: object; /** Data collected from user in a conversation. */ collectedData?: Record; /** The index of the message that started the current goal. */ goalFirstMsgIndex?: number; /** A set of pre-generated replies given by the AI. */ suggestedReplies?: string[]; /** The summary of the conversation up to this point. */ conversationSummary?: string; } /** * A request to Chat API. * * @public */ export declare interface MessageRequest { /** * The id corresponds to the current conversation. This is generated * by the server on the first message of the conversation and returned * in {@link MessageResponse}. * * @remarks * The first request for a new conversation may omit this id, but subsequent * requests for the same conversation should include the same id returned in * the response. */ conversationId?: string; /** * The messages of the current conversation. * * @remarks * The most recent message is the last message in the array, * in which Chat API will generate a reply for. */ messages: Message[]; /** {@inheritDoc MessageNotes} */ notes?: MessageNotes; /** * Additional information to pass into the instruction flow. This data could * then be used in the URL or body of a REST API step, influence Chat API's * assessment in a conditional step, or help construct a reply with additional * details. * * @remarks * May be any valid JSON object */ context?: any; } /** * A response from Chat API. * * @public */ export declare interface MessageResponse { /** * The id corresponds to the current conversation. * * @remarks * This is undefined only when it's an initial bot response without any user message present. */ conversationId?: string; /** The generated reply to the latest message in the request. */ message: Message; /** {@inheritDoc MessageNotes} */ notes: MessageNotes; /** {@inheritdoc IntegrationDetails} */ integrationDetails?: IntegrationDetails; } /** * Types of sender of a message. * * @public */ export declare enum MessageSource { /** From a user. */ USER = "USER", /** From Chat API server. */ BOT = "BOT", /** From third-party integration. */ AGENT = "AGENT" } /** * Provider for the ChatCore library. * * @public */ export declare function provideChatCore(config: ChatConfig): ChatCore; /* Excluded from this release type: provideChatCoreInternal */ /** * Raw response from Chat API. * * @remarks * Response uses WHATWG ReadableStream API for browser environment * and NodeJS.ReadableStream API for node environment. * * @public */ export declare type RawResponse = Response | Response_2; /** * The region to send the requests to. * * @public */ export declare enum Region { US = "US", EU = "EU" } /** * An event that indicates start of Chat stream. * * @public */ export declare interface StartEvent { /** Name of the event. */ event: EnumOrLiteral; /** {@inheritdoc MessageNotes} */ data: MessageNotes; } /** * Types of stream events returned from Chat Stream API. * * @public */ export declare type StreamEvent = StartEvent | TokenStreamEvent | EndEvent; /** * A function to execute when a {@link StreamEvent} occurs. * * @public */ export declare type StreamEventCallback = (event: Extract; }>) => void; /** * Names of stream events returned from Chat Stream API. * * @public */ export declare enum StreamEventName { /** {@inheritdoc StartEvent} */ StartEvent = "startTokenStream", /** {@inheritdoc TokenStreamEvent} */ TokenStreamEvent = "streamToken", /** {@inheritdoc EndEvent} */ EndEvent = "endStream" } /** * Wrapper class around {@link RawResponse} that provides * an interface for working with Chat's streaming data in * both browser and Node environments. * * @public */ export declare class StreamResponse { /** * {@inheritdoc RawResponse} * * @public */ readonly rawResponse: RawResponse; private streamDataParser; private isConsumed; private eventListeners; constructor(rawResponse: RawResponse); /** * Registers a function that will be called whenever the specified stream event occurs. * * @public * * @param eventName - name of the event to listen * @param cb - callback function to invoke when event occurs */ addEventListener>(eventName: E, cb: StreamEventCallback): void; /** * Reads data from a stream response and invokes callbacks from event * listeners for each chunk of data that is read. * * @remarks * Once the data has been consumed from the stream, this method will * simply return immediately on subsequent calls. * * @public */ consume(): Promise; private consumeWebStream; private consumeNodeStream; private handleEvent; } /** * Data returned from a {@link TokenStreamEvent}. * * @public */ export declare interface TokenStreamData { /** Chunk of data returned from stream response. */ token: string; } /** * An event that carries a partial response. * * @public */ export declare interface TokenStreamEvent { /** Name of the event. */ event: EnumOrLiteral; /** {@inheritdoc TokenStreamData} */ data: TokenStreamData; } /** * Configurations for Zendesk handoff. * * @public */ export declare interface ZendeskHandoff { } export { }