@meetsmore-oss/use-ai-client 1.14.0 → 1.15.0
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 +20517 -20504
- package/dist/bundled.js.map +1 -1
- package/dist/index.d.ts +29 -3
- package/dist/index.js +45 -36
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.d.ts
CHANGED
|
@@ -324,6 +324,18 @@ interface UseAIConfig {
|
|
|
324
324
|
/** The WebSocket URL of the UseAI server */
|
|
325
325
|
serverUrl: string;
|
|
326
326
|
}
|
|
327
|
+
/**
|
|
328
|
+
* Toggles for optional chat UI features. Each feature defaults to enabled
|
|
329
|
+
* when its flag is omitted, so set a flag to false to opt out of that feature.
|
|
330
|
+
*/
|
|
331
|
+
interface EnabledFeatures {
|
|
332
|
+
/**
|
|
333
|
+
* The "save as slash command" UI (hover save button + inline save editor)
|
|
334
|
+
* on user messages. Saved-command autocomplete via "/" is unaffected.
|
|
335
|
+
* @default true
|
|
336
|
+
*/
|
|
337
|
+
slashCommands?: boolean;
|
|
338
|
+
}
|
|
327
339
|
|
|
328
340
|
/**
|
|
329
341
|
* Handler for AG-UI events from the server.
|
|
@@ -1584,6 +1596,13 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1584
1596
|
* Defaults to LocalStorageCommandRepository if not provided.
|
|
1585
1597
|
*/
|
|
1586
1598
|
commandRepository?: CommandRepository;
|
|
1599
|
+
/**
|
|
1600
|
+
* Opt-out toggles for optional chat UI features. Each feature defaults to
|
|
1601
|
+
* enabled, so only set a flag to false to hide it. For example, set
|
|
1602
|
+
* `{ slashCommands: false }` to hide the "save as slash command" UI while
|
|
1603
|
+
* keeping "/" autocomplete for existing saved commands.
|
|
1604
|
+
*/
|
|
1605
|
+
enabledFeatures?: EnabledFeatures;
|
|
1587
1606
|
/**
|
|
1588
1607
|
* Whether to render the built-in chat UI (floating button + panel).
|
|
1589
1608
|
* Set to false when using the `<UseAIChat>` component to control chat placement.
|
|
@@ -1695,7 +1714,7 @@ interface UseAIProviderProps extends UseAIConfig {
|
|
|
1695
1714
|
* }
|
|
1696
1715
|
* ```
|
|
1697
1716
|
*/
|
|
1698
|
-
declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, forwardedPropsProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, submitMode, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
|
|
1717
|
+
declare function UseAIProvider({ serverUrl, children, systemPrompt, CustomButton, CustomChat, chatRepository, forwardedPropsProvider, fileUploadConfig: fileUploadConfigProp, commandRepository, enabledFeatures, renderChat, theme: customTheme, strings: customStrings, visibleAgentIds, onOpenChange, submitMode, }: UseAIProviderProps): react_jsx_runtime.JSX.Element;
|
|
1699
1718
|
/**
|
|
1700
1719
|
* Hook to access the UseAI context.
|
|
1701
1720
|
* When used outside a UseAIProvider, returns a no-op context and logs a warning.
|
|
@@ -1744,6 +1763,13 @@ interface UseAIChatPanelProps {
|
|
|
1744
1763
|
fileProcessing?: FileProcessingState | null;
|
|
1745
1764
|
commands?: SavedCommand[];
|
|
1746
1765
|
onSaveCommand?: (name: string, text: string) => Promise<string>;
|
|
1766
|
+
/**
|
|
1767
|
+
* Opt-out toggles for optional chat UI features. Each feature defaults to
|
|
1768
|
+
* enabled when omitted. `slashCommands` controls the "save as slash command"
|
|
1769
|
+
* UI (hover save button + inline editor); saved-command autocomplete is
|
|
1770
|
+
* unaffected.
|
|
1771
|
+
*/
|
|
1772
|
+
enabledFeatures?: EnabledFeatures;
|
|
1747
1773
|
onRenameCommand?: (id: string, newName: string) => Promise<void>;
|
|
1748
1774
|
onDeleteCommand?: (id: string) => Promise<void>;
|
|
1749
1775
|
/** Optional close button to render in header (for floating mode) */
|
|
@@ -1786,7 +1812,7 @@ interface UseAIChatPanelProps {
|
|
|
1786
1812
|
* Chat panel content - fills its container.
|
|
1787
1813
|
* Use directly for embedded mode, or wrap with UseAIFloatingChatWrapper for floating mode.
|
|
1788
1814
|
*/
|
|
1789
|
-
declare function UseAIChatPanel({ onSendMessage, onAbort, messages, loading, connected, streamingText, streamingReasoning, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, submitMode, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
|
|
1815
|
+
declare function UseAIChatPanel({ onSendMessage, onAbort, messages, loading, connected, streamingText, streamingReasoning, currentChatId, onNewChat, onLoadChat, onDeleteChat, onListChats, onGetChat, suggestions, availableAgents, defaultAgent, selectedAgent, onAgentChange, fileUploadConfig, fileProcessing, commands, onSaveCommand, enabledFeatures, onRenameCommand, onDeleteCommand, closeButton, executingTool, feedbackEnabled, onFeedback, pendingApprovals, onApproveToolCall, onRejectToolCall, submitMode, }: UseAIChatPanelProps): react_jsx_runtime.JSX.Element;
|
|
1790
1816
|
|
|
1791
1817
|
/**
|
|
1792
1818
|
* Props for the floating chat wrapper.
|
|
@@ -2612,4 +2638,4 @@ interface UseDropdownStateOptions {
|
|
|
2612
2638
|
*/
|
|
2613
2639
|
declare function useDropdownState(options?: UseDropdownStateOptions): UseDropdownStateReturn;
|
|
2614
2640
|
|
|
2615
|
-
export { type AgentContextValue, type Chat, type ChatContextValue, type ChatMetadata, type ChatPanelProps, type ChatRepository, CloseButton, type CommandContextValue, type CommandRepository, type CreateChatOptions, type CreateCommandOptions, DEFAULT_MAX_FILE_SIZE, type DefinedTool, type DropZoneProps, EmbedFileUploadBackend, type ExecutingToolDisplay, type FileAttachment, type FileProcessingState, type FileProcessingStatus, type FileTransformer, type FileTransformerContext, type FileTransformerMap, type FileUploadBackend, type FileUploadConfig, type FloatingButtonProps, type InlineSaveProps, type ListChatsOptions, type ListCommandsOptions, LocalStorageChatRepository, LocalStorageCommandRepository, type Message, type PendingToolApproval, type PersistedContentPart, type PersistedFileContent, type PersistedFileMetadata, type PersistedMessage, type PersistedMessageContent, type PersistedTextContent, type ProcessAttachmentsConfig, type PromptsContextValue, type RegisterToolsOptions, type SavedCommand, type SendMessageOptions, type SubmitMode, type ToolExecutionContext, type ToolOptions, type ToolRegistryContextValue, type ToolsDefinition, type TriggerWorkflowOptions, UseAIChat, UseAIChatPanel, type UseAIChatPanelProps, type UseAIChatPanelStrings, type UseAIChatPanelTheme, type UseAIChatProps, UseAIClient, type UseAIConfig, type UseAIContextValue, UseAIFloatingButton, UseAIFloatingChatWrapper, type UseAIOptions, UseAIProvider, type UseAIProviderProps, type UseAIResult, type UseAIStrings, type UseAITheme, type UseAIWorkflowResult, type UseAgentSelectionOptions, type UseAgentSelectionReturn, type UseChatManagementOptions, type UseChatManagementReturn, type UseCommandManagementOptions, type UseCommandManagementReturn, type UseDropdownStateOptions, type UseDropdownStateReturn, type UseFeedbackOptions, type UseFeedbackReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseServerEventsOptions, type UseServerEventsReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolSystemOptions, type UseToolSystemReturn, type WorkflowProgress, clearTransformationCache, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, findTransformerPattern, generateChatId, generateCommandId, generateMessageId, matchesMimeType, processAttachments, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFeedback, useFileUpload, useMessageQueue, usePromptState, useServerEvents, useSlashCommands, useStableTools, useStrings, useTheme, useToolSystem, validateCommandName };
|
|
2641
|
+
export { type AgentContextValue, type Chat, type ChatContextValue, type ChatMetadata, type ChatPanelProps, type ChatRepository, CloseButton, type CommandContextValue, type CommandRepository, type CreateChatOptions, type CreateCommandOptions, DEFAULT_MAX_FILE_SIZE, type DefinedTool, type DropZoneProps, EmbedFileUploadBackend, type EnabledFeatures, type ExecutingToolDisplay, type FileAttachment, type FileProcessingState, type FileProcessingStatus, type FileTransformer, type FileTransformerContext, type FileTransformerMap, type FileUploadBackend, type FileUploadConfig, type FloatingButtonProps, type InlineSaveProps, type ListChatsOptions, type ListCommandsOptions, LocalStorageChatRepository, LocalStorageCommandRepository, type Message, type PendingToolApproval, type PersistedContentPart, type PersistedFileContent, type PersistedFileMetadata, type PersistedMessage, type PersistedMessageContent, type PersistedTextContent, type ProcessAttachmentsConfig, type PromptsContextValue, type RegisterToolsOptions, type SavedCommand, type SendMessageOptions, type SubmitMode, type ToolExecutionContext, type ToolOptions, type ToolRegistryContextValue, type ToolsDefinition, type TriggerWorkflowOptions, UseAIChat, UseAIChatPanel, type UseAIChatPanelProps, type UseAIChatPanelStrings, type UseAIChatPanelTheme, type UseAIChatProps, UseAIClient, type UseAIConfig, type UseAIContextValue, UseAIFloatingButton, UseAIFloatingChatWrapper, type UseAIOptions, UseAIProvider, type UseAIProviderProps, type UseAIResult, type UseAIStrings, type UseAITheme, type UseAIWorkflowResult, type UseAgentSelectionOptions, type UseAgentSelectionReturn, type UseChatManagementOptions, type UseChatManagementReturn, type UseCommandManagementOptions, type UseCommandManagementReturn, type UseDropdownStateOptions, type UseDropdownStateReturn, type UseFeedbackOptions, type UseFeedbackReturn, type UseFileUploadOptions, type UseFileUploadReturn, type UseMessageQueueOptions, type UseMessageQueueReturn, type UsePromptStateOptions, type UsePromptStateReturn, type UseServerEventsOptions, type UseServerEventsReturn, type UseSlashCommandsOptions, type UseSlashCommandsReturn, type UseToolSystemOptions, type UseToolSystemReturn, type WorkflowProgress, clearTransformationCache, convertToolsToDefinitions, defaultStrings, defaultTheme, defineTool, executeDefinedTool, findTransformerPattern, generateChatId, generateCommandId, generateMessageId, matchesMimeType, processAttachments, useAI, useAIContext, useAIWorkflow, useAgentSelection, useChatManagement, useCommandManagement, useDropdownState, useFeedback, useFileUpload, useMessageQueue, usePromptState, useServerEvents, useSlashCommands, useStableTools, useStrings, useTheme, useToolSystem, validateCommandName };
|
package/dist/index.js
CHANGED
|
@@ -374,6 +374,12 @@ function shouldSubmitOnEnter(e, mode) {
|
|
|
374
374
|
return e.metaKey || e.ctrlKey;
|
|
375
375
|
}
|
|
376
376
|
|
|
377
|
+
// src/types.ts
|
|
378
|
+
import { EventType, ErrorCode, TOOL_APPROVAL_REQUEST } from "@meetsmore-oss/use-ai-core";
|
|
379
|
+
var DEFAULT_ENABLED_FEATURES = {
|
|
380
|
+
slashCommands: true
|
|
381
|
+
};
|
|
382
|
+
|
|
377
383
|
// src/components/MarkdownContent.tsx
|
|
378
384
|
import ReactMarkdown from "react-markdown";
|
|
379
385
|
import remarkGfm from "remark-gfm";
|
|
@@ -2189,6 +2195,7 @@ function UseAIChatPanel({
|
|
|
2189
2195
|
fileProcessing,
|
|
2190
2196
|
commands = [],
|
|
2191
2197
|
onSaveCommand,
|
|
2198
|
+
enabledFeatures,
|
|
2192
2199
|
onRenameCommand,
|
|
2193
2200
|
onDeleteCommand,
|
|
2194
2201
|
closeButton,
|
|
@@ -2202,6 +2209,8 @@ function UseAIChatPanel({
|
|
|
2202
2209
|
}) {
|
|
2203
2210
|
const strings = useStrings();
|
|
2204
2211
|
const theme = useTheme();
|
|
2212
|
+
const features = { ...DEFAULT_ENABLED_FEATURES, ...enabledFeatures };
|
|
2213
|
+
const slashCommandsEnabled = features.slashCommands;
|
|
2205
2214
|
const displayMessages = mergeAssistantMessagesForDisplay(messages);
|
|
2206
2215
|
const [input, setInput] = useState6("");
|
|
2207
2216
|
const chatHistoryDropdown = useDropdownState();
|
|
@@ -2776,7 +2785,7 @@ function UseAIChatPanel({
|
|
|
2776
2785
|
maxWidth: "80%"
|
|
2777
2786
|
},
|
|
2778
2787
|
children: [
|
|
2779
|
-
message.role === "user" && hoveredMessageId === message.id && onSaveCommand && !slashCommands.isSavingCommand(message.id) && /* @__PURE__ */ jsx12(
|
|
2788
|
+
message.role === "user" && slashCommandsEnabled && hoveredMessageId === message.id && onSaveCommand && !slashCommands.isSavingCommand(message.id) && /* @__PURE__ */ jsx12(
|
|
2780
2789
|
"button",
|
|
2781
2790
|
{
|
|
2782
2791
|
"data-testid": "save-command-button",
|
|
@@ -3380,6 +3389,7 @@ function UseAIChat({ floating = false, submitMode }) {
|
|
|
3380
3389
|
fileProcessing: ctx.fileProcessing,
|
|
3381
3390
|
commands: ctx.commands.list,
|
|
3382
3391
|
onSaveCommand: ctx.commands.save,
|
|
3392
|
+
enabledFeatures: ctx.enabledFeatures,
|
|
3383
3393
|
onRenameCommand: ctx.commands.rename,
|
|
3384
3394
|
onDeleteCommand: ctx.commands.delete,
|
|
3385
3395
|
executingTool: ctx.tools.executing,
|
|
@@ -3411,7 +3421,7 @@ function UseAIChat({ floating = false, submitMode }) {
|
|
|
3411
3421
|
|
|
3412
3422
|
// src/client.ts
|
|
3413
3423
|
import { io } from "socket.io-client";
|
|
3414
|
-
import { EventType } from "@meetsmore-oss/use-ai-core";
|
|
3424
|
+
import { EventType as EventType2 } from "@meetsmore-oss/use-ai-core";
|
|
3415
3425
|
import { v4 as uuidv42 } from "uuid";
|
|
3416
3426
|
var UseAIClient = class {
|
|
3417
3427
|
/**
|
|
@@ -3517,7 +3527,7 @@ var UseAIClient = class {
|
|
|
3517
3527
|
});
|
|
3518
3528
|
}
|
|
3519
3529
|
handleEvent(event) {
|
|
3520
|
-
if (event.type ===
|
|
3530
|
+
if (event.type === EventType2.RUN_STARTED) {
|
|
3521
3531
|
this._currentAssistantMessage = {
|
|
3522
3532
|
id: uuidv42(),
|
|
3523
3533
|
role: "assistant",
|
|
@@ -3529,31 +3539,31 @@ var UseAIClient = class {
|
|
|
3529
3539
|
this._currentReasoningBlockText = "";
|
|
3530
3540
|
this._currentMessageContent = "";
|
|
3531
3541
|
}
|
|
3532
|
-
if (event.type ===
|
|
3542
|
+
if (event.type === EventType2.TEXT_MESSAGE_START) {
|
|
3533
3543
|
const e = event;
|
|
3534
3544
|
this._currentMessageId = e.messageId;
|
|
3535
3545
|
this._currentMessageContent = "";
|
|
3536
|
-
} else if (event.type ===
|
|
3546
|
+
} else if (event.type === EventType2.TEXT_MESSAGE_CONTENT) {
|
|
3537
3547
|
const e = event;
|
|
3538
3548
|
this._currentMessageContent += e.delta;
|
|
3539
|
-
} else if (event.type ===
|
|
3549
|
+
} else if (event.type === EventType2.TEXT_MESSAGE_END) {
|
|
3540
3550
|
if (this._currentAssistantMessage) {
|
|
3541
3551
|
this._currentAssistantMessage.content = this._currentMessageContent;
|
|
3542
3552
|
}
|
|
3543
3553
|
this._currentMessageId = null;
|
|
3544
|
-
} else if (event.type ===
|
|
3554
|
+
} else if (event.type === EventType2.TOOL_CALL_START) {
|
|
3545
3555
|
const e = event;
|
|
3546
3556
|
this.currentToolCalls.set(e.toolCallId, {
|
|
3547
3557
|
name: e.toolCallName,
|
|
3548
3558
|
args: ""
|
|
3549
3559
|
});
|
|
3550
|
-
} else if (event.type ===
|
|
3560
|
+
} else if (event.type === EventType2.TOOL_CALL_ARGS) {
|
|
3551
3561
|
const e = event;
|
|
3552
3562
|
const toolCall = this.currentToolCalls.get(e.toolCallId);
|
|
3553
3563
|
if (toolCall) {
|
|
3554
3564
|
toolCall.args += e.delta;
|
|
3555
3565
|
}
|
|
3556
|
-
} else if (event.type ===
|
|
3566
|
+
} else if (event.type === EventType2.TOOL_CALL_END) {
|
|
3557
3567
|
const e = event;
|
|
3558
3568
|
const toolCall = this.currentToolCalls.get(e.toolCallId);
|
|
3559
3569
|
if (toolCall) {
|
|
@@ -3566,17 +3576,17 @@ var UseAIClient = class {
|
|
|
3566
3576
|
}
|
|
3567
3577
|
});
|
|
3568
3578
|
}
|
|
3569
|
-
} else if (event.type ===
|
|
3579
|
+
} else if (event.type === EventType2.REASONING_MESSAGE_START) {
|
|
3570
3580
|
this._currentReasoningBlockText = "";
|
|
3571
|
-
} else if (event.type ===
|
|
3581
|
+
} else if (event.type === EventType2.REASONING_MESSAGE_CONTENT) {
|
|
3572
3582
|
const e = event;
|
|
3573
3583
|
this._currentReasoningBlockText += e.delta;
|
|
3574
|
-
} else if (event.type ===
|
|
3584
|
+
} else if (event.type === EventType2.REASONING_MESSAGE_END) {
|
|
3575
3585
|
this._currentReasoningBlocks.push({
|
|
3576
3586
|
text: this._currentReasoningBlockText
|
|
3577
3587
|
});
|
|
3578
3588
|
this._currentReasoningBlockText = "";
|
|
3579
|
-
} else if (event.type ===
|
|
3589
|
+
} else if (event.type === EventType2.REASONING_ENCRYPTED_VALUE) {
|
|
3580
3590
|
const e = event;
|
|
3581
3591
|
if (e.subtype === "message" && this._currentReasoningBlocks.length > 0) {
|
|
3582
3592
|
const lastBlock = this._currentReasoningBlocks[this._currentReasoningBlocks.length - 1];
|
|
@@ -3587,7 +3597,7 @@ var UseAIClient = class {
|
|
|
3587
3597
|
tc.encryptedValue = e.encryptedValue;
|
|
3588
3598
|
}
|
|
3589
3599
|
}
|
|
3590
|
-
} else if (event.type ===
|
|
3600
|
+
} else if (event.type === EventType2.TOOL_CALL_RESULT) {
|
|
3591
3601
|
const e = event;
|
|
3592
3602
|
const alreadyTracked = this._pendingToolResults.some(
|
|
3593
3603
|
(r) => "toolCallId" in r && r.toolCallId === e.toolCallId
|
|
@@ -3600,7 +3610,7 @@ var UseAIClient = class {
|
|
|
3600
3610
|
toolCallId: e.toolCallId
|
|
3601
3611
|
});
|
|
3602
3612
|
}
|
|
3603
|
-
} else if (event.type ===
|
|
3613
|
+
} else if (event.type === EventType2.STEP_FINISHED) {
|
|
3604
3614
|
if (this._currentAssistantToolCalls.length > 0 && this._currentAssistantMessage) {
|
|
3605
3615
|
const reasoningParts = this._currentReasoningBlocks.length > 0 ? [...this._currentReasoningBlocks] : void 0;
|
|
3606
3616
|
const assistantMsg = {
|
|
@@ -3616,11 +3626,12 @@ var UseAIClient = class {
|
|
|
3616
3626
|
this._currentAssistantToolCalls = [];
|
|
3617
3627
|
this._pendingToolResults = [];
|
|
3618
3628
|
this._currentReasoningBlocks = [];
|
|
3629
|
+
this._currentMessageContent = "";
|
|
3619
3630
|
}
|
|
3620
|
-
} else if (event.type ===
|
|
3631
|
+
} else if (event.type === EventType2.RUN_FINISHED) {
|
|
3621
3632
|
this.finalizeRun({ aborted: false });
|
|
3622
3633
|
}
|
|
3623
|
-
if (event.type ===
|
|
3634
|
+
if (event.type === EventType2.RUN_FINISHED || event.type === EventType2.RUN_ERROR) {
|
|
3624
3635
|
this._currentRunId = null;
|
|
3625
3636
|
}
|
|
3626
3637
|
this.eventHandlers.forEach((handler) => handler(event));
|
|
@@ -3913,7 +3924,7 @@ var UseAIClient = class {
|
|
|
3913
3924
|
*/
|
|
3914
3925
|
onTextMessage(handler) {
|
|
3915
3926
|
return this.onEvent("text-message-handler", (event) => {
|
|
3916
|
-
if (event.type ===
|
|
3927
|
+
if (event.type === EventType2.TEXT_MESSAGE_END && this._currentMessageContent) {
|
|
3917
3928
|
handler(this._currentMessageContent);
|
|
3918
3929
|
}
|
|
3919
3930
|
});
|
|
@@ -3927,7 +3938,7 @@ var UseAIClient = class {
|
|
|
3927
3938
|
*/
|
|
3928
3939
|
onToolCall(handler) {
|
|
3929
3940
|
return this.onEvent("tool-call-handler", (event) => {
|
|
3930
|
-
if (event.type ===
|
|
3941
|
+
if (event.type === EventType2.TOOL_CALL_END) {
|
|
3931
3942
|
const e = event;
|
|
3932
3943
|
const toolCall = this.currentToolCalls.get(e.toolCallId);
|
|
3933
3944
|
if (toolCall) {
|
|
@@ -5380,11 +5391,6 @@ function useFeedback({
|
|
|
5380
5391
|
|
|
5381
5392
|
// src/hooks/useServerEvents.ts
|
|
5382
5393
|
import { useState as useState13, useCallback as useCallback11, useRef as useRef10 } from "react";
|
|
5383
|
-
|
|
5384
|
-
// src/types.ts
|
|
5385
|
-
import { EventType as EventType2, ErrorCode, TOOL_APPROVAL_REQUEST } from "@meetsmore-oss/use-ai-core";
|
|
5386
|
-
|
|
5387
|
-
// src/hooks/useServerEvents.ts
|
|
5388
5394
|
function useServerEvents({
|
|
5389
5395
|
toolSystem,
|
|
5390
5396
|
saveAIResponse,
|
|
@@ -5438,21 +5444,21 @@ function useServerEvents({
|
|
|
5438
5444
|
const handleServerEvent = useCallback11(async (client, event) => {
|
|
5439
5445
|
const ts = toolSystemRef.current;
|
|
5440
5446
|
const strs = stringsRef.current;
|
|
5441
|
-
if (event.type ===
|
|
5447
|
+
if (event.type === EventType.RUN_STARTED) {
|
|
5442
5448
|
messageCountAtRunStartRef.current = client.messages.length;
|
|
5443
5449
|
runIdAtRunStartRef.current = client.currentRunId ?? void 0;
|
|
5444
5450
|
hasTextFromPriorStepRef.current = false;
|
|
5445
5451
|
setStreamingReasoning("");
|
|
5446
|
-
} else if (event.type ===
|
|
5452
|
+
} else if (event.type === EventType.REASONING_MESSAGE_START) {
|
|
5447
5453
|
setStreamingReasoning((prev) => prev ? prev + "\n\n" : prev);
|
|
5448
|
-
} else if (event.type ===
|
|
5454
|
+
} else if (event.type === EventType.REASONING_MESSAGE_CONTENT) {
|
|
5449
5455
|
const reasoningEvent = event;
|
|
5450
5456
|
setStreamingReasoning((prev) => prev + reasoningEvent.delta);
|
|
5451
|
-
} else if (event.type ===
|
|
5457
|
+
} else if (event.type === EventType.TEXT_MESSAGE_START) {
|
|
5452
5458
|
if (hasTextFromPriorStepRef.current) {
|
|
5453
5459
|
setStreamingText((prev) => prev + "\n\n");
|
|
5454
5460
|
}
|
|
5455
|
-
} else if (event.type ===
|
|
5461
|
+
} else if (event.type === EventType.TOOL_CALL_START) {
|
|
5456
5462
|
const e = event;
|
|
5457
5463
|
const tool = ts.aggregatedToolsRef.current[e.toolCallName];
|
|
5458
5464
|
const title = e.annotations?.title ?? tool?._options?.annotations?.title ?? null;
|
|
@@ -5461,7 +5467,7 @@ function useServerEvents({
|
|
|
5461
5467
|
executingToolFallbackRef.current = fallbacks[Math.floor(Math.random() * fallbacks.length)];
|
|
5462
5468
|
}
|
|
5463
5469
|
setExecutingTool({ toolCallId: e.toolCallId, title });
|
|
5464
|
-
} else if (event.type ===
|
|
5470
|
+
} else if (event.type === EventType.TOOL_CALL_END) {
|
|
5465
5471
|
const toolCallEnd = event;
|
|
5466
5472
|
const toolCallId = toolCallEnd.toolCallId;
|
|
5467
5473
|
setExecutingTool((prev) => prev?.toolCallId === toolCallId ? null : prev);
|
|
@@ -5486,16 +5492,16 @@ function useServerEvents({
|
|
|
5486
5492
|
} else if (event.type === TOOL_APPROVAL_REQUEST) {
|
|
5487
5493
|
const e = event;
|
|
5488
5494
|
ts.handleApprovalRequest(e);
|
|
5489
|
-
} else if (event.type ===
|
|
5495
|
+
} else if (event.type === EventType.TEXT_MESSAGE_CONTENT) {
|
|
5490
5496
|
const contentEvent = event;
|
|
5491
5497
|
hasTextFromPriorStepRef.current = true;
|
|
5492
5498
|
setStreamingText((prev) => prev + contentEvent.delta);
|
|
5493
|
-
} else if (event.type ===
|
|
5494
|
-
} else if (event.type ===
|
|
5499
|
+
} else if (event.type === EventType.TEXT_MESSAGE_END) {
|
|
5500
|
+
} else if (event.type === EventType.RUN_FINISHED) {
|
|
5495
5501
|
const finishedEvent = event;
|
|
5496
5502
|
await persistFinalResponse(client, { aborted: false, traceId: finishedEvent.runId });
|
|
5497
5503
|
resetRunUiState();
|
|
5498
|
-
} else if (event.type ===
|
|
5504
|
+
} else if (event.type === EventType.RUN_ERROR) {
|
|
5499
5505
|
const errorEvent = event;
|
|
5500
5506
|
const errorCode = errorEvent.message;
|
|
5501
5507
|
if (errorCode === ErrorCode.ABORTED) {
|
|
@@ -5696,6 +5702,7 @@ function UseAIProvider({
|
|
|
5696
5702
|
forwardedPropsProvider,
|
|
5697
5703
|
fileUploadConfig: fileUploadConfigProp,
|
|
5698
5704
|
commandRepository,
|
|
5705
|
+
enabledFeatures,
|
|
5699
5706
|
renderChat = true,
|
|
5700
5707
|
theme: customTheme,
|
|
5701
5708
|
strings: customStrings,
|
|
@@ -5948,6 +5955,7 @@ function UseAIProvider({
|
|
|
5948
5955
|
rename: renameCommand,
|
|
5949
5956
|
delete: deleteCommand
|
|
5950
5957
|
},
|
|
5958
|
+
enabledFeatures,
|
|
5951
5959
|
ui: {
|
|
5952
5960
|
isOpen: isChatOpen,
|
|
5953
5961
|
setOpen: handleSetChatOpen
|
|
@@ -5991,6 +5999,7 @@ function UseAIProvider({
|
|
|
5991
5999
|
fileProcessing: fileProcessingState,
|
|
5992
6000
|
commands,
|
|
5993
6001
|
onSaveCommand: saveCommand,
|
|
6002
|
+
enabledFeatures,
|
|
5994
6003
|
onRenameCommand: renameCommand,
|
|
5995
6004
|
onDeleteCommand: deleteCommand,
|
|
5996
6005
|
executingTool: serverEvents.executingTool,
|
|
@@ -6224,7 +6233,7 @@ function useAI(options = {}) {
|
|
|
6224
6233
|
}, [enabled, client]);
|
|
6225
6234
|
const handleAGUIEvent = useCallback14(async (event) => {
|
|
6226
6235
|
switch (event.type) {
|
|
6227
|
-
case
|
|
6236
|
+
case EventType.TEXT_MESSAGE_END: {
|
|
6228
6237
|
const content = client?.currentMessageContent;
|
|
6229
6238
|
if (content) {
|
|
6230
6239
|
setResponse(content);
|
|
@@ -6232,7 +6241,7 @@ function useAI(options = {}) {
|
|
|
6232
6241
|
}
|
|
6233
6242
|
break;
|
|
6234
6243
|
}
|
|
6235
|
-
case
|
|
6244
|
+
case EventType.RUN_ERROR: {
|
|
6236
6245
|
const errorEvent = event;
|
|
6237
6246
|
const error2 = new Error(errorEvent.message);
|
|
6238
6247
|
setError(error2);
|