/************************************************************************* * Copyright 2023 Adobe * All Rights Reserved. * * NOTICE: Adobe permits you to use, modify, and distribute this file in * accordance with the terms of the Adobe license agreement accompanying * it. If you have received this file from a source other than Adobe, * then your use, modification, or distribution of it requires the prior * written permission of Adobe. **************************************************************************/ /** * Internal APIs, meant to be used by Unified Shell only. * @packageDocumentation * @module ai */ import EventEmitter from './src/EventEmitter'; import type { JSX } from 'react'; export interface Prompt { icon: JSX.Element; label: string; name: string; } export interface Source { citationNumber?: number; commentedQuery?: string; commented_query?: string; endIndex: number; startIndex: number; title?: string; url: string; } export interface MultimodalElementItem { alttext: string; caption?: string; height: number; id: string; imgUrl?: string; thumbnailHeight: number; thumbnailUrl: string; thumbnailWidth: number; title: string; transcript?: string; type: string; url: string; videoUrl?: string; width: number; } export interface MultimodalElements { elements: MultimodalElementItem[]; } export interface ToastOptions { actionLabel?: string; placement?: 'top start' | 'top' | 'top end' | 'bottom start' | 'bottom' | 'bottom end'; variant?: 'positive' | 'info' | 'error' | 'neutral' | 'negative' | 'success'; shouldCloseOnAction?: boolean; timeout?: number; onClose?: () => void; onAction?: () => void; } export interface SuccessResponse { answer: string; chatId: string; confidence?: { confidenceLevel?: 'low' | 'high'; confidenceIndicators?: { lowOosConfidenceDetected?: boolean; insufficientContentDetected?: boolean; }; }; customData?: Record; gsdisplayconfig?: any; interactionId: string; internalErrorCode?: string; prompts: Prompt[]; date: Date | null; sources: Source[]; promptSuggestions: string[]; clarifications?: { label: string; value: string; }[]; promptSuggestionsWithPlaceholders?: QuerySuggestion[]; reportingDataDefinition?: any; usageInsights: string; visualizations: any[]; capability: string; request: { message: string; }; uiComponent?: any; multimodalElements?: MultimodalElements; } export interface TemplatePlaceholder { length: number; rawPlaceholder?: string; raw_placeholder?: string; placeholderText?: string; placeholder_text?: string; placeholderType?: string; placeholder_type?: string; displayAttribute?: string; display_attribute?: string; startPosition?: number; start_position?: number; } export interface QuerySuggestion { suggestion: string; tags: Record; placeholders: TemplatePlaceholder[]; itemId?: string; item_id?: string; id?: string; } export interface UserActionResponse { action: string; data?: any; } export interface SystemResponse { message: string; } export interface ErrorResponse { chatId?: string; error: boolean; date: Date | null; interactionId?: string; internalErrorCode?: string; message?: string; requestId?: string; status: number; uiComponent: any; } export type Response = SuccessResponse | UserActionResponse | SystemResponse | ErrorResponse; export declare enum AIMessageType { BUTTON_ACTIVE = "BUTTON_ACTIVE", BUTTON_VISIBLE = "BUTTON_VISIBLE", CLOSE = "CLOSE", CONTEXT = "CONTEXT", ENABLE_ASSISTANT = "ENABLE_ASSISTANT", ERROR = "ERROR", LINK = "LINK", MESSAGE_SUBMISSION = "MESSAGE_SUBMISSION", OPEN = "OPEN", QUERY = "QUERY", RESPONSE = "RESPONSE", SET_USER_PERMISSION = "SET_USER_PERMISSION", USER_ACTION = "USER_ACTION" } export interface AIMessagePayload { /** * The active state of the button. */ buttonActive?: boolean; /** * The visibility of the button. */ buttonVisible?: boolean; /** * The context for the AI chat. */ context?: AIContext; /** * The payload data of the custom event. */ data?: any; /** * Whether the user has permission to use the AI Assistant. */ hasPermission?: boolean; /** * The id of the custom event. */ id?: string; /** * Whether the AI panel is open or closed. */ isOpen?: boolean; /** * The permissions required to enable the AI UI. */ permissions?: string[]; /** * The query that was sent to the AI. */ query?: string; /** * The response from the AI. */ response?: Response; /** * Whether the query should automatically be submitted. */ shouldSubmit?: boolean; /** * The type of message. */ type: AIMessageType; } export interface AIContext { /** * Catch all for now. */ [key: string]: any; } /** * This is the application id sent to the Agent Orchestrator. */ export declare enum AIApplicationId { AEM = "aem", AEP = "aep", CJA = "cja", CJM = "cjm", DATACOLLECTION = "datacollection", GENSTUDIO = "genstudio", IVO = "ivo-ui", SAPPHIRE = "sapphire" } export interface AppContext { mainAppAgentApplicationId?: AIApplicationId; mainAppId: string; mainAppRoot: string; } interface AIMessageEvent { BUTTON_ACTIVE: AIMessagePayload; BUTTON_VISIBLE: AIMessagePayload; CLOSE: AIMessagePayload; CONTEXT: AIMessagePayload; ENABLE_ASSISTANT: AIMessagePayload; ERROR: AIMessagePayload; LINK: AIMessagePayload; MESSAGE_SUBMISSION: AIMessagePayload; OPEN: AIMessagePayload; QUERY: AIMessagePayload; RESPONSE: AIMessagePayload; SET_USER_PERMISSION: AIMessagePayload; USER_ACTION: AIMessagePayload; } export interface AIApi extends EventEmitter { /** * Requests the appid and approot from the application. This is used to * asynchronously request the appid and approot on-demand. * * ***Example:*** * * ```typescript * ai.appContext(); * ``` */ appContext: () => Promise; /** * Sets the context for the AI chat. This can be called unlimited times to * ensure the context has the correct information. This value will be fetched * on every request for context by the AI chat UI when a user submits a query. * Please make sure to keep this value up-to-date when any context values * change within the application. * ***Example:*** * * ```typescript * ai.context = {...}; * ``` */ context?: AIContext; /** * Closes the chat side rail. * * ***Example:*** * * ```typescript * ai.closeChat(); * ``` */ closeChat: () => void; /** * Requests the documentation sources object from the configuration object. * * ***Example:*** * * ```typescript * ai.getDocumentationSources(); * ``` */ getDocumentationSources: () => Promise>>; /** * Requests the context from the application. This is used to asynchronously * request the context on-demand. * * ***Example:*** * * ```typescript * ai.onContextRequest(async () => ({...})); * ``` */ onContextRequest: (callback: () => Promise) => void; /** * Opens the chat side rail with an optional pre-populated query. * By default, the query is automatically submitted. This can be overwritten by setting * the shouldSubmit parameter to false. * * ***Example:*** * * ```typescript * ai.openChat('How do I create a new project?'); // Automatically submits the query * ai.openChat('How do I create a new project?', false); // Populates the chat input but does not auto submit * ``` */ openChat: (query?: string, shouldSubmit?: boolean) => void; /** * Send a message to the AI chat. * * ***Example:*** * * ```typescript * ai.sendMessage({type: AIMessageType.ACTION_COMPLETE}); * ``` */ sendMessage: (payload: AIMessagePayload) => void; /** * Adds a button to the not provisioned dialog that calls a callback function when pressed. * Designed to be used by Workfront to launch their review agreement dialog. * @param callback Function to be called on button click */ setProvisioningButton: (callback: () => void) => void; /** * Sets the user has permission flag for the given application, org, and sandbox. * @param hasPermission Whether the user has permission to use the AI Assistant feature. */ setUserPermission: (hasPermission: boolean) => void; /** * Send a message to Unified Shell to show the Assistant. This includes * permissions that Unified Shell will validate to determine for access. * * ***Example:*** * * ```typescript * ai.showAssistant(['permission1', 'permission2']); * ``` */ showAssistant: (permissions: string[]) => void; /** * Sends a message to Unified Shell to show a toast message. * * ***Example:*** * * ```typescript * ai.showToast('Hello, world!', {position: 'bottom center', variant: 'success'}); */ showToast: (message: string, options: ToastOptions) => void; /** * Sends a message to Unified Shell to change the active status of the Assistant button. * * ***Example:*** * * ```typescript * ai.toggleButtonActive(false); */ toggleButtonActive: (active: boolean) => void; /** * Sends a message to Unified Shell to show the Assistant button. * * ***Example:*** * * ```typescript * ai.toggleButtonVisible(true); */ toggleButtonVisible: (visible: boolean) => void; /** * Sends a message to Unified Shell to toggle the AI panel open or closed. * * ***Example to close the panel:*** * * ```typescript * ai.togglePanel(false); * ``` * * ***Example to open the panel:*** * * ```typescript * ai.togglePanel(true); */ togglePanel: (isOpen: boolean) => void; } declare const ai: AIApi; export default ai;