@meetsmore-oss/use-ai-client 1.9.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundled.js +3964 -1253
- package/dist/bundled.js.map +1 -1
- package/dist/index.d.ts +547 -539
- package/dist/index.js +182 -72
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
- package/dist/chunk-STF3H6F5.js +0 -13
- package/dist/chunk-STF3H6F5.js.map +0 -1
- package/dist/chunk-UM4UCU4W.js +0 -46
- package/dist/chunk-UM4UCU4W.js.map +0 -1
- package/dist/types-GWPQMSYT.js +0 -9
- package/dist/types-GWPQMSYT.js.map +0 -1
- package/dist/types-RJZTRF3U.js +0 -9
- package/dist/types-RJZTRF3U.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export { z } from 'zod';
|
|
3
|
-
import { ToolAnnotations, ToolDefinition, WorkflowStatus,
|
|
3
|
+
import { ToolAnnotations, ToolDefinition, WorkflowStatus, MultimodalContent, UseAIForwardedProps, AGUIEvent, Message as Message$1, AgentInfo, UseAIClientMessage, FeedbackValue, ToolApprovalRequestEvent } from '@meetsmore-oss/use-ai-core';
|
|
4
4
|
export { AgentInfo, ToolAnnotations, ToolDefinition } from '@meetsmore-oss/use-ai-core';
|
|
5
5
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
6
|
import React$1, { MutableRefObject, RefObject, ReactNode } from 'react';
|
|
@@ -325,6 +325,245 @@ interface UseAIConfig {
|
|
|
325
325
|
serverUrl: string;
|
|
326
326
|
}
|
|
327
327
|
|
|
328
|
+
/**
|
|
329
|
+
* Handler for AG-UI events from the server.
|
|
330
|
+
*/
|
|
331
|
+
type AGUIEventHandler = (event: AGUIEvent) => void;
|
|
332
|
+
/**
|
|
333
|
+
* Simplified message handler for text responses.
|
|
334
|
+
*/
|
|
335
|
+
type MessageHandler = (content: string) => void;
|
|
336
|
+
/**
|
|
337
|
+
* Tool call handler that receives the tool name, arguments, and a callback to send the result.
|
|
338
|
+
*/
|
|
339
|
+
type ToolCallHandler = (toolCallId: string, toolName: string, args: Record<string, unknown>) => void;
|
|
340
|
+
/**
|
|
341
|
+
* Socket.IO client for communicating with the UseAI server.
|
|
342
|
+
* Uses the AG-UI protocol (https://docs.ag-ui.com/), so will be compatible with other AG-UI compliant servers.
|
|
343
|
+
*
|
|
344
|
+
* Handles:
|
|
345
|
+
* - Connection management and automatic reconnection
|
|
346
|
+
* - Sending RunAgentInput messages to server
|
|
347
|
+
* - Parsing AG-UI event streams from server
|
|
348
|
+
* - Tool execution coordination
|
|
349
|
+
*
|
|
350
|
+
* You probably don't need to use this directly, instead use {@link UseAIProvider}.
|
|
351
|
+
*/
|
|
352
|
+
declare class UseAIClient {
|
|
353
|
+
private serverUrl;
|
|
354
|
+
private socket;
|
|
355
|
+
private eventHandlers;
|
|
356
|
+
private reconnectAttempts;
|
|
357
|
+
private maxReconnectAttempts;
|
|
358
|
+
private reconnectDelay;
|
|
359
|
+
private _threadId;
|
|
360
|
+
private _tools;
|
|
361
|
+
private _messages;
|
|
362
|
+
private _state;
|
|
363
|
+
private _availableAgents;
|
|
364
|
+
private _defaultAgent;
|
|
365
|
+
private _selectedAgent;
|
|
366
|
+
private agentsChangeHandlers;
|
|
367
|
+
private connectionStateHandlers;
|
|
368
|
+
private _currentMessageId;
|
|
369
|
+
private _currentMessageContent;
|
|
370
|
+
private _currentAssistantMessage;
|
|
371
|
+
private _currentAssistantToolCalls;
|
|
372
|
+
private _pendingToolResults;
|
|
373
|
+
private currentToolCalls;
|
|
374
|
+
private _langfuseEnabled;
|
|
375
|
+
private langfuseConfigHandlers;
|
|
376
|
+
/**
|
|
377
|
+
* Creates a new UseAI client instance.
|
|
378
|
+
*
|
|
379
|
+
* @param serverUrl - The WebSocket URL of the UseAI server
|
|
380
|
+
*/
|
|
381
|
+
constructor(serverUrl: string);
|
|
382
|
+
/**
|
|
383
|
+
* Establishes a Socket.IO connection to the server.
|
|
384
|
+
* Connection state changes are notified via onConnectionStateChange().
|
|
385
|
+
* Socket.IO handles reconnection automatically.
|
|
386
|
+
*/
|
|
387
|
+
connect(): void;
|
|
388
|
+
private handleEvent;
|
|
389
|
+
/**
|
|
390
|
+
* Registers available tools and optional state with the server.
|
|
391
|
+
* This updates the session state for future agent runs.
|
|
392
|
+
*
|
|
393
|
+
* @param tools - Array of tool definitions to register
|
|
394
|
+
* @param state - Optional state object to provide to the AI.
|
|
395
|
+
*/
|
|
396
|
+
registerTools(tools: ToolDefinition[], state?: unknown): void;
|
|
397
|
+
/**
|
|
398
|
+
* Updates the state without re-registering tools.
|
|
399
|
+
* Call this before sendPrompt to ensure the AI sees the latest UI state.
|
|
400
|
+
*
|
|
401
|
+
* @param state - The current state object to provide to the AI
|
|
402
|
+
*/
|
|
403
|
+
updateState(state: unknown): void;
|
|
404
|
+
/**
|
|
405
|
+
* Sends a user prompt to the AI.
|
|
406
|
+
*
|
|
407
|
+
* @param prompt - The user's prompt/question (text part)
|
|
408
|
+
* @param multimodalContent - Optional multimodal content (text, images, files)
|
|
409
|
+
* @param forwardedProps - Optional props to forward to the server (e.g., telemetryMetadata, mcpHeaders).
|
|
410
|
+
* Internally merged with other forwardedProps.
|
|
411
|
+
*/
|
|
412
|
+
sendPrompt(prompt: string, multimodalContent?: MultimodalContent[], forwardedProps?: UseAIForwardedProps): Promise<void>;
|
|
413
|
+
/**
|
|
414
|
+
* Sends the result of a tool execution back to the server.
|
|
415
|
+
*
|
|
416
|
+
* @param toolCallId - The ID of the tool call being responded to
|
|
417
|
+
* @param result - The result returned by the tool execution
|
|
418
|
+
* @param state - Optional updated state to send back to the AI
|
|
419
|
+
*/
|
|
420
|
+
sendToolResponse(toolCallId: string, result: unknown, state?: unknown): void;
|
|
421
|
+
/**
|
|
422
|
+
* Sends a tool approval response back to the server.
|
|
423
|
+
*
|
|
424
|
+
* @param toolCallId - The ID of the tool call being approved/rejected
|
|
425
|
+
* @param approved - Whether the tool execution is approved
|
|
426
|
+
* @param reason - Optional reason for rejection (shown to AI)
|
|
427
|
+
*/
|
|
428
|
+
sendToolApprovalResponse(toolCallId: string, approved: boolean, reason?: string): void;
|
|
429
|
+
/**
|
|
430
|
+
* Retrieves accumulated tool call data for a specific tool call ID.
|
|
431
|
+
* Used to get the complete tool name and arguments after they've been streamed
|
|
432
|
+
* across multiple TOOL_CALL_ARGS events.
|
|
433
|
+
*
|
|
434
|
+
* @param toolCallId - The ID of the tool call
|
|
435
|
+
* @returns Object with tool name and accumulated arguments, or undefined if not found
|
|
436
|
+
*/
|
|
437
|
+
getToolCallData(toolCallId: string): {
|
|
438
|
+
name: string;
|
|
439
|
+
args: string;
|
|
440
|
+
} | undefined;
|
|
441
|
+
/**
|
|
442
|
+
* Registers an AG-UI event handler for receiving server events.
|
|
443
|
+
*
|
|
444
|
+
* @param id - Unique identifier for this handler
|
|
445
|
+
* @param handler - Callback function to handle incoming AG-UI events
|
|
446
|
+
* @returns Cleanup function to unregister the handler
|
|
447
|
+
*/
|
|
448
|
+
onEvent(id: string, handler: AGUIEventHandler): () => void;
|
|
449
|
+
/**
|
|
450
|
+
* Helper method to listen for text message content.
|
|
451
|
+
* Aggregates TEXT_MESSAGE_CONTENT events and calls handler with complete messages.
|
|
452
|
+
*
|
|
453
|
+
* @param handler - Callback function to handle complete text messages
|
|
454
|
+
* @returns Cleanup function
|
|
455
|
+
*/
|
|
456
|
+
onTextMessage(handler: MessageHandler): () => void;
|
|
457
|
+
/**
|
|
458
|
+
* Helper method to listen for tool call requests.
|
|
459
|
+
* Aggregates TOOL_CALL_* events and calls handler with complete tool calls.
|
|
460
|
+
*
|
|
461
|
+
* @param handler - Callback function to handle tool calls
|
|
462
|
+
* @returns Cleanup function
|
|
463
|
+
*/
|
|
464
|
+
onToolCall(handler: ToolCallHandler): () => void;
|
|
465
|
+
/**
|
|
466
|
+
* Gets the current accumulated message content (useful during streaming).
|
|
467
|
+
*/
|
|
468
|
+
get currentMessageContent(): string;
|
|
469
|
+
/**
|
|
470
|
+
* Gets the current thread ID for this session.
|
|
471
|
+
* Generates a new one if not set.
|
|
472
|
+
*/
|
|
473
|
+
get threadId(): string;
|
|
474
|
+
/**
|
|
475
|
+
* Gets the current conversation messages.
|
|
476
|
+
*/
|
|
477
|
+
get messages(): Message$1[];
|
|
478
|
+
/**
|
|
479
|
+
* Gets the current state.
|
|
480
|
+
*/
|
|
481
|
+
get state(): unknown;
|
|
482
|
+
/**
|
|
483
|
+
* Gets the list of available agents from the server.
|
|
484
|
+
*/
|
|
485
|
+
get availableAgents(): AgentInfo[];
|
|
486
|
+
/**
|
|
487
|
+
* Gets the default agent ID from the server.
|
|
488
|
+
*/
|
|
489
|
+
get defaultAgent(): string | null;
|
|
490
|
+
/**
|
|
491
|
+
* Gets the currently selected agent ID.
|
|
492
|
+
* Returns null if using server default.
|
|
493
|
+
*/
|
|
494
|
+
get selectedAgent(): string | null;
|
|
495
|
+
/**
|
|
496
|
+
* Gets the effective agent ID (selected or default).
|
|
497
|
+
*/
|
|
498
|
+
get currentAgent(): string | null;
|
|
499
|
+
/**
|
|
500
|
+
* Sets the agent to use for requests.
|
|
501
|
+
* Pass null to use the server default.
|
|
502
|
+
*
|
|
503
|
+
* @param agentId - The agent ID to use, or null for server default
|
|
504
|
+
*/
|
|
505
|
+
setAgent(agentId: string | null): void;
|
|
506
|
+
/**
|
|
507
|
+
* Subscribes to agent changes (when server sends available agents).
|
|
508
|
+
*
|
|
509
|
+
* @param handler - Callback function receiving agents list and default agent
|
|
510
|
+
* @returns Cleanup function to unsubscribe
|
|
511
|
+
*/
|
|
512
|
+
onAgentsChange(handler: (agents: AgentInfo[], defaultAgent: string | null) => void): () => void;
|
|
513
|
+
/**
|
|
514
|
+
* Subscribes to connection state changes.
|
|
515
|
+
* This is called on both initial connection and reconnection.
|
|
516
|
+
*
|
|
517
|
+
* @param handler - Callback function receiving connection state (true = connected, false = disconnected)
|
|
518
|
+
* @returns Cleanup function to unsubscribe
|
|
519
|
+
*/
|
|
520
|
+
onConnectionStateChange(handler: (connected: boolean) => void): () => void;
|
|
521
|
+
/**
|
|
522
|
+
* Sets the thread ID for this session.
|
|
523
|
+
* When the thread ID changes, conversation state is cleared to prevent history bleeding.
|
|
524
|
+
* Use this when switching between different chat conversations.
|
|
525
|
+
*
|
|
526
|
+
* @param threadId - The thread/chat ID to use (typically the chatId)
|
|
527
|
+
*/
|
|
528
|
+
setThreadId(threadId: string): void;
|
|
529
|
+
/**
|
|
530
|
+
* Loads messages into the conversation history (for resuming from storage).
|
|
531
|
+
* @param messages - Array of messages to load
|
|
532
|
+
*/
|
|
533
|
+
loadMessages(messages: Message$1[]): void;
|
|
534
|
+
/**
|
|
535
|
+
* Clears the conversation history and resets the thread.
|
|
536
|
+
*/
|
|
537
|
+
clearConversation(): void;
|
|
538
|
+
send(message: UseAIClientMessage): void;
|
|
539
|
+
/**
|
|
540
|
+
* Closes the Socket.IO connection to the server.
|
|
541
|
+
*/
|
|
542
|
+
disconnect(): void;
|
|
543
|
+
/**
|
|
544
|
+
* Checks if the client is currently connected to the server.
|
|
545
|
+
*
|
|
546
|
+
* @returns true if connected, false otherwise
|
|
547
|
+
*/
|
|
548
|
+
isConnected(): boolean;
|
|
549
|
+
/**
|
|
550
|
+
* Subscribes to Langfuse config changes.
|
|
551
|
+
*
|
|
552
|
+
* @param handler - Callback function receiving langfuse enabled status
|
|
553
|
+
* @returns Cleanup function to unsubscribe
|
|
554
|
+
*/
|
|
555
|
+
onLangfuseConfigChange(handler: (enabled: boolean) => void): () => void;
|
|
556
|
+
/**
|
|
557
|
+
* Submits feedback for an assistant message.
|
|
558
|
+
* Sends feedback to the server, which forwards it to Langfuse.
|
|
559
|
+
*
|
|
560
|
+
* @param messageId - The client-side message ID
|
|
561
|
+
* @param traceId - The Langfuse trace ID (runId from RUN_FINISHED)
|
|
562
|
+
* @param feedback - 'upvote' for positive, 'downvote' for negative, null to remove
|
|
563
|
+
*/
|
|
564
|
+
submitFeedback(messageId: string, traceId: string, feedback: FeedbackValue): void;
|
|
565
|
+
}
|
|
566
|
+
|
|
328
567
|
/**
|
|
329
568
|
* Default maximum file size (10MB)
|
|
330
569
|
*/
|
|
@@ -476,7 +715,7 @@ type ChatMetadata = Record<string, unknown>;
|
|
|
476
715
|
* Display mode for chat messages.
|
|
477
716
|
* Determines the visual styling of the message bubble.
|
|
478
717
|
*/
|
|
479
|
-
type MessageDisplayMode
|
|
718
|
+
type MessageDisplayMode = 'default' | 'error';
|
|
480
719
|
/**
|
|
481
720
|
* Text content part for persisted messages.
|
|
482
721
|
*/
|
|
@@ -506,17 +745,38 @@ type PersistedMessageContent = string | PersistedContentPart[];
|
|
|
506
745
|
* Message format for persisted chat history.
|
|
507
746
|
* Compatible with AI SDK's UIMessage format for future integration.
|
|
508
747
|
*/
|
|
748
|
+
/**
|
|
749
|
+
* Tool call entry on an assistant message.
|
|
750
|
+
* Matches the AG-UI MessageToolCall format.
|
|
751
|
+
*/
|
|
752
|
+
interface PersistedToolCall {
|
|
753
|
+
/** @example "toolu_01abc123" */
|
|
754
|
+
id: string;
|
|
755
|
+
type: 'function';
|
|
756
|
+
function: {
|
|
757
|
+
name: string;
|
|
758
|
+
/** JSON-serialized arguments */
|
|
759
|
+
arguments: string;
|
|
760
|
+
};
|
|
761
|
+
}
|
|
509
762
|
interface PersistedMessage {
|
|
510
763
|
id: string;
|
|
511
764
|
role: 'user' | 'assistant' | 'tool';
|
|
512
765
|
/** Content can be a string or multimodal content array */
|
|
513
766
|
content: PersistedMessageContent;
|
|
514
767
|
createdAt: Date;
|
|
515
|
-
displayMode?: MessageDisplayMode
|
|
768
|
+
displayMode?: MessageDisplayMode;
|
|
516
769
|
/** Langfuse trace ID for feedback tracking (only for assistant messages) */
|
|
517
770
|
traceId?: string;
|
|
518
771
|
/** User feedback on this message (only for assistant messages) */
|
|
519
772
|
feedback?: FeedbackValue;
|
|
773
|
+
/** Tool calls made by the assistant in this message (only for assistant messages) */
|
|
774
|
+
toolCalls?: PersistedToolCall[];
|
|
775
|
+
/**
|
|
776
|
+
* ID of the tool call this message is a result of (only for tool messages)
|
|
777
|
+
* @example "toolu_01abc123"
|
|
778
|
+
*/
|
|
779
|
+
toolCallId?: string;
|
|
520
780
|
}
|
|
521
781
|
/**
|
|
522
782
|
* Represents a stored chat conversation.
|
|
@@ -659,11 +919,137 @@ declare function generateCommandId(): string;
|
|
|
659
919
|
*/
|
|
660
920
|
declare function validateCommandName(name: string): string | null;
|
|
661
921
|
|
|
922
|
+
interface RegisterToolsOptions {
|
|
923
|
+
/** Mark component as invisible (no visual state, skip prompt wait) */
|
|
924
|
+
invisible?: boolean;
|
|
925
|
+
}
|
|
662
926
|
/**
|
|
663
|
-
*
|
|
664
|
-
* Use for internationalization (i18n) or branding.
|
|
927
|
+
* Pending tool approval request state.
|
|
665
928
|
*/
|
|
666
|
-
|
|
929
|
+
interface PendingToolApproval {
|
|
930
|
+
toolCallId: string;
|
|
931
|
+
toolCallName: string;
|
|
932
|
+
toolCallArgs: Record<string, unknown>;
|
|
933
|
+
annotations?: ToolAnnotations;
|
|
934
|
+
/** Optional message explaining why approval is needed (runtime approval) */
|
|
935
|
+
message?: string;
|
|
936
|
+
/** Optional metadata for the approval request (runtime approval) */
|
|
937
|
+
metadata?: Record<string, unknown>;
|
|
938
|
+
}
|
|
939
|
+
interface UseToolSystemOptions {
|
|
940
|
+
/** Reference to the UseAI client for sending responses */
|
|
941
|
+
clientRef: RefObject<UseAIClient | null>;
|
|
942
|
+
/** Builds the aggregated state from all registered prompts */
|
|
943
|
+
buildState: () => unknown;
|
|
944
|
+
}
|
|
945
|
+
interface UseToolSystemReturn {
|
|
946
|
+
/** Registers tools for a specific component */
|
|
947
|
+
registerTools: (id: string, tools: ToolsDefinition, options?: RegisterToolsOptions) => void;
|
|
948
|
+
/** Unregisters tools for a specific component */
|
|
949
|
+
unregisterTools: (id: string) => void;
|
|
950
|
+
/** Checks if a component is marked as invisible */
|
|
951
|
+
isInvisible: (id: string) => boolean;
|
|
952
|
+
/** All tools aggregated from registered components */
|
|
953
|
+
aggregatedTools: ToolsDefinition;
|
|
954
|
+
/** Whether any tools are registered */
|
|
955
|
+
hasTools: boolean;
|
|
956
|
+
/** Ref to current aggregated tools (for use in closures) */
|
|
957
|
+
aggregatedToolsRef: MutableRefObject<ToolsDefinition>;
|
|
958
|
+
/** Signals that a component has completed its registration in useLayoutEffect */
|
|
959
|
+
signalReady: (id: string) => void;
|
|
960
|
+
/** Current tool registry version (increments when tools change) */
|
|
961
|
+
toolRegistryVersion: number;
|
|
962
|
+
/** Registers a waiter function for a component (called when tool exec needs to wait for re-render) */
|
|
963
|
+
registerWaiter: (id: string, waiter: () => Promise<void>) => void;
|
|
964
|
+
/** Unregisters a waiter function */
|
|
965
|
+
unregisterWaiter: (id: string) => void;
|
|
966
|
+
/** All pending tool approval requests */
|
|
967
|
+
pendingApprovals: PendingToolApproval[];
|
|
968
|
+
/** Handle a tool approval request event from the server */
|
|
969
|
+
handleApprovalRequest: (event: ToolApprovalRequestEvent) => void;
|
|
970
|
+
/** Execute a tool call and send the response to the server */
|
|
971
|
+
executeToolCall: (toolCallId: string, name: string, input: unknown) => Promise<void>;
|
|
972
|
+
/** Store a tool call as pending approval (deferred execution) */
|
|
973
|
+
storePendingToolCall: (toolCallId: string, name: string, input: unknown, toolCallData: {
|
|
974
|
+
name: string;
|
|
975
|
+
args: string;
|
|
976
|
+
}) => void;
|
|
977
|
+
/** Approve all pending tool calls and execute them */
|
|
978
|
+
approveAll: () => Promise<void>;
|
|
979
|
+
/** Reject all pending tool calls with optional reason */
|
|
980
|
+
rejectAll: (reason?: string) => void;
|
|
981
|
+
}
|
|
982
|
+
/**
|
|
983
|
+
* Unified hook for the tool lifecycle: registration, waiter coordination,
|
|
984
|
+
* and execution (including approval flow).
|
|
985
|
+
*
|
|
986
|
+
* Merges what were previously three separate concerns:
|
|
987
|
+
* - Tool registry (registration, aggregation, ownership tracking)
|
|
988
|
+
* - Waiters (waiting for component re-renders after tool execution)
|
|
989
|
+
* - Tool execution (running tools, sending responses, approval flow)
|
|
990
|
+
*
|
|
991
|
+
* The only external dependency is `buildState` from prompt management,
|
|
992
|
+
* which provides the aggregated app state sent alongside tool responses.
|
|
993
|
+
*/
|
|
994
|
+
declare function useToolSystem({ clientRef, buildState, }: UseToolSystemOptions): UseToolSystemReturn;
|
|
995
|
+
|
|
996
|
+
/**
|
|
997
|
+
* Options for programmatically sending a message via sendMessage().
|
|
998
|
+
*/
|
|
999
|
+
interface SendMessageOptions {
|
|
1000
|
+
/** Start a new chat before sending. Default: false (continue existing chat) */
|
|
1001
|
+
newChat?: boolean;
|
|
1002
|
+
/** File attachments to include with the message */
|
|
1003
|
+
attachments?: File[];
|
|
1004
|
+
/** Open the chat panel after sending. Default: true */
|
|
1005
|
+
openChat?: boolean;
|
|
1006
|
+
/** Metadata to set on the new chat (only used when newChat: true) */
|
|
1007
|
+
metadata?: ChatMetadata;
|
|
1008
|
+
/**
|
|
1009
|
+
* Forwarded props for observability and configuration (e.g., telemetryMetadata, mcpHeaders).
|
|
1010
|
+
* This is merged with provider-level forwardedProps (message-level takes precedence).
|
|
1011
|
+
*/
|
|
1012
|
+
forwardedProps?: UseAIForwardedProps;
|
|
1013
|
+
}
|
|
1014
|
+
interface UseMessageQueueOptions {
|
|
1015
|
+
/** The function that actually sends a message (the provider's handleSendMessage) */
|
|
1016
|
+
sendFn: (message: string, attachments?: FileAttachment[], forwardedProps?: UseAIForwardedProps) => Promise<void>;
|
|
1017
|
+
/** Creates a new chat */
|
|
1018
|
+
createNewChat: (options?: CreateChatOptions) => Promise<string>;
|
|
1019
|
+
/** Callback to open/close the chat panel */
|
|
1020
|
+
setOpen?: (open: boolean) => void;
|
|
1021
|
+
/** Whether the client is connected */
|
|
1022
|
+
connected: boolean;
|
|
1023
|
+
/** Whether the AI is currently loading/processing */
|
|
1024
|
+
loading: boolean;
|
|
1025
|
+
/** Whether there's a pending tool approval blocking the queue */
|
|
1026
|
+
hasPendingApproval: boolean;
|
|
1027
|
+
}
|
|
1028
|
+
interface UseMessageQueueReturn {
|
|
1029
|
+
/**
|
|
1030
|
+
* Programmatically send a message to the chat.
|
|
1031
|
+
* Messages are queued and processed one at a time.
|
|
1032
|
+
* Throws on failure (e.g., not connected, no sendFn).
|
|
1033
|
+
*/
|
|
1034
|
+
sendMessage: (message: string, options?: SendMessageOptions) => Promise<void>;
|
|
1035
|
+
}
|
|
1036
|
+
/**
|
|
1037
|
+
* Hook for queuing and sending programmatic messages.
|
|
1038
|
+
*
|
|
1039
|
+
* Handles:
|
|
1040
|
+
* - Message queuing (one at a time)
|
|
1041
|
+
* - Waiting for loading + approval to complete between messages
|
|
1042
|
+
* - Creating new chats before sending
|
|
1043
|
+
* - Opening the chat panel after sending
|
|
1044
|
+
* - Converting File[] to FileAttachment[]
|
|
1045
|
+
*/
|
|
1046
|
+
declare function useMessageQueue({ sendFn, createNewChat, setOpen, connected, loading, hasPendingApproval, }: UseMessageQueueOptions): UseMessageQueueReturn;
|
|
1047
|
+
|
|
1048
|
+
/**
|
|
1049
|
+
* Default text labels for the chat UI.
|
|
1050
|
+
* Use for internationalization (i18n) or branding.
|
|
1051
|
+
*/
|
|
1052
|
+
declare const defaultStrings: {
|
|
667
1053
|
header: {
|
|
668
1054
|
/** Header title when no chat history feature */
|
|
669
1055
|
aiAssistant: string;
|
|
@@ -770,542 +1156,96 @@ declare const defaultStrings: {
|
|
|
770
1156
|
};
|
|
771
1157
|
};
|
|
772
1158
|
/**
|
|
773
|
-
* Customizable text labels for the chat UI.
|
|
774
|
-
*/
|
|
775
|
-
type UseAIStrings = typeof defaultStrings;
|
|
776
|
-
/**
|
|
777
|
-
* Hook to access the current strings.
|
|
778
|
-
* Returns the strings from UseAIProvider, or defaults if not inside a provider.
|
|
779
|
-
*
|
|
780
|
-
* @example
|
|
781
|
-
* ```tsx
|
|
782
|
-
* function MyComponent() {
|
|
783
|
-
* const strings = useStrings();
|
|
784
|
-
* return <button>{strings.input.send}</button>;
|
|
785
|
-
* }
|
|
786
|
-
* ```
|
|
787
|
-
*/
|
|
788
|
-
declare function useStrings(): UseAIStrings;
|
|
789
|
-
|
|
790
|
-
/**
|
|
791
|
-
* Default theme configuration for the chat UI.
|
|
792
|
-
* All colors support CSS color values (hex, rgb, hsl, gradients, etc.)
|
|
793
|
-
*/
|
|
794
|
-
declare const defaultTheme: {
|
|
795
|
-
/** Primary color for buttons, links, active states */
|
|
796
|
-
primaryColor: string;
|
|
797
|
-
/** Primary gradient for user messages and buttons */
|
|
798
|
-
primaryGradient: string;
|
|
799
|
-
/** Translucent primary color for overlays (e.g., drop zone) */
|
|
800
|
-
primaryColorTranslucent: string;
|
|
801
|
-
/** Panel background color */
|
|
802
|
-
backgroundColor: string;
|
|
803
|
-
/** Assistant message bubble background */
|
|
804
|
-
assistantMessageBackground: string;
|
|
805
|
-
/** Hover background for buttons and items */
|
|
806
|
-
hoverBackground: string;
|
|
807
|
-
/** Active/selected item background */
|
|
808
|
-
activeBackground: string;
|
|
809
|
-
/** Disabled button background */
|
|
810
|
-
buttonDisabledBackground: string;
|
|
811
|
-
/** Primary text color */
|
|
812
|
-
textColor: string;
|
|
813
|
-
/** Secondary/muted text color */
|
|
814
|
-
secondaryTextColor: string;
|
|
815
|
-
/** Placeholder text color */
|
|
816
|
-
placeholderTextColor: string;
|
|
817
|
-
/** Online status indicator color */
|
|
818
|
-
onlineColor: string;
|
|
819
|
-
/** Offline status indicator color */
|
|
820
|
-
offlineColor: string;
|
|
821
|
-
/** Unread notification indicator color */
|
|
822
|
-
unreadIndicatorColor: string;
|
|
823
|
-
/** Error message background */
|
|
824
|
-
errorBackground: string;
|
|
825
|
-
/** Error message text color */
|
|
826
|
-
errorTextColor: string;
|
|
827
|
-
/** Danger/destructive action color (e.g., delete) */
|
|
828
|
-
dangerColor: string;
|
|
829
|
-
/** Border color for dividers and inputs */
|
|
830
|
-
borderColor: string;
|
|
831
|
-
/** Dashed border color (e.g., file placeholder) */
|
|
832
|
-
dashedBorderColor: string;
|
|
833
|
-
/** Panel box shadow */
|
|
834
|
-
panelShadow: string;
|
|
835
|
-
/** Dropdown box shadow */
|
|
836
|
-
dropdownShadow: string;
|
|
837
|
-
/** Button box shadow */
|
|
838
|
-
buttonShadow: string;
|
|
839
|
-
/** Button hover box shadow */
|
|
840
|
-
buttonHoverShadow: string;
|
|
841
|
-
/** Font family */
|
|
842
|
-
fontFamily: string;
|
|
843
|
-
/** Modal backdrop color */
|
|
844
|
-
backdropColor: string;
|
|
845
|
-
};
|
|
846
|
-
/**
|
|
847
|
-
* Theme configuration for the chat UI.
|
|
848
|
-
*/
|
|
849
|
-
type UseAITheme = typeof defaultTheme;
|
|
850
|
-
/**
|
|
851
|
-
* Hook to access the current theme.
|
|
852
|
-
* Returns the theme from UseAIProvider, or defaults if not inside a provider.
|
|
853
|
-
*
|
|
854
|
-
* @example
|
|
855
|
-
* ```tsx
|
|
856
|
-
* function MyComponent() {
|
|
857
|
-
* const theme = useTheme();
|
|
858
|
-
* return <div style={{ color: theme.primaryColor }}>Hello</div>;
|
|
859
|
-
* }
|
|
860
|
-
* ```
|
|
861
|
-
*/
|
|
862
|
-
declare function useTheme(): UseAITheme;
|
|
863
|
-
|
|
864
|
-
type UseAIChatPanelStrings = UseAIStrings;
|
|
865
|
-
type UseAIChatPanelTheme = UseAITheme;
|
|
866
|
-
/**
|
|
867
|
-
* Display mode for chat messages.
|
|
868
|
-
*/
|
|
869
|
-
type MessageDisplayMode = 'default' | 'error';
|
|
870
|
-
/**
|
|
871
|
-
* Represents a single message in the AI conversation.
|
|
872
|
-
*/
|
|
873
|
-
interface Message {
|
|
874
|
-
/** Unique identifier for the message */
|
|
875
|
-
id: string;
|
|
876
|
-
/** The role of the message sender */
|
|
877
|
-
role: 'user' | 'assistant';
|
|
878
|
-
/** The message content - string or multimodal content */
|
|
879
|
-
content: PersistedMessageContent;
|
|
880
|
-
/** When the message was created */
|
|
881
|
-
timestamp: Date;
|
|
882
|
-
/** Display mode for styling the message bubble */
|
|
883
|
-
displayMode?: MessageDisplayMode;
|
|
884
|
-
/** Langfuse trace ID for feedback tracking (only for assistant messages) */
|
|
885
|
-
traceId?: string;
|
|
886
|
-
/** User feedback on this message (only for assistant messages) */
|
|
887
|
-
feedback?: FeedbackValue;
|
|
888
|
-
}
|
|
889
|
-
/**
|
|
890
|
-
* Props for the chat panel component.
|
|
891
|
-
*/
|
|
892
|
-
interface UseAIChatPanelProps {
|
|
893
|
-
onSendMessage: (message: string, attachments?: FileAttachment[]) => void;
|
|
894
|
-
messages: Message[];
|
|
895
|
-
loading: boolean;
|
|
896
|
-
connected: boolean;
|
|
897
|
-
/** Currently streaming text from assistant (real-time updates) */
|
|
898
|
-
streamingText?: string;
|
|
899
|
-
currentChatId?: string | null;
|
|
900
|
-
onNewChat?: () => Promise<string | void>;
|
|
901
|
-
onLoadChat?: (chatId: string) => Promise<void>;
|
|
902
|
-
onDeleteChat?: (chatId: string) => Promise<void>;
|
|
903
|
-
onListChats?: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
904
|
-
/** Gets the current chat */
|
|
905
|
-
onGetChat?: () => Promise<Chat | null>;
|
|
906
|
-
suggestions?: string[];
|
|
907
|
-
availableAgents?: AgentInfo[];
|
|
908
|
-
defaultAgent?: string | null;
|
|
909
|
-
selectedAgent?: string | null;
|
|
910
|
-
onAgentChange?: (agentId: string | null) => void;
|
|
911
|
-
fileUploadConfig?: FileUploadConfig;
|
|
912
|
-
/** File processing state for send-time transformations (e.g., OCR) */
|
|
913
|
-
fileProcessing?: FileProcessingState | null;
|
|
914
|
-
commands?: SavedCommand[];
|
|
915
|
-
onSaveCommand?: (name: string, text: string) => Promise<string>;
|
|
916
|
-
onRenameCommand?: (id: string, newName: string) => Promise<void>;
|
|
917
|
-
onDeleteCommand?: (id: string) => Promise<void>;
|
|
918
|
-
/** Optional close button to render in header (for floating mode) */
|
|
919
|
-
closeButton?: React$1.ReactNode;
|
|
920
|
-
/** Currently executing tool info for status display */
|
|
921
|
-
executingTool?: {
|
|
922
|
-
displayText: string;
|
|
923
|
-
} | null;
|
|
924
|
-
/** Whether feedback buttons are enabled (requires Langfuse on server) */
|
|
925
|
-
feedbackEnabled?: boolean;
|
|
926
|
-
/** Callback when user submits feedback on a message */
|
|
927
|
-
onFeedback?: (messageId: string, traceId: string, feedback: FeedbackValue) => void;
|
|
928
|
-
/** Pending tool approvals awaiting user confirmation */
|
|
929
|
-
pendingApprovals?: Array<{
|
|
930
|
-
toolCallId: string;
|
|
931
|
-
toolCallName: string;
|
|
932
|
-
toolCallArgs: Record<string, unknown>;
|
|
933
|
-
annotations?: ToolAnnotations;
|
|
934
|
-
}>;
|
|
935
|
-
/** Callback to approve all pending tool calls */
|
|
936
|
-
onApproveToolCall?: () => void;
|
|
937
|
-
/** Callback to reject all pending tool calls */
|
|
938
|
-
onRejectToolCall?: (reason?: string) => void;
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* Chat panel content - fills its container.
|
|
942
|
-
* Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
|
|
943
|
-
*/
|
|
944
|
-
declare function UseAIChatPanel({ onSendMessage, messages, loading, connected, streamingText, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
|
|
945
|
-
|
|
946
|
-
/**
|
|
947
|
-
* Handler for AG-UI events from the server.
|
|
948
|
-
*/
|
|
949
|
-
type AGUIEventHandler = (event: AGUIEvent) => void;
|
|
950
|
-
/**
|
|
951
|
-
* Simplified message handler for text responses.
|
|
952
|
-
*/
|
|
953
|
-
type MessageHandler = (content: string) => void;
|
|
954
|
-
/**
|
|
955
|
-
* Tool call handler that receives the tool name, arguments, and a callback to send the result.
|
|
956
|
-
*/
|
|
957
|
-
type ToolCallHandler = (toolCallId: string, toolName: string, args: Record<string, unknown>) => void;
|
|
958
|
-
/**
|
|
959
|
-
* Socket.IO client for communicating with the UseAI server.
|
|
960
|
-
* Uses the AG-UI protocol (https://docs.ag-ui.com/), so will be compatible with other AG-UI compliant servers.
|
|
961
|
-
*
|
|
962
|
-
* Handles:
|
|
963
|
-
* - Connection management and automatic reconnection
|
|
964
|
-
* - Sending RunAgentInput messages to server
|
|
965
|
-
* - Parsing AG-UI event streams from server
|
|
966
|
-
* - Tool execution coordination
|
|
967
|
-
*
|
|
968
|
-
* You probably don't need to use this directly, instead use {@link UseAIProvider}.
|
|
969
|
-
*/
|
|
970
|
-
declare class UseAIClient {
|
|
971
|
-
private serverUrl;
|
|
972
|
-
private socket;
|
|
973
|
-
private eventHandlers;
|
|
974
|
-
private reconnectAttempts;
|
|
975
|
-
private maxReconnectAttempts;
|
|
976
|
-
private reconnectDelay;
|
|
977
|
-
private _threadId;
|
|
978
|
-
private _tools;
|
|
979
|
-
private _messages;
|
|
980
|
-
private _state;
|
|
981
|
-
private _availableAgents;
|
|
982
|
-
private _defaultAgent;
|
|
983
|
-
private _selectedAgent;
|
|
984
|
-
private agentsChangeHandlers;
|
|
985
|
-
private connectionStateHandlers;
|
|
986
|
-
private _currentMessageId;
|
|
987
|
-
private _currentMessageContent;
|
|
988
|
-
private _currentAssistantMessage;
|
|
989
|
-
private _currentAssistantToolCalls;
|
|
990
|
-
private currentToolCalls;
|
|
991
|
-
private _langfuseEnabled;
|
|
992
|
-
private langfuseConfigHandlers;
|
|
993
|
-
/**
|
|
994
|
-
* Creates a new UseAI client instance.
|
|
995
|
-
*
|
|
996
|
-
* @param serverUrl - The WebSocket URL of the UseAI server
|
|
997
|
-
*/
|
|
998
|
-
constructor(serverUrl: string);
|
|
999
|
-
/**
|
|
1000
|
-
* Establishes a Socket.IO connection to the server.
|
|
1001
|
-
* Connection state changes are notified via onConnectionStateChange().
|
|
1002
|
-
* Socket.IO handles reconnection automatically.
|
|
1003
|
-
*/
|
|
1004
|
-
connect(): void;
|
|
1005
|
-
private handleEvent;
|
|
1006
|
-
/**
|
|
1007
|
-
* Registers available tools and optional state with the server.
|
|
1008
|
-
* This updates the session state for future agent runs.
|
|
1009
|
-
*
|
|
1010
|
-
* @param tools - Array of tool definitions to register
|
|
1011
|
-
* @param state - Optional state object to provide to the AI.
|
|
1012
|
-
*/
|
|
1013
|
-
registerTools(tools: ToolDefinition[], state?: unknown): void;
|
|
1014
|
-
/**
|
|
1015
|
-
* Updates the state without re-registering tools.
|
|
1016
|
-
* Call this before sendPrompt to ensure the AI sees the latest UI state.
|
|
1017
|
-
*
|
|
1018
|
-
* @param state - The current state object to provide to the AI
|
|
1019
|
-
*/
|
|
1020
|
-
updateState(state: unknown): void;
|
|
1021
|
-
/**
|
|
1022
|
-
* Sends a user prompt to the AI.
|
|
1023
|
-
*
|
|
1024
|
-
* @param prompt - The user's prompt/question (text part)
|
|
1025
|
-
* @param multimodalContent - Optional multimodal content (text, images, files)
|
|
1026
|
-
* @param forwardedProps - Optional props to forward to the server (e.g., telemetryMetadata, mcpHeaders).
|
|
1027
|
-
* Internally merged with other forwardedProps.
|
|
1028
|
-
*/
|
|
1029
|
-
sendPrompt(prompt: string, multimodalContent?: MultimodalContent[], forwardedProps?: UseAIForwardedProps): Promise<void>;
|
|
1030
|
-
/**
|
|
1031
|
-
* Sends the result of a tool execution back to the server.
|
|
1032
|
-
*
|
|
1033
|
-
* @param toolCallId - The ID of the tool call being responded to
|
|
1034
|
-
* @param result - The result returned by the tool execution
|
|
1035
|
-
* @param state - Optional updated state to send back to the AI
|
|
1036
|
-
*/
|
|
1037
|
-
sendToolResponse(toolCallId: string, result: unknown, state?: unknown): void;
|
|
1038
|
-
/**
|
|
1039
|
-
* Sends a tool approval response back to the server.
|
|
1040
|
-
*
|
|
1041
|
-
* @param toolCallId - The ID of the tool call being approved/rejected
|
|
1042
|
-
* @param approved - Whether the tool execution is approved
|
|
1043
|
-
* @param reason - Optional reason for rejection (shown to AI)
|
|
1044
|
-
*/
|
|
1045
|
-
sendToolApprovalResponse(toolCallId: string, approved: boolean, reason?: string): void;
|
|
1046
|
-
/**
|
|
1047
|
-
* Retrieves accumulated tool call data for a specific tool call ID.
|
|
1048
|
-
* Used to get the complete tool name and arguments after they've been streamed
|
|
1049
|
-
* across multiple TOOL_CALL_ARGS events.
|
|
1050
|
-
*
|
|
1051
|
-
* @param toolCallId - The ID of the tool call
|
|
1052
|
-
* @returns Object with tool name and accumulated arguments, or undefined if not found
|
|
1053
|
-
*/
|
|
1054
|
-
getToolCallData(toolCallId: string): {
|
|
1055
|
-
name: string;
|
|
1056
|
-
args: string;
|
|
1057
|
-
} | undefined;
|
|
1058
|
-
/**
|
|
1059
|
-
* Registers an AG-UI event handler for receiving server events.
|
|
1060
|
-
*
|
|
1061
|
-
* @param id - Unique identifier for this handler
|
|
1062
|
-
* @param handler - Callback function to handle incoming AG-UI events
|
|
1063
|
-
* @returns Cleanup function to unregister the handler
|
|
1064
|
-
*/
|
|
1065
|
-
onEvent(id: string, handler: AGUIEventHandler): () => void;
|
|
1066
|
-
/**
|
|
1067
|
-
* Helper method to listen for text message content.
|
|
1068
|
-
* Aggregates TEXT_MESSAGE_CONTENT events and calls handler with complete messages.
|
|
1069
|
-
*
|
|
1070
|
-
* @param handler - Callback function to handle complete text messages
|
|
1071
|
-
* @returns Cleanup function
|
|
1072
|
-
*/
|
|
1073
|
-
onTextMessage(handler: MessageHandler): () => void;
|
|
1074
|
-
/**
|
|
1075
|
-
* Helper method to listen for tool call requests.
|
|
1076
|
-
* Aggregates TOOL_CALL_* events and calls handler with complete tool calls.
|
|
1077
|
-
*
|
|
1078
|
-
* @param handler - Callback function to handle tool calls
|
|
1079
|
-
* @returns Cleanup function
|
|
1080
|
-
*/
|
|
1081
|
-
onToolCall(handler: ToolCallHandler): () => void;
|
|
1082
|
-
/**
|
|
1083
|
-
* Gets the current accumulated message content (useful during streaming).
|
|
1084
|
-
*/
|
|
1085
|
-
get currentMessageContent(): string;
|
|
1086
|
-
/**
|
|
1087
|
-
* Gets the current thread ID for this session.
|
|
1088
|
-
* Generates a new one if not set.
|
|
1089
|
-
*/
|
|
1090
|
-
get threadId(): string;
|
|
1091
|
-
/**
|
|
1092
|
-
* Gets the current conversation messages.
|
|
1093
|
-
*/
|
|
1094
|
-
get messages(): Message$1[];
|
|
1095
|
-
/**
|
|
1096
|
-
* Gets the current state.
|
|
1097
|
-
*/
|
|
1098
|
-
get state(): unknown;
|
|
1099
|
-
/**
|
|
1100
|
-
* Gets the list of available agents from the server.
|
|
1101
|
-
*/
|
|
1102
|
-
get availableAgents(): AgentInfo[];
|
|
1103
|
-
/**
|
|
1104
|
-
* Gets the default agent ID from the server.
|
|
1105
|
-
*/
|
|
1106
|
-
get defaultAgent(): string | null;
|
|
1107
|
-
/**
|
|
1108
|
-
* Gets the currently selected agent ID.
|
|
1109
|
-
* Returns null if using server default.
|
|
1110
|
-
*/
|
|
1111
|
-
get selectedAgent(): string | null;
|
|
1112
|
-
/**
|
|
1113
|
-
* Gets the effective agent ID (selected or default).
|
|
1114
|
-
*/
|
|
1115
|
-
get currentAgent(): string | null;
|
|
1116
|
-
/**
|
|
1117
|
-
* Sets the agent to use for requests.
|
|
1118
|
-
* Pass null to use the server default.
|
|
1119
|
-
*
|
|
1120
|
-
* @param agentId - The agent ID to use, or null for server default
|
|
1121
|
-
*/
|
|
1122
|
-
setAgent(agentId: string | null): void;
|
|
1123
|
-
/**
|
|
1124
|
-
* Subscribes to agent changes (when server sends available agents).
|
|
1125
|
-
*
|
|
1126
|
-
* @param handler - Callback function receiving agents list and default agent
|
|
1127
|
-
* @returns Cleanup function to unsubscribe
|
|
1128
|
-
*/
|
|
1129
|
-
onAgentsChange(handler: (agents: AgentInfo[], defaultAgent: string | null) => void): () => void;
|
|
1130
|
-
/**
|
|
1131
|
-
* Subscribes to connection state changes.
|
|
1132
|
-
* This is called on both initial connection and reconnection.
|
|
1133
|
-
*
|
|
1134
|
-
* @param handler - Callback function receiving connection state (true = connected, false = disconnected)
|
|
1135
|
-
* @returns Cleanup function to unsubscribe
|
|
1136
|
-
*/
|
|
1137
|
-
onConnectionStateChange(handler: (connected: boolean) => void): () => void;
|
|
1138
|
-
/**
|
|
1139
|
-
* Sets the thread ID for this session.
|
|
1140
|
-
* When the thread ID changes, conversation state is cleared to prevent history bleeding.
|
|
1141
|
-
* Use this when switching between different chat conversations.
|
|
1142
|
-
*
|
|
1143
|
-
* @param threadId - The thread/chat ID to use (typically the chatId)
|
|
1144
|
-
*/
|
|
1145
|
-
setThreadId(threadId: string): void;
|
|
1146
|
-
/**
|
|
1147
|
-
* Loads messages into the conversation history (for resuming from storage).
|
|
1148
|
-
* @param messages - Array of messages to load
|
|
1149
|
-
*/
|
|
1150
|
-
loadMessages(messages: Message$1[]): void;
|
|
1151
|
-
/**
|
|
1152
|
-
* Clears the conversation history and resets the thread.
|
|
1153
|
-
*/
|
|
1154
|
-
clearConversation(): void;
|
|
1155
|
-
send(message: UseAIClientMessage): void;
|
|
1156
|
-
/**
|
|
1157
|
-
* Closes the Socket.IO connection to the server.
|
|
1158
|
-
*/
|
|
1159
|
-
disconnect(): void;
|
|
1160
|
-
/**
|
|
1161
|
-
* Checks if the client is currently connected to the server.
|
|
1162
|
-
*
|
|
1163
|
-
* @returns true if connected, false otherwise
|
|
1164
|
-
*/
|
|
1165
|
-
isConnected(): boolean;
|
|
1166
|
-
/**
|
|
1167
|
-
* Subscribes to Langfuse config changes.
|
|
1168
|
-
*
|
|
1169
|
-
* @param handler - Callback function receiving langfuse enabled status
|
|
1170
|
-
* @returns Cleanup function to unsubscribe
|
|
1171
|
-
*/
|
|
1172
|
-
onLangfuseConfigChange(handler: (enabled: boolean) => void): () => void;
|
|
1173
|
-
/**
|
|
1174
|
-
* Submits feedback for an assistant message.
|
|
1175
|
-
* Sends feedback to the server, which forwards it to Langfuse.
|
|
1176
|
-
*
|
|
1177
|
-
* @param messageId - The client-side message ID
|
|
1178
|
-
* @param traceId - The Langfuse trace ID (runId from RUN_FINISHED)
|
|
1179
|
-
* @param feedback - 'upvote' for positive, 'downvote' for negative, null to remove
|
|
1180
|
-
*/
|
|
1181
|
-
submitFeedback(messageId: string, traceId: string, feedback: FeedbackValue): void;
|
|
1182
|
-
}
|
|
1183
|
-
|
|
1184
|
-
interface RegisterToolsOptions {
|
|
1185
|
-
/** Mark component as invisible (no visual state, skip prompt wait) */
|
|
1186
|
-
invisible?: boolean;
|
|
1187
|
-
}
|
|
1188
|
-
/**
|
|
1189
|
-
* Pending tool approval request state.
|
|
1159
|
+
* Customizable text labels for the chat UI.
|
|
1190
1160
|
*/
|
|
1191
|
-
|
|
1192
|
-
toolCallId: string;
|
|
1193
|
-
toolCallName: string;
|
|
1194
|
-
toolCallArgs: Record<string, unknown>;
|
|
1195
|
-
annotations?: ToolAnnotations;
|
|
1196
|
-
/** Optional message explaining why approval is needed (runtime approval) */
|
|
1197
|
-
message?: string;
|
|
1198
|
-
/** Optional metadata for the approval request (runtime approval) */
|
|
1199
|
-
metadata?: Record<string, unknown>;
|
|
1200
|
-
}
|
|
1201
|
-
interface UseToolSystemOptions {
|
|
1202
|
-
/** Reference to the UseAI client for sending responses */
|
|
1203
|
-
clientRef: RefObject<UseAIClient | null>;
|
|
1204
|
-
/** Builds the aggregated state from all registered prompts */
|
|
1205
|
-
buildState: () => unknown;
|
|
1206
|
-
}
|
|
1207
|
-
interface UseToolSystemReturn {
|
|
1208
|
-
/** Registers tools for a specific component */
|
|
1209
|
-
registerTools: (id: string, tools: ToolsDefinition, options?: RegisterToolsOptions) => void;
|
|
1210
|
-
/** Unregisters tools for a specific component */
|
|
1211
|
-
unregisterTools: (id: string) => void;
|
|
1212
|
-
/** Checks if a component is marked as invisible */
|
|
1213
|
-
isInvisible: (id: string) => boolean;
|
|
1214
|
-
/** All tools aggregated from registered components */
|
|
1215
|
-
aggregatedTools: ToolsDefinition;
|
|
1216
|
-
/** Whether any tools are registered */
|
|
1217
|
-
hasTools: boolean;
|
|
1218
|
-
/** Ref to current aggregated tools (for use in closures) */
|
|
1219
|
-
aggregatedToolsRef: MutableRefObject<ToolsDefinition>;
|
|
1220
|
-
/** Signals that a component has completed its registration in useLayoutEffect */
|
|
1221
|
-
signalReady: (id: string) => void;
|
|
1222
|
-
/** Current tool registry version (increments when tools change) */
|
|
1223
|
-
toolRegistryVersion: number;
|
|
1224
|
-
/** Registers a waiter function for a component (called when tool exec needs to wait for re-render) */
|
|
1225
|
-
registerWaiter: (id: string, waiter: () => Promise<void>) => void;
|
|
1226
|
-
/** Unregisters a waiter function */
|
|
1227
|
-
unregisterWaiter: (id: string) => void;
|
|
1228
|
-
/** All pending tool approval requests */
|
|
1229
|
-
pendingApprovals: PendingToolApproval[];
|
|
1230
|
-
/** Handle a tool approval request event from the server */
|
|
1231
|
-
handleApprovalRequest: (event: ToolApprovalRequestEvent) => void;
|
|
1232
|
-
/** Execute a tool call and send the response to the server */
|
|
1233
|
-
executeToolCall: (toolCallId: string, name: string, input: unknown) => Promise<void>;
|
|
1234
|
-
/** Store a tool call as pending approval (deferred execution) */
|
|
1235
|
-
storePendingToolCall: (toolCallId: string, name: string, input: unknown, toolCallData: {
|
|
1236
|
-
name: string;
|
|
1237
|
-
args: string;
|
|
1238
|
-
}) => void;
|
|
1239
|
-
/** Approve all pending tool calls and execute them */
|
|
1240
|
-
approveAll: () => Promise<void>;
|
|
1241
|
-
/** Reject all pending tool calls with optional reason */
|
|
1242
|
-
rejectAll: (reason?: string) => void;
|
|
1243
|
-
}
|
|
1161
|
+
type UseAIStrings = typeof defaultStrings;
|
|
1244
1162
|
/**
|
|
1245
|
-
*
|
|
1246
|
-
*
|
|
1247
|
-
*
|
|
1248
|
-
* Merges what were previously three separate concerns:
|
|
1249
|
-
* - Tool registry (registration, aggregation, ownership tracking)
|
|
1250
|
-
* - Waiters (waiting for component re-renders after tool execution)
|
|
1251
|
-
* - Tool execution (running tools, sending responses, approval flow)
|
|
1163
|
+
* Hook to access the current strings.
|
|
1164
|
+
* Returns the strings from UseAIProvider, or defaults if not inside a provider.
|
|
1252
1165
|
*
|
|
1253
|
-
*
|
|
1254
|
-
*
|
|
1166
|
+
* @example
|
|
1167
|
+
* ```tsx
|
|
1168
|
+
* function MyComponent() {
|
|
1169
|
+
* const strings = useStrings();
|
|
1170
|
+
* return <button>{strings.input.send}</button>;
|
|
1171
|
+
* }
|
|
1172
|
+
* ```
|
|
1255
1173
|
*/
|
|
1256
|
-
declare function
|
|
1174
|
+
declare function useStrings(): UseAIStrings;
|
|
1257
1175
|
|
|
1258
1176
|
/**
|
|
1259
|
-
*
|
|
1177
|
+
* Default theme configuration for the chat UI.
|
|
1178
|
+
* All colors support CSS color values (hex, rgb, hsl, gradients, etc.)
|
|
1260
1179
|
*/
|
|
1261
|
-
|
|
1262
|
-
/**
|
|
1263
|
-
|
|
1264
|
-
/**
|
|
1265
|
-
|
|
1266
|
-
/**
|
|
1267
|
-
|
|
1268
|
-
/**
|
|
1269
|
-
|
|
1270
|
-
/**
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
|
|
1275
|
-
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1180
|
+
declare const defaultTheme: {
|
|
1181
|
+
/** Primary color for buttons, links, active states */
|
|
1182
|
+
primaryColor: string;
|
|
1183
|
+
/** Primary gradient for user messages and buttons */
|
|
1184
|
+
primaryGradient: string;
|
|
1185
|
+
/** Translucent primary color for overlays (e.g., drop zone) */
|
|
1186
|
+
primaryColorTranslucent: string;
|
|
1187
|
+
/** Panel background color */
|
|
1188
|
+
backgroundColor: string;
|
|
1189
|
+
/** Assistant message bubble background */
|
|
1190
|
+
assistantMessageBackground: string;
|
|
1191
|
+
/** Hover background for buttons and items */
|
|
1192
|
+
hoverBackground: string;
|
|
1193
|
+
/** Active/selected item background */
|
|
1194
|
+
activeBackground: string;
|
|
1195
|
+
/** Disabled button background */
|
|
1196
|
+
buttonDisabledBackground: string;
|
|
1197
|
+
/** Primary text color */
|
|
1198
|
+
textColor: string;
|
|
1199
|
+
/** Secondary/muted text color */
|
|
1200
|
+
secondaryTextColor: string;
|
|
1201
|
+
/** Placeholder text color */
|
|
1202
|
+
placeholderTextColor: string;
|
|
1203
|
+
/** Online status indicator color */
|
|
1204
|
+
onlineColor: string;
|
|
1205
|
+
/** Offline status indicator color */
|
|
1206
|
+
offlineColor: string;
|
|
1207
|
+
/** Unread notification indicator color */
|
|
1208
|
+
unreadIndicatorColor: string;
|
|
1209
|
+
/** Error message background */
|
|
1210
|
+
errorBackground: string;
|
|
1211
|
+
/** Error message text color */
|
|
1212
|
+
errorTextColor: string;
|
|
1213
|
+
/** Danger/destructive action color (e.g., delete) */
|
|
1214
|
+
dangerColor: string;
|
|
1215
|
+
/** Border color for dividers and inputs */
|
|
1216
|
+
borderColor: string;
|
|
1217
|
+
/** Dashed border color (e.g., file placeholder) */
|
|
1218
|
+
dashedBorderColor: string;
|
|
1219
|
+
/** Panel box shadow */
|
|
1220
|
+
panelShadow: string;
|
|
1221
|
+
/** Dropdown box shadow */
|
|
1222
|
+
dropdownShadow: string;
|
|
1223
|
+
/** Button box shadow */
|
|
1224
|
+
buttonShadow: string;
|
|
1225
|
+
/** Button hover box shadow */
|
|
1226
|
+
buttonHoverShadow: string;
|
|
1227
|
+
/** Font family */
|
|
1228
|
+
fontFamily: string;
|
|
1229
|
+
/** Modal backdrop color */
|
|
1230
|
+
backdropColor: string;
|
|
1231
|
+
};
|
|
1298
1232
|
/**
|
|
1299
|
-
*
|
|
1233
|
+
* Theme configuration for the chat UI.
|
|
1234
|
+
*/
|
|
1235
|
+
type UseAITheme = typeof defaultTheme;
|
|
1236
|
+
/**
|
|
1237
|
+
* Hook to access the current theme.
|
|
1238
|
+
* Returns the theme from UseAIProvider, or defaults if not inside a provider.
|
|
1300
1239
|
*
|
|
1301
|
-
*
|
|
1302
|
-
*
|
|
1303
|
-
*
|
|
1304
|
-
*
|
|
1305
|
-
*
|
|
1306
|
-
*
|
|
1240
|
+
* @example
|
|
1241
|
+
* ```tsx
|
|
1242
|
+
* function MyComponent() {
|
|
1243
|
+
* const theme = useTheme();
|
|
1244
|
+
* return <div style={{ color: theme.primaryColor }}>Hello</div>;
|
|
1245
|
+
* }
|
|
1246
|
+
* ```
|
|
1307
1247
|
*/
|
|
1308
|
-
declare function
|
|
1248
|
+
declare function useTheme(): UseAITheme;
|
|
1309
1249
|
|
|
1310
1250
|
/**
|
|
1311
1251
|
* Chat management context (from useChatManagement hook).
|
|
@@ -1433,7 +1373,7 @@ interface ChatPanelProps {
|
|
|
1433
1373
|
/** Callback when a message is sent */
|
|
1434
1374
|
onSendMessage: (message: string) => void;
|
|
1435
1375
|
/** Array of messages in the conversation */
|
|
1436
|
-
messages:
|
|
1376
|
+
messages: PersistedMessage[];
|
|
1437
1377
|
/** Whether the AI is currently processing */
|
|
1438
1378
|
loading: boolean;
|
|
1439
1379
|
/** Whether the client is connected to the server */
|
|
@@ -1615,6 +1555,69 @@ declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton
|
|
|
1615
1555
|
*/
|
|
1616
1556
|
declare function useAIContext(): UseAIContextValue;
|
|
1617
1557
|
|
|
1558
|
+
type UseAIChatPanelStrings = UseAIStrings;
|
|
1559
|
+
type UseAIChatPanelTheme = UseAITheme;
|
|
1560
|
+
/**
|
|
1561
|
+
* @deprecated Use `PersistedMessage` directly instead.
|
|
1562
|
+
*/
|
|
1563
|
+
type Message = PersistedMessage;
|
|
1564
|
+
/**
|
|
1565
|
+
* Props for the chat panel component.
|
|
1566
|
+
*/
|
|
1567
|
+
interface UseAIChatPanelProps {
|
|
1568
|
+
onSendMessage: (message: string, attachments?: FileAttachment[]) => void;
|
|
1569
|
+
messages: Message[];
|
|
1570
|
+
loading: boolean;
|
|
1571
|
+
connected: boolean;
|
|
1572
|
+
/** Currently streaming text from assistant (real-time updates) */
|
|
1573
|
+
streamingText?: string;
|
|
1574
|
+
currentChatId?: string | null;
|
|
1575
|
+
onNewChat?: () => Promise<string | void>;
|
|
1576
|
+
onLoadChat?: (chatId: string) => Promise<void>;
|
|
1577
|
+
onDeleteChat?: (chatId: string) => Promise<void>;
|
|
1578
|
+
onListChats?: () => Promise<Array<Omit<Chat, 'messages'>>>;
|
|
1579
|
+
/** Gets the current chat */
|
|
1580
|
+
onGetChat?: () => Promise<Chat | null>;
|
|
1581
|
+
suggestions?: string[];
|
|
1582
|
+
availableAgents?: AgentInfo[];
|
|
1583
|
+
defaultAgent?: string | null;
|
|
1584
|
+
selectedAgent?: string | null;
|
|
1585
|
+
onAgentChange?: (agentId: string | null) => void;
|
|
1586
|
+
fileUploadConfig?: FileUploadConfig;
|
|
1587
|
+
/** File processing state for send-time transformations (e.g., OCR) */
|
|
1588
|
+
fileProcessing?: FileProcessingState | null;
|
|
1589
|
+
commands?: SavedCommand[];
|
|
1590
|
+
onSaveCommand?: (name: string, text: string) => Promise<string>;
|
|
1591
|
+
onRenameCommand?: (id: string, newName: string) => Promise<void>;
|
|
1592
|
+
onDeleteCommand?: (id: string) => Promise<void>;
|
|
1593
|
+
/** Optional close button to render in header (for floating mode) */
|
|
1594
|
+
closeButton?: React$1.ReactNode;
|
|
1595
|
+
/** Currently executing tool info for status display */
|
|
1596
|
+
executingTool?: {
|
|
1597
|
+
displayText: string;
|
|
1598
|
+
} | null;
|
|
1599
|
+
/** Whether feedback buttons are enabled (requires Langfuse on server) */
|
|
1600
|
+
feedbackEnabled?: boolean;
|
|
1601
|
+
/** Callback when user submits feedback on a message */
|
|
1602
|
+
onFeedback?: (messageId: string, traceId: string, feedback: FeedbackValue) => void;
|
|
1603
|
+
/** Pending tool approvals awaiting user confirmation */
|
|
1604
|
+
pendingApprovals?: Array<{
|
|
1605
|
+
toolCallId: string;
|
|
1606
|
+
toolCallName: string;
|
|
1607
|
+
toolCallArgs: Record<string, unknown>;
|
|
1608
|
+
annotations?: ToolAnnotations;
|
|
1609
|
+
}>;
|
|
1610
|
+
/** Callback to approve all pending tool calls */
|
|
1611
|
+
onApproveToolCall?: () => void;
|
|
1612
|
+
/** Callback to reject all pending tool calls */
|
|
1613
|
+
onRejectToolCall?: (reason?: string) => void;
|
|
1614
|
+
}
|
|
1615
|
+
/**
|
|
1616
|
+
* Chat panel content - fills its container.
|
|
1617
|
+
* Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
|
|
1618
|
+
*/
|
|
1619
|
+
declare function UseAIChatPanel({ onSendMessage, messages, loading, connected, streamingText, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
|
|
1620
|
+
|
|
1618
1621
|
/**
|
|
1619
1622
|
* Props for the floating chat wrapper.
|
|
1620
1623
|
*/
|
|
@@ -2067,9 +2070,9 @@ interface UseChatManagementOptions {
|
|
|
2067
2070
|
/** Reference to the UseAIClient (can be null during initialization) */
|
|
2068
2071
|
clientRef: React.MutableRefObject<UseAIClient | null>;
|
|
2069
2072
|
/** Current messages state (owned by provider) */
|
|
2070
|
-
messages:
|
|
2073
|
+
messages: PersistedMessage[];
|
|
2071
2074
|
/** Setter for messages state (owned by provider) */
|
|
2072
|
-
setMessages: React.Dispatch<React.SetStateAction<
|
|
2075
|
+
setMessages: React.Dispatch<React.SetStateAction<PersistedMessage[]>>;
|
|
2073
2076
|
/** Whether the client is connected */
|
|
2074
2077
|
connected?: boolean;
|
|
2075
2078
|
}
|
|
@@ -2094,8 +2097,13 @@ interface UseChatManagementReturn {
|
|
|
2094
2097
|
activatePendingChat: () => string | null;
|
|
2095
2098
|
/** Saves a user message to storage and reloads messages */
|
|
2096
2099
|
saveUserMessage: (chatId: string, content: PersistedMessageContent) => Promise<boolean>;
|
|
2097
|
-
/**
|
|
2098
|
-
|
|
2100
|
+
/**
|
|
2101
|
+
* Saves an AI response to storage and optionally reloads messages.
|
|
2102
|
+
* When turnMessages are provided, intermediate assistant+tool messages from
|
|
2103
|
+
* the turn are persisted before the final assistant message, preserving the
|
|
2104
|
+
* complete tool call context for conversation history.
|
|
2105
|
+
*/
|
|
2106
|
+
saveAIResponse: (content: string, displayMode?: 'default' | 'error', traceId?: string, turnMessages?: PersistedMessage[]) => Promise<void>;
|
|
2099
2107
|
/** Reloads messages from storage for the given chat ID */
|
|
2100
2108
|
reloadMessages: (chatId: string) => Promise<void>;
|
|
2101
2109
|
/** Get the current chat object. Metadata is frozen to prevent accidental mutation. */
|
|
@@ -2257,7 +2265,7 @@ interface UseServerEventsOptions {
|
|
|
2257
2265
|
/** Tool system for executing tools and looking up tool metadata */
|
|
2258
2266
|
toolSystem: UseToolSystemReturn;
|
|
2259
2267
|
/** Saves an AI response to chat storage */
|
|
2260
|
-
saveAIResponse: (content: string, displayMode?: 'default' | 'error', traceId?: string) => Promise<void>;
|
|
2268
|
+
saveAIResponse: (content: string, displayMode?: 'default' | 'error', traceId?: string, turnMessages?: PersistedMessage[]) => Promise<void>;
|
|
2261
2269
|
/** UI strings for error messages and tool execution fallbacks */
|
|
2262
2270
|
strings: UseAIStrings;
|
|
2263
2271
|
}
|
|
@@ -2307,7 +2315,7 @@ interface UseFeedbackOptions {
|
|
|
2307
2315
|
/** Callback to get the currently displayed chat ID */
|
|
2308
2316
|
getDisplayedChatId: () => string | null;
|
|
2309
2317
|
/** Setter for messages state (for optimistic UI updates) */
|
|
2310
|
-
setMessages: React.Dispatch<React.SetStateAction<
|
|
2318
|
+
setMessages: React.Dispatch<React.SetStateAction<PersistedMessage[]>>;
|
|
2311
2319
|
}
|
|
2312
2320
|
interface UseFeedbackReturn {
|
|
2313
2321
|
/** Whether Langfuse feedback is enabled on the server */
|