import { ChatAPI } from './ChatAPI'; import { KamanFile } from './FileExplorerAPI'; import { AvatarConfig, AvatarStatus } from '../components/Avatar/types'; export interface KamanTextRequest { type: "text"; text: string; } export interface KamanFileRequest { type: "file"; files: { url: string; mimeType: string; fileName: string; fileId?: string; }[]; text: string; } export interface KamanUserRequest { type: "user"; value: any; } export type KamanRequest = KamanTextRequest | KamanFileRequest | KamanUserRequest; export interface KamanDoRequest { sessionId: string; input: KamanRequest; expertId: string; appDetails?: any; assistantMessageId?: string; uiTools?: FunctionType[]; runtimeKnowledgeBases?: (string | number)[]; replaceExpertKbs?: boolean; modelOverride?: string; } export type FieldType = "string" | "number" | "boolean" | "object" | "array" | "date" | "file" | "binary"; export interface Field { name: string; description: string; type: FieldType; innerFields?: Field[]; required: boolean; default?: any; or?: Field[]; } export interface FunctionType { name: string; description: string; sync?: boolean; inputFields: Field[]; outputFields?: Field[]; userFields?: Field[]; func: (args: Record) => Promise | any; } export interface AvailableCredential { id: number; name: string; createdAt: string; } export interface ToolConfirmationOption { value: 'approve' | 'approve_session' | 'reject'; label: string; } export interface Interrupt { value: { error: string; message: string; fieldsNeeded?: Record; instanceId?: string; oauthConfig?: Record; credentialsRequired?: boolean; credentialSelection?: boolean; resourceType?: 'mcp' | 'plugin'; resourceId?: number; resourceName?: string; missingFields?: string[]; availableCredentials?: AvailableCredential[]; type?: 'tool_confirmation' | 'credentials' | 'oauth' | 'form' | 'iteration_limit'; toolName?: string; stats?: { llmCalls: number; toolCalls: number; thinkIterations: number; totalIterations: number; limits: { maxLlmCalls: number; maxToolCalls: number; maxThinkIterations: number; maxTotalIterations: number; }; }; toolArgs?: any; toolCallId?: string; options?: ToolConfirmationOption[]; [k: string]: unknown; }; when: string; resumable: boolean; ns: string[]; } /** * Tool progress event - sent during tool execution to show real-time progress */ export type ToolProgressStatus = 'starting' | 'completed' | 'failed'; export interface ToolProgress { toolName: string; toolCallId: string; status: ToolProgressStatus; args?: any; result?: string; error?: string; duration?: number; index?: number; total?: number; /** Sub-agent thread ID for fetching message history */ threadId?: string; } /** * Plan step status */ export type PlanStepStatus = "pending" | "in_progress" | "completed" | "skipped"; /** * Plan step structure */ export interface PlanStep { id: number; description: string; status: PlanStepStatus; notes?: string; } /** * Plan data from agent */ export interface PlanData { goal: string; steps: PlanStep[]; currentStep?: number; progress?: number; } /** * Structured error from agent */ export interface StructuredError { category: string; message: string; userMessage: string; isRetryable: boolean; suggestedAction?: string; technicalDetails?: string; } /** * Thinking state from agent */ export interface ThinkingState { phase: string; confidence: string; thoughtCount: number; budget: number; hasUncertainties: boolean; decisionCount: number; currentThought?: string; } /** * Marketplace tool suggestion from agent - tool the user could install */ export interface MarketplaceTool { pluginId: number; pluginName: string; description: string; icon?: string; category?: string; pricing?: { model: string; pricePerUnit?: number; }; rating?: number; type?: string; functions?: string[]; } export interface Message { id: string; content: string; role: "user" | "assistant"; timestamp: Date; attachments?: Array<{ id: string; name: string; type: string; url: string; }>; interrupt?: Array; suggestions?: Array; thought?: string; toolProgress?: ToolProgress; toolProgressHistory?: ToolProgress[]; plan?: PlanData; status?: 'sending' | 'queued' | 'sent'; isError?: boolean; localHistory?: any[]; structuredError?: StructuredError; thinkingState?: ThinkingState; marketplaceTools?: MarketplaceTool[]; mamProgress?: { status: string; message: string; assetCount?: number; }; assetPreview?: { tagId: string; type: string; sourceUrl: string; description: string; }; vmStatus?: { status: "provisioning" | "ready" | "error"; vmSessionId?: string; error?: string; }; hidden?: boolean; } /** * Auto-greet mode for the chatbot. * - "static": Show a hardcoded text as the first assistant message * - "personalized": Pick a greeting from autoGreetMessages based on autoGreetPersona * - "auto-hi": Silently send "hi" to the agent, show the response, hide the user's "hi" */ export type AutoGreetMode = "static" | "personalized" | "auto-hi"; export interface ChatSession { id: string; title: string; lastMessage?: string; lastUpdated: Date; messages: Message[]; isPinned?: boolean; } export interface ChatContextType { sessions: ChatSession[]; currentSessionId: string | null; currentArtifacts: any | null; isHistoryOpen: boolean; isArtifactOpen: boolean; currentUserId: string; expertId: string; baseUrl: string | undefined; chatApi: ChatAPI | undefined; apiKey?: string; token?: string; showAppsSelection?: boolean; skipWelcomeInput?: boolean; initialPrompt?: string; autoGreet?: AutoGreetMode; autoGreetMessage?: string; autoGreetMessages?: Record; autoGreetPersona?: string; appDetail?: any; expertDetails?: any; currentArtifact?: any; showInfoButton?: boolean; showThinking?: boolean; expertName?: string; isProcessingMessage?: boolean; currentToolProgress?: ToolProgress | null; currentPlan?: PlanData | null; totalSessions?: number; isLoadingMoreSessions?: boolean; avatarConfig?: AvatarConfig | null; avatarStatus?: AvatarStatus; avatarEnabled?: boolean; avatarMuted?: boolean; playAvatarTTS?: (text: string) => Promise; stopAvatarAudio?: () => void; toggleAvatarMute?: (muted: boolean) => void; lipsyncManager?: any; createSession: (title?: string) => void; switchSession: (sessionId: string) => void; renameSession: (sessionId: string, newTitle: string) => void; deleteSession: (sessionId: string) => void; pinSession: (sessionId: string) => void; unpinSession: (sessionId: string) => void; sendMessage: (content: string, attachments?: (File | KamanFile)[], humanInput?: any, existingMessageId?: string) => void; stopChat: () => Promise; resumeActiveStream: (sessionId: string) => Promise; toggleHistory: () => void; toggleArtifact: () => void; setCurrentArtifacts: (artifact: any) => void | ((f: (prev: any) => any) => void); changeExpert?: (expertId: string) => void; setCurrentArtifact: (artifact: any) => void; setSessions: (f: (prev: ChatSession[]) => ChatSession[]) => void; loadMoreSessions?: () => Promise; selectedModel?: string | null; availableModels?: any[]; setSelectedModel?: (model: string | null) => void; refreshModels?: () => Promise; rateLimitInfo?: { limitType: string; limitValue?: number; currentUsage?: number; retryAfterSeconds: number; resetAt?: string; message?: string; } | null; pendingRateLimitMessage?: string | null; retryAfterRateLimit?: () => void; dismissRateLimit?: () => void; registerToolHandler?: (id: string, handler: (toolName: string, args: Record) => Promise | any | null) => void; unregisterToolHandler?: (id: string) => void; registerToolDefinitions?: (id: string, getTools: () => FunctionType[]) => void; unregisterToolDefinitions?: (id: string) => void; } export type { AvatarConfig, AvatarStatus };