2024-06-25 03:02:38 -04:00
|
|
|
import { v4 } from 'uuid';
|
2024-08-30 00:14:37 -04:00
|
|
|
import { useCallback, useRef } from 'react';
|
2024-08-18 19:02:46 -04:00
|
|
|
import { useSetRecoilState } from 'recoil';
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
import { useParams, useNavigate, useLocation } from 'react-router-dom';
|
2024-06-25 03:02:38 -04:00
|
|
|
import { useQueryClient } from '@tanstack/react-query';
|
|
|
|
|
import {
|
|
|
|
|
QueryKeys,
|
|
|
|
|
Constants,
|
|
|
|
|
EndpointURLs,
|
|
|
|
|
tPresetSchema,
|
|
|
|
|
tMessageSchema,
|
|
|
|
|
tConvoUpdateSchema,
|
🎨 feat: UI Refresh for Enhanced UX (#6346)
* ✨ feat: Add Expand Chat functionality and improve UI components
* ✨ feat: Introduce Chat Badges feature with editing capabilities and UI enhancements
* ✨ feat: re-implement file attachment functionality with new components and improved UI
* ✨ feat: Enhance BadgeRow component with drag-and-drop functionality and add animations for better user experience
* ✨ feat: Add useChatBadges hook and enhance Badge component with animations and toggle functionality
* feat: Improve Add/Delete Badges + style and bug fixes
* ✨ feat: Refactor EditBadges component and optimize useChatBadges hook for improved performance and readability
* ✨ feat: Add type definition for LucideIcon in EditBadges component
* refactor: Clean up BadgeRow component by removing outdated comment and improving code readability
* refactor: Rename app-icon class to badge-icon for consistency and improve badge styling
* feat: Add Center Chat Input toggle and update related components for improved UI/UX
* refactor: Simplify ChatView and MessagesView components for improved readability and performance
* refactor: Improve layout and positioning of scroll button in MessagesView component
* refactor: Adjust scroll button position in MessagesView component for better visibility
* refactor: Remove redundant background class from Badge component for cleaner styling
* feat: disable chat badges
* refactor: adjust positioning of scroll button and popover for improved layout
* refactor: simplify class names in ChatForm and RemoveFile components for cleaner code
* refactor: move Switcher to HeaderOptions from SidePanel
* fix(Landing): duplicate description
* feat: add SplitText component for animated text display and update Landing component to use it
* feat(Chat): add ConversationStarters component and integrate it into ChatView; remove ConvoStarter component
* feat(Chat): enhance Message component layout and styling for improved readability
* feat(ControlCombobox, Select): enhance styling and add animation for improved UI experience
* feat(Chat): update Header and HeaderNewChat components for improved layout and styling
* feat(Chat): add ModelDropdown (now includes both endpoint and model) and refactor Menu components for improved UI
* feat(ModelDropdown): add Agent Select; removed old AgentSwitcher components
* feat(ModelDropdown): add settings button for user key configuration
* fix(ModelDropdown): the model dropdown wasn't opening automatically when opening the endpoint one
* refactor(Chat): remove unused EndpointsMenu and related components to streamline codebase
* feat: enhance greeting message and improve accessibility fro ModelDropdown
* refactor(Endpoints): add new hooks and components for endpoint management
* feat(Endpoint): add support for modelSpecs
* feat(Endpoints): add mobile support
* fix: type issues
* fix(modelSpec): type issue
* fix(EndpointMenuDropdown): double overflow scroller in mobile model list
* fix: search model on mobile
* refactor: Endpoint/Model/modelSpec dropdown
* refactor: reorganize imports in Endpoint components
* refactor: remove unused translation keys from English locale
* BREAKING: moving to ariakit with new CustomMenu
* refactor: remove unnecessary comments
* refactor: remove EndpointItem, ModelDropdownButton, SpecIcon, and SpecItem components
* 🔧 fix: AI Icon bump when regenerating message
* wip: chat UI refactoring, fix issues
* chore: add recent update to useAutoSave
* feat: add access control for agent permissions in useMentions hook
* refactor: streamline ModelSelector by removing unused endpoints logic
* refactor: enhance ModelSelector and context by integrating endpointsConfig and improving type usage
* feat: update ModelSelectorContext to utilize conversation data for initial state
* feat: add selector effects for synced endpoint handling
* feat: add guard clause for conversation endpoint in useSelectorEffects hook
* fix: safely call onSelectMention and add autofocus to mention input
* chore: typing
* refactor: ModelSelector to streamline key dialog handling and improve endpoint rendering
* refactor: extract SettingsButton component for cleaner endpoint item rendering
* wip: first pass, expand set api key
* wip: first pass, expanding set key
* refactor: update EndpointItem styles for improved layout and hover effects
* refactor: adjust padding in EndpointItem for improved layout consistency
* refactor: update preset structure in useSelectMention to include spec as null
* refactor: rename setKeyDialogOpen to onOpenChange for clarity and consistency, bring focus back to button that opened dialog
* feat: add SpecIcon component for dynamic model spec icons in menu, adjust icon styling
* refactor: update getSelectedIcon to accept additional parameters and improve icon rendering logic
* fix: adjust padding in MessageRender for improved layout
* refactor: remove inline style for menu width in CustomMenu component
* refactor: enhance layout and styling in ModelSpecItem component for better responsiveness
* refactor: update getDefaultModelSpec to accept startupConfig and improve model spec retrieval logic
* refactor: improve key management and default values in ModelSelector and related components
* refactor: adjust menu width and improve responsiveness in CustomMenu and EndpointItem components
* refactor: enhance focus styles and responsiveness in EndpointItem component
* refactor: improve layout and spacing in Header and ModelSelector components for better responsiveness
* refactor: adjust button styles for consistency and improved layout in AddMultiConvo and PresetsMenu components
* fix: initial fix of assistant names
* fix: assistants handling
* chore: update version of librechat-data-provider to 0.7.75 and add 'spec' to excludedKeys
* fix: improve endpoint filtering logic based on interface configuration and access rights
* fix: remove unused HeaderOptions import and set spec to null in presets and mentions
* fix: ensure currentExample is always an object when updating examples
* fix: update interfaceConfig checks to ensure modelSelect is considered for rendering components
* fix: update model selection logic to consider interface configuration when prioritizing model specs
* fix: add missing localizations
* fix: remove unused agent and assistant selection translations
* fix: implement debounced state updates for selected values in useSelectorEffects
* style: minor style changes related to the ModelSelector
* fix: adjust maximum height for popover and set fixed height for model item
* fix: update placeholders for model and endpoint search inputs
* fix: refactor MessageRender and ContentRender components to better match each other
* fix: remove convo fallback for iconURL in MessageRender and ContentRender components
* fix: update handling of spec, iconURL, and modelLabel in conversation presets, to allow better interchangeability
* fix: replace chatGptLabel with modelLabel in OpenAI settings configuration (fully deprecate chatGptLabel)
* fix: remove console log for assistantNames in useEndpoints hook
* refactor: add cleanInput and cleanOutput options to default conversation handling
* chore: update bun.lockb
* fix: set default value for showIconInHeader in getSelectedIcon function
* refactor: enhance error handling in message processing when latest message has existing content blocks
* chore: allow import/no-cycle for messages
* fix: adjust flex properties in BookmarkMenu for better layout
* feat: support both 'prompt' and 'q' as query parameters in useQueryParams hook
* feat: re-enable Badges components
* refactor: disable edit badge component
* chore: rename assistantMap to assistantsMap for consistency
* chore: rename assistantMap to assistantsMap for consistency in Mention component
* feat: set staleTime for various queries to improve data freshness
* feat: add spec field to tQueryParamsSchema for model specification
* feat: enhance useQueryParams to handle model specs
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-25 23:50:58 +01:00
|
|
|
ContentTypes,
|
2025-04-12 18:46:36 -04:00
|
|
|
isAssistantsEndpoint,
|
2024-06-25 03:02:38 -04:00
|
|
|
} from 'librechat-data-provider';
|
2025-04-15 10:04:00 +02:00
|
|
|
import type { TMessage, TConversation, EventSubmission } from 'librechat-data-provider';
|
2024-08-19 03:51:17 -04:00
|
|
|
import type { TResData, TFinalResData, ConvoGenerator } from '~/common';
|
2025-04-15 10:04:00 +02:00
|
|
|
import type { InfiniteData } from '@tanstack/react-query';
|
🚧 chore: merge latest dev build to main repo (#3844)
* agents - phase 1 (#30)
* chore: copy assistant files
* feat: frontend and data-provider
* feat: backend get endpoint test
* fix(MessageEndpointIcon): switched to AgentName and AgentAvatar
* fix: small fixes
* fix: agent endpoint config
* fix: show Agent Builder
* chore: install agentus
* chore: initial scaffolding for agents
* fix: updated Assistant logic to Agent Logic for some Agent components
* WIP first pass, demo of agent package
* WIP: initial backend infra for agents
* fix: agent list error
* wip: agents routing
* chore: Refactor useSSE hook to handle different data events
* wip: correctly emit events
* chore: Update @librechat/agentus npm dependency to version 1.0.9
* remove comment
* first pass: streaming agent text
* chore: Remove @librechat/agentus root-level workspace npm dependency
* feat: Agent Schema and Model
* fix: content handling fixes
* fix: content message save
* WIP: new content data
* fix: run step issue with tool calls
* chore: Update @librechat/agentus npm dependency to version 1.1.5
* feat: update controller and agent routes
* wip: initial backend tool and tool error handling support
* wip: tool chunks
* chore: Update @librechat/agentus npm dependency to version 1.1.7
* chore: update tool_call typing, add test conditions and logs
* fix: create agent
* fix: create agent
* first pass: render completed content parts
* fix: remove logging, fix step handler typing
* chore: Update @librechat/agentus npm dependency to version 1.1.9
* refactor: cleanup maps on unmount
* chore: Update BaseClient.js to safely count tokens for string, number, and boolean values
* fix: support subsequent messages with tool_calls
* chore: export order
* fix: select agent
* fix: tool call types and handling
* chore: switch to anthropic for testing
* fix: AgentSelect
* refactor: experimental: OpenAIClient to use array for intermediateReply
* fix(useSSE): revert old condition for streaming legacy client tokens
* fix: lint
* revert `agent_id` to `id`
* chore: update localization keys for agent-related components
* feat: zod schema handling for actions
* refactor(actions): if no params, no zodSchema
* chore: Update @librechat/agentus npm dependency to version 1.2.1
* feat: first pass, actions
* refactor: empty schema for actions without params
* feat: Update createRun function to accept additional options
* fix: message payload formatting; feat: add more client options
* fix: ToolCall component rendering when action has no args but has output
* refactor(ToolCall): allow non-stringy args
* WIP: first pass, correctly formatted tool_calls between providers
* refactor: Remove duplicate import of 'roles' module
* refactor: Exclude 'vite.config.ts' from TypeScript compilation
* refactor: fix agent related types
> - no need to use endpoint/model fields for identifying agent metadata
> - add `provider` distinction for agent-configured 'endpoint'
- no need for agent-endpoint map
- reduce complexity of tools as functions into tools as string[]
- fix types related to above changes
- reduce unnecessary variables for queries/mutations and corresponding react-query keys
* refactor: Add tools and tool_kwargs fields to agent schema
* refactor: Remove unused code and update dependencies
* refactor: Update updateAgentHandler to use req.body directly
* refactor: Update AgentSelect component to use localized hooks
* refactor: Update agent schema to include tools and provider fields
* refactor(AgentPanel): add scrollbar gutter, add provider field to form, fix agent schema required values
* refactor: Update AgentSwitcher component to use selectedAgentId instead of selectedAgent
* refactor: Update AgentPanel component to include alternateName import and defaultAgentFormValues
* refactor(SelectDropDown): allow setting value as option while still supporting legacy usage (string values only)
* refactor: SelectDropdown changes - Only necessary when the available values are objects with label/value fields and the selected value is expected to be a string.
* refactor: TypeError issues and handle provider as option
* feat: Add placeholder for provider selection in AgentPanel component
* refactor: Update agent schema to include author and provider fields
* fix: show expected 'create agent' placeholder when creating agent
* chore: fix localization strings, hide capabilities form for now
* chore: typing
* refactor: import order and use compact agents schema for now
* chore: typing
* refactor: Update AgentForm type to use AgentCapabilities
* fix agent form agent selection issues
* feat: responsive agent selection
* fix: Handle cancelled fetch in useSelectAgent hook
* fix: reset agent form on accordion close/open
* feat: Add agent_id to default conversation for agents endpoint
* feat: agents endpoint request handling
* refactor: reset conversation model on agent select
* refactor: add `additional_instructions` to conversation schema, organize other fields
* chore: casing
* chore: types
* refactor(loadAgentTools): explicitly pass agent_id, do not pass `model` to loadAgentTools for now, load action sets by agent_id
* WIP: initial draft of real agent client initialization
* WIP: first pass, anthropic agent requests
* feat: remember last selected agent
* feat: openai and azure connected
* fix: prioritize agent model for runs unless an explicit override model is passed from client
* feat: Agent Actions
* fix: save agent id to convo
* feat: model panel (#29)
* feat: model panel
* bring back comments
* fix: method still null
* fix: AgentPanel FormContext
* feat: add more parameters
* fix: style issues; refactor: Agent Controller
* fix: cherry-pick
* fix: Update AgentAvatar component to use AssistantIcon instead of BrainCircuit
* feat: OGDialog for delete agent; feat(assistant): update Agent types, introduced `model_parameters`
* feat: icon and general `model_parameters` update
* feat: use react-hook-form better
* fix: agent builder form reset issue when switching panels
* refactor: modularize agent builder form
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
* fix: AgentPanel and ModelPanel type issues and use `useFormContext` and `watch` instead of `methods` directly and `useWatch`.
* fix: tool call issues due to invalid input (anthropic) of empty string
* fix: handle empty text in Part component
---------
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
* refactor: remove form ModelPanel and fixed nested ternary expressions in AgentConfig
* fix: Model Parameters not saved correctly
* refactor: remove console log
* feat: avatar upload and get for Agents (#36)
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
* chore: update to public package
* fix: typing, optional chaining
* fix: cursor not showing for content parts
* chore: conditionally enable agents
* ci: fix azure test
* ci: fix frontend tests, fix eslint api
* refactor: Remove unused errorContentPart variable
* continue of the agent message PR (#40)
* last fixes
* fix: agentMap
* pr merge test (#41)
* fix: model icon not fetching correctly
* remove console logs
* feat: agent name
* refactor: pass documentsMap as a prop to allow re-render of assistant form
* refactor: pass documentsMap as a prop to allow re-render of assistant form
* chore: Bump version to 0.7.419
* fix: TypeError: Cannot read properties of undefined (reading 'id')
* refactor: update AgentSwitcher component to use ControlCombobox instead of Combobox
---------
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
2024-08-31 16:33:51 -04:00
|
|
|
import type { TGenTitleMutation } from '~/data-provider';
|
2025-04-15 10:04:00 +02:00
|
|
|
import type { SetterOrUpdater, Resetter } from 'recoil';
|
|
|
|
|
import type { ConversationCursorData } from '~/utils';
|
2024-06-25 03:02:38 -04:00
|
|
|
import {
|
2025-04-29 03:49:02 -04:00
|
|
|
logger,
|
2024-08-09 02:11:56 -04:00
|
|
|
scrollToEnd,
|
2025-04-29 03:49:02 -04:00
|
|
|
getAllContentText,
|
2025-04-15 10:04:00 +02:00
|
|
|
addConvoToAllQueries,
|
|
|
|
|
updateConvoInAllQueries,
|
|
|
|
|
removeConvoFromAllQueries,
|
|
|
|
|
findConversationInInfinite,
|
2024-06-25 03:02:38 -04:00
|
|
|
} from '~/utils';
|
2024-09-30 17:17:57 -04:00
|
|
|
import useAttachmentHandler from '~/hooks/SSE/useAttachmentHandler';
|
2024-06-25 03:02:38 -04:00
|
|
|
import useContentHandler from '~/hooks/SSE/useContentHandler';
|
2025-04-07 19:16:56 -04:00
|
|
|
import store, { useApplyNewAgentTemplate } from '~/store';
|
🚧 chore: merge latest dev build to main repo (#3844)
* agents - phase 1 (#30)
* chore: copy assistant files
* feat: frontend and data-provider
* feat: backend get endpoint test
* fix(MessageEndpointIcon): switched to AgentName and AgentAvatar
* fix: small fixes
* fix: agent endpoint config
* fix: show Agent Builder
* chore: install agentus
* chore: initial scaffolding for agents
* fix: updated Assistant logic to Agent Logic for some Agent components
* WIP first pass, demo of agent package
* WIP: initial backend infra for agents
* fix: agent list error
* wip: agents routing
* chore: Refactor useSSE hook to handle different data events
* wip: correctly emit events
* chore: Update @librechat/agentus npm dependency to version 1.0.9
* remove comment
* first pass: streaming agent text
* chore: Remove @librechat/agentus root-level workspace npm dependency
* feat: Agent Schema and Model
* fix: content handling fixes
* fix: content message save
* WIP: new content data
* fix: run step issue with tool calls
* chore: Update @librechat/agentus npm dependency to version 1.1.5
* feat: update controller and agent routes
* wip: initial backend tool and tool error handling support
* wip: tool chunks
* chore: Update @librechat/agentus npm dependency to version 1.1.7
* chore: update tool_call typing, add test conditions and logs
* fix: create agent
* fix: create agent
* first pass: render completed content parts
* fix: remove logging, fix step handler typing
* chore: Update @librechat/agentus npm dependency to version 1.1.9
* refactor: cleanup maps on unmount
* chore: Update BaseClient.js to safely count tokens for string, number, and boolean values
* fix: support subsequent messages with tool_calls
* chore: export order
* fix: select agent
* fix: tool call types and handling
* chore: switch to anthropic for testing
* fix: AgentSelect
* refactor: experimental: OpenAIClient to use array for intermediateReply
* fix(useSSE): revert old condition for streaming legacy client tokens
* fix: lint
* revert `agent_id` to `id`
* chore: update localization keys for agent-related components
* feat: zod schema handling for actions
* refactor(actions): if no params, no zodSchema
* chore: Update @librechat/agentus npm dependency to version 1.2.1
* feat: first pass, actions
* refactor: empty schema for actions without params
* feat: Update createRun function to accept additional options
* fix: message payload formatting; feat: add more client options
* fix: ToolCall component rendering when action has no args but has output
* refactor(ToolCall): allow non-stringy args
* WIP: first pass, correctly formatted tool_calls between providers
* refactor: Remove duplicate import of 'roles' module
* refactor: Exclude 'vite.config.ts' from TypeScript compilation
* refactor: fix agent related types
> - no need to use endpoint/model fields for identifying agent metadata
> - add `provider` distinction for agent-configured 'endpoint'
- no need for agent-endpoint map
- reduce complexity of tools as functions into tools as string[]
- fix types related to above changes
- reduce unnecessary variables for queries/mutations and corresponding react-query keys
* refactor: Add tools and tool_kwargs fields to agent schema
* refactor: Remove unused code and update dependencies
* refactor: Update updateAgentHandler to use req.body directly
* refactor: Update AgentSelect component to use localized hooks
* refactor: Update agent schema to include tools and provider fields
* refactor(AgentPanel): add scrollbar gutter, add provider field to form, fix agent schema required values
* refactor: Update AgentSwitcher component to use selectedAgentId instead of selectedAgent
* refactor: Update AgentPanel component to include alternateName import and defaultAgentFormValues
* refactor(SelectDropDown): allow setting value as option while still supporting legacy usage (string values only)
* refactor: SelectDropdown changes - Only necessary when the available values are objects with label/value fields and the selected value is expected to be a string.
* refactor: TypeError issues and handle provider as option
* feat: Add placeholder for provider selection in AgentPanel component
* refactor: Update agent schema to include author and provider fields
* fix: show expected 'create agent' placeholder when creating agent
* chore: fix localization strings, hide capabilities form for now
* chore: typing
* refactor: import order and use compact agents schema for now
* chore: typing
* refactor: Update AgentForm type to use AgentCapabilities
* fix agent form agent selection issues
* feat: responsive agent selection
* fix: Handle cancelled fetch in useSelectAgent hook
* fix: reset agent form on accordion close/open
* feat: Add agent_id to default conversation for agents endpoint
* feat: agents endpoint request handling
* refactor: reset conversation model on agent select
* refactor: add `additional_instructions` to conversation schema, organize other fields
* chore: casing
* chore: types
* refactor(loadAgentTools): explicitly pass agent_id, do not pass `model` to loadAgentTools for now, load action sets by agent_id
* WIP: initial draft of real agent client initialization
* WIP: first pass, anthropic agent requests
* feat: remember last selected agent
* feat: openai and azure connected
* fix: prioritize agent model for runs unless an explicit override model is passed from client
* feat: Agent Actions
* fix: save agent id to convo
* feat: model panel (#29)
* feat: model panel
* bring back comments
* fix: method still null
* fix: AgentPanel FormContext
* feat: add more parameters
* fix: style issues; refactor: Agent Controller
* fix: cherry-pick
* fix: Update AgentAvatar component to use AssistantIcon instead of BrainCircuit
* feat: OGDialog for delete agent; feat(assistant): update Agent types, introduced `model_parameters`
* feat: icon and general `model_parameters` update
* feat: use react-hook-form better
* fix: agent builder form reset issue when switching panels
* refactor: modularize agent builder form
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
* fix: AgentPanel and ModelPanel type issues and use `useFormContext` and `watch` instead of `methods` directly and `useWatch`.
* fix: tool call issues due to invalid input (anthropic) of empty string
* fix: handle empty text in Part component
---------
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
* refactor: remove form ModelPanel and fixed nested ternary expressions in AgentConfig
* fix: Model Parameters not saved correctly
* refactor: remove console log
* feat: avatar upload and get for Agents (#36)
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
* chore: update to public package
* fix: typing, optional chaining
* fix: cursor not showing for content parts
* chore: conditionally enable agents
* ci: fix azure test
* ci: fix frontend tests, fix eslint api
* refactor: Remove unused errorContentPart variable
* continue of the agent message PR (#40)
* last fixes
* fix: agentMap
* pr merge test (#41)
* fix: model icon not fetching correctly
* remove console logs
* feat: agent name
* refactor: pass documentsMap as a prop to allow re-render of assistant form
* refactor: pass documentsMap as a prop to allow re-render of assistant form
* chore: Bump version to 0.7.419
* fix: TypeError: Cannot read properties of undefined (reading 'id')
* refactor: update AgentSwitcher component to use ControlCombobox instead of Combobox
---------
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
2024-08-31 16:33:51 -04:00
|
|
|
import useStepHandler from '~/hooks/SSE/useStepHandler';
|
2024-06-25 03:02:38 -04:00
|
|
|
import { useAuthContext } from '~/hooks/AuthContext';
|
2024-09-10 19:00:27 -04:00
|
|
|
import { MESSAGE_UPDATE_INTERVAL } from '~/common';
|
2024-08-13 03:04:27 -04:00
|
|
|
import { useLiveAnnouncer } from '~/Providers';
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
type TSyncData = {
|
|
|
|
|
sync: boolean;
|
|
|
|
|
thread_id: string;
|
|
|
|
|
messages?: TMessage[];
|
|
|
|
|
requestMessage: TMessage;
|
|
|
|
|
responseMessage: TMessage;
|
|
|
|
|
conversationId: string;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export type EventHandlerParams = {
|
|
|
|
|
isAddedRequest?: boolean;
|
|
|
|
|
genTitle?: TGenTitleMutation;
|
|
|
|
|
setCompleted: React.Dispatch<React.SetStateAction<Set<unknown>>>;
|
|
|
|
|
setMessages: (messages: TMessage[]) => void;
|
|
|
|
|
getMessages: () => TMessage[] | undefined;
|
|
|
|
|
setIsSubmitting: SetterOrUpdater<boolean>;
|
|
|
|
|
setConversation?: SetterOrUpdater<TConversation | null>;
|
|
|
|
|
newConversation?: ConvoGenerator;
|
|
|
|
|
setShowStopButton: SetterOrUpdater<boolean>;
|
|
|
|
|
resetLatestMessage?: Resetter;
|
|
|
|
|
};
|
|
|
|
|
|
🎨 feat: UI Refresh for Enhanced UX (#6346)
* ✨ feat: Add Expand Chat functionality and improve UI components
* ✨ feat: Introduce Chat Badges feature with editing capabilities and UI enhancements
* ✨ feat: re-implement file attachment functionality with new components and improved UI
* ✨ feat: Enhance BadgeRow component with drag-and-drop functionality and add animations for better user experience
* ✨ feat: Add useChatBadges hook and enhance Badge component with animations and toggle functionality
* feat: Improve Add/Delete Badges + style and bug fixes
* ✨ feat: Refactor EditBadges component and optimize useChatBadges hook for improved performance and readability
* ✨ feat: Add type definition for LucideIcon in EditBadges component
* refactor: Clean up BadgeRow component by removing outdated comment and improving code readability
* refactor: Rename app-icon class to badge-icon for consistency and improve badge styling
* feat: Add Center Chat Input toggle and update related components for improved UI/UX
* refactor: Simplify ChatView and MessagesView components for improved readability and performance
* refactor: Improve layout and positioning of scroll button in MessagesView component
* refactor: Adjust scroll button position in MessagesView component for better visibility
* refactor: Remove redundant background class from Badge component for cleaner styling
* feat: disable chat badges
* refactor: adjust positioning of scroll button and popover for improved layout
* refactor: simplify class names in ChatForm and RemoveFile components for cleaner code
* refactor: move Switcher to HeaderOptions from SidePanel
* fix(Landing): duplicate description
* feat: add SplitText component for animated text display and update Landing component to use it
* feat(Chat): add ConversationStarters component and integrate it into ChatView; remove ConvoStarter component
* feat(Chat): enhance Message component layout and styling for improved readability
* feat(ControlCombobox, Select): enhance styling and add animation for improved UI experience
* feat(Chat): update Header and HeaderNewChat components for improved layout and styling
* feat(Chat): add ModelDropdown (now includes both endpoint and model) and refactor Menu components for improved UI
* feat(ModelDropdown): add Agent Select; removed old AgentSwitcher components
* feat(ModelDropdown): add settings button for user key configuration
* fix(ModelDropdown): the model dropdown wasn't opening automatically when opening the endpoint one
* refactor(Chat): remove unused EndpointsMenu and related components to streamline codebase
* feat: enhance greeting message and improve accessibility fro ModelDropdown
* refactor(Endpoints): add new hooks and components for endpoint management
* feat(Endpoint): add support for modelSpecs
* feat(Endpoints): add mobile support
* fix: type issues
* fix(modelSpec): type issue
* fix(EndpointMenuDropdown): double overflow scroller in mobile model list
* fix: search model on mobile
* refactor: Endpoint/Model/modelSpec dropdown
* refactor: reorganize imports in Endpoint components
* refactor: remove unused translation keys from English locale
* BREAKING: moving to ariakit with new CustomMenu
* refactor: remove unnecessary comments
* refactor: remove EndpointItem, ModelDropdownButton, SpecIcon, and SpecItem components
* 🔧 fix: AI Icon bump when regenerating message
* wip: chat UI refactoring, fix issues
* chore: add recent update to useAutoSave
* feat: add access control for agent permissions in useMentions hook
* refactor: streamline ModelSelector by removing unused endpoints logic
* refactor: enhance ModelSelector and context by integrating endpointsConfig and improving type usage
* feat: update ModelSelectorContext to utilize conversation data for initial state
* feat: add selector effects for synced endpoint handling
* feat: add guard clause for conversation endpoint in useSelectorEffects hook
* fix: safely call onSelectMention and add autofocus to mention input
* chore: typing
* refactor: ModelSelector to streamline key dialog handling and improve endpoint rendering
* refactor: extract SettingsButton component for cleaner endpoint item rendering
* wip: first pass, expand set api key
* wip: first pass, expanding set key
* refactor: update EndpointItem styles for improved layout and hover effects
* refactor: adjust padding in EndpointItem for improved layout consistency
* refactor: update preset structure in useSelectMention to include spec as null
* refactor: rename setKeyDialogOpen to onOpenChange for clarity and consistency, bring focus back to button that opened dialog
* feat: add SpecIcon component for dynamic model spec icons in menu, adjust icon styling
* refactor: update getSelectedIcon to accept additional parameters and improve icon rendering logic
* fix: adjust padding in MessageRender for improved layout
* refactor: remove inline style for menu width in CustomMenu component
* refactor: enhance layout and styling in ModelSpecItem component for better responsiveness
* refactor: update getDefaultModelSpec to accept startupConfig and improve model spec retrieval logic
* refactor: improve key management and default values in ModelSelector and related components
* refactor: adjust menu width and improve responsiveness in CustomMenu and EndpointItem components
* refactor: enhance focus styles and responsiveness in EndpointItem component
* refactor: improve layout and spacing in Header and ModelSelector components for better responsiveness
* refactor: adjust button styles for consistency and improved layout in AddMultiConvo and PresetsMenu components
* fix: initial fix of assistant names
* fix: assistants handling
* chore: update version of librechat-data-provider to 0.7.75 and add 'spec' to excludedKeys
* fix: improve endpoint filtering logic based on interface configuration and access rights
* fix: remove unused HeaderOptions import and set spec to null in presets and mentions
* fix: ensure currentExample is always an object when updating examples
* fix: update interfaceConfig checks to ensure modelSelect is considered for rendering components
* fix: update model selection logic to consider interface configuration when prioritizing model specs
* fix: add missing localizations
* fix: remove unused agent and assistant selection translations
* fix: implement debounced state updates for selected values in useSelectorEffects
* style: minor style changes related to the ModelSelector
* fix: adjust maximum height for popover and set fixed height for model item
* fix: update placeholders for model and endpoint search inputs
* fix: refactor MessageRender and ContentRender components to better match each other
* fix: remove convo fallback for iconURL in MessageRender and ContentRender components
* fix: update handling of spec, iconURL, and modelLabel in conversation presets, to allow better interchangeability
* fix: replace chatGptLabel with modelLabel in OpenAI settings configuration (fully deprecate chatGptLabel)
* fix: remove console log for assistantNames in useEndpoints hook
* refactor: add cleanInput and cleanOutput options to default conversation handling
* chore: update bun.lockb
* fix: set default value for showIconInHeader in getSelectedIcon function
* refactor: enhance error handling in message processing when latest message has existing content blocks
* chore: allow import/no-cycle for messages
* fix: adjust flex properties in BookmarkMenu for better layout
* feat: support both 'prompt' and 'q' as query parameters in useQueryParams hook
* feat: re-enable Badges components
* refactor: disable edit badge component
* chore: rename assistantMap to assistantsMap for consistency
* chore: rename assistantMap to assistantsMap for consistency in Mention component
* feat: set staleTime for various queries to improve data freshness
* feat: add spec field to tQueryParamsSchema for model specification
* feat: enhance useQueryParams to handle model specs
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-25 23:50:58 +01:00
|
|
|
const createErrorMessage = ({
|
|
|
|
|
errorMetadata,
|
|
|
|
|
getMessages,
|
|
|
|
|
submission,
|
|
|
|
|
error,
|
|
|
|
|
}: {
|
|
|
|
|
getMessages: () => TMessage[] | undefined;
|
|
|
|
|
errorMetadata?: Partial<TMessage>;
|
|
|
|
|
submission: EventSubmission;
|
|
|
|
|
error?: Error | unknown;
|
|
|
|
|
}) => {
|
|
|
|
|
const currentMessages = getMessages();
|
|
|
|
|
const latestMessage = currentMessages?.[currentMessages.length - 1];
|
|
|
|
|
let errorMessage: TMessage;
|
|
|
|
|
const text = submission.initialResponse.text.length > 45 ? submission.initialResponse.text : '';
|
|
|
|
|
const errorText =
|
|
|
|
|
(errorMetadata?.text || text || (error as Error | undefined)?.message) ??
|
|
|
|
|
'Error cancelling request';
|
|
|
|
|
const latestContent = latestMessage?.content ?? [];
|
|
|
|
|
let isValidContentPart = false;
|
|
|
|
|
if (latestContent.length > 0) {
|
|
|
|
|
const latestContentPart = latestContent[latestContent.length - 1];
|
|
|
|
|
const latestPartValue = latestContentPart?.[latestContentPart.type ?? ''];
|
|
|
|
|
isValidContentPart =
|
|
|
|
|
latestContentPart.type !== ContentTypes.TEXT ||
|
|
|
|
|
(latestContentPart.type === ContentTypes.TEXT && typeof latestPartValue === 'string')
|
|
|
|
|
? true
|
|
|
|
|
: latestPartValue?.value !== '';
|
|
|
|
|
}
|
|
|
|
|
if (
|
|
|
|
|
latestMessage?.conversationId &&
|
|
|
|
|
latestMessage?.messageId &&
|
|
|
|
|
latestContent &&
|
|
|
|
|
isValidContentPart
|
|
|
|
|
) {
|
|
|
|
|
const content = [...latestContent];
|
|
|
|
|
content.push({
|
|
|
|
|
type: ContentTypes.ERROR,
|
|
|
|
|
error: errorText,
|
|
|
|
|
});
|
|
|
|
|
errorMessage = {
|
|
|
|
|
...latestMessage,
|
|
|
|
|
...errorMetadata,
|
|
|
|
|
error: undefined,
|
|
|
|
|
text: '',
|
|
|
|
|
content,
|
|
|
|
|
};
|
|
|
|
|
if (
|
|
|
|
|
submission.userMessage.messageId &&
|
|
|
|
|
submission.userMessage.messageId !== errorMessage.parentMessageId
|
|
|
|
|
) {
|
|
|
|
|
errorMessage.parentMessageId = submission.userMessage.messageId;
|
|
|
|
|
}
|
|
|
|
|
return errorMessage;
|
|
|
|
|
} else if (errorMetadata) {
|
|
|
|
|
return errorMetadata as TMessage;
|
|
|
|
|
} else {
|
|
|
|
|
errorMessage = {
|
|
|
|
|
...submission,
|
|
|
|
|
...submission.initialResponse,
|
|
|
|
|
text: errorText,
|
|
|
|
|
unfinished: !!text.length,
|
|
|
|
|
error: true,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return tMessageSchema.parse(errorMessage);
|
|
|
|
|
};
|
|
|
|
|
|
2025-04-15 10:04:00 +02:00
|
|
|
export const getConvoTitle = ({
|
|
|
|
|
parentId,
|
|
|
|
|
queryClient,
|
|
|
|
|
currentTitle,
|
|
|
|
|
conversationId,
|
|
|
|
|
}: {
|
|
|
|
|
parentId?: string | null;
|
|
|
|
|
queryClient: ReturnType<typeof useQueryClient>;
|
|
|
|
|
currentTitle?: string | null;
|
|
|
|
|
conversationId?: string | null;
|
|
|
|
|
}): string | null | undefined => {
|
|
|
|
|
if (
|
|
|
|
|
parentId !== Constants.NO_PARENT &&
|
|
|
|
|
(currentTitle?.toLowerCase().includes('new chat') ?? false)
|
|
|
|
|
) {
|
|
|
|
|
const currentConvo = queryClient.getQueryData<TConversation>([
|
|
|
|
|
QueryKeys.conversation,
|
|
|
|
|
conversationId,
|
|
|
|
|
]);
|
|
|
|
|
if (currentConvo?.title) {
|
|
|
|
|
return currentConvo.title;
|
|
|
|
|
}
|
|
|
|
|
const convos = queryClient.getQueryData<InfiniteData<ConversationCursorData>>([
|
|
|
|
|
QueryKeys.allConversations,
|
|
|
|
|
]);
|
|
|
|
|
const cachedConvo = findConversationInInfinite(convos, conversationId ?? '');
|
|
|
|
|
return cachedConvo?.title ?? currentConvo?.title ?? null;
|
|
|
|
|
}
|
|
|
|
|
return currentTitle;
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-25 03:02:38 -04:00
|
|
|
export default function useEventHandlers({
|
|
|
|
|
genTitle,
|
|
|
|
|
setMessages,
|
|
|
|
|
getMessages,
|
|
|
|
|
setCompleted,
|
2024-09-30 17:17:57 -04:00
|
|
|
isAddedRequest = false,
|
2024-06-25 03:02:38 -04:00
|
|
|
setConversation,
|
|
|
|
|
setIsSubmitting,
|
|
|
|
|
newConversation,
|
|
|
|
|
setShowStopButton,
|
|
|
|
|
resetLatestMessage,
|
|
|
|
|
}: EventHandlerParams) {
|
|
|
|
|
const queryClient = useQueryClient();
|
2024-08-30 00:14:37 -04:00
|
|
|
const { announcePolite } = useLiveAnnouncer();
|
2025-04-07 19:16:56 -04:00
|
|
|
const applyAgentTemplate = useApplyNewAgentTemplate();
|
|
|
|
|
const setAbortScroll = useSetRecoilState(store.abortScroll);
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
const navigate = useNavigate();
|
|
|
|
|
const location = useLocation();
|
2024-06-25 03:02:38 -04:00
|
|
|
|
2024-08-30 00:14:37 -04:00
|
|
|
const lastAnnouncementTimeRef = useRef(Date.now());
|
2024-06-25 03:02:38 -04:00
|
|
|
const { conversationId: paramId } = useParams();
|
|
|
|
|
const { token } = useAuthContext();
|
|
|
|
|
|
|
|
|
|
const contentHandler = useContentHandler({ setMessages, getMessages });
|
2024-09-10 19:00:27 -04:00
|
|
|
const stepHandler = useStepHandler({
|
|
|
|
|
setMessages,
|
|
|
|
|
getMessages,
|
|
|
|
|
announcePolite,
|
|
|
|
|
setIsSubmitting,
|
|
|
|
|
lastAnnouncementTimeRef,
|
|
|
|
|
});
|
2025-04-26 04:30:58 -04:00
|
|
|
const attachmentHandler = useAttachmentHandler(queryClient);
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
const messageHandler = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
(data: string | undefined, submission: EventSubmission) => {
|
2024-06-25 03:02:38 -04:00
|
|
|
const {
|
|
|
|
|
messages,
|
|
|
|
|
userMessage,
|
|
|
|
|
plugin,
|
|
|
|
|
plugins,
|
|
|
|
|
initialResponse,
|
|
|
|
|
isRegenerate = false,
|
|
|
|
|
} = submission;
|
2024-08-13 03:04:27 -04:00
|
|
|
const text = data ?? '';
|
2024-08-26 15:34:46 -04:00
|
|
|
setIsSubmitting(true);
|
2024-08-30 00:14:37 -04:00
|
|
|
|
|
|
|
|
const currentTime = Date.now();
|
|
|
|
|
if (currentTime - lastAnnouncementTimeRef.current > MESSAGE_UPDATE_INTERVAL) {
|
|
|
|
|
announcePolite({ message: 'composing', isStatus: true });
|
|
|
|
|
lastAnnouncementTimeRef.current = currentTime;
|
2024-08-13 03:04:27 -04:00
|
|
|
}
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
if (isRegenerate) {
|
|
|
|
|
setMessages([
|
|
|
|
|
...messages,
|
|
|
|
|
{
|
|
|
|
|
...initialResponse,
|
2024-08-13 03:04:27 -04:00
|
|
|
text,
|
2024-06-25 03:02:38 -04:00
|
|
|
plugin: plugin ?? null,
|
|
|
|
|
plugins: plugins ?? [],
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
} else {
|
|
|
|
|
setMessages([
|
|
|
|
|
...messages,
|
|
|
|
|
userMessage,
|
|
|
|
|
{
|
|
|
|
|
...initialResponse,
|
2024-08-13 03:04:27 -04:00
|
|
|
text,
|
2024-06-25 03:02:38 -04:00
|
|
|
plugin: plugin ?? null,
|
|
|
|
|
plugins: plugins ?? [],
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-08-26 15:34:46 -04:00
|
|
|
[setMessages, announcePolite, setIsSubmitting],
|
2024-06-25 03:02:38 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const cancelHandler = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
(data: TResData, submission: EventSubmission) => {
|
2024-06-25 03:02:38 -04:00
|
|
|
const { requestMessage, responseMessage, conversation } = data;
|
|
|
|
|
const { messages, isRegenerate = false } = submission;
|
2024-09-30 17:17:57 -04:00
|
|
|
const convoUpdate =
|
|
|
|
|
(conversation as TConversation | null) ?? (submission.conversation as TConversation);
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
// update the messages
|
|
|
|
|
if (isRegenerate) {
|
2024-09-30 17:17:57 -04:00
|
|
|
const messagesUpdate = (
|
|
|
|
|
[...messages, responseMessage] as Array<TMessage | undefined>
|
|
|
|
|
).filter((msg) => msg);
|
|
|
|
|
setMessages(messagesUpdate as TMessage[]);
|
2024-06-25 03:02:38 -04:00
|
|
|
} else {
|
2024-09-30 17:17:57 -04:00
|
|
|
const messagesUpdate = (
|
|
|
|
|
[...messages, requestMessage, responseMessage] as Array<TMessage | undefined>
|
|
|
|
|
).filter((msg) => msg);
|
|
|
|
|
setMessages(messagesUpdate as TMessage[]);
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isNewConvo = conversation.conversationId !== submission.conversation.conversationId;
|
|
|
|
|
if (isNewConvo) {
|
2025-04-15 10:04:00 +02:00
|
|
|
removeConvoFromAllQueries(queryClient, submission.conversation.conversationId as string);
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// refresh title
|
2024-08-13 03:04:27 -04:00
|
|
|
if (genTitle && isNewConvo && requestMessage.parentMessageId === Constants.NO_PARENT) {
|
2024-06-25 03:02:38 -04:00
|
|
|
setTimeout(() => {
|
|
|
|
|
genTitle.mutate({ conversationId: convoUpdate.conversationId as string });
|
|
|
|
|
}, 2500);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (setConversation && !isAddedRequest) {
|
|
|
|
|
setConversation((prevState) => {
|
2025-04-15 10:04:00 +02:00
|
|
|
const update = { ...prevState, ...convoUpdate };
|
2024-06-25 03:02:38 -04:00
|
|
|
return update;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
},
|
|
|
|
|
[setMessages, setConversation, genTitle, isAddedRequest, queryClient, setIsSubmitting],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const syncHandler = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
(data: TSyncData, submission: EventSubmission) => {
|
2024-06-25 03:02:38 -04:00
|
|
|
const { conversationId, thread_id, responseMessage, requestMessage } = data;
|
|
|
|
|
const { initialResponse, messages: _messages, userMessage } = submission;
|
|
|
|
|
const messages = _messages.filter((msg) => msg.messageId !== userMessage.messageId);
|
|
|
|
|
|
|
|
|
|
setMessages([
|
|
|
|
|
...messages,
|
|
|
|
|
requestMessage,
|
|
|
|
|
{
|
|
|
|
|
...initialResponse,
|
|
|
|
|
...responseMessage,
|
|
|
|
|
},
|
|
|
|
|
]);
|
|
|
|
|
|
2024-08-30 00:14:37 -04:00
|
|
|
announcePolite({
|
2024-08-19 03:51:17 -04:00
|
|
|
message: 'start',
|
2024-08-30 00:14:37 -04:00
|
|
|
isStatus: true,
|
2024-08-19 03:51:17 -04:00
|
|
|
});
|
|
|
|
|
|
2024-06-25 03:02:38 -04:00
|
|
|
let update = {} as TConversation;
|
|
|
|
|
if (setConversation && !isAddedRequest) {
|
|
|
|
|
setConversation((prevState) => {
|
|
|
|
|
const parentId = requestMessage.parentMessageId;
|
2025-04-15 10:04:00 +02:00
|
|
|
const title = getConvoTitle({
|
|
|
|
|
parentId,
|
|
|
|
|
queryClient,
|
|
|
|
|
conversationId,
|
|
|
|
|
currentTitle: prevState?.title,
|
|
|
|
|
});
|
2024-06-25 03:02:38 -04:00
|
|
|
update = tConvoUpdateSchema.parse({
|
|
|
|
|
...prevState,
|
|
|
|
|
conversationId,
|
|
|
|
|
thread_id,
|
|
|
|
|
title,
|
|
|
|
|
messages: [requestMessage.messageId, responseMessage.messageId],
|
|
|
|
|
}) as TConversation;
|
|
|
|
|
return update;
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-15 10:04:00 +02:00
|
|
|
if (requestMessage.parentMessageId === Constants.NO_PARENT) {
|
|
|
|
|
addConvoToAllQueries(queryClient, update);
|
|
|
|
|
} else {
|
|
|
|
|
updateConvoInAllQueries(queryClient, update.conversationId!, (_c) => update);
|
|
|
|
|
}
|
2024-06-25 03:02:38 -04:00
|
|
|
} else if (setConversation) {
|
|
|
|
|
setConversation((prevState) => {
|
|
|
|
|
update = tConvoUpdateSchema.parse({
|
|
|
|
|
...prevState,
|
|
|
|
|
conversationId,
|
|
|
|
|
thread_id,
|
|
|
|
|
messages: [requestMessage.messageId, responseMessage.messageId],
|
|
|
|
|
}) as TConversation;
|
|
|
|
|
return update;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setShowStopButton(true);
|
|
|
|
|
if (resetLatestMessage) {
|
|
|
|
|
resetLatestMessage();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[
|
|
|
|
|
queryClient,
|
2024-08-19 03:51:17 -04:00
|
|
|
setMessages,
|
2024-06-25 03:02:38 -04:00
|
|
|
isAddedRequest,
|
2024-08-30 00:14:37 -04:00
|
|
|
announcePolite,
|
2024-08-19 03:51:17 -04:00
|
|
|
setConversation,
|
2024-06-25 03:02:38 -04:00
|
|
|
setShowStopButton,
|
|
|
|
|
resetLatestMessage,
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const createdHandler = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
(data: TResData, submission: EventSubmission) => {
|
2025-02-06 08:11:47 -08:00
|
|
|
const { messages, userMessage, isRegenerate = false, isTemporary = false } = submission;
|
2024-06-25 03:02:38 -04:00
|
|
|
const initialResponse = {
|
|
|
|
|
...submission.initialResponse,
|
2024-08-13 03:04:27 -04:00
|
|
|
parentMessageId: userMessage.messageId,
|
|
|
|
|
messageId: userMessage.messageId + '_',
|
2024-06-25 03:02:38 -04:00
|
|
|
};
|
|
|
|
|
if (isRegenerate) {
|
|
|
|
|
setMessages([...messages, initialResponse]);
|
|
|
|
|
} else {
|
|
|
|
|
setMessages([...messages, userMessage, initialResponse]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { conversationId, parentMessageId } = userMessage;
|
2024-08-30 00:14:37 -04:00
|
|
|
lastAnnouncementTimeRef.current = Date.now();
|
|
|
|
|
announcePolite({
|
2024-08-19 03:51:17 -04:00
|
|
|
message: 'start',
|
2024-08-30 00:14:37 -04:00
|
|
|
isStatus: true,
|
2024-08-13 03:04:27 -04:00
|
|
|
});
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
let update = {} as TConversation;
|
2025-04-07 19:16:56 -04:00
|
|
|
if (conversationId) {
|
|
|
|
|
applyAgentTemplate(conversationId, submission.conversation.conversationId);
|
|
|
|
|
}
|
2024-06-25 03:02:38 -04:00
|
|
|
if (setConversation && !isAddedRequest) {
|
|
|
|
|
setConversation((prevState) => {
|
2024-08-13 03:04:27 -04:00
|
|
|
const parentId = isRegenerate ? userMessage.overrideParentMessageId : parentMessageId;
|
2025-04-15 10:04:00 +02:00
|
|
|
const title = getConvoTitle({
|
|
|
|
|
parentId,
|
|
|
|
|
queryClient,
|
|
|
|
|
conversationId,
|
|
|
|
|
currentTitle: prevState?.title,
|
|
|
|
|
});
|
2024-06-25 03:02:38 -04:00
|
|
|
update = tConvoUpdateSchema.parse({
|
|
|
|
|
...prevState,
|
|
|
|
|
conversationId,
|
|
|
|
|
title,
|
|
|
|
|
}) as TConversation;
|
|
|
|
|
return update;
|
|
|
|
|
});
|
|
|
|
|
|
2025-04-15 10:04:00 +02:00
|
|
|
if (!isTemporary) {
|
2024-06-25 03:02:38 -04:00
|
|
|
if (parentMessageId === Constants.NO_PARENT) {
|
2025-04-15 10:04:00 +02:00
|
|
|
addConvoToAllQueries(queryClient, update);
|
2024-06-25 03:02:38 -04:00
|
|
|
} else {
|
2025-04-15 10:04:00 +02:00
|
|
|
updateConvoInAllQueries(queryClient, update.conversationId!, (_c) => update);
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
2025-04-15 10:04:00 +02:00
|
|
|
}
|
2024-06-25 03:02:38 -04:00
|
|
|
} else if (setConversation) {
|
|
|
|
|
setConversation((prevState) => {
|
|
|
|
|
update = tConvoUpdateSchema.parse({
|
|
|
|
|
...prevState,
|
|
|
|
|
conversationId,
|
|
|
|
|
}) as TConversation;
|
|
|
|
|
return update;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (resetLatestMessage) {
|
|
|
|
|
resetLatestMessage();
|
|
|
|
|
}
|
2024-08-18 19:02:46 -04:00
|
|
|
scrollToEnd(() => setAbortScroll(false));
|
2024-06-25 03:02:38 -04:00
|
|
|
},
|
2024-08-13 03:04:27 -04:00
|
|
|
[
|
|
|
|
|
setMessages,
|
|
|
|
|
queryClient,
|
2024-08-18 19:02:46 -04:00
|
|
|
setAbortScroll,
|
2024-08-13 03:04:27 -04:00
|
|
|
isAddedRequest,
|
2024-08-30 00:14:37 -04:00
|
|
|
announcePolite,
|
2024-08-18 19:02:46 -04:00
|
|
|
setConversation,
|
|
|
|
|
resetLatestMessage,
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
applyAgentTemplate,
|
2024-08-13 03:04:27 -04:00
|
|
|
],
|
2024-06-25 03:02:38 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const finalHandler = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
(data: TFinalResData, submission: EventSubmission) => {
|
2024-06-25 03:02:38 -04:00
|
|
|
const { requestMessage, responseMessage, conversation, runMessages } = data;
|
2025-02-06 08:11:47 -08:00
|
|
|
const {
|
|
|
|
|
messages,
|
|
|
|
|
conversation: submissionConvo,
|
|
|
|
|
isRegenerate = false,
|
|
|
|
|
isTemporary = false,
|
|
|
|
|
} = submission;
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
setShowStopButton(false);
|
2024-08-13 03:04:27 -04:00
|
|
|
setCompleted((prev) => new Set(prev.add(submission.initialResponse.messageId)));
|
2024-06-25 03:02:38 -04:00
|
|
|
|
|
|
|
|
const currentMessages = getMessages();
|
2024-08-19 03:51:17 -04:00
|
|
|
/* Early return if messages are empty; i.e., the user navigated away */
|
|
|
|
|
if (!currentMessages || currentMessages.length === 0) {
|
2025-04-15 10:04:00 +02:00
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
2024-08-13 03:04:27 -04:00
|
|
|
/* a11y announcements */
|
2025-04-15 10:04:00 +02:00
|
|
|
announcePolite({ message: 'end', isStatus: true });
|
|
|
|
|
announcePolite({ message: getAllContentText(responseMessage) });
|
2024-08-13 03:04:27 -04:00
|
|
|
|
2024-08-19 03:51:17 -04:00
|
|
|
/* Update messages; if assistants endpoint, client doesn't receive responseMessage */
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
let finalMessages: TMessage[] = [];
|
2024-06-25 03:02:38 -04:00
|
|
|
if (runMessages) {
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
finalMessages = [...runMessages];
|
2024-06-25 03:02:38 -04:00
|
|
|
} else if (isRegenerate && responseMessage) {
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
finalMessages = [...messages, responseMessage];
|
2024-08-19 03:51:17 -04:00
|
|
|
} else if (requestMessage != null && responseMessage != null) {
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
finalMessages = [...messages, requestMessage, responseMessage];
|
|
|
|
|
}
|
|
|
|
|
if (finalMessages.length > 0) {
|
|
|
|
|
setMessages(finalMessages);
|
|
|
|
|
queryClient.setQueryData<TMessage[]>(
|
|
|
|
|
[QueryKeys.messages, conversation.conversationId],
|
|
|
|
|
finalMessages,
|
|
|
|
|
);
|
2025-05-07 17:11:33 -04:00
|
|
|
} else if (
|
|
|
|
|
isAssistantsEndpoint(submissionConvo.endpoint) &&
|
|
|
|
|
(!submissionConvo.conversationId || submissionConvo.conversationId === Constants.NEW_CONVO)
|
|
|
|
|
) {
|
|
|
|
|
queryClient.setQueryData<TMessage[]>(
|
|
|
|
|
[QueryKeys.messages, conversation.conversationId],
|
|
|
|
|
[...currentMessages],
|
|
|
|
|
);
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const isNewConvo = conversation.conversationId !== submissionConvo.conversationId;
|
|
|
|
|
if (isNewConvo) {
|
2025-04-15 10:04:00 +02:00
|
|
|
removeConvoFromAllQueries(queryClient, submissionConvo.conversationId as string);
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
2024-08-19 03:51:17 -04:00
|
|
|
/* Refresh title */
|
2024-06-25 03:02:38 -04:00
|
|
|
if (
|
|
|
|
|
genTitle &&
|
|
|
|
|
isNewConvo &&
|
2025-02-06 08:11:47 -08:00
|
|
|
!isTemporary &&
|
2024-06-25 03:02:38 -04:00
|
|
|
requestMessage &&
|
|
|
|
|
requestMessage.parentMessageId === Constants.NO_PARENT
|
|
|
|
|
) {
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
genTitle.mutate({ conversationId: conversation.conversationId as string });
|
|
|
|
|
}, 2500);
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-19 03:51:17 -04:00
|
|
|
if (setConversation && isAddedRequest !== true) {
|
2024-06-25 03:02:38 -04:00
|
|
|
setConversation((prevState) => {
|
|
|
|
|
const update = {
|
|
|
|
|
...prevState,
|
2025-04-15 10:04:00 +02:00
|
|
|
...(conversation as TConversation),
|
2024-06-25 03:02:38 -04:00
|
|
|
};
|
2024-08-19 03:51:17 -04:00
|
|
|
if (prevState?.model != null && prevState.model !== submissionConvo.model) {
|
2024-06-25 03:02:38 -04:00
|
|
|
update.model = prevState.model;
|
|
|
|
|
}
|
2025-04-15 10:04:00 +02:00
|
|
|
const cachedConvo = queryClient.getQueryData<TConversation>([
|
|
|
|
|
QueryKeys.conversation,
|
|
|
|
|
conversation.conversationId,
|
|
|
|
|
]);
|
|
|
|
|
if (!cachedConvo) {
|
|
|
|
|
queryClient.setQueryData([QueryKeys.conversation, conversation.conversationId], update);
|
|
|
|
|
}
|
2024-06-25 03:02:38 -04:00
|
|
|
return update;
|
|
|
|
|
});
|
2025-04-29 03:49:02 -04:00
|
|
|
if (location.pathname === '/c/new') {
|
|
|
|
|
navigate(`/c/${conversation.conversationId}`, { replace: true });
|
|
|
|
|
}
|
2024-06-25 03:02:38 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
},
|
|
|
|
|
[
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
setShowStopButton,
|
2024-06-25 03:02:38 -04:00
|
|
|
setCompleted,
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
getMessages,
|
2024-08-13 03:04:27 -04:00
|
|
|
announcePolite,
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
genTitle,
|
2024-06-25 03:02:38 -04:00
|
|
|
setConversation,
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
isAddedRequest,
|
2024-06-25 03:02:38 -04:00
|
|
|
setIsSubmitting,
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
setMessages,
|
|
|
|
|
queryClient,
|
|
|
|
|
location.pathname,
|
|
|
|
|
navigate,
|
2024-06-25 03:02:38 -04:00
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const errorHandler = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
({ data, submission }: { data?: TResData; submission: EventSubmission }) => {
|
2024-06-25 03:02:38 -04:00
|
|
|
const { messages, userMessage, initialResponse } = submission;
|
|
|
|
|
setCompleted((prev) => new Set(prev.add(initialResponse.messageId)));
|
|
|
|
|
|
2025-04-01 03:50:32 -04:00
|
|
|
const conversationId =
|
|
|
|
|
userMessage.conversationId ?? submission.conversation?.conversationId ?? '';
|
2024-06-25 03:02:38 -04:00
|
|
|
|
2025-04-29 03:49:02 -04:00
|
|
|
const setErrorMessages = (convoId: string, errorMessage: TMessage) => {
|
|
|
|
|
const finalMessages: TMessage[] = [...messages, userMessage, errorMessage];
|
|
|
|
|
setMessages(finalMessages);
|
|
|
|
|
queryClient.setQueryData<TMessage[]>([QueryKeys.messages, convoId], finalMessages);
|
|
|
|
|
};
|
|
|
|
|
|
2024-06-25 03:02:38 -04:00
|
|
|
const parseErrorResponse = (data: TResData | Partial<TMessage>) => {
|
|
|
|
|
const metadata = data['responseMessage'] ?? data;
|
2024-08-19 03:51:17 -04:00
|
|
|
const errorMessage: Partial<TMessage> = {
|
2024-06-25 03:02:38 -04:00
|
|
|
...initialResponse,
|
|
|
|
|
...metadata,
|
|
|
|
|
error: true,
|
2024-08-13 03:04:27 -04:00
|
|
|
parentMessageId: userMessage.messageId,
|
2024-06-25 03:02:38 -04:00
|
|
|
};
|
|
|
|
|
|
2024-08-19 03:51:17 -04:00
|
|
|
if (errorMessage.messageId === undefined || errorMessage.messageId === '') {
|
2024-06-25 03:02:38 -04:00
|
|
|
errorMessage.messageId = v4();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return tMessageSchema.parse(errorMessage);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (!data) {
|
2025-04-29 03:49:02 -04:00
|
|
|
const convoId = conversationId || `_${v4()}`;
|
🎨 feat: UI Refresh for Enhanced UX (#6346)
* ✨ feat: Add Expand Chat functionality and improve UI components
* ✨ feat: Introduce Chat Badges feature with editing capabilities and UI enhancements
* ✨ feat: re-implement file attachment functionality with new components and improved UI
* ✨ feat: Enhance BadgeRow component with drag-and-drop functionality and add animations for better user experience
* ✨ feat: Add useChatBadges hook and enhance Badge component with animations and toggle functionality
* feat: Improve Add/Delete Badges + style and bug fixes
* ✨ feat: Refactor EditBadges component and optimize useChatBadges hook for improved performance and readability
* ✨ feat: Add type definition for LucideIcon in EditBadges component
* refactor: Clean up BadgeRow component by removing outdated comment and improving code readability
* refactor: Rename app-icon class to badge-icon for consistency and improve badge styling
* feat: Add Center Chat Input toggle and update related components for improved UI/UX
* refactor: Simplify ChatView and MessagesView components for improved readability and performance
* refactor: Improve layout and positioning of scroll button in MessagesView component
* refactor: Adjust scroll button position in MessagesView component for better visibility
* refactor: Remove redundant background class from Badge component for cleaner styling
* feat: disable chat badges
* refactor: adjust positioning of scroll button and popover for improved layout
* refactor: simplify class names in ChatForm and RemoveFile components for cleaner code
* refactor: move Switcher to HeaderOptions from SidePanel
* fix(Landing): duplicate description
* feat: add SplitText component for animated text display and update Landing component to use it
* feat(Chat): add ConversationStarters component and integrate it into ChatView; remove ConvoStarter component
* feat(Chat): enhance Message component layout and styling for improved readability
* feat(ControlCombobox, Select): enhance styling and add animation for improved UI experience
* feat(Chat): update Header and HeaderNewChat components for improved layout and styling
* feat(Chat): add ModelDropdown (now includes both endpoint and model) and refactor Menu components for improved UI
* feat(ModelDropdown): add Agent Select; removed old AgentSwitcher components
* feat(ModelDropdown): add settings button for user key configuration
* fix(ModelDropdown): the model dropdown wasn't opening automatically when opening the endpoint one
* refactor(Chat): remove unused EndpointsMenu and related components to streamline codebase
* feat: enhance greeting message and improve accessibility fro ModelDropdown
* refactor(Endpoints): add new hooks and components for endpoint management
* feat(Endpoint): add support for modelSpecs
* feat(Endpoints): add mobile support
* fix: type issues
* fix(modelSpec): type issue
* fix(EndpointMenuDropdown): double overflow scroller in mobile model list
* fix: search model on mobile
* refactor: Endpoint/Model/modelSpec dropdown
* refactor: reorganize imports in Endpoint components
* refactor: remove unused translation keys from English locale
* BREAKING: moving to ariakit with new CustomMenu
* refactor: remove unnecessary comments
* refactor: remove EndpointItem, ModelDropdownButton, SpecIcon, and SpecItem components
* 🔧 fix: AI Icon bump when regenerating message
* wip: chat UI refactoring, fix issues
* chore: add recent update to useAutoSave
* feat: add access control for agent permissions in useMentions hook
* refactor: streamline ModelSelector by removing unused endpoints logic
* refactor: enhance ModelSelector and context by integrating endpointsConfig and improving type usage
* feat: update ModelSelectorContext to utilize conversation data for initial state
* feat: add selector effects for synced endpoint handling
* feat: add guard clause for conversation endpoint in useSelectorEffects hook
* fix: safely call onSelectMention and add autofocus to mention input
* chore: typing
* refactor: ModelSelector to streamline key dialog handling and improve endpoint rendering
* refactor: extract SettingsButton component for cleaner endpoint item rendering
* wip: first pass, expand set api key
* wip: first pass, expanding set key
* refactor: update EndpointItem styles for improved layout and hover effects
* refactor: adjust padding in EndpointItem for improved layout consistency
* refactor: update preset structure in useSelectMention to include spec as null
* refactor: rename setKeyDialogOpen to onOpenChange for clarity and consistency, bring focus back to button that opened dialog
* feat: add SpecIcon component for dynamic model spec icons in menu, adjust icon styling
* refactor: update getSelectedIcon to accept additional parameters and improve icon rendering logic
* fix: adjust padding in MessageRender for improved layout
* refactor: remove inline style for menu width in CustomMenu component
* refactor: enhance layout and styling in ModelSpecItem component for better responsiveness
* refactor: update getDefaultModelSpec to accept startupConfig and improve model spec retrieval logic
* refactor: improve key management and default values in ModelSelector and related components
* refactor: adjust menu width and improve responsiveness in CustomMenu and EndpointItem components
* refactor: enhance focus styles and responsiveness in EndpointItem component
* refactor: improve layout and spacing in Header and ModelSelector components for better responsiveness
* refactor: adjust button styles for consistency and improved layout in AddMultiConvo and PresetsMenu components
* fix: initial fix of assistant names
* fix: assistants handling
* chore: update version of librechat-data-provider to 0.7.75 and add 'spec' to excludedKeys
* fix: improve endpoint filtering logic based on interface configuration and access rights
* fix: remove unused HeaderOptions import and set spec to null in presets and mentions
* fix: ensure currentExample is always an object when updating examples
* fix: update interfaceConfig checks to ensure modelSelect is considered for rendering components
* fix: update model selection logic to consider interface configuration when prioritizing model specs
* fix: add missing localizations
* fix: remove unused agent and assistant selection translations
* fix: implement debounced state updates for selected values in useSelectorEffects
* style: minor style changes related to the ModelSelector
* fix: adjust maximum height for popover and set fixed height for model item
* fix: update placeholders for model and endpoint search inputs
* fix: refactor MessageRender and ContentRender components to better match each other
* fix: remove convo fallback for iconURL in MessageRender and ContentRender components
* fix: update handling of spec, iconURL, and modelLabel in conversation presets, to allow better interchangeability
* fix: replace chatGptLabel with modelLabel in OpenAI settings configuration (fully deprecate chatGptLabel)
* fix: remove console log for assistantNames in useEndpoints hook
* refactor: add cleanInput and cleanOutput options to default conversation handling
* chore: update bun.lockb
* fix: set default value for showIconInHeader in getSelectedIcon function
* refactor: enhance error handling in message processing when latest message has existing content blocks
* chore: allow import/no-cycle for messages
* fix: adjust flex properties in BookmarkMenu for better layout
* feat: support both 'prompt' and 'q' as query parameters in useQueryParams hook
* feat: re-enable Badges components
* refactor: disable edit badge component
* chore: rename assistantMap to assistantsMap for consistency
* chore: rename assistantMap to assistantsMap for consistency in Mention component
* feat: set staleTime for various queries to improve data freshness
* feat: add spec field to tQueryParamsSchema for model specification
* feat: enhance useQueryParams to handle model specs
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-25 23:50:58 +01:00
|
|
|
const errorMetadata = parseErrorResponse({
|
2024-06-25 03:02:38 -04:00
|
|
|
text: 'Error connecting to server, try refreshing the page.',
|
|
|
|
|
...submission,
|
|
|
|
|
conversationId: convoId,
|
|
|
|
|
});
|
🎨 feat: UI Refresh for Enhanced UX (#6346)
* ✨ feat: Add Expand Chat functionality and improve UI components
* ✨ feat: Introduce Chat Badges feature with editing capabilities and UI enhancements
* ✨ feat: re-implement file attachment functionality with new components and improved UI
* ✨ feat: Enhance BadgeRow component with drag-and-drop functionality and add animations for better user experience
* ✨ feat: Add useChatBadges hook and enhance Badge component with animations and toggle functionality
* feat: Improve Add/Delete Badges + style and bug fixes
* ✨ feat: Refactor EditBadges component and optimize useChatBadges hook for improved performance and readability
* ✨ feat: Add type definition for LucideIcon in EditBadges component
* refactor: Clean up BadgeRow component by removing outdated comment and improving code readability
* refactor: Rename app-icon class to badge-icon for consistency and improve badge styling
* feat: Add Center Chat Input toggle and update related components for improved UI/UX
* refactor: Simplify ChatView and MessagesView components for improved readability and performance
* refactor: Improve layout and positioning of scroll button in MessagesView component
* refactor: Adjust scroll button position in MessagesView component for better visibility
* refactor: Remove redundant background class from Badge component for cleaner styling
* feat: disable chat badges
* refactor: adjust positioning of scroll button and popover for improved layout
* refactor: simplify class names in ChatForm and RemoveFile components for cleaner code
* refactor: move Switcher to HeaderOptions from SidePanel
* fix(Landing): duplicate description
* feat: add SplitText component for animated text display and update Landing component to use it
* feat(Chat): add ConversationStarters component and integrate it into ChatView; remove ConvoStarter component
* feat(Chat): enhance Message component layout and styling for improved readability
* feat(ControlCombobox, Select): enhance styling and add animation for improved UI experience
* feat(Chat): update Header and HeaderNewChat components for improved layout and styling
* feat(Chat): add ModelDropdown (now includes both endpoint and model) and refactor Menu components for improved UI
* feat(ModelDropdown): add Agent Select; removed old AgentSwitcher components
* feat(ModelDropdown): add settings button for user key configuration
* fix(ModelDropdown): the model dropdown wasn't opening automatically when opening the endpoint one
* refactor(Chat): remove unused EndpointsMenu and related components to streamline codebase
* feat: enhance greeting message and improve accessibility fro ModelDropdown
* refactor(Endpoints): add new hooks and components for endpoint management
* feat(Endpoint): add support for modelSpecs
* feat(Endpoints): add mobile support
* fix: type issues
* fix(modelSpec): type issue
* fix(EndpointMenuDropdown): double overflow scroller in mobile model list
* fix: search model on mobile
* refactor: Endpoint/Model/modelSpec dropdown
* refactor: reorganize imports in Endpoint components
* refactor: remove unused translation keys from English locale
* BREAKING: moving to ariakit with new CustomMenu
* refactor: remove unnecessary comments
* refactor: remove EndpointItem, ModelDropdownButton, SpecIcon, and SpecItem components
* 🔧 fix: AI Icon bump when regenerating message
* wip: chat UI refactoring, fix issues
* chore: add recent update to useAutoSave
* feat: add access control for agent permissions in useMentions hook
* refactor: streamline ModelSelector by removing unused endpoints logic
* refactor: enhance ModelSelector and context by integrating endpointsConfig and improving type usage
* feat: update ModelSelectorContext to utilize conversation data for initial state
* feat: add selector effects for synced endpoint handling
* feat: add guard clause for conversation endpoint in useSelectorEffects hook
* fix: safely call onSelectMention and add autofocus to mention input
* chore: typing
* refactor: ModelSelector to streamline key dialog handling and improve endpoint rendering
* refactor: extract SettingsButton component for cleaner endpoint item rendering
* wip: first pass, expand set api key
* wip: first pass, expanding set key
* refactor: update EndpointItem styles for improved layout and hover effects
* refactor: adjust padding in EndpointItem for improved layout consistency
* refactor: update preset structure in useSelectMention to include spec as null
* refactor: rename setKeyDialogOpen to onOpenChange for clarity and consistency, bring focus back to button that opened dialog
* feat: add SpecIcon component for dynamic model spec icons in menu, adjust icon styling
* refactor: update getSelectedIcon to accept additional parameters and improve icon rendering logic
* fix: adjust padding in MessageRender for improved layout
* refactor: remove inline style for menu width in CustomMenu component
* refactor: enhance layout and styling in ModelSpecItem component for better responsiveness
* refactor: update getDefaultModelSpec to accept startupConfig and improve model spec retrieval logic
* refactor: improve key management and default values in ModelSelector and related components
* refactor: adjust menu width and improve responsiveness in CustomMenu and EndpointItem components
* refactor: enhance focus styles and responsiveness in EndpointItem component
* refactor: improve layout and spacing in Header and ModelSelector components for better responsiveness
* refactor: adjust button styles for consistency and improved layout in AddMultiConvo and PresetsMenu components
* fix: initial fix of assistant names
* fix: assistants handling
* chore: update version of librechat-data-provider to 0.7.75 and add 'spec' to excludedKeys
* fix: improve endpoint filtering logic based on interface configuration and access rights
* fix: remove unused HeaderOptions import and set spec to null in presets and mentions
* fix: ensure currentExample is always an object when updating examples
* fix: update interfaceConfig checks to ensure modelSelect is considered for rendering components
* fix: update model selection logic to consider interface configuration when prioritizing model specs
* fix: add missing localizations
* fix: remove unused agent and assistant selection translations
* fix: implement debounced state updates for selected values in useSelectorEffects
* style: minor style changes related to the ModelSelector
* fix: adjust maximum height for popover and set fixed height for model item
* fix: update placeholders for model and endpoint search inputs
* fix: refactor MessageRender and ContentRender components to better match each other
* fix: remove convo fallback for iconURL in MessageRender and ContentRender components
* fix: update handling of spec, iconURL, and modelLabel in conversation presets, to allow better interchangeability
* fix: replace chatGptLabel with modelLabel in OpenAI settings configuration (fully deprecate chatGptLabel)
* fix: remove console log for assistantNames in useEndpoints hook
* refactor: add cleanInput and cleanOutput options to default conversation handling
* chore: update bun.lockb
* fix: set default value for showIconInHeader in getSelectedIcon function
* refactor: enhance error handling in message processing when latest message has existing content blocks
* chore: allow import/no-cycle for messages
* fix: adjust flex properties in BookmarkMenu for better layout
* feat: support both 'prompt' and 'q' as query parameters in useQueryParams hook
* feat: re-enable Badges components
* refactor: disable edit badge component
* chore: rename assistantMap to assistantsMap for consistency
* chore: rename assistantMap to assistantsMap for consistency in Mention component
* feat: set staleTime for various queries to improve data freshness
* feat: add spec field to tQueryParamsSchema for model specification
* feat: enhance useQueryParams to handle model specs
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-25 23:50:58 +01:00
|
|
|
const errorResponse = createErrorMessage({
|
|
|
|
|
errorMetadata,
|
|
|
|
|
getMessages,
|
|
|
|
|
submission,
|
|
|
|
|
});
|
2025-04-29 03:49:02 -04:00
|
|
|
setErrorMessages(convoId, errorResponse);
|
2024-06-25 03:02:38 -04:00
|
|
|
if (newConversation) {
|
|
|
|
|
newConversation({
|
|
|
|
|
template: { conversationId: convoId },
|
2024-08-13 03:04:27 -04:00
|
|
|
preset: tPresetSchema.parse(submission.conversation),
|
2024-06-25 03:02:38 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-30 17:17:57 -04:00
|
|
|
const receivedConvoId = data.conversationId ?? '';
|
|
|
|
|
if (!conversationId && !receivedConvoId) {
|
2025-04-29 03:49:02 -04:00
|
|
|
const convoId = `_${v4()}`;
|
2024-06-25 03:02:38 -04:00
|
|
|
const errorResponse = parseErrorResponse(data);
|
2025-04-29 03:49:02 -04:00
|
|
|
setErrorMessages(convoId, errorResponse);
|
2024-06-25 03:02:38 -04:00
|
|
|
if (newConversation) {
|
|
|
|
|
newConversation({
|
|
|
|
|
template: { conversationId: convoId },
|
2024-08-13 03:04:27 -04:00
|
|
|
preset: tPresetSchema.parse(submission.conversation),
|
2024-06-25 03:02:38 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
2024-09-30 17:17:57 -04:00
|
|
|
} else if (!receivedConvoId) {
|
2024-06-25 03:02:38 -04:00
|
|
|
const errorResponse = parseErrorResponse(data);
|
2025-04-29 03:49:02 -04:00
|
|
|
setErrorMessages(conversationId, errorResponse);
|
2024-06-25 03:02:38 -04:00
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const errorResponse = tMessageSchema.parse({
|
|
|
|
|
...data,
|
|
|
|
|
error: true,
|
2024-08-13 03:04:27 -04:00
|
|
|
parentMessageId: userMessage.messageId,
|
2024-06-25 03:02:38 -04:00
|
|
|
});
|
|
|
|
|
|
2025-04-29 03:49:02 -04:00
|
|
|
setErrorMessages(receivedConvoId, errorResponse);
|
2025-04-02 18:44:13 -04:00
|
|
|
if (receivedConvoId && paramId === Constants.NEW_CONVO && newConversation) {
|
2024-06-25 03:02:38 -04:00
|
|
|
newConversation({
|
2024-09-30 17:17:57 -04:00
|
|
|
template: { conversationId: receivedConvoId },
|
2024-08-13 03:04:27 -04:00
|
|
|
preset: tPresetSchema.parse(submission.conversation),
|
2024-06-25 03:02:38 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
|
|
|
|
},
|
2025-04-29 03:49:02 -04:00
|
|
|
[
|
|
|
|
|
setCompleted,
|
|
|
|
|
setMessages,
|
|
|
|
|
paramId,
|
|
|
|
|
newConversation,
|
|
|
|
|
setIsSubmitting,
|
|
|
|
|
getMessages,
|
|
|
|
|
queryClient,
|
|
|
|
|
],
|
2024-06-25 03:02:38 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const abortConversation = useCallback(
|
2024-08-21 18:18:45 -04:00
|
|
|
async (conversationId = '', submission: EventSubmission, messages?: TMessage[]) => {
|
2024-06-25 03:02:38 -04:00
|
|
|
const runAbortKey = `${conversationId}:${messages?.[messages.length - 1]?.messageId ?? ''}`;
|
2024-09-30 17:17:57 -04:00
|
|
|
const { endpoint: _endpoint, endpointType } =
|
|
|
|
|
(submission.conversation as TConversation | null) ?? {};
|
2024-06-25 03:02:38 -04:00
|
|
|
const endpoint = endpointType ?? _endpoint;
|
2025-04-15 10:04:00 +02:00
|
|
|
if (
|
|
|
|
|
!isAssistantsEndpoint(endpoint) &&
|
|
|
|
|
messages?.[messages.length - 1] != null &&
|
|
|
|
|
messages[messages.length - 2] != null
|
|
|
|
|
) {
|
2025-04-17 00:40:26 -04:00
|
|
|
let requestMessage = messages[messages.length - 2];
|
2025-04-15 10:04:00 +02:00
|
|
|
const responseMessage = messages[messages.length - 1];
|
2025-04-17 00:40:26 -04:00
|
|
|
if (requestMessage.messageId !== responseMessage.parentMessageId) {
|
|
|
|
|
// the request message is the parent of response, which we search for backwards
|
|
|
|
|
for (let i = messages.length - 3; i >= 0; i--) {
|
|
|
|
|
if (messages[i].messageId === responseMessage.parentMessageId) {
|
|
|
|
|
requestMessage = messages[i];
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-04-15 10:04:00 +02:00
|
|
|
finalHandler(
|
|
|
|
|
{
|
|
|
|
|
conversation: {
|
|
|
|
|
conversationId,
|
|
|
|
|
},
|
|
|
|
|
requestMessage,
|
|
|
|
|
responseMessage,
|
|
|
|
|
},
|
|
|
|
|
submission,
|
|
|
|
|
);
|
|
|
|
|
return;
|
|
|
|
|
} else if (!isAssistantsEndpoint(endpoint)) {
|
2025-04-29 03:49:02 -04:00
|
|
|
const convoId = conversationId || `_${v4()}`;
|
|
|
|
|
logger.log('conversation', 'Aborted conversation with minimal messages, ID: ' + convoId);
|
2025-04-12 18:46:36 -04:00
|
|
|
if (newConversation) {
|
|
|
|
|
newConversation({
|
2025-04-29 03:49:02 -04:00
|
|
|
template: { conversationId: convoId },
|
2025-04-12 18:46:36 -04:00
|
|
|
preset: tPresetSchema.parse(submission.conversation),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-25 03:02:38 -04:00
|
|
|
try {
|
|
|
|
|
const response = await fetch(`${EndpointURLs[endpoint ?? '']}/abort`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
Authorization: `Bearer ${token}`,
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
abortKey: runAbortKey,
|
|
|
|
|
endpoint,
|
|
|
|
|
}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Check if the response is JSON
|
|
|
|
|
const contentType = response.headers.get('content-type');
|
2024-08-19 03:51:17 -04:00
|
|
|
if (contentType != null && contentType.includes('application/json')) {
|
2024-06-25 03:02:38 -04:00
|
|
|
const data = await response.json();
|
|
|
|
|
if (response.status === 404) {
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-09-30 17:17:57 -04:00
|
|
|
if (data.final === true) {
|
2024-06-25 03:02:38 -04:00
|
|
|
finalHandler(data, submission);
|
|
|
|
|
} else {
|
|
|
|
|
cancelHandler(data, submission);
|
|
|
|
|
}
|
2025-04-03 20:42:56 -04:00
|
|
|
} else if (response.status === 204 || response.status === 200) {
|
2024-06-25 03:02:38 -04:00
|
|
|
setIsSubmitting(false);
|
|
|
|
|
} else {
|
|
|
|
|
throw new Error(
|
|
|
|
|
'Unexpected response from server; Status: ' +
|
|
|
|
|
response.status +
|
|
|
|
|
' ' +
|
|
|
|
|
response.statusText,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
🎨 feat: UI Refresh for Enhanced UX (#6346)
* ✨ feat: Add Expand Chat functionality and improve UI components
* ✨ feat: Introduce Chat Badges feature with editing capabilities and UI enhancements
* ✨ feat: re-implement file attachment functionality with new components and improved UI
* ✨ feat: Enhance BadgeRow component with drag-and-drop functionality and add animations for better user experience
* ✨ feat: Add useChatBadges hook and enhance Badge component with animations and toggle functionality
* feat: Improve Add/Delete Badges + style and bug fixes
* ✨ feat: Refactor EditBadges component and optimize useChatBadges hook for improved performance and readability
* ✨ feat: Add type definition for LucideIcon in EditBadges component
* refactor: Clean up BadgeRow component by removing outdated comment and improving code readability
* refactor: Rename app-icon class to badge-icon for consistency and improve badge styling
* feat: Add Center Chat Input toggle and update related components for improved UI/UX
* refactor: Simplify ChatView and MessagesView components for improved readability and performance
* refactor: Improve layout and positioning of scroll button in MessagesView component
* refactor: Adjust scroll button position in MessagesView component for better visibility
* refactor: Remove redundant background class from Badge component for cleaner styling
* feat: disable chat badges
* refactor: adjust positioning of scroll button and popover for improved layout
* refactor: simplify class names in ChatForm and RemoveFile components for cleaner code
* refactor: move Switcher to HeaderOptions from SidePanel
* fix(Landing): duplicate description
* feat: add SplitText component for animated text display and update Landing component to use it
* feat(Chat): add ConversationStarters component and integrate it into ChatView; remove ConvoStarter component
* feat(Chat): enhance Message component layout and styling for improved readability
* feat(ControlCombobox, Select): enhance styling and add animation for improved UI experience
* feat(Chat): update Header and HeaderNewChat components for improved layout and styling
* feat(Chat): add ModelDropdown (now includes both endpoint and model) and refactor Menu components for improved UI
* feat(ModelDropdown): add Agent Select; removed old AgentSwitcher components
* feat(ModelDropdown): add settings button for user key configuration
* fix(ModelDropdown): the model dropdown wasn't opening automatically when opening the endpoint one
* refactor(Chat): remove unused EndpointsMenu and related components to streamline codebase
* feat: enhance greeting message and improve accessibility fro ModelDropdown
* refactor(Endpoints): add new hooks and components for endpoint management
* feat(Endpoint): add support for modelSpecs
* feat(Endpoints): add mobile support
* fix: type issues
* fix(modelSpec): type issue
* fix(EndpointMenuDropdown): double overflow scroller in mobile model list
* fix: search model on mobile
* refactor: Endpoint/Model/modelSpec dropdown
* refactor: reorganize imports in Endpoint components
* refactor: remove unused translation keys from English locale
* BREAKING: moving to ariakit with new CustomMenu
* refactor: remove unnecessary comments
* refactor: remove EndpointItem, ModelDropdownButton, SpecIcon, and SpecItem components
* 🔧 fix: AI Icon bump when regenerating message
* wip: chat UI refactoring, fix issues
* chore: add recent update to useAutoSave
* feat: add access control for agent permissions in useMentions hook
* refactor: streamline ModelSelector by removing unused endpoints logic
* refactor: enhance ModelSelector and context by integrating endpointsConfig and improving type usage
* feat: update ModelSelectorContext to utilize conversation data for initial state
* feat: add selector effects for synced endpoint handling
* feat: add guard clause for conversation endpoint in useSelectorEffects hook
* fix: safely call onSelectMention and add autofocus to mention input
* chore: typing
* refactor: ModelSelector to streamline key dialog handling and improve endpoint rendering
* refactor: extract SettingsButton component for cleaner endpoint item rendering
* wip: first pass, expand set api key
* wip: first pass, expanding set key
* refactor: update EndpointItem styles for improved layout and hover effects
* refactor: adjust padding in EndpointItem for improved layout consistency
* refactor: update preset structure in useSelectMention to include spec as null
* refactor: rename setKeyDialogOpen to onOpenChange for clarity and consistency, bring focus back to button that opened dialog
* feat: add SpecIcon component for dynamic model spec icons in menu, adjust icon styling
* refactor: update getSelectedIcon to accept additional parameters and improve icon rendering logic
* fix: adjust padding in MessageRender for improved layout
* refactor: remove inline style for menu width in CustomMenu component
* refactor: enhance layout and styling in ModelSpecItem component for better responsiveness
* refactor: update getDefaultModelSpec to accept startupConfig and improve model spec retrieval logic
* refactor: improve key management and default values in ModelSelector and related components
* refactor: adjust menu width and improve responsiveness in CustomMenu and EndpointItem components
* refactor: enhance focus styles and responsiveness in EndpointItem component
* refactor: improve layout and spacing in Header and ModelSelector components for better responsiveness
* refactor: adjust button styles for consistency and improved layout in AddMultiConvo and PresetsMenu components
* fix: initial fix of assistant names
* fix: assistants handling
* chore: update version of librechat-data-provider to 0.7.75 and add 'spec' to excludedKeys
* fix: improve endpoint filtering logic based on interface configuration and access rights
* fix: remove unused HeaderOptions import and set spec to null in presets and mentions
* fix: ensure currentExample is always an object when updating examples
* fix: update interfaceConfig checks to ensure modelSelect is considered for rendering components
* fix: update model selection logic to consider interface configuration when prioritizing model specs
* fix: add missing localizations
* fix: remove unused agent and assistant selection translations
* fix: implement debounced state updates for selected values in useSelectorEffects
* style: minor style changes related to the ModelSelector
* fix: adjust maximum height for popover and set fixed height for model item
* fix: update placeholders for model and endpoint search inputs
* fix: refactor MessageRender and ContentRender components to better match each other
* fix: remove convo fallback for iconURL in MessageRender and ContentRender components
* fix: update handling of spec, iconURL, and modelLabel in conversation presets, to allow better interchangeability
* fix: replace chatGptLabel with modelLabel in OpenAI settings configuration (fully deprecate chatGptLabel)
* fix: remove console log for assistantNames in useEndpoints hook
* refactor: add cleanInput and cleanOutput options to default conversation handling
* chore: update bun.lockb
* fix: set default value for showIconInHeader in getSelectedIcon function
* refactor: enhance error handling in message processing when latest message has existing content blocks
* chore: allow import/no-cycle for messages
* fix: adjust flex properties in BookmarkMenu for better layout
* feat: support both 'prompt' and 'q' as query parameters in useQueryParams hook
* feat: re-enable Badges components
* refactor: disable edit badge component
* chore: rename assistantMap to assistantsMap for consistency
* chore: rename assistantMap to assistantsMap for consistency in Mention component
* feat: set staleTime for various queries to improve data freshness
* feat: add spec field to tQueryParamsSchema for model specification
* feat: enhance useQueryParams to handle model specs
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-25 23:50:58 +01:00
|
|
|
const errorResponse = createErrorMessage({
|
|
|
|
|
getMessages,
|
|
|
|
|
submission,
|
|
|
|
|
error,
|
|
|
|
|
});
|
2024-06-25 03:02:38 -04:00
|
|
|
setMessages([...submission.messages, submission.userMessage, errorResponse]);
|
|
|
|
|
if (newConversation) {
|
|
|
|
|
newConversation({
|
🎨 feat: UI Refresh for Enhanced UX (#6346)
* ✨ feat: Add Expand Chat functionality and improve UI components
* ✨ feat: Introduce Chat Badges feature with editing capabilities and UI enhancements
* ✨ feat: re-implement file attachment functionality with new components and improved UI
* ✨ feat: Enhance BadgeRow component with drag-and-drop functionality and add animations for better user experience
* ✨ feat: Add useChatBadges hook and enhance Badge component with animations and toggle functionality
* feat: Improve Add/Delete Badges + style and bug fixes
* ✨ feat: Refactor EditBadges component and optimize useChatBadges hook for improved performance and readability
* ✨ feat: Add type definition for LucideIcon in EditBadges component
* refactor: Clean up BadgeRow component by removing outdated comment and improving code readability
* refactor: Rename app-icon class to badge-icon for consistency and improve badge styling
* feat: Add Center Chat Input toggle and update related components for improved UI/UX
* refactor: Simplify ChatView and MessagesView components for improved readability and performance
* refactor: Improve layout and positioning of scroll button in MessagesView component
* refactor: Adjust scroll button position in MessagesView component for better visibility
* refactor: Remove redundant background class from Badge component for cleaner styling
* feat: disable chat badges
* refactor: adjust positioning of scroll button and popover for improved layout
* refactor: simplify class names in ChatForm and RemoveFile components for cleaner code
* refactor: move Switcher to HeaderOptions from SidePanel
* fix(Landing): duplicate description
* feat: add SplitText component for animated text display and update Landing component to use it
* feat(Chat): add ConversationStarters component and integrate it into ChatView; remove ConvoStarter component
* feat(Chat): enhance Message component layout and styling for improved readability
* feat(ControlCombobox, Select): enhance styling and add animation for improved UI experience
* feat(Chat): update Header and HeaderNewChat components for improved layout and styling
* feat(Chat): add ModelDropdown (now includes both endpoint and model) and refactor Menu components for improved UI
* feat(ModelDropdown): add Agent Select; removed old AgentSwitcher components
* feat(ModelDropdown): add settings button for user key configuration
* fix(ModelDropdown): the model dropdown wasn't opening automatically when opening the endpoint one
* refactor(Chat): remove unused EndpointsMenu and related components to streamline codebase
* feat: enhance greeting message and improve accessibility fro ModelDropdown
* refactor(Endpoints): add new hooks and components for endpoint management
* feat(Endpoint): add support for modelSpecs
* feat(Endpoints): add mobile support
* fix: type issues
* fix(modelSpec): type issue
* fix(EndpointMenuDropdown): double overflow scroller in mobile model list
* fix: search model on mobile
* refactor: Endpoint/Model/modelSpec dropdown
* refactor: reorganize imports in Endpoint components
* refactor: remove unused translation keys from English locale
* BREAKING: moving to ariakit with new CustomMenu
* refactor: remove unnecessary comments
* refactor: remove EndpointItem, ModelDropdownButton, SpecIcon, and SpecItem components
* 🔧 fix: AI Icon bump when regenerating message
* wip: chat UI refactoring, fix issues
* chore: add recent update to useAutoSave
* feat: add access control for agent permissions in useMentions hook
* refactor: streamline ModelSelector by removing unused endpoints logic
* refactor: enhance ModelSelector and context by integrating endpointsConfig and improving type usage
* feat: update ModelSelectorContext to utilize conversation data for initial state
* feat: add selector effects for synced endpoint handling
* feat: add guard clause for conversation endpoint in useSelectorEffects hook
* fix: safely call onSelectMention and add autofocus to mention input
* chore: typing
* refactor: ModelSelector to streamline key dialog handling and improve endpoint rendering
* refactor: extract SettingsButton component for cleaner endpoint item rendering
* wip: first pass, expand set api key
* wip: first pass, expanding set key
* refactor: update EndpointItem styles for improved layout and hover effects
* refactor: adjust padding in EndpointItem for improved layout consistency
* refactor: update preset structure in useSelectMention to include spec as null
* refactor: rename setKeyDialogOpen to onOpenChange for clarity and consistency, bring focus back to button that opened dialog
* feat: add SpecIcon component for dynamic model spec icons in menu, adjust icon styling
* refactor: update getSelectedIcon to accept additional parameters and improve icon rendering logic
* fix: adjust padding in MessageRender for improved layout
* refactor: remove inline style for menu width in CustomMenu component
* refactor: enhance layout and styling in ModelSpecItem component for better responsiveness
* refactor: update getDefaultModelSpec to accept startupConfig and improve model spec retrieval logic
* refactor: improve key management and default values in ModelSelector and related components
* refactor: adjust menu width and improve responsiveness in CustomMenu and EndpointItem components
* refactor: enhance focus styles and responsiveness in EndpointItem component
* refactor: improve layout and spacing in Header and ModelSelector components for better responsiveness
* refactor: adjust button styles for consistency and improved layout in AddMultiConvo and PresetsMenu components
* fix: initial fix of assistant names
* fix: assistants handling
* chore: update version of librechat-data-provider to 0.7.75 and add 'spec' to excludedKeys
* fix: improve endpoint filtering logic based on interface configuration and access rights
* fix: remove unused HeaderOptions import and set spec to null in presets and mentions
* fix: ensure currentExample is always an object when updating examples
* fix: update interfaceConfig checks to ensure modelSelect is considered for rendering components
* fix: update model selection logic to consider interface configuration when prioritizing model specs
* fix: add missing localizations
* fix: remove unused agent and assistant selection translations
* fix: implement debounced state updates for selected values in useSelectorEffects
* style: minor style changes related to the ModelSelector
* fix: adjust maximum height for popover and set fixed height for model item
* fix: update placeholders for model and endpoint search inputs
* fix: refactor MessageRender and ContentRender components to better match each other
* fix: remove convo fallback for iconURL in MessageRender and ContentRender components
* fix: update handling of spec, iconURL, and modelLabel in conversation presets, to allow better interchangeability
* fix: replace chatGptLabel with modelLabel in OpenAI settings configuration (fully deprecate chatGptLabel)
* fix: remove console log for assistantNames in useEndpoints hook
* refactor: add cleanInput and cleanOutput options to default conversation handling
* chore: update bun.lockb
* fix: set default value for showIconInHeader in getSelectedIcon function
* refactor: enhance error handling in message processing when latest message has existing content blocks
* chore: allow import/no-cycle for messages
* fix: adjust flex properties in BookmarkMenu for better layout
* feat: support both 'prompt' and 'q' as query parameters in useQueryParams hook
* feat: re-enable Badges components
* refactor: disable edit badge component
* chore: rename assistantMap to assistantsMap for consistency
* chore: rename assistantMap to assistantsMap for consistency in Mention component
* feat: set staleTime for various queries to improve data freshness
* feat: add spec field to tQueryParamsSchema for model specification
* feat: enhance useQueryParams to handle model specs
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
2025-03-25 23:50:58 +01:00
|
|
|
template: { conversationId: conversationId || errorResponse.conversationId || v4() },
|
2024-08-13 03:04:27 -04:00
|
|
|
preset: tPresetSchema.parse(submission.conversation),
|
2024-06-25 03:02:38 -04:00
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
setIsSubmitting(false);
|
|
|
|
|
}
|
|
|
|
|
},
|
🧭 refactor: Modernize Nav/Header (#7094)
* refactor: streamline model preset handling in conversation setup
* refactor: integrate navigation and location hooks in chat functions and event handlers, prevent cache from fetching on final event handling
* fix: prevent adding code interpreter non-image output to file list on message attachment event, fix all unhandled edge cases when this is done (treating the file download as an image attachment, undefined fields, message tokenCount issues, use of `startsWith` on undefined "text") although it is now prevent altogether
* chore: remove unused jailbreak prop from MinimalIcon component in EndpointIcon
* feat: add new SVG icons (MobileSidebar, Sidebar, XAIcon), fix: xAI styling in dark vs. light modes, adjust styling of Landing icons
* fix: open conversation in new tab on navigation with ctrl/meta key
* refactor: update Nav & Header to use close/open sidebar buttons, as well as redesign "New Chat"/"Bookmarks" buttons to the top of the Nav, matching the latest design of ChatGPT for simplicity and to free up space
* chore: remove unused isToggleHovering state and simplify opacity logic in Nav component
* style: match mobile nav to mobile header
2025-04-27 14:03:25 -04:00
|
|
|
[
|
|
|
|
|
finalHandler,
|
|
|
|
|
newConversation,
|
|
|
|
|
setIsSubmitting,
|
|
|
|
|
token,
|
|
|
|
|
cancelHandler,
|
|
|
|
|
getMessages,
|
|
|
|
|
setMessages,
|
|
|
|
|
],
|
2024-06-25 03:02:38 -04:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return {
|
🚧 chore: merge latest dev build to main repo (#3844)
* agents - phase 1 (#30)
* chore: copy assistant files
* feat: frontend and data-provider
* feat: backend get endpoint test
* fix(MessageEndpointIcon): switched to AgentName and AgentAvatar
* fix: small fixes
* fix: agent endpoint config
* fix: show Agent Builder
* chore: install agentus
* chore: initial scaffolding for agents
* fix: updated Assistant logic to Agent Logic for some Agent components
* WIP first pass, demo of agent package
* WIP: initial backend infra for agents
* fix: agent list error
* wip: agents routing
* chore: Refactor useSSE hook to handle different data events
* wip: correctly emit events
* chore: Update @librechat/agentus npm dependency to version 1.0.9
* remove comment
* first pass: streaming agent text
* chore: Remove @librechat/agentus root-level workspace npm dependency
* feat: Agent Schema and Model
* fix: content handling fixes
* fix: content message save
* WIP: new content data
* fix: run step issue with tool calls
* chore: Update @librechat/agentus npm dependency to version 1.1.5
* feat: update controller and agent routes
* wip: initial backend tool and tool error handling support
* wip: tool chunks
* chore: Update @librechat/agentus npm dependency to version 1.1.7
* chore: update tool_call typing, add test conditions and logs
* fix: create agent
* fix: create agent
* first pass: render completed content parts
* fix: remove logging, fix step handler typing
* chore: Update @librechat/agentus npm dependency to version 1.1.9
* refactor: cleanup maps on unmount
* chore: Update BaseClient.js to safely count tokens for string, number, and boolean values
* fix: support subsequent messages with tool_calls
* chore: export order
* fix: select agent
* fix: tool call types and handling
* chore: switch to anthropic for testing
* fix: AgentSelect
* refactor: experimental: OpenAIClient to use array for intermediateReply
* fix(useSSE): revert old condition for streaming legacy client tokens
* fix: lint
* revert `agent_id` to `id`
* chore: update localization keys for agent-related components
* feat: zod schema handling for actions
* refactor(actions): if no params, no zodSchema
* chore: Update @librechat/agentus npm dependency to version 1.2.1
* feat: first pass, actions
* refactor: empty schema for actions without params
* feat: Update createRun function to accept additional options
* fix: message payload formatting; feat: add more client options
* fix: ToolCall component rendering when action has no args but has output
* refactor(ToolCall): allow non-stringy args
* WIP: first pass, correctly formatted tool_calls between providers
* refactor: Remove duplicate import of 'roles' module
* refactor: Exclude 'vite.config.ts' from TypeScript compilation
* refactor: fix agent related types
> - no need to use endpoint/model fields for identifying agent metadata
> - add `provider` distinction for agent-configured 'endpoint'
- no need for agent-endpoint map
- reduce complexity of tools as functions into tools as string[]
- fix types related to above changes
- reduce unnecessary variables for queries/mutations and corresponding react-query keys
* refactor: Add tools and tool_kwargs fields to agent schema
* refactor: Remove unused code and update dependencies
* refactor: Update updateAgentHandler to use req.body directly
* refactor: Update AgentSelect component to use localized hooks
* refactor: Update agent schema to include tools and provider fields
* refactor(AgentPanel): add scrollbar gutter, add provider field to form, fix agent schema required values
* refactor: Update AgentSwitcher component to use selectedAgentId instead of selectedAgent
* refactor: Update AgentPanel component to include alternateName import and defaultAgentFormValues
* refactor(SelectDropDown): allow setting value as option while still supporting legacy usage (string values only)
* refactor: SelectDropdown changes - Only necessary when the available values are objects with label/value fields and the selected value is expected to be a string.
* refactor: TypeError issues and handle provider as option
* feat: Add placeholder for provider selection in AgentPanel component
* refactor: Update agent schema to include author and provider fields
* fix: show expected 'create agent' placeholder when creating agent
* chore: fix localization strings, hide capabilities form for now
* chore: typing
* refactor: import order and use compact agents schema for now
* chore: typing
* refactor: Update AgentForm type to use AgentCapabilities
* fix agent form agent selection issues
* feat: responsive agent selection
* fix: Handle cancelled fetch in useSelectAgent hook
* fix: reset agent form on accordion close/open
* feat: Add agent_id to default conversation for agents endpoint
* feat: agents endpoint request handling
* refactor: reset conversation model on agent select
* refactor: add `additional_instructions` to conversation schema, organize other fields
* chore: casing
* chore: types
* refactor(loadAgentTools): explicitly pass agent_id, do not pass `model` to loadAgentTools for now, load action sets by agent_id
* WIP: initial draft of real agent client initialization
* WIP: first pass, anthropic agent requests
* feat: remember last selected agent
* feat: openai and azure connected
* fix: prioritize agent model for runs unless an explicit override model is passed from client
* feat: Agent Actions
* fix: save agent id to convo
* feat: model panel (#29)
* feat: model panel
* bring back comments
* fix: method still null
* fix: AgentPanel FormContext
* feat: add more parameters
* fix: style issues; refactor: Agent Controller
* fix: cherry-pick
* fix: Update AgentAvatar component to use AssistantIcon instead of BrainCircuit
* feat: OGDialog for delete agent; feat(assistant): update Agent types, introduced `model_parameters`
* feat: icon and general `model_parameters` update
* feat: use react-hook-form better
* fix: agent builder form reset issue when switching panels
* refactor: modularize agent builder form
---------
Co-authored-by: Danny Avila <danny@librechat.ai>
* fix: AgentPanel and ModelPanel type issues and use `useFormContext` and `watch` instead of `methods` directly and `useWatch`.
* fix: tool call issues due to invalid input (anthropic) of empty string
* fix: handle empty text in Part component
---------
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
* refactor: remove form ModelPanel and fixed nested ternary expressions in AgentConfig
* fix: Model Parameters not saved correctly
* refactor: remove console log
* feat: avatar upload and get for Agents (#36)
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
* chore: update to public package
* fix: typing, optional chaining
* fix: cursor not showing for content parts
* chore: conditionally enable agents
* ci: fix azure test
* ci: fix frontend tests, fix eslint api
* refactor: Remove unused errorContentPart variable
* continue of the agent message PR (#40)
* last fixes
* fix: agentMap
* pr merge test (#41)
* fix: model icon not fetching correctly
* remove console logs
* feat: agent name
* refactor: pass documentsMap as a prop to allow re-render of assistant form
* refactor: pass documentsMap as a prop to allow re-render of assistant form
* chore: Bump version to 0.7.419
* fix: TypeError: Cannot read properties of undefined (reading 'id')
* refactor: update AgentSwitcher component to use ControlCombobox instead of Combobox
---------
Co-authored-by: Marco Beretta <81851188+berry-13@users.noreply.github.com>
2024-08-31 16:33:51 -04:00
|
|
|
stepHandler,
|
2024-06-25 03:02:38 -04:00
|
|
|
syncHandler,
|
|
|
|
|
finalHandler,
|
|
|
|
|
errorHandler,
|
|
|
|
|
messageHandler,
|
|
|
|
|
contentHandler,
|
|
|
|
|
createdHandler,
|
2024-09-30 17:17:57 -04:00
|
|
|
attachmentHandler,
|
2024-06-25 03:02:38 -04:00
|
|
|
abortConversation,
|
|
|
|
|
};
|
|
|
|
|
}
|