import type { AIToolCallResult, AIToolDefinition } from '@gitbook/api'; import type { IconName } from '@gitbook/icons'; /** * Confirmation action to be displayed to the user before executing a tool. */ export type GitBookToolConfirmation = { icon?: IconName; label: string; /** * Supporting context displayed to the user above the confirmation dialog, * to help them understand what they are approving or rejecting. * Limited to 512 characters. */ context?: string; }; /** * Custom tool definition to be passed to the AI assistant. */ export type GitBookToolDefinition = AIToolDefinition & { /** * Confirmation action to be displayed to the user before executing the tool. * Provide a static object, or a function that receives the input provided by * the AI assistant and returns the confirmation — useful to display dynamic * context based on the arguments the tool is about to be executed with. */ confirmation?: GitBookToolConfirmation | ((input: object) => GitBookToolConfirmation); /** * Callback when the tool is executed. * The input is provided by the AI assistant following the input schema of the tool. */ execute: (input: object) => Promise>; }; /** * Custom button definition to be passed to the embeddable GitBook. */ export type GitBookEmbeddableActionDefinition = { /** * Icon to be displayed in the button. */ icon: IconName; /** * Label to be displayed in the button. */ label: string; /** * Callback when the button is clicked. */ onClick: () => void | Promise; }; /** * Overall configuration for the layout of the GitBook embed. */ export type GitBookEmbeddableConfiguration = { /** Tabs to display in the embed (if enabled on the site). */ tabs: ('assistant' | 'docs' | 'search')[]; /** Tab to open the embed on. */ defaultTab?: 'assistant' | 'docs' | 'search'; /** Page to open the docs tab on, instead of the site's home page. */ defaultPage?: string; /** Additional buttons to be displayed in the header of the GitBook embed. */ actions: GitBookEmbeddableActionDefinition[]; /** * Additional buttons to be displayed in the header of the GitBook embed. * @deprecated Use `actions` instead. */ buttons?: GitBookEmbeddableActionDefinition[]; /** Message to be displayed in the welcome page. */ greeting: { title: string; subtitle: string; }; /** * Override the assistant name displayed in the UI. * Limited to 32 characters. */ assistantName?: string; /** Suggestions of questions to be displayed in the welcome page. */ suggestions: string[]; /** Tools to be provided to the assistant. */ tools: GitBookToolDefinition[]; /** * Display GitBook branding in the embed. */ trademark?: boolean; /** * Display a close button inside the assistant. */ closeButton?: boolean; }; /** * Messages sent from the parent to the frame. */ export type ParentToFrameMessage = | { type: 'postUserMessage'; message: string; } | { type: 'clearChat'; } | { type: 'configure'; settings: GitBookEmbeddableConfiguration; } | { type: 'navigateToPage'; pagePath: string; } | { type: 'navigateToAssistant'; }; /** * Messages sent from the frame to the parent. */ export type FrameToParentMessage = { type: 'close'; };