// Don't import from the generated folder, as it is removed when we build and publish the package. import type { Static, TSchema, Type } from "@sinclair/typebox"; export type Maybe = T | undefined; export interface Scalars { ID: string; String: string; Boolean: boolean; Int: number; Float: number; Upload: any; /** All dates within this schema are ISO-8601 strings without time or timezone. */ Date: any; /** All date-times are supposed to be are ISO-8601 strings, but we do accept input in other formats. That behavior will change and we will replace Date and DateTime's behavior with that of StrictDate. */ DateTime: any; /** A datetime input and output type only accepts ISO-8601 dates. */ StrictDateTimeInput: string; /** General-use Upload input scalar */ FileToUpload: any; /** General-use scalar to use for fields of JSON data. See https://www.npmjs.com/package/graphql-type-json for more information. */ JSONObject: any; /** Represents a rich text document in its native ProseMirror document format. This is a JSON object with a specific schema. Use a TipTap editor instance from the @kazoohr/richtext-components package to interact with this format. */ RichTextDocument: any; } export type AiAssistantConversationMessageRole = /** A message that was sent by the LLM */ | "MODEL" /** A message comes from tool calling. */ | "TOOL" /** A message that was sent by the user. */ | "USER"; export interface Message { __typename?: "Message"; /** The unique identifier of the message. */ id: Scalars["ID"]; /** The role of the message. */ role: AiAssistantConversationMessageRole; /** The text content of the message. */ messageText: Scalars["String"]; /** The conversation that the message belongs to. */ conversationId: Scalars["String"]; /** Optional metadata for the message to store such as toolNames etc */ metadata?: Maybe; } export type AiAssistantSuggestedPromptsProps = { suggestedPrompts: Record; onSelect: (prompt: AiAssistantSuggestedPrompt) => void | Promise; includeGlobalPrompts?: boolean; }; export type AiAssistantSuggestedPrompt = { title: string; fullPrompt?: string; // Allow customization of the suggested action button in the UI className?: string; }; export type SupportedTextModel = "small" | "medium" | "large"; export type ChatItem = { role: "user" | "model" | "tool"; parts: ChatData[]; }; export type ToolDeclaration = { name: string; description: string; /** * A user-friendly, present-tense name for the tool (e.g., "Performing calculations"). * This is shown in the AI Assistant UI while the tool is executing. */ displayName: string; /** * A user-friendly, past-tense name for the tool (e.g., "Performed calculations"). * This is shown in the AI Assistant's debug mode after the tool has finished executing. */ pastTenseDisplayName: string; parameters?: any; /** * Currently unused. Investigate intent and potential removal before using. */ chatItemMatches?: (chatItem: { role: "user" | "model" | "tool"; parts: ChatData[]; }) => boolean; fulfill: (result: Static) => Promise; }; /** * Debug info added during the execution of the AI assistant. */ export type DebugInfo = { time: Date; message: string; data?: any; level: "info" | "error" | "warn"; }[]; export type PropRefs = { onAfterLlmCall?: (messages: Omit[]) => void; onBeforeLlmCall?: () => void; onError?: (error: Error) => void; onChunkAdded?: () => void; tools?: ToolDeclaration[]; model?: SupportedTextModel; /** * The current state of the chat. * * When to access this: * - When you're in async handler functions * - When you're in callbacks * * When NOT to access this: * - When you're in anywhere in the UI state rendering path * * If you're rendering the UI, use the `messages` prop, please. This is for * AI assistant state, which often requires up-to-date state for making * updates. */ messages: ChatStateTree; temperature?: number; isMounted: boolean; systemInstruction?: () => string | Promise; getConversationById: ( conversationId: string ) => ChatStateTree[string] | undefined; getFollowUpSuggestions?: GetFollowUpSuggestions; setFollowUpSuggestionsByConversationId: React.Dispatch< React.SetStateAction> >; handleSendUserMessage: (args: { conversationId?: string; messageText: string; }) => Promise; setPrompt: ( conversationId: string | undefined, prompt: string | ((prev: string) => string) ) => void; onSelectedConversationChange?: ( conversationId: string | undefined, messages: ChatStateTree ) => void; selectedConversationId: string | undefined; onSelectedConversationLoaded?: ( /** * The conversation that loaded. */ conversationId: string | undefined, /** * The conversation that is currently selected */ selectedConversationId: string | undefined, messages: ChatStateTree ) => void; sendMessages: (conversationId: string) => Promise; setMessages: React.Dispatch>; }; export type ChatData = | ChatDataText | ChatDataToolCall | ChatDataToolResult | ChatDataFile; export type ChatDataText = { type: "text"; text: string }; export type ChatDataFile = { type: "file"; toolName: string; fileUri: string; mimeType: string; args?: unknown; }; export type ChatDataToolCall = { type: "toolCall"; toolName: string; args: Record; }; export type ChatDataToolResult = { type: "toolResult"; toolName: string; args?: unknown; result: string; }; export type ChatHistoryItem = { title: string; messages: any[]; [key: string]: any; }; export type GetFollowUpSuggestions = (args: { conversation: ChatStateTree[string]; }) => Promise; export type ChatHistory = Record; export type ChatSizes = "half" | "full"; export type AiAssistantControls = { /** * Set the prompt to use for the AI assistant. * @param prompt - The prompt to set. * @param submit - Whether to submit the prompt to the AI assistant once the new prompt is set. */ setPrompt?: (prompt: string, submit?: boolean) => void; }; export type AiAssistantProps = { /** * The title to display in the window. Default: "WorkTango AI Assistant". */ windowTitle?: React.ReactNode; /** * The full suite of tools to use for the AI assistant. */ tools?: ToolDeclaration[]; /** * Whether to enable debug mode. Default: false. */ enableDebug?: boolean; /** * Whether to enable voice features. Default: false. */ enableVoiceFeatures?: boolean; /** * The function to call when the AI assistant is closed. */ onClose: () => void; /** * This is a callback event that is invoked when the user sends a message. */ onSendMessage?: (message: string) => void; /** * Whether to show a close button in the chat window. Default: true. */ hasCloseButton?: boolean; /** * The zero state to display when the chat window is empty. */ chatWindowZeroState?: React.ReactNode; /** * Whether to show a button to toggle the chat size. Default: true. */ hasToggleChatSizeButton?: boolean; /** * If true, the chat history (list of past conversations) will be shown, by default */ hasChatHistory?: boolean; /** * The initial width of the chat window. Default: "default". */ startingWidth?: ChatSizes; /** * The system instruction to use for the AI assistant. */ systemInstruction?: () => string | Promise; /** * The initial prompt to use for the AI assistant. */ initialPrompt?: string; /** * A ref to the controls object for the AI assistant. Used to allow some form * of control over the AI assistant from outside the component, allowing things * like recommended prompts to be set from outside the component. */ controls?: React.MutableRefObject; /** * Whether to show the chat history by default. Default: true. */ chatHistoryShownByDefault?: boolean; /** * Otherwise, if there's a chat history, we start with the latest history, so * the user can continue the previous conversation. */ startWithNewChat?: boolean; /** * The minimum number of characters that must be entered before the user can * submit a message. Default: 5. */ minimumCharacterCount?: number; /** * The ID of the conversation to start with. If not provided, a new conversation will be created. */ initialConversationId?: string; /** * Returns a set of follow-up suggestions for the given conversation. */ getFollowUpSuggestions?: GetFollowUpSuggestions; /** * Invoked with a raw string of the chat (in plain text) to get a possible title */ getChatTitle?: (chat: string) => Promise; /** * The model size to use for the AI assistant. Default: "large". */ model?: SupportedTextModel; /** * Whether to enable the AI response rating component. Default: false. * Cannot bundle feature-flags-react in packages/ai-assistant so this is how we have to pass feature flags to the Ai Assistant. */ enableResponseRating?: boolean; }; export type ChatStateTree = Record< string, { id: string; title: string; isUpdatingTitle?: boolean; updatedAt: Date; isLoading: boolean; messages: Omit[]; } >; // ChatItem augmented with some UI stuff export type AugmentedChatItem = ChatItem & { id?: string; timestamp?: Date; isPending?: boolean; filterFromApiCalls?: boolean; }; /** * If { loading: true }, a small loader will be shown. You can use this show a * loading state in any place of the UI. */ export type FollowUpSuggestion = | { type: "loading"; id?: string } | { type?: "suggestion"; /** * A unique identifier for the follow-up suggestion. This will be used to keep user-level state for dismissed items. */ id: string; /** * The title of the follow-up suggestion. This will be displayed in the UI as a pill button, so keep it short. */ title: string; /** * The function to call when the follow-up suggestion is clicked. */ onClick: () => void; /** * Optional CSS class name for custom styling of the pill. */ className?: string; }; export interface Conversation { id: string; title: string; updatedAt?: Date; messages: { conversationId: string; id: string; messageText: string; role: string; }[]; } export type GetStructuredResponseOptions = { model?: SupportedTextModel | undefined; temperature?: number | undefined; prompt: string; schema: (t: typeof Type) => T; }; export type GetChatCompletionOptions = { model?: SupportedTextModel | undefined; temperature?: number | undefined; systemInstruction?: string | undefined; stream?: boolean; messages: ChatItem[]; tools?: ToolDeclaration[] | undefined; onChunk?: (chunk: ChatData) => void; onError?: (error: Error) => void; onComplete?: () => void; };