Commit Graph

2679 Commits

Author SHA1 Message Date
Apple\Apple
4ae8bf2f71 ♻️ refactor(playground): major architectural overhaul and code optimization
Completely restructured the Playground component from a 1437-line monolith
into a maintainable, modular architecture with 62.4% code reduction (540 lines).

**Key Improvements:**
- **Modular Architecture**: Extracted business logic into separate utility files
  - `utils/constants.js` - Centralized constant management
  - `utils/messageUtils.js` - Message processing utilities
  - `utils/apiUtils.js` - API-related helper functions
- **Custom Hooks**: Created specialized hooks for better state management
  - `usePlaygroundState.js` - Centralized state management
  - `useMessageActions.js` - Message operation handlers
  - `useApiRequest.js` - API request management
- **Code Quality**: Applied SOLID principles and functional programming patterns
- **Performance**: Optimized re-renders with useCallback and proper dependency arrays
- **Maintainability**: Implemented single responsibility principle and separation of concerns

**Technical Achievements:**
- Eliminated code duplication and redundancy
- Replaced magic strings with typed constants
- Extracted complex inline logic into pure functions
- Improved error handling and API response processing
- Enhanced code readability and testability

**Breaking Changes:** None - All existing functionality preserved

This refactor transforms the codebase into enterprise-grade quality following
React best practices and modern development standards.
2025-05-30 22:14:44 +08:00
Apple\Apple
0a848c2d6c feat(playground): add role toggle feature for AI messages
- Add role toggle button in MessageActions component for assistant/system messages
- Implement handleRoleToggle function in Playground component to switch between assistant and system roles
- Add visual distinction for system messages with orange badge indicator
- Update roleInfo configuration to use consistent avatars for assistant and system roles
- Add proper tooltip texts and visual feedback for role switching
- Ensure role toggle is disabled during message generation to prevent conflicts

This feature allows users to easily switch message roles between assistant and system,
providing better control over conversation flow and message categorization in the playground interface.
2025-05-30 21:51:09 +08:00
Apple\Apple
eeb9fe9b7f feat: enhance debug panel with real-time preview and collapsible tabs
- Add real-time request body preview that updates when parameters change
- Implement pre-constructed payload generation for debugging without sending requests
- Add support for image URLs in preview payload construction
- Upgrade debug panel to card-style tabs with custom arrow navigation
- Add collapsible functionality and dropdown menu for tab selection
- Integrate image-enabled messages with proper multimodal content structure
- Refactor tab state management with internal useState and external sync
- Remove redundant status labels and clean up component structure
- Set preview tab as default active tab for better UX
- Maintain backward compatibility with existing debug functionality

This enhancement significantly improves the debugging experience by allowing
developers to see exactly what request will be sent before actually sending it,
with real-time updates as they adjust parameters, models, or image settings.
2025-05-30 21:34:13 +08:00
Apple\Apple
fbb189ecd7 feat: add image upload toggle with auto-disable after sending
Add a toggle switch to enable/disable image uploads in the playground,
with automatic disabling after message sending to prevent accidental
image inclusion in subsequent messages.

Changes:
- Add `imageEnabled` field to default configuration with false as default
- Enhance ImageUrlInput component with enable/disable toggle switch
- Update UI to show disabled state with opacity and color changes
- Modify message sending logic to only include images when enabled
- Implement auto-disable functionality after message is sent
- Update SettingsPanel to pass through new imageEnabled props
- Maintain backward compatibility with existing configurations

User Experience:
- Images are disabled by default for privacy and intentional usage
- Users must explicitly enable image uploads before adding URLs
- After sending a message with images, the feature auto-disables
- Clear visual feedback shows current enabled/disabled state
- Manual control allows users to re-enable when needed

This improves user control over multimodal conversations and prevents
unintentional image sharing in follow-up messages.
2025-05-30 20:05:13 +08:00
Apple\Apple
2abf2c464f 🎨 style(ui): Optimize the detail page height 2025-05-30 19:37:12 +08:00
Apple\Apple
9c5ab755c1 🐛 fix(playground): improve multimodal content handling and error resilience
Fix TypeError when processing multimodal messages containing both text and images.
The error "textContent.text.trim is not a function" occurred when textContent
was null or textContent.text was not a string type.

Changes:
- Add comprehensive type checking for textContent.text access
- Implement getTextContent() utility function for unified content extraction
- Enhance error handling to support multimodal content display
- Fix message copy functionality to handle array-format content
- Improve message reset functionality to extract text content for retry
- Add user-friendly warnings when copying messages without text content

Technical improvements:
- Validate textContent existence and text property type before calling trim()
- Extract text content from multimodal messages for operations like copy/retry
- Maintain backward compatibility with string-format content
- Preserve all existing functionality while adding robust error handling

Fixes issues with:
- Image + text message processing
- Message copying from multimodal content
- Message retry with image attachments
- Error display for complex message formats

This ensures the playground component handles multimodal content gracefully
without breaking existing text-only message functionality.
2025-05-30 19:32:49 +08:00
Apple\Apple
c5ed0753a6 🎨 refactor(playground): Refactor the structure of the playground and implement responsive design adaptation 2025-05-30 19:24:17 +08:00
Apple\Apple
faa7abcc7f Revert "🔖chore: Remove the handling of the MarkdownRender component and the <think> tag"
This reverts commit 96f338c964.
2025-05-30 01:31:38 +08:00
Apple\Apple
bbf7fe2d1d Merge remote-tracking branch 'origin/ui/refactor' into ui/refactor 2025-05-29 16:25:33 +08:00
Apple\Apple
96f338c964 🔖chore: Remove the handling of the MarkdownRender component and the <think> tag 2025-05-29 16:25:13 +08:00
CaIon
21d68f61ea Merge remote-tracking branch 'origin/ui/refactor' into ui/refactor 2025-05-29 15:52:16 +08:00
CaIon
f47bc44dbc refactor: Update TopUp component to utilize StatusContext for dynamic top-up settings 2025-05-29 15:52:11 +08:00
Apple\Apple
75c94d9374 🛠️ fix(chat): optimize think tag handling and reasoning panel behavior
BREAKING CHANGE: Refactor message stream processing and think tag handling logic

- Improve automatic collapse behavior of reasoning panel
  - Collapse panel immediately after reasoning content completion
  - Add detection for complete think tag pairs
  - Remove dependency on full content completion

- Enhance think tag processing
  - Unify tag handling logic across stream and stop states
  - Add robust handling for unclosed think tags
  - Prevent markdown rendering errors from malformed tags

- Simplify state management
  - Reduce complexity in collapse condition checks
  - Remove redundant state transitions
  - Improve code readability by removing unnecessary comments

This commit ensures a more stable and predictable behavior in the chat interface, particularly in handling streaming responses and reasoning content display.
2025-05-29 12:02:29 +08:00
Apple\Apple
31ece25252 🐛 fix(Playground): Prevent markdown error from <think> tags in reasoning display
- Modified the `renderCustomChatContent` function to strip `<think>` and `</think>` tags from `finalExtractedThinkingContent` before passing it to the `MarkdownRender` component. This resolves potential parsing errors caused by unclosed or malformed tags.
- Added a conditional check to ensure that the thinking process block is only rendered if `finalExtractedThinkingContent` has actual content and the section is expanded, improving rendering stability.
2025-05-29 11:25:26 +08:00
Apple\Apple
2dcd6fa2b9 🧠 fix(Playground): Enhance <think> tag processing and remove redundant comments
This commit significantly refactors the handling of <think> tags within the Playground component to improve robustness, prevent Markdown rendering errors, and ensure accurate separation of reasoning and displayable content.

Key changes include:
- Modified `handleNonStreamRequest`, `onStopGenerator`, and `renderCustomChatContent` for more resilient <think> tag parsing.
- Implemented logic to correctly extract content from fully paired `<think>...</think>` tags.
- Added handling for unclosed `<think>` tags, particularly relevant during streaming responses, to capture ongoing thought processes.
- Ensured `reasoningContent` is accurately populated from all sources (API, paired tags, and unclosed streaming tags).
- Thoroughly sanitized the final `currentDisplayableFinalContent` to remove all residual `<think>` and `</think>` string instances, preventing issues with the Markdown renderer.
- Corrected the usage of `thinkTagRegex.lastIndex = 0;` to ensure proper regex state resetting before each use in loops.

Additionally, numerous explanatory comments detailing the "how" of the code (rather than the "why") have been removed to improve code readability and reduce noise.
2025-05-29 04:21:33 +08:00
Apple\Apple
19cd98cb99 Merge branch 'main' into ui/refactor 2025-05-29 03:57:05 +08:00
Apple\Apple
5a370f17f2 Merge remote-tracking branch 'origin/ui/refactor' into ui/refactor 2025-05-29 03:56:28 +08:00
Apple\Apple
cd5960686f feat: enhance chat playground with improved message handling and UI
- Add message operations (copy, retry, delete) with tooltips
- Improve thinking chain processing and display logic
- Enhance error handling and debug information presentation
- Optimize UI layout and responsive design
  - Fix height calculations for better viewport usage
  - Improve mobile view adaptability
- Add comprehensive error feedback for message operations
- Implement fallback clipboard functionality
- Refine debug panel with better error tracking
- Add transition animations for better UX
- Update styling with modern gradient backgrounds
2025-05-29 03:56:08 +08:00
CaIon
c1a70ad690 style: Add styles for semi-table components to improve layout and presentation 2025-05-29 03:35:18 +08:00
creamlike1024
361b0abec9 fix: pingerCtx 泄漏 2025-05-28 21:34:45 +08:00
CaIon
e01b517843 fix: Change ParallelTooCalls from bool to *bool in GeneralOpenAIRequest for optional handling 2025-05-28 21:12:55 +08:00
CaIon
f613a79f3e feat: Enhance image request validation in relay-image.go: set default model and size, improve error handling for size format, and ensure prompt and N parameters are validated correctly. 2025-05-28 20:18:37 +08:00
Apple\Apple
6bb49ade76 Merge remote-tracking branch 'origin/main' into ui/refactor 2025-05-28 18:42:19 +08:00
IcedTangerine
87540b4f7c Merge pull request #1110 from wangr0031/fix_parallel_tool_calls
feat: chat/completion路由透传parallel_tool_calls参数
2025-05-28 14:25:43 +08:00
IcedTangerine
e3d7b31a49 Update openai_request.go 2025-05-28 14:25:24 +08:00
IcedTangerine
bf016543c3 Merge pull request #1113 from tbphp/tbphp_vertex_gemini_global_region
fix: Vertex channel global region format
2025-05-28 14:16:47 +08:00
IcedTangerine
eb94aa13e6 Merge pull request #1111 from feitianbubu/fxm-ali-fetch-models-url
fix: ali FetchUpstreamModels url
2025-05-28 14:11:17 +08:00
Apple\Apple
16b9cb6ff4 🎨 style(ui): The send button for chat is changed to have rounded corners 2025-05-28 02:01:54 +08:00
tbphp
6e72dcd0ba fix: Vertex channel global region format 2025-05-27 21:50:53 +08:00
skynono
96ab4177ca fix: ali FetchUpstreamModels url 2025-05-27 11:22:40 +08:00
wang.rong
76824a0337 chat/completion透传parallel_tool_calls参数 2025-05-27 09:32:20 +08:00
Apple\Apple
22af6af9c7 🛠️ fix(chat): enhance message generation stop behavior
This commit improves the handling of message generation interruption in the
playground chat interface, ensuring both content and thinking process are
properly preserved.

Key changes:
- Preserve existing content when stopping message generation
- Handle both direct reasoningContent and <think> tag formats
- Extract and merge thinking process from unclosed <think> tags
- Maintain consistent thinking chain format with separators
- Auto-collapse reasoning panel after stopping for cleaner UI

Technical details:
- Modified onStopGenerator to properly handle SSE connection closure
- Added regex pattern to extract thinking content from <think> tags
- Implemented proper state management for incomplete messages
- Ensured all content types are preserved in their respective fields

This fix resolves the issue where thinking chain content would be lost
when stopping message generation mid-stream.
2025-05-27 02:07:42 +08:00
Apple\Apple
d542b529cb 🔗 feat: add navigation to topup page from balance cards
- Add click-to-navigate functionality on balance cards in both Detail and TokensTable components
- Implement navigation to '/console/topup' when clicking on current balance
- Add useNavigate hook and necessary imports
- Keep consistent navigation behavior across components

Components affected:
- web/src/pages/Detail/index.js
- web/src/components/TokensTable.js
2025-05-26 23:30:26 +08:00
Apple\Apple
a7c79a9e34 🌐 i18n: add internationalization support for Loading component
This commit introduces the following changes:

- Add i18n support to the Loading component
- Import useTranslation hook from react-i18next
- Replace hardcoded Chinese text with translation keys
- Support dynamic content interpolation for loading prompts
- Use {{name}} variable in translation template

Technical details:
- Added: import { useTranslation } from 'react-i18next'
- Modified: Loading text from static Chinese to i18n keys
- Translation keys added:
  - "加载中..."
  - "加载{{name}}中..."

File changed: web/src/components/Loading.js
2025-05-26 23:10:42 +08:00
Apple\Apple
e85f687c6b feat: add notice modal component with empty state support
This commit introduces the following changes:

- Create a reusable NoticeModal component to handle system announcements
- Extract notice functionality from Home and HeaderBar components
- Add loading and empty states using Semi UI illustrations
- Implement "close for today" feature with localStorage
- Support both light and dark mode for empty state illustrations
- Add proper error handling and loading states
- Improve code reusability and maintainability

Breaking changes: None
Related components: HeaderBar.js, Home/index.js, NoticeModal.js
2025-05-26 23:06:55 +08:00
Apple\Apple
acdfd86286 🎨 style(ui): Adjust the size of the icon 2025-05-26 22:30:04 +08:00
Apple\Apple
1e57317322 🎨 style(ui): Optimize icon adaptation 2025-05-26 22:25:38 +08:00
Apple\Apple
16ad2d48d8 🎨 style(ui): Modify the sidebar background color to match the theme color 2025-05-26 22:09:50 +08:00
Apple\Apple
21077d4696 🐛 fix(headerbar): Fix the issue where the header disappears on mobile screen sizes. 2025-05-26 22:01:57 +08:00
Apple\Apple
d3a6f1cc46 Merge branch 'main' into ui/refactor
# Conflicts:
#	web/src/components/ChannelsTable.js
#	web/src/pages/Home/index.js
#	web/src/pages/Playground/Playground.js
2025-05-26 21:53:30 +08:00
Apple\Apple
5b5f10cadc 🔖chore: Preparation modifications before the merger 2025-05-26 21:52:37 +08:00
Apple\Apple
fa06ea19a6 🔧 fix(chat): optimize SSE connection status handling
- Remove unnecessary undefined status check in readystatechange event
- Only show disconnection message for actual non-200 status codes
- Remove redundant else branch for normal status handling
- Prevent false "Connection lost" messages on successful completion
2025-05-26 20:24:04 +08:00
Apple\Apple
3454d6c29e Merge remote-tracking branch 'origin/ui/refactor' into ui/refactor 2025-05-26 19:59:51 +08:00
Apple\Apple
d96eb6fb1c 🐛 fix(chat): improve error handling and UI feedback for SSE communication
- Add comprehensive error handling for SSE events
- Implement proper error state UI with Semi Typography
- Prevent white screen issues on non-200 responses
- Add error logging for better debugging
- Enhance message state management for error conditions
- Improve user feedback with i18n error messages
- Ensure UI stability during error states
- Add try-catch blocks for JSON parsing and stream initialization
- Handle connection termination gracefully
- Preserve error states in message stream updates
2025-05-26 19:58:01 +08:00
CaIon
693dfd18f9 🎨 style(ModelPricing): Update card shadow and add margin for improved layout 2025-05-26 19:41:21 +08:00
IcedTangerine
3cd29a4963 Merge pull request #1109 from feitianbubu/fix-qwen-thinking
fix: ali parameter.enable_thinking must be set to false for non-strea…
2025-05-26 19:32:34 +08:00
creamlike1024
41120b4d75 Merge branch 'main' of github.com:QuantumNous/new-api 2025-05-26 18:56:14 +08:00
creamlike1024
30d5a11f46 fix: search-preview model web search billing 2025-05-26 18:53:41 +08:00
skynono
368fd75c86 fix: ali parameter.enable_thinking must be set to false for non-streaming calls 2025-05-26 17:41:02 +08:00
IcedTangerine
ee07762611 Merge pull request #1075 from feitianbubu/fix-default-model-not-exist
fix: if default model is not exist, set the first one as default
2025-05-26 17:21:14 +08:00